blob: a987fab90a976171fdad5d77635c9483a8fbe1f5 [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;
Kevin Rocard68646ba2019-03-20 13:26:49 -070065 status = parcel->writeInt32((int32_t) getAllowedCapturePolicy());
66 if (status != NO_ERROR) goto error;
Phil Burk4e1af9f2018-01-03 15:54:35 -080067 status = parcel->writeInt32(getSessionId());
68 if (status != NO_ERROR) goto error;
Phil Burkc0c70e32017-02-09 13:18:38 -080069 return NO_ERROR;
70error:
Phil Burk0127c1b2018-03-29 13:48:06 -070071 ALOGE("%s(): write failed = %d", __func__, status);
Phil Burkc0c70e32017-02-09 13:18:38 -080072 return status;
Phil Burk5ed503c2017-02-01 09:38:15 -080073}
74
75status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
jiabin901f65d2017-07-12 17:56:35 -070076 int32_t value;
77 status_t status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080078 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070079 setDeviceId(value);
80 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080081 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070082 setSampleRate(value);
83 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080084 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070085 setSamplesPerFrame(value);
86 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080087 if (status != NO_ERROR) goto error;
Phil Burkd4ccc622017-12-20 15:32:44 -080088 setSharingMode((aaudio_sharing_mode_t) value);
jiabin901f65d2017-07-12 17:56:35 -070089 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080090 if (status != NO_ERROR) goto error;
Phil Burk0127c1b2018-03-29 13:48:06 -070091 setFormat((audio_format_t) value);
92
jiabin901f65d2017-07-12 17:56:35 -070093 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080094 if (status != NO_ERROR) goto error;
Phil Burk15f7cab2017-08-04 09:13:31 -070095 setDirection((aaudio_direction_t) value);
96 status = parcel->readInt32(&value);
97 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070098 setBufferCapacity(value);
Phil Burkd4ccc622017-12-20 15:32:44 -080099 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);
Phil Burk4e1af9f2018-01-03 15:54:35 -0800108 status = parcel->readInt32(&value);
109 if (status != NO_ERROR) goto error;
Kevin Rocard68646ba2019-03-20 13:26:49 -0700110 setAllowedCapturePolicy((aaudio_allowed_capture_policy_t) value);
111 status = parcel->readInt32(&value);
112 if (status != NO_ERROR) goto error;
Phil Burk4e1af9f2018-01-03 15:54:35 -0800113 setSessionId(value);
Phil Burk0127c1b2018-03-29 13:48:06 -0700114
Phil Burkc0c70e32017-02-09 13:18:38 -0800115 return NO_ERROR;
116error:
Phil Burk0127c1b2018-03-29 13:48:06 -0700117 ALOGE("%s(): read failed = %d", __func__, status);
Phil Burkc0c70e32017-02-09 13:18:38 -0800118 return status;
Phil Burk15f7cab2017-08-04 09:13:31 -0700119}