Skip to content

Commit

Permalink
Fix incorrect selection if pix_fmt is overridden before ffGetFormat()
Browse files Browse the repository at this point in the history
The DRM renderer does this for the out-of-tree v4l2m2m patches to ensure
we get NV12 buffers, but it ends up clobbering our own preference for
DRM_PRIME frames in the process.
  • Loading branch information
cgutman committed Oct 4, 2024
1 parent 3279d9c commit 9936085
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/streaming/video/ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,33 @@ enum AVPixelFormat FFmpegVideoDecoder::ffGetFormat(AVCodecContext* context,
const enum AVPixelFormat* pixFmts)
{
FFmpegVideoDecoder* decoder = (FFmpegVideoDecoder*)context->opaque;
const enum AVPixelFormat *p;
const AVPixelFormat *p;
AVPixelFormat desiredFmt;

for (p = pixFmts; *p != -1; p++) {
if (decoder->m_HwDecodeCfg) {
desiredFmt = decoder->m_HwDecodeCfg->pix_fmt;
}
else if (decoder->m_RequiredPixelFormat != AV_PIX_FMT_NONE) {
desiredFmt = decoder->m_RequiredPixelFormat;
}
else {
desiredFmt = decoder->m_FrontendRenderer->getPreferredPixelFormat(decoder->m_VideoFormat);
}

for (p = pixFmts; *p != AV_PIX_FMT_NONE; p++) {
// Only match our hardware decoding codec or preferred SW pixel
// format (if not using hardware decoding). It's crucial
// to override the default get_format() which will try
// to gracefully fall back to software decode and break us.
if (*p == (decoder->m_HwDecodeCfg ? decoder->m_HwDecodeCfg->pix_fmt : context->pix_fmt) &&
decoder->m_BackendRenderer->prepareDecoderContextInGetFormat(context, *p)) {
if (*p == desiredFmt && decoder->m_BackendRenderer->prepareDecoderContextInGetFormat(context, *p)) {
return *p;
}
}

// Failed to match the preferred pixel formats. Try non-preferred pixel format options
// for non-hwaccel decoders if we didn't have a required pixel format to use.
if (decoder->m_HwDecodeCfg == nullptr && decoder->m_RequiredPixelFormat == AV_PIX_FMT_NONE) {
for (p = pixFmts; *p != -1; p++) {
for (p = pixFmts; *p != AV_PIX_FMT_NONE; p++) {
if (decoder->m_FrontendRenderer->isPixelFormatSupported(decoder->m_VideoFormat, *p) &&
decoder->m_BackendRenderer->prepareDecoderContextInGetFormat(context, *p)) {
return *p;
Expand Down

0 comments on commit 9936085

Please sign in to comment.