History

lavc/ffv1enc: move bit writer to per-slice context

Anton Khirnov committed 2 years ago

Commit d2f50721 parent 889faed3 files · +13 −11Browse files

Unified · Split

3 files
  1. libavcodec/ffv1.h +2 −1
  2. libavcodec/ffv1enc.c +4 −3
  3. libavcodec/ffv1enc_template.c +7 −7
libavcodec/ffv1.h+2−1
@@ -79,13 +79,14 @@ typedef struct FFV1SliceContext { · 78 unmodified lines
7979 int slice_y;
8080
8181 int run_index;
82+
83+ PutBitContext pb;
8284 } FFV1SliceContext;
8385
8486 typedef struct FFV1Context {
8587 AVClass *class;
8688 AVCodecContext *avctx;
8789 RangeCoder c;
88− PutBitContext pb;
8990 uint64_t rc_stat[256][2];
9091 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
9192 int version;
libavcodec/ffv1enc.c+4−3
@@ -1057,7 +1057,7 @@ retry: · 1056 unmodified lines
10571057 }
10581058 if (fs->ac == AC_GOLOMB_RICE) {
10591059 fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0;
1060− init_put_bits(&fs->pb,
1060+ init_put_bits(&sc->pb,
10611061 fs->c.bytestream_start + fs->ac_byte_count,
10621062 fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count);
10631063 }
@@ -1209,13 +1209,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 145 unmodified lines
12091209 buf_p = pkt->data;
12101210 for (i = 0; i < f->slice_count; i++) {
12111211 FFV1Context *fs = f->slice_context[i];
1212+ FFV1SliceContext *sc = &f->slices[i];
12121213 int bytes;
12131214
12141215 if (fs->ac != AC_GOLOMB_RICE) {
12151216 bytes = ff_rac_terminate(&fs->c, 1);
12161217 } else {
1217− flush_put_bits(&fs->pb); // FIXME: nicer padding
1218− bytes = fs->ac_byte_count + put_bytes_output(&fs->pb);
1218+ flush_put_bits(&sc->pb); // FIXME: nicer padding
1219+ bytes = fs->ac_byte_count + put_bytes_output(&sc->pb);
12191220 }
12201221 if (i > 0 || f->version > 2) {
12211222 av_assert0(bytes < pkt->size / f->slice_count);
libavcodec/ffv1enc_template.c+7−7
@@ -39,7 +39,7 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 38 unmodified lines
3939 return AVERROR_INVALIDDATA;
4040 }
4141 } else {
42− if (put_bytes_left(&s->pb, 0) < w * 4) {
42+ if (put_bytes_left(&sc->pb, 0) < w * 4) {
4343 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
4444 return AVERROR_INVALIDDATA;
4545 }
@@ -86,10 +86,10 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 40 unmodified lines
8686 while (run_count >= 1 << ff_log2_run[run_index]) {
8787 run_count -= 1 << ff_log2_run[run_index];
8888 run_index++;
89− put_bits(&s->pb, 1, 1);
89+ put_bits(&sc->pb, 1, 1);
9090 }
9191
92− put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count);
92+ put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
9393 if (run_index)
9494 run_index--;
9595 run_count = 0;
@@ -103,21 +103,21 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 7 unmodified lines
103103
104104 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
105105 run_count, run_index, run_mode, x,
106− (int)put_bits_count(&s->pb));
106+ (int)put_bits_count(&sc->pb));
107107
108108 if (run_mode == 0)
109− put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);
109+ put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
110110 }
111111 }
112112 if (run_mode) {
113113 while (run_count >= 1 << ff_log2_run[run_index]) {
114114 run_count -= 1 << ff_log2_run[run_index];
115115 run_index++;
116− put_bits(&s->pb, 1, 1);
116+ put_bits(&sc->pb, 1, 1);
117117 }
118118
119119 if (run_count)
120− put_bits(&s->pb, 1, 1);
120+ put_bits(&sc->pb, 1, 1);
121121 }
122122 sc->run_index = run_index;
123123

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t