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; |
| 39 | status = parcel->writeInt32(mDeviceId); |
| 40 | if (status != NO_ERROR) goto error; |
| 41 | status = parcel->writeInt32(mSampleRate); |
| 42 | if (status != NO_ERROR) goto error; |
| 43 | status = parcel->writeInt32(mSamplesPerFrame); |
| 44 | if (status != NO_ERROR) goto error; |
| 45 | status = parcel->writeInt32((int32_t) mSharingMode); |
| 46 | ALOGD("AAudioStreamConfiguration.writeToParcel(): mSharingMode = %d", mSharingMode); |
| 47 | if (status != NO_ERROR) goto error; |
| 48 | status = parcel->writeInt32((int32_t) mAudioFormat); |
| 49 | if (status != NO_ERROR) goto error; |
| 50 | status = parcel->writeInt32(mBufferCapacity); |
| 51 | if (status != NO_ERROR) goto error; |
| 52 | return NO_ERROR; |
| 53 | error: |
| 54 | ALOGE("AAudioStreamConfiguration.writeToParcel(): write failed = %d", status); |
| 55 | return status; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) { |
| 59 | int32_t temp; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 60 | status_t status = parcel->readInt32(&mDeviceId); |
| 61 | if (status != NO_ERROR) goto error; |
| 62 | status = parcel->readInt32(&mSampleRate); |
| 63 | if (status != NO_ERROR) goto error; |
| 64 | status = parcel->readInt32(&mSamplesPerFrame); |
| 65 | if (status != NO_ERROR) goto error; |
| 66 | status = parcel->readInt32(&temp); |
| 67 | if (status != NO_ERROR) goto error; |
| 68 | mSharingMode = (aaudio_sharing_mode_t) temp; |
| 69 | ALOGD("AAudioStreamConfiguration.readFromParcel(): mSharingMode = %d", mSharingMode); |
| 70 | status = parcel->readInt32(&temp); |
| 71 | if (status != NO_ERROR) goto error; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 72 | mAudioFormat = (aaudio_audio_format_t) temp; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 73 | status = parcel->readInt32(&mBufferCapacity); |
| 74 | if (status != NO_ERROR) goto error; |
| 75 | return NO_ERROR; |
| 76 | error: |
| 77 | ALOGE("AAudioStreamConfiguration.readFromParcel(): read failed = %d", status); |
| 78 | return status; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 81 | aaudio_result_t AAudioStreamConfiguration::validate() const { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 82 | // Validate results of the open. |
| 83 | if (mSampleRate < 0 || mSampleRate >= 8 * 48000) { // TODO review limits |
| 84 | ALOGE("AAudioStreamConfiguration.validate(): invalid sampleRate = %d", mSampleRate); |
| 85 | return AAUDIO_ERROR_INTERNAL; |
| 86 | } |
| 87 | |
| 88 | if (mSamplesPerFrame < 1 || mSamplesPerFrame >= 32) { // TODO review limits |
| 89 | ALOGE("AAudioStreamConfiguration.validate() invalid samplesPerFrame = %d", mSamplesPerFrame); |
| 90 | return AAUDIO_ERROR_INTERNAL; |
| 91 | } |
| 92 | |
| 93 | switch (mAudioFormat) { |
| 94 | case AAUDIO_FORMAT_PCM_I16: |
| 95 | case AAUDIO_FORMAT_PCM_FLOAT: |
| 96 | case AAUDIO_FORMAT_PCM_I8_24: |
| 97 | case AAUDIO_FORMAT_PCM_I32: |
| 98 | break; |
| 99 | default: |
| 100 | ALOGE("AAudioStreamConfiguration.validate() invalid audioFormat = %d", mAudioFormat); |
| 101 | return AAUDIO_ERROR_INTERNAL; |
| 102 | } |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 103 | |
| 104 | if (mBufferCapacity < 0) { |
| 105 | ALOGE("AAudioStreamConfiguration.validate() invalid mBufferCapacity = %d", mBufferCapacity); |
| 106 | return AAUDIO_ERROR_INTERNAL; |
| 107 | } |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 108 | return AAUDIO_OK; |
| 109 | } |
| 110 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 111 | void AAudioStreamConfiguration::dump() const { |
| 112 | ALOGD("AAudioStreamConfiguration mDeviceId = %d", mDeviceId); |
| 113 | ALOGD("AAudioStreamConfiguration mSampleRate = %d", mSampleRate); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 114 | ALOGD("AAudioStreamConfiguration mSamplesPerFrame = %d", mSamplesPerFrame); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 115 | ALOGD("AAudioStreamConfiguration mSharingMode = %d", (int)mSharingMode); |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 116 | ALOGD("AAudioStreamConfiguration mAudioFormat = %d", (int)mAudioFormat); |
| 117 | ALOGD("AAudioStreamConfiguration mBufferCapacity = %d", mBufferCapacity); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 118 | } |