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 | |
| 17 | #include <stdint.h> |
| 18 | |
| 19 | #include <sys/mman.h> |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 20 | #include <aaudio/AAudio.h> |
| 21 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 22 | #include <binder/Parcel.h> |
| 23 | #include <binder/Parcelable.h> |
| 24 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 25 | #include "binding/AAudioStreamConfiguration.h" |
| 26 | |
| 27 | using android::NO_ERROR; |
| 28 | using android::status_t; |
| 29 | using android::Parcel; |
| 30 | using android::Parcelable; |
| 31 | |
| 32 | using namespace aaudio; |
| 33 | |
| 34 | AAudioStreamConfiguration::AAudioStreamConfiguration() {} |
| 35 | AAudioStreamConfiguration::~AAudioStreamConfiguration() {} |
| 36 | |
| 37 | status_t AAudioStreamConfiguration::writeToParcel(Parcel* parcel) const { |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 38 | status_t status; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 39 | status = parcel->writeInt32(getDeviceId()); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 40 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 41 | status = parcel->writeInt32(getSampleRate()); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 42 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 43 | status = parcel->writeInt32(getSamplesPerFrame()); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 44 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 45 | status = parcel->writeInt32((int32_t) getSharingMode()); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 46 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 47 | status = parcel->writeInt32((int32_t) getFormat()); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 48 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 49 | status = parcel->writeInt32(getBufferCapacity()); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 50 | if (status != NO_ERROR) goto error; |
| 51 | return NO_ERROR; |
| 52 | error: |
| 53 | ALOGE("AAudioStreamConfiguration.writeToParcel(): write failed = %d", status); |
| 54 | return status; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) { |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 58 | int32_t value; |
| 59 | status_t status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 60 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 61 | setDeviceId(value); |
| 62 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 63 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 64 | setSampleRate(value); |
| 65 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 66 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 67 | setSamplesPerFrame(value); |
| 68 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 69 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 70 | setSharingMode(value); |
| 71 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 72 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 73 | setFormat(value); |
| 74 | status = parcel->readInt32(&value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 75 | if (status != NO_ERROR) goto error; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 76 | setBufferCapacity(value); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 77 | return NO_ERROR; |
| 78 | error: |
| 79 | ALOGE("AAudioStreamConfiguration.readFromParcel(): read failed = %d", status); |
| 80 | return status; |
jiabin | 901f65d | 2017-07-12 17:56:35 -0700 | [diff] [blame] | 81 | } |