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; |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 65 | status = parcel->writeInt32(getSessionId()); |
| 66 | if (status != NO_ERROR) goto error; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 67 | return NO_ERROR; |
| 68 | error: |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 69 | ALOGE("%s(): write failed = %d", __func__, status); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 70 | return status; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) { |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 74 | int32_t value; |
| 75 | status_t status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 76 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 77 | setDeviceId(value); |
| 78 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 79 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 80 | setSampleRate(value); |
| 81 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 82 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 83 | setSamplesPerFrame(value); |
| 84 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 85 | if (status != NO_ERROR) goto error; |
Phil Burk | d4ccc62 | 2017-12-20 15:32:44 -0800 | [diff] [blame] | 86 | setSharingMode((aaudio_sharing_mode_t) value); |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 87 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 88 | if (status != NO_ERROR) goto error; |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 89 | setFormat((audio_format_t) value); |
| 90 | |
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 | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 93 | setDirection((aaudio_direction_t) value); |
| 94 | status = parcel->readInt32(&value); |
| 95 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 96 | setBufferCapacity(value); |
Phil Burk | d4ccc62 | 2017-12-20 15:32:44 -0800 | [diff] [blame] | 97 | 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 Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 106 | status = parcel->readInt32(&value); |
| 107 | if (status != NO_ERROR) goto error; |
| 108 | setSessionId(value); |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 109 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 110 | return NO_ERROR; |
| 111 | error: |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 112 | ALOGE("%s(): read failed = %d", __func__, status); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 113 | return status; |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 114 | } |