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),
31 __mChannel(EChannel::CHANNEL_MONO),
32 __mSampleType(ESampleType::SAMPLE_TYPE_U8),
33 __mAudioType(EAudioType::AUDIO_IN_TYPE_MEDIA),
37 CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex) throw(CAudioError) :
38 __mSampleRate(sampleRate),
40 __mSampleType(sampleType),
41 __mAudioType(audioType),
42 __mAudioIndex(audioIndex) {
43 // Check to invalid AudioInfo
44 if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE || sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE) {
45 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The sampleRate is invalid [sampleRate:%d]", sampleRate);
48 if (channel < CAudioInfo::EChannel::CHANNEL_MONO || channel >= CAudioInfo::EChannel::CHANNEL_MAX) {
49 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The channel is invalid [channel:%d]", channel);
52 if (sampleType < CAudioInfo::ESampleType::SAMPLE_TYPE_U8 || sampleType >= CAudioInfo::ESampleType::SAMPLE_TYPE_MAX) {
53 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The sampleType is invalid [sampleType:%d]", sampleType);
56 if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
57 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The audioType is invalid [audioType:%d]", audioType);
61 unsigned int CAudioInfo::getSampleRate() {
65 CAudioInfo::EChannel CAudioInfo::getChannel() {
69 CAudioInfo::ESampleType CAudioInfo::getSampleType() {
73 CAudioInfo::EAudioType CAudioInfo::getAudioType() {
77 void CAudioInfo::setAudioType(CAudioInfo::EAudioType audioType) {
78 __mAudioType = audioType;
82 int CAudioInfo::getAudioIndex() {
86 void CAudioInfo::setAudioIndex(int audioIndex) {
87 __mAudioIndex = audioIndex;
91 int CAudioInfo::getSampleSize() {
92 int bytes_in_sample = 0;
93 int number_of_channel = 0;
95 switch (__mSampleType) {
96 case ESampleType::SAMPLE_TYPE_U8:
99 case ESampleType::SAMPLE_TYPE_S16_LE:
103 AUDIO_IO_LOGW("As unrecognized sample type %d, let's assume S16_LE", __mSampleType);
108 switch (__mChannel) {
109 case EChannel::CHANNEL_MONO:
110 number_of_channel = 1;
112 case EChannel::CHANNEL_STEREO:
113 number_of_channel = 2;
116 AUDIO_IO_LOGW("As unrecognized channel %d, let's assume STEREO", __mChannel);
117 number_of_channel = 2;
121 return bytes_in_sample * number_of_channel;
124 void CAudioInfo::convertAudioType2StreamType(CAudioInfo::EAudioType audioType, char **streamType) {
125 if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
126 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The audioType is not supported [audioType:%d]", audioType);
128 *streamType = (char *)__STREAM_TYPE_TABLE[(unsigned int)audioType];
132 void CAudioInfo::convertInputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType) {
133 for (unsigned int i = (unsigned int)CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i++) {
134 if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType)) {
135 *audioType = (CAudioInfo::EAudioType)i;
139 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of input is not supported [streamType:%s]", streamType);
143 void CAudioInfo::convertOutputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType) {
144 for (unsigned int i = (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_TYPE_MAX ; i++) {
145 if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType)) {
146 *audioType = (CAudioInfo::EAudioType)i;
150 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of output is not supported [streamType:%s]", streamType);