Use the correct width and height of the test frame when performing the test decode

Using the stream resolution instead of the test frame resolution was causing all non-720p streams to fail on the VisionFive 2 board with the wave5 driver.

It also likely fixes a similar interoperability issue with the qcom-venus driver that was reported in #1042
This commit is contained in:
Cameron Gutman 2023-09-14 18:16:45 -05:00
parent edfb3cfdc8
commit 1dd6cdb567
2 changed files with 18 additions and 2 deletions

View file

@ -796,6 +796,19 @@ bool FFmpegVideoDecoder::tryInitializeRenderer(const AVCodec* decoder,
const AVCodecHWConfig* hwConfig,
std::function<IFFmpegRenderer*()> createRendererFunc)
{
DECODER_PARAMETERS testFrameDecoderParams = *params;
// Setup the test decoder parameters using the dimensions for the test frame. These are
// used to populate the AVCodecContext fields of the same names.
//
// While most decoders don't care what dimensions we specify here, V4L2M2M seems to puke
// if we pass whatever the native stream resolution is then decode a 720p test frame.
//
// For qcom-venus, it seems to lead to failures allocating capture buffers (bug #1042).
// For wave5 (VisionFive), it leads to an invalid pitch error when calling drmModeAddFB2().
testFrameDecoderParams.width = 1280;
testFrameDecoderParams.height = 720;
m_HwDecodeCfg = hwConfig;
// i == 0 - Indirect via EGL or DRM frontend with zero-copy DMA-BUF passing
@ -807,8 +820,8 @@ bool FFmpegVideoDecoder::tryInitializeRenderer(const AVCodec* decoder,
#endif
SDL_assert(m_BackendRenderer == nullptr);
if ((m_BackendRenderer = createRendererFunc()) != nullptr &&
m_BackendRenderer->initialize(params) &&
completeInitialization(decoder, params, m_TestOnly || m_BackendRenderer->needsTestFrame(), i == 0 /* EGL/DRM */)) {
m_BackendRenderer->initialize(m_BackendRenderer->needsTestFrame() ? &testFrameDecoderParams : params) &&
completeInitialization(decoder, m_BackendRenderer->needsTestFrame() ? &testFrameDecoderParams : params, m_TestOnly || m_BackendRenderer->needsTestFrame(), i == 0 /* EGL/DRM */)) {
if (m_TestOnly) {
// This decoder is only for testing capabilities, so don't bother
// creating a usable renderer

View file

@ -1,5 +1,8 @@
#include "ffmpeg.h"
// NOTE: All test frames MUST be 720p in order for us to provide the correct dimensions in the AVCodecContext!
// See FFmpegVideoDecoder::tryInitializeRenderer() for details.
// 720p 60 FPS H.264 with 1 reference frame
const uint8_t FFmpegVideoDecoder::k_H264TestFrame[] = {
0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x20, 0xac, 0x2b, 0x40, 0x28, 0x02, 0xdd, 0x80, 0xb5, 0x06, 0x06, 0x06, 0xa5, 0x00, 0x00, 0x03, 0x03, 0xe8, 0x00, 0x01, 0xd4, 0xc0, 0x8f, 0x4a, 0xa0,