?? ctlutil.h
字號:
//------------------------------------------------------------------------------
// File: CtlUtil.h
//
// Desc: DirectShow base classes.
//
// Copyright (c) 1992-2002 Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
// Base classes implementing IDispatch parsing for the basic control dual
// interfaces. Derive from these and implement just the custom method and
// property methods. We also implement CPosPassThru that can be used by
// renderers and transforms to pass by IMediaPosition and IMediaSeeking
#ifndef __CTLUTIL__
#define __CTLUTIL__
// OLE Automation has different ideas of TRUE and FALSE
#define OATRUE (-1)
#define OAFALSE (0)
// It's possible that we could replace this class with CreateStdDispatch
class CBaseDispatch
{
ITypeInfo * m_pti;
public:
CBaseDispatch() : m_pti(NULL) {}
~CBaseDispatch();
/* IDispatch methods */
STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
STDMETHODIMP GetTypeInfo(
REFIID riid,
UINT itinfo,
LCID lcid,
ITypeInfo ** pptinfo);
STDMETHODIMP GetIDsOfNames(
REFIID riid,
OLECHAR ** rgszNames,
UINT cNames,
LCID lcid,
DISPID * rgdispid);
};
class AM_NOVTABLE CMediaControl :
public IMediaControl,
public CUnknown
{
CBaseDispatch m_basedisp;
public:
CMediaControl(const TCHAR *, LPUNKNOWN);
DECLARE_IUNKNOWN
// override this to publicise our interfaces
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
/* IDispatch methods */
STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
STDMETHODIMP GetTypeInfo(
UINT itinfo,
LCID lcid,
ITypeInfo ** pptinfo);
STDMETHODIMP GetIDsOfNames(
REFIID riid,
OLECHAR ** rgszNames,
UINT cNames,
LCID lcid,
DISPID * rgdispid);
STDMETHODIMP Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS * pdispparams,
VARIANT * pvarResult,
EXCEPINFO * pexcepinfo,
UINT * puArgErr);
};
class AM_NOVTABLE CMediaEvent :
public IMediaEventEx,
public CUnknown
{
CBaseDispatch m_basedisp;
public:
CMediaEvent(const TCHAR *, LPUNKNOWN);
DECLARE_IUNKNOWN
// override this to publicise our interfaces
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
/* IDispatch methods */
STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
STDMETHODIMP GetTypeInfo(
UINT itinfo,
LCID lcid,
ITypeInfo ** pptinfo);
STDMETHODIMP GetIDsOfNames(
REFIID riid,
OLECHAR ** rgszNames,
UINT cNames,
LCID lcid,
DISPID * rgdispid);
STDMETHODIMP Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS * pdispparams,
VARIANT * pvarResult,
EXCEPINFO * pexcepinfo,
UINT * puArgErr);
};
class AM_NOVTABLE CMediaPosition :
public IMediaPosition,
public CUnknown
{
CBaseDispatch m_basedisp;
public:
CMediaPosition(const TCHAR *, LPUNKNOWN);
CMediaPosition(const TCHAR *, LPUNKNOWN, HRESULT *phr);
DECLARE_IUNKNOWN
// override this to publicise our interfaces
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
/* IDispatch methods */
STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
STDMETHODIMP GetTypeInfo(
UINT itinfo,
LCID lcid,
ITypeInfo ** pptinfo);
STDMETHODIMP GetIDsOfNames(
REFIID riid,
OLECHAR ** rgszNames,
UINT cNames,
LCID lcid,
DISPID * rgdispid);
STDMETHODIMP Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS * pdispparams,
VARIANT * pvarResult,
EXCEPINFO * pexcepinfo,
UINT * puArgErr);
};
// OA-compatibility means that we must use double as the RefTime value,
// and REFERENCE_TIME (essentially a LONGLONG) within filters.
// this class converts between the two
class COARefTime : public CRefTime {
public:
COARefTime() {
};
COARefTime(CRefTime t)
: CRefTime(t)
{
};
COARefTime(REFERENCE_TIME t)
: CRefTime(t)
{
};
COARefTime(double d) {
m_time = (LONGLONG) (d * 10000000);
};
operator double() {
return double(m_time) / 10000000;
};
operator REFERENCE_TIME() {
return m_time;
};
COARefTime& operator=(const double& rd) {
m_time = (LONGLONG) (rd * 10000000);
return *this;
}
COARefTime& operator=(const REFERENCE_TIME& rt) {
m_time = rt;
return *this;
}
inline BOOL operator==(const COARefTime& rt)
{
return m_time == rt.m_time;
};
inline BOOL operator!=(const COARefTime& rt)
{
return m_time != rt.m_time;
};
inline BOOL operator < (const COARefTime& rt)
{
return m_time < rt.m_time;
};
inline BOOL operator > (const COARefTime& rt)
{
return m_time > rt.m_time;
};
inline BOOL operator >= (const COARefTime& rt)
{
return m_time >= rt.m_time;
};
inline BOOL operator <= (const COARefTime& rt)
{
return m_time <= rt.m_time;
};
inline COARefTime operator+(const COARefTime& rt)
{
return COARefTime(m_time + rt.m_time);
};
inline COARefTime operator-(const COARefTime& rt)
{
return COARefTime(m_time - rt.m_time);
};
inline COARefTime operator*(LONG l)
{
return COARefTime(m_time * l);
};
inline COARefTime operator/(LONG l)
{
return COARefTime(m_time / l);
};
private:
// Prevent bugs from constructing from LONG (which gets
// converted to double and then multiplied by 10000000
COARefTime(LONG);
operator=(LONG);
};
// A utility class that handles IMediaPosition and IMediaSeeking on behalf
// of single-input pin renderers, or transform filters.
//
// Renderers will expose this from the filter; transform filters will
// expose it from the output pin and not the renderer.
//
// Create one of these, giving it your IPin* for your input pin, and delegate
// all IMediaPosition methods to it. It will query the input pin for
// IMediaPosition and respond appropriately.
//
// Call ForceRefresh if the pin connection changes.
//
// This class no longer caches the upstream IMediaPosition or IMediaSeeking
// it acquires it on each method call. This means ForceRefresh is not needed.
// The method is kept for source compatibility and to minimise the changes
// if we need to put it back later for performance reasons.
class CPosPassThru : public IMediaSeeking, public CMediaPosition
{
IPin *m_pPin;
HRESULT GetPeer(IMediaPosition **ppMP);
HRESULT GetPeerSeeking(IMediaSeeking **ppMS);
public:
CPosPassThru(const TCHAR *, LPUNKNOWN, HRESULT*, IPin *);
DECLARE_IUNKNOWN
HRESULT ForceRefresh() {
return S_OK;
};
// override to return an accurate current position
virtual HRESULT GetMediaTime(LONGLONG *pStartTime,LONGLONG *pEndTime) {
return E_FAIL;
}
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid,void **ppv);
// IMediaSeeking methods
STDMETHODIMP GetCapabilities( DWORD * pCapabilities );
STDMETHODIMP CheckCapabilities( DWORD * pCapabilities );
STDMETHODIMP SetTimeFormat(const GUID * pFormat);
STDMETHODIMP GetTimeFormat(GUID *pFormat);
STDMETHODIMP IsUsingTimeFormat(const GUID * pFormat);
STDMETHODIMP IsFormatSupported( const GUID * pFormat);
STDMETHODIMP QueryPreferredFormat( GUID *pFormat);
STDMETHODIMP ConvertTimeFormat(LONGLONG * pTarget, const GUID * pTargetFormat,
LONGLONG Source, const GUID * pSourceFormat );
STDMETHODIMP SetPositions( LONGLONG * pCurrent, DWORD CurrentFlags
, LONGLONG * pStop, DWORD StopFlags );
STDMETHODIMP GetPositions( LONGLONG * pCurrent, LONGLONG * pStop );
STDMETHODIMP GetCurrentPosition( LONGLONG * pCurrent );
STDMETHODIMP GetStopPosition( LONGLONG * pStop );
STDMETHODIMP SetRate( double dRate);
STDMETHODIMP GetRate( double * pdRate);
STDMETHODIMP GetDuration( LONGLONG *pDuration);
STDMETHODIMP GetAvailable( LONGLONG *pEarliest, LONGLONG *pLatest );
STDMETHODIMP GetPreroll( LONGLONG *pllPreroll );
// IMediaPosition properties
STDMETHODIMP get_Duration(REFTIME * plength);
STDMETHODIMP put_CurrentPosition(REFTIME llTime);
STDMETHODIMP get_StopTime(REFTIME * pllTime);
STDMETHODIMP put_StopTime(REFTIME llTime);
STDMETHODIMP get_PrerollTime(REFTIME * pllTime);
STDMETHODIMP put_PrerollTime(REFTIME llTime);
STDMETHODIMP get_Rate(double * pdRate);
STDMETHODIMP put_Rate(double dRate);
STDMETHODIMP get_CurrentPosition(REFTIME * pllTime);
STDMETHODIMP CanSeekForward(LONG *pCanSeekForward);
STDMETHODIMP CanSeekBackward(LONG *pCanSeekBackward);
private:
HRESULT GetSeekingLongLong( HRESULT (__stdcall IMediaSeeking::*pMethod)( LONGLONG * ),
LONGLONG * pll );
};
// Adds the ability to return a current position
class CRendererPosPassThru : public CPosPassThru
{
CCritSec m_PositionLock; // Locks access to our position
LONGLONG m_StartMedia; // Start media time last seen
LONGLONG m_EndMedia; // And likewise the end media
BOOL m_bReset; // Have media times been set
public:
// Used to help with passing media times through graph
CRendererPosPassThru(const TCHAR *, LPUNKNOWN, HRESULT*, IPin *);
HRESULT RegisterMediaTime(IMediaSample *pMediaSample);
HRESULT RegisterMediaTime(LONGLONG StartTime,LONGLONG EndTime);
HRESULT GetMediaTime(LONGLONG *pStartTime,LONGLONG *pEndTime);
HRESULT ResetMediaTime();
HRESULT EOS();
};
STDAPI CreatePosPassThru(
LPUNKNOWN pAgg,
BOOL bRenderer,
IPin *pPin,
IUnknown **ppPassThru
);
// A class that handles the IDispatch part of IBasicAudio and leaves the
// properties and methods themselves pure virtual.
class AM_NOVTABLE CBasicAudio : public IBasicAudio, public CUnknown
{
CBaseDispatch m_basedisp;
public:
CBasicAudio(const TCHAR *, LPUNKNOWN);
DECLARE_IUNKNOWN
// override this to publicise our interfaces
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
/* IDispatch methods */
STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
STDMETHODIMP GetTypeInfo(
UINT itinfo,
LCID lcid,
ITypeInfo ** pptinfo);
STDMETHODIMP GetIDsOfNames(
REFIID riid,
OLECHAR ** rgszNames,
UINT cNames,
LCID lcid,
DISPID * rgdispid);
STDMETHODIMP Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS * pdispparams,
VARIANT * pvarResult,
EXCEPINFO * pexcepinfo,
UINT * puArgErr);
};
// A class that handles the IDispatch part of IBasicVideo and leaves the
// properties and methods themselves pure virtual.
class AM_NOVTABLE CBaseBasicVideo : public IBasicVideo2, public CUnknown
{
CBaseDispatch m_basedisp;
public:
CBaseBasicVideo(const TCHAR *, LPUNKNOWN);
DECLARE_IUNKNOWN
// override this to publicise our interfaces
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
/* IDispatch methods */
STDMETHODIMP GetTypeInfoCount(UINT * pctinfo);
STDMETHODIMP GetTypeInfo(
UINT itinfo,
LCID lcid,
ITypeInfo ** pptinfo);
STDMETHODIMP GetIDsOfNames(
REFIID riid,
OLECHAR ** rgszNames,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -