blob: 153fce3cb5f43d2dc124142cb35dd85e2dfe5c15 [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 Burk39f02dd2017-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;
53 return NO_ERROR;
54error:
55 ALOGE("AAudioStreamConfiguration.writeToParcel(): write failed = %d", status);
56 return status;
Phil Burk5ed503c2017-02-01 09:38:15 -080057}
58
59status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
jiabin901f65d2017-07-12 17:56:35 -070060 int32_t value;
61 status_t status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080062 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070063 setDeviceId(value);
64 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080065 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070066 setSampleRate(value);
67 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 setSamplesPerFrame(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 setSharingMode(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 setFormat(value);
76 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080077 if (status != NO_ERROR) goto error;
Phil Burk39f02dd2017-08-04 09:13:31 -070078 setDirection((aaudio_direction_t) value);
79 status = parcel->readInt32(&value);
80 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070081 setBufferCapacity(value);
Phil Burkc0c70e32017-02-09 13:18:38 -080082 return NO_ERROR;
83error:
84 ALOGE("AAudioStreamConfiguration.readFromParcel(): read failed = %d", status);
85 return status;
Phil Burk39f02dd2017-08-04 09:13:31 -070086}