Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 17 | #ifndef AAUDIO_AAUDIO_SERVICE_H |
| 18 | #define AAUDIO_AAUDIO_SERVICE_H |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 19 | |
| 20 | #include <time.h> |
| 21 | #include <pthread.h> |
| 22 | |
| 23 | #include <binder/BinderService.h> |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 24 | #include <media/AudioClient.h> |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 25 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 26 | #include <aaudio/AAudio.h> |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 27 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 28 | #include "binding/AAudioCommon.h" |
| 29 | #include "binding/AAudioServiceInterface.h" |
| 30 | #include "binding/IAAudioService.h" |
| 31 | |
| 32 | #include "AAudioServiceStreamBase.h" |
| 33 | #include "AAudioStreamTracker.h" |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | |
| 37 | class AAudioService : |
| 38 | public BinderService<AAudioService>, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 39 | public BnAAudioService, |
| 40 | public aaudio::AAudioServiceInterface |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 41 | { |
| 42 | friend class BinderService<AAudioService>; |
| 43 | |
| 44 | public: |
| 45 | AAudioService(); |
| 46 | virtual ~AAudioService(); |
| 47 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 48 | static const char* getServiceName() { return AAUDIO_SERVICE_NAME; } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 49 | |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 50 | virtual status_t dump(int fd, const Vector<String16>& args) override; |
| 51 | |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 52 | virtual void registerClient(const sp<IAAudioClient>& client); |
| 53 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 54 | aaudio::aaudio_handle_t openStream(const aaudio::AAudioStreamRequest &request, |
| 55 | aaudio::AAudioStreamConfiguration &configurationOutput) |
| 56 | override; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 57 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 58 | aaudio_result_t closeStream(aaudio::aaudio_handle_t streamHandle) override; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 59 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 60 | aaudio_result_t getStreamDescription( |
| 61 | aaudio::aaudio_handle_t streamHandle, |
| 62 | aaudio::AudioEndpointParcelable &parcelable) override; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 63 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 64 | aaudio_result_t startStream(aaudio::aaudio_handle_t streamHandle) override; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 65 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 66 | aaudio_result_t pauseStream(aaudio::aaudio_handle_t streamHandle) override; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 67 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 68 | aaudio_result_t stopStream(aaudio::aaudio_handle_t streamHandle) override; |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 69 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 70 | aaudio_result_t flushStream(aaudio::aaudio_handle_t streamHandle) override; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 71 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 72 | aaudio_result_t registerAudioThread(aaudio::aaudio_handle_t streamHandle, |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 73 | pid_t tid, |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 74 | int64_t periodNanoseconds) override; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 75 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 76 | aaudio_result_t unregisterAudioThread(aaudio::aaudio_handle_t streamHandle, |
| 77 | pid_t tid) override; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 78 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 79 | aaudio_result_t startClient(aaudio::aaudio_handle_t streamHandle, |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 80 | const android::AudioClient& client, |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 81 | audio_port_handle_t *clientHandle) override; |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 82 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 83 | aaudio_result_t stopClient(aaudio::aaudio_handle_t streamHandle, |
| 84 | audio_port_handle_t clientHandle) override; |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 85 | |
Phil Burk | bbd5286 | 2018-04-13 11:37:42 -0700 | [diff] [blame] | 86 | aaudio_result_t disconnectStreamByPortHandle(audio_port_handle_t portHandle); |
| 87 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 88 | private: |
| 89 | |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 90 | /** |
| 91 | * Lookup stream and then validate access to the stream. |
| 92 | * @param streamHandle |
| 93 | * @return |
| 94 | */ |
| 95 | sp<aaudio::AAudioServiceStreamBase> convertHandleToServiceStream( |
| 96 | aaudio::aaudio_handle_t streamHandle); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 97 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 98 | |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 99 | |
Phil Burk | 9486252 | 2017-09-13 21:31:36 -0700 | [diff] [blame] | 100 | bool releaseStream(const sp<aaudio::AAudioServiceStreamBase> &serviceStream); |
| 101 | |
| 102 | aaudio_result_t checkForPendingClose(const sp<aaudio::AAudioServiceStreamBase> &serviceStream, |
| 103 | aaudio_result_t defaultResult); |
| 104 | |
| 105 | android::AudioClient mAudioClient; |
| 106 | |
| 107 | aaudio::AAudioStreamTracker mStreamTracker; |
Phil Burk | 523b304 | 2017-09-13 13:03:08 -0700 | [diff] [blame] | 108 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 109 | enum constants { |
| 110 | DEFAULT_AUDIO_PRIORITY = 2 |
| 111 | }; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } /* namespace android */ |
| 115 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 116 | #endif //AAUDIO_AAUDIO_SERVICE_H |