diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2015-07-13 00:48:48 +0200 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2015-07-13 21:59:53 +0200 |
commit | 8e373fe048812a25b238ea60a7052b8c07639a42 (patch) | |
tree | 35d55df71b4aa7f3f7dde96ace5e86b3afd9208d /libavcodec | |
parent | c571424c7f6276a6374e1784ce2a33d4b6a4292d (diff) | |
download | ffmpeg-8e373fe048812a25b238ea60a7052b8c07639a42.tar.gz |
hevc: Factor out the pixel format mapping from the sps parser
The function will grow larger as more formats are supported.
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/hevc_ps.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index a1eaf6ea11..13fb31c957 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -642,10 +642,41 @@ static int scaling_list_data(GetBitContext *gb, AVCodecContext *avctx, ScalingLi return 0; } +static int map_pixel_format(AVCodecContext *avctx, HEVCSPS *sps) +{ + const AVPixFmtDescriptor *desc; + if (sps->chroma_format_idc == 1) { + switch (sps->bit_depth) { + case 8: sps->pix_fmt = AV_PIX_FMT_YUV420P; break; + case 9: sps->pix_fmt = AV_PIX_FMT_YUV420P9; break; + case 10: sps->pix_fmt = AV_PIX_FMT_YUV420P10; break; + default: + av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", + sps->bit_depth); + return AVERROR_PATCHWELCOME; + } + } else { + av_log(avctx, AV_LOG_ERROR, + "non-4:2:0 support is currently unspecified.\n"); + return AVERROR_PATCHWELCOME; + } + + desc = av_pix_fmt_desc_get(sps->pix_fmt); + if (!desc) + return AVERROR(EINVAL); + + sps->hshift[0] = sps->vshift[0] = 0; + sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w; + sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h; + + sps->pixel_shift = sps->bit_depth > 8; + + return 0; +} + int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx) { - const AVPixFmtDescriptor *desc; int ret = 0; int log2_diff_max_min_transform_block_size; int bit_depth_chroma, start, vui_present, sublayer_ordering_info; @@ -737,34 +768,10 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, goto err; } - if (sps->chroma_format_idc == 1) { - switch (sps->bit_depth) { - case 8: sps->pix_fmt = AV_PIX_FMT_YUV420P; break; - case 9: sps->pix_fmt = AV_PIX_FMT_YUV420P9; break; - case 10: sps->pix_fmt = AV_PIX_FMT_YUV420P10; break; - default: - av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", - sps->bit_depth); - ret = AVERROR_PATCHWELCOME; - goto err; - } - } else { - av_log(avctx, AV_LOG_ERROR, - "non-4:2:0 support is currently unspecified.\n"); - return AVERROR_PATCHWELCOME; - } - desc = av_pix_fmt_desc_get(sps->pix_fmt); - if (!desc) { - ret = AVERROR(EINVAL); + ret = map_pixel_format(avctx, sps); + if (ret < 0) goto err; - } - - sps->hshift[0] = sps->vshift[0] = 0; - sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w; - sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h; - - sps->pixel_shift = sps->bit_depth > 8; sps->log2_max_poc_lsb = get_ue_golomb_long(gb) + 4; if (sps->log2_max_poc_lsb > 16) { |