Interface IVideoRendererVMR9
- Namespace
- VisioForge.Core.Types
- Assembly
- VisioForge.Core.dll
Defines the contract for the Video Mixing Renderer 9 (VMR-9), which is used for rendering video on Windows.
public interface IVideoRendererVMR9 : IVideoRendererBaseImplements
Examples
// Example of using VMR-9 renderer for custom video positioning:
IVideoRendererVMR9 vmr9 = GetVMR9Renderer();
// Define source rectangle (crop the video)
var srcRect = new DsRect(100, 50, 720, 480); // Crop to 720x480 starting at (100,50)
// Define destination rectangle (where to display)
var dstRect = new DsRect(0, 0, 1280, 720); // Scale to fill 1280x720 window
// Apply the positioning asynchronously
vmr9.VMR9SetVideoPosition(srcRect, dstRect, async_: true);
// Handle display mode changes (e.g., monitor resolution change)
vmr9.VMR9DisplayModeChanged(async_: true);
// Force repaint when needed
IntPtr windowHandle = GetWindowHandle();
IntPtr deviceContext = GetDC(windowHandle);
vmr9.VMR9RepaintVideo(windowHandle, deviceContext, async_: true);
ReleaseDC(windowHandle, deviceContext);
Remarks
VMR-9 is a DirectShow filter that provides advanced video rendering capabilities on Windows platforms. It supports hardware acceleration, multiple video streams mixing, alpha blending, and deinterlacing. This interface provides direct control over VMR-9's rendering behavior.
Key features of VMR-9:
- Hardware-accelerated rendering using Direct3D 9
- Support for mixing multiple video streams
- Alpha blending and transparency effects
- Custom allocator-presenter support for advanced scenarios
- Windowless rendering mode for better integration with applications
Implementation notes:
- All methods support both synchronous and asynchronous execution
- Async operations are recommended for UI responsiveness
- The renderer must be properly initialized before calling these methods
- Window handles must remain valid throughout the renderer's lifetime
Methods
VMR9DisplayModeChanged(bool)
Notifies the renderer that the display mode has changed.
void VMR9DisplayModeChanged(bool async_)Parameters
async_bool-
If set to
true, the operation is performed asynchronously without blocking the calling thread.
Remarks
Call this method when the display resolution, color depth, or refresh rate changes. This ensures the renderer can adapt to the new display configuration and maintain optimal rendering quality. Common scenarios include monitor resolution changes, moving windows between monitors, or switching between fullscreen and windowed modes.
VMR9RepaintVideo(nint, nint, bool)
Repaints the current video frame.
void VMR9RepaintVideo(nint host, nint hdc, bool async_)Parameters
hostnint-
The window handle of the host application where the video should be rendered.
hdcnint-
The device context handle for drawing. Can be IntPtr.Zero to use the default device context.
async_bool-
If set to
true, the operation is performed asynchronously without blocking the calling thread.
Remarks
This method is useful when you need to force a refresh of the video display, such as after window invalidation or when the video appears frozen. The async parameter allows for non-blocking operation which is important for maintaining UI responsiveness.
VMR9SetVideoPosition(DsRect, DsRect, bool)
Sets the source and destination rectangles for the video, allowing for cropping and scaling.
void VMR9SetVideoPosition(DsRect srcRect, DsRect dstRect, bool async_)Parameters
srcRectDsRect-
The source rectangle within the original video frame. Defines which portion of the video to display.
dstRectDsRect-
The destination rectangle on the display surface. Defines where and at what size to render the video.
async_bool-
If set to
true, the operation is performed asynchronously without blocking the calling thread.
Remarks
This method provides precise control over video positioning and scaling. The source rectangle allows you to crop the video by selecting only a portion of the original frame. The destination rectangle determines where the video appears and its display size.
Common use cases:
- Implementing pan and zoom functionality
- Letterboxing or pillarboxing to maintain aspect ratio
- Picture-in-picture displays
- Custom video layouts in multi-stream scenarios