From c5819a0682f3ee19532465ac9d7923d2c3f91975 Mon Sep 17 00:00:00 2001 From: Klaas de Waal Date: Wed, 3 Nov 2021 21:18:47 +0100 Subject: [PATCH] Restarting playback with VDPAU after PMT change Playback of some recordings of the Finnish broadcaster YLE fails when the VDPAU hardware accelerator is selected in the playback profile. This is caused by a restart of the video decoding after a PMT change. This problem only occurs with the MythTV-specific demuxer (mpegts-mythtv.c) and not with the original FFmpeg demuxer (mpegts.c) because the FFmpeg demuxer largely ignores PMT changes once playback has started. The first time the VDPAU codec support is checked, the pixel format is given as AV_PIX_FMT_YUV420P. This pixel format translates to video frame type FMT_YV12. There is a check if the video frame type is FMT_YV12 and this check succeeds. At the end, when it is decided that VDPAU can be used, the pixel format is set to AV_PIX_FMT_VDPAU. After a playback restart following a PMT change the VDPAU codec support is checked again. The AVCodecContext is re-used and the pixel format is still set to AV_PIX_FMT_VDPAU. This pixel format translate to video frame type FMT_VDPAU. The check if the frame type is FMT_YV12 now fails and there is an attempt to continue with FFMPEG decoding. This also fails, then resulting in a black screen while waiting forever. The fix is to accept also video frame type FMT_VDPAU for use with VDPAU decoding. This does solve the playback problems of all available YLE test clips. It can possibly also solve playback problems in other cases where the PMT changes such as when a channel that is broadcasting only part of the day does start broadcasting. Note that in the beginning of MythVDPAUContext::GetSupportedCodec there is a check if frame type FMT_VDPAU is supported and VDPAU can only be used if this is the case. It therefore makes sense to accept FMT_VDPAU as a valid video frame type and it was probably an omission in the original code that this frame type was not accepted. Refs #402 --- mythtv/libs/libmythtv/decoders/mythvdpaucontext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mythtv/libs/libmythtv/decoders/mythvdpaucontext.cpp b/mythtv/libs/libmythtv/decoders/mythvdpaucontext.cpp index fba4ac66e31..47c4d1b0a4c 100644 --- a/mythtv/libs/libmythtv/decoders/mythvdpaucontext.cpp +++ b/mythtv/libs/libmythtv/decoders/mythvdpaucontext.cpp @@ -68,7 +68,7 @@ int MythVDPAUContext::InitialiseContext(AVCodecContext* Context) return -1; } - // allocate the hardware frames context + // Allocate the hardware frames context Context->hw_frames_ctx = av_hwframe_ctx_alloc(hwdeviceref); if (!Context->hw_frames_ctx) { @@ -137,7 +137,7 @@ MythCodecID MythVDPAUContext::GetSupportedCodec(AVCodecContext **Context, // VDPAU only supports 8bit 420p:( VideoFrameType type = MythAVUtil::PixelFormatToFrameType((*Context)->pix_fmt); - bool vdpau = (type == FMT_YV12) && MythVDPAUHelper::HaveVDPAU() && + bool vdpau = (type == FMT_YV12 || type == FMT_VDPAU) && MythVDPAUHelper::HaveVDPAU() && (decodeonly ? codec_is_vdpau_dechw(success) : codec_is_vdpau_hw(success)); if (vdpau)