blob: 3d1bc9b7a95f5f697a7e429fafb235fcbb2fe2a8 [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
Phil Burk0127c1b2018-03-29 13:48:06 -070017#define LOG_TAG "AAudioStreamConfiguration"
18//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
Phil Burk5ed503c2017-02-01 09:38:15 -080021#include <stdint.h>
22
23#include <sys/mman.h>
Phil Burka4eb0d82017-04-12 15:44:06 -070024#include <aaudio/AAudio.h>
25
Phil Burk5ed503c2017-02-01 09:38:15 -080026#include <binder/Parcel.h>
27#include <binder/Parcelable.h>
28
Phil Burk5ed503c2017-02-01 09:38:15 -080029#include "binding/AAudioStreamConfiguration.h"
30
31using android::NO_ERROR;
32using android::status_t;
33using android::Parcel;
34using android::Parcelable;
35
36using namespace aaudio;
37
38AAudioStreamConfiguration::AAudioStreamConfiguration() {}
39AAudioStreamConfiguration::~AAudioStreamConfiguration() {}
40
41status_t AAudioStreamConfiguration::writeToParcel(Parcel* parcel) const {
Phil Burkc0c70e32017-02-09 13:18:38 -080042 status_t status;
Phil Burk0127c1b2018-03-29 13:48:06 -070043
jiabin901f65d2017-07-12 17:56:35 -070044 status = parcel->writeInt32(getDeviceId());
Phil Burkc0c70e32017-02-09 13:18:38 -080045 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070046 status = parcel->writeInt32(getSampleRate());
Phil Burkc0c70e32017-02-09 13:18:38 -080047 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070048 status = parcel->writeInt32(getSamplesPerFrame());
Phil Burkc0c70e32017-02-09 13:18:38 -080049 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070050 status = parcel->writeInt32((int32_t) getSharingMode());
Phil Burkc0c70e32017-02-09 13:18:38 -080051 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070052 status = parcel->writeInt32((int32_t) getFormat());
Phil Burkc0c70e32017-02-09 13:18:38 -080053 if (status != NO_ERROR) goto error;
Phil Burk0127c1b2018-03-29 13:48:06 -070054
Phil Burk15f7cab2017-08-04 09:13:31 -070055 status = parcel->writeInt32((int32_t) getDirection());
56 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070057 status = parcel->writeInt32(getBufferCapacity());
Phil Burkc0c70e32017-02-09 13:18:38 -080058 if (status != NO_ERROR) goto error;
Phil Burkd4ccc622017-12-20 15:32:44 -080059 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;
Phil Burk4e1af9f2018-01-03 15:54:35 -080065 status = parcel->writeInt32(getSessionId());
66 if (status != NO_ERROR) goto error;
Phil Burkc0c70e32017-02-09 13:18:38 -080067 return NO_ERROR;
68error:
Phil Burk0127c1b2018-03-29 13:48:06 -070069 ALOGE("%s(): write failed = %d", __func__, status);
Phil Burkc0c70e32017-02-09 13:18:38 -080070 return status;
Phil Burk5ed503c2017-02-01 09:38:15 -080071}
72
73status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
jiabin901f65d2017-07-12 17:56:35 -070074 int32_t value;
75 status_t status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080076 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070077 setDeviceId(value);
78 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080079 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070080 setSampleRate(value);
81 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080082 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070083 setSamplesPerFrame(value);
84 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080085 if (status != NO_ERROR) goto error;
Phil Burkd4ccc622017-12-20 15:32:44 -080086 setSharingMode((aaudio_sharing_mode_t) value);
jiabin901f65d2017-07-12 17:56:35 -070087 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080088 if (status != NO_ERROR) goto error;
Phil Burk0127c1b2018-03-29 13:48:06 -070089 setFormat((audio_format_t) value);
90
jiabin901f65d2017-07-12 17:56:35 -070091 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080092 if (status != NO_ERROR) goto error;
Phil Burk15f7cab2017-08-04 09:13:31 -070093 setDirection((aaudio_direction_t) value);
94 status = parcel->readInt32(&value);
95 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070096 setBufferCapacity(value);
Phil Burkd4ccc622017-12-20 15:32:44 -080097 status = parcel->readInt32(&value);
98 if (status != NO_ERROR) goto error;
99 setUsage((aaudio_usage_t) value);
100 status = parcel->readInt32(&value);
101 if (status != NO_ERROR) goto error;
102 setContentType((aaudio_content_type_t) value);
103 status = parcel->readInt32(&value);
104 if (status != NO_ERROR) goto error;
105 setInputPreset((aaudio_input_preset_t) value);
Phil Burk4e1af9f2018-01-03 15:54:35 -0800106 status = parcel->readInt32(&value);
107 if (status != NO_ERROR) goto error;
108 setSessionId(value);
Phil Burk0127c1b2018-03-29 13:48:06 -0700109
Phil Burkc0c70e32017-02-09 13:18:38 -0800110 return NO_ERROR;
111error:
Phil Burk0127c1b2018-03-29 13:48:06 -0700112 ALOGE("%s(): read failed = %d", __func__, status);
Phil Burkc0c70e32017-02-09 13:18:38 -0800113 return status;
Phil Burk15f7cab2017-08-04 09:13:31 -0700114}