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
79 int slice_y;79 int slice_y;
80 80
81 int run_index;81 int run_index;
82
83 PutBitContext pb;
82} FFV1SliceContext;84} FFV1SliceContext;
83 85
84typedef struct FFV1Context {86typedef struct FFV1Context {
85 AVClass *class;87 AVClass *class;
86 AVCodecContext *avctx;88 AVCodecContext *avctx;
87 RangeCoder c;89 RangeCoder c;
88 PutBitContext pb;
89 uint64_t rc_stat[256][2];90 uint64_t rc_stat[256][2];
90 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];91 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
91 int version;92 int version;
libavcodec/ffv1enc.c+4−3
@@ -1057,7 +1057,7 @@ retry: · 1056 unmodified lines
1057 }1057 }
1058 if (fs->ac == AC_GOLOMB_RICE) {1058 if (fs->ac == AC_GOLOMB_RICE) {
1059 fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0;1059 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,
1061 fs->c.bytestream_start + fs->ac_byte_count,1061 fs->c.bytestream_start + fs->ac_byte_count,
1062 fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count);1062 fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count);
1063 }1063 }
@@ -1209,13 +1209,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 145 unmodified lines
1209 buf_p = pkt->data;1209 buf_p = pkt->data;
1210 for (i = 0; i < f->slice_count; i++) {1210 for (i = 0; i < f->slice_count; i++) {
1211 FFV1Context *fs = f->slice_context[i];1211 FFV1Context *fs = f->slice_context[i];
1212 FFV1SliceContext *sc = &f->slices[i];
1212 int bytes;1213 int bytes;
1213 1214
1214 if (fs->ac != AC_GOLOMB_RICE) {1215 if (fs->ac != AC_GOLOMB_RICE) {
1215 bytes = ff_rac_terminate(&fs->c, 1);1216 bytes = ff_rac_terminate(&fs->c, 1);
1216 } else {1217 } else {
1217 flush_put_bits(&fs->pb); // FIXME: nicer padding1218 flush_put_bits(&sc->pb); // FIXME: nicer padding
1218 bytes = fs->ac_byte_count + put_bytes_output(&fs->pb);1219 bytes = fs->ac_byte_count + put_bytes_output(&sc->pb);
1219 }1220 }
1220 if (i > 0 || f->version > 2) {1221 if (i > 0 || f->version > 2) {
1221 av_assert0(bytes < pkt->size / f->slice_count);1222 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
39 return AVERROR_INVALIDDATA;39 return AVERROR_INVALIDDATA;
40 }40 }
41 } else {41 } else {
42 if (put_bytes_left(&s->pb, 0) < w * 4) {42 if (put_bytes_left(&sc->pb, 0) < w * 4) {
43 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");43 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
44 return AVERROR_INVALIDDATA;44 return AVERROR_INVALIDDATA;
45 }45 }
@@ -86,10 +86,10 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 40 unmodified lines
86 while (run_count >= 1 << ff_log2_run[run_index]) {86 while (run_count >= 1 << ff_log2_run[run_index]) {
87 run_count -= 1 << ff_log2_run[run_index];87 run_count -= 1 << ff_log2_run[run_index];
88 run_index++;88 run_index++;
89 put_bits(&s->pb, 1, 1);89 put_bits(&sc->pb, 1, 1);
90 }90 }
91 91
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);
93 if (run_index)93 if (run_index)
94 run_index--;94 run_index--;
95 run_count = 0;95 run_count = 0;
@@ -103,21 +103,21 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 7 unmodified lines
103 103
104 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",104 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
105 run_count, run_index, run_mode, x,105 run_count, run_index, run_mode, x,
106 (int)put_bits_count(&s->pb));106 (int)put_bits_count(&sc->pb));
107 107
108 if (run_mode == 0)108 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);
110 }110 }
111 }111 }
112 if (run_mode) {112 if (run_mode) {
113 while (run_count >= 1 << ff_log2_run[run_index]) {113 while (run_count >= 1 << ff_log2_run[run_index]) {
114 run_count -= 1 << ff_log2_run[run_index];114 run_count -= 1 << ff_log2_run[run_index];
115 run_index++;115 run_index++;
116 put_bits(&s->pb, 1, 1);116 put_bits(&sc->pb, 1, 1);
117 }117 }
118 118
119 if (run_count)119 if (run_count)
120 put_bits(&s->pb, 1, 1);120 put_bits(&sc->pb, 1, 1);
121 }121 }
122 sc->run_index = run_index;122 sc->run_index = run_index;
123 123

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