Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AAudioStreamConfiguration" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | |
| 23 | #include <sys/mman.h> |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 24 | #include <aaudio/AAudio.h> |
| 25 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 26 | #include "binding/AAudioStreamConfiguration.h" |
| 27 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 28 | using namespace aaudio; |
| 29 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 30 | using android::media::audio::common::AudioFormat; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 31 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 32 | AAudioStreamConfiguration::AAudioStreamConfiguration(const StreamParameters& parcelable) { |
jiabin | a909409 | 2021-06-28 20:36:45 +0000 | [diff] [blame] | 33 | setChannelMask(parcelable.channelMask); |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 34 | setSampleRate(parcelable.sampleRate); |
| 35 | setDeviceId(parcelable.deviceId); |
| 36 | static_assert(sizeof(aaudio_sharing_mode_t) == sizeof(parcelable.sharingMode)); |
| 37 | setSharingMode(parcelable.sharingMode); |
| 38 | static_assert(sizeof(audio_format_t) == sizeof(parcelable.audioFormat)); |
| 39 | setFormat(static_cast<audio_format_t>(parcelable.audioFormat)); |
| 40 | static_assert(sizeof(aaudio_direction_t) == sizeof(parcelable.direction)); |
| 41 | setDirection(parcelable.direction); |
| 42 | static_assert(sizeof(audio_usage_t) == sizeof(parcelable.usage)); |
| 43 | setUsage(parcelable.usage); |
| 44 | static_assert(sizeof(aaudio_content_type_t) == sizeof(parcelable.contentType)); |
| 45 | setContentType(parcelable.contentType); |
Jean-Michel Trivi | 656bfdc | 2021-09-20 18:42:37 -0700 | [diff] [blame] | 46 | |
| 47 | static_assert(sizeof(aaudio_spatialization_behavior_t) == |
| 48 | sizeof(parcelable.spatializationBehavior)); |
| 49 | setSpatializationBehavior(parcelable.spatializationBehavior); |
| 50 | setIsContentSpatialized(parcelable.isContentSpatialized); |
| 51 | |
| 52 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 53 | static_assert(sizeof(aaudio_input_preset_t) == sizeof(parcelable.inputPreset)); |
| 54 | setInputPreset(parcelable.inputPreset); |
| 55 | setBufferCapacity(parcelable.bufferCapacity); |
| 56 | static_assert( |
| 57 | sizeof(aaudio_allowed_capture_policy_t) == sizeof(parcelable.allowedCapturePolicy)); |
| 58 | setAllowedCapturePolicy(parcelable.allowedCapturePolicy); |
| 59 | static_assert(sizeof(aaudio_session_id_t) == sizeof(parcelable.sessionId)); |
| 60 | setSessionId(parcelable.sessionId); |
| 61 | setPrivacySensitive(parcelable.isPrivacySensitive); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 64 | AAudioStreamConfiguration& |
| 65 | AAudioStreamConfiguration::operator=(const StreamParameters& parcelable) { |
| 66 | this->~AAudioStreamConfiguration(); |
| 67 | new (this) AAudioStreamConfiguration(parcelable); |
| 68 | return *this; |
| 69 | } |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 70 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 71 | StreamParameters AAudioStreamConfiguration::parcelable() const { |
| 72 | StreamParameters result; |
jiabin | a909409 | 2021-06-28 20:36:45 +0000 | [diff] [blame] | 73 | result.channelMask = getChannelMask(); |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 74 | result.sampleRate = getSampleRate(); |
| 75 | result.deviceId = getDeviceId(); |
| 76 | static_assert(sizeof(aaudio_sharing_mode_t) == sizeof(result.sharingMode)); |
| 77 | result.sharingMode = getSharingMode(); |
| 78 | static_assert(sizeof(audio_format_t) == sizeof(result.audioFormat)); |
| 79 | result.audioFormat = static_cast<AudioFormat>(getFormat()); |
| 80 | static_assert(sizeof(aaudio_direction_t) == sizeof(result.direction)); |
| 81 | result.direction = getDirection(); |
| 82 | static_assert(sizeof(audio_usage_t) == sizeof(result.usage)); |
| 83 | result.usage = getUsage(); |
| 84 | static_assert(sizeof(aaudio_content_type_t) == sizeof(result.contentType)); |
| 85 | result.contentType = getContentType(); |
| 86 | static_assert(sizeof(aaudio_input_preset_t) == sizeof(result.inputPreset)); |
| 87 | result.inputPreset = getInputPreset(); |
| 88 | result.bufferCapacity = getBufferCapacity(); |
| 89 | static_assert(sizeof(aaudio_allowed_capture_policy_t) == sizeof(result.allowedCapturePolicy)); |
| 90 | result.allowedCapturePolicy = getAllowedCapturePolicy(); |
| 91 | static_assert(sizeof(aaudio_session_id_t) == sizeof(result.sessionId)); |
| 92 | result.sessionId = getSessionId(); |
| 93 | result.isPrivacySensitive = isPrivacySensitive(); |
| 94 | return result; |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 95 | } |