blob: 14d1671bfca1e5d86582b624a887027dd7c78f5d [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);
49 static_assert(sizeof(aaudio_input_preset_t) == sizeof(parcelable.inputPreset));
50 setInputPreset(parcelable.inputPreset);
51 setBufferCapacity(parcelable.bufferCapacity);
52 static_assert(
53 sizeof(aaudio_allowed_capture_policy_t) == sizeof(parcelable.allowedCapturePolicy));
54 setAllowedCapturePolicy(parcelable.allowedCapturePolicy);
55 static_assert(sizeof(aaudio_session_id_t) == sizeof(parcelable.sessionId));
56 setSessionId(parcelable.sessionId);
57 setPrivacySensitive(parcelable.isPrivacySensitive);
Phil Burk5ed503c2017-02-01 09:38:15 -080058}
59
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070060AAudioStreamConfiguration&
61AAudioStreamConfiguration::operator=(const StreamParameters& parcelable) {
62 this->~AAudioStreamConfiguration();
63 new (this) AAudioStreamConfiguration(parcelable);
64 return *this;
65}
Phil Burk0127c1b2018-03-29 13:48:06 -070066
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070067StreamParameters AAudioStreamConfiguration::parcelable() const {
68 StreamParameters result;
jiabina9094092021-06-28 20:36:45 +000069 result.channelMask = getChannelMask();
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070070 result.sampleRate = getSampleRate();
71 result.deviceId = getDeviceId();
72 static_assert(sizeof(aaudio_sharing_mode_t) == sizeof(result.sharingMode));
73 result.sharingMode = getSharingMode();
Mikhail Naganovb60bd1b2021-07-15 17:31:43 -070074 auto convAudioFormat = android::legacy2aidl_audio_format_t_AudioFormatDescription(getFormat());
75 if (convAudioFormat.ok()) {
76 result.audioFormat = convAudioFormat.value();
77 } else {
78 result.audioFormat = AudioFormatDescription{};
Mikhail Naganov57bd06f2021-08-10 16:41:54 -070079 result.audioFormat.type =
80 android::media::audio::common::AudioFormatType::SYS_RESERVED_INVALID;
Mikhail Naganovb60bd1b2021-07-15 17:31:43 -070081 }
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070082 static_assert(sizeof(aaudio_direction_t) == sizeof(result.direction));
83 result.direction = getDirection();
84 static_assert(sizeof(audio_usage_t) == sizeof(result.usage));
85 result.usage = getUsage();
86 static_assert(sizeof(aaudio_content_type_t) == sizeof(result.contentType));
87 result.contentType = getContentType();
88 static_assert(sizeof(aaudio_input_preset_t) == sizeof(result.inputPreset));
89 result.inputPreset = getInputPreset();
90 result.bufferCapacity = getBufferCapacity();
91 static_assert(sizeof(aaudio_allowed_capture_policy_t) == sizeof(result.allowedCapturePolicy));
92 result.allowedCapturePolicy = getAllowedCapturePolicy();
93 static_assert(sizeof(aaudio_session_id_t) == sizeof(result.sessionId));
94 result.sessionId = getSessionId();
95 result.isPrivacySensitive = isPrivacySensitive();
96 return result;
Phil Burk15f7cab2017-08-04 09:13:31 -070097}