📄 cfilternetreceiver.cpp
字号:
//
// CFilterNetReceiver.cpp
//
#include <streams.h> // quartz, includes windows
// Eliminate two expected level 4 warnings from the Microsoft compiler.
// The class does not have an assignment or copy operator, and so cannot
// be passed by value. This is normal. This file compiles clean at the
// highest (most picky) warning level (-W4).
#pragma warning(disable: 4511 4512)
#pragma warning(disable: 4355)
#include <initguid.h>
#include "FilterNetReceiverGuid.h"
#if (1100 > _MSC_VER)
#include <olectlid.h>
#else
#include <olectl.h>
#endif
#include "CFilterNetReceiver.h"
#include "defines.h"
//
// setup data
//
const AMOVIESETUP_MEDIATYPE sudPinTypes =
{
&MEDIATYPE_Video, // Major type
&MEDIASUBTYPE_NULL // Minor type
};
const AMOVIESETUP_PIN psudPins[] =
{
{
L"Output", // String pin name
FALSE, // Is it rendered
TRUE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
L"Input", // Connects to pin
1, // Number of types
&sudPinTypes // The pin details
}
};
const AMOVIESETUP_FILTER sudFilter =
{
&CLSID_NetReceiver, // Filter CLSID
L"HQ Net Receiver", // Filter name
MERIT_DO_NOT_USE, // Its merit
1, // Number of pins
psudPins // Pin details
};
// List of class IDs and creator functions for the class factory. This
// provides the link between the OLE entry point in the DLL and an object
// being created. The class factory will call the static CreateInstance
CFactoryTemplate g_Templates[] =
{
{
L"HQ Net Receiver",
&CLSID_NetReceiver,
CFilterNetReceiver::CreateInstance,
NULL,
&sudFilter
}
};
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
// ----------------------------------------------------------------------------
// Filter implementation
// ----------------------------------------------------------------------------
CFilterNetReceiver::CFilterNetReceiver(LPUNKNOWN lpunk, HRESULT *phr) :
CAsyncReader(NAME("Net_Receiver"), lpunk, &mNetStream, phr),
mNetStream(this)
{
m_clsid = CLSID_NetReceiver;
// Assume the coming data is MPEG1
DecideOutputMediaType(FT_MPEG1);
}
CFilterNetReceiver::~CFilterNetReceiver()
{
}
//
// CreateInstance
//
// Override CClassFactory method.
// Provide the way for COM to create a CNullInPlace object
//
CUnknown * WINAPI CFilterNetReceiver::CreateInstance(LPUNKNOWN punk, HRESULT *phr)
{
CFilterNetReceiver *pNewObject = new CFilterNetReceiver(punk, phr);
if (pNewObject == NULL)
{
*phr = E_OUTOFMEMORY;
}
return pNewObject;
}
//
// Basic COM - used here to reveal our own interfaces
STDMETHODIMP CFilterNetReceiver::NonDelegatingQueryInterface(REFIID riid, void ** ppv)
{
CheckPointer(ppv, E_POINTER);
if (riid == IID_INetReceiver)
{
return GetInterface((INetReceiver *) this, ppv);
}
else
{
return CAsyncReader::NonDelegatingQueryInterface(riid, ppv);
}
}
STDMETHODIMP CFilterNetReceiver::Run(REFERENCE_TIME tStart)
{
CAutoLock lck(&m_csFilter);
return CAsyncReader::Run(tStart);
}
STDMETHODIMP CFilterNetReceiver::Pause()
{
CAutoLock lck(&m_csFilter);
HRESULT hr = NOERROR;
if (m_State == State_Paused)
{
// (This space left deliberately blank)
}
else
{
if (m_State == State_Stopped)
{
// allow a class derived from CTransformFilter
// to know about starting and stopping streaming
hr = StartStreaming();
}
else if (m_State == State_Running)
{
}
if (SUCCEEDED(hr))
{
hr = CBaseFilter::Pause();
}
}
return hr;
}
STDMETHODIMP CFilterNetReceiver::Stop()
{
CAutoLock lck1(&m_csFilter);
HRESULT hr = CAsyncReader::Stop();
if (SUCCEEDED(hr))
{
hr = StopStreaming();
}
return hr;
}
HRESULT CFilterNetReceiver::StartStreaming(void)
{
mNetStream.mController.StartStreaming();
return NOERROR;
}
HRESULT CFilterNetReceiver::StopStreaming(void)
{
mNetStream.mController.StopStreaming();
return NOERROR;
}
// Determine the output pin's media type, so we can connect down
HRESULT CFilterNetReceiver::DecideOutputMediaType(long inMedia)
{
m_mt.SetType(&MEDIATYPE_Stream);
switch (inMedia)
{
case FT_MPEG1:
m_mt.SetSubtype(&MEDIASUBTYPE_MPEG1System);
break;
case FT_MPEG2:
m_mt.SetSubtype(&MEDIASUBTYPE_MPEG2_PROGRAM);
break;
case FT_MP3:
m_mt.SetSubtype(&MEDIASUBTYPE_MPEG1Audio);
break;
case FT_AVI:
m_mt.SetSubtype(&MEDIASUBTYPE_Avi);
break;
default:
m_mt.SetSubtype(&MEDIASUBTYPE_NULL);
return E_FAIL;
}
return NOERROR;
}
BOOL CFilterNetReceiver::IsFlushing(void)
{
return m_Io.m_bFlushing;
}
void CFilterNetReceiver::PauseGraph(void)
{
if (m_pGraph)
{
if (m_State == State_Paused)
{
return;
}
IMediaControl * pControl = NULL;
m_pGraph->QueryInterface(IID_IMediaControl, (void**) &pControl);
if (pControl)
{
pControl->Release();
pControl->Pause();
}
}
}
void CFilterNetReceiver::RunGraph(void)
{
if (m_pGraph)
{
if (m_State == State_Running)
{
return;
}
IMediaControl * pControl = NULL;
m_pGraph->QueryInterface(IID_IMediaControl, (void**) &pControl);
if (pControl)
{
pControl->Release();
pControl->Run();
}
}
}
// --- INetReceiver methods ---
STDMETHODIMP CFilterNetReceiver::SetStreamType(long inType)
{
mNetStream.mController.SetStreamType(inType);
DecideOutputMediaType(inType);
return NOERROR;
}
STDMETHODIMP CFilterNetReceiver::SetSize(long inTotalSize,
long inCheckOffset)
{
mNetStream.mController.SetSize(inTotalSize, inCheckOffset);
return NOERROR;
}
STDMETHODIMP CFilterNetReceiver::SetStreamSocket(SOCKET inSocket)
{
mNetStream.mController.SetStreamSocket(inSocket);
return NOERROR;
}
STDMETHODIMP CFilterNetReceiver::StartReceiving(void)
{
BOOL pass = mNetStream.mController.StartReceiving();
return pass ? NOERROR : E_FAIL;
}
STDMETHODIMP CFilterNetReceiver::StopReceiving(void)
{
mNetStream.mController.StopReceiving();
return NOERROR;
}
// Check if already received enough data for filter-connect-downstream
STDMETHODIMP CFilterNetReceiver::CanConnectToDownstream(void)
{
BOOL ready = mNetStream.mController.IsReadToBeChecked();
return ready ? S_OK : S_FALSE;
}
/******************************Public Routine******************************\
* exported entry points for registration and
* unregistration (in this case they only call
* through to default implmentations).
*
*
*
* History:
*
\**************************************************************************/
STDAPI DllRegisterServer()
{
return AMovieDllRegisterServer2( TRUE );
}
STDAPI DllUnregisterServer()
{
return AMovieDllRegisterServer2( FALSE );
}
// Microsoft C Compiler will give hundreds of warnings about
// unused inline functions in header files. Try to disable them.
#pragma warning( disable:4514)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -