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 17 #define LOG_TAG "AAudioStreamConfiguration" 18 //#define LOG_NDEBUG 0 19 #include <utils/Log.h> 20 21 #include <stdint.h> 22 23 #include <sys/mman.h> 24 #include <aaudio/AAudio.h> 25 26 #include <media/AidlConversion.h> 27 28 #include "binding/AAudioStreamConfiguration.h" 29 30 using namespace aaudio; 31 32 using android::media::audio::common::AudioFormatDescription; 33 AAudioStreamConfiguration(const StreamParameters & parcelable)34AAudioStreamConfiguration::AAudioStreamConfiguration(const StreamParameters& parcelable) { 35 setChannelMask(parcelable.channelMask); 36 setSampleRate(parcelable.sampleRate); 37 setDeviceId(parcelable.deviceId); 38 static_assert(sizeof(aaudio_sharing_mode_t) == sizeof(parcelable.sharingMode)); 39 setSharingMode(parcelable.sharingMode); 40 auto convFormat = android::aidl2legacy_AudioFormatDescription_audio_format_t( 41 parcelable.audioFormat); 42 setFormat(convFormat.ok() ? convFormat.value() : AUDIO_FORMAT_INVALID); 43 static_assert(sizeof(aaudio_direction_t) == sizeof(parcelable.direction)); 44 setDirection(parcelable.direction); 45 static_assert(sizeof(audio_usage_t) == sizeof(parcelable.usage)); 46 setUsage(parcelable.usage); 47 static_assert(sizeof(aaudio_content_type_t) == sizeof(parcelable.contentType)); 48 setContentType(parcelable.contentType); 49 50 static_assert(sizeof(aaudio_spatialization_behavior_t) == 51 sizeof(parcelable.spatializationBehavior)); 52 setSpatializationBehavior(parcelable.spatializationBehavior); 53 setIsContentSpatialized(parcelable.isContentSpatialized); 54 55 56 static_assert(sizeof(aaudio_input_preset_t) == sizeof(parcelable.inputPreset)); 57 setInputPreset(parcelable.inputPreset); 58 setBufferCapacity(parcelable.bufferCapacity); 59 static_assert( 60 sizeof(aaudio_allowed_capture_policy_t) == sizeof(parcelable.allowedCapturePolicy)); 61 setAllowedCapturePolicy(parcelable.allowedCapturePolicy); 62 static_assert(sizeof(aaudio_session_id_t) == sizeof(parcelable.sessionId)); 63 setSessionId(parcelable.sessionId); 64 setPrivacySensitive(parcelable.isPrivacySensitive); 65 } 66 67 AAudioStreamConfiguration& operator =(const StreamParameters & parcelable)68AAudioStreamConfiguration::operator=(const StreamParameters& parcelable) { 69 this->~AAudioStreamConfiguration(); 70 new (this) AAudioStreamConfiguration(parcelable); 71 return *this; 72 } 73 parcelable() const74StreamParameters AAudioStreamConfiguration::parcelable() const { 75 StreamParameters result; 76 result.channelMask = getChannelMask(); 77 result.sampleRate = getSampleRate(); 78 result.deviceId = getDeviceId(); 79 static_assert(sizeof(aaudio_sharing_mode_t) == sizeof(result.sharingMode)); 80 result.sharingMode = getSharingMode(); 81 auto convAudioFormat = android::legacy2aidl_audio_format_t_AudioFormatDescription(getFormat()); 82 if (convAudioFormat.ok()) { 83 result.audioFormat = convAudioFormat.value(); 84 } else { 85 result.audioFormat = AudioFormatDescription{}; 86 result.audioFormat.type = 87 android::media::audio::common::AudioFormatType::SYS_RESERVED_INVALID; 88 } 89 static_assert(sizeof(aaudio_direction_t) == sizeof(result.direction)); 90 result.direction = getDirection(); 91 static_assert(sizeof(audio_usage_t) == sizeof(result.usage)); 92 result.usage = getUsage(); 93 static_assert(sizeof(aaudio_content_type_t) == sizeof(result.contentType)); 94 result.contentType = getContentType(); 95 static_assert(sizeof(aaudio_input_preset_t) == sizeof(result.inputPreset)); 96 result.inputPreset = getInputPreset(); 97 result.bufferCapacity = getBufferCapacity(); 98 static_assert(sizeof(aaudio_allowed_capture_policy_t) == sizeof(result.allowedCapturePolicy)); 99 result.allowedCapturePolicy = getAllowedCapturePolicy(); 100 static_assert(sizeof(aaudio_session_id_t) == sizeof(result.sessionId)); 101 result.sessionId = getSessionId(); 102 result.isPrivacySensitive = isPrivacySensitive(); 103 return result; 104 } 105