1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <aaudio/IAAudioService.h> 20 #include <binding/AAudioServiceInterface.h> 21 22 namespace aaudio { 23 24 /** 25 * An adapter that takes in an underlying IAAudioService and exposes an 26 * AAudioServiceInterface. 27 * 28 * This class is abstract: the client is expected to inherit from this class and implement those 29 * methods from AAudioServiceInterface that don't have counterparts in IAAudioService. 30 */ 31 class AAudioBinderAdapter : public AAudioServiceInterface { 32 public: 33 AAudioBinderAdapter(IAAudioService* delegate, int32_t serviceLifetimeId); 34 35 void registerClient(const android::sp<IAAudioClient>& client) override; 36 37 AAudioHandleInfo openStream(const AAudioStreamRequest& request, 38 AAudioStreamConfiguration& configuration) override; 39 40 aaudio_result_t closeStream(const AAudioHandleInfo& streamHandleInfo) override; 41 42 aaudio_result_t getStreamDescription(const AAudioHandleInfo& streamHandleInfo, 43 AudioEndpointParcelable& endpoint) override; 44 45 aaudio_result_t startStream(const AAudioHandleInfo& streamHandleInfo) override; 46 47 aaudio_result_t pauseStream(const AAudioHandleInfo& streamHandleInfo) override; 48 49 aaudio_result_t stopStream(const AAudioHandleInfo& streamHandleInfo) override; 50 51 aaudio_result_t flushStream(const AAudioHandleInfo& streamHandleInfo) override; 52 53 aaudio_result_t registerAudioThread(const AAudioHandleInfo& streamHandleInfo, 54 pid_t clientThreadId, 55 int64_t periodNanoseconds) override; 56 57 aaudio_result_t unregisterAudioThread(const AAudioHandleInfo& streamHandleInfo, 58 pid_t clientThreadId) override; 59 60 aaudio_result_t exitStandby(const AAudioHandleInfo& streamHandleInfo, 61 AudioEndpointParcelable &parcelable) override; 62 63 private: 64 IAAudioService* const mDelegate; 65 // A unique id to recognize the service that the adapter connected to. 66 const int32_t mServiceLifetimeId; 67 }; 68 69 } // namespace aaudio 70