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> |
| 27 | #include "utility/HandleTracker.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 28 | #include "binding/IAAudioService.h" |
| 29 | #include "binding/AAudioServiceInterface.h" |
| 30 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 31 | #include "AAudioServiceStreamBase.h" |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | class AAudioService : |
| 36 | public BinderService<AAudioService>, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 37 | public BnAAudioService, |
| 38 | public aaudio::AAudioServiceInterface |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 39 | { |
| 40 | friend class BinderService<AAudioService>; |
| 41 | |
| 42 | public: |
| 43 | AAudioService(); |
| 44 | virtual ~AAudioService(); |
| 45 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 46 | static const char* getServiceName() { return AAUDIO_SERVICE_NAME; } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 47 | |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 48 | virtual status_t dump(int fd, const Vector<String16>& args) override; |
| 49 | |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 50 | virtual void registerClient(const sp<IAAudioClient>& client); |
| 51 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 52 | virtual aaudio_handle_t openStream(const aaudio::AAudioStreamRequest &request, |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 53 | aaudio::AAudioStreamConfiguration &configurationOutput); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 54 | |
| 55 | virtual aaudio_result_t closeStream(aaudio_handle_t streamHandle); |
| 56 | |
| 57 | virtual aaudio_result_t getStreamDescription( |
| 58 | aaudio_handle_t streamHandle, |
| 59 | aaudio::AudioEndpointParcelable &parcelable); |
| 60 | |
| 61 | virtual aaudio_result_t startStream(aaudio_handle_t streamHandle); |
| 62 | |
| 63 | virtual aaudio_result_t pauseStream(aaudio_handle_t streamHandle); |
| 64 | |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 65 | virtual aaudio_result_t stopStream(aaudio_handle_t streamHandle); |
| 66 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 67 | virtual aaudio_result_t flushStream(aaudio_handle_t streamHandle); |
| 68 | |
| 69 | virtual aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle, |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 70 | pid_t tid, |
| 71 | int64_t periodNanoseconds) ; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 72 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 73 | virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle, |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 74 | pid_t tid); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 75 | |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame^] | 76 | virtual aaudio_result_t startClient(aaudio_handle_t streamHandle, |
| 77 | const android::AudioClient& client, |
| 78 | audio_port_handle_t *clientHandle); |
| 79 | |
| 80 | virtual aaudio_result_t stopClient(aaudio_handle_t streamHandle, |
| 81 | audio_port_handle_t clientHandle); |
| 82 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 83 | private: |
| 84 | |
| 85 | aaudio::AAudioServiceStreamBase *convertHandleToServiceStream(aaudio_handle_t streamHandle) const; |
| 86 | |
| 87 | HandleTracker mHandleTracker; |
| 88 | |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame^] | 89 | android::AudioClient mAudioClient; |
Phil Burk | 2ac035f | 2017-06-23 14:51:14 -0700 | [diff] [blame] | 90 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 91 | enum constants { |
| 92 | DEFAULT_AUDIO_PRIORITY = 2 |
| 93 | }; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } /* namespace android */ |
| 97 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 98 | #endif //AAUDIO_AAUDIO_SERVICE_H |