#ifndef __USE_Video_H__
#define __USE_Video_H__
#include "com_video.h"
#include "api_c/mvideo_c.h"

static const rtc::MediaStats g_emptyMediaStats;
class Use_Video : public Com_Video
{
public:
	Q_OBJECT
public:
	 Use_Video(QWidget *parent = 0);
	~Use_Video();
public:
	AVDHandle getHandle() const { return module_; }
public:
	void onAttach(AVDHandle room);
	void onDetach();
protected:
	void updateLocalCameras();
	void updateRemotePublishedCameras();
	void fillResolutions();
protected: // c or cpp api imp
	bool   isAttach() const { return 0 != module_; }
	bool   api_engineSetOption(rtc::EngineOption option, void* value);
	bool   api_isSelfDevice(const rtc::DeviceId& dId) const;
	Result api_attachRender(const rtc::DeviceId& dId, IVideoView* view);
	Result api_detachRender(const rtc::DeviceId& dId);
	Result api_detachRender_1(IVideoView* view);
	Result api_subscribe(const rtc::DeviceId& dId);
	Result api_unsubscribe(const rtc::DeviceId& dId);
	Result api_muteLocalCamera(const rtc::DeviceId& dId);
	Result api_unmuteLocalCamera(const rtc::DeviceId& dId);
	Result api_publishLocalCamera(const rtc::Camera& cam);
	Result api_unpublishLocalCamera();
	Result api_previewLocalCamera(const rtc::DeviceId& dId);
	Result api_unpreviewLocalCamera();
	Result api_setVideoBitrate(const rtc::DeviceId& dId, int min, int max);
	Result api_changeCapability(const rtc::DeviceId& dId, const rtc::CameraCapability& cap);
	void   api_switchIndexvideo(int index);
	const rtc::MediaStats& getMediaStats();
	rtc::Camera api_getCamera(const rtc::DeviceId& dId);
public:
	/// video implementation
	static void s_onCameraStatusNotify(AVDHandle handle, AVDCameraStatus status, const char* fromId);
	static void s_onCameraDataNotify(AVDHandle handle, int level, const char* description, const char* fromId);
	static void s_onPublishCameraNotify(AVDHandle handle, const AVDCamera& camera);
	static void s_onUnpublishCameraNotify(AVDHandle handle, const AVDCamera& camera);
	static void s_onSubscribeResult(AVDHandle handle, Result result, const char* fromId);
	static void s_onUnsubscribeResult(AVDHandle handle, Result result, const char* fromId);
	static void s_onPublishLocalResult(AVDHandle handle, Result result, const char* fromId);
	static void s_onUnpublishLocalResult(AVDHandle handle, Result result, const char* fromId);
private:
	AVDHandle room_;
	AVDHandle usermanager_;
	AVDHandle module_;
	Video_Callback cb_module_;
	AVDHandle moduledevice_;
	VideoDevice_Callback cb_moduledevice_;
    rtc::MediaStats mediastats_;
};

#endif //__USE_Video_H__
