blob: bec439339377cbd77228f4610ab62ca69ba059c3 [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
Phil Burk5ed503c2017-02-01 09:38:15 -080026#include "binding/AAudioStreamConfiguration.h"
27
Phil Burk5ed503c2017-02-01 09:38:15 -080028using namespace aaudio;
29
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070030using android::media::audio::common::AudioFormat;
Phil Burk5ed503c2017-02-01 09:38:15 -080031
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070032AAudioStreamConfiguration::AAudioStreamConfiguration(const StreamParameters& parcelable) {
jiabina9094092021-06-28 20:36:45 +000033 setChannelMask(parcelable.channelMask);
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070034 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 Trivi656bfdc2021-09-20 18:42:37 -070046
47 static_assert(sizeof(aaudio_spatialization_behavior_t) ==
48 sizeof(parcelable.spatializationBehavior));
49 setSpatializationBehavior(parcelable.spatializationBehavior);
50 setIsContentSpatialized(parcelable.isContentSpatialized);
51
52
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070053 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 Burk5ed503c2017-02-01 09:38:15 -080062}
63
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070064AAudioStreamConfiguration&
65AAudioStreamConfiguration::operator=(const StreamParameters& parcelable) {
66 this->~AAudioStreamConfiguration();
67 new (this) AAudioStreamConfiguration(parcelable);
68 return *this;
69}
Phil Burk0127c1b2018-03-29 13:48:06 -070070
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070071StreamParameters AAudioStreamConfiguration::parcelable() const {
72 StreamParameters result;
jiabina9094092021-06-28 20:36:45 +000073 result.channelMask = getChannelMask();
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070074 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 Burk15f7cab2017-08-04 09:13:31 -070095}