#ifndef __USE_Audio_H__
#define __USE_Audio_H__
#include "com_audio.h"
#include "api_c/maudio_c.h"

class Use_Audio :public Com_Audio
{
public:
	Q_OBJECT
public:
	 Use_Audio(QWidget *parent = 0);
	~Use_Audio();
public:
	AVDHandle getHandle() const { return module_; }
public:
	void onAttach(AVDHandle room);
	void onDetach(); 
protected:
	void updateLocalMicrophones();
	void updateLocalSpeakers();
protected: // c or cpp api imp
	bool   isAttach() const { return 0 != module_; }
	bool   api_engineSetOption(rtc::EngineOption option, void* value);
	bool   api_roomSetOption(rtc::RoomOption option, std::string& value);
	Result api_openMicrophone(bool open);
	Result api_muteMicrophone(bool mute);
	Result api_muteSpeaker(bool mute);
	Result api_monitorAudioLevel(bool enable);
	Result api_setRecordingMicrophone(const rtc::DeviceId& curId);
	Result api_setPlayoutSpeaker(const rtc::DeviceId& curId);
	Result api_applyPlayoutGain(float gain);
public:
	/// audio implementation
	static void s_onMicrophoneStatusNotify(AVDHandle handle, AVDMicrophoneStatus status, const char* fromUserId);
	static void s_onAudioLevelMonitorNotify(AVDHandle handle, const AVDAudioInfo& info);
	static void s_onOpenMicrophoneResult(AVDHandle handle, Result result);
	static void s_onCloseMicrophoneResult(AVDHandle handle, Result result);

private:
	AVDHandle room_;
	AVDHandle module_;
	Audio_Callback cb_module_;
	AVDHandle moduledevice_;
	AudioDevice_Callback cb_moduledevice_;
};

#endif //__USE_Audio_H__
