AAudioStreamConfiguration.cpp revision 4e1af9fc9c1108d4514e92774f750bcd434dbbcc
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#include <stdint.h>
18
19#include <sys/mman.h>
20#include <aaudio/AAudio.h>
21
22#include <binder/Parcel.h>
23#include <binder/Parcelable.h>
24
25#include "binding/AAudioStreamConfiguration.h"
26
27using android::NO_ERROR;
28using android::status_t;
29using android::Parcel;
30using android::Parcelable;
31
32using namespace aaudio;
33
34AAudioStreamConfiguration::AAudioStreamConfiguration() {}
35AAudioStreamConfiguration::~AAudioStreamConfiguration() {}
36
37status_t AAudioStreamConfiguration::writeToParcel(Parcel* parcel) const {
38    status_t status;
39    status = parcel->writeInt32(getDeviceId());
40    if (status != NO_ERROR) goto error;
41    status = parcel->writeInt32(getSampleRate());
42    if (status != NO_ERROR) goto error;
43    status = parcel->writeInt32(getSamplesPerFrame());
44    if (status != NO_ERROR) goto error;
45    status = parcel->writeInt32((int32_t) getSharingMode());
46    if (status != NO_ERROR) goto error;
47    status = parcel->writeInt32((int32_t) getFormat());
48    if (status != NO_ERROR) goto error;
49    status = parcel->writeInt32((int32_t) getDirection());
50    if (status != NO_ERROR) goto error;
51    status = parcel->writeInt32(getBufferCapacity());
52    if (status != NO_ERROR) goto error;
53    status = parcel->writeInt32((int32_t) getUsage());
54    if (status != NO_ERROR) goto error;
55    status = parcel->writeInt32((int32_t) getContentType());
56    if (status != NO_ERROR) goto error;
57    status = parcel->writeInt32((int32_t) getInputPreset());
58    if (status != NO_ERROR) goto error;
59    status = parcel->writeInt32(getSessionId());
60    if (status != NO_ERROR) goto error;
61    return NO_ERROR;
62error:
63    ALOGE("AAudioStreamConfiguration.writeToParcel(): write failed = %d", status);
64    return status;
65}
66
67status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
68    int32_t value;
69    status_t status = parcel->readInt32(&value);
70    if (status != NO_ERROR) goto error;
71    setDeviceId(value);
72    status = parcel->readInt32(&value);
73    if (status != NO_ERROR) goto error;
74    setSampleRate(value);
75    status = parcel->readInt32(&value);
76    if (status != NO_ERROR) goto error;
77    setSamplesPerFrame(value);
78    status = parcel->readInt32(&value);
79    if (status != NO_ERROR) goto error;
80    setSharingMode((aaudio_sharing_mode_t) value);
81    status = parcel->readInt32(&value);
82    if (status != NO_ERROR) goto error;
83    setFormat((aaudio_format_t) value);
84    status = parcel->readInt32(&value);
85    if (status != NO_ERROR) goto error;
86    setDirection((aaudio_direction_t) value);
87    status = parcel->readInt32(&value);
88    if (status != NO_ERROR) goto error;
89    setBufferCapacity(value);
90    status = parcel->readInt32(&value);
91    if (status != NO_ERROR) goto error;
92    setUsage((aaudio_usage_t) value);
93    status = parcel->readInt32(&value);
94    if (status != NO_ERROR) goto error;
95    setContentType((aaudio_content_type_t) value);
96    status = parcel->readInt32(&value);
97    if (status != NO_ERROR) goto error;
98    setInputPreset((aaudio_input_preset_t) value);
99    status = parcel->readInt32(&value);
100    if (status != NO_ERROR) goto error;
101    setSessionId(value);
102    return NO_ERROR;
103error:
104    ALOGE("AAudioStreamConfiguration.readFromParcel(): read failed = %d", status);
105    return status;
106}
107