|
DSTex.h头文件的内容:#ifndef _DSTEX_HEADER_INCLUDED_
#define _DSTEX_HEADER_INCLUDED_
#include<d3d9.h>
#include<d3dx9.h>
#include<streams.h>
#include<atlbase.h>
#ifndef DSTEX_EXPORT
#define DSTEX_DLL _declspec(dllimport)
#else
#define DSTEX_DLL _declspec(dllexport)
#endif
#define CDSERR_OK 0 //没有错误
#define CDSERR_CREATEGRAPHERR 1 //创建图表失败
#define CDSERR_CREATETRFAILED 2 //创建TextureRenderer失败
#define CDSERR_ADDFILTERFAILED 3 //把解码器加到图表失败
#define CDSERR_MEDIANOTFOUND 4 //媒体文件未找到
#define CDSERR_ADDSRCFILTERFAILED 5 //把源解码器加到图表失败
#define CDSERR_CANNOTFINDOUTPUTPIN 6 //无法找到输出口
#define CDSERR_CANNOTRENDERSRCOUTPUTPIN 7 //无法渲染源输出口
#define CDSERR_CANNOTGETDURATION 8 //无法取得总时长
#define CDSERR_CANNOTGETPOSITION 9 //无法取得播放进度
#define CDSERR_CANNOTSETPOSITION 10 //无法设置播放进度
#define CDSERR_CANNOTPLAY 11 //无法播放
#define CDSERR_CANNOTPAUSE 12 //无法暂停
#define CDSERR_CANNOTSTOP 13 //无法停止
#define CDSERR_CANNOTGETEVENT 14 //无法取得事件
#define CDSERR_CANNOTGETFPS 15 //无法取得FPS
#define CDSERR_NOTINITIALIZED 16 //没有完成初始化
#ifndef CDSTEX_INLINE
#define CDSTEX_INLINE inline
#endif
class DSTEX_DLL CDSTex
{
private:
template class DSTEX_DLL CComPtr<IGraphBuilder> m_pGB; //GraphBuilder
template class DSTEX_DLL CComPtr<IMediaControl> m_pMC; //多媒体控制
template class DSTEX_DLL CComPtr<IMediaPosition> m_pMP; //多媒体位置
template class DSTEX_DLL CComPtr<IMediaEvent> m_pME; //多媒体事件
template class DSTEX_DLL CComPtr<IBaseFilter> m_pRenderer; //渲染器
LPTSTR m_szMediaFile; //媒体文件的文件名
LPDIRECT3DDEVICE9 m_pDev9;
DWORD m_dwErrCode; //错误码
HRESULT m_hrLastHRESULT;//最后的HRESULT
public:
CDSTex() {m_pGB=NULL;m_pMC=NULL;m_pMP=NULL;m_pME=NULL;m_pRenderer=NULL;m_pDev9=NULL;m_dwErrCode=CDSERR_OK;m_hrLastHRESULT=S_OK;}
~CDSTex() {ReleaseDSTex();}
BOOL InitDSTex(LPDIRECT3DDEVICE9 pDev9,LPTSTR szSourceFile);
void ReleaseDSTex();
BOOL GetDuration(double*);
BOOL GetCurrentPosition(double*);
BOOL SetCurrentPosition(double);
BOOL CheckEnd();
BOOL Play();
BOOL Pause();
BOOL Stop();
LPDIRECT3DDEVICE9 GetDevice();
void SetDevice(LPDIRECT3DDEVICE9);
LPDIRECT3DTEXTURE9 GetTexture();
D3DFORMAT GetTextureFormat();
LPTSTR GetMediaFile();
DWORD GetVideoWidth();
DWORD GetVideoHeight();
DWORD GetTextureWidth();
DWORD GetTextureHeight();
BOOL GetFrameRate(int*);
void SetLastError(DWORD dwErrCode);
DWORD GetLastError();
void SetLastHRESULT(HRESULT hr);
HRESULT GetLastHRESULT();
};
//-----------------------------------------------------------------------------
//GetDevice
//-----------------------------------------------------------------------------
CDSTEX_INLINE
LPDIRECT3DDEVICE9 CDSTex::GetDevice()
{
return m_pDev9;
}
//-----------------------------------------------------------------------------
//SetDevice
//-----------------------------------------------------------------------------
CDSTEX_INLINE
void CDSTex::SetDevice(LPDIRECT3DDEVICE9 pDev)
{
m_pDev9=pDev;
}
//-----------------------------------------------------------------------------
//GetMediaFile
//-----------------------------------------------------------------------------
CDSTEX_INLINE
LPTSTR CDSTex::GetMediaFile()
{
return m_szMediaFile;
}
//-----------------------------------------------------------------------------
//SetLastError
//-----------------------------------------------------------------------------
CDSTEX_INLINE
void CDSTex::SetLastError(DWORD dwErrCode)
{
m_dwErrCode=dwErrCode;
}
//-----------------------------------------------------------------------------
//GetLastError
//-----------------------------------------------------------------------------
CDSTEX_INLINE
DWORD CDSTex::GetLastError()
{
return m_dwErrCode;
}
//-----------------------------------------------------------------------------
//SetLastHRESULT
//-----------------------------------------------------------------------------
CDSTEX_INLINE
void CDSTex::SetLastHRESULT(HRESULT hr)
{
m_hrLastHRESULT=hr;
}
//-----------------------------------------------------------------------------
//GetLastHRESULT
//-----------------------------------------------------------------------------
CDSTEX_INLINE
HRESULT CDSTex::GetLastHRESULT()
{
return m_hrLastHRESULT;
}
//-----------------------------------------------------------------------------
//GetDuration
//-----------------------------------------------------------------------------
CDSTEX_INLINE
BOOL CDSTex::GetDuration(double* pdbDuration)
{
HRESULT hr;
if(FAILED(hr=m_pMP->get_Duration(pdbDuration)))
{
this->SetLastError(CDSERR_CANNOTGETDURATION);
this->SetLastHRESULT(hr);
return FALSE;
}
else
{
this->SetLastError(CDSERR_OK);
this->SetLastHRESULT(hr);
return TRUE;
}
}
//-----------------------------------------------------------------------------
//GetCurrentPosition
//-----------------------------------------------------------------------------
CDSTEX_INLINE
BOOL CDSTex::GetCurrentPosition(double* pdbPosition)
{
HRESULT hr;
if(FAILED(hr=m_pMP->get_CurrentPosition(pdbPosition)))
{
this->SetLastError(CDSERR_CANNOTGETPOSITION);
this->SetLastHRESULT(hr);
return FALSE;
}
else
{
this->SetLastError(CDSERR_OK);
this->SetLastHRESULT(hr);
return TRUE;
}
}
//-----------------------------------------------------------------------------
//SetCurrentPosition
//-----------------------------------------------------------------------------
CDSTEX_INLINE
BOOL CDSTex::SetCurrentPosition(double dbPosition)
{
HRESULT hr;
if(FAILED(hr=m_pMP->put_CurrentPosition(dbPosition)))
{
this->SetLastError(CDSERR_CANNOTSETPOSITION);
this->SetLastHRESULT(hr);
return FALSE;
}
else
{
this->SetLastError(CDSERR_OK);
this->SetLastHRESULT(hr);
return TRUE;
}
}
//-----------------------------------------------------------------------------
//Play
//-----------------------------------------------------------------------------
CDSTEX_INLINE
BOOL CDSTex: lay()
{
HRESULT hr;
if(FAILED(hr=m_pMC->Run()))
{
this->SetLastError(CDSERR_CANNOTPLAY);
this->SetLastHRESULT(hr);
return FALSE;
}
else
{
this->SetLastError(CDSERR_OK);
this->SetLastHRESULT(hr);
return TRUE;
}
}
//-----------------------------------------------------------------------------
//Pause
//-----------------------------------------------------------------------------
CDSTEX_INLINE
BOOL CDSTex: ause()
{
HRESULT hr;
if(FAILED(hr=m_pMC-> ause()))
{
this->SetLastError(CDSERR_CANNOTPAUSE);
this->SetLastHRESULT(hr);
return FALSE;
}
else
{
this->SetLastError(CDSERR_OK);
this->SetLastHRESULT(hr);
return TRUE;
}
}
//-----------------------------------------------------------------------------
//Stop
//-----------------------------------------------------------------------------
CDSTEX_INLINE
BOOL CDSTex::Stop()
{
HRESULT hr;
if(FAILED(hr=m_pMC->Stop()))
{
this->SetLastError(CDSERR_CANNOTSTOP);
this->SetLastHRESULT(hr);
return FALSE;
}
else
{
this->SetLastError(CDSERR_OK);
this->SetLastHRESULT(hr);
return TRUE;
}
}
#endif
|