From: Seungbae Shin Date: Fri, 16 Aug 2019 09:05:56 +0000 (+0900) Subject: revise CAudioInfo conversion X-Git-Tag: submit/tizen/20190910.071813^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F91%2F212191%2F5;p=platform%2Fcore%2Fapi%2Faudio-io.git revise CAudioInfo conversion Change-Id: I0116ac94c3444179292f4b668fa35ae4f590b039 --- diff --git a/include/CAudioInfo.h b/include/CAudioInfo.h index 3ccc58f..82ee921 100644 --- a/include/CAudioInfo.h +++ b/include/CAudioInfo.h @@ -127,11 +127,13 @@ namespace tizen_media_audio { void setAudioType(EAudioType audioType) noexcept; int getAudioIndex() noexcept; void setAudioIndex(int audioIndex) noexcept; - void convertAudioType2StreamType(CAudioInfo::EAudioType audioType, char **streamType); - void convertInputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType); - void convertOutputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType); int getSampleSize() noexcept; + /* Setter & Getter Utilities */ + const char* getConvertedStreamType(); + void setAudioTypeByInputStreamType(const char* streamType); + void setAudioTypeByOutputStreamType(const char* streamType); + private: const char *__STREAM_TYPE_TABLE[(unsigned int)EAudioType::AUDIO_TYPE_MAX] = { /* Input Type */ @@ -173,6 +175,9 @@ namespace tizen_media_audio { "network-source-media", /**< AUDIO_OUT_TYPE_MEDIA_NETWORK_SOURCE */ }; + EAudioType convertInputStreamTypeToAudioType(const char *streamType); + EAudioType convertOutputStreamTypeToAudioType(const char *streamType); + unsigned int __mSampleRate; EChannel __mChannel; ESampleType __mSampleType; diff --git a/src/cpp/CAudioIO.cpp b/src/cpp/CAudioIO.cpp index 55d4d87..fbeaf82 100644 --- a/src/cpp/CAudioIO.cpp +++ b/src/cpp/CAudioIO.cpp @@ -340,7 +340,6 @@ void CAudioIO::setStreamInfo(sound_stream_info_h stream_info) { THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE, "it is not permitted while started"); int errorCode = SOUND_MANAGER_ERROR_NONE; - CAudioInfo::EAudioType audioType = CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA; char *type = nullptr; int index = -1; bool avail = false; @@ -353,10 +352,9 @@ void CAudioIO::setStreamInfo(sound_stream_info_h stream_info) { if ((errorCode = sound_manager_get_type_from_stream_information(stream_info, &type)) != SOUND_MANAGER_ERROR_NONE) THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info->stream_type is invalid [ret:%d]", errorCode); if (mDirection == CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN) - getAudioInfo().convertInputStreamType2AudioType(type, &audioType); + getAudioInfo().setAudioTypeByInputStreamType(type); else - getAudioInfo().convertOutputStreamType2AudioType(type, &audioType); - getAudioInfo().setAudioType(audioType); + getAudioInfo().setAudioTypeByOutputStreamType(type); if ((errorCode = sound_manager_get_index_from_stream_information(stream_info, &index)) != SOUND_MANAGER_ERROR_NONE) THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info->index is invalid [ret:%d]", errorCode); diff --git a/src/cpp/CAudioInfo.cpp b/src/cpp/CAudioInfo.cpp index 6f6ca9b..aff4ee0 100644 --- a/src/cpp/CAudioInfo.cpp +++ b/src/cpp/CAudioInfo.cpp @@ -74,6 +74,14 @@ void CAudioInfo::setAudioType(CAudioInfo::EAudioType audioType) noexcept { __mAudioType = audioType; } +void CAudioInfo::setAudioTypeByInputStreamType(const char* streamType) { + __mAudioType = convertInputStreamTypeToAudioType(streamType); +} + +void CAudioInfo::setAudioTypeByOutputStreamType(const char* streamType) { + __mAudioType = convertOutputStreamTypeToAudioType(streamType); +} + int CAudioInfo::getAudioIndex() noexcept { return __mAudioIndex; } @@ -108,30 +116,26 @@ int CAudioInfo::getSampleSize() noexcept { return bytes_in_sample * static_cast(__mChannel); } -void CAudioInfo::convertAudioType2StreamType(CAudioInfo::EAudioType audioType, char **streamType) { - if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) +const char* CAudioInfo::getConvertedStreamType() { + if (__mAudioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || __mAudioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, - "The audioType is not supported [audioType:%u]", to_integral(audioType)); + "The audioType is not supported [audioType:%u]", to_integral(__mAudioType)); - *streamType = (char *)__STREAM_TYPE_TABLE[(unsigned int)audioType]; + return __STREAM_TYPE_TABLE[(unsigned int)__mAudioType]; } -void CAudioInfo::convertInputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType) { +CAudioInfo::EAudioType CAudioInfo::convertInputStreamTypeToAudioType(const char *streamType) { for (auto i = (unsigned int)CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i++) { - if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType)) { - *audioType = (CAudioInfo::EAudioType)i; - return; - } + if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType)) + return (CAudioInfo::EAudioType)i; } THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of input is not supported [streamType:%s]", streamType); } -void CAudioInfo::convertOutputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType) { +CAudioInfo::EAudioType CAudioInfo::convertOutputStreamTypeToAudioType(const char *streamType) { for (auto i = (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_TYPE_MAX ; i++) { - if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType)) { - *audioType = (CAudioInfo::EAudioType)i; - return; - } + if (!strcmp((char *)__STREAM_TYPE_TABLE[i], streamType)) + return (CAudioInfo::EAudioType)i; } THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of output is not supported [streamType:%s]", streamType); } diff --git a/src/cpp/CPulseAudioClient.cpp b/src/cpp/CPulseAudioClient.cpp index 0676cb8..219ac1e 100644 --- a/src/cpp/CPulseAudioClient.cpp +++ b/src/cpp/CPulseAudioClient.cpp @@ -293,10 +293,7 @@ void CPulseAudioClient::initialize() { THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_proplist_new()"); //LCOV_EXCL_LINE // Adds values on proplist for delivery to PULSEAUDIO - char *streamType = nullptr; - CAudioInfo::EAudioType audioType = __mSpec.getAudioInfo().getAudioType(); - __mSpec.getAudioInfo().convertAudioType2StreamType(audioType, &streamType); - pa_proplist_sets(__mpPropList, PA_PROP_MEDIA_ROLE, streamType); + pa_proplist_sets(__mpPropList, PA_PROP_MEDIA_ROLE, __mSpec.getAudioInfo().getConvertedStreamType()); int index = __mSpec.getAudioInfo().getAudioIndex(); if (index >= 0)