| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1 | /* | 
 | 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 Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AAudioStreamConfiguration" | 
 | 18 | //#define LOG_NDEBUG 0 | 
 | 19 | #include <utils/Log.h> | 
 | 20 |  | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 21 | #include <stdint.h> | 
 | 22 |  | 
 | 23 | #include <sys/mman.h> | 
| Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 24 | #include <aaudio/AAudio.h> | 
 | 25 |  | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 26 | #include <binder/Parcel.h> | 
 | 27 | #include <binder/Parcelable.h> | 
 | 28 |  | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 29 | #include "binding/AAudioStreamConfiguration.h" | 
 | 30 |  | 
 | 31 | using android::NO_ERROR; | 
 | 32 | using android::status_t; | 
 | 33 | using android::Parcel; | 
 | 34 | using android::Parcelable; | 
 | 35 |  | 
 | 36 | using namespace aaudio; | 
 | 37 |  | 
 | 38 | AAudioStreamConfiguration::AAudioStreamConfiguration() {} | 
 | 39 | AAudioStreamConfiguration::~AAudioStreamConfiguration() {} | 
 | 40 |  | 
 | 41 | status_t AAudioStreamConfiguration::writeToParcel(Parcel* parcel) const { | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 42 |     status_t status; | 
| Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 43 |  | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 44 |     status = parcel->writeInt32(getDeviceId()); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 45 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 46 |     status = parcel->writeInt32(getSampleRate()); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 47 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 48 |     status = parcel->writeInt32(getSamplesPerFrame()); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 49 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 50 |     status = parcel->writeInt32((int32_t) getSharingMode()); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 51 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 52 |     status = parcel->writeInt32((int32_t) getFormat()); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 53 |     if (status != NO_ERROR) goto error; | 
| Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 54 |  | 
| Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 55 |     status = parcel->writeInt32((int32_t) getDirection()); | 
 | 56 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 57 |     status = parcel->writeInt32(getBufferCapacity()); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 58 |     if (status != NO_ERROR) goto error; | 
| Phil Burk | d4ccc62 | 2017-12-20 15:32:44 -0800 | [diff] [blame] | 59 |     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 Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 65 |     status = parcel->writeInt32((int32_t) getAllowedCapturePolicy()); | 
 | 66 |     if (status != NO_ERROR) goto error; | 
| Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 67 |     status = parcel->writeInt32(getSessionId()); | 
 | 68 |     if (status != NO_ERROR) goto error; | 
| Eric Laurent | d17c850 | 2019-10-24 15:58:35 -0700 | [diff] [blame] | 69 |     status = parcel->writeInt32(isPrivacySensitive() ? 1 : 0); | 
 | 70 |     if (status != NO_ERROR) goto error; | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 71 |     return NO_ERROR; | 
 | 72 | error: | 
| Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 73 |     ALOGE("%s(): write failed = %d", __func__, status); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 74 |     return status; | 
| Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 75 | } | 
 | 76 |  | 
 | 77 | status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) { | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 78 |     int32_t value; | 
 | 79 |     status_t status = parcel->readInt32(&value); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 80 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 81 |     setDeviceId(value); | 
 | 82 |     status = parcel->readInt32(&value); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 83 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 84 |     setSampleRate(value); | 
 | 85 |     status = parcel->readInt32(&value); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 86 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 87 |     setSamplesPerFrame(value); | 
 | 88 |     status = parcel->readInt32(&value); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 89 |     if (status != NO_ERROR) goto error; | 
| Phil Burk | d4ccc62 | 2017-12-20 15:32:44 -0800 | [diff] [blame] | 90 |     setSharingMode((aaudio_sharing_mode_t) value); | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 91 |     status = parcel->readInt32(&value); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 92 |     if (status != NO_ERROR) goto error; | 
| Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 93 |     setFormat((audio_format_t) value); | 
 | 94 |  | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 95 |     status = parcel->readInt32(&value); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 96 |     if (status != NO_ERROR) goto error; | 
| Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 97 |     setDirection((aaudio_direction_t) value); | 
 | 98 |     status = parcel->readInt32(&value); | 
 | 99 |     if (status != NO_ERROR) goto error; | 
| jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 100 |     setBufferCapacity(value); | 
| Phil Burk | d4ccc62 | 2017-12-20 15:32:44 -0800 | [diff] [blame] | 101 |     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 Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 110 |     status = parcel->readInt32(&value); | 
 | 111 |     if (status != NO_ERROR) goto error; | 
| Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 112 |     setAllowedCapturePolicy((aaudio_allowed_capture_policy_t) value); | 
 | 113 |     status = parcel->readInt32(&value); | 
 | 114 |     if (status != NO_ERROR) goto error; | 
| Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 115 |     setSessionId(value); | 
| Eric Laurent | d17c850 | 2019-10-24 15:58:35 -0700 | [diff] [blame] | 116 |     status = parcel->readInt32(&value); | 
 | 117 |     if (status != NO_ERROR) goto error; | 
 | 118 |     setPrivacySensitive(value == 1); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 119 |     return NO_ERROR; | 
 | 120 | error: | 
| Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 121 |     ALOGE("%s(): read failed = %d", __func__, status); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 122 |     return status; | 
| Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 123 | } |