From 5dedb2afd64e27ad08308487e185f7e3a5bea1b9 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 14 Apr 2017 16:09:07 +0200 Subject: [PATCH] avcodec/dnxhd*: add ff_dnxhd_get_hr_frame_size() Signed-off-by: Paul B Mahol --- libavcodec/dnxhd_parser.c | 15 +-------------- libavcodec/dnxhddata.h | 13 +++++++++++++ libavcodec/dnxhdenc.c | 11 ++--------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/libavcodec/dnxhd_parser.c b/libavcodec/dnxhd_parser.c index d5844dffda..de1cf5a041 100644 --- a/libavcodec/dnxhd_parser.c +++ b/libavcodec/dnxhd_parser.c @@ -36,19 +36,6 @@ typedef struct { int w, h; } DNXHDParserContext; -static int dnxhd_get_hr_frame_size(int cid, int w, int h) -{ - int result, i = ff_dnxhd_get_cid_table(cid); - - if (i < 0) - return i; - - result = ((h + 15) / 16) * ((w + 15) / 16) * (int64_t)ff_dnxhd_cid_table[i].packet_scale.num / ff_dnxhd_cid_table[i].packet_scale.den; - result = (result + 2048) / 4096 * 4096; - - return FFMAX(result, 8192); -} - static int dnxhd_find_frame_end(DNXHDParserContext *dctx, const uint8_t *buf, int buf_size) { @@ -93,7 +80,7 @@ static int dnxhd_find_frame_end(DNXHDParserContext *dctx, dctx->remaining = avpriv_dnxhd_get_frame_size(cid); if (dctx->remaining <= 0) { - dctx->remaining = dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h); + dctx->remaining = ff_dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h); if (dctx->remaining <= 0) return dctx->remaining; } diff --git a/libavcodec/dnxhddata.h b/libavcodec/dnxhddata.h index 89262a13c1..c96c5e8f65 100644 --- a/libavcodec/dnxhddata.h +++ b/libavcodec/dnxhddata.h @@ -91,6 +91,19 @@ static av_always_inline uint64_t ff_dnxhd_parse_header_prefix(const uint8_t *buf return ff_dnxhd_check_header_prefix(prefix); } +static av_always_inline int ff_dnxhd_get_hr_frame_size(int cid, int w, int h) +{ + int result, i = ff_dnxhd_get_cid_table(cid); + + if (i < 0) + return i; + + result = ((h + 15) / 16) * ((w + 15) / 16) * (int64_t)ff_dnxhd_cid_table[i].packet_scale.num / ff_dnxhd_cid_table[i].packet_scale.den; + result = (result + 2048) / 4096 * 4096; + + return FFMAX(result, 8192); +} + int avpriv_dnxhd_get_frame_size(int cid); int avpriv_dnxhd_get_interlaced(int cid); #if LIBAVCODEC_VERSION_MAJOR < 58 diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index 35fa77794a..1c270a4ad7 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -362,13 +362,6 @@ fail: return AVERROR(ENOMEM); } -static int dnxhd_get_hr_frame_size(const CIDEntry* profile, int mb_num) -{ - int result = mb_num * profile->packet_scale.num / profile->packet_scale.den; - result = (result + 2048) / 4096 * 4096; - return FFMAX(result, 8192); -} - static av_cold int dnxhd_encode_init(AVCodecContext *avctx) { DNXHDEncContext *ctx = avctx->priv_data; @@ -483,8 +476,8 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx) ctx->m.mb_num = ctx->m.mb_height * ctx->m.mb_width; if (ctx->cid_table->frame_size == DNXHD_VARIABLE) { - ctx->frame_size = dnxhd_get_hr_frame_size(ctx->cid_table, - ctx->m.mb_num); + ctx->frame_size = ff_dnxhd_get_hr_frame_size(ctx->cid, + ctx->m.mb_width, ctx->m.mb_height); ctx->coding_unit_size = ctx->frame_size; } else { ctx->frame_size = ctx->cid_table->frame_size; -- 2.11.0