#ifndef __COM_Video_H__
#define __COM_Video_H__
#include "ui_use_video.h"
#include "api/mvideo.h"
#include "dlg_videobitrates.h"
#include "videoview2.h"

class Com_Video :public QWidget
	, public rtc::IMVideo::IListener
	, public IGetMediaStats
{
public:
	Q_OBJECT
public:
	 Com_Video(QWidget *parent = 0);
	~Com_Video();
public:
	void onAttach();
	void onDetach();
protected:
	virtual void updateLocalCameras();
	virtual void updateRemotePublishedCameras();
	virtual void fillResolutions();
	void fillCodecs();
	rtc::CameraCapability getCurrentCapability();
	rtc::VideoCodec getCurrentCodec();
	rtc::Camera getSelectedCameraParams();
public slots:
	bool on_previewCamera(bool preview);
	bool on_publishCamera(bool pub);
	bool on_muteCamera(bool mute);
	void on_setBitrate();
	void on_changeCapbility();
	void on_showLocalBitrates();
	bool on_subscribeRemote(bool sub);
	bool on_attachRemote(bool attach);
    void on_localCameras_itemChanged();
protected:
    rtc::DeviceId getSelectedDeviceId(QListWidget* listw);
    int getRemoteCameraRowByDeviceId(const rtc::DeviceId& deviceId, bool remove);
	void resetControls(bool enable);

protected: // c or cpp api imp
	virtual bool   isAttach() const = 0;
	virtual bool   api_engineSetOption(rtc::EngineOption option, void* value) = 0;
    virtual bool   api_isSelfDevice(const rtc::DeviceId& dId) const = 0;
    virtual Result api_attachRender(const rtc::DeviceId& dId, IVideoView* view) = 0;
    virtual Result api_detachRender(const rtc::DeviceId& dId) = 0;
    virtual Result api_detachRender_1(IVideoView* view) = 0;
    virtual Result api_subscribe(const rtc::DeviceId& dId) = 0;
    virtual Result api_unsubscribe(const rtc::DeviceId& dId) = 0;
    virtual Result api_muteLocalCamera(const rtc::DeviceId& dId) = 0;
    virtual Result api_unmuteLocalCamera(const rtc::DeviceId& dId) = 0;
    virtual Result api_publishLocalCamera( rtc::Camera& cam) = 0;
	virtual Result api_unpublishLocalCamera() = 0;
    virtual Result api_previewLocalCamera(const rtc::DeviceId& dId) = 0;
	virtual Result api_unpreviewLocalCamera() = 0;
    virtual Result api_setVideoBitrate(const rtc::DeviceId& dId, int min, int max) = 0;
    virtual Result api_changeCapability(const rtc::DeviceId& dId, const rtc::CameraCapability& cap) = 0;
	virtual void   api_switchIndexvideo(int index) = 0;
	virtual const rtc::MediaStats& getMediaStats() = 0;
    virtual rtc::Camera api_getCamera(const rtc::DeviceId& dId) = 0;

public:
	/// IVideo::IListener implementation
    virtual void onCameraStatusNotify(rtc::CameraStatus status, const rtc::DeviceId& fromId);
    virtual void onCameraDataNotify(int level, const rtc::String& description, const rtc::DeviceId& fromId);
	virtual void onPublishCameraNotify(const rtc::Camera& camera);
	virtual void onUnpublishCameraNotify(const rtc::Camera& camera);
    virtual void onSubscribeResult(Result result, const rtc::DeviceId& fromId);
    virtual void onUnsubscribeResult(Result result, const rtc::DeviceId& fromId);
    virtual void onPublishLocalResult(Result result, const rtc::DeviceId& fromId);
    virtual void onUnpublishLocalResult(Result result, const rtc::DeviceId& fromId);
        virtual void onCameraCapabilityNotify(const rtc::DeviceId& fromId, const uint32 width, const uint32 height, const uint32 fps) ;

protected:
	Ui::Use_Video ui;
    IVideoView* localview_;
    IVideoView* remoteview_;
    rtc::DeviceId curLocalId_;
	bool		   smallCapbility_;
    rtc::DeviceId curRemoteId_;
	//
	Dlg_VideoBitrates dlg_localvb_;
};

#endif //__COM_Video_H__
