From 9ac44ad9d06f504aa7e53e0eb7480a40dce5d376 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sat, 29 Dec 2012 19:30:12 +0100 Subject: [PATCH] h264: check SPS entries directly to detect pixel format changes Comparing AVCodecContext.pix_fmt against the get_pixel_format() return value has the side effect of calling the get_format() callback on each slice. Users of the callback will probably handle hardware accelerator initialization in the callback. --- libavcodec/h264.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index fae8440a1e..366059722f 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -2592,7 +2592,6 @@ static int decode_slice_header(H264Context *h, H264Context *h0) int default_ref_list_done = 0; int last_pic_structure, last_pic_droppable; int needs_reinit = 0; - enum AVPixelFormat pix_fmt; /* FIXME: 2tap qpel isn't implemented for high bit depth. */ if ((s->avctx->flags2 & CODEC_FLAG2_FAST) && @@ -2669,8 +2668,14 @@ 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]; @@ -2709,24 +2714,17 @@ static int decode_slice_header(H264Context *h, H264Context *h0) s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; if (h->sps.colour_description_present_flag) { + if (s->avctx->colorspace != h->sps.colorspace) + needs_reinit = 1; s->avctx->color_primaries = h->sps.color_primaries; s->avctx->color_trc = h->sps.color_trc; s->avctx->colorspace = h->sps.colorspace; } } - ret = get_pixel_format(h); - if (ret < 0) - return ret; - else - pix_fmt = ret; - if (s->avctx->pix_fmt == PIX_FMT_NONE) - s->avctx->pix_fmt = pix_fmt; - if (s->context_initialized && (s->width != s->avctx->width || s->height != s->avctx->height || - pix_fmt != s->avctx->pix_fmt || needs_reinit || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) { @@ -2736,12 +2734,14 @@ static int decode_slice_header(H264Context *h, H264Context *h0) return AVERROR_INVALIDDATA; } - av_log(h->s.avctx, AV_LOG_INFO, "Reinit context to %dx%d, " - "pix_fmt: %d\n", s->width, s->height, pix_fmt); - flush_change(h); - s->avctx->pix_fmt = pix_fmt; + if ((ret = get_pixel_format(h)) < 0) + return ret; + s->avctx->pix_fmt = ret; + + av_log(h->s.avctx, AV_LOG_INFO, "Reinit context to %dx%d, " + "pix_fmt: %d\n", s->width, s->height, s->avctx->pix_fmt); if ((ret = h264_slice_header_init(h, 1)) < 0) { av_log(h->s.avctx, AV_LOG_ERROR, @@ -2756,6 +2756,11 @@ static int decode_slice_header(H264Context *h, H264Context *h0) "Cannot (re-)initialize context during parallel decoding.\n"); return -1; } + + if ((ret = get_pixel_format(h)) < 0) + return ret; + s->avctx->pix_fmt = ret; + if ((ret = h264_slice_header_init(h, 0)) < 0) { av_log(h->s.avctx, AV_LOG_ERROR, "h264_slice_header_init() failed\n");