#include <type_traits>
#include <string>
+#include <optional>
+#include <tuple>
+
#include <sound_manager.h>
#include <sound_manager_internal.h>
-#include <optional>
namespace tizen_media_audio {
CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex);
virtual ~CAudioInfo() = default;
- /* Setter & Getter */
- unsigned int getSampleRate() const noexcept;
- EChannel getChannel() const noexcept;
- ESampleType getSampleType() const noexcept;
- EAudioType getAudioType() const noexcept;
- int getAudioIndex() const noexcept;
- void setAudioIndex(int audioIndex) noexcept;
+ /* Audio Specification */
+ std::tuple<ESampleType, unsigned int, EChannel> getSpec() const noexcept;
int getSampleSize() const noexcept;
+ /* Stream Properties */
+ void setAudioIndex(int audioIndex) noexcept;
+ void setAudioTypeByInputStreamType(const char* streamType);
+ void setAudioTypeByOutputStreamType(const char* streamType);
+ EAudioType getAudioType() const noexcept;
+ std::pair<const char*, int> getStreamProperties() const;
+
/* Effect */
void setEffectMethod(int method) noexcept;
std::string getEffectMethod() const noexcept;
+
void setEffectMethodWithReference(sound_effect_method_with_reference_e method, int id) noexcept;
std::pair<std::string, int> getEffectMethodWithReference() const noexcept;
- /* Setter & Getter Utilities */
- const char* getConvertedStreamType() const;
- void setAudioTypeByInputStreamType(const char* streamType);
- void setAudioTypeByOutputStreamType(const char* streamType);
+ /* Utilities */
+ size_t msToBytes(size_t milliseconds) const noexcept;
+ size_t bytesToMs(size_t bytes) const noexcept;
private:
const char *__STREAM_TYPE_TABLE[(unsigned int)EAudioType::AUDIO_TYPE_MAX] = {
Name: capi-media-audio-io
Summary: An Audio Input & Audio Output library in Tizen Native API
-Version: 0.5.60
+Version: 0.5.61
Release: 0
Group: Multimedia/API
License: Apache-2.0
__mAudioType(audioType),
__mAudioIndex(audioIndex) {
// Check to invalid AudioInfo
- if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE ||
- sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE)
+ if (sampleRate < MIN_SYSTEM_SAMPLERATE ||
+ sampleRate > MAX_SYSTEM_SAMPLERATE)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"The sampleRate is invalid [sampleRate:%u]", sampleRate);
- if (channel < CAudioInfo::EChannel::CHANNEL_MONO ||
- channel >= CAudioInfo::EChannel::CHANNEL_MAX)
+ if (channel < EChannel::CHANNEL_MONO ||
+ channel >= EChannel::CHANNEL_MAX)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"The channel is invalid [channel:%u]", to_integral(channel));
- if (sampleType < CAudioInfo::ESampleType::SAMPLE_TYPE_U8 ||
- sampleType >= CAudioInfo::ESampleType::SAMPLE_TYPE_MAX)
+ if (sampleType < ESampleType::SAMPLE_TYPE_U8 ||
+ sampleType >= ESampleType::SAMPLE_TYPE_MAX)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"The sampleType is invalid [sampleType:%u]", to_integral(sampleType));
- if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
- audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
+ if (audioType < EAudioType::AUDIO_IN_TYPE_MEDIA ||
+ audioType >= EAudioType::AUDIO_TYPE_MAX)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"The audioType is invalid [audioType:%u]", to_integral(audioType));
}
-unsigned int CAudioInfo::getSampleRate() const noexcept {
- return __mSampleRate;
-}
-
-CAudioInfo::EChannel CAudioInfo::getChannel() const noexcept {
- return __mChannel;
-}
-
-CAudioInfo::ESampleType CAudioInfo::getSampleType() const noexcept {
- return __mSampleType;
+std::tuple<CAudioInfo::ESampleType, unsigned int, CAudioInfo::EChannel> CAudioInfo::getSpec() const noexcept {
+ return { __mSampleType, __mSampleRate, __mChannel };
}
CAudioInfo::EAudioType CAudioInfo::getAudioType() const noexcept {
__mAudioType = convertOutputStreamTypeToAudioType(streamType);
}
-int CAudioInfo::getAudioIndex() const noexcept {
- return __mAudioIndex;
-}
-
void CAudioInfo::setAudioIndex(int audioIndex) noexcept {
__mAudioIndex = audioIndex;
}
return bytes_in_sample * static_cast<int>(__mChannel);
}
+
+size_t CAudioInfo::msToBytes(size_t milliseconds) const noexcept {
+ return milliseconds * __mSampleRate * getSampleSize() / 1000;
+}
+
+size_t CAudioInfo::bytesToMs(size_t bytes) const noexcept {
+ return bytes * 1000 / getSampleSize() / __mSampleRate;
+}
+
void CAudioInfo::setEffectMethod(int method) noexcept {
__mEffectMethod = method;
}
return make_pair(method, __mEffectMethodReferenceDeviceId);
}
-const char* CAudioInfo::getConvertedStreamType() const {
- if (__mAudioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
- __mAudioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
+std::pair<const char*, int> CAudioInfo::getStreamProperties() const {
+ if (__mAudioType < EAudioType::AUDIO_IN_TYPE_MEDIA ||
+ __mAudioType >= EAudioType::AUDIO_TYPE_MAX)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
"The audioType is not supported [audioType:%u]", to_integral(__mAudioType));
- return __STREAM_TYPE_TABLE[(unsigned int)__mAudioType];
+ return std::make_pair(__STREAM_TYPE_TABLE[(unsigned int)__mAudioType], __mAudioIndex);
}
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;
+ for (auto i = (unsigned int)EAudioType::AUDIO_IN_TYPE_MEDIA;
+ i < (unsigned int)EAudioType::AUDIO_OUT_TYPE_MEDIA;
i++) {
if (!strcmp(__STREAM_TYPE_TABLE[i], streamType))
- return (CAudioInfo::EAudioType)i;
+ return (EAudioType)i;
}
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
"The streamType of input is not supported [streamType:%s]", streamType);
}
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;
+ for (auto i = (unsigned int)EAudioType::AUDIO_OUT_TYPE_MEDIA;
+ i < (unsigned int)EAudioType::AUDIO_TYPE_MAX;
i++) {
if (!strcmp(__STREAM_TYPE_TABLE[i], streamType))
- return (CAudioInfo::EAudioType)i;
+ return (EAudioType)i;
}
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
"The streamType of output is not supported [streamType:%s]", streamType);
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioInput"); //LCOV_EXCL_LINE
/* FIXME : return calculated size here to satisfy backward compatibility */
- return (mAudioInfo.getSampleRate() * DEFAULT_PERIOD_SIZE) / 1000 * mAudioInfo.getSampleSize();
+ return mAudioInfo.msToBytes(DEFAULT_PERIOD_SIZE);
}
void CAudioInput::setStreamCallback(SStreamCallback callback) {
"Did not initialize or prepare CAudioOutput"); //LCOV_EXCL_LINE
/* FIXME : return calculated size here to satisfy backward compatibility */
- return (mAudioInfo.getSampleRate() * DEFAULT_PERIOD_SIZE) / 1000 * mAudioInfo.getSampleSize();
+ return mAudioInfo.msToBytes(DEFAULT_PERIOD_SIZE);
}
size_t CAudioOutput::write(const void* buffer, size_t length) {
void CAudioOutput::__dumpStat() noexcept {
AUDIO_IO_LOGD("pClient[%p] : total written %5" PRIu64 " times, %10" PRIu64 " bytes, %7" PRIu64 " ms",
- mpPulseAudioClient, __mTotalWrittenCount, __mTotalWrittenBytes,
- __mTotalWrittenBytes * 1000 / mAudioInfo.getSampleSize() / mAudioInfo.getSampleRate());
+ mpPulseAudioClient, __mTotalWrittenCount, __mTotalWrittenBytes, mAudioInfo.bytesToMs(__mTotalWrittenBytes));
}
void CAudioOutput::__dumpStat(size_t length) noexcept {
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_proplist_new()"); //LCOV_EXCL_LINE
// Adds values on proplist for delivery to PULSEAUDIO
- pa_proplist_sets(__mpPropList, PA_PROP_MEDIA_ROLE, __mSpec.getAudioInfo().getConvertedStreamType());
+ auto [ streamType, streamIndex ] = __mSpec.getAudioInfo().getStreamProperties();
- int index = __mSpec.getAudioInfo().getAudioIndex();
- if (index >= 0)
- pa_proplist_setf(__mpPropList, PA_PROP_MEDIA_PARENT_ID, "%u", (unsigned int) index);
+ pa_proplist_sets(__mpPropList, PA_PROP_MEDIA_ROLE, streamType);
+ if (streamIndex >= 0)
+ pa_proplist_setf(__mpPropList, PA_PROP_MEDIA_PARENT_ID, "%d", streamIndex);
if (__mDirection == EStreamDirection::STREAM_DIRECTION_RECORD) {
/* Noise-suppression effect should be set first. */
}
void CPulseStreamSpec::__adjustSpec() noexcept {
+
+ auto [ sampletype, samplerate, channels ] = __mAudioInfo.getSpec();
+
// Sets a sampleRate
- __mSampleSpec.rate = __mAudioInfo.getSampleRate();
+ __mSampleSpec.rate = samplerate;
// Convert channels for PA
- __mSampleSpec.channels = static_cast<uint8_t>(__mAudioInfo.getChannel());
+ __mSampleSpec.channels = static_cast<uint8_t>(channels);
// Convert format for PA
- switch (__mAudioInfo.getSampleType()) {
+ switch (sampletype) {
case CAudioInfo::ESampleType::SAMPLE_TYPE_U8:
__mSampleSpec.format = PA_SAMPLE_U8;
break;
VALID_POINTER_END
}
+static int __get_samplerate(const CAudioInfo& info) {
+ unsigned int samplerate = 0;
+ std::tie(std::ignore, samplerate, std::ignore) = info.getSpec();
+ return static_cast<int>(samplerate);
+}
+
+static audio_channel_e __get_channels(const CAudioInfo& info) {
+ CAudioInfo::EChannel channels;
+ std::tie(std::ignore, std::ignore, channels) = info.getSpec();
+ return __convert_audio_info_channel_to_channel(channels);
+}
+
+static audio_sample_type_e __get_sampletype(const CAudioInfo& info) {
+ CAudioInfo::ESampleType sampletype;
+ std::tie(sampletype, std::ignore, std::ignore) = info.getSpec();
+ return __convert_audio_info_sample_type_to_sample_type(sampletype);
+}
+
/**
* Implements CAPI functions
*/
"Parameters are NULL input:%p, sample_rate:%p", input, sample_rate);
assert(handle->audioIoHandle);
- *sample_rate = handle->audioIoHandle->getAudioInfo().getSampleRate();
+ *sample_rate = __get_samplerate(handle->audioIoHandle->getAudioInfo());
} catch (const CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
return __convert_audio_io_error(e.getError());
"Parameters are NULL input:%p, channel:%p", input, channel);
assert(handle->audioIoHandle);
- *channel = __convert_audio_info_channel_to_channel(handle->audioIoHandle->getAudioInfo().getChannel());
+ *channel = __get_channels(handle->audioIoHandle->getAudioInfo());
} catch (const CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
return __convert_audio_io_error(e.getError());
"Parameters are NULL input:%p, type:%p", input, type);
assert(handle->audioIoHandle);
- *type = __convert_audio_info_sample_type_to_sample_type(handle->audioIoHandle->getAudioInfo().getSampleType());
+ *type = __get_sampletype(handle->audioIoHandle->getAudioInfo());
} catch (const CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
return __convert_audio_io_error(e.getError());
"Parameters are NULL output:%p, sample_rate:%p", output, sample_rate);
assert(handle->audioIoHandle);
- *sample_rate = handle->audioIoHandle->getAudioInfo().getSampleRate();
+ *sample_rate = __get_samplerate(handle->audioIoHandle->getAudioInfo());
} catch (const CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
return __convert_audio_io_error(e.getError());
"Parameters are NULL output:%p, channel:%p", output, channel);
assert(handle->audioIoHandle);
- *channel = __convert_audio_info_channel_to_channel(handle->audioIoHandle->getAudioInfo().getChannel());
+ *channel = __get_channels(handle->audioIoHandle->getAudioInfo());
} catch (const CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
return __convert_audio_io_error(e.getError());
"Parameters are NULL output:%p, type:%p", output, type);
assert(handle->audioIoHandle);
- *type = __convert_audio_info_sample_type_to_sample_type(handle->audioIoHandle->getAudioInfo().getSampleType());
+ *type = __get_sampletype(handle->audioIoHandle->getAudioInfo());
} catch (const CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
return __convert_audio_io_error(e.getError());