with these changes to fix chroma format and bit depth changes h264.c
looks mostly ok too. Please amend to the original patch.
Janne
---8<---
---
libavcodec/h264.c | 28 +++++++++++++++-------------
libavcodec/h264.h | 3 ++-
2 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 14435f0..add804a 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1229,6 +1229,9 @@ static av_cold void common_init(H264Context *h)
h->width = h->avctx->width;
h->height = h->avctx->height;
+ h->bit_depth_luma = 8;
+ h->chroma_format_idc = 1;
+
ff_h264dsp_init(&h->h264dsp, 8, 1);
ff_h264chroma_init(&h->h264chroma, h->sps.bit_depth_chroma);
ff_h264qpel_init(&h->h264qpel, 8);
@@ -1415,6 +1418,7 @@ static int decode_update_thread_context(AVCodecContext
*dst,
{
H264Context *h = dst->priv_data, *h1 = src->priv_data;
int inited = h->context_initialized, err = 0;
+ int context_reinitialized = 0;
int i;
if (dst == src || !h1->context_initialized)
@@ -1443,7 +1447,7 @@ static int decode_update_thread_context(AVCodecContext
*dst,
av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed");
return err;
}
- h->context_reinitialized = 1;
+ context_reinitialized = 1;
/* update linesize on resize. The decoder doesn't
* necessarily call ff_h264_frame_start in the new thread */
@@ -1452,7 +1456,6 @@ static int decode_update_thread_context(AVCodecContext
*dst,
/* copy block_offset since frame_start may not be called */
memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset));
- h264_set_parameter_from_sps(h);
}
if (!inited) {
@@ -1568,6 +1571,9 @@ static int decode_update_thread_context(AVCodecContext
*dst,
h->last_slice_type = h1->last_slice_type;
+ if (context_reinitialized)
+ h264_set_parameter_from_sps(h);
+
if (!h->cur_pic_ptr)
return 0;
@@ -3029,19 +3035,18 @@ static int decode_slice_header(H264Context *h,
H264Context *h0)
}
if (h->pps.sps_id != h->current_sps_id ||
- h->context_reinitialized ||
h0->sps_buffers[h->pps.sps_id]->new) {
- SPS *new_sps = h0->sps_buffers[h->pps.sps_id];
-
h0->sps_buffers[h->pps.sps_id]->new = 0;
- if (h->sps.chroma_format_idc != new_sps->chroma_format_idc ||
- h->sps.bit_depth_luma != new_sps->bit_depth_luma)
- needs_reinit = 1;
-
h->current_sps_id = h->pps.sps_id;
h->sps = *h0->sps_buffers[h->pps.sps_id];
+ if (h->bit_depth_luma != h->sps.bit_depth_luma ||
+ h->chroma_format_idc != h->sps.chroma_format_idc) {
+ h->bit_depth_luma = h->sps.bit_depth_luma;
+ h->chroma_format_idc = h->sps.chroma_format_idc;
+ needs_reinit = 1;
+ }
if ((ret = h264_set_parameter_from_sps(h)) < 0)
return ret;
}
@@ -3090,8 +3095,7 @@ static int decode_slice_header(H264Context *h,
H264Context *h0)
if (h->context_initialized &&
(h->width != h->avctx->width ||
h->height != h->avctx->height ||
- needs_reinit ||
- av_cmp_q(h->sps.sar, h->avctx->sample_aspect_ratio))) {
+ needs_reinit)) {
if (h != h0) {
av_log(h->avctx, AV_LOG_ERROR, "changing width/height on "
@@ -3113,7 +3117,6 @@ static int decode_slice_header(H264Context *h,
H264Context *h0)
"h264_slice_header_init() failed\n");
return ret;
}
- h->context_reinitialized = 1;
}
if (!h->context_initialized) {
if (h != h0) {
@@ -4563,7 +4566,6 @@ out:
decode_postinit(h, 1);
field_end(h, 0);
- h->context_reinitialized = 0;
if (!h->next_output_pic) {
/* Wait for second field. */
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 6d57723..45c134e 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -485,7 +485,8 @@ typedef struct H264Context {
int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4)
int got_first; ///< this flag is != 0 if we've parsed a frame
- int context_reinitialized;
+ int bit_depth_luma; ///< luma bit depth from sps to detect changes
+ int chroma_format_idc; ///< chroma format from sps to detect changes
SPS *sps_buffers[MAX_SPS_COUNT];
PPS *pps_buffers[MAX_PPS_COUNT];
--
1.8.1.2
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel