Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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_BINDING_AAUDIO_SERVICE_INTERFACE_H |
| 18 | #define ANDROID_AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 19 | |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 20 | #include <utils/StrongPointer.h> |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 21 | #include <media/AudioClient.h> |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 22 | |
Ytai Ben-Tsvi | 0412f73 | 2020-08-17 14:43:36 -0700 | [diff] [blame] | 23 | #include "aaudio/IAAudioClient.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 24 | #include "binding/AAudioServiceDefinitions.h" |
| 25 | #include "binding/AAudioStreamRequest.h" |
| 26 | #include "binding/AAudioStreamConfiguration.h" |
| 27 | #include "binding/AudioEndpointParcelable.h" |
| 28 | |
| 29 | /** |
| 30 | * This has the same methods as IAAudioService but without the Binder features. |
| 31 | * |
| 32 | * It allows us to abstract the Binder interface and use an AudioStreamInternal |
| 33 | * both in the client and in the service. |
| 34 | */ |
| 35 | namespace aaudio { |
| 36 | |
| 37 | class AAudioServiceInterface { |
| 38 | public: |
| 39 | |
jiabin | d5bd06a | 2021-04-27 22:04:08 +0000 | [diff] [blame] | 40 | AAudioServiceInterface() = default; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 41 | virtual ~AAudioServiceInterface() = default; |
| 42 | |
Ytai Ben-Tsvi | 0412f73 | 2020-08-17 14:43:36 -0700 | [diff] [blame] | 43 | virtual void registerClient(const android::sp<IAAudioClient>& client) = 0; |
Phil Burk | 11e8d33 | 2017-05-24 09:59:02 -0700 | [diff] [blame] | 44 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 45 | /** |
| 46 | * @param request info needed to create the stream |
| 47 | * @param configuration contains information about the created stream |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 48 | * @return an object for aaudio handle information, which includes the connected |
| 49 | * aaudio service lifetime id to recognize the connected aaudio service |
| 50 | * and aaudio handle to recognize the stream. If an error occurs, the |
| 51 | * aaudio handle will be set as the negative error. |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 52 | */ |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 53 | virtual AAudioHandleInfo openStream(const AAudioStreamRequest &request, |
| 54 | AAudioStreamConfiguration &configuration) = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 55 | |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 56 | virtual aaudio_result_t closeStream(const AAudioHandleInfo& streamHandleInfo) = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 57 | |
| 58 | /* Get an immutable description of the in-memory queues |
| 59 | * used to communicate with the underlying HAL or Service. |
| 60 | */ |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 61 | virtual aaudio_result_t getStreamDescription(const AAudioHandleInfo& streamHandleInfo, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 62 | AudioEndpointParcelable &parcelable) = 0; |
| 63 | |
| 64 | /** |
| 65 | * Start the flow of data. |
| 66 | */ |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 67 | virtual aaudio_result_t startStream(const AAudioHandleInfo& streamHandleInfo) = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Stop the flow of data such that start() can resume without loss of data. |
| 71 | */ |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 72 | virtual aaudio_result_t pauseStream(const AAudioHandleInfo& streamHandleInfo) = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 75 | * Stop the flow of data after data currently in the buffer has played. |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 76 | */ |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 77 | virtual aaudio_result_t stopStream(const AAudioHandleInfo& streamHandleInfo) = 0; |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 80 | * Discard any data held by the underlying HAL or Service. |
| 81 | */ |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 82 | virtual aaudio_result_t flushStream(const AAudioHandleInfo& streamHandleInfo) = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Manage the specified thread as a low latency audio thread. |
| 86 | */ |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 87 | virtual aaudio_result_t registerAudioThread(const AAudioHandleInfo& streamHandleInfo, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 88 | pid_t clientThreadId, |
| 89 | int64_t periodNanoseconds) = 0; |
| 90 | |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 91 | virtual aaudio_result_t unregisterAudioThread(const AAudioHandleInfo& streamHandleInfo, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 92 | pid_t clientThreadId) = 0; |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 93 | |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 94 | virtual aaudio_result_t startClient(const AAudioHandleInfo& streamHandleInfo, |
jiabin | d1f1cb6 | 2020-03-24 11:57:57 -0700 | [diff] [blame] | 95 | const android::AudioClient& client, |
| 96 | const audio_attributes_t *attr, |
| 97 | audio_port_handle_t *clientHandle) = 0; |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 98 | |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 99 | virtual aaudio_result_t stopClient(const AAudioHandleInfo& streamHandleInfo, |
Eric Laurent | a54f128 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 100 | audio_port_handle_t clientHandle) = 0; |
jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Exit the standby mode. |
| 104 | * |
| 105 | * @param streamHandle the stream handle |
| 106 | * @param parcelable contains new data queue information |
| 107 | * @return the result of the execution |
| 108 | */ |
jiabin | 5f78781 | 2023-03-02 20:42:43 +0000 | [diff] [blame] | 109 | virtual aaudio_result_t exitStandby(const AAudioHandleInfo& streamHandleInfo, |
jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 110 | AudioEndpointParcelable &parcelable) = 0; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | } /* namespace aaudio */ |
| 114 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 115 | #endif //ANDROID_AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H |