video.h
[與此頁面 相關的功能 DirectShow是舊版功能。 它已被 MediaPlayer、 IMFMediaEngine和 Media Foundation 中的音訊/視訊擷取取代。 這些功能已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用 MediaPlayer、 IMFMediaEngine 和 音訊/視訊擷取 ,而不是 DirectShow。 Microsoft 建議盡可能重寫使用舊版 API 的現有程式碼,以使用新的 API。]
本主題包含 DirectShow 中音訊/視訊播放教學課程的程式碼。
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
#pragma once
#include <windows.h>
#include <dshow.h>
#include <d3d9.h>
#include <Vmr9.h>
#include <Evr.h>
template <class T> void SafeRelease(T **ppT)
{
if (*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}
HRESULT RemoveUnconnectedRenderer(IGraphBuilder *pGraph, IBaseFilter *pRenderer, BOOL *pbRemoved);
HRESULT AddFilterByCLSID(IGraphBuilder *pGraph, REFGUID clsid, IBaseFilter **ppF, LPCWSTR wszName);
// Abstract class to manage the video renderer filter.
// Specific implementations handle the VMR-7, VMR-9, or EVR filter.
class CVideoRenderer
{
public:
virtual ~CVideoRenderer() {};
virtual BOOL HasVideo() const = 0;
virtual HRESULT AddToGraph(IGraphBuilder *pGraph, HWND hwnd) = 0;
virtual HRESULT FinalizeGraph(IGraphBuilder *pGraph) = 0;
virtual HRESULT UpdateVideoWindow(HWND hwnd, const LPRECT prc) = 0;
virtual HRESULT Repaint(HWND hwnd, HDC hdc) = 0;
virtual HRESULT DisplayModeChanged() = 0;
};
// Manages the VMR-7 video renderer filter.
class CVMR7 : public CVideoRenderer
{
IVMRWindowlessControl *m_pWindowless;
public:
CVMR7();
~CVMR7();
BOOL HasVideo() const;
HRESULT AddToGraph(IGraphBuilder *pGraph, HWND hwnd);
HRESULT FinalizeGraph(IGraphBuilder *pGraph);
HRESULT UpdateVideoWindow(HWND hwnd, const LPRECT prc);
HRESULT Repaint(HWND hwnd, HDC hdc);
HRESULT DisplayModeChanged();
};
// Manages the VMR-9 video renderer filter.
class CVMR9 : public CVideoRenderer
{
IVMRWindowlessControl9 *m_pWindowless;
public:
CVMR9();
~CVMR9();
BOOL HasVideo() const;
HRESULT AddToGraph(IGraphBuilder *pGraph, HWND hwnd);
HRESULT FinalizeGraph(IGraphBuilder *pGraph);
HRESULT UpdateVideoWindow(HWND hwnd, const LPRECT prc);
HRESULT Repaint(HWND hwnd, HDC hdc);
HRESULT DisplayModeChanged();
};
// Manages the EVR video renderer filter.
class CEVR : public CVideoRenderer
{
IBaseFilter *m_pEVR;
IMFVideoDisplayControl *m_pVideoDisplay;
public:
CEVR();
~CEVR();
BOOL HasVideo() const;
HRESULT AddToGraph(IGraphBuilder *pGraph, HWND hwnd);
HRESULT FinalizeGraph(IGraphBuilder *pGraph);
HRESULT UpdateVideoWindow(HWND hwnd, const LPRECT prc);
HRESULT Repaint(HWND hwnd, HDC hdc);
HRESULT DisplayModeChanged();
};
相關主題