#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 */ }
+ void* mUserData {};
+ void (*onStream)(size_t nbytes, void* user_data) {};
+
+ 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 */ }
- };
-
- struct SInterruptCallback {
- void* mUserData;
- void (*onInterrupt)(IAudioSessionEventListener::EInterruptCode code, void* user_data);
-
- SInterruptCallback() : mUserData(NULL), onInterrupt(NULL)
- { /* Empty Body */ }
+ void* mUserData {};
+ void (*onStateChanged)(CAudioInfo::EAudioIOState state, CAudioInfo::EAudioIOState statePrev, bool byPolicy, void* user_data) {};
+
+ void set(void (*callback)(CAudioInfo::EAudioIOState, CAudioInfo::EAudioIOState, bool, void*), void* userdata) {
+ onStateChanged = callback;
+ mUserData = userdata;
+ }
+
+ void unset() {
+ onStateChanged = nullptr;
+ mUserData = nullptr;
+ }
};
/* Constructor & Destructor */
- CAudioIO();
- CAudioIO(CAudioInfo& audioInfo);
- virtual ~CAudioIO();
-
- /* Pure Virtual Methods */
- virtual void initialize() = 0;
- virtual void finalize() = 0;
-
- virtual void prepare() = 0;
- virtual void unprepare() = 0;
-
- virtual void pause() = 0;
- virtual void resume() = 0;
-
- virtual void drain() = 0;
- virtual void flush() = 0;
-
- virtual int getBufferSize() = 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);
+ virtual void onCorked(CPulseAudioClient* pClient, bool corked);
/* Methods */
+ 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;
+
CAudioInfo& getAudioInfo();
virtual void setStreamCallback(SStreamCallback callback);
virtual void setStateChangedCallback(SStateChangedCallback callback);
SStateChangedCallback getStateChangedCallback();
- void setInterruptCallback(SInterruptCallback callback);
- SInterruptCallback getInterruptCallback();
-
- void ignoreSession();
-
void setStreamInfo(sound_stream_info_h stream_info);
- void setInternalStreamInfo(); /* this is for session backward compatibility and will be removed later */
- static int sendInterrupt(void* user_data);
-
- CAudioInfo::EAudioIOState getState();
+ void setState(CAudioInfo::EAudioIOState state);
+ CAudioInfo::EAudioIOState getState() noexcept;
protected:
/* Protected Methods */
virtual bool isInit();
virtual bool IsReady();
- void internalLock();
- void internalUnlock();
- void internalSessionLock();
- void internalSessionUnlock();
- void internalWait();
- void internalSignal();
-
- bool isForceIgnore();
- bool isSessionEnabled();
-
- CAudioSessionHandler* mpAudioSessionHandler;
- CPulseAudioClient* mpPulseAudioClient;
+ CPulseAudioClient* mpPulseAudioClient {};
CAudioInfo mAudioInfo;
SStreamCallback mStreamCallback;
SStateChangedCallback mStateChangedCallback;
- SInterruptCallback mInterruptCallback;
- IAudioSessionEventListener::EInterruptCode mInterruptCode;
- CAudioInfo::EAudioDirection mDirection;
- CAudioInfo::EAudioIOState mState;
- CAudioInfo::EAudioIOState mStatePrev;
- bool mByPolicy;
- bool mIsInterrupted;
+ CAudioInfo::EAudioDirection mDirection { CAudioInfo::EAudioDirection::AUDIO_DIRECTION_MAX };
+ CAudioInfo::EAudioIOState mState { CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE };
+ CAudioInfo::EAudioIOState mStatePrev { CAudioInfo::EAudioIOState::AUDIO_IO_STATE_NONE };
+ bool mByPolicy {};
+ std::timed_mutex mMutex;
+ std::mutex mCondMutex;
+ std::condition_variable mCond;
private:
- pthread_mutex_t __mMutex;
- pthread_mutex_t __mSessionMutex;
- pthread_mutex_t __mCondMutex;
- pthread_cond_t __mCond;
- bool __mIsInit;
- bool __mForceIgnore;
-
- void abandonInternalFocus(); /* this is for session backward compatibility and will be removed later */
+ bool __mIsInit {};
};