blob: 2d501efaeb883b5a419d9aaf97bcd468191c6573 [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) {
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 Burk5ed503c2017-02-01 09:38:15 -080055}
56
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070057AAudioStreamConfiguration&
58AAudioStreamConfiguration::operator=(const StreamParameters& parcelable) {
59 this->~AAudioStreamConfiguration();
60 new (this) AAudioStreamConfiguration(parcelable);
61 return *this;
62}
Phil Burk0127c1b2018-03-29 13:48:06 -070063
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070064StreamParameters 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 Burk15f7cab2017-08-04 09:13:31 -070088}