共用方式為


步驟 2:宣告 CVideoRenderer 和衍生類別

[與此頁面相關的功能 DirectShow是舊版功能。 它已被 MediaPlayerIMFMediaEngineMedia Foundation 中的音訊/視訊擷取取代。 這些功能已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用 MediaPlayerIMFMediaEngine音訊/視訊擷取 ,而不是 DirectShow。 Microsoft 建議使用舊版 API 的現有程式碼盡可能重寫為使用新的 API。

本主題是 DirectShow 中音訊/視訊播放教學課程的步驟 2。 完整的程式碼會顯示在 DirectShow 播放範例主題中。

DirectShow 提供數個不同的篩選來轉譯視訊:

如需這些篩選準則之間差異的詳細資訊,請參閱 選擇正確的影片轉譯器

在本教學課程中,下列抽象類別是用來包裝影片轉譯器篩選。

// 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;
};

注意:

  • 如果已建立視訊轉譯器,此方法 HasVideo 會傳回 TRUE
  • 方法 AddToGraph 會將視訊轉譯器新增至篩選圖形。
  • 方法 FinalizeGraph 會完成圖形建置步驟。
  • UpdateVideoWindow方法會更新視訊目的地矩形。
  • 方法會 Repaint 重新繪製目前的視訊畫面。
  • 方法會 DisplayModeChanged 處理顯示模式變更。

本教學課程稍後會詳細說明這些方法。

接下來,宣告衍生類別來包裝三個視訊轉譯器:EVR、VMR-9 和 VMR-7。

CEVR 類別

類別 CEVR 會管理 EVR。 它包含 EVR 之 IBaseFilterIMFVideoDisplayControl 介面的指標。

// 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();
};

CVMR9 類別

類別 CVMR9 會管理 VMR-9。 它包含 IVMRWindowlessControl9 介面的指標。

// 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();
};

CVMR7 類別

類別 CVMR7 會管理 VMR-7。 它包含 IVMRWindowlessControl 介面的指標。

// 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();
};

下一 步:步驟 3:建置篩選圖形

DirectShow 中的音訊/視訊播放

使用影片混合轉譯器

影片轉譯