• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     return NO_ERROR;
70 error:
71     ALOGE("%s(): write failed = %d", __func__, status);
72     return status;
73 }
74 
readFromParcel(const Parcel * parcel)75 status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
76     int32_t value;
77     status_t status = parcel->readInt32(&value);
78     if (status != NO_ERROR) goto error;
79     setDeviceId(value);
80     status = parcel->readInt32(&value);
81     if (status != NO_ERROR) goto error;
82     setSampleRate(value);
83     status = parcel->readInt32(&value);
84     if (status != NO_ERROR) goto error;
85     setSamplesPerFrame(value);
86     status = parcel->readInt32(&value);
87     if (status != NO_ERROR) goto error;
88     setSharingMode((aaudio_sharing_mode_t) value);
89     status = parcel->readInt32(&value);
90     if (status != NO_ERROR) goto error;
91     setFormat((audio_format_t) value);
92 
93     status = parcel->readInt32(&value);
94     if (status != NO_ERROR) goto error;
95     setDirection((aaudio_direction_t) value);
96     status = parcel->readInt32(&value);
97     if (status != NO_ERROR) goto error;
98     setBufferCapacity(value);
99     status = parcel->readInt32(&value);
100     if (status != NO_ERROR) goto error;
101     setUsage((aaudio_usage_t) value);
102     status = parcel->readInt32(&value);
103     if (status != NO_ERROR) goto error;
104     setContentType((aaudio_content_type_t) value);
105     status = parcel->readInt32(&value);
106     if (status != NO_ERROR) goto error;
107     setInputPreset((aaudio_input_preset_t) value);
108     status = parcel->readInt32(&value);
109     if (status != NO_ERROR) goto error;
110     setAllowedCapturePolicy((aaudio_allowed_capture_policy_t) value);
111     status = parcel->readInt32(&value);
112     if (status != NO_ERROR) goto error;
113     setSessionId(value);
114 
115     return NO_ERROR;
116 error:
117     ALOGE("%s(): read failed = %d", __func__, status);
118     return status;
119 }
120