blob: 09eaa4279d1f38fd9b781f6f7403179411e6cb4b [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
17#include <stdint.h>
18
19#include <sys/mman.h>
Phil Burka4eb0d82017-04-12 15:44:06 -070020#include <aaudio/AAudio.h>
21
Phil Burk5ed503c2017-02-01 09:38:15 -080022#include <binder/Parcel.h>
23#include <binder/Parcelable.h>
24
Phil Burk5ed503c2017-02-01 09:38:15 -080025#include "binding/AAudioStreamConfiguration.h"
26
27using android::NO_ERROR;
28using android::status_t;
29using android::Parcel;
30using android::Parcelable;
31
32using namespace aaudio;
33
34AAudioStreamConfiguration::AAudioStreamConfiguration() {}
35AAudioStreamConfiguration::~AAudioStreamConfiguration() {}
36
37status_t AAudioStreamConfiguration::writeToParcel(Parcel* parcel) const {
Phil Burkc0c70e32017-02-09 13:18:38 -080038 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);
Phil Burkc0c70e32017-02-09 13:18:38 -080046 if (status != NO_ERROR) goto error;
47 status = parcel->writeInt32((int32_t) mAudioFormat);
48 if (status != NO_ERROR) goto error;
49 status = parcel->writeInt32(mBufferCapacity);
50 if (status != NO_ERROR) goto error;
51 return NO_ERROR;
52error:
53 ALOGE("AAudioStreamConfiguration.writeToParcel(): write failed = %d", status);
54 return status;
Phil Burk5ed503c2017-02-01 09:38:15 -080055}
56
57status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
58 int32_t temp;
Phil Burkc0c70e32017-02-09 13:18:38 -080059 status_t status = parcel->readInt32(&mDeviceId);
60 if (status != NO_ERROR) goto error;
61 status = parcel->readInt32(&mSampleRate);
62 if (status != NO_ERROR) goto error;
63 status = parcel->readInt32(&mSamplesPerFrame);
64 if (status != NO_ERROR) goto error;
65 status = parcel->readInt32(&temp);
66 if (status != NO_ERROR) goto error;
67 mSharingMode = (aaudio_sharing_mode_t) temp;
Phil Burkc0c70e32017-02-09 13:18:38 -080068 status = parcel->readInt32(&temp);
69 if (status != NO_ERROR) goto error;
Phil Burk5ed503c2017-02-01 09:38:15 -080070 mAudioFormat = (aaudio_audio_format_t) temp;
Phil Burkc0c70e32017-02-09 13:18:38 -080071 status = parcel->readInt32(&mBufferCapacity);
72 if (status != NO_ERROR) goto error;
73 return NO_ERROR;
74error:
75 ALOGE("AAudioStreamConfiguration.readFromParcel(): read failed = %d", status);
76 return status;
Phil Burk5ed503c2017-02-01 09:38:15 -080077}
78
Phil Burkc0c70e32017-02-09 13:18:38 -080079aaudio_result_t AAudioStreamConfiguration::validate() const {
Phil Burk5ed503c2017-02-01 09:38:15 -080080 // Validate results of the open.
81 if (mSampleRate < 0 || mSampleRate >= 8 * 48000) { // TODO review limits
82 ALOGE("AAudioStreamConfiguration.validate(): invalid sampleRate = %d", mSampleRate);
83 return AAUDIO_ERROR_INTERNAL;
84 }
85
86 if (mSamplesPerFrame < 1 || mSamplesPerFrame >= 32) { // TODO review limits
87 ALOGE("AAudioStreamConfiguration.validate() invalid samplesPerFrame = %d", mSamplesPerFrame);
88 return AAUDIO_ERROR_INTERNAL;
89 }
90
91 switch (mAudioFormat) {
92 case AAUDIO_FORMAT_PCM_I16:
93 case AAUDIO_FORMAT_PCM_FLOAT:
Phil Burk5ed503c2017-02-01 09:38:15 -080094 break;
95 default:
96 ALOGE("AAudioStreamConfiguration.validate() invalid audioFormat = %d", mAudioFormat);
97 return AAUDIO_ERROR_INTERNAL;
98 }
Phil Burk3df348f2017-02-08 11:41:55 -080099
100 if (mBufferCapacity < 0) {
101 ALOGE("AAudioStreamConfiguration.validate() invalid mBufferCapacity = %d", mBufferCapacity);
102 return AAUDIO_ERROR_INTERNAL;
103 }
Phil Burk5ed503c2017-02-01 09:38:15 -0800104 return AAUDIO_OK;
105}
106
Phil Burkc0c70e32017-02-09 13:18:38 -0800107void AAudioStreamConfiguration::dump() const {
108 ALOGD("AAudioStreamConfiguration mDeviceId = %d", mDeviceId);
109 ALOGD("AAudioStreamConfiguration mSampleRate = %d", mSampleRate);
Phil Burk5ed503c2017-02-01 09:38:15 -0800110 ALOGD("AAudioStreamConfiguration mSamplesPerFrame = %d", mSamplesPerFrame);
Phil Burkc0c70e32017-02-09 13:18:38 -0800111 ALOGD("AAudioStreamConfiguration mSharingMode = %d", (int)mSharingMode);
Phil Burk3df348f2017-02-08 11:41:55 -0800112 ALOGD("AAudioStreamConfiguration mAudioFormat = %d", (int)mAudioFormat);
113 ALOGD("AAudioStreamConfiguration mBufferCapacity = %d", mBufferCapacity);
Phil Burk5ed503c2017-02-01 09:38:15 -0800114}