Module: libav
Branch: release/0.8
Commit: 38648e22a86c4fec0d438ebf62d5c9b4279e179e

Author:    Diego Biurrun <[email protected]>
Committer: Diego Biurrun <[email protected]>
Date:      Thu Nov 17 17:24:13 2016 +0100

h264: Reinit the context on pixel format changes

Fixes all kinds of undefined behavior in such cases.

Bug-Id: 939

---

 libavcodec/h264.c |    7 ++++++-
 libavcodec/h264.h |    3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index c53799d..2f54508 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -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");
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index c0e043e..ebb032d 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -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;

_______________________________________________
libav-commits mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-commits

Reply via email to