2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "CAudioIODef.h"
23 using namespace tizen_media_audio;
29 CAudioInfo::CAudioInfo()
30 : mSampleRate(MAX_SYSTEM_SAMPLERATE), mChannel(CHANNEL_MONO),
31 mSampleType(SAMPLE_TYPE_U8), mAudioType(AUDIO_IN_TYPE_MEDIA),
35 CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex) throw (CAudioError)
36 : mSampleRate(sampleRate), mChannel(channel), mSampleType(sampleType), mAudioType(audioType), mAudioIndex(audioIndex) {
37 // Check to invalid AudioInfo
38 if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE || sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE) {
39 THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "The sampleRate is invalid [sampleRate:%d]", sampleRate);
42 if (channel < CAudioInfo::CHANNEL_MONO || channel >= CAudioInfo::CHANNEL_MAX) {
43 THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "The channel is invalid [channel:%d]", channel);
46 if (sampleType < CAudioInfo::SAMPLE_TYPE_U8 || sampleType >= CAudioInfo::SAMPLE_TYPE_MAX) {
47 THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "The sampleType is invalid [sampleType:%d]", sampleType);
50 if (audioType < CAudioInfo::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::AUDIO_TYPE_MAX) {
51 THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "The audioType is invalid [audioType:%d]", audioType);
55 unsigned int CAudioInfo::getSampleRate() {
59 CAudioInfo::EChannel CAudioInfo::getChannel() {
63 CAudioInfo::ESampleType CAudioInfo::getSampleType() {
67 CAudioInfo::EAudioType CAudioInfo::getAudioType() {
71 void CAudioInfo::setAudioType(CAudioInfo::EAudioType AudioType) {
72 mAudioType = AudioType;
76 int CAudioInfo::getAudioIndex() {
80 void CAudioInfo::setAudioIndex(int AudioIndex) {
81 mAudioIndex = AudioIndex;
85 void CAudioInfo::convertAudioType2StreamType (CAudioInfo::EAudioType audioType, char **streamType)
87 if (audioType < CAudioInfo::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::AUDIO_TYPE_MAX) {
88 THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_NOT_SUPPORTED_TYPE, "The audioType is not supported [audioType:%d]", audioType);
90 *streamType = (char *)StreamTypeTable[audioType];
94 void CAudioInfo::convertInputStreamType2AudioType (char *streamType, CAudioInfo::EAudioType *audioType)
97 for (i = CAudioInfo::AUDIO_IN_TYPE_MEDIA ; i < CAudioInfo::AUDIO_OUT_TYPE_MEDIA ; i++) {
98 if (!strcmp((char *)StreamTypeTable[i], streamType)) {
102 if (i >= CAudioInfo::AUDIO_OUT_TYPE_MEDIA) {
103 THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_NOT_SUPPORTED_TYPE, "The streamType is not supported [streamType:%s]", streamType);
105 *audioType = (CAudioInfo::EAudioType)i;
109 void CAudioInfo::convertOutputStreamType2AudioType (char *streamType, CAudioInfo::EAudioType *audioType)
112 for (i = CAudioInfo::AUDIO_OUT_TYPE_MEDIA ; i < CAudioInfo::AUDIO_TYPE_MAX ; i++) {
113 if (!strcmp((char *)StreamTypeTable[i], streamType)) {
117 if (i >= CAudioInfo::AUDIO_TYPE_MAX) {
118 THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_NOT_SUPPORTED_TYPE, "The streamType is not supported [streamType:%s]", streamType);
120 *audioType = (CAudioInfo::EAudioType)i;