From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 3/5] avcodec/cfhddata: Avoid code duplication when creating codebooks Date: Sat, 3 Sep 2022 22:35:57 +0200 Message-ID: <AS8P250MB0744F1E0C3DA5DB1EAF58F7B8F7D9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <AS8P250MB07443029028BA4485D8478F18F7D9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/cfhddata.c | 94 ++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 55 deletions(-) diff --git a/libavcodec/cfhddata.c b/libavcodec/cfhddata.c index 7c4b1454f3..017eb9375c 100644 --- a/libavcodec/cfhddata.c +++ b/libavcodec/cfhddata.c @@ -124,38 +124,42 @@ static const CFHD_RL_ELEM table_18_vlc[NB_VLC_TABLE_18] = { { 1, 29, 12 }, { 1, 18, 10 }, { 1, 8, 7 }, { 1, 2, 3 }, }; -av_cold int ff_cfhd_init_vlcs(CFHDContext *s) +static av_cold int cfhd_init_vlc(CFHD_RL_VLC_ELEM out[], unsigned out_size, + const CFHD_RL_ELEM table_vlc[], unsigned table_size, + VLC *vlc, void *logctx) { - int i, j, ret = 0; uint8_t new_cfhd_vlc_len[NB_VLC_TABLE_18 * 2]; uint16_t new_cfhd_vlc_run[NB_VLC_TABLE_18 * 2]; int16_t new_cfhd_vlc_level[NB_VLC_TABLE_18 * 2]; + unsigned j; + int ret; /** Similar to dv.c, generate signed VLC tables **/ - /* Table 9 */ - for (i = 0, j = 0; i < NB_VLC_TABLE_9; i++, j++) { - new_cfhd_vlc_len[j] = table_9_vlc[i].len; - new_cfhd_vlc_run[j] = table_9_vlc[i].run; - new_cfhd_vlc_level[j] = table_9_vlc[i].level; + for (unsigned i = j = 0; i < table_size; i++, j++) { + new_cfhd_vlc_len[j] = table_vlc[i].len; + new_cfhd_vlc_run[j] = table_vlc[i].run; + new_cfhd_vlc_level[j] = table_vlc[i].level; /* Don't include the zero level nor escape bits */ - if (table_9_vlc[i].level && table_9_vlc[i].run) { + if (table_vlc[i].level && table_vlc[i].run) { new_cfhd_vlc_len[j]++; j++; - new_cfhd_vlc_len[j] = table_9_vlc[i].len + 1; - new_cfhd_vlc_run[j] = table_9_vlc[i].run; - new_cfhd_vlc_level[j] = -table_9_vlc[i].level; + new_cfhd_vlc_len[j] = table_vlc[i].len + 1; + new_cfhd_vlc_run[j] = table_vlc[i].run; + new_cfhd_vlc_level[j] = -table_vlc[i].level; } } - ret = ff_init_vlc_from_lengths(&s->vlc_9, VLC_BITS, j, new_cfhd_vlc_len, - 1, NULL, 0, 0, 0, 0, s->avctx); + ret = ff_init_vlc_from_lengths(vlc, VLC_BITS, j, new_cfhd_vlc_len, + 1, NULL, 0, 0, 0, 0, logctx); if (ret < 0) return ret; - for (i = 0; i < s->vlc_9.table_size; i++) { - int code = s->vlc_9.table[i].sym; - int len = s->vlc_9.table[i].len; + av_assert0(vlc->table_size == out_size); + + for (unsigned i = 0; i < out_size; i++) { + int code = vlc->table[i].sym; + int len = vlc->table[i].len; int level, run; if (len < 0) { // more bits needed @@ -165,49 +169,29 @@ av_cold int ff_cfhd_init_vlcs(CFHDContext *s) run = new_cfhd_vlc_run[code]; level = new_cfhd_vlc_level[code]; } - s->table_9_rl_vlc[i].len = len; - s->table_9_rl_vlc[i].level = level; - s->table_9_rl_vlc[i].run = run; + out[i].len = len; + out[i].level = level; + out[i].run = run; } - /* Table 18 */ - for (i = 0, j = 0; i < NB_VLC_TABLE_18; i++, j++) { - new_cfhd_vlc_len[j] = table_18_vlc[i].len; - new_cfhd_vlc_run[j] = table_18_vlc[i].run; - new_cfhd_vlc_level[j] = table_18_vlc[i].level; + return 0; +} - /* Don't include the zero level nor escape bits */ - if (table_18_vlc[i].level && table_18_vlc[i].run) { - new_cfhd_vlc_len[j]++; - j++; - new_cfhd_vlc_len[j] = table_18_vlc[i].len + 1; - new_cfhd_vlc_run[j] = table_18_vlc[i].run; - new_cfhd_vlc_level[j] = -table_18_vlc[i].level; - } - } +av_cold int ff_cfhd_init_vlcs(CFHDContext *s) +{ + int ret; - ret = ff_init_vlc_from_lengths(&s->vlc_18, VLC_BITS, j, new_cfhd_vlc_len, - 1, NULL, 0, 0, 0, 0, s->avctx); + /* Table 9 */ + ret = cfhd_init_vlc(s->table_9_rl_vlc, FF_ARRAY_ELEMS(s->table_9_rl_vlc), + table_9_vlc, FF_ARRAY_ELEMS(table_9_vlc), + &s->vlc_9, s->avctx); if (ret < 0) return ret; - av_assert0(s->vlc_18.table_size == 4572); - - for (i = 0; i < s->vlc_18.table_size; i++) { - int code = s->vlc_18.table[i].sym; - int len = s->vlc_18.table[i].len; - int level, run; - - if (len < 0) { // more bits needed - run = 0; - level = code; - } else { - run = new_cfhd_vlc_run[code]; - level = new_cfhd_vlc_level[code]; - } - s->table_18_rl_vlc[i].len = len; - s->table_18_rl_vlc[i].level = level; - s->table_18_rl_vlc[i].run = run; - } - - return ret; + /* Table 18 */ + ret = cfhd_init_vlc(s->table_18_rl_vlc, FF_ARRAY_ELEMS(s->table_18_rl_vlc), + table_18_vlc, FF_ARRAY_ELEMS(table_18_vlc), + &s->vlc_18, s->avctx); + if (ret < 0) + return ret; + return 0; } -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-09-03 20:36 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-03 20:30 [FFmpeg-devel] [PATCH 1/5] avcodec/cfhd, cfhddata: Simplify check for escape Andreas Rheinhardt 2022-09-03 20:35 ` [FFmpeg-devel] [PATCH 2/5] avcodec/cfhddata: Avoid code tables Andreas Rheinhardt 2022-09-03 20:35 ` Andreas Rheinhardt [this message] 2022-09-03 20:35 ` [FFmpeg-devel] [PATCH 4/5] avcodec/cfhd, cfhddata: Free VLC as soon as it is not needed Andreas Rheinhardt 2022-09-03 20:35 ` [FFmpeg-devel] [PATCH 5/5] avcodec/cfhddata: Reduce stack usage Andreas Rheinhardt 2022-09-03 21:49 ` Paul B Mahol 2022-09-03 21:56 ` Andreas Rheinhardt 2022-09-05 10:25 ` Paul B Mahol
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS8P250MB0744F1E0C3DA5DB1EAF58F7B8F7D9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git