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) :
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:%u]", sampleRate);
47 if (channel < CAudioInfo::EChannel::CHANNEL_MONO || channel >= CAudioInfo::EChannel::CHANNEL_MAX)
48 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The channel is invalid [channel:%u]", to_integral(channel));
50 if (sampleType < CAudioInfo::ESampleType::SAMPLE_TYPE_U8 || sampleType >= CAudioInfo::ESampleType::SAMPLE_TYPE_MAX)
51 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The sampleType is invalid [sampleType:%u]", to_integral(sampleType));
53 if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
54 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The audioType is invalid [audioType:%u]", to_integral(audioType));
57 unsigned int CAudioInfo::getSampleRate() noexcept {
61 CAudioInfo::EChannel CAudioInfo::getChannel() noexcept {
65 CAudioInfo::ESampleType CAudioInfo::getSampleType() noexcept {
69 CAudioInfo::EAudioType CAudioInfo::getAudioType() noexcept {
73 void CAudioInfo::setAudioType(CAudioInfo::EAudioType audioType) noexcept {
74 __mAudioType = audioType;
77 void CAudioInfo::setAudioTypeByInputStreamType(const char* streamType) {
78 __mAudioType = convertInputStreamTypeToAudioType(streamType);
81 void CAudioInfo::setAudioTypeByOutputStreamType(const char* streamType) {
82 __mAudioType = convertOutputStreamTypeToAudioType(streamType);
85 int CAudioInfo::getAudioIndex() noexcept {
89 void CAudioInfo::setAudioIndex(int audioIndex) noexcept {
90 __mAudioIndex = audioIndex;
93 int CAudioInfo::getSampleSize() noexcept {
94 int bytes_in_sample = 0;
96 switch (__mSampleType) {
97 case ESampleType::SAMPLE_TYPE_U8:
100 case ESampleType::SAMPLE_TYPE_S16_LE:
103 case ESampleType::SAMPLE_TYPE_S24_LE:
106 case ESampleType::SAMPLE_TYPE_S24_32_LE:
107 case ESampleType::SAMPLE_TYPE_S32_LE:
111 AUDIO_IO_LOGW("As unrecognized sample type %d, let's assume S16_LE", static_cast<int>(__mSampleType));
116 return bytes_in_sample * static_cast<int>(__mChannel);
119 const char* CAudioInfo::getConvertedStreamType() {
120 if (__mAudioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || __mAudioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
121 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
122 "The audioType is not supported [audioType:%u]", to_integral(__mAudioType));
124 return __STREAM_TYPE_TABLE[(unsigned int)__mAudioType];
127 CAudioInfo::EAudioType CAudioInfo::convertInputStreamTypeToAudioType(const char *streamType) {
128 for (auto i = (unsigned int)CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i++) {
129 if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType))
130 return (CAudioInfo::EAudioType)i;
132 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of input is not supported [streamType:%s]", streamType);
135 CAudioInfo::EAudioType CAudioInfo::convertOutputStreamTypeToAudioType(const char *streamType) {
136 for (auto i = (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_TYPE_MAX ; i++) {
137 if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType))
138 return (CAudioInfo::EAudioType)i;
140 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of output is not supported [streamType:%s]", streamType);