blob: b785f884ad0eba4eca154b8954d9fe3c1d504c0b [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;
Eric Laurentd17c8502019-10-24 15:58:35 -070069 status = parcel->writeInt32(isPrivacySensitive() ? 1 : 0);
70 if (status != NO_ERROR) goto error;
Phil Burkc0c70e32017-02-09 13:18:38 -080071 return NO_ERROR;
72error:
Phil Burk0127c1b2018-03-29 13:48:06 -070073 ALOGE("%s(): write failed = %d", __func__, status);
Phil Burkc0c70e32017-02-09 13:18:38 -080074 return status;
Phil Burk5ed503c2017-02-01 09:38:15 -080075}
76
77status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
jiabin901f65d2017-07-12 17:56:35 -070078 int32_t value;
79 status_t status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080080 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070081 setDeviceId(value);
82 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080083 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070084 setSampleRate(value);
85 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080086 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -070087 setSamplesPerFrame(value);
88 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080089 if (status != NO_ERROR) goto error;
Phil Burkd4ccc622017-12-20 15:32:44 -080090 setSharingMode((aaudio_sharing_mode_t) value);
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 Burk0127c1b2018-03-29 13:48:06 -070093 setFormat((audio_format_t) value);
94
jiabin901f65d2017-07-12 17:56:35 -070095 status = parcel->readInt32(&value);
Phil Burkc0c70e32017-02-09 13:18:38 -080096 if (status != NO_ERROR) goto error;
Phil Burk15f7cab2017-08-04 09:13:31 -070097 setDirection((aaudio_direction_t) value);
98 status = parcel->readInt32(&value);
99 if (status != NO_ERROR) goto error;
jiabin901f65d2017-07-12 17:56:35 -0700100 setBufferCapacity(value);
Phil Burkd4ccc622017-12-20 15:32:44 -0800101 status = parcel->readInt32(&value);
102 if (status != NO_ERROR) goto error;
103 setUsage((aaudio_usage_t) value);
104 status = parcel->readInt32(&value);
105 if (status != NO_ERROR) goto error;
106 setContentType((aaudio_content_type_t) value);
107 status = parcel->readInt32(&value);
108 if (status != NO_ERROR) goto error;
109 setInputPreset((aaudio_input_preset_t) value);
Phil Burk4e1af9f2018-01-03 15:54:35 -0800110 status = parcel->readInt32(&value);
111 if (status != NO_ERROR) goto error;
Kevin Rocard68646ba2019-03-20 13:26:49 -0700112 setAllowedCapturePolicy((aaudio_allowed_capture_policy_t) value);
113 status = parcel->readInt32(&value);
114 if (status != NO_ERROR) goto error;
Phil Burk4e1af9f2018-01-03 15:54:35 -0800115 setSessionId(value);
Eric Laurentd17c8502019-10-24 15:58:35 -0700116 status = parcel->readInt32(&value);
117 if (status != NO_ERROR) goto error;
118 setPrivacySensitive(value == 1);
Phil Burkc0c70e32017-02-09 13:18:38 -0800119 return NO_ERROR;
120error:
Phil Burk0127c1b2018-03-29 13:48:06 -0700121 ALOGE("%s(): read failed = %d", __func__, status);
Phil Burkc0c70e32017-02-09 13:18:38 -0800122 return status;
Phil Burk15f7cab2017-08-04 09:13:31 -0700123}