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 "binding/AAudioStreamConfiguration.h"
27 
28 using namespace aaudio;
29 
30 using android::media::audio::common::AudioFormat;
31 
AAudioStreamConfiguration(const StreamParameters & parcelable)32 AAudioStreamConfiguration::AAudioStreamConfiguration(const StreamParameters& parcelable) {
33     setChannelMask(parcelable.channelMask);
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 
47     static_assert(sizeof(aaudio_spatialization_behavior_t) ==
48             sizeof(parcelable.spatializationBehavior));
49     setSpatializationBehavior(parcelable.spatializationBehavior);
50     setIsContentSpatialized(parcelable.isContentSpatialized);
51 
52 
53     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);
62 }
63 
64 AAudioStreamConfiguration&
operator =(const StreamParameters & parcelable)65 AAudioStreamConfiguration::operator=(const StreamParameters& parcelable) {
66     this->~AAudioStreamConfiguration();
67     new (this) AAudioStreamConfiguration(parcelable);
68     return *this;
69 }
70 
parcelable() const71 StreamParameters AAudioStreamConfiguration::parcelable() const {
72     StreamParameters result;
73     result.channelMask = getChannelMask();
74     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;
95 }
96