• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <binding/AAudioBinderAdapter.h>
18 #include <media/AidlConversionUtil.h>
19 #include <utility/AAudioUtilities.h>
20 
21 namespace aaudio {
22 
23 using android::aidl_utils::statusTFromBinderStatus;
24 using android::binder::Status;
25 
AAudioBinderAdapter(IAAudioService * delegate)26 AAudioBinderAdapter::AAudioBinderAdapter(IAAudioService* delegate)
27         : mDelegate(delegate) {}
28 
registerClient(const android::sp<IAAudioClient> & client)29 void AAudioBinderAdapter::registerClient(const android::sp<IAAudioClient>& client) {
30     mDelegate->registerClient(client);
31 }
32 
openStream(const AAudioStreamRequest & request,AAudioStreamConfiguration & config)33 aaudio_handle_t AAudioBinderAdapter::openStream(const AAudioStreamRequest& request,
34                                                 AAudioStreamConfiguration& config) {
35     aaudio_handle_t result;
36     StreamParameters params;
37     Status status = mDelegate->openStream(request.parcelable(),
38                                           &params,
39                                           &result);
40     if (!status.isOk()) {
41         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
42     }
43     config = params;
44     return result;
45 }
46 
closeStream(aaudio_handle_t streamHandle)47 aaudio_result_t AAudioBinderAdapter::closeStream(aaudio_handle_t streamHandle) {
48     aaudio_result_t result;
49     Status status = mDelegate->closeStream(streamHandle, &result);
50     if (!status.isOk()) {
51         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
52     }
53     return result;
54 }
55 
getStreamDescription(aaudio_handle_t streamHandle,AudioEndpointParcelable & endpointOut)56 aaudio_result_t AAudioBinderAdapter::getStreamDescription(aaudio_handle_t streamHandle,
57                                                           AudioEndpointParcelable& endpointOut) {
58     aaudio_result_t result;
59     Endpoint endpoint;
60     Status status = mDelegate->getStreamDescription(streamHandle,
61                                                     &endpoint,
62                                                     &result);
63     if (!status.isOk()) {
64         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
65     }
66     endpointOut = std::move(endpoint);
67     return result;
68 }
69 
startStream(aaudio_handle_t streamHandle)70 aaudio_result_t AAudioBinderAdapter::startStream(aaudio_handle_t streamHandle) {
71     aaudio_result_t result;
72     Status status = mDelegate->startStream(streamHandle, &result);
73     if (!status.isOk()) {
74         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
75     }
76     return result;
77 }
78 
pauseStream(aaudio_handle_t streamHandle)79 aaudio_result_t AAudioBinderAdapter::pauseStream(aaudio_handle_t streamHandle) {
80     aaudio_result_t result;
81     Status status = mDelegate->pauseStream(streamHandle, &result);
82     if (!status.isOk()) {
83         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
84     }
85     return result;
86 }
87 
stopStream(aaudio_handle_t streamHandle)88 aaudio_result_t AAudioBinderAdapter::stopStream(aaudio_handle_t streamHandle) {
89     aaudio_result_t result;
90     Status status = mDelegate->stopStream(streamHandle, &result);
91     if (!status.isOk()) {
92         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
93     }
94     return result;
95 }
96 
flushStream(aaudio_handle_t streamHandle)97 aaudio_result_t AAudioBinderAdapter::flushStream(aaudio_handle_t streamHandle) {
98     aaudio_result_t result;
99     Status status = mDelegate->flushStream(streamHandle, &result);
100     if (!status.isOk()) {
101         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
102     }
103     return result;
104 }
105 
registerAudioThread(aaudio_handle_t streamHandle,pid_t clientThreadId,int64_t periodNanoseconds)106 aaudio_result_t AAudioBinderAdapter::registerAudioThread(aaudio_handle_t streamHandle,
107                                                          pid_t clientThreadId,
108                                                          int64_t periodNanoseconds) {
109     aaudio_result_t result;
110     Status status = mDelegate->registerAudioThread(streamHandle, clientThreadId, periodNanoseconds, &result);
111     if (!status.isOk()) {
112         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
113     }
114     return result;
115 }
116 
unregisterAudioThread(aaudio_handle_t streamHandle,pid_t clientThreadId)117 aaudio_result_t AAudioBinderAdapter::unregisterAudioThread(aaudio_handle_t streamHandle,
118                                                            pid_t clientThreadId) {
119     aaudio_result_t result;
120     Status status = mDelegate->unregisterAudioThread(streamHandle, clientThreadId, &result);
121     if (!status.isOk()) {
122         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
123     }
124     return result;
125 }
126 
exitStandby(aaudio_handle_t streamHandle,AudioEndpointParcelable & endpointOut)127 aaudio_result_t AAudioBinderAdapter::exitStandby(aaudio_handle_t streamHandle,
128                                                  AudioEndpointParcelable &endpointOut) {
129     aaudio_result_t result;
130     Endpoint endpoint;
131     Status status = mDelegate->exitStandby(streamHandle, &endpoint, &result);
132     if (!status.isOk()) {
133         result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
134     }
135     endpointOut = std::move(endpoint);
136     return result;
137 }
138 
139 }  // namespace aaudio
140