?? asyncfilter.cpp
字號(hào):
// AsyncFilter.cpp: implementation of the CAsyncFilter class.
//
//////////////////////////////////////////////////////////////////////
#define MCAST_PORT 4000
#define LOCAL_PORT 6000
#define LOCAL_IP "172.16.129.86"
#define MCAST_IP "239.216.30.54"
#include "stdafx.h"
#include "Client.h"
#include "AsyncFilter.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//DIVX3:33564944-0000-0010-8000-00AA00389B71
//extern GUID MEDIASUBTYPE_DIVX3;
DEFINE_GUID(MEDIASUBTYPE_DIVX3,
0x78766964, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
CAsyncFilter::CAsyncFilter(HRESULT * phr):
CAsyncReader(NAME("Source"), NULL, &m_Stream, phr)
{
m_mt.majortype = MEDIATYPE_Stream;
//m_mt.subtype = MEDIASUBTYPE_NULL;
m_mt.subtype = MEDIASUBTYPE_Avi;
//m_mt.subtype = MEDIASUBTYPE_DIVX3;
WSADATA wsaData;
if(WSAStartup(MAKEWORD(2,2),&wsaData) != 0)
{
return;
};
unsigned long addr = ntohl(inet_addr("172.16.129.86"));
int nRet;
/* unsigned long remoteIP = inet_addr(MCAST_IP);
_ASSERT(remoteIP != INADDR_NONE);
// 創(chuàng)建RTP會(huì)話(huà)
status = m_rtpSession.Create(LOCAL_PORT,localIP);
//checkerror(status);
m_rtpSession.JoinMulticastGroup(remoteIP);*/
nRet = m_rtpSession.Create(10000);
nRet = m_rtpSession.AddDestination(addr,10002);
nRet = m_rtpSession.SetMaxPacketSize(60000);
m_rtpSession.SetDefaultPayloadType(0);
m_rtpSession.SetDefaultMark(false);
m_rtpSession.SetDefaultTimeStampIncrement(10);
m_Stream.SetRTPSession(&m_rtpSession);
m_hPollDataThrd = NULL;
m_bRunThread = FALSE;
StartPollData();
CTRLMSG msg;
msg.msgType = QUEST_LENGTH;
msg.msgSubType = OTHER;
msg.dwLength = 0;
m_rtpSession.SendPacket(&msg,sizeof(CTRLMSG));
}
CAsyncFilter::~CAsyncFilter()
{
m_rtpSession.ClearDestinations();
//m_rtpSession.Destroy();
WSACleanup();
}
void CAsyncFilter::SetMediaLength(LONGLONG llMeidaLen)
{
m_Stream.SetMediaLength(llMeidaLen);
}
DWORD WINAPI CAsyncFilter::PollDataProc(void *pParam)
{
CAsyncFilter *pFilter = (CAsyncFilter*)pParam;
// pFilter = (CAsyncFilter)pParam;
int nRet = 0;
while(1)
{
nRet = pFilter->m_rtpSession.PollData();
if (pFilter->m_rtpSession.GotoFirstSourceWithData())
{
do
{
RTPPacket *pack;
pack = pFilter->m_rtpSession.GetNextPacket();
pFilter->ProcessQuery((char*)pack->GetPayload(),
pack->GetPayloadLength());
delete pack;
} while (pFilter->m_rtpSession.GotoNextSourceWithData());
}
Sleep(1);
}
return 0;
}
HRESULT CAsyncFilter::ProcessQuery(char *pbData,int nLength)
{
/* CTRLMSG msg = {0};
memcpy(&msg,pbData,sizeof(CTRLMSG));
if(QUERYMEDIATYPE == msg.nType)
{
m_pPin[0]->SendMediaType();
m_pPin[1]->SendMediaType();
}*/
m_Stream.FillBuffer(pbData,nLength);
return S_OK;
}
HRESULT CAsyncFilter::StartPollData()
{
if(m_hPollDataThrd != NULL)
return S_OK;
DWORD dwThreadId;
m_hPollDataThrd = CreateThread(NULL,
0,
PollDataProc,
(LPVOID)this,
0,
&dwThreadId);
if(!m_hPollDataThrd)
{
m_hPollDataThrd = NULL;
m_bRunThread = FALSE;
return S_FALSE;
}
m_bRunThread = TRUE;
return S_OK;
}
HRESULT CAsyncFilter::StopPollData()
{
if(m_hPollDataThrd == NULL) return S_OK;
m_bRunThread = FALSE;
TerminateThread(m_hPollDataThrd,0);
m_hPollDataThrd = NULL;
return S_OK;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -