diff mbox

[FFmpeg-devel,4/4] avcodec/videotoolbox: fix decoding of some hevc videos

Message ID 20180504225711.69909-4-ffmpeg@tmm1.net
State Superseded
Headers show

Commit Message

Aman Gupta May 4, 2018, 10:57 p.m. UTC
From: Aman Gupta <aman@tmm1.net>

See https://s3.amazonaws.com/tmm1/videotoolbox/germany-hevc-zdf.ts

Although videotoolbox_buffer_create() sets frame->hw_frames_ctx,
by the time videotoolbox_postproc_frame() is called, some frames
randomly have frame->hw_frames_ctx == NULL. I don't really
understand what's going on, and why this only affects some frames
and only in some hevc videos.

This patch attempts to detect the missing hw_frames_ctx and reset
it in the post_process callback. This is obviously a huge hack, but
it does fix playback of the affected samples.
---
 libavcodec/videotoolbox.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox

Patch

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 08b133e1b1..279180179d 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -73,6 +73,7 @@  static int videotoolbox_buffer_copy(VTContext *vtctx,
 
 static int videotoolbox_postproc_frame(void *avctx, AVFrame *frame)
 {
+    VTContext *vtctx = ((AVCodecContext *)avctx)->internal->hwaccel_priv_data;
     CVPixelBufferRef ref = *(CVPixelBufferRef *)frame->buf[0]->data;
 
     if (!ref) {
@@ -83,6 +84,11 @@  static int videotoolbox_postproc_frame(void *avctx, AVFrame *frame)
 
     frame->data[3] = (uint8_t*)ref;
 
+    if (!frame->hw_frames_ctx)
+        frame->hw_frames_ctx = av_buffer_ref(vtctx->cached_hw_frames_ctx);
+    if (!frame->hw_frames_ctx)
+        return AVERROR(ENOMEM);
+
     return 0;
 }