// VCDemoDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "VCDemo.h"
#include "VCDemoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// 对话框数据
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};


CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CVCDemoDlg 对话框




CVCDemoDlg::CVCDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CVCDemoDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	pPlayCameraNode=NULL;
	m_logEvt=NULL;
	m_pPlayer=NULL;
	m_pImgList=NULL;
	m_plogObj=NULL;	
	nPlayVideoType=1;
	nPtzOk=0;
	ptzDevId="";
	m_bInviteVideoFinish=1;
	m_bIsTalkIng=0;
	m_bIsBroadCasting=0;
}


void CVCDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_DEVTREE, m_DevTree);
	DDX_Control(pDX, IDC_PRESETLIST, m_prestList);
	DDX_Control(pDX, IDC_ALARMLIST, m_alarmList);
}

BEGIN_MESSAGE_MAP(CVCDemoDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_WM_DESTROY()
	ON_NOTIFY(NM_DBLCLK, IDC_DEVTREE, &CVCDemoDlg::OnNMDblclkDevtree)
	ON_BN_CLICKED(IDC_AUDIO, &CVCDemoDlg::OnBnClickedAudio)
	ON_BN_CLICKED(IDC_VIEWPRE, &CVCDemoDlg::OnBnClickedViewpre)
	ON_BN_CLICKED(IDC_PTZINIT, &CVCDemoDlg::OnBnClickedPtzinit)
	ON_BN_CLICKED(IDC_SETCAPTURE, &CVCDemoDlg::OnBnClickedSetcapture)
	ON_BN_CLICKED(IDC_CHANGEVIDEO, &CVCDemoDlg::OnBnClickedChangevideo)
	ON_BN_CLICKED(IDC_STOPPLAY, &CVCDemoDlg::OnBnClickedStopplay)
	ON_BN_CLICKED(IDC_RECORDPLAYER, &CVCDemoDlg::OnBnClickedRecordplayer)
	ON_BN_CLICKED(IDC_RECORDFILE, &CVCDemoDlg::OnBnClickedRecordfile)
	ON_BN_CLICKED(IDC_DJ, &CVCDemoDlg::OnBnClickedDj)
	ON_BN_CLICKED(IDC_GB, &CVCDemoDlg::OnBnClickedGb)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON3, &CVCDemoDlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_ZOOMUP, &CVCDemoDlg::OnBnClickedZoomup)
	ON_BN_CLICKED(IDC_ZOOMDOWN, &CVCDemoDlg::OnBnClickedZoomdown)
END_MESSAGE_MAP()





CVCDemoDlg::~CVCDemoDlg()
{
	if(m_pPlayer)
	{
		delete m_pPlayer;
		m_pPlayer=NULL;
	}
	if(m_logEvt)
	{
		delete m_logEvt;
		m_logEvt=NULL;
	}
	if(m_pImgList)
	{
		m_pImgList->DeleteImageList();
		delete m_pImgList;
		m_pImgList=NULL;
	}
}





// CVCDemoDlg 消息处理程序

BOOL CVCDemoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标


	
	HRESULT	hres=m_plogObj.CreateInstance(CLSID_PlatInterActive);//
	if( FAILED( hres ) )
	{
		MessageBox(_T("创建通信控件失败!"));
		this->EndDialog(0);
		return TRUE;
	}
	if(m_logEvt==NULL)
	{
		m_logEvt=new CIPlatInterActiveEvent(this);
	}
	m_logEvt->DispEventAdvise(m_plogObj);
	if(m_pPlayer==NULL)
	{
		m_pPlayer=new CTPPlayerAtl();
	}
	if(m_pPlayer)
	{
		RECT rect;
		rect.left=190;
		rect.top=30;
		rect.right=720+rect.left;
		rect.bottom=560+rect.top;
		BOOL res=m_pPlayer->Create(AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW |CS_DBLCLKS | CS_PARENTDC,this->m_hIcon,0,0)
			,NULL,WS_VISIBLE | WS_CHILD ,rect,this,0);
		if(!res)
		{
			MessageBox(_T("创建播放控件失败!"));
			this->EndDialog(0);
			return TRUE;
		}
		HWND hWnd = m_pPlayer->Detach();//必须这样做，才能处理鼠标事件
		m_pPlayer->SubclassWindow(hWnd);
		m_pPlayer->MoveWindow(rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE);//改变窗口位置
		m_pPlayer->ShowWindow(SW_SHOW);
	}
	m_loginForm.m_parent=this;
	this->m_loginForm.DoModal();
	if(!m_loginForm.m_HaveLogin)
	{
		this->EndDialog(0);
		return TRUE;
	}

	m_pImgList=new CImageList(); 
	if(m_pImgList!=NULL)
	{
		m_pImgList->Create(IDB_DEVSTATUSIMG,16,11,RGB(255,0,255));
		m_DevTree.SetImageList(m_pImgList,TVSIL_NORMAL);
	}

	m_alarmList.InsertColumn(0,_T("类型"),0,60);
	m_alarmList.InsertColumn(1,_T("信息"),0,120);
	::SetTimer(NULL,100,500,NULL);


	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void CVCDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CVCDemoDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标显示。
//
HCURSOR CVCDemoDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CVCDemoDlg::OnDestroy()
{
	if(m_pPlayer && m_pPlayer->get_IsRecording())
	{
		SetDlgItemText(IDC_RECORDFILE,_T("开始录像"));
		m_pPlayer->StopRecord();
	}
	if(m_pPlayer)
	{
		m_pPlayer->StopWithOutWait();
	}
	if(m_logEvt && m_plogObj)
	{
		m_plogObj->LogoutPlat();		
	}
	if (m_plogObj != NULL || m_plogObj.GetInterfacePtr() != NULL) 
	{
		m_logEvt->DispEventUnadvise(m_plogObj);
		m_plogObj.Release();
		m_plogObj = NULL;
	}
	m_DevTree.DeleteAllItems();
	CDialog::OnDestroy();
}


int CVCDemoDlg::ReloadDeviceList(_bstr_t & strXml)
{
		

	int count=0;
	m_devListDoc.Clear();
	m_devListDoc.Parse(strXml);
	devtreemap.clear();
	if(!m_devListDoc.Error())
	{//可以解释  
		m_DevTree.DeleteAllItems();
		TiXmlNode * groupnode=m_devListDoc.RootElement()->FirstChild();//.SelectNode("DevGroup");
		while(groupnode)
		{//<DevGroup Id="860021289896099" Name="第二组高清（355）设备"  DomainId="86002"  >
			const char * groupname=groupnode->ToElement()->Attribute("Name");
			HTREEITEM hGroupItem=m_DevTree.InsertItem(_bstr_t(groupname),NULL,NULL);
			m_DevTree.SetItemData(hGroupItem,(DWORD_PTR)groupnode);
			TiXmlNode * mastrenode=groupnode->FirstChild();
			while(mastrenode)
			{//<Master Id="86002M1289896122" Name="高清88195"  Type="3" GroupId="860021289896099" 
				//DomainId="86002" DevCount="1"  DeviceState="0"  IpAddr="0"  CommPort="1024"  
				//LoginName="admin"  LoginPassword="123456"  PTZRight="1"  SURVEILRight="1"  VideoReplayRight="0" 
				//AudioControlRight="1"  BCControlRight="1"  AlarmMngRight="0"  >
				TiXmlNode * cameranode=mastrenode->FirstChild();
				if(cameranode!=NULL)
				{
					const char * mastername=cameranode->ToElement()->Attribute("Name");
					HTREEITEM hParent=m_DevTree.InsertItem(_bstr_t(mastername),hGroupItem,NULL);
					m_DevTree.SetItemImage(hParent,1,1);
					m_DevTree.SetItemData(hParent,(DWORD_PTR)mastrenode);
					_bstr_t mdevid=_bstr_t(mastrenode->ToElement()->Attribute("Id"))+"_m";
					devtreemap[mdevid]=hParent;
					while(cameranode)
					{//<Camera Id="86002S1289896136" Name="IPC88195"  MasterId="86002M1289896122" Type="1"  IsDoubleStream="1"
						//WithPTZ="1"  WithAudioIn="1" WithAudioOut="1"  VSSId="3" ConnType="2"  MFSCmdIP="0" MFSCmdPort="0" 
						//VSSCmdIP="-2074564416" VSSCmdPort="554"  VisitStreamOption="0"  IpAddr="0"  CommPort="1024" 
						//LoginName="admin"  LoginPassword="123456" />
						const char * szCameraName=cameranode->ToElement()->Attribute("Name");
						HTREEITEM hCamearItem=m_DevTree.InsertItem(_bstr_t(szCameraName),hParent,NULL);
						m_DevTree.SetItemData(hCamearItem,(DWORD_PTR)cameranode);
						m_DevTree.SetItemImage(hCamearItem,6,6);
						count++;
						_bstr_t devid=_bstr_t(cameranode->ToElement()->Attribute("Id"))+"_c";
						devtreemap[devid]=hCamearItem;
						cameranode=cameranode->NextSibling();
					}
				}
				mastrenode=mastrenode->NextSibling();
			}
			groupnode=groupnode->NextSibling();
		}
	}
	if(count>0)
	{//更新状态
		UpdateDevListStatus();
	}
	
	return count;
}



int CVCDemoDlg::UpdateDevListStatus()
{
	_bstr_t devlist=m_plogObj->GetDeviceState(_T(""));
	//"<Response Code="83" DeviceState="{755000001:2,755000011:2,755000021:2,755000031:0,755000041:0,755000051:2,755000061:0,755010001:1,755010011:1,0:0}"  Result ="0"/>"
	CStringArray ret;
	TiXmlDocument doc;
	doc.Parse(devlist);
	if(!doc.Error())
	{
		const char * data=doc.FirstChildElement()->Attribute("DeviceState");
		if(data!=NULL && strlen(data)>2)
		{
			_bstr_t tempstr(data);
			char * pData=(char *)tempstr;
			int len=strlen(pData);
			*(pData+len-1)=0;//去掉最后一个字符
			pData++;//去掉第一个字符
			_bstr_t DevStatusData=pData;
			int itemcount=Split(DevStatusData,",",1,ret);
			if(itemcount>1)
			{//说明有节点
				for(int idx=0;idx<itemcount;idx++)
				{
					CStringArray devLs;
					int retItemC=Split(_bstr_t(ret[idx]),":",1,devLs);
					if(retItemC>=2)
					{//
						_bstr_t seldevid=devLs[0];
						seldevid=seldevid+"_m";
						HTREEITEM hItem=devtreemap[seldevid];
						if(hItem!=NULL)
						{
							int value=atol(_bstr_t(devLs[1]));
							int imgidx=6;
							switch(value)
							{
								case 0:
								{
									imgidx=6;
									//imgurl="resources/images/camera/notconnect.gif";
								}
								break;
								case 1:
								{
									imgidx=6;
									//imgurl="resources/images/camera/offline.gif";
								}
								break;
								case 2:
								{
									imgidx=3;
									//imgurl="resources/images/camera/online.gif";
								}
								break;
								default:
								{
									imgidx=6;
									//imgurl="resources/images/camera/offline.gif";
								}
							}
							HTREEITEM hChild=m_DevTree.GetChildItem(hItem);
							while(hChild)
							{
								m_DevTree.SetItemImage(hChild,imgidx,imgidx);
								hChild=m_DevTree.GetNextSiblingItem(hChild);
							}
						}
					}
				}
			}
		}
	}
	return -1;
}




int CVCDemoDlg::OnPlayVieo(_bstr_t & strXml)
{
	//<Response Code="81" nFsmType="1" MediaType="257" DevId="86002S1289896254" nRecordState="0" 
	//	LocalPort="31621" MulticastIP="0" MulticastPort="0" MediaSendPort="59999" VideoParamLen="316" 
	//	VideoParam="d==" AudioParamLen="56" AudioParam="d=" ConnType="0" nTransPro="1" 
	//	SrcInst="2835" VSSCmdIP="-2074564416" VSSCmdPort="554" MFSCmdIP="0" MFSCmdPort="0"  Result ="0"/>

		TiXmlDocument doc;
		doc.Parse(strXml);			
		TiXmlElement * item=doc.FirstChildElement();
		const char * DevId=item->Attribute("DevId");//播放的设备ID
		const char * Result=item->Attribute("Result");//成功时，此值为0,否则为错误代码
		if(atol(Result)!=0)
		{
			MessageBox(_T("申请视频流失败!"),_T("申请失败"));
			return -1;
		}
		const char * VideoParam=item->Attribute("VideoParam");//视频解码参数
		const char * VideoParamLen=item->Attribute("VideoParamLen");//视频解码参数长度
		const char * nTransPro=item->Attribute("nTransPro");//是否为TCP连接，如果为１则表示为ＴＣＰ，调用m_pPlayer->SetConnectType进行设置
		const char * LocalPort=item->Attribute("LocalPort");//视频端口
		const char * VSSCmdIP=item->Attribute("VSSCmdIP");//视频流vss服务器ip
		const char * VSSCmdPort=item->Attribute("VSSCmdPort");//vss端口
		const char * SrcInst=item->Attribute("SrcInst");//唯一标识符
		const char * ConnType=item->Attribute("ConnType");//
		const char * szMediaType=item->Attribute("MediaType");////0x0101 后面是视频，前面是音频
		const char * AudioParam=item->Attribute("AudioParam");
		const char * AudioParamLen=item->Attribute("AudioParamLen");
		const char * szMcastIP=item->Attribute("MulticastIP");//组播放IP
		const char * szMulticastPort	=item->Attribute("MulticastPort");//组播端口
		const char * szFsmType	=item->Attribute("nFsmType"); //1不是组播放，２是组播
		int ErrorCode;

		int nConnectType=atol(ConnType);
        if(nConnectType==0)
        {//连接vss服务器查看视频
            
        }else if(nConnectType==1)
        {//连接mfs服务器查看视频
            //HeartBeatIP=parseInt(treenode.attributes["MFSCmdIP"]);
			VSSCmdIP=item->Attribute("MFSCmdIP");//视频流vss服务器ip
        }else  if(nConnectType==2)
        {//直接连接ipc,此类型暂时不会出现

        }

		if(atol(ConnType)==1)
		{//
			VSSCmdIP=item->Attribute("MFSCmdIP");//打洞IP
		}
		const char * MediaSendPort=item->Attribute("MediaSendPort");//打洞端口 
		int videoport=atol((char *)(LocalPort));
		int vssip=atol((char *)(VSSCmdIP));
		int vssport=atol((char *)(VSSCmdPort));
		int iSrcInst=atol((char *)(SrcInst));
		int iVideoParamLen=atol((char *)(VideoParamLen));
		int iMediaSendPort=atol((char *)(MediaSendPort));		
        if (atol(nTransPro) != 0)
        {//为TCP连接
           ErrorCode=m_pPlayer->SetConnectType(1);
        }
        else
        {//UDP连接
            ErrorCode=m_pPlayer->SetConnectType(0);
        }
		m_pPlayer->Stop();
		if(iVideoParamLen<=0)
		{
			return -2;
		}
		ErrorCode=m_pPlayer->SetupDecode(_bstr_t(VideoParam),iVideoParamLen,0);//设置视频解码参数

		int mediatype=atol(szMediaType);////0x0101 后面是视频，前面是音频
		if((mediatype & 0x0100)!=0)
		{//有音频
			int iaudioParamLen=atol(AudioParamLen);
			if(iaudioParamLen>0)
			{//音频参数存在
				ErrorCode=m_pPlayer->SetupDecode(_bstr_t(AudioParam),iaudioParamLen,1);//设置音频解码参数
			}
		}
		int nMulticastIP=0;
		if (atol(nTransPro) == 0)
		{//upd播放时，要播放是否为组播放
			if(atol(szFsmType)==2)
			{//为组播，则视频端口是改成组播IP
				nMulticastIP=atol(szMcastIP);
				videoport=atol(szMulticastPort);//组播端口
			}
		}
		m_bInviteVideoFinish=1;//标记不用再新请求
		ErrorCode=m_pPlayer->SetVideoParameter(nMulticastIP,videoport,vssip,iMediaSendPort,iSrcInst);//设置收流参数
		ErrorCode=m_pPlayer->Play();//启动播放

		if((mediatype & 0x0100)!=0)
		{//有音频
			ErrorCode=m_pPlayer->SetAudioOn(1);
			SetDlgItemText(IDC_AUDIO,_T("停止声音"));
		}else
		{
			ErrorCode=m_pPlayer->SetAudioOn(0);
			SetDlgItemText(IDC_AUDIO,_T("播放声音"));
		}
		return 0;
}






int CVCDemoDlg::OnInterfaceXMLResp(LONG nCode,LONG nParam, BSTR strXml)
{
	if(nCode==33)
	{//收到视频列表
		int ReadCameraCount=ReloadDeviceList(_bstr_t(strXml));//显示设备列表
	}else if(nCode==81)
	{//播放视频事件
		OnPlayVieo(_bstr_t(strXml));//处理播放
	}else if(nCode==92)
	{//云台预置点信息 <Response Code="92" IPCID="" DataLen="0" PTZResponse=""  Result ="20503"/>
		{
			if(lastPresetMsg!=_bstr_t(strXml))
			{//和上次一样的话，则不更新
				lastPresetMsg=strXml;
				TiXmlDocument doc;
				doc.LoadFromString(_bstr_t(strXml));
				if(!doc.Error())
				{
					const char * ptzmsg=doc.FirstChildElement()->Attribute("PTZResponse");
					TiXmlDocument doc2;
					doc2.LoadFromString(_bstr_t(ptzmsg));				
					if(!doc2.Error())
					{
						//<?xml version="1.0" encoding="GB2312" ?>
						//<XML_TOPSEE><MESSAGE_HEADER Msg_type="PTZ_CONTROL_MESSAGE" Msg_code="PTZ_CMD" Msg_flag="0" />
						//<MESSAGE_BODY>1^o8#00:00-24:00^</MESSAGE_BODY></XML_TOPSEE>
						TiXmlNode * node=doc2.FirstChildElement();
						if(node!=NULL)
						{//取预置点
							TiXmlNode * datanode=node->SelectNode("MESSAGE_BODY");
							if(datanode)
							{//1^o8#00:00-24:00^
								const char * data=node->ToElement()->GetNodeText("MESSAGE_BODY");
								CStringArray ret;
								int count=Split(_bstr_t(data),"^",1,ret);
								if(count>1)
								{//有节点
									m_prestList.ResetContent();
									for(int idx=1;idx<count;idx++)
									{
										CStringArray nodels;
										int nodecount=Split(_bstr_t(ret[idx]),"#",1,nodels);
										if(nodecount==1)
										{//只有一个节点，则为预置点
											m_prestList.InsertString(idx-1,nodels[0]);
										}else if(nodecount==2)
										{//是规则，o8#00:00-24:00，这里不处理

										}
									}
								}
							}
						}
					}
				}
			}
		}
	}else if(nCode==226)
	{//下载并转换成功 <Response Code="226" sDatFile=""   sAviFile=""  Result "" /> 

	}else if(nCode==220)
	{//CodeIpcFileUploadStatus = 220,//<0失败，0～100进度,上传进度 <Response Code=""  DevId=""  FilePath="" Progress="" Result ="" />

	}else if(nCode==224)
	{//CodeFileDownloadStatus = 224,//<0失败，0～100进度,下载进度 <Response Code=""  DevId=""  FilePath="" Progress="" Result ="" />

	}else if(213==nCode)
	{////云台被抢占或视频被抢占
		MessageBox(strXml,_T("云台被抢占或视频被抢占"));
		nPtzOk=0;//云台不能控制
	}else if(225==nCode)
	{//设备状态改变 <Response Code="225"  DevId="devid"  State=""  Result ="0" />
		{//<Response Code="225"  DevId="devid"  State=""  Result ="0" />
			TiXmlDocument doc;
			doc.LoadFromString(_bstr_t(strXml));
			if(!doc.Error())
			{//状态更新
				const char * devid=doc.FirstChildElement()->Attribute("DevId");
				const char * status=doc.FirstChildElement()->Attribute("State");
				int iStatus=atol(status);
				_bstr_t bsdevid=_bstr_t(devid)+"_c";
				HTREEITEM hItem=devtreemap[bsdevid];//=hCamearItem;
				if(hItem!=NULL)
				{//找到节点
					int imgidx=6;
					switch(iStatus)
					{
						case 0:
						{
							imgidx=6;
							//imgurl="resources/images/camera/notconnect.gif";
						}
						break;
						case 1:
						{
							imgidx=6;
							//imgurl="resources/images/camera/offline.gif";
						}
						break;
						case 2:
						{
							imgidx=3;
							//imgurl="resources/images/camera/online.gif";
						}
						break;
						default:
						{
							imgidx=6;
							//imgurl="resources/images/camera/offline.gif";
						}
						break;
					}
					//m_DevTree.SetItemImage(hItem,imgidx,imgidx);
					HTREEITEM hChild=m_DevTree.GetChildItem(hItem);
					while(hChild)
					{
						m_DevTree.SetItemImage(hChild,imgidx,imgidx);
						hChild=m_DevTree.GetNextSiblingItem(hChild);
					}
				}
			}
		}
	}else if(203==nCode)
	{//实时事件		
		if(m_alarmList.GetItemCount()>10)
		{
			m_alarmList.DeleteItem(m_alarmList.GetItemCount()-1);
		}
		{//<Response Code="203" DevId="86002S1289895787" Timestamp="1290059404" Type="7" Description="/mnt/mmc0/motion/2010/11/18/135004-av-1.avi"  Result ="0"/>
			_bstr_t typemsg="事件";
			_bstr_t alarmmsg;
			TiXmlDocument doc;
			doc.LoadFromString(_bstr_t(strXml));
			if(!doc.Error())
			{
				typemsg=typemsg+doc.FirstChildElement()->Attribute("Type");
				alarmmsg=doc.FirstChildElement()->Attribute("Description");
				int idx=m_alarmList.InsertItem(0,typemsg);
				m_alarmList.SetItemText(idx,1,alarmmsg);
			}
		}
	}else if(204==nCode)
	{//实时报警		
		if(m_alarmList.GetItemCount()>10)
		{
			m_alarmList.DeleteItem(m_alarmList.GetItemCount()-1);
		}
		{//<Response Code="204" DevId="860000062" Timestamp="1290058889" Type="260" IsRaise="1" AlarmLevel="1" Description="Video input lost"  Result ="0"/>
			_bstr_t typemsg="报警";
			_bstr_t alarmmsg;
			TiXmlDocument doc;
			doc.LoadFromString(_bstr_t(strXml));
			if(!doc.Error())
			{
				typemsg=typemsg+doc.FirstChildElement()->Attribute("Type");
				alarmmsg=doc.FirstChildElement()->Attribute("Description");
				int idx=m_alarmList.InsertItem(0,typemsg);
				m_alarmList.SetItemText(idx,1,alarmmsg);
			}
		}
	}else if(nCode==91)
	{//云台申请成功响应<Response Code="91" CameraId="755000012" Result ="0"/> 
		TiXmlDocument doc;
		_bstr_t xml(strXml);
		doc.Parse(xml);
		TiXmlElement * item=doc.FirstChildElement();
		if(item)
		{
			nPtzOk=1;//云台成功		
			ptzDevId=item->Attribute("CameraId");//播放的设备ID
			SendCmd("<xml>\n<cmd>GetPresetList</cmd>\n</xml>");
			MessageBox(_T("请求云台控制成功"),ptzDevId);
		}else
		{
			MessageBox(strXml,_T("申请云台控制返回成功，但取ID失败"));
			nPtzOk=1;//云台失败	
			ptzDevId="";
		}
	}else if(nCode==92)
	{//云台申请失败
		nPtzOk=0;
		ptzDevId="";
		MessageBox(strXml,_T("申请云台控制失败"));
	}else if(nCode==141 || nCode==145 || nCode==149)
	{//录像查询结果
		m_SearchDlg.OnRecaLoginXml(nCode,strXml);
	}
	return S_OK;
}




int CVCDemoDlg::OnInterfaceDataResp(LONG nCode,BYTE* byteData)
{

	return S_OK;
}



//双击节点
void CVCDemoDlg::OnNMDblclkDevtree(NMHDR *pNMHDR, LRESULT *pResult)
{
	*pResult = 0;
	HTREEITEM hItem=m_DevTree.GetSelectedItem();
	if(hItem==NULL)
	{//没有选上
		return ;
	}
	TiXmlNode * node=(TiXmlNode *)m_DevTree.GetItemData(hItem);
	if(node && m_pPlayer)
	{//如果是双击到子设备，则进行播放
		TiXmlElement * nodeElm=node->ToElement();
		_bstr_t itemName=_bstr_t(nodeElm->Value());
		if(itemName==_bstr_t("Camera"))
		{//<Camera Id="86002S1289896136" Name="IPC88195"  MasterId="86002M1289896122" Type="1"  IsDoubleStream="1" 
			//WithPTZ="1"  WithAudioIn="1" WithAudioOut="1"  VSSId="3" ConnType="2"  MFSCmdIP="0" MFSCmdPort="0"  
			//VSSCmdIP="-2074564416" VSSCmdPort="554"  VisitStreamOption="0"  IpAddr="0"  CommPort="1024"  
			//LoginName="admin"  LoginPassword="123456" />
			if(m_loginForm.nSURVEILRight)
			{//视频播放权限
				m_pPlayer->Stop();//先停掉正在播放的视频
				m_pPlayer->SetDrawBorder(0);//不显示选中时的红色边框				 
				nPtzOk=0;
				TiXmlNode * pParentNode=nodeElm->Parent();//取主设备
				if(pParentNode==NULL)
				{
					MessageBox(_T("取主设备失败"),_T("取主设备失败"));
					return ;
				}

				TiXmlElement * parentElm=pParentNode->ToElement();
				const char * havevideoRight=parentElm->Attribute("SURVEILRight");//查看用户对此设备是否有权限访问
				if(_bstr_t(havevideoRight)!=_bstr_t("1"))
				{
					MessageBox(_T("此用户没有权限访问此视频"),_T("没权限"));
					return ;
				}
				if(m_bIsTalkIng)
				{
					m_bIsTalkIng=0;
					m_plogObj->StopTalk(PlayDevId);
					SetDlgItemText(IDC_DJ,_T("启动对讲"));
				}
				if(m_bIsBroadCasting)
				{
					m_bIsBroadCasting=0;
					m_plogObj->StopBroadcast(_T("-1"));
					SetDlgItemText(IDC_DJ,_T("启动广播"));
				}
				if(nPlayVideoType!=-1 && PlayDevId.length()>0)
				{
					m_plogObj->StopDeviceMonitor(PlayDevId,nPlayVideoType);//停止上次申请的视频流
					nPlayVideoType=-1;
					PlayDevId="";
				}

				//#define VS_VISITSTREAM_NO_FIRBID		0	//不禁止任何码流
				//#define VS_VISITSTREAM_FIRBID_0		1	//禁止第0路(CIF)
				//#define VS_VISITSTREAM_FIRBID_1		2	//禁止第1路(D1)
				//#define VS_VISITSTREAM_FIRBID_BOTH	3	//禁止第0路、第1路
				int nNotAllowType=atol(nodeElm->Attribute("VisitStreamOption"));//取得在观看的视频ID
				if((nNotAllowType & 0x01)==0)
				{//允许播放CIF
					_bstr_t devid=_bstr_t(nodeElm->Attribute("Id"));//取得在观看的视频ID					
					PlayDevId=devid;
					int port=m_pPlayer->GetBindPort();//取得收流端口
					_bstr_t ret=m_plogObj->InviteDeviceMonitor(devid,0,port,0);//申请d1
					m_bInviteVideoFinish=0;
					m_nLastInviteTime=::GetTickCount();
					pPlayCameraNode=nodeElm;
					if(strstr((char *)ret,"Result =\"0\"")==NULL)
					{//<Response Code="81" Result ="0"/>
						MessageBox(_T("请求流失败"),_T("请求流失败"));
					}
					SetDlgItemText(IDC_CHANGEVIDEO,_T("切换D1"));
					nPlayVideoType=0;
				}else if((nNotAllowType & 0x02)==0)
				{//允许播放D1
					_bstr_t devid=_bstr_t(nodeElm->Attribute("Id"));//取得在观看的视频ID
					PlayDevId=devid;
					int port=m_pPlayer->GetBindPort();//取得收流端口
					_bstr_t ret=m_plogObj->InviteDeviceMonitor(devid,1,port,0);//申请cif,申请后，等待81事件
					m_bInviteVideoFinish=0;
					m_nLastInviteTime=::GetTickCount();
					pPlayCameraNode=nodeElm;
					if(strstr((char *)ret,"Result =\"0\"")==NULL)
					{//<Response Code="81" Result ="0"/>
						MessageBox(_T("请求流失败"),_T("请求流失败"));
					}
					SetDlgItemText(IDC_CHANGEVIDEO,_T("切换CIF"));
					nPlayVideoType=1;
				}else
				{//没权限播放
					MessageBox(_T("此用户没权限观看此视频"),_T("无权限操作"));
				}
			}else
			{
				MessageBox(_T("此用户没有视频控制权限"),_T("无权限操作"));
			}
		}
	}
}



///播放声音
void CVCDemoDlg::OnBnClickedAudio()
{

	if(m_pPlayer!=NULL)
	{
		if(m_pPlayer->get_AudioIsOn())
		{
			m_pPlayer->SetAudioOn(0);
			SetDlgItemText(IDC_AUDIO,_T("播放声音"));
		}else
		{
			m_pPlayer->SetAudioOn(1);
			SetDlgItemText(IDC_AUDIO,_T("停止声音"));
		}
	}
}


//查询预置点
void CVCDemoDlg::OnBnClickedViewpre()
{
	CString preset;
	int idx=m_prestList.GetCurSel();
	if(idx<0)
	{
		MessageBox(_T("请先选择预置点"),_T("请先选择预置点"));
		return ;
	}
	m_prestList.GetLBText(idx,preset);
	_bstr_t precmd="";
	precmd=precmd+"<xml><cmd>callpreset</cmd><preset>"+preset+"</preset></xml>";
	long ret=SendCmd(precmd);
	return;
}


int CVCDemoDlg::SendCmd(_bstr_t cmd)
{
	return m_plogObj->SendPTZCmd(ptzDevId,1,cmd);
}



///请求云台控制
void CVCDemoDlg::OnBnClickedPtzinit()
{
	if(pPlayCameraNode==NULL)
	{
		MessageBox(_T("云台控制必须在视频播放状态下进行"),_T("先播放视频"));
		return ;
	}
	if(m_loginForm.nPTZRight==0)
	{
		MessageBox(_T("用户没有云台控制权限"),_T("无云台控制权限"));
		return ;
	}
	_bstr_t haevptz=_bstr_t(pPlayCameraNode->Attribute("WithPTZ"));//取得在观看的视频ID
	if(haevptz!=_bstr_t("1"))
	{//此设备没有云台
		MessageBox(_T("此设备没有云台"),_T("此设备没有云台"));
		return ;
	}
	TiXmlNode * pNode=pPlayCameraNode->Parent();//主设备
	if(pNode==NULL)
	{
		return ;
	}
	TiXmlElement * parentElm=pNode->ToElement();
	if(parentElm==NULL)
	{
		MessageBox(_T("取主设备失败"),_T("取主设备失败"));
		return ;
	}
	const char * havePtzRight=parentElm->Attribute("PTZRight");
	if(_bstr_t(havePtzRight)!=_bstr_t("1"))
	{
		MessageBox(_T("此用户没有权限控制此云台"),_T("没权限"));
		return ;
	}
	_bstr_t devid=_bstr_t(pPlayCameraNode->Attribute("Id"));//请求控制ID
	m_plogObj->InvitePTZControl(devid);//请求控制
}


void CVCDemoDlg::OnBnClickedSetcapture()
{
	int isPlayeing=atol(_bstr_t(m_pPlayer->GetUserData(_T("gethaveplayed"))));//当时是否正在播放
	if(isPlayeing!=1)
	{
		MessageBox(_T("只有在播放时才能抓拍"),_T("错误操作"));
		return ;
	}
	//m_pPlayer->SetCaptureDir(1,_T("c:\\"));//前面为语言，后面为空时让用户选择，不为空时，则保存到此路径
	//m_pPlayer->SetCaptureDir(1,NULL);//前面为语言，后面为空时让用户选择，不为空时，则保存到此路径
	CString dir=m_pPlayer->GetCaptureDir(0);
	m_pPlayer->SnapShot(dir);//抓图
}



void CVCDemoDlg::OnBnClickedChangevideo()
{
	if(pPlayCameraNode==NULL)
	{
		return ;
	}
	if(nPlayVideoType==0)
	{//切换成cif	
		//使用时，一定要判断是否可以切换成CIF,示例就不再判断，判断方法见双击请求视频流
		m_pPlayer->Stop();//停止正在播放的视频
		_bstr_t devid=_bstr_t(pPlayCameraNode->Attribute("Id"));//取得在观看的视频ID
		PlayDevId=devid;
		int port=m_pPlayer->GetBindPort();//取得收流端口
		m_plogObj->StopDeviceMonitor(devid,0);//停止上次申请的视频流
		_bstr_t ret=m_plogObj->InviteDeviceMonitor(devid,1,port,0);//申请d1
		m_bInviteVideoFinish=0;
		m_nLastInviteTime=::GetTickCount();
		if(strstr((char *)ret,"Result =\"0\"")==NULL)
		{//<Response Code="81" Result ="0"/>
			MessageBox(_T("请求流失败"),_T("请求流失败"));
		}
		SetDlgItemText(IDC_CHANGEVIDEO,_T("切换CIF"));
		nPlayVideoType=1;
	}else
	{//切换成d1
		//使用时，一定要判断是否可以切换成D1,示例就不再判断，判断方法见双击请求视频流
		m_pPlayer->Stop();//停止正在播放的视频
		_bstr_t devid=_bstr_t(pPlayCameraNode->Attribute("Id"));//取得在观看的视频ID
		PlayDevId=devid;
		int port=m_pPlayer->GetBindPort();//取得收流端口
		m_plogObj->StopDeviceMonitor(devid,1);//停止上次申请的视频流
		_bstr_t ret=m_plogObj->InviteDeviceMonitor(devid,0,port,0);//申请d1
		m_bInviteVideoFinish=0;
		m_nLastInviteTime=::GetTickCount();
		if(strstr((char *)ret,"Result =\"0\"")==NULL)
		{//<Response Code="81" Result ="0"/>
			MessageBox(_T("请求流失败"),_T("请求流失败"));
		}
		SetDlgItemText(IDC_CHANGEVIDEO,_T("切换D1"));
		nPlayVideoType=0;
	}
}




///注意pspeed,tspeed速度可以控制1-10之间,更多操作见云台控制协议文档
int CVCDemoDlg::SendPtzByName(_bstr_t name,_bstr_t pspeed,_bstr_t tspeed,_bstr_t addstr)
{
	if(ptzDevId.length()>0)
	{
		_bstr_t sendmsg;
		sendmsg="<xml><cmd>"+name+"</cmd><panspeed>"+pspeed+"</panspeed><tiltspeed>"+tspeed+"</tiltspeed>"+addstr+"</xml>";
		return SendCmd(sendmsg);
	}
	return -1;
}


//消息（LIB）/事件(COM) 代码
enum EventCode
{
	RECVDATATIMEOUT=1			//收取流时，如果10秒内都没有数据，则会发送此消息
	,FOCUSCHANGE				//播放器焦点改变时发生
	,STARTPLAY					//开始播放
	,ENTERWAITFORBUFFER			//进入缓冲
	,SETUP_VIDEO_PARAM_OK		//SetupDecoder返回成功
	,SETUP_AUDIO_PARAM_OK		//SetupDecoder返回成功
	,SNAPSHORT_FINISH			//抓图结束
	,BINDPORTERROR				//邦定端口失败
	,VSS_STOPPLAY				//播放VSS文件结束
	,VSS_STARTPLAY				//开始播放
	,VSS_PLAYNEXT				//播放下一个文件
	,VSS_SETUPERROR				//调用setup返回失败
	,CREATE_THREAD_ERROR		//创建线程失败
	,LOC_STOPPLAY				//停止本地文件播放
	,LOC_OPENFILEERROR			//本地文件播放时打开文件失败
	,LOC_PLAYERROR				//播放失败退出
	,LOC_PAUSEPLAY				//暂停播放
	,LOC_OPENFILE_ERROR			//打开本地文件失败
	,RECV_RETUN_ERROR			//RTPRECV读取数据返回少于16个字节
	,FIRSTPLAY					//第一次播放
};


void CVCDemoDlg::OnTimer(UINT_PTR nIDEvent)
{
	if(nIDEvent==100)
	{//定时取流
		if(m_bInviteVideoFinish==0)
		{
			if(pPlayCameraNode)
			{
				if(::GetTickCount()-m_nLastInviteTime>5000)
				{//5秒请求一次
					if(nPlayVideoType!=0)
					{//D1
						m_pPlayer->Stop();//停止正在播放的视频
						_bstr_t devid=_bstr_t(pPlayCameraNode->Attribute("Id"));//取得在观看的视频ID
						int port=m_pPlayer->GetBindPort();//取得收流端口
						_bstr_t ret=m_plogObj->InviteDeviceMonitor(devid,1,port,0);//申请d1
						m_nLastInviteTime=::GetTickCount();
					}else
					{//CIF
						_bstr_t devid=_bstr_t(pPlayCameraNode->Attribute("Id"));//取得在观看的视频ID
						int port=m_pPlayer->GetBindPort();//取得收流端口
						_bstr_t ret=m_plogObj->InviteDeviceMonitor(devid,0,port,0);//申请d1 
						m_nLastInviteTime=::GetTickCount();
					}
				}
			}
		}
	}
	CDialog::OnTimer(nIDEvent);
}



BOOL CVCDemoDlg::PreTranslateMessage(MSG* pMsg)
{
	if(pMsg->message==0x4401)
	{//事件通知
		if(pMsg->hwnd==m_pPlayer->m_hWnd)
		{//播放器的事件
			if(RECVDATATIMEOUT==pMsg->wParam)
			{//10秒内没有收到视频流数据，要求重新请求视频
				m_bInviteVideoFinish=0;//要重新请求
			}
		}
	}

	if(nPtzOk)
	{//要进行云台控制
		if(pMsg->hwnd==::GetDlgItem(m_hWnd,IDC_MOVELEFT))
		{//
			switch(pMsg->message)
			{
			case WM_LBUTTONDOWN:
				{//按下
					SendPtzByName("left","5","5","");
					return S_OK;
				}
				break;
			case WM_LBUTTONUP:
				{//放开
					SendPtzByName("stop","5","5","");
					return S_OK;
				}
				break;
			}
		}else if(pMsg->hwnd==::GetDlgItem(m_hWnd,IDC_MOVERIGHT))
		{
			switch(pMsg->message)
			{
			case WM_LBUTTONDOWN:
				{//按下
					SendPtzByName("right","5","5","");
					return S_OK;
				}
				break;
			case WM_LBUTTONUP:
				{//放开
					SendPtzByName("stop","5","5","");
					return S_OK;
				}
				break;
			}
		}else if(pMsg->hwnd==::GetDlgItem(m_hWnd,IDC_MOVEDOWN))
		{
			switch(pMsg->message)
			{
			case WM_LBUTTONDOWN:
				{//按下
					SendPtzByName("down","5","5","");
					return S_OK;
				}
				break;
			case WM_LBUTTONUP:
				{//放开
					SendPtzByName("stop","5","5","");
					return S_OK;
				}
				break;
			}
		}else if(pMsg->hwnd==::GetDlgItem(m_hWnd,IDC_MOVEUP))
		{
			switch(pMsg->message)
			{
			case WM_LBUTTONDOWN:
				{//按下
					SendPtzByName("up","5","5","");
					return S_OK;
				}
				break;
			case WM_LBUTTONUP:
				{//放开
					SendPtzByName("stop","5","5","");
					return S_OK;
				}
				break;
			}
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}


//停止播放视频
void CVCDemoDlg::OnBnClickedStopplay()
{	
	if(nPlayVideoType!=-1 && PlayDevId.length()>0)
	{
		if(m_bIsTalkIng)
		{
			m_bIsTalkIng=0;
			m_plogObj->StopTalk(PlayDevId);
			SetDlgItemText(IDC_DJ,_T("启动对讲"));
		}
		if(m_bIsBroadCasting)
		{
			m_bIsBroadCasting=0;
			m_plogObj->StopBroadcast(_T("-1"));
			SetDlgItemText(IDC_DJ,_T("启动广播"));
		}
		int ErrorCode=m_pPlayer->Stop();
		_bstr_t stopVideo=m_plogObj->StopDeviceMonitor(PlayDevId,nPlayVideoType);//停止上次申请的视频流		
		nPlayVideoType=-1;
		PlayDevId="";
	}else
	{
		MessageBox(_T("当前没有播放视频，无法停止"),_T("错误操作"));
	}
}


///查询录像
void CVCDemoDlg::OnBnClickedRecordplayer()
{
	if(m_loginForm.nVideoReplayRight==0)
	{
		MessageBox(_T("没有回放权限"),_T("错误操作"));
		return ;
	}
	m_SearchDlg.m_parent=this;
	m_SearchDlg.DoModal();
}



void CVCDemoDlg::OnBnClickedRecordfile()
{	
	int isPlayeing=atol(_bstr_t(m_pPlayer->GetUserData(_T("gethaveplayed"))));//当时是否正在播放
    if(isPlayeing!=1)
    {
		MessageBox(_T("只有在正在播放时才能录像"),_T("错误操作"));
        return ;
    }
	if(m_pPlayer->get_IsRecording())
	{//停止录像
		SetDlgItemText(IDC_RECORDFILE,_T("开始录像"));
		m_pPlayer->StopRecord();
	}else
	{
		///进行录像，录像时，如果不停止半小时会自动停止
		m_pPlayer->StartRecord(_T("c:\\"));
		if(m_pPlayer->get_IsRecording())
		{
			SetDlgItemText(IDC_RECORDFILE,_T("停止录像"));
		}else
		{
			SetDlgItemText(IDC_RECORDFILE,_T("开始录像"));
		}
	}
}



//对讲
void CVCDemoDlg::OnBnClickedDj()
{
	if(m_bIsTalkIng)
	{
		int ret=m_plogObj->StopTalk(PlayDevId);
		if(ret==0)
		{
			SetDlgItemText(IDC_DJ,_T("启动对讲"));
			m_bIsTalkIng=0;
		}else
		{
			MessageBox(_T("停止对讲失败"),_T("对讲错误"));
		}
		return ;
	}
	if(m_bIsBroadCasting)
	{
		MessageBox(_T("当前正在广播中，不允许启用对讲"),_T("对讲错误"));
		return ;
	}
	//m_bIsTalkIng=0;
	//m_bIsBroadCasting=0;

	//RequestTalk();
	if(PlayDevId.length()<=0)
	{
		MessageBox(_T("只有在播放时才能对讲"),_T("对讲错误"));
		return ;
	}
	//RequestTalk(BSTR strCameraId,LONG nCodecType,LONG nSampleRate,LONG nSampleBitsWitdh,LONG nChannels,LONG BitRate,[out,retval] LONG* nResult);
	int ret=0;//m_plogObj->RequestTalk(PlayDevId,0,8000,16,2,128000);//G711格式
	//ret=m_plogObj->RequestTalk(PlayDevId,0,8000,16,2,128000);//G711格式
	ret=m_plogObj->RequestTalk(PlayDevId,0,16000,16,2,16000);//AAC格式
	if(ret!=0)
	{
		MessageBox(_T("请求对讲失败"),_T("对讲错误"));
	}else
	{
		m_bIsTalkIng=1;
		SetDlgItemText(IDC_DJ,_T("停止对讲"));
	}
}



//[id(101), helpstring("方法")] HRESULT RequestTalk(BSTR strCameraId,LONG nCodecType,LONG nSampleRate,LONG nSampleBitsWitdh,LONG nChannels,LONG BitRate,[out,retval] LONG* nResult);
//[id(102), helpstring("方法")] HRESULT RequestBroadcast(BSTR strDomainId,LONG nCodecType,LONG nSampleRate,LONG nSampleBitsWitdh,LONG nChannels,LONG BitRate,[out,retval] LONG* nResult);
//LONG nCodecType 0表示g711，1表示aac
//nSampleRate,nSampleBitsWitdh,nChannels,BitRate 分别表示采样率，样本宽度，通道数，码率
//RequestBroadcast的参数strDomainId=“”表示对当前域进行广播。listCameraId表示摄像头序列，使用,分割。
//对讲和广播只能同时进行一个任务。
//把上次登录时候获取的设备信息保存到文件（如lgs_3064172861.dat）中，反序列化完成激发CodeGetDeviceList 事件给客户端


//广播
void CVCDemoDlg::OnBnClickedGb()
{
	if(m_bIsBroadCasting)
	{
		int ret=m_plogObj->StopBroadcast(_T("-1"));
		if(ret==0)
		{
			SetDlgItemText(IDC_GB,_T("启动广播"));
			m_bIsBroadCasting=0;
		}else
		{
			MessageBox(_T("停止对讲失败"),_T("广播错误"));
		}
		return ;
	}
	if(m_bIsTalkIng)
	{
		MessageBox(_T("当前正在对讲中，不允许启用广播"),_T("广播错误"));
		return ;
	}
	//m_bIsTalkIng=0;
	//m_bIsBroadCasting=0;


	//RequestTalk();
	if(PlayDevId.length()<=0)
	{
		MessageBox(_T("只有在播放时才能广播"),_T("广播错误"));
		return ;
	}
	//RequestBroadcast(BSTR strDomainId,LONG nCodecType,LONG nSampleRate,LONG nSampleBitsWitdh,LONG nChannels,LONG BitRate,[out,retval] LONG* nResult);
	int ret=0;
	m_plogObj->RequestBroadcast(_T(""),0,8000,16,2,128000);//对所有设备进行广播,G711	
	//ret=m_plogObj->RequestBroadcast(_T(""),0,16000,16,2,16000);//AAC格式
	if(ret!=0)
	{
		MessageBox(_T("请求广播失败"),_T("广播错误"));
	}else
	{
		m_bIsBroadCasting=1;
		SetDlgItemText(IDC_GB,_T("停止广播"));
	}
}

void CVCDemoDlg::OnBnClickedButton3()
{
	if(m_pPlayer)
	{
		m_pPlayer->SetZoomRectOn(3);
	}
}

void CVCDemoDlg::OnBnClickedZoomup()
{
	if(m_pPlayer)
	{
		m_pPlayer->SetZoomRectOn(1);
	}
}

void CVCDemoDlg::OnBnClickedZoomdown()
{
	if(m_pPlayer)
	{
		m_pPlayer->SetZoomRectOn(2);
	}
}
