- remove {} for single statement.
- use noexcept keyword for non-throw methods.
- use override keyword for overrided function.
- remove unused methods.
- use default keyword for empty destructors.
- use explict keyword on single argument class constructor to prevent auto conversion.
- use nullptr instead of NULL if possible.
- use ! operator instead of comparing with false.
- use auto when initializing with a cast to avoid duplicating the type name.
- remove explict end return of void functions.
[Version] 0.5.19
[Issue Type] Refactoring
Change-Id: I5118a6ff5e85f9d9e02c7875b2cbe691652ef064
static const unsigned int MSG_LENGTH = 512;
/* Constructor & Destructor */
- CAudioError(EError err);
+ explicit CAudioError(EError err);
CAudioError(EError err, const char* fileName, const char* parentFunc, int lineNum);
CAudioError(EError err, const char* msg, const char* fileName, const char* parentFunc, int lineNum);
CAudioError(const CAudioError& err);
- ~CAudioError();
+ virtual ~CAudioError() = default;
/* Static Methods */
static EError getLastError();
static EError __mLastError;
static char __mLastErrorMsg[MSG_LENGTH];
EError __mError;
- char __mErrorMsg[MSG_LENGTH];
+ char __mErrorMsg[MSG_LENGTH]{};
};
void* mUserData;
void (*onStream)(size_t nbytes, void* user_data);
- SStreamCallback() : mUserData(NULL), onStream(NULL)
+ SStreamCallback() : mUserData(nullptr), onStream(nullptr)
{ /* Empty Body */ }
};
void* mUserData;
void (*onStateChanged)(CAudioInfo::EAudioIOState state, CAudioInfo::EAudioIOState statePrev, bool byPolicy, void* user_data);
- SStateChangedCallback() : mUserData(NULL), onStateChanged(NULL)
+ SStateChangedCallback() : mUserData(nullptr), onStateChanged(nullptr)
{ /* Empty Body */ }
};
/* Constructor & Destructor */
CAudioIO();
- CAudioIO(CAudioInfo& audioInfo);
- virtual ~CAudioIO();
+ explicit CAudioIO(CAudioInfo& audioInfo);
+ virtual ~CAudioIO() = default;
/* Pure Virtual Methods */
virtual void initialize() = 0;
virtual void pause() = 0;
virtual void resume() = 0;
+ /* FIXME : drain needed to be moved to sub-class */
virtual void drain();
virtual void flush() = 0;
void setStreamInfo(sound_stream_info_h stream_info);
- CAudioInfo::EAudioIOState getState();
+ CAudioInfo::EAudioIOState getState() noexcept;
protected:
/* Protected Methods */
/* Constructors */
CAudioInfo();
CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sampleType, EAudioType audioType, int audioIndex);
+ virtual ~CAudioInfo() = default;
/* Setter & Getter */
- unsigned int getSampleRate();
- EChannel getChannel();
- ESampleType getSampleType();
- EAudioType getAudioType();
- void setAudioType(EAudioType audioType);
- int getAudioIndex();
- void setAudioIndex(int audioIndex);
+ unsigned int getSampleRate() noexcept;
+ EChannel getChannel() noexcept;
+ ESampleType getSampleType() noexcept;
+ EAudioType getAudioType() noexcept;
+ 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();
+ int getSampleSize() noexcept;
private:
const char *__STREAM_TYPE_TABLE[(unsigned int)EAudioType::AUDIO_TYPE_MAX] = {
class CAudioInput : public CAudioIO {
public:
/* Constructor & Destructor */
- CAudioInput(CAudioInfo& info);
- CAudioInput(
- unsigned int sampleRate,
- CAudioInfo::EChannel channel,
- CAudioInfo::ESampleType sampleType,
- CAudioInfo::EAudioType audioType);
- ~CAudioInput();
+ explicit CAudioInput(CAudioInfo& info);
+ ~CAudioInput() = default;
/* Overridden Handler */
- virtual void onStream(CPulseAudioClient* pClient, size_t length);
+ void onStream(CPulseAudioClient* pClient, size_t length) override;
/* Implemented Methods */
- virtual void initialize();
- virtual void finalize();
+ void initialize() override;
+ void finalize() override;
- virtual void prepare();
- virtual void unprepare();
+ void prepare() override;
+ void unprepare() override;
- virtual void pause();
- virtual void resume();
+ void pause() override;
+ void resume() override;
- virtual void flush();
+ void flush() override;
- virtual int getBufferSize();
+ int getBufferSize() override;
/* Overridden Methods */
- virtual void setStreamCallback(SStreamCallback callback);
+ void setStreamCallback(SStreamCallback callback) override;
/* Methods */
size_t read(void* buffer, size_t length);
private:
/* Private Methods */
- void __setInit(bool flag);
- bool __IsInit();
- bool __IsReady();
+ void __setInit(bool flag) noexcept;
+ bool __IsInit() noexcept;
+ bool __IsReady() noexcept;
bool __mIsUsedSyncRead;
bool __mIsInit;
class CAudioOutput : public CAudioIO {
public:
/* Constructor & Destructor */
- CAudioOutput(CAudioInfo& info);
- CAudioOutput(
- unsigned int smapleRate,
- CAudioInfo::EChannel channel,
- CAudioInfo::ESampleType sampleType,
- CAudioInfo::EAudioType type);
- ~CAudioOutput();
+ explicit CAudioOutput(CAudioInfo& info);
+ ~CAudioOutput() = default;
/* Overridden Handler */
- virtual void onStream(CPulseAudioClient* pClient, size_t length);
+ void onStream(CPulseAudioClient* pClient, size_t length) override;
/* Implemented Methods */
- virtual void initialize();
- virtual void finalize();
+ void initialize() override;
+ void finalize() override;
- virtual void prepare();
- virtual void unprepare();
+ void prepare() override;
+ void unprepare() override;
- virtual void pause();
- virtual void resume();
+ void pause() override;
+ void resume() override;
- virtual void drain();
- virtual void flush();
+ void drain() override;
+ void flush() override;
- virtual int getBufferSize();
+ int getBufferSize() override;
/* Methods */
size_t write(const void* buffer, size_t length);
private:
/* Private Methods */
- void __setInit(bool flag);
- bool __IsInit();
- bool __IsReady();
+ void __setInit(bool flag) noexcept;
+ bool __IsInit() noexcept;
+ bool __IsReady() noexcept;
bool __mIsUsedSyncWrite;
bool __mIsInit;
/**
* PULSE Thread
*/
- class CPulseAudioVolume;
- class CPulseAudioPolicy;
class CPulseStreamSpec;
class CPulseAudioClient {
public:
bool flush();
void checkRunningState();
- bool isInThread();
+ bool isInThread() noexcept;
size_t getWritableSize();
size_t getReadableSize();
pa_usec_t getLatency();
pa_usec_t getFinalLatency();
- /* Setter & Getter */
- EStreamDirection getStreamDirection();
- CPulseStreamSpec getStreamSpec();
-
private:
/* Members */
EStreamDirection __mDirection;
/* Private Calblack Method */
static void __contextStateChangeCb(pa_context* c, void* user_data);
- static void __successContextCb(pa_context* c, int success, void* user_data);
-
static void __streamStateChangeCb(pa_stream* s, void* user_data);
static void __streamCaptureCb(pa_stream* s, size_t length, void* user_data);
static void __streamPlaybackCb(pa_stream* s, size_t length, void* user_data);
/* Constructor & Destructor */
CPulseStreamSpec();
CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo);
- CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo, int customLatency);
- ~CPulseStreamSpec();
+ ~CPulseStreamSpec() = default;
/* Setter & Getter */
- EStreamLatency getStreamLatency();
- const char* getStreamLatencyToString();
- CAudioInfo& getAudioInfo();
- pa_sample_spec getSampleSpec();
- pa_channel_map getChannelMap();
- const char* getStreamName();
+ EStreamLatency getStreamLatency() noexcept;
+ const char* getStreamLatencyToString() noexcept;
+ CAudioInfo& getAudioInfo() noexcept;
+ pa_sample_spec getSampleSpec() noexcept;
+ pa_channel_map getChannelMap() noexcept;
+ const char* getStreamName() noexcept;
private:
/* Private Methods */
- void __adjustSpec();
+ void __adjustSpec() noexcept;
/* Members */
EStreamLatency __mLatency;
Name: capi-media-audio-io
Summary: An Audio Input & Audio Output library in Tizen Native API
-Version: 0.5.18
+Version: 0.5.19
Release: 0
Group: Multimedia/API
License: Apache-2.0
* class CAudioError
*/
CAudioError::EError CAudioError::__mLastError = CAudioError::EError::ERROR_NONE;
-char CAudioError::__mLastErrorMsg[CAudioError::MSG_LENGTH];
+char CAudioError::__mLastErrorMsg[MSG_LENGTH];
//LCOV_EXCL_START
CAudioError::CAudioError(EError err) :
findFileName++;
const char* errStr = __convertErrorToString(__mError);
- snprintf(__mErrorMsg, CAudioError::MSG_LENGTH, "["
+ snprintf(__mErrorMsg, MSG_LENGTH, "["
COLOR_RED "THROW" COLOR_END ":%s|"
COLOR_YELLOW "ERR" COLOR_END ":%s|"
COLOR_YELLOW "FUNC" COLOR_END ":%s(%d)]", findFileName, errStr, parentFunc, lineNum);
- snprintf(__mLastErrorMsg, CAudioError::MSG_LENGTH, "LastError:%s", __mErrorMsg);
+ snprintf(__mLastErrorMsg, MSG_LENGTH, "LastError:%s", __mErrorMsg);
}
//LCOV_EXCL_STOP
findFileName++;
const char* errStr = __convertErrorToString(__mError);
- snprintf(__mErrorMsg, CAudioError::MSG_LENGTH, "["
+ snprintf(__mErrorMsg, MSG_LENGTH, "["
COLOR_RED "THROW" COLOR_END ":%s|"
COLOR_YELLOW "ERR" COLOR_END ":%s|"
COLOR_YELLOW "FUNC" COLOR_END ":%s(%d)]"
COLOR_YELLOW "MSG" COLOR_END ":"
COLOR_CYAN "%s" COLOR_END, findFileName, errStr, parentFunc, lineNum, msg);
- snprintf(__mLastErrorMsg, CAudioError::MSG_LENGTH, "LastError:%s", __mErrorMsg);
+ snprintf(__mLastErrorMsg, MSG_LENGTH, "LastError:%s", __mErrorMsg);
}
//LCOV_EXCL_START
}
//LCOV_EXCL_STOP
-CAudioError::~CAudioError() {
-}
-
const char* CAudioError::__convertErrorToString(EError err) {
switch (err) {
default:
*/
//LCOV_EXCL_START
CAudioIO::CAudioIO() :
- mpPulseAudioClient(NULL),
+ mpPulseAudioClient(nullptr),
__mMutex(PTHREAD_MUTEX_INITIALIZER),
__mCondMutex(PTHREAD_MUTEX_INITIALIZER),
__mCond(PTHREAD_COND_INITIALIZER),
//LCOV_EXCL_STOP
CAudioIO::CAudioIO(CAudioInfo& audioInfo) :
- mpPulseAudioClient(NULL),
+ mpPulseAudioClient(nullptr),
__mMutex(PTHREAD_MUTEX_INITIALIZER),
__mCondMutex(PTHREAD_MUTEX_INITIALIZER),
__mCond(PTHREAD_COND_INITIALIZER),
mByPolicy = false;
}
-CAudioIO::~CAudioIO() {
-}
-
void CAudioIO::setInit(bool flag) {
__mIsInit = flag;
}
bool CAudioIO::IsReady() {
return ((mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING ||
- mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED)? true : false);
+ mState == CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED));
}
void CAudioIO::internalLock() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
if (pthread_mutex_lock(&__mMutex) != 0)
}
void CAudioIO::internalUnlock() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
if (pthread_mutex_unlock(&__mMutex) != 0)
}
void CAudioIO::internalWait() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
#ifdef _AUDIO_IO_DEBUG_TIMING_
}
void CAudioIO::internalSignal() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
#ifdef _AUDIO_IO_DEBUG_TIMING_
}
void CAudioIO::initialize() {
- if (__mIsInit == true)
+ if (__mIsInit)
return;
AUDIO_IO_LOGD("initialize");
}
void CAudioIO::finalize() {
- if (__mIsInit == false)
+ if (!__mIsInit)
return;
AUDIO_IO_LOGD("finalize");
}
void CAudioIO::onStream(CPulseAudioClient* pClient, size_t length) {
- assert(__mIsInit == true);
- assert(pClient != NULL);
+ assert(__mIsInit);
+ assert(pClient);
assert(length > 0);
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("mStreamCallback.onStream(%p), pClient(%p), length(%zu)", mStreamCallback.onStream, pClient, length);
#endif
- if (mStreamCallback.onStream != NULL)
+ if (mStreamCallback.onStream)
mStreamCallback.onStream(length, mStreamCallback.mUserData);
}
void CAudioIO::onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy) {
- assert(__mIsInit == true);
+ assert(__mIsInit);
assert(state >= CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE && state < CAudioInfo::EAudioIOState::AUDIO_IO_STATE_MAX);
mStatePrev = mState;
if (mState == mStatePrev)
return;
- const char* state_string[] = { "NONE", "IDLE", "RUNNING", "PAUSED" };
+ static const char* state_string[] = { "NONE", "IDLE", "RUNNING", "PAUSED" };
AUDIO_IO_LOGD("previous(%s,%d) ===> current(%s,%d), by_policy(%d)",
state_string[static_cast<int>(mStatePrev)],
static_cast<int>(mState),
mByPolicy);
- if (mStateChangedCallback.onStateChanged != NULL)
+ if (mStateChangedCallback.onStateChanged)
mStateChangedCallback.onStateChanged(mState, mStatePrev, mByPolicy, mStateChangedCallback.mUserData);
}
onStateChanged(state, false);
}
-CAudioInfo::EAudioIOState CAudioIO::getState() {
+CAudioInfo::EAudioIOState CAudioIO::getState() noexcept {
return mState;
}
void CAudioIO::prepare() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
}
void CAudioIO::unprepare() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
}
void CAudioIO::pause() {
- if (__mIsInit == false || IsReady() == false)
+ if (!__mIsInit || !IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
try {
}
void CAudioIO::resume() {
- if (__mIsInit == false || IsReady() == false)
+ if (!__mIsInit || !IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
try {
}
void CAudioIO::drain() {
- if (__mIsInit == false || IsReady() == false)
+ if (!__mIsInit || !IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
try {
}
void CAudioIO::flush() {
- if (__mIsInit == false || IsReady() == false)
+ if (!__mIsInit || !IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize or prepare CAudioIO");
try {
}
CAudioInfo& CAudioIO::getAudioInfo() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
return mAudioInfo;
}
void CAudioIO::setStreamCallback(SStreamCallback callback) {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
mStreamCallback = callback;
}
CAudioIO::SStreamCallback CAudioIO::getStreamCallback() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
return mStreamCallback;
}
void CAudioIO::setStateChangedCallback(SStateChangedCallback callback) {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
mStateChangedCallback = callback;
}
CAudioIO::SStateChangedCallback CAudioIO::getStateChangedCallback() {
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
return mStateChangedCallback;
}
void CAudioIO::setStreamInfo(sound_stream_info_h stream_info) {
- if (stream_info == NULL)
+ if (!stream_info)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_ARGUMENT, "stream_info is NULL");
- if (__mIsInit == false)
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioIO");
- try {
- if (mState != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE)
- 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 = NULL;
- int index = -1;
- bool avail = false;
-
- if ((errorCode = sound_manager_is_available_stream_information(stream_info, NATIVE_API_AUDIO_IO, &avail)) != SOUND_MANAGER_ERROR_NONE)
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info is invalid [ret:%d]", errorCode);
- if (!avail)
- THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "Input stream is not supported");
-
- 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); //LCOV_EXCL_LINE
- if (mDirection == CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN)
- getAudioInfo().convertInputStreamType2AudioType(type, &audioType);
- else
- getAudioInfo().convertOutputStreamType2AudioType(type, &audioType);
- getAudioInfo().setAudioType(audioType);
-
- 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); //LCOV_EXCL_LINE
- getAudioInfo().setAudioIndex(index);
-
- } catch (CAudioError& e) {
- throw;
- }
+ if (mState != CAudioInfo::EAudioIOState::AUDIO_IO_STATE_IDLE)
+ 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;
+
+ if ((errorCode = sound_manager_is_available_stream_information(stream_info, NATIVE_API_AUDIO_IO, &avail)) != SOUND_MANAGER_ERROR_NONE)
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info is invalid [ret:%d]", errorCode);
+ if (!avail)
+ THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "Input stream is not supported");
+
+ 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);
+ else
+ getAudioInfo().convertOutputStreamType2AudioType(type, &audioType);
+ getAudioInfo().setAudioType(audioType);
+
+ 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);
+ getAudioInfo().setAudioIndex(index);
}
__mAudioType(audioType),
__mAudioIndex(audioIndex) {
// Check to invalid AudioInfo
- if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE || sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE) {
+ if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE || sampleRate > CAudioInfo::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 < CAudioInfo::EChannel::CHANNEL_MONO || channel >= CAudioInfo::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 < CAudioInfo::ESampleType::SAMPLE_TYPE_U8 || sampleType >= CAudioInfo::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 < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::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() {
+unsigned int CAudioInfo::getSampleRate() noexcept {
return __mSampleRate;
}
-CAudioInfo::EChannel CAudioInfo::getChannel() {
+CAudioInfo::EChannel CAudioInfo::getChannel() noexcept {
return __mChannel;
}
-CAudioInfo::ESampleType CAudioInfo::getSampleType() {
+CAudioInfo::ESampleType CAudioInfo::getSampleType() noexcept {
return __mSampleType;
}
-CAudioInfo::EAudioType CAudioInfo::getAudioType() {
+CAudioInfo::EAudioType CAudioInfo::getAudioType() noexcept {
return __mAudioType;
}
-void CAudioInfo::setAudioType(CAudioInfo::EAudioType audioType) {
+void CAudioInfo::setAudioType(CAudioInfo::EAudioType audioType) noexcept {
__mAudioType = audioType;
- return;
}
-int CAudioInfo::getAudioIndex() {
+int CAudioInfo::getAudioIndex() noexcept {
return __mAudioIndex;
}
-void CAudioInfo::setAudioIndex(int audioIndex) {
+void CAudioInfo::setAudioIndex(int audioIndex) noexcept {
__mAudioIndex = audioIndex;
- return;
}
-int CAudioInfo::getSampleSize() {
+int CAudioInfo::getSampleSize() noexcept {
int bytes_in_sample = 0;
switch (__mSampleType) {
"The audioType is not supported [audioType:%u]", to_integral(audioType));
*streamType = (char *)__STREAM_TYPE_TABLE[(unsigned int)audioType];
- return;
}
void CAudioInfo::convertInputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType) {
- for (unsigned int i = (unsigned int)CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i++) {
+ 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;
}
}
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of input is not supported [streamType:%s]", streamType);
- return;
}
void CAudioInfo::convertOutputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType) {
- for (unsigned int i = (unsigned int)CAudioInfo::EAudioType::AUDIO_OUT_TYPE_MEDIA ; i < (unsigned int)CAudioInfo::EAudioType::AUDIO_TYPE_MAX ; i++) {
+ 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;
}
}
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The streamType of output is not supported [streamType:%s]", streamType);
- return;
}
mDirection = CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN;
}
-//LCOV_EXCL_START
-CAudioInput::CAudioInput(
- unsigned int sampleRate,
- CAudioInfo::EChannel channel,
- CAudioInfo::ESampleType type,
- CAudioInfo::EAudioType audioType) :
- __mIsUsedSyncRead(true),
- __mIsInit(false) {
- mDirection = CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN;
- mAudioInfo = CAudioInfo(sampleRate, channel, type, audioType, -1);
-}
-//LCOV_EXCL_STOP
-
-CAudioInput::~CAudioInput() {
-}
-
void CAudioInput::onStream(CPulseAudioClient* pClient, size_t length) {
assert(pClient);
* Does not call CAudioIO::onStream() for synchronization
* if a user is using read()
*/
- if (__mIsUsedSyncRead == true) {
+ if (__mIsUsedSyncRead) {
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("Sync Read Mode! - pClient:[%p], length:[%zu]", pClient, length);
#endif
CAudioIO::onStream(pClient, length);
}
-void CAudioInput::__setInit(bool flag) {
+void CAudioInput::__setInit(bool flag) noexcept {
__mIsInit = flag;
}
-bool CAudioInput::__IsInit() {
- return (CAudioIO::isInit() == true && __mIsInit == true);
+bool CAudioInput::__IsInit() noexcept {
+ return (CAudioIO::isInit() && __mIsInit);
}
-bool CAudioInput::__IsReady() {
+bool CAudioInput::__IsReady() noexcept {
return CAudioIO::IsReady();
}
void CAudioInput::initialize() {
- if (__IsInit() == true)
+ if (__IsInit())
return;
- if (cpp_audio_in_has_record_privilege() == false)
+ if (!cpp_audio_in_has_record_privilege())
THROW_ERROR_MSG(CAudioError::EError::ERROR_PERMISSION_DENIED, "No privilege for record");
try {
}
void CAudioInput::finalize() {
- if (__IsInit() == false) {
+ if (!__IsInit()) {
AUDIO_IO_LOGD("Did not initialize");
return;
}
}
void CAudioInput::prepare() {
- if (__IsInit() == false)
+ if (!__IsInit())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioInput");
- if (__IsReady() == true) {
+ if (__IsReady()) {
AUDIO_IO_LOGD("Already prepared CAudioInput");
CAudioIO::prepare();
return;
}
void CAudioInput::unprepare() {
- if (__IsInit() == false)
+ if (!__IsInit())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize CAudioInput");
- if (__IsReady() == false) {
+ if (!__IsReady()) {
AUDIO_IO_LOGD("Already unprepared");
return;
}
}
void CAudioInput::pause() {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE,
"Can't pause if not in Running state");
- if (mpPulseAudioClient->isInThread() == true)
+ if (mpPulseAudioClient->isInThread())
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't pause in thread");
CAudioIO::pause();
}
void CAudioInput::resume() {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE,
"Can't resume if not in Paused state");
- if (mpPulseAudioClient->isInThread() == true)
+ if (mpPulseAudioClient->isInThread())
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't resume in thread");
CAudioIO::resume();
}
void CAudioInput::flush() {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
}
int CAudioInput::getBufferSize() {
- if (__IsInit() == false)
+ if (!__IsInit())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioInput");
/* FIXME : return calculated size here to satisfy backward compatibility */
}
void CAudioInput::setStreamCallback(SStreamCallback callback) {
- if (__IsInit() == false)
+ if (!__IsInit())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioInput");
- if (callback.onStream == NULL)
- __mIsUsedSyncRead = true;
- else
- __mIsUsedSyncRead = false;
+ __mIsUsedSyncRead = (callback.onStream == nullptr);
+
AUDIO_IO_LOGD("__mIsUsedSyncRead = %d", __mIsUsedSyncRead);
CAudioIO::setStreamCallback(callback);
}
size_t CAudioInput::read(void* buffer, size_t length) {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
- if (buffer == NULL)
+ if (!buffer)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL buffer:%p", buffer);
"Can't read if not in Running state");
/* Checks synchronous flag */
- if (__mIsUsedSyncRead == false)
+ if (!__mIsUsedSyncRead)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Invalid operation of read() if receive stream callback");
internalLock();
// If another thread did call unprepare, do not read
- if (mpPulseAudioClient == NULL)
+ if (!mpPulseAudioClient)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize CPulseAudioClient");
}
int CAudioInput::peek(const void** buffer, size_t* length) {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
- if (buffer == NULL || length == NULL)
+ if (buffer == nullptr || length == nullptr)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL buffer:%p, length:%p", buffer, length);
/* Checks synchronous flag */
- if (__mIsUsedSyncRead == true)
+ if (__mIsUsedSyncRead)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Invalid operation of peek() if does not receive a stream callback");
}
int CAudioInput::drop() {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioInput");
/* Checks synchronous flag */
- if (__mIsUsedSyncRead == true)
+ if (__mIsUsedSyncRead)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION,
"Invalid operation of drop() if does not receive a stream callback");
/**
* class CAudioOutput
*/
+
CAudioOutput::CAudioOutput(CAudioInfo& info) :
CAudioIO(info),
__mIsUsedSyncWrite(false),
mDirection = CAudioInfo::EAudioDirection::AUDIO_DIRECTION_OUT;
}
-//LCOV_EXCL_START
-CAudioOutput::CAudioOutput(
- unsigned int sampleRate,
- CAudioInfo::EChannel channel,
- CAudioInfo::ESampleType sampleType,
- CAudioInfo::EAudioType audioType) :
- __mIsUsedSyncWrite(false),
- __mIsInit(false) {
- mDirection = CAudioInfo::EAudioDirection::AUDIO_DIRECTION_OUT;
- mAudioInfo = CAudioInfo(sampleRate, channel, sampleType, audioType, -1);
-}
-//LCOV_EXCL_STOP
-
-CAudioOutput::~CAudioOutput() {
-}
-
void CAudioOutput::onStream(CPulseAudioClient* pClient, size_t length) {
assert(pClient);
* Does not call CAudioIO::onStream() for synchronization
* if a user is using write()
*/
- if (__mIsUsedSyncWrite == true) {
+ if (__mIsUsedSyncWrite) {
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("Sync Write Mode! - signal! - pClient:[%p], length:[%zu]", pClient, length);
#endif
CAudioIO::onStream(pClient, length);
}
-void CAudioOutput::__setInit(bool flag) {
+void CAudioOutput::__setInit(bool flag) noexcept {
__mIsInit = flag;
}
-bool CAudioOutput::__IsInit() {
- return (CAudioIO::isInit() == true && __mIsInit == true);
+bool CAudioOutput::__IsInit() noexcept {
+ return (CAudioIO::isInit() && __mIsInit);
}
-bool CAudioOutput::__IsReady() {
+bool CAudioOutput::__IsReady() noexcept {
return CAudioIO::IsReady();
}
void CAudioOutput::initialize() {
- if (__IsInit() == true)
+ if (__IsInit())
return;
try {
}
void CAudioOutput::finalize() {
- if (__IsInit() == false) {
+ if (!__IsInit()) {
AUDIO_IO_LOGD("Did not initialize");
return;
}
}
void CAudioOutput::prepare() {
- if (__IsInit() == false)
+ if (!__IsInit())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioOutput");
- if (__IsReady() == true) {
+ if (__IsReady()) {
AUDIO_IO_LOGD("Already prepared CAudioOutput");
CAudioIO::prepare();
return;
}
void CAudioOutput::unprepare() {
- if (__IsInit() == false)
+ if (!__IsInit())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize CAudioOutput");
- if (__IsReady() == false) {
+ if (!__IsReady()) {
AUDIO_IO_LOGD("Already unprepared");
return;
}
}
void CAudioOutput::pause() {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE,
"Can't pause if not in Running state");
- if (mpPulseAudioClient->isInThread() == true)
+ if (mpPulseAudioClient->isInThread() )
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't pause in thread");
CAudioIO::pause();
}
void CAudioOutput::resume() {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_STATE,
"Can't resume if not in Paused state");
- if (mpPulseAudioClient->isInThread() == true)
+ if (mpPulseAudioClient->isInThread())
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't resume in thread");
CAudioIO::resume();
}
void CAudioOutput::drain() {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
}
void CAudioOutput::flush() {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
}
int CAudioOutput::getBufferSize() {
- if (__IsInit() == false)
+ if (!__IsInit())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
}
size_t CAudioOutput::write(const void* buffer, size_t length) {
- if (__IsInit() == false || __IsReady() == false)
+ if (!__IsInit() || !__IsReady())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize or prepare CAudioOutput");
- if (buffer == NULL)
+ if (!buffer)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are invalid - buffer:%p, length:%zu", buffer, length);
"Can't write if not in Running state");
/* When write() is called in PulseAudio callback, bypass a pcm data to CPulseAudioClient (For Asynchronous) */
- if (mpPulseAudioClient && mpPulseAudioClient->isInThread() == true) {
+ if (mpPulseAudioClient && mpPulseAudioClient->isInThread()) {
int ret = mpPulseAudioClient->write(buffer, length);
if (ret < 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION,
internalLock();
// If another thread did call unprepare, do not write
- if (mpPulseAudioClient == NULL)
+ if (!mpPulseAudioClient)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
"Did not initialize CPulseAudioClient");
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ git st* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "CAudioIODef.h"
#include <unistd.h>
#include <inttypes.h>
+
#ifdef ENABLE_DPM
#include <dpm/restriction.h>
#endif
__mDirection(direction),
__mSpec(spec),
__mpListener(listener),
- __mpMainloop(NULL),
- __mpContext(NULL),
- __mpStream(NULL),
- __mpPropList(NULL),
+ __mpMainloop(nullptr),
+ __mpContext(nullptr),
+ __mpStream(nullptr),
+ __mpPropList(nullptr),
__mIsInit(false),
__mIsOperationSuccess(false),
- __mpSyncReadDataPtr(NULL),
+ __mpSyncReadDataPtr(nullptr),
__mSyncReadIndex(0),
__mSyncReadLength(0),
__mIsUsedSyncRead(false),
}
void CPulseAudioClient::__contextStateChangeCb(pa_context* c, void* user_data) {
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
assert(pClient);
assert(c);
}
//LCOV_EXCL_START
-void CPulseAudioClient::__successContextCb(pa_context* c, int success, void* user_data) {
- AUDIO_IO_LOGD("pa_context[%p], success[%d], user_data[%p]", c, success, user_data);
- assert(c);
- assert(user_data);
-
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
- pClient->__mIsOperationSuccess = static_cast<bool>(success);
-
- pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
-}
-
static bool __is_microphone_restricted(void) {
int state = 1;
#ifdef ENABLE_DPM
- device_policy_manager_h dpm_h = NULL;
+ device_policy_manager_h dpm_h = nullptr;
int ret = 0;
if ((dpm_h = dpm_manager_create())) {
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
switch (pa_stream_get_state(s)) {
case PA_STREAM_READY:
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
assert(pClient->__mpListener);
assert(pClient->__mpMainloop);
- if (pClient->__mIsUsedSyncRead == true) {
+ if (pClient->__mIsUsedSyncRead)
pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
- }
pClient->__mpListener->onStream(pClient, length);
}
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
assert(pClient->__mpListener);
#ifndef DISABLE_MOBILE_BACK_COMP
- if (pClient->__mIsInit == false) {
+ if (!pClient->__mIsInit) {
AUDIO_IO_LOGD("Occurred this listener when an out stream is on the way to create : Write dummy, length[%zu]", length);
__dummy_write(s, length);
return;
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
}
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
AUDIO_IO_LOGD("stream %p started.", pClient);
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
AUDIO_IO_LOGD("stream %p UnderFlow...", pClient);
AUDIO_IO_LOGE("NAME : %s, Prop : %p", name, pl);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
- if (strcmp(name, PA_STREAM_EVENT_POP_TIMEOUT) == 0) {
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
+ if (strcmp(name, PA_STREAM_EVENT_POP_TIMEOUT) == 0)
pa_operation_unref(pa_stream_cork(pClient->__mpStream, 1, NULL, NULL));
- }
}
//LCOV_EXCL_STOP
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
pClient->__mIsOperationSuccess = static_cast<bool>(success);
pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
pClient->__mIsOperationSuccess = static_cast<bool>(success);
pClient->__mIsDraining = false;
}
assert(s);
assert(user_data);
- CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+ auto pClient = static_cast<CPulseAudioClient*>(user_data);
pClient->__mIsOperationSuccess = static_cast<bool>(success);
pClient->__mIsDraining = false;
}
void CPulseAudioClient::initialize() {
- if (__mIsInit == true) {
+ if (__mIsInit)
return;
- }
int ret = 0;
int err = 0;
try {
// Allocates PA proplist
__mpPropList = pa_proplist_new();
- if (__mpPropList == NULL) {
+ if (!__mpPropList)
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 = NULL;
+ char *streamType = nullptr;
CAudioInfo::EAudioType audioType = __mSpec.getAudioInfo().getAudioType();
__mSpec.getAudioInfo().convertAudioType2StreamType(audioType, &streamType);
pa_proplist_sets(__mpPropList, PA_PROP_MEDIA_ROLE, streamType);
int index = __mSpec.getAudioInfo().getAudioIndex();
- if (index >= 0) {
+ if (index >= 0)
pa_proplist_setf(__mpPropList, PA_PROP_MEDIA_PARENT_ID, "%u", (unsigned int) index);
- }
// Adds latency on proplist for delivery to PULSEAUDIO
AUDIO_IO_LOGD("LATENCY : %s[%d]", __mSpec.getStreamLatencyToString(), static_cast<int>(__mSpec.getStreamLatency()));
// Allocates PA mainloop
__mpMainloop = pa_threaded_mainloop_new();
- if (__mpMainloop == NULL) {
+ if (!__mpMainloop)
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_threaded_mainloop_new()"); //LCOV_EXCL_LINE
- }
// Allocates PA context
__mpContext = pa_context_new(pa_threaded_mainloop_get_api(__mpMainloop), CLIENT_NAME);
- if (__mpContext == NULL) {
+ if (!__mpContext)
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_context_new()"); //LCOV_EXCL_LINE
- }
// Sets context state changed callback
pa_context_set_state_callback(__mpContext, __contextStateChangeCb, this);
// Connects this client with PA server
- if (pa_context_connect(__mpContext, NULL, PA_CONTEXT_NOFLAGS, NULL) < 0) {
+ if (pa_context_connect(__mpContext, NULL, PA_CONTEXT_NOFLAGS, NULL) < 0)
THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_context_connect()"); //LCOV_EXCL_LINE
- }
// LOCK for synchronous connection
pa_threaded_mainloop_lock(__mpMainloop);
pa_context_state_t state;
state = pa_context_get_state(__mpContext);
- if (state == PA_CONTEXT_READY) {
+ if (state == PA_CONTEXT_READY)
break;
- }
if (!PA_CONTEXT_IS_GOOD(state)) {
//LCOV_EXCL_START
pa_channel_map map = __mSpec.getChannelMap();
__mpStream = pa_stream_new_with_proplist(__mpContext, __mSpec.getStreamName(), &ss, &map, __mpPropList);
- if (__mpStream == NULL) {
+ if (!__mpStream) {
//LCOV_EXCL_START
pa_threaded_mainloop_unlock(__mpMainloop);
THROW_ERROR_MSG(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_new_with_proplist()");
// Connect stream with PA Server
if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
- pa_stream_flags_t flags = static_cast<pa_stream_flags_t>(
+ auto flags = static_cast<pa_stream_flags_t>(
PA_STREAM_INTERPOLATE_TIMING |
PA_STREAM_ADJUST_LATENCY |
#ifndef DISABLE_MOBILE_BACK_COMP
ret = pa_stream_connect_playback(__mpStream, NULL, NULL, flags, NULL, NULL);
} else {
- pa_stream_flags_t flags = static_cast<pa_stream_flags_t>(
+ auto flags = static_cast<pa_stream_flags_t>(
PA_STREAM_INTERPOLATE_TIMING |
PA_STREAM_ADJUST_LATENCY |
#ifndef DISABLE_MOBILE_BACK_COMP
}
while (true) {
- pa_stream_state_t state;
- state = pa_stream_get_state(__mpStream);
+ pa_stream_state_t state = pa_stream_get_state(__mpStream);
if (state == PA_STREAM_READY) {
AUDIO_IO_LOGD("STREAM READY");
if (!PA_STREAM_IS_GOOD(state)) {
err = pa_context_errno(__mpContext);
pa_threaded_mainloop_unlock(__mpMainloop);
- if (err == PA_ERR_ACCESS) {
+ if (err == PA_ERR_ACCESS)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_DEVICE_POLICY_RESTRICTION, "pa_stream's state is not good : err[%d]", err);
- } else {
+ else
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "pa_stream's state is not good : err[%d]", err); //LCOV_EXCL_LINE
- }
}
/* Wait until the stream is ready */
void CPulseAudioClient::finalize() {
AUDIO_IO_LOGD("");
- if (__mpMainloop && isInThread() == false)
+ if (__mpMainloop && !isInThread())
pa_threaded_mainloop_lock(__mpMainloop);
/* clear callbacks */
pa_stream_set_event_callback(__mpStream, NULL, NULL);
}
- if (__mpMainloop && isInThread() == false)
+ if (__mpMainloop && !isInThread())
pa_threaded_mainloop_unlock(__mpMainloop);
/* Wait for drain complete if draining before finalize */
if (__mIsDraining) {
unsigned int drain_wait_count = 0;
- while (__mIsDraining && drain_wait_count++ < drain_wait_max_count) {
+ while (__mIsDraining && drain_wait_count++ < drain_wait_max_count)
usleep(drain_wait_interval);
- }
AUDIO_IO_LOGD("wait for drain complete!!!! [%d * %d usec]",
drain_wait_count, drain_wait_interval);
}
- if (__mpMainloop != NULL) {
+ if (__mpMainloop)
pa_threaded_mainloop_stop(__mpMainloop);
- }
- if (__mpStream != NULL) {
+ if (__mpStream) {
pa_stream_disconnect(__mpStream);
pa_stream_unref(__mpStream);
- __mpStream = NULL;
+ __mpStream = nullptr;
}
- if (__mpContext != NULL) {
+ if (__mpContext) {
pa_context_disconnect(__mpContext);
pa_context_unref(__mpContext);
- __mpContext = NULL;
+ __mpContext = nullptr;
}
- if (__mpMainloop != NULL) {
+ if (__mpMainloop) {
pa_threaded_mainloop_free(__mpMainloop);
- __mpMainloop = NULL;
+ __mpMainloop = nullptr;
}
- if (__mpPropList != NULL) {
+ if (__mpPropList) {
pa_proplist_free(__mpPropList);
- __mpPropList = NULL;
+ __mpPropList = nullptr;
}
__mIsInit = false;
}
int CPulseAudioClient::read(void* buffer, size_t length) {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
- if (buffer == NULL) {
+ if (!buffer)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The parameter is invalid : buffer[%p]", buffer);
- }
- if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+ if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client couldn't use this function");
- }
size_t lengthIter = length;
int ret = 0;
while (lengthIter > 0) {
size_t l;
- while (__mpSyncReadDataPtr == NULL) {
+ while (!__mpSyncReadDataPtr) {
ret = pa_stream_peek(__mpStream, &__mpSyncReadDataPtr, &__mSyncReadLength);
- if (ret != 0) {
+ if (ret != 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pa_stream_peek() : ret[%d]", ret);
- }
if (__mSyncReadLength <= 0) {
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("readLength(%zu byte) is not valid. wait...", __mSyncReadLength);
#endif
pa_threaded_mainloop_wait(__mpMainloop);
- } else if (__mpSyncReadDataPtr == NULL) {
+ } else if (!__mpSyncReadDataPtr) {
// Data peeked, but it doesn't have any data
ret = pa_stream_drop(__mpStream);
- if (ret != 0) {
+ if (ret != 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pa_stream_drop() : ret[%d]", ret); //LCOV_EXCL_LINE
- }
} else {
__mSyncReadIndex = 0;
}
}
- if (__mSyncReadLength < lengthIter) {
+ if (__mSyncReadLength < lengthIter)
l = __mSyncReadLength;
- } else {
+ else
l = lengthIter;
- }
// Copy partial pcm data on out parameter
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("__mSyncReadLength is zero, do drop()");
#endif
ret = pa_stream_drop(__mpStream);
- if (ret != 0) {
+ if (ret != 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pa_stream_drop() : ret[%d]", ret); //LCOV_EXCL_LINE
- }
// Reset the internal pointer
- __mpSyncReadDataPtr = NULL;
+ __mpSyncReadDataPtr = nullptr;
__mSyncReadLength = 0;
__mSyncReadIndex = 0;
}
}
int CPulseAudioClient::peek(const void** buffer, size_t* length) {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
- if (buffer == NULL || length == NULL) {
+ if (!buffer || !length)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The parameter is invalid : buffer[%p], length[%p]", buffer, length);
- }
- if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+ if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client couldn't use this function");
- }
int ret = 0;
- if (isInThread() == false) {
+ if (!isInThread()) {
pa_threaded_mainloop_lock(__mpMainloop);
ret = pa_stream_peek(__mpStream, buffer, length);
pa_threaded_mainloop_unlock(__mpMainloop);
AUDIO_IO_LOGD("buffer[%p], length[%zu]", *buffer, *length);
#endif
- if (ret < 0) {
+ if (ret < 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_peek() : err[%d]", ret); //LCOV_EXCL_LINE
- }
return ret;
}
int CPulseAudioClient::drop() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("");
checkRunningState();
- if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+ if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client couldn't use this function");
- }
int ret = 0;
- if (isInThread() == false) {
+ if (!isInThread()) {
pa_threaded_mainloop_lock(__mpMainloop);
ret = pa_stream_drop(__mpStream);
pa_threaded_mainloop_unlock(__mpMainloop);
ret = pa_stream_drop(__mpStream);
}
- if (ret < 0) {
+ if (ret < 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_drop() : err[%d]", ret); //LCOV_EXCL_LINE
- }
return ret;
}
int CPulseAudioClient::write(const void* data, size_t length) {
- if (data == NULL) {
+ if (!data)
THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The parameter is invalid");
- }
- if (__mDirection == EStreamDirection::STREAM_DIRECTION_RECORD) {
+ if (__mDirection == EStreamDirection::STREAM_DIRECTION_RECORD)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client couldn't use this function");
- }
int ret = 0;
AUDIO_IO_LOGD("data[%p], length[%zu], First[%d]", data, length, __mIsFirstStream);
#endif
- if (isInThread() == false) {
+ if (!isInThread()) {
pa_threaded_mainloop_lock(__mpMainloop);
if (pa_stream_is_corked(__mpStream)) {
AUDIO_IO_LOGW("stream is corked...do uncork here first!!!!");
ret = pa_stream_write(__mpStream, data, length, NULL, 0LL, PA_SEEK_RELATIVE);
}
- if (ret < 0) {
+ if (ret < 0)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_write() : err[%d]", ret); //LCOV_EXCL_LINE
- }
return ret;
}
void CPulseAudioClient::cork(bool cork) {
AUDIO_IO_LOGD("cork[%d]", cork);
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
- if (isInThread() == true) {
+ if (isInThread())
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "This operation is not supported in callback");
- }
checkRunningState();
// Set __mIsFirstStream flag when uncork(resume) stream, because prebuf will be enable again
- if (cork == false)
+ if (!cork)
__mIsFirstStream = true;
- if (isInThread() == false) {
+ if (!isInThread()) {
pa_threaded_mainloop_lock(__mpMainloop);
pa_operation_unref(pa_stream_cork(__mpStream, static_cast<int>(cork), __successStreamCb, this));
pa_threaded_mainloop_unlock(__mpMainloop);
} else {
pa_operation_unref(pa_stream_cork(__mpStream, static_cast<int>(cork), __successStreamCb, this));
}
-
- return;
}
bool CPulseAudioClient::isCorked() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
int isCork = 0;
- if (isInThread() == false) {
+ if (!isInThread()) {
pa_threaded_mainloop_lock(__mpMainloop);
isCork = pa_stream_is_corked(__mpStream);
pa_threaded_mainloop_unlock(__mpMainloop);
}
bool CPulseAudioClient::drain() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
return true;
}
- if (isInThread() == false) {
+ if (!isInThread()) {
AUDIO_IO_LOGD("drain");
pa_threaded_mainloop_lock(__mpMainloop);
pa_operation* o = pa_stream_drain(__mpStream, __successDrainCb, this);
__mIsDraining = true;
- while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
+ while (pa_operation_get_state(o) == PA_OPERATION_RUNNING)
pa_threaded_mainloop_wait(__mpMainloop);
- }
+
pa_operation_unref(o);
pa_threaded_mainloop_unlock(__mpMainloop);
AUDIO_IO_LOGD("drain done");
}
bool CPulseAudioClient::flush() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
- if (isInThread() == false) {
+ if (!isInThread()) {
AUDIO_IO_LOGD("flush");
pa_threaded_mainloop_lock(__mpMainloop);
pa_operation_unref(pa_stream_flush(__mpStream, __successStreamCb, this));
}
size_t CPulseAudioClient::getWritableSize() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
- if (__mDirection != EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+ if (__mDirection != EStreamDirection::STREAM_DIRECTION_PLAYBACK)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "This client is used for Playback");
- }
size_t ret = 0;
- if (isInThread() == false) {
+ if (!isInThread()) {
pa_threaded_mainloop_lock(__mpMainloop);
ret = pa_stream_writable_size(__mpStream);
pa_threaded_mainloop_unlock(__mpMainloop);
}
void CPulseAudioClient::checkRunningState() {
- if (__mpContext == NULL || PA_CONTEXT_IS_GOOD(pa_context_get_state(__mpContext)) == 0) {
+ if (!__mpContext || !PA_CONTEXT_IS_GOOD(pa_context_get_state(__mpContext)))
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_INITIALIZED, "The context[%p] is not created or not good state", __mpContext);
- }
- if (__mpStream == NULL || PA_STREAM_IS_GOOD(pa_stream_get_state(__mpStream)) == 0) {
+
+ if (!__mpStream || !PA_STREAM_IS_GOOD(pa_stream_get_state(__mpStream)))
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_INITIALIZED, "The stream[%p] is not created or not good state", __mpStream);
- }
- if (pa_context_get_state(__mpContext) != PA_CONTEXT_READY || pa_stream_get_state(__mpStream) != PA_STREAM_READY) {
+
+ if (pa_context_get_state(__mpContext) != PA_CONTEXT_READY || pa_stream_get_state(__mpStream) != PA_STREAM_READY)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_INITIALIZED, "The context[%p] or stream[%p] state is not ready", __mpContext, __mpStream);
- }
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("This client is running");
#endif
}
-bool CPulseAudioClient::isInThread() {
+bool CPulseAudioClient::isInThread() noexcept {
int ret = pa_threaded_mainloop_in_thread(__mpMainloop);
#ifdef _AUDIO_IO_DEBUG_TIMING_
//LCOV_EXCL_START
size_t CPulseAudioClient::getReadableSize() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
- if (__mDirection != EStreamDirection::STREAM_DIRECTION_RECORD) {
+ if (__mDirection != EStreamDirection::STREAM_DIRECTION_RECORD)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "This client is used for Capture");
- }
size_t ret = 0;
- if (isInThread() == false) {
+ if (!isInThread()) {
pa_threaded_mainloop_lock(__mpMainloop);
- ret = pa_stream_writable_size(__mpStream);
+ ret = pa_stream_readable_size(__mpStream);
pa_threaded_mainloop_unlock(__mpMainloop);
} else {
ret = pa_stream_writable_size(__mpStream);
}
size_t CPulseAudioClient::getBufferSize() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
size_t ret = 0;
try {
- if (isInThread() == false) {
+ if (!isInThread())
pa_threaded_mainloop_lock(__mpMainloop);
- }
const pa_buffer_attr* attr = pa_stream_get_buffer_attr(__mpStream);
- if (attr == NULL) {
+ if (!attr) {
int _err = pa_context_errno(__mpContext);
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_get_buffer_attr() : err[%d]", _err);
}
AUDIO_IO_LOGD("RECORD buffer size[%zu]", ret);
}
} catch (CAudioError& e) {
- if (isInThread() == false) {
+ if (!isInThread())
pa_threaded_mainloop_unlock(__mpMainloop);
- }
throw;
}
- if (isInThread() == false) {
+ if (!isInThread())
pa_threaded_mainloop_unlock(__mpMainloop);
- }
return ret;
}
pa_usec_t CPulseAudioClient::getLatency() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
pa_usec_t ret = 0;
int negative = 0;
- if (isInThread() == false) {
+ if (!isInThread()) {
if (pa_stream_get_latency(__mpStream, &ret, &negative) < 0) {
int _err = pa_context_errno(__mpContext);
- if (_err != PA_ERR_NODATA) {
+ if (_err != PA_ERR_NODATA)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_get_latency() : err[%d]", _err);
- }
}
return negative ? 0 : ret;
}
try {
while (true) {
- if (pa_stream_get_latency(__mpStream, &ret, &negative) >= 0) {
+ if (pa_stream_get_latency(__mpStream, &ret, &negative) >= 0)
break;
- }
int _err = pa_context_errno(__mpContext);
- if (_err != PA_ERR_NODATA) {
+ if (_err != PA_ERR_NODATA)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_get_latency() : err[%d]", _err);
- }
/* Wait until latency data is available again */
pa_threaded_mainloop_wait(__mpMainloop);
}
pa_usec_t CPulseAudioClient::getFinalLatency() {
- if (__mIsInit == false) {
+ if (!__mIsInit)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
- }
checkRunningState();
pa_usec_t ret = 0;
- uint32_t ver = 0;
try {
- if (isInThread() == false) {
+ if (!isInThread())
pa_threaded_mainloop_lock(__mpMainloop);
- }
- ver = pa_context_get_server_protocol_version(__mpContext);
+ uint32_t ver = pa_context_get_server_protocol_version(__mpContext);
if (ver >= 13) {
const pa_buffer_attr* buffer_attr = pa_stream_get_buffer_attr(__mpStream);
const pa_sample_spec* sample_spec = pa_stream_get_sample_spec(__mpStream);
const pa_timing_info* timing_info = pa_stream_get_timing_info(__mpStream);
- if (buffer_attr == NULL || sample_spec == NULL || timing_info == NULL) {
+ if (!buffer_attr || !sample_spec || !timing_info)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to get buffer_attr[%p] or sample_spec[%p] or timing_info[%p] from a pa_stream",
buffer_attr, sample_spec, timing_info);
- }
if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
ret = (pa_bytes_to_usec(buffer_attr->tlength, sample_spec) + timing_info->configured_sink_usec);
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED, "This version(ver.%d) is not supported", ver);
}
- if (isInThread() == false) {
+ if (!isInThread())
pa_threaded_mainloop_unlock(__mpMainloop);
- }
} catch (CAudioError& e) {
- if (isInThread() == false) {
+ if (!isInThread())
pa_threaded_mainloop_unlock(__mpMainloop);
- }
throw;
}
return ret;
}
-
-CPulseAudioClient::EStreamDirection CPulseAudioClient::getStreamDirection() {
- return __mDirection;
-}
-
-CPulseStreamSpec CPulseAudioClient::getStreamSpec() {
- return __mSpec;
-}
//LCOV_EXCL_STOP
//LCOV_EXCL_START
CPulseStreamSpec::CPulseStreamSpec():
__mLatency(EStreamLatency::STREAM_LATENCY_INPUT_DEFAULT),
- __mStreamName(NULL) {
+ __mStreamName(nullptr) {
__adjustSpec();
}
//LCOV_EXCL_STOP
CPulseStreamSpec::CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo) :
__mLatency(latency),
__mAudioInfo(audioInfo),
- __mStreamName(NULL) {
+ __mStreamName(nullptr) {
__adjustSpec();
}
-//LCOV_EXCL_START
-CPulseStreamSpec::CPulseStreamSpec(EStreamLatency latency, CAudioInfo& audioInfo, int customLatency) :
- __mLatency(latency),
- __mAudioInfo(audioInfo),
- __mStreamName(NULL) {
- __adjustSpec();
-}
-//LCOV_EXCL_STOP
-
-CPulseStreamSpec::~CPulseStreamSpec() {
-}
-
-void CPulseStreamSpec::__adjustSpec() {
+void CPulseStreamSpec::__adjustSpec() noexcept {
// Sets a sampleRate
__mSampleSpec.rate = __mAudioInfo.getSampleRate();
//LCOV_EXCL_STOP
}
-CPulseStreamSpec::EStreamLatency CPulseStreamSpec::getStreamLatency() {
+CPulseStreamSpec::EStreamLatency CPulseStreamSpec::getStreamLatency() noexcept {
return __mLatency;
}
-const char* CPulseStreamSpec::getStreamLatencyToString() {
+const char* CPulseStreamSpec::getStreamLatencyToString() noexcept {
const char* latency;
switch (__mLatency) {
return latency;
}
-CAudioInfo& CPulseStreamSpec::getAudioInfo() {
+CAudioInfo& CPulseStreamSpec::getAudioInfo() noexcept {
return __mAudioInfo;
}
-pa_sample_spec CPulseStreamSpec::getSampleSpec() {
+pa_sample_spec CPulseStreamSpec::getSampleSpec() noexcept {
return __mSampleSpec;
}
-pa_channel_map CPulseStreamSpec::getChannelMap() {
+pa_channel_map CPulseStreamSpec::getChannelMap() noexcept {
return __mChannelMap;
}
-const char* CPulseStreamSpec::getStreamName() {
+const char* CPulseStreamSpec::getStreamName() noexcept {
return __mStreamName;
}
PrivilegeData prData;
prData.paMainloop = pa_threaded_mainloop_new();
- if (prData.paMainloop == NULL)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_threaded_mainloop_new()"); //LCOV_EXCL_LINE
+ if (!prData.paMainloop)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_threaded_mainloop_new()");
c = pa_context_new(pa_threaded_mainloop_get_api(prData.paMainloop), CLIENT_NAME);
- if (c == NULL)
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_context_new()"); //LCOV_EXCL_LINE
+ if (!c)
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_context_new()");
pa_context_set_state_callback(c, __contextStateChangeCb, prData.paMainloop);
void* user_data;
audio_in_stream_cb onStream;
- audio_io_stream_cb_s() : user_data(NULL), onStream(NULL)
+ audio_io_stream_cb_s() : user_data(nullptr), onStream(nullptr)
{/* Empty Body */}
} audio_io_stream_cb_s;
void* user_data;
audio_in_state_changed_cb onStateChanged;
- audio_io_state_changed_cb_s() : user_data(NULL), onStateChanged(NULL)
+ audio_io_state_changed_cb_s() : user_data(nullptr), onStateChanged(nullptr)
{/* Empty Body */}
} audio_io_state_changed_cb_s;
audio_io_stream_cb_s stream_callback;
audio_io_state_changed_cb_s state_changed_callback;
- audio_io_s() : audioIoHandle(NULL)
+ audio_io_s() : audioIoHandle(nullptr)
{/* Empty Body */}
} audio_io_s;
VALID_POINTER_START(obj)
if (is_output)
- *(audio_out_h *)obj = NULL;
+ *(audio_out_h *)obj = nullptr;
else
- *(audio_in_h *)obj = NULL;
+ *(audio_in_h *)obj = nullptr;
VALID_POINTER_END
}
* Implements CAPI functions
*/
int cpp_audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_in_h *input) {
- audio_io_s* handle = NULL;
+ audio_io_s* handle = nullptr;
bool mic_enable = false;
- int ret = 0;
+
try {
- if (input == NULL) {
+ if (!input)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- }
__check_audio_param(sample_rate, channel, type, false);
AUDIO_IO_LOGD("samplerate:[%d] channel:[0x%x] sample_type:[0x%x]", sample_rate, channel, type);
/* If MIC is not supported, return NOT_SUPPORTED error */
- ret = system_info_get_platform_bool(FEATURE_MICROPHONE, &mic_enable);
+ int ret = system_info_get_platform_bool(FEATURE_MICROPHONE, &mic_enable);
AUDIO_IO_LOGD("system_info_platform [%s]=[%d], ret[%d]", FEATURE_MICROPHONE, mic_enable, ret);
- if (ret != SYSTEM_INFO_ERROR_NONE || !mic_enable) {
+ if (ret != SYSTEM_INFO_ERROR_NONE || !mic_enable)
THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "System doesn't support microphone!");
- }
CAudioInfo audioInfo = __generate_audio_input_info(sample_rate, channel, type);
__handle_safe_free(handle, (void *)input, false);
return __convert_CAudioError(e);
} catch (const std::bad_alloc&) {
-//LCOV_EXCL_START
- CAudioError e = CAudioError::EError::ERROR_OUT_OF_MEMORY;
+ CAudioError e(CAudioError::EError::ERROR_OUT_OF_MEMORY);
AUDIO_IO_LOGE("Failed to allocate handle");
__handle_safe_free(handle, (void *)input, false);
return __convert_CAudioError(e);
}
int cpp_audio_in_destroy(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
assert(handle->audioIoHandle);
}
int cpp_audio_in_set_sound_stream_info(audio_in_h input, sound_stream_info_h stream_info) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || stream_info == NULL)
+ if (!handle || !stream_info)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, stream_info:%p", input, stream_info);
assert(handle->audioIoHandle);
}
int cpp_audio_in_prepare(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
assert(handle->audioIoHandle);
}
int cpp_audio_in_unprepare(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
assert(handle->audioIoHandle);
}
int cpp_audio_in_pause(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
assert(handle->audioIoHandle);
}
int cpp_audio_in_resume(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
assert(handle->audioIoHandle);
}
int cpp_audio_in_flush(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
assert(handle->audioIoHandle);
}
int cpp_audio_in_read(audio_in_h input, void *buffer, unsigned int length) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
int ret = 0;
try {
- if (handle == NULL || buffer == NULL)
+ auto handle = static_cast<audio_io_s*>(input);
+ if (!handle || !buffer)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, buffer:%p", input, buffer);
assert(handle->audioIoHandle);
- CAudioInput* inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
- if (inputHandle == NULL) {
+ auto inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
+ if (!inputHandle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
- }
- size_t readn = inputHandle->read(buffer, static_cast<size_t>(length));
+ auto readn = inputHandle->read(buffer, static_cast<size_t>(length));
ret = static_cast<int>(readn);
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("readn:%zu", readn);
}
int cpp_audio_in_get_buffer_size(audio_in_h input, int *size) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
-
try {
- if (handle == NULL || size == NULL)
+ auto handle = static_cast<audio_io_s*>(input);
+ if (!handle || !size)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, size:%p", input, size);
assert(handle->audioIoHandle);
- CAudioIO* inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
- if (inputHandle == NULL) {
+ auto inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
+ if (!inputHandle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
- }
+
*size = inputHandle->getBufferSize();
} catch (CAudioError& e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
}
int cpp_audio_in_get_sample_rate(audio_in_h input, int *sample_rate) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
-
try {
- if (handle == NULL || sample_rate == NULL)
+ auto handle = static_cast<audio_io_s*>(input);
+ if (!handle || !sample_rate)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, sample_rate:%p", input, sample_rate);
assert(handle->audioIoHandle);
}
int cpp_audio_in_get_channel(audio_in_h input, audio_channel_e *channel) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
-
try {
- if (handle == NULL || channel == NULL)
+ auto handle = static_cast<audio_io_s*>(input);
+ if (!handle || !channel)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, channel:%p", input, channel);
assert(handle->audioIoHandle);
- const CAudioInfo::EChannel srcChannel = handle->audioIoHandle->getAudioInfo().getChannel();
- audio_channel_e dstChannel = AUDIO_CHANNEL_MONO;
+ auto srcChannel = handle->audioIoHandle->getAudioInfo().getChannel();
+ auto dstChannel = AUDIO_CHANNEL_MONO;
__convert_audio_info_channel_2_channel(srcChannel, dstChannel);
*channel = dstChannel;
}
int cpp_audio_in_get_sample_type(audio_in_h input, audio_sample_type_e *type) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
-
try {
- if (handle == NULL || type == NULL)
+ auto handle = static_cast<audio_io_s*>(input);
+ if (!handle || !type)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, type:%p", input, type);
assert(handle->audioIoHandle);
- const CAudioInfo::ESampleType srcSampleType = handle->audioIoHandle->getAudioInfo().getSampleType();
- audio_sample_type_e dstSampleType = AUDIO_SAMPLE_TYPE_U8;
+ auto srcSampleType = handle->audioIoHandle->getAudioInfo().getSampleType();
+ auto dstSampleType = AUDIO_SAMPLE_TYPE_U8;
__convert_audio_info_sample_type_2_sample_type(srcSampleType, dstSampleType);
*type = dstSampleType;
}
static void __stream_cb_internal(size_t nbytes, void *user_data) {
- audio_io_s* audioIo = static_cast<audio_io_s*>(user_data);
+ auto audioIo = static_cast<audio_io_s*>(user_data);
assert(audioIo);
if (audioIo->stream_callback.onStream)
CAudioInfo::EAudioIOState state_prev,
bool by_policy,
void *user_data) {
- audio_io_s* audioIo = static_cast<audio_io_s*>(user_data);
+ auto audioIo = static_cast<audio_io_s*>(user_data);
assert(audioIo);
if (audioIo->state_changed_callback.onStateChanged)
//LCOV_EXCL_STOP
int cpp_audio_in_set_stream_cb(audio_in_h input, audio_in_stream_cb callback, void* user_data) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || callback == NULL)
+ if (!handle || !callback)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, callback:%p", input, callback);
assert(handle->audioIoHandle);
handle->stream_callback.onStream = callback;
handle->stream_callback.user_data = user_data;
- CAudioIO::SStreamCallback cb = handle->audioIoHandle->getStreamCallback();
+ auto cb = handle->audioIoHandle->getStreamCallback();
cb.mUserData = static_cast<void*>(handle);
cb.onStream = __stream_cb_internal;
}
int cpp_audio_in_unset_stream_cb(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
-
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
assert(handle->audioIoHandle);
AUDIO_IO_LOGD("[%p]", handle);
- handle->stream_callback.onStream = NULL;
- handle->stream_callback.user_data = NULL;
+ handle->stream_callback.onStream = nullptr;
+ handle->stream_callback.user_data = nullptr;
- CAudioIO::SStreamCallback cb = handle->audioIoHandle->getStreamCallback();
- cb.mUserData = NULL;
- cb.onStream = NULL;
+ auto cb = handle->audioIoHandle->getStreamCallback();
+ cb.mUserData = nullptr;
+ cb.onStream = nullptr;
handle->audioIoHandle->setStreamCallback(cb);
} catch (CAudioError& e) {
}
int cpp_audio_in_peek(audio_in_h input, const void **buffer, unsigned int *length) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
size_t _length = 0;
try {
- if (handle == NULL || buffer == NULL)
+ auto handle = static_cast<audio_io_s*>(input);
+ if (!handle || !buffer)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, buffer:%p", input, buffer);
- CAudioInput* inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
- if (inputHandle == NULL)
+ auto inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
+ if (!inputHandle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
inputHandle->peek(buffer, &_length);
}
int cpp_audio_in_drop(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
-
try {
- if (handle == NULL)
+ auto handle = static_cast<audio_io_s*>(input);
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p", input);
- CAudioInput* inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
- if (inputHandle == NULL)
+ auto inputHandle = static_cast<CAudioInput*>(handle->audioIoHandle);
+ if (!inputHandle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
inputHandle->drop();
}
int cpp_audio_in_set_state_changed_cb(audio_in_h input, audio_in_state_changed_cb callback, void* user_data) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL || callback == NULL)
+ if (!handle || !callback)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL input:%p, callback:%p", input, callback);
assert(handle->audioIoHandle);
handle->state_changed_callback.onStateChanged = callback;
handle->state_changed_callback.user_data = user_data;
- CAudioIO::SStateChangedCallback cb = handle->audioIoHandle->getStateChangedCallback();
+ auto cb = handle->audioIoHandle->getStateChangedCallback();
cb.mUserData = static_cast<void*>(handle);
cb.onStateChanged = __state_changed_cb_internal;
}
int cpp_audio_in_unset_state_changed_cb(audio_in_h input) {
- audio_io_s* handle = static_cast<audio_io_s*>(input);
+ auto handle = static_cast<audio_io_s*>(input);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", input);
assert(handle->audioIoHandle);
AUDIO_IO_LOGD("[%p]", handle);
- handle->state_changed_callback.onStateChanged = NULL;
- handle->state_changed_callback.user_data = NULL;
+ handle->state_changed_callback.onStateChanged = nullptr;
+ handle->state_changed_callback.user_data = nullptr;
- CAudioIO::SStateChangedCallback cb = handle->audioIoHandle->getStateChangedCallback();
- cb.mUserData = NULL;
- cb.onStateChanged = NULL;
+ auto cb = handle->audioIoHandle->getStateChangedCallback();
+ cb.mUserData = nullptr;
+ cb.onStateChanged = nullptr;
handle->audioIoHandle->setStateChangedCallback(cb);
} catch (CAudioError& e) {
* Audio Out
*/
int cpp_audio_out_create_new(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_out_h *output) {
- audio_io_s* handle = NULL;
+ audio_io_s* handle = nullptr;
try {
- if (output == NULL)
+ if (!output)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
__handle_safe_free(handle, (void *)output, true);
return __convert_CAudioError(e);
} catch (const std::bad_alloc&) {
-//LCOV_EXCL_START
- CAudioError e = CAudioError::EError::ERROR_OUT_OF_MEMORY;
+ CAudioError e(CAudioError::EError::ERROR_OUT_OF_MEMORY);
AUDIO_IO_LOGE("Failed to allocate handle");
__handle_safe_free(handle, (void *)output, true);
return __convert_CAudioError(e);
}
int cpp_audio_out_destroy(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
assert(handle->audioIoHandle);
return __convert_CAudioError(e);
}
- AUDIO_IO_LOGD("destroyed");
+ AUDIO_IO_LOGD("[%p] destroyed", handle);
return AUDIO_IO_ERROR_NONE;
}
int cpp_audio_out_set_sound_stream_info(audio_out_h output, sound_stream_info_h stream_info) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || stream_info == NULL)
+ if (!handle || !stream_info)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, stream_info:%p", output, stream_info);
assert(handle->audioIoHandle);
}
int cpp_audio_out_prepare(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
assert(handle->audioIoHandle);
}
int cpp_audio_out_unprepare(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
assert(handle->audioIoHandle);
}
int cpp_audio_out_pause(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
assert(handle->audioIoHandle);
}
int cpp_audio_out_resume(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
assert(handle->audioIoHandle);
}
int cpp_audio_out_drain(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
assert(handle->audioIoHandle);
}
int cpp_audio_out_flush(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p", output);
assert(handle->audioIoHandle);
}
int cpp_audio_out_write(audio_out_h output, void *buffer, unsigned int length) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
int ret = 0;
try {
- if (handle == NULL || buffer == NULL)
+ auto handle = static_cast<audio_io_s*>(output);
+ if (!handle || !buffer)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameter is NULL output:%p, buffer:%p", output, buffer);
assert(handle->audioIoHandle);
- CAudioOutput* outputHandle = static_cast<CAudioOutput*>(handle->audioIoHandle);
- if (outputHandle == NULL)
+ auto outputHandle = static_cast<CAudioOutput*>(handle->audioIoHandle);
+ if (!outputHandle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
- size_t written = outputHandle->write(buffer, static_cast<size_t>(length));
+ auto written = outputHandle->write(buffer, static_cast<size_t>(length));
ret = static_cast<int>(written);
#ifdef _AUDIO_IO_DEBUG_TIMING_
AUDIO_IO_LOGD("written:%zu", written);
}
int cpp_audio_out_get_buffer_size(audio_out_h output, int *size) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
-
try {
- if (handle == NULL || size == NULL)
+ auto handle = static_cast<audio_io_s*>(output);
+ if (!handle || !size)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, size:%p", output, size);
assert(handle->audioIoHandle);
- CAudioOutput* outputHandle = static_cast<CAudioOutput*>(handle->audioIoHandle);
- if (outputHandle == NULL)
+ auto outputHandle = static_cast<CAudioOutput*>(handle->audioIoHandle);
+ if (!outputHandle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
*size = outputHandle->getBufferSize();
}
int cpp_audio_out_get_sample_rate(audio_out_h output, int *sample_rate) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
-
try {
- if (handle == NULL || sample_rate == NULL)
+ auto handle = static_cast<audio_io_s*>(output);
+ if (!handle || !sample_rate)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, sample_rate:%p", output, sample_rate);
assert(handle->audioIoHandle);
}
int cpp_audio_out_get_channel(audio_out_h output, audio_channel_e *channel) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
-
try {
- if (handle == NULL || channel == NULL)
+ auto handle = static_cast<audio_io_s*>(output);
+ if (!handle || !channel)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, channel:%p", output, channel);
assert(handle->audioIoHandle);
- const CAudioInfo::EChannel srcChannel = handle->audioIoHandle->getAudioInfo().getChannel();
- audio_channel_e dstChannel = AUDIO_CHANNEL_MONO;
+ auto srcChannel = handle->audioIoHandle->getAudioInfo().getChannel();
+ auto dstChannel = AUDIO_CHANNEL_MONO;
__convert_audio_info_channel_2_channel(srcChannel, dstChannel);
*channel = dstChannel;
}
int cpp_audio_out_get_sample_type(audio_out_h output, audio_sample_type_e *type) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
-
try {
- if (handle == NULL || type == NULL)
+ auto handle = static_cast<audio_io_s*>(output);
+ if (!handle || !type)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, type:%p", output, type);
assert(handle->audioIoHandle);
- const CAudioInfo::ESampleType srcSampleType = handle->audioIoHandle->getAudioInfo().getSampleType();
- audio_sample_type_e dstSampleType = AUDIO_SAMPLE_TYPE_U8;
+ auto srcSampleType = handle->audioIoHandle->getAudioInfo().getSampleType();
+ auto dstSampleType = AUDIO_SAMPLE_TYPE_U8;
__convert_audio_info_sample_type_2_sample_type(srcSampleType, dstSampleType);
*type = dstSampleType;
}
int cpp_audio_out_get_sound_type(audio_out_h output, sound_type_e *type) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || type == NULL)
+ if (!handle || !type)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, type:%p", output, type);
assert(handle->audioIoHandle);
- const CAudioInfo::EAudioType srcAudioType = handle->audioIoHandle->getAudioInfo().getAudioType();
- sound_type_e dstSoundType = SOUND_TYPE_MEDIA;
+ auto srcAudioType = handle->audioIoHandle->getAudioInfo().getAudioType();
+ auto dstSoundType = SOUND_TYPE_MEDIA;
__convert_audio_info_audio_type_2_sound_type(srcAudioType, dstSoundType);
*type = dstSoundType;
}
int cpp_audio_out_set_stream_cb(audio_out_h output, audio_out_stream_cb callback, void* user_data) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || callback == NULL)
+ if (!handle || !callback)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, callback:%p", output, callback);
assert(handle->audioIoHandle);
handle->stream_callback.onStream = callback;
handle->stream_callback.user_data = user_data;
- CAudioIO::SStreamCallback cb = handle->audioIoHandle->getStreamCallback();
+ auto cb = handle->audioIoHandle->getStreamCallback();
cb.mUserData = static_cast<void*>(handle);
cb.onStream = __stream_cb_internal;
}
int cpp_audio_out_unset_stream_cb(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
assert(handle->audioIoHandle);
AUDIO_IO_LOGD("[%p]", handle);
- handle->stream_callback.onStream = NULL;
- handle->stream_callback.user_data = NULL;
+ handle->stream_callback.onStream = nullptr;
+ handle->stream_callback.user_data = nullptr;
- CAudioIO::SStreamCallback cb = handle->audioIoHandle->getStreamCallback();
- cb.mUserData = NULL;
- cb.onStream = NULL;
+ auto cb = handle->audioIoHandle->getStreamCallback();
+ cb.mUserData = nullptr;
+ cb.onStream = nullptr;
handle->audioIoHandle->setStreamCallback(cb);
} catch (CAudioError& e) {
}
int cpp_audio_out_set_state_changed_cb(audio_out_h output, audio_in_state_changed_cb callback, void* user_data) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL || callback == NULL)
+ if (!handle || !callback)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p, callback:%p", output, callback);
assert(handle->audioIoHandle);
handle->state_changed_callback.onStateChanged = callback;
handle->state_changed_callback.user_data = user_data;
- CAudioIO::SStateChangedCallback cb = handle->audioIoHandle->getStateChangedCallback();
+ auto cb = handle->audioIoHandle->getStateChangedCallback();
cb.mUserData = static_cast<void*>(handle);
cb.onStateChanged = __state_changed_cb_internal;
}
int cpp_audio_out_unset_state_changed_cb(audio_out_h output) {
- audio_io_s* handle = static_cast<audio_io_s*>(output);
+ auto handle = static_cast<audio_io_s*>(output);
try {
- if (handle == NULL)
+ if (!handle)
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT,
"Parameters are NULL output:%p", output);
assert(handle->audioIoHandle);
AUDIO_IO_LOGD("[%p]", handle);
- handle->state_changed_callback.onStateChanged = NULL;
- handle->state_changed_callback.user_data = NULL;
+ handle->state_changed_callback.onStateChanged = nullptr;
+ handle->state_changed_callback.user_data = nullptr;
- CAudioIO::SStateChangedCallback cb = handle->audioIoHandle->getStateChangedCallback();
- cb.mUserData = NULL;
- cb.onStateChanged = NULL;
+ auto cb = handle->audioIoHandle->getStateChangedCallback();
+ cb.mUserData = nullptr;
+ cb.onStateChanged = nullptr;
handle->audioIoHandle->setStateChangedCallback(cb);
} catch (CAudioError& e) {