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 <binder/Parcel.h>
27 #include <binder/Parcelable.h>
28 
29 #include "binding/AAudioStreamConfiguration.h"
30 
31 using android::NO_ERROR;
32 using android::status_t;
33 using android::Parcel;
34 using android::Parcelable;
35 
36 using namespace aaudio;
37 
AAudioStreamConfiguration()38 AAudioStreamConfiguration::AAudioStreamConfiguration() {}
~AAudioStreamConfiguration()39 AAudioStreamConfiguration::~AAudioStreamConfiguration() {}
40 
writeToParcel(Parcel * parcel) const41 status_t AAudioStreamConfiguration::writeToParcel(Parcel* parcel) const {
42     status_t status;
43 
44     status = parcel->writeInt32(getDeviceId());
45     if (status != NO_ERROR) goto error;
46     status = parcel->writeInt32(getSampleRate());
47     if (status != NO_ERROR) goto error;
48     status = parcel->writeInt32(getSamplesPerFrame());
49     if (status != NO_ERROR) goto error;
50     status = parcel->writeInt32((int32_t) getSharingMode());
51     if (status != NO_ERROR) goto error;
52     status = parcel->writeInt32((int32_t) getFormat());
53     if (status != NO_ERROR) goto error;
54 
55     status = parcel->writeInt32((int32_t) getDirection());
56     if (status != NO_ERROR) goto error;
57     status = parcel->writeInt32(getBufferCapacity());
58     if (status != NO_ERROR) goto error;
59     status = parcel->writeInt32((int32_t) getUsage());
60     if (status != NO_ERROR) goto error;
61     status = parcel->writeInt32((int32_t) getContentType());
62     if (status != NO_ERROR) goto error;
63     status = parcel->writeInt32((int32_t) getInputPreset());
64     if (status != NO_ERROR) goto error;
65     status = parcel->writeInt32((int32_t) getAllowedCapturePolicy());
66     if (status != NO_ERROR) goto error;
67     status = parcel->writeInt32(getSessionId());
68     if (status != NO_ERROR) goto error;
69     status = parcel->writeInt32(isPrivacySensitive() ? 1 : 0);
70     if (status != NO_ERROR) goto error;
71     return NO_ERROR;
72 error:
73     ALOGE("%s(): write failed = %d", __func__, status);
74     return status;
75 }
76 
readFromParcel(const Parcel * parcel)77 status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
78     int32_t value;
79     status_t status = parcel->readInt32(&value);
80     if (status != NO_ERROR) goto error;
81     setDeviceId(value);
82     status = parcel->readInt32(&value);
83     if (status != NO_ERROR) goto error;
84     setSampleRate(value);
85     status = parcel->readInt32(&value);
86     if (status != NO_ERROR) goto error;
87     setSamplesPerFrame(value);
88     status = parcel->readInt32(&value);
89     if (status != NO_ERROR) goto error;
90     setSharingMode((aaudio_sharing_mode_t) value);
91     status = parcel->readInt32(&value);
92     if (status != NO_ERROR) goto error;
93     setFormat((audio_format_t) value);
94 
95     status = parcel->readInt32(&value);
96     if (status != NO_ERROR) goto error;
97     setDirection((aaudio_direction_t) value);
98     status = parcel->readInt32(&value);
99     if (status != NO_ERROR) goto error;
100     setBufferCapacity(value);
101     status = parcel->readInt32(&value);
102     if (status != NO_ERROR) goto error;
103     setUsage((aaudio_usage_t) value);
104     status = parcel->readInt32(&value);
105     if (status != NO_ERROR) goto error;
106     setContentType((aaudio_content_type_t) value);
107     status = parcel->readInt32(&value);
108     if (status != NO_ERROR) goto error;
109     setInputPreset((aaudio_input_preset_t) value);
110     status = parcel->readInt32(&value);
111     if (status != NO_ERROR) goto error;
112     setAllowedCapturePolicy((aaudio_allowed_capture_policy_t) value);
113     status = parcel->readInt32(&value);
114     if (status != NO_ERROR) goto error;
115     setSessionId(value);
116     status = parcel->readInt32(&value);
117     if (status != NO_ERROR) goto error;
118     setPrivacySensitive(value == 1);
119     return NO_ERROR;
120 error:
121     ALOGE("%s(): read failed = %d", __func__, status);
122     return status;
123 }
124