blob: b60bac2f034d39b189843afc38894f853869bc21 [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -08001/*
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 Burk0127c1b2018-03-29 13:48:06 -070017#define LOG_TAG "AAudioStreamConfiguration"
18//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
Phil Burk5ed503c2017-02-01 09:38:15 -080021#include <stdint.h>
22
23#include <sys/mman.h>
Phil Burka4eb0d82017-04-12 15:44:06 -070024#include <aaudio/AAudio.h>
25
Mikhail Naganovb60bd1b2021-07-15 17:31:43 -070026#include <media/AidlConversion.h>
27
Phil Burk5ed503c2017-02-01 09:38:15 -080028#include "binding/AAudioStreamConfiguration.h"
29
Phil Burk5ed503c2017-02-01 09:38:15 -080030using namespace aaudio;
31
Mikhail Naganov57bd06f2021-08-10 16:41:54 -070032using android::media::audio::common::AudioFormatDescription;
Phil Burk5ed503c2017-02-01 09:38:15 -080033
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070034AAudioStreamConfiguration::AAudioStreamConfiguration(const StreamParameters& parcelable) {
jiabina9094092021-06-28 20:36:45 +000035 setChannelMask(parcelable.channelMask);
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070036 setSampleRate(parcelable.sampleRate);
37 setDeviceId(parcelable.deviceId);
38 static_assert(sizeof(aaudio_sharing_mode_t) == sizeof(parcelable.sharingMode));
39 setSharingMode(parcelable.sharingMode);
Mikhail Naganovb60bd1b2021-07-15 17:31:43 -070040 auto convFormat = android::aidl2legacy_AudioFormatDescription_audio_format_t(
41 parcelable.audioFormat);
42 setFormat(convFormat.ok() ? convFormat.value() : AUDIO_FORMAT_INVALID);
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070043 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);
Jean-Michel Trivi656bfdc2021-09-20 18:42:37 -070049
50 static_assert(sizeof(aaudio_spatialization_behavior_t) ==
51 sizeof(parcelable.spatializationBehavior));
52 setSpatializationBehavior(parcelable.spatializationBehavior);
53 setIsContentSpatialized(parcelable.isContentSpatialized);
54
55
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070056 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);
Phil Burk5ed503c2017-02-01 09:38:15 -080065}
66
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070067AAudioStreamConfiguration&
68AAudioStreamConfiguration::operator=(const StreamParameters& parcelable) {
69 this->~AAudioStreamConfiguration();
70 new (this) AAudioStreamConfiguration(parcelable);
71 return *this;
72}
Phil Burk0127c1b2018-03-29 13:48:06 -070073
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070074StreamParameters AAudioStreamConfiguration::parcelable() const {
75 StreamParameters result;
jiabina9094092021-06-28 20:36:45 +000076 result.channelMask = getChannelMask();
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070077 result.sampleRate = getSampleRate();
78 result.deviceId = getDeviceId();
79 static_assert(sizeof(aaudio_sharing_mode_t) == sizeof(result.sharingMode));
80 result.sharingMode = getSharingMode();
Mikhail Naganovb60bd1b2021-07-15 17:31:43 -070081 auto convAudioFormat = android::legacy2aidl_audio_format_t_AudioFormatDescription(getFormat());
82 if (convAudioFormat.ok()) {
83 result.audioFormat = convAudioFormat.value();
84 } else {
85 result.audioFormat = AudioFormatDescription{};
Mikhail Naganov57bd06f2021-08-10 16:41:54 -070086 result.audioFormat.type =
87 android::media::audio::common::AudioFormatType::SYS_RESERVED_INVALID;
Mikhail Naganovb60bd1b2021-07-15 17:31:43 -070088 }
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070089 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;
Phil Burk15f7cab2017-08-04 09:13:31 -0700104}