| 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 | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_AAUDIO_IAAUDIO_SERVICE_H | 
|  | 18 | #define ANDROID_AAUDIO_IAAUDIO_SERVICE_H | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 | #include <utils/RefBase.h> | 
|  | 22 | #include <binder/TextOutput.h> | 
|  | 23 | #include <binder/IInterface.h> | 
|  | 24 |  | 
|  | 25 | #include <aaudio/AAudio.h> | 
|  | 26 |  | 
|  | 27 | #include "binding/AAudioServiceDefinitions.h" | 
|  | 28 | #include "binding/AudioEndpointParcelable.h" | 
|  | 29 | #include "binding/AAudioStreamRequest.h" | 
|  | 30 | #include "binding/AAudioStreamConfiguration.h" | 
| Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame^] | 31 | #include "binding/IAAudioClient.h" | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 32 | #include "utility/HandleTracker.h" | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 33 |  | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 34 | namespace android { | 
|  | 35 |  | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 36 | #define AAUDIO_SERVICE_NAME  "media.aaudio" | 
|  | 37 |  | 
| Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame^] | 38 | // Interface (our AIDL) - service methods called by client | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 39 | class IAAudioService : public IInterface { | 
|  | 40 | public: | 
|  | 41 |  | 
|  | 42 | DECLARE_META_INTERFACE(AAudioService); | 
|  | 43 |  | 
| Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame^] | 44 | // Register an object to receive audio input/output change and track notifications. | 
|  | 45 | // For a given calling pid, AAudio service disregards any registrations after the first. | 
|  | 46 | // Thus the IAAudioClient must be a singleton per process. | 
|  | 47 | virtual void registerClient(const sp<IAAudioClient>& client) = 0; | 
|  | 48 |  | 
| Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 49 | /** | 
|  | 50 | * @param request info needed to create the stream | 
|  | 51 | * @param configuration contains information about the created stream | 
|  | 52 | * @return handle to the stream or a negative error | 
|  | 53 | */ | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 54 | virtual aaudio_handle_t openStream(const aaudio::AAudioStreamRequest &request, | 
|  | 55 | aaudio::AAudioStreamConfiguration &configurationOutput) = 0; | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 56 |  | 
| Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 57 | virtual aaudio_result_t closeStream(aaudio::aaudio_handle_t streamHandle) = 0; | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 58 |  | 
|  | 59 | /* Get an immutable description of the in-memory queues | 
|  | 60 | * used to communicate with the underlying HAL or Service. | 
|  | 61 | */ | 
| Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 62 | virtual aaudio_result_t getStreamDescription(aaudio::aaudio_handle_t streamHandle, | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 63 | aaudio::AudioEndpointParcelable &parcelable) = 0; | 
|  | 64 |  | 
|  | 65 | /** | 
|  | 66 | * Start the flow of data. | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 67 | * This is asynchronous. When complete, the service will send a STARTED event. | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 68 | */ | 
| Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 69 | virtual aaudio_result_t startStream(aaudio::aaudio_handle_t streamHandle) = 0; | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 70 |  | 
|  | 71 | /** | 
|  | 72 | * Stop the flow of data such that start() can resume without loss of data. | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 73 | * This is asynchronous. When complete, the service will send a PAUSED event. | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 74 | */ | 
| Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 75 | virtual aaudio_result_t pauseStream(aaudio::aaudio_handle_t streamHandle) = 0; | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 76 |  | 
|  | 77 | /** | 
| Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 78 | * Stop the flow of data such that the data currently in the buffer is played. | 
|  | 79 | * This is asynchronous. When complete, the service will send a STOPPED event. | 
|  | 80 | */ | 
|  | 81 | virtual aaudio_result_t stopStream(aaudio::aaudio_handle_t streamHandle) = 0; | 
|  | 82 |  | 
|  | 83 | /** | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 84 | *  Discard any data held by the underlying HAL or Service. | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 85 | * This is asynchronous. When complete, the service will send a FLUSHED event. | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 86 | */ | 
| Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 87 | virtual aaudio_result_t flushStream(aaudio::aaudio_handle_t streamHandle) = 0; | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 88 |  | 
|  | 89 | /** | 
|  | 90 | * Manage the specified thread as a low latency audio thread. | 
|  | 91 | */ | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 92 | virtual aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle, | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 93 | pid_t clientThreadId, | 
| Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 94 | int64_t periodNanoseconds) = 0; | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 95 |  | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 96 | virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle, | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 97 | pid_t clientThreadId) = 0; | 
|  | 98 | }; | 
|  | 99 |  | 
|  | 100 | class BnAAudioService : public BnInterface<IAAudioService> { | 
|  | 101 | public: | 
|  | 102 | virtual status_t onTransact(uint32_t code, const Parcel& data, | 
|  | 103 | Parcel* reply, uint32_t flags = 0); | 
|  | 104 |  | 
|  | 105 | }; | 
|  | 106 |  | 
|  | 107 | } /* namespace android */ | 
|  | 108 |  | 
| Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 109 | #endif //ANDROID_AAUDIO_IAAUDIO_SERVICE_H |