#ifndef __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__
#define __TIZEN_MEDIA_AUDIO_IO_CAUDIO_IO_H__
-
#ifdef __cplusplus
+#include <sound_manager.h>
+#include <mutex>
+#include <condition_variable>
namespace tizen_media_audio {
* You can't take this object directly.
*/
class IPulseStreamListener;
- class IAudioSessionEventListener;
- class CAudioIO : public IPulseStreamListener, public IAudioSessionEventListener {
+ class CAudioIO : public IPulseStreamListener {
public:
struct SStreamCallback {
void* mUserData;
void (*onStream)(size_t nbytes, void* user_data);
- SStreamCallback() : mUserData(NULL), onStream(NULL)
- { /* Empty Body */ }
+ SStreamCallback() : mUserData(nullptr), onStream(nullptr) {
+ /* Empty Body */
+ }
+
+ void set(void (*callback)(size_t, void*), void* userdata) {
+ onStream = callback;
+ mUserData = userdata;
+ }
+
+ void unset() {
+ onStream = nullptr;
+ mUserData = nullptr;
+ }
};
struct SStateChangedCallback {
void* mUserData;
void (*onStateChanged)(CAudioInfo::EAudioIOState state, CAudioInfo::EAudioIOState statePrev, bool byPolicy, void* user_data);
- SStateChangedCallback() : mUserData(NULL), onStateChanged(NULL)
- { /* Empty Body */ }
- };
+ SStateChangedCallback() : mUserData(nullptr), onStateChanged(nullptr) {
+ /* Empty Body */
+ }
- struct SInterruptCallback {
- void* mUserData;
- void (*onInterrupt)(IAudioSessionEventListener::EInterruptCode code, void* user_data);
+ void set(void (*callback)(CAudioInfo::EAudioIOState, CAudioInfo::EAudioIOState, bool, void*), void* userdata) {
+ onStateChanged = callback;
+ mUserData = userdata;
+ }
- SInterruptCallback() : mUserData(NULL), onInterrupt(NULL)
- { /* Empty Body */ }
+ void unset() {
+ onStateChanged = nullptr;
+ mUserData = nullptr;
+ }
};
/* Constructor & Destructor */
CAudioIO();
- CAudioIO(CAudioInfo& audioInfo);
- virtual ~CAudioIO();
-
- /* Pure Virtual Methods */
- virtual void initialize() throw(CAudioError) = 0;
- virtual void finalize() = 0;
-
- virtual void prepare() throw(CAudioError) = 0;
- virtual void unprepare() throw(CAudioError) = 0;
-
- virtual void pause() throw(CAudioError) = 0;
- virtual void resume() throw(CAudioError) = 0;
-
- virtual void drain() throw(CAudioError) = 0;
- virtual void flush() throw(CAudioError) = 0;
-
- virtual int getBufferSize() throw(CAudioError) = 0;
+ explicit CAudioIO(CAudioInfo& audioInfo);
+ virtual ~CAudioIO() = default;
/* Implemented Handlers */
virtual void onStream(CPulseAudioClient* pClient, size_t length);
virtual void onStateChanged(CAudioInfo::EAudioIOState state, bool byPolicy);
virtual void onStateChanged(CAudioInfo::EAudioIOState state);
- virtual void onInterrupt(CAudioSessionHandler* pHandler, int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info);
- virtual void onSignal(CAudioSessionHandler* pHandler, mm_sound_signal_name_t signal, int value);
/* Methods */
- CAudioInfo& getAudioInfo() throw(CAudioError);
+ virtual void initialize();
+ virtual void finalize();
+ virtual void prepare();
+ virtual void unprepare();
+ virtual void pause();
+ virtual void resume();
+ virtual void flush();
+ virtual int getBufferSize() = 0;
- virtual void setStreamCallback(SStreamCallback callback) throw(CAudioError);
- SStreamCallback getStreamCallback() throw(CAudioError);
+ CAudioInfo& getAudioInfo();
- virtual void setStateChangedCallback(SStateChangedCallback callback) throw(CAudioError);
- SStateChangedCallback getStateChangedCallback() throw(CAudioError);
+ virtual void setStreamCallback(SStreamCallback callback);
+ SStreamCallback getStreamCallback();
- void setInterruptCallback(SInterruptCallback callback) throw(CAudioError);
- SInterruptCallback getInterruptCallback() throw(CAudioError);
+ virtual void setStateChangedCallback(SStateChangedCallback callback);
+ SStateChangedCallback getStateChangedCallback();
- void ignoreSession() throw(CAudioError);
+ void setStreamInfo(sound_stream_info_h stream_info);
+
+ CAudioInfo::EAudioIOState getState() noexcept;
protected:
/* Protected Methods */
virtual bool isInit();
virtual bool IsReady();
- void internalLock() throw(CAudioError);
- void internalUnlock() throw(CAudioError);
- void internalWait() throw(CAudioError);
- void internalSignal() throw(CAudioError);
-
- bool isForceIgnore();
-
- CAudioSessionHandler* mpAudioSessionHandler;
CPulseAudioClient* mpPulseAudioClient;
CAudioInfo mAudioInfo;
SStreamCallback mStreamCallback;
SStateChangedCallback mStateChangedCallback;
- SInterruptCallback mInterruptCallback;
+ CAudioInfo::EAudioDirection mDirection;
CAudioInfo::EAudioIOState mState;
CAudioInfo::EAudioIOState mStatePrev;
bool mByPolicy;
+ std::mutex mMutex;
+ std::mutex mCondMutex;
+ std::condition_variable mCond;
private:
- pthread_mutex_t __mMutex;
- pthread_cond_t __mCond;
bool __mIsInit;
- bool __mForceIgnore;
};