h264: Reinit the context on pixel format changes
authorDiego Biurrun <diego@biurrun.de>
Thu, 17 Nov 2016 16:24:13 +0000 (17:24 +0100)
committerDiego Biurrun <diego@biurrun.de>
Thu, 17 Nov 2016 16:24:13 +0000 (17:24 +0100)
Fixes all kinds of undefined behavior in such cases.

Bug-Id: 939

libavcodec/h264.c
libavcodec/h264.h

index c53799d..2f54508 100644 (file)
@@ -2795,7 +2795,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
 
     if (s->context_initialized
         && (   s->width != s->avctx->width || s->height != s->avctx->height
-            || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {
+            || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio) ||
+            h->chroma_format_idc != h->sps.chroma_format_idc ||
+            h->bit_depth         != h->sps.bit_depth_luma)) {
         if(h != h0 || (HAVE_THREADS && h->s.avctx->active_thread_type & FF_THREAD_FRAME)) {
             av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0);
             return AVERROR_PATCHWELCOME;   // width / height changed during parallelized decoding
@@ -2886,6 +2888,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
         s->first_field = 0;
         h->prev_interlaced_frame = 1;
 
+        h->chroma_format_idc = h->sps.chroma_format_idc;
+        h->bit_depth         = h->sps.bit_depth_luma;
+
         init_scan_tables(h);
         if (ff_h264_alloc_tables(h) < 0) {
             av_log(h->s.avctx, AV_LOG_ERROR, "Could not allocate memory for h264\n");
index c0e043e..ebb032d 100644 (file)
@@ -350,6 +350,9 @@ typedef struct H264Context{
     int slice_type_nos;        ///< S free slice type (SI/SP are remapped to I/P)
     int slice_type_fixed;
 
+    int chroma_format_idc;
+    int bit_depth;
+
     //interlacing specific flags
     int mb_aff_frame;
     int mb_field_decoding_flag;