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