DSHOW Using VMR for Windowless Control

xiaoxiao2021-04-01  218

General steps:

Create a Graph Builder interface

Create a VMR interface and add to Graphbuiler

Query the IVMRFILTERCONFIG interface Set VMRMRMODE_WINDOWLESS mode; query the IVMWindowLessControl interface Set the VMR display window to the Application window.

Render video file

SetVideoPositon Set the location of the video display

Query IMEDIALCONTROL Interface and Run

Corresponding WM_PAINT message, pay attention to the background and video windows of the digging of the video window (PWC-> RepaintVideo)

Clean up the work (when to clean those interfaces, it is still unclear, and then study ^ _ ^)

Still write it first, because it is easy to forget, and the process is more difficult, huh, huh.

note:

Playing no own window, is directly putting the video drawn on the Application window, so when Application needs to respond to the WM_PAINT message, pay attention to the video's drawing (PAINT).

At this point, Windowless video playback "Window" (actually Windowless) and Application's window should be separated separately (corresponding WM_PAIN).

First, check if there is a video window on the Windowless window on the window of the Application:

IF (PWC). Where PWC is the created IVMRWindowLESSCONTROL interface. If the PWC! = NULL indicates that there is video, then dig the Windowless window by creating a Combinerg, first redraw this comBinergn, then call

PWC-> Repaintvideo re-paints the Windowless video window. which is

Void OnPaint (HWND HWND)

{

Paintstruct PS;

HDC HDC;

Rect rcclient;

GetClientRect (hwnd, & rcclient);

HDC = BeginPaint (HWND, & PS);

IF (g_pwc)

{

HRGN RGNCLIENT = CreateRectrGnIndirect (& RCLIENT);

HRGN RGNVIDEO = CreateRectrGnIndirect (& g_rcdest); // Saved from Earlier.

Combinergn (Rgnclient, RGNCLIENT, RGNVIDEO, RGN_DIFF); // Paint On This Region.

Hbrush Hbr = GetSysColorbrush (color_btnface);

FillRgn (HDC, RGNCLIENT, HBR);

DeleteObject (HBR);

DeleteObject (RGNCLIENT);

DeleteObject (RGNVideo);

// Request the VMR to Paint the video.

HRESULT HR = g_pwc-> repaintvideo (hwnd, hdc);

}

Else // no video image. Just Paint The Whole Client Area.

{

FillRect (HDC, & RC2, (Hbrush) (Color_BTNFACE 1);

}

Endpaint (hwnd, & ps);

}

The type of VMR COM interface is IBASEFILTER, and the COCREATEINSTANCE third parameter is IID_IBASEFILTER.

Graph Buider is iGraphBuilder, and the COCREATEINSTANCE third parameter is IID_IGRAPHBUILDER After creating a VMR instance interface, the filter should be added to the Graph Builder.

PGRAPH-> AddFilter (PVMR, L "Video Mixing Render);

// The second parameter seems to take a name casually, just a name.

The VMR should be configured after the VMR is created and added to the Graph Builder. Here you need to query two interfaces: IVMRFILTERCONFIG and IVMRWINDOWLESSCONTROL, set the rendering mode for Windowless (

PCONFIG-> SetRenderingMode, set the window of the VMR to the Application window (

PWC-> SetVideoClippingWindow (HwinMain))

You also need to specify the location of the Windowless video window in the Application window: PWC-> SetVideoPOSISTON (& RCSRC, & RCDEST). There are two RECTs, representing the size zone of the source video and the area sizes to be displayed on the window. The source area size can be obtained via PWC-> GetnativeVideoSize ((& lwidth, & lheight, null, null), then set how much size RECT: setRect (& RCSRC, 0, 0, LWIDTH / 2, LHEIGHT / 2) / / At this point, only 1/2 of the source screen is taken. Then set the zone RCDEST to be set to set it with the PWC-> SetVideoPOSISTON.

What does Color_BTnFace 1 mean? It seems that 1 is not 1 is almost the same?

转载请注明原文地址:https://www.9cbs.com/read-131282.html

New Post(0)