扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:BLOG 2007年10月16日
关键字: VC DirectShow 视频
#include "ddraw.h" #include "mmstream.h" #include "amstream.h" #include "ddstream.h" |
DDSURFACEDESC ddsd; IDirectDraw *pDD; IDirectDrawSurface *pPrimarySurface; IMultiMediaStream *pMMStream; |
HRESULT Init() { ...... pDD=NULL; pPrimarySurface=NULL; pMMStream=NULL; ZeroMemmory(ddsd,sizeof(ddsd)); HRESULT r; //初始化COM CoInitialize(NULL); //初始化DirectDraw r=InitDDraw(); return r; } |
void Uninit() { ...... if(pMMStream!=NULL) pMMStream->Release(); if(pPrimarySurface!=NULL) pPrimarySurface->Release(); if(pDD!=NULL) pDD->Release(); CoUninitialize(); } |
HRESULT InitDDraw() { HRESULT r; if(FAILED(r=DirectDrawCreate(NULL, &pDD, NULL))) return r; if(FAILED(r=pDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN))) return r; if(FAILED(r=pDD->SetDisplayMode(640,480,16))) //分辨率设置 return r; ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if(FAILED(pDD->CreateSurface(&ddsd, &pPrimarySurface, NULL))) return r; return S_OK; } |
HRESULT LoadFromFile(const char * szFileName, IMultiMediaStream **ppMMStream, IDirectDraw *pDD) { HRESULT r; IAMMultiMediaStream *pAMStream; if(FAILED(r=CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER, IID_IAMMultiMediaStream, (void **)&pAMStream))) return r; WCHAR wPath[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, szFileName, -1, wPath, sizeof(wPath)/sizeof(wPath[0])); if(FAILED(r=pAMStream->Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD, NULL))) return r; if(FAILED(r=pAMStream->AddMediaStream(pDD, &MSPID_PrimaryVideo, 0, NULL))) return r; if(FAILED(r=pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL))) return r; if(FAILED(r=pAMStream->OpenFile(wPath, 0))) return r; *ppMMStream = pAMStream; return S_OK; } |
const char * szFileName, IMultiMediaStream **ppMMStream和IDirectDraw *pDD |
HRESULT Play(IDirectDrawSurface *pSurface, IMultiMediaStream *pMMStream) { IMediaStream *pPrimaryVidStream; IDirectDrawMediaStream *pDDStream; IDirectDrawStreamSample *pSample; RECT rect; DDSURFACEDESC ddsd; pMMStream->GetMediaStream(MSPID_PrimaryVideo, &pPrimaryVidStream); pPrimaryVidStream->QueryInterface(IID_IDirectDrawMediaStream, (void **)&pDDStream); ddsd.dwSize = sizeof(ddsd); pDDStream->GetFormat(&ddsd, NULL, NULL, NULL); rect.top =100; rect.left =150; rect.bottom = ddsd.dwHeight+100; rect.right = ddsd.dwWidth+150; pDDStream->CreateSample(pSurface, &rect, 0, &pSample); pMMStream->SetState(STREAMSTATE_RUN); while (pSample->Update(0, NULL, NULL, NULL) == S_OK); pMMStream->SetState(STREAMSTATE_STOP); pSample->Release(); pDDStream->Release(); pPrimaryVidStream->Release(); } |
IMediaStream *pPrimaryVidStream; IDirectDrawMediaStream *pDDStream; IDirectDrawStreamSample *pSample; RECT rect; DDSURFACEDESC ddsd; |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者