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) { |
| 33 | setSamplesPerFrame(parcelable.samplesPerFrame); |
| 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); |
| 46 | static_assert(sizeof(aaudio_input_preset_t) == sizeof(parcelable.inputPreset)); |
| 47 | setInputPreset(parcelable.inputPreset); |
| 48 | setBufferCapacity(parcelable.bufferCapacity); |
| 49 | static_assert( |
| 50 | sizeof(aaudio_allowed_capture_policy_t) == sizeof(parcelable.allowedCapturePolicy)); |
| 51 | setAllowedCapturePolicy(parcelable.allowedCapturePolicy); |
| 52 | static_assert(sizeof(aaudio_session_id_t) == sizeof(parcelable.sessionId)); |
| 53 | setSessionId(parcelable.sessionId); |
| 54 | setPrivacySensitive(parcelable.isPrivacySensitive); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 57 | AAudioStreamConfiguration& |
| 58 | AAudioStreamConfiguration::operator=(const StreamParameters& parcelable) { |
| 59 | this->~AAudioStreamConfiguration(); |
| 60 | new (this) AAudioStreamConfiguration(parcelable); |
| 61 | return *this; |
| 62 | } |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 63 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 64 | StreamParameters AAudioStreamConfiguration::parcelable() const { |
| 65 | StreamParameters result; |
| 66 | result.samplesPerFrame = getSamplesPerFrame(); |
| 67 | result.sampleRate = getSampleRate(); |
| 68 | result.deviceId = getDeviceId(); |
| 69 | static_assert(sizeof(aaudio_sharing_mode_t) == sizeof(result.sharingMode)); |
| 70 | result.sharingMode = getSharingMode(); |
| 71 | static_assert(sizeof(audio_format_t) == sizeof(result.audioFormat)); |
| 72 | result.audioFormat = static_cast<AudioFormat>(getFormat()); |
| 73 | static_assert(sizeof(aaudio_direction_t) == sizeof(result.direction)); |
| 74 | result.direction = getDirection(); |
| 75 | static_assert(sizeof(audio_usage_t) == sizeof(result.usage)); |
| 76 | result.usage = getUsage(); |
| 77 | static_assert(sizeof(aaudio_content_type_t) == sizeof(result.contentType)); |
| 78 | result.contentType = getContentType(); |
| 79 | static_assert(sizeof(aaudio_input_preset_t) == sizeof(result.inputPreset)); |
| 80 | result.inputPreset = getInputPreset(); |
| 81 | result.bufferCapacity = getBufferCapacity(); |
| 82 | static_assert(sizeof(aaudio_allowed_capture_policy_t) == sizeof(result.allowedCapturePolicy)); |
| 83 | result.allowedCapturePolicy = getAllowedCapturePolicy(); |
| 84 | static_assert(sizeof(aaudio_session_id_t) == sizeof(result.sessionId)); |
| 85 | result.sessionId = getSessionId(); |
| 86 | result.isPrivacySensitive = isPrivacySensitive(); |
| 87 | return result; |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 88 | } |