blob: 97672a0a74948599904330cbe05e9a92d5c5ad94 [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
17#include <stdint.h>
18
19#include <sys/mman.h>
Phil Burka4eb0d82017-04-12 15:44:06 -070020#include <aaudio/AAudio.h>
21
Phil Burk5ed503c2017-02-01 09:38:15 -080022#include <binder/Parcel.h>
23#include <binder/Parcelable.h>
24
Phil Burk5ed503c2017-02-01 09:38:15 -080025#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 {
Phil Burkc0c70e32017-02-09 13:18:38 -080038 status_t status;
jiabin901f65d2017-07-12 17:56:35 -070039 status = parcel->writeInt32(getDeviceId());
Phil Burkc0c70e32017-02-09 13:18:38 -080040 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070041 status = parcel->writeInt32(getSampleRate());
Phil Burkc0c70e32017-02-09 13:18:38 -080042 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070043 status = parcel->writeInt32(getSamplesPerFrame());
Phil Burkc0c70e32017-02-09 13:18:38 -080044 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070045 status = parcel->writeInt32((int32_t) getSharingMode());
Phil Burkc0c70e32017-02-09 13:18:38 -080046 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070047 status = parcel->writeInt32((int32_t) getFormat());
Phil Burkc0c70e32017-02-09 13:18:38 -080048 if (status != NO_ERROR) goto error;
Phil Burk15f7cab2017-08-04 09:13:31 -070049 status = parcel->writeInt32((int32_t) getDirection());
50 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070051 status = parcel->writeInt32(getBufferCapacity());
Phil Burkc0c70e32017-02-09 13:18:38 -080052 if (status != NO_ERROR) goto error;
Phil Burkd4ccc622017-12-20 15:32:44 -080053 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;
Phil Burkc0c70e32017-02-09 13:18:38 -080059 return NO_ERROR;
60error:
61 ALOGE("AAudioStreamConfiguration.writeToParcel(): write failed = %d", status);
62 return status;
Phil Burk5ed503c2017-02-01 09:38:15 -080063}
64
65status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
jiabin901f65d2017-07-12 17:56:35 -070066 int32_t value;
67 status_t status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080068 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070069 setDeviceId(value);
70 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080071 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070072 setSampleRate(value);
73 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080074 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070075 setSamplesPerFrame(value);
76 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080077 if (status != NO_ERROR) goto error;
Phil Burkd4ccc622017-12-20 15:32:44 -080078 setSharingMode((aaudio_sharing_mode_t) value);
jiabin901f65d2017-07-12 17:56:35 -070079 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080080 if (status != NO_ERROR) goto error;
Phil Burkd4ccc622017-12-20 15:32:44 -080081 setFormat((aaudio_format_t) value);
jiabin901f65d2017-07-12 17:56:35 -070082 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080083 if (status != NO_ERROR) goto error;
Phil Burk15f7cab2017-08-04 09:13:31 -070084 setDirection((aaudio_direction_t) value);
85 status = parcel->readInt32(&value);
86 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070087 setBufferCapacity(value);
Phil Burkd4ccc622017-12-20 15:32:44 -080088 status = parcel->readInt32(&value);
89 if (status != NO_ERROR) goto error;
90 setUsage((aaudio_usage_t) value);
91 status = parcel->readInt32(&value);
92 if (status != NO_ERROR) goto error;
93 setContentType((aaudio_content_type_t) value);
94 status = parcel->readInt32(&value);
95 if (status != NO_ERROR) goto error;
96 setInputPreset((aaudio_input_preset_t) value);
Phil Burkc0c70e32017-02-09 13:18:38 -080097 return NO_ERROR;
98error:
99 ALOGE("AAudioStreamConfiguration.readFromParcel(): read failed = %d", status);
100 return status;
Phil Burk15f7cab2017-08-04 09:13:31 -0700101}