diff options
author | Anton Khirnov <anton@khirnov.net> | 2016-10-02 15:39:10 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2016-12-14 09:06:45 +0100 |
commit | 86157e6db2c7a9222f77fa7e7f50fb9aebc3aa81 (patch) | |
tree | 43836ce28517e70bceb65d3b62cb96e0a5579bdf | |
parent | 730c02326094bcfb1fa67f10a7e7b22f03f5a88f (diff) | |
download | ffmpeg-86157e6db2c7a9222f77fa7e7f50fb9aebc3aa81.tar.gz |
hevc: decouple calling get_format() from exporting the SPS parameters
This makes sure ff_get_format() does not get called unnecessarily from
update_thread_context().
-rw-r--r-- | libavcodec/hevcdec.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 9dd86c289e..27fd6832ab 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -380,24 +380,10 @@ static void export_stream_params(AVCodecContext *avctx, const HEVCParamSets *ps, num, den, 1 << 30); } -static int set_sps(HEVCContext *s, const HEVCSPS *sps) +static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps) { #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + CONFIG_HEVC_D3D11VA_HWACCEL + CONFIG_HEVC_VDPAU_HWACCEL) enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts; - int ret; - - pic_arrays_free(s); - s->ps.sps = NULL; - s->ps.vps = NULL; - - if (!sps) - return 0; - - ret = pic_arrays_init(s, sps); - if (ret < 0) - goto fail; - - export_stream_params(s->avctx, &s->ps, sps); if (sps->pix_fmt == AV_PIX_FMT_YUV420P || sps->pix_fmt == AV_PIX_FMT_YUVJ420P || sps->pix_fmt == AV_PIX_FMT_YUV420P10) { @@ -417,10 +403,28 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps) *fmt++ = sps->pix_fmt; *fmt = AV_PIX_FMT_NONE; - ret = ff_get_format(s->avctx, pix_fmts); + return ff_get_format(s->avctx, pix_fmts); +} + +static int set_sps(HEVCContext *s, const HEVCSPS *sps, + enum AVPixelFormat pix_fmt) +{ + int ret; + + pic_arrays_free(s); + s->ps.sps = NULL; + s->ps.vps = NULL; + + if (!sps) + return 0; + + ret = pic_arrays_init(s, sps); if (ret < 0) goto fail; - s->avctx->pix_fmt = ret; + + export_stream_params(s->avctx, &s->ps, sps); + + s->avctx->pix_fmt = pix_fmt; ff_hevc_pred_init(&s->hpc, sps->bit_depth); ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); @@ -475,10 +479,17 @@ static int hls_slice_header(HEVCContext *s) s->ps.pps = (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data; if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) { + enum AVPixelFormat pix_fmt; + s->ps.sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data; ff_hevc_clear_refs(s); - ret = set_sps(s, s->ps.sps); + + pix_fmt = get_format(s, s->ps.sps); + if (pix_fmt < 0) + return pix_fmt; + + ret = set_sps(s, s->ps.sps, pix_fmt); if (ret < 0) return ret; @@ -2985,7 +2996,7 @@ static int hevc_update_thread_context(AVCodecContext *dst, } if (s->ps.sps != s0->ps.sps) - ret = set_sps(s, s0->ps.sps); + ret = set_sps(s, s0->ps.sps, src->pix_fmt); s->seq_decode = s0->seq_decode; s->seq_output = s0->seq_output; |