blob: 1cb2bfafd89734682a308a87d0a039af1eb7c93f [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>
20#include <binder/Parcel.h>
21#include <binder/Parcelable.h>
22
23#include <aaudio/AAudioDefinitions.h>
24
25#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 {
38 parcel->writeInt32(mDeviceId);
39 parcel->writeInt32(mSampleRate);
40 parcel->writeInt32(mSamplesPerFrame);
41 parcel->writeInt32((int32_t) mAudioFormat);
42 return NO_ERROR; // TODO check for errors above
43}
44
45status_t AAudioStreamConfiguration::readFromParcel(const Parcel* parcel) {
46 int32_t temp;
47 parcel->readInt32(&mDeviceId);
48 parcel->readInt32(&mSampleRate);
49 parcel->readInt32(&mSamplesPerFrame);
50 parcel->readInt32(&temp);
51 mAudioFormat = (aaudio_audio_format_t) temp;
52 return NO_ERROR; // TODO check for errors above
53}
54
55aaudio_result_t AAudioStreamConfiguration::validate() {
56 // Validate results of the open.
57 if (mSampleRate < 0 || mSampleRate >= 8 * 48000) { // TODO review limits
58 ALOGE("AAudioStreamConfiguration.validate(): invalid sampleRate = %d", mSampleRate);
59 return AAUDIO_ERROR_INTERNAL;
60 }
61
62 if (mSamplesPerFrame < 1 || mSamplesPerFrame >= 32) { // TODO review limits
63 ALOGE("AAudioStreamConfiguration.validate() invalid samplesPerFrame = %d", mSamplesPerFrame);
64 return AAUDIO_ERROR_INTERNAL;
65 }
66
67 switch (mAudioFormat) {
68 case AAUDIO_FORMAT_PCM_I16:
69 case AAUDIO_FORMAT_PCM_FLOAT:
70 case AAUDIO_FORMAT_PCM_I8_24:
71 case AAUDIO_FORMAT_PCM_I32:
72 break;
73 default:
74 ALOGE("AAudioStreamConfiguration.validate() invalid audioFormat = %d", mAudioFormat);
75 return AAUDIO_ERROR_INTERNAL;
76 }
77 return AAUDIO_OK;
78}
79
80void AAudioStreamConfiguration::dump() {
81 ALOGD("AAudioStreamConfiguration mSampleRate = %d -----", mSampleRate);
82 ALOGD("AAudioStreamConfiguration mSamplesPerFrame = %d", mSamplesPerFrame);
83 ALOGD("AAudioStreamConfiguration mAudioFormat = %d", (int)mAudioFormat);
84}