Setting DXVA-HD States

During video processing, the Microsoft DirectX Video Acceleration High Definition (DXVA-HD) device maintains a persistent state from one frame to the next. Each state has a documented default. After you configure the device, set any states that you wish to change from their defaults. Before you process each frame, update any states that should change.

Note

This design differs from DXVA-VP. In DXVA-VP, the application must specify all of the VP parameters with each frame.

 

Device states fall into two categories:

  • Stream states apply each input stream separately. You can apply different settings to each stream.
  • Blit states apply globally to the entire video processing blit.

The following stream states are defined.

Stream State Description
DXVAHD_STREAM_STATE_D3DFORMAT Input video format.
DXVAHD_STREAM_STATE_FRAME_FORMAT Interlacing.
DXVAHD_STREAM_STATE_INPUT_COLOR_SPACE Input color space. This state specifies the RGB color range and the YCbCr transfer matrix for the input stream.
DXVAHD_STREAM_STATE_OUTPUT_RATE Output frame rate. This state controls frame-rate conversion.
DXVAHD_STREAM_STATE_SOURCE_RECT Source rectangle.
DXVAHD_STREAM_STATE_DESTINATION_RECT Destination rectangle.
DXVAHD_STREAM_STATE_ALPHA Planar alpha.
DXVAHD_STREAM_STATE_PALETTE Color palette. This state applies only to palettized input formats.
DXVAHD_STREAM_STATE_LUMA_KEY Luma key.
DXVAHD_STREAM_STATE_ASPECT_RATIO Pixel aspect ratio.
DXVAHD_STREAM_STATE_FILTER_Xxxx Image filter settings. The driver can support brightness, contrast, and other image filters.

 

The following blit states are defined:

Blit State Description
DXVAHD_BLT_STATE_TARGET_RECT Target rectangle.
DXVAHD_BLT_STATE_BACKGROUND_COLOR Background color.
DXVAHD_BLT_STATE_OUTPUT_COLOR_SPACE Output color space.
DXVAHD_BLT_STATE_ALPHA_FILL Alpha fill mode.
DXVAHD_BLT_STATE_CONSTRICTION Constriction. This state controls whether the device downsamples the output.

 

To set a stream state, call the IDXVAHD_VideoProcessor::SetVideoProcessStreamState method. To set a blit state, call the IDXVAHD_VideoProcessor::SetVideoProcessBltState method. In both of these methods, an enumeration value specifies the state to set. The state data is given using a state-specific data structure, which the application casts to a void* type.

The following code example sets the input format and destination rectangle for stream 0, and sets the background color to black.

HRESULT SetDXVAHDStates(HWND hwnd, D3DFORMAT inputFormat)
{
    // Set the initial stream states.

    // Set the format of the input stream

    DXVAHD_STREAM_STATE_D3DFORMAT_DATA d3dformat = { inputFormat };

    HRESULT hr = g_pDXVAVP->SetVideoProcessStreamState(
        0,  // Stream index
        DXVAHD_STREAM_STATE_D3DFORMAT,
        sizeof(d3dformat),
        &d3dformat
        );

    if (SUCCEEDED(hr))
    { 
        // For this example, the input stream contains progressive frames.

        DXVAHD_STREAM_STATE_FRAME_FORMAT_DATA frame_format = { DXVAHD_FRAME_FORMAT_PROGRESSIVE };
        
        hr = g_pDXVAVP->SetVideoProcessStreamState(
            0, // Stream index
            DXVAHD_STREAM_STATE_FRAME_FORMAT,
            sizeof(frame_format),
            &frame_format
            );
    }

    if (SUCCEEDED(hr))
    { 
        // Compute the letterbox area.

        RECT rcDest;
        GetClientRect(hwnd, &rcDest);

        RECT rcSrc;
        SetRect(&rcSrc, 0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);

        rcDest = LetterBoxRect(rcSrc, rcDest);

        // Set the destination rectangle, so the frame is displayed within the 
        // letterbox area. Otherwise, the frame is stretched to cover the 
        // entire surface.

        DXVAHD_STREAM_STATE_DESTINATION_RECT_DATA DstRect = { TRUE, rcDest };

        hr = g_pDXVAVP->SetVideoProcessStreamState(
            0, // Stream index 
            DXVAHD_STREAM_STATE_DESTINATION_RECT,
            sizeof(DstRect),
            &DstRect
            );
    }

    if (SUCCEEDED(hr))
    { 
        DXVAHD_COLOR_RGBA rgbBackground = { 0.0f, 0.0f, 0.0f, 1.0f };  // RGBA

        DXVAHD_BLT_STATE_BACKGROUND_COLOR_DATA background = { FALSE, rgbBackground };

        hr = g_pDXVAVP->SetVideoProcessBltState(
            DXVAHD_BLT_STATE_BACKGROUND_COLOR,
            sizeof (background),
            &background
            );
    }

    return hr;
}

DXVA-HD