History

avcodec/cbs_vp8: Add support for VP8 codec bitstream

This commit adds support for VP8 bitstream read methods to the cbs codec. This enables the trace_headers bitstream filter to support VP8, in addition to AV1, H.264, H.265, and VP9. This can be useful for debugging VP8 stream issues. The CBS VP8 implements a simple VP8 boolean decoder using GetBitContext to read the bitstream. Only the read methods `read_unit` and `split_fragment` are implemented. The write methods `write_unit` and `assemble_fragment` return the error code AVERROR_PATCHWELCOME. This is because CBS VP8 write is unlikely to be used by any applications at the moment. The write methods can be added later if there is a real need for them. TESTS: ffmpeg -i fate-suite/vp8/frame_size_change.webm -vcodec copy -bsf:v trace_headers -f null -

Dai, Jianhui J committed 3 years ago

Commit c9fe9fb1 parent 5cb8acc7 files · +772 −1Browse files

Showing the changes to libavcodec (6 of 7 files). Show all

Unified · Split

6 files
  1. libavcodec/Makefile +1 −0
  2. libavcodec/cbs.c +6 −0
  3. libavcodec/cbs_internal.h +1 −0
  4. libavcodec/cbs_vp8.c +380 −0
  5. libavcodec/cbs_vp8.h +133 −0
  6. libavcodec/cbs_vp8_syntax_template.c +248 −0
libavcodec/Makefile+1−0
@@ -81,6 +81,7 @@ OBJS-$(CONFIG_CBS_H265) += cbs_h2645.o cbs_sei.o h2645_parse.o · 80 unmodified lines
81OBJS-$(CONFIG_CBS_H266) += cbs_h2645.o cbs_sei.o h2645_parse.o81OBJS-$(CONFIG_CBS_H266) += cbs_h2645.o cbs_sei.o h2645_parse.o
82OBJS-$(CONFIG_CBS_JPEG) += cbs_jpeg.o82OBJS-$(CONFIG_CBS_JPEG) += cbs_jpeg.o
83OBJS-$(CONFIG_CBS_MPEG2) += cbs_mpeg2.o83OBJS-$(CONFIG_CBS_MPEG2) += cbs_mpeg2.o
84OBJS-$(CONFIG_CBS_VP8) += cbs_vp8.o vp8data.o
84OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o85OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
85OBJS-$(CONFIG_CRYSTALHD) += crystalhd.o86OBJS-$(CONFIG_CRYSTALHD) += crystalhd.o
86OBJS-$(CONFIG_DEFLATE_WRAPPER) += zlib_wrapper.o87OBJS-$(CONFIG_DEFLATE_WRAPPER) += zlib_wrapper.o
libavcodec/cbs.c+6−0
@@ -50,6 +50,9 @@ static const CodedBitstreamType *const cbs_type_table[] = { · 49 unmodified lines
50#if CONFIG_CBS_MPEG250#if CONFIG_CBS_MPEG2
51 &ff_cbs_type_mpeg2,51 &ff_cbs_type_mpeg2,
52#endif52#endif
53#if CONFIG_CBS_VP8
54 &ff_cbs_type_vp8,
55#endif
53#if CONFIG_CBS_VP956#if CONFIG_CBS_VP9
54 &ff_cbs_type_vp9,57 &ff_cbs_type_vp9,
55#endif58#endif
@@ -74,6 +77,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = { · 18 unmodified lines
74#if CONFIG_CBS_MPEG277#if CONFIG_CBS_MPEG2
75 AV_CODEC_ID_MPEG2VIDEO,78 AV_CODEC_ID_MPEG2VIDEO,
76#endif79#endif
80#if CONFIG_CBS_VP8
81 AV_CODEC_ID_VP8,
82#endif
77#if CONFIG_CBS_VP983#if CONFIG_CBS_VP9
78 AV_CODEC_ID_VP9,84 AV_CODEC_ID_VP9,
79#endif85#endif
libavcodec/cbs_internal.h+1−0
@@ -341,6 +341,7 @@ extern const CodedBitstreamType ff_cbs_type_h265; · 340 unmodified lines
341extern const CodedBitstreamType ff_cbs_type_h266;341extern const CodedBitstreamType ff_cbs_type_h266;
342extern const CodedBitstreamType ff_cbs_type_jpeg;342extern const CodedBitstreamType ff_cbs_type_jpeg;
343extern const CodedBitstreamType ff_cbs_type_mpeg2;343extern const CodedBitstreamType ff_cbs_type_mpeg2;
344extern const CodedBitstreamType ff_cbs_type_vp8;
344extern const CodedBitstreamType ff_cbs_type_vp9;345extern const CodedBitstreamType ff_cbs_type_vp9;
345 346
346 347
libavcodec/cbs_vp8.c+380−0
@@ -0,0 +1,380 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "libavutil/avassert.h"
20
21#include "cbs.h"
22#include "cbs_internal.h"
23#include "cbs_vp8.h"
24
25#include <stdbool.h>
26
27#define DEFAULT_PROB 0x80
28
29// The probability table is defined in 'vp8data.c'.
30extern const uint8_t ff_vp8_token_update_probs[4][8][3][11];
31
32// Implements VP8 boolean decoder using GetBitContext to read the bitstream.
33typedef struct CBSVP8BoolDecoder {
34 GetBitContext *gbc;
35
36 uint8_t value;
37 uint8_t range;
38
39 uint8_t count; // Store the number of bits in the `value` buffer.
40
41} CBSVP8BoolDecoder;
42
43static int cbs_vp8_bool_decoder_init(CBSVP8BoolDecoder *decoder, GetBitContext *gbc)
44{
45 av_assert0(decoder);
46 av_assert0(gbc);
47
48 decoder->gbc = gbc;
49 decoder->value = 0;
50 decoder->range = 255;
51
52 decoder->count = 0;
53
54 return 0;
55}
56
57static bool cbs_vp8_bool_decoder_fill_value(CBSVP8BoolDecoder *decoder)
58{
59 int bits = 8 - decoder->count;
60
61 av_assert0(decoder->count <= 8);
62 if (decoder->count == 8) {
63 return true;
64 }
65
66 if (get_bits_left(decoder->gbc) >= bits) {
67 decoder->value |= get_bits(decoder->gbc, bits);
68 decoder->count += bits;
69 }
70
71 return (decoder->count == 8);
72}
73
74static int cbs_vp8_bool_decoder_read_bool(CBSVP8BoolDecoder *decoder,
75 const uint8_t prob, uint8_t *output)
76{
77 uint8_t split = 1 + (((decoder->range - 1) * prob) >> 8);
78
79 if (!cbs_vp8_bool_decoder_fill_value(decoder)) {
80 return AVERROR_INVALIDDATA;
81 }
82
83 av_assert0(decoder->count == 8);
84 if (decoder->value >= split) {
85 *output = 1;
86 decoder->range -= split;
87 decoder->value -= split;
88 } else {
89 *output = 0;
90 decoder->range = split;
91 }
92
93 while (decoder->range < 128) {
94 decoder->value <<= 1;
95 decoder->range <<= 1;
96 --decoder->count;
97 }
98
99 return 0;
100}
101
102static int cbs_vp8_bool_decoder_read_literal(CBSVP8BoolDecoder *decoder,
103 const uint8_t prob,
104 uint32_t num_bits,
105 uint32_t *output)
106{
107 int ret = 0;
108
109 av_assert0(num_bits <= 32);
110
111 *output = 0;
112 for (; num_bits > 0; --num_bits) {
113 uint8_t bit_output = 0;
114 if ((ret = cbs_vp8_bool_decoder_read_bool(decoder, prob,
115 &bit_output)) != 0) {
116 return ret;
117 }
118
119 *output = (*output << 1) | bit_output;
120 }
121
122 return 0;
123}
124
125static int cbs_vp8_bool_decoder_read_unsigned(
126 CodedBitstreamContext *ctx, CBSVP8BoolDecoder *bool_decoder, int width,
127 uint8_t prob, const char *name, const int *subscripts, uint32_t *write_to,
128 bool trace_enable)
129{
130 int ret = 0;
131 GetBitContext *gbc = bool_decoder->gbc;
132 uint32_t value;
133
134 CBS_TRACE_READ_START();
135
136 av_assert0(width >= 0 && width <= 8);
137
138 ret = cbs_vp8_bool_decoder_read_literal(bool_decoder, prob, width, &value);
139 if (ret != 0) {
140 return ret;
141 }
142
143 if (trace_enable) {
144 CBS_TRACE_READ_END();
145 }
146
147 *write_to = value;
148 return 0;
149}
150
151static int cbs_vp8_bool_decoder_read_signed(
152 CodedBitstreamContext *ctx, CBSVP8BoolDecoder *bool_decoder, int width,
153 uint8_t prob, const char *name, const int *subscripts, int32_t *write_to)
154{
155 int ret = 0;
156 GetBitContext *gbc = bool_decoder->gbc;
157 int32_t value;
158 uint8_t sign = 0;
159
160 CBS_TRACE_READ_START();
161
162 av_assert0(width >= 0 && width <= 8);
163
164 ret = cbs_vp8_bool_decoder_read_literal(bool_decoder, prob, width, &value);
165 if (ret != 0) {
166 return ret;
167 }
168
169 ret = cbs_vp8_bool_decoder_read_bool(bool_decoder, prob, &sign);
170 if (ret != 0) {
171 return ret;
172 }
173
174 if (sign) {
175 value = -value;
176 }
177
178 CBS_TRACE_READ_END();
179
180 *write_to = value;
181 return 0;
182}
183
184static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, GetBitContext *gbc,
185 int width, const char *name,
186 const int *subscripts, uint32_t *write_to)
187{
188 int32_t value;
189
190 CBS_TRACE_READ_START();
191
192 av_assert0(width > 0 && width <= 24);
193
194 if (get_bits_left(gbc) < width) {
195 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value: bitstream ended.\n");
196 return AVERROR_INVALIDDATA;
197 }
198
199 value = get_bits_le(gbc, width);
200
201 CBS_TRACE_READ_END();
202
203 *write_to = value;
204 return 0;
205}
206
207#define HEADER(name) \
208 do { \
209 ff_cbs_trace_header(ctx, name); \
210 } while (0)
211
212#define CHECK(call) \
213 do { \
214 int err = (call); \
215 if (err < 0) \
216 return err; \
217 } while (0)
218
219#define FUNC_NAME(rw, codec, name) cbs_##codec##_##rw##_##name
220#define FUNC_VP8(rw, name) FUNC_NAME(rw, vp8, name)
221#define FUNC(name) FUNC_VP8(READWRITE, name)
222
223#define SUBSCRIPTS(subs, ...) \
224 (subs > 0 ? ((int[subs + 1]){subs, __VA_ARGS__}) : NULL)
225
226#define f(width, name) xf(width, name, 0)
227
228// bool [de|en]coder methods.
229#define bc_f(width, name) bc_unsigned_subs(width, DEFAULT_PROB, true, name, 0)
230#define bc_s(width, name) bc_signed_subs(width, DEFAULT_PROB, name, 0)
231#define bc_fs(width, name, subs, ...) \
232 bc_unsigned_subs(width, DEFAULT_PROB, true, name, subs, __VA_ARGS__)
233#define bc_ss(width, name, subs, ...) \
234 bc_signed_subs(width, DEFAULT_PROB, name, subs, __VA_ARGS__)
235
236// bool [de|en]coder methods for boolean value and disable tracing.
237#define bc_b(name) bc_unsigned_subs(1, DEFAULT_PROB, false, name, 0)
238#define bc_b_prob(prob, name) bc_unsigned_subs(1, prob, false, name, 0)
239
240#define READ
241#define READWRITE read
242#define RWContext GetBitContext
243#define CBSVP8BoolCodingRW CBSVP8BoolDecoder
244
245#define xf(width, name, subs, ...) \
246 do { \
247 uint32_t value; \
248 CHECK(cbs_vp8_read_unsigned_le(ctx, rw, width, #name, \
249 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
250 current->name = value; \
251 } while (0)
252
253#define fixed(width, name, value) \
254 do { \
255 uint32_t fixed_value; \
256 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, 0, &fixed_value, \
257 value, value)); \
258 } while (0)
259
260#define bc_unsigned_subs(width, prob, enable_trace, name, subs, ...) \
261 do { \
262 uint32_t value; \
263 CHECK(cbs_vp8_bool_decoder_read_unsigned( \
264 ctx, bool_coding_rw, width, prob, #name, \
265 SUBSCRIPTS(subs, __VA_ARGS__), &value, enable_trace)); \
266 current->name = value; \
267 } while (0)
268
269#define bc_signed_subs(width, prob, name, subs, ...) \
270 do { \
271 int32_t value; \
272 CHECK(cbs_vp8_bool_decoder_read_signed( \
273 ctx, bool_coding_rw, width, prob, #name, \
274 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
275 current->name = value; \
276 } while (0)
277
278#include "cbs_vp8_syntax_template.c"
279
280static int cbs_vp8_split_fragment(CodedBitstreamContext *ctx,
281 CodedBitstreamFragment *frag, int header)
282{
283 int err;
284
285 if (frag->data_size == 0)
286 return AVERROR_INVALIDDATA;
287
288 err = ff_cbs_append_unit_data(frag, 0, frag->data, frag->data_size,
289 frag->data_ref);
290 if (err < 0)
291 return err;
292
293 return 0;
294}
295
296static int cbs_vp8_read_unit(CodedBitstreamContext *ctx,
297 CodedBitstreamUnit *unit)
298{
299 VP8RawFrame *frame;
300 GetBitContext gbc;
301 CBSVP8BoolDecoder bool_decoder;
302 int err, pos;
303
304 err = ff_cbs_alloc_unit_content(ctx, unit);
305 if (err < 0)
306 return err;
307 frame = unit->content;
308
309 // Create GetBitContext for uncompressed header.
310 err = init_get_bits8_le(&gbc, unit->data, 8 * unit->data_size);
311 if (err < 0)
312 return err;
313
314 err = cbs_vp8_read_uncompressed_header(ctx, &gbc, frame);
315 if (err < 0)
316 return err;
317
318 pos = get_bits_count(&gbc);
319 av_assert0(pos % 8 == 0);
320
321 // Create boolean decoder for compressed header.
322 err = cbs_vp8_bool_decoder_init(&bool_decoder, &gbc);
323 if (err < 0)
324 return err;
325
326 err = cbs_vp8_read_compressed_header(ctx, &bool_decoder, frame);
327 if (err < 0)
328 return err;
329
330 pos = get_bits_count(&gbc);
331 pos /= 8;
332 av_assert0(pos <= unit->data_size);
333
334 frame->data_ref = av_buffer_ref(unit->data_ref);
335 if (!frame->data_ref)
336 return AVERROR(ENOMEM);
337
338 frame->data = unit->data + pos;
339 frame->data_size = unit->data_size - pos;
340
341 return 0;
342}
343
344static int cbs_vp8_write_unit(CodedBitstreamContext *ctx,
345 CodedBitstreamUnit *unit, PutBitContext *pbc)
346{
347 return AVERROR_PATCHWELCOME;
348}
349
350static int cbs_vp8_assemble_fragment(CodedBitstreamContext *ctx,
351 CodedBitstreamFragment *frag)
352{
353 return AVERROR_PATCHWELCOME;
354}
355
356static void cbs_vp8_flush(CodedBitstreamContext *ctx)
357{
358 // Do nothing.
359}
360
361static const CodedBitstreamUnitTypeDescriptor cbs_vp8_unit_types[] = {
362 CBS_UNIT_TYPE_INTERNAL_REF(0, VP8RawFrame, data),
363 CBS_UNIT_TYPE_END_OF_LIST,
364};
365
366const CodedBitstreamType ff_cbs_type_vp8 = {
367 .codec_id = AV_CODEC_ID_VP8,
368
369 .priv_data_size = 0,
370
371 .unit_types = cbs_vp8_unit_types,
372
373 .split_fragment = &cbs_vp8_split_fragment,
374 .read_unit = &cbs_vp8_read_unit,
375 .write_unit = &cbs_vp8_write_unit,
376
377 .flush = &cbs_vp8_flush,
378
379 .assemble_fragment = &cbs_vp8_assemble_fragment,
380};
libavcodec/cbs_vp8.h+133−0
@@ -0,0 +1,133 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVCODEC_CBS_VP8_H
20#define AVCODEC_CBS_VP8_H
21
22#include <stddef.h>
23#include <stdint.h>
24
25#include "cbs.h"
26
27enum {
28 VP8_START_CODE_0 = 0x9D,
29 VP8_START_CODE_1 = 0x01,
30 VP8_START_CODE_2 = 0x2A,
31};
32
33enum {
34 VP8_KEY_FRAME = 0,
35 VP8_NON_KEY_FRAME = 1,
36};
37
38typedef struct VP8RawFrameHeader {
39 // frame tag
40 uint8_t frame_type;
41 uint8_t profile;
42 uint8_t show_frame;
43 uint32_t first_partition_length_in_bytes;
44
45 uint16_t width;
46 uint8_t horizontal_scale;
47 uint16_t height;
48 uint8_t vertical_scale;
49
50 // frame header
51 uint8_t color_space;
52 uint8_t clamping_type;
53
54 // segmentation
55 uint8_t segmentation_enable;
56 uint8_t update_segment_map;
57 uint8_t update_segment_feature_data;
58 uint8_t segment_feature_mode;
59 uint8_t segment_qp_update[4];
60 int8_t segment_qp[4];
61 uint8_t segment_loop_filter_level_update[4];
62 int8_t segment_loop_filter_level[4];
63 uint8_t segment_probs_update[3];
64 uint8_t segment_probs[3];
65
66 // loop filter
67 uint8_t loop_filter_type;
68 uint8_t loop_filter_level;
69 uint8_t loop_filter_sharpness;
70 uint8_t mode_ref_lf_delta_enable;
71 uint8_t mode_ref_lf_delta_update;
72 uint8_t ref_lf_deltas_update[4];
73 int8_t ref_lf_deltas[4];
74 uint8_t mode_lf_deltas_update[4];
75 int8_t mode_lf_deltas[4];
76
77 uint8_t log2_token_partitions;
78
79 // qp
80 uint8_t base_qindex;
81 uint8_t y1dc_delta_q_present;
82 int8_t y1dc_delta_q;
83 uint8_t y2dc_delta_q_present;
84 int8_t y2dc_delta_q;
85 uint8_t y2ac_delta_q_present;
86 int8_t y2ac_delta_q;
87 uint8_t uvdc_delta_q_present;
88 int8_t uvdc_delta_q;
89 uint8_t uvac_delta_q_present;
90 int8_t uvac_delta_q;
91
92 // ref
93 uint8_t refresh_golden_frame;
94 uint8_t refresh_alternate_frame;
95 uint8_t copy_buffer_to_golden;
96 uint8_t copy_buffer_to_alternate;
97 uint8_t ref_frame_sign_bias_golden;
98 uint8_t ref_frame_sign_bias_alternate;
99 uint8_t refresh_last_frame;
100
101 uint8_t refresh_entropy_probs;
102
103 // token probs
104 uint8_t coeff_prob_update[4][8][3][11];
105 uint8_t coeff_prob[4][8][3][11];
106
107 uint8_t mb_no_skip_coeff;
108 uint8_t prob_skip_false;
109
110 uint8_t prob_intra;
111 uint8_t prob_last;
112 uint8_t prob_golden;
113
114 uint8_t intra_16x16_prob_update;
115 uint8_t intra_16x16_prob[4];
116
117 uint8_t intra_chrome_prob_update;
118 uint8_t intra_chrome_prob[3];
119
120 // mv probs
121 uint8_t mv_prob_update[2][19];
122 uint8_t mv_prob[2][19];
123} VP8RawFrameHeader;
124
125typedef struct VP8RawFrame {
126 VP8RawFrameHeader header;
127
128 uint8_t *data;
129 AVBufferRef *data_ref;
130 size_t data_size;
131} VP8RawFrame;
132
133#endif /* AVCODEC_CBS_VP8_H */
libavcodec/cbs_vp8_syntax_template.c+248−0
@@ -0,0 +1,248 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19static int FUNC(update_segmentation)(CodedBitstreamContext *ctx,
20 CBSVP8BoolCodingRW *bool_coding_rw,
21 VP8RawFrameHeader *current)
22{
23 bc_f(1, update_segment_map);
24 bc_f(1, update_segment_feature_data);
25
26 if (current->update_segment_feature_data) {
27 bc_f(1, segment_feature_mode);
28 // quantizer
29 for (int i = 0; i < 4; i++) {
30 bc_b(segment_qp_update[i]);
31 if (current->segment_qp_update[i])
32 bc_ss(7, segment_qp[i], 1, i);
33 }
34 // loop filter
35 for (int i = 0; i < 4; i++) {
36 bc_b(segment_loop_filter_level_update[i]);
37 if (current->segment_loop_filter_level_update[i])
38 bc_ss(6, segment_loop_filter_level[i], 1, i);
39 }
40 }
41
42 if (current->update_segment_map) {
43 for (int i = 0; i < 3; i++) {
44 bc_b(segment_probs_update[i]);
45 if (current->segment_probs_update[i])
46 bc_fs(8, segment_probs[i], 1, i);
47 }
48 }
49
50 return 0;
51}
52
53static int FUNC(mode_ref_lf_deltas)(CodedBitstreamContext *ctx,
54 CBSVP8BoolCodingRW *bool_coding_rw,
55 VP8RawFrameHeader *current)
56{
57 bc_f(1, mode_ref_lf_delta_enable);
58 if (current->mode_ref_lf_delta_enable) {
59 bc_b(mode_ref_lf_delta_update);
60 if (current->mode_ref_lf_delta_update) {
61 // ref_lf_deltas
62 for (int i = 0; i < 4; i++) {
63 bc_b(ref_lf_deltas_update[i]);
64 if (current->ref_lf_deltas_update[i])
65 bc_ss(6, ref_lf_deltas[i], 1, i);
66 }
67 // mode_lf_deltas
68 for (int i = 0; i < 4; i++) {
69 bc_b(mode_lf_deltas_update[i]);
70 if (current->mode_lf_deltas_update[i])
71 bc_ss(6, mode_lf_deltas[i], 1, i);
72 }
73 }
74 }
75
76 return 0;
77}
78
79static int FUNC(quantization_params)(CodedBitstreamContext *ctx,
80 CBSVP8BoolCodingRW *bool_coding_rw,
81 VP8RawFrameHeader *current)
82{
83 bc_f(7, base_qindex);
84
85 bc_b(y1dc_delta_q_present);
86 if (current->y1dc_delta_q_present)
87 bc_s(4, y1dc_delta_q);
88
89 bc_b(y2dc_delta_q_present);
90 if (current->y2dc_delta_q_present)
91 bc_s(4, y2dc_delta_q);
92
93 bc_b(y2ac_delta_q_present);
94 if (current->y2ac_delta_q_present)
95 bc_s(4, y2ac_delta_q);
96
97 bc_b(uvdc_delta_q_present);
98 if (current->uvdc_delta_q_present)
99 bc_s(4, uvdc_delta_q);
100
101 bc_b(uvac_delta_q_present);
102 if (current->uvac_delta_q_present)
103 bc_s(4, uvac_delta_q);
104
105 return 0;
106}
107
108static int FUNC(update_token_probs)(CodedBitstreamContext *ctx,
109 CBSVP8BoolCodingRW *bool_coding_rw,
110 VP8RawFrameHeader *current)
111{
112 for (int i = 0; i < 4; ++i) {
113 for (int j = 0; j < 8; ++j) {
114 for (int k = 0; k < 3; ++k) {
115 for (int l = 0; l < 11; ++l) {
116 bc_b_prob(ff_vp8_token_update_probs[i][j][k][l],
117 coeff_prob_update[i][j][k][l]);
118 if (current->coeff_prob_update[i][j][k][l])
119 bc_fs(8, coeff_prob[i][j][k][l], 4, i, j, k, l);
120 }
121 }
122 }
123 }
124
125 return 0;
126}
127
128static int FUNC(update_mv_probs)(CodedBitstreamContext *ctx,
129 CBSVP8BoolCodingRW *bool_coding_rw,
130 VP8RawFrameHeader *current)
131{
132 for (int i = 0; i < 2; ++i) {
133 for (int j = 0; j < 19; ++j) {
134 bc_b(mv_prob_update[i][j]);
135 if (current->mv_prob_update[i][j])
136 bc_fs(7, mv_prob[i][j], 2, i, j);
137 }
138 }
139
140 return 0;
141}
142
143static int FUNC(frame_tag)(CodedBitstreamContext *ctx, RWContext *rw,
144 VP8RawFrameHeader *current)
145{
146 f(1, frame_type);
147 f(3, profile);
148 f(1, show_frame);
149 f(19, first_partition_length_in_bytes);
150
151 if (current->frame_type == VP8_KEY_FRAME) {
152 fixed(8, start_code_0, VP8_START_CODE_0);
153 fixed(8, start_code_1, VP8_START_CODE_1);
154 fixed(8, start_code_2, VP8_START_CODE_2);
155
156 f(14, width);
157 f(2, horizontal_scale);
158 f(14, height);
159 f(2, vertical_scale);
160 }
161
162 return 0;
163}
164
165static int FUNC(frame_header)(CodedBitstreamContext *ctx,
166 CBSVP8BoolCodingRW *bool_coding_rw,
167 VP8RawFrameHeader *current)
168{
169 if (current->frame_type == VP8_KEY_FRAME) {
170 bc_f(1, color_space);
171 bc_f(1, clamping_type);
172 }
173
174 bc_f(1, segmentation_enable);
175 if (current->segmentation_enable)
176 CHECK(FUNC(update_segmentation)(ctx, bool_coding_rw, current));
177
178 bc_f(1, loop_filter_type);
179 bc_f(6, loop_filter_level);
180 bc_f(3, loop_filter_sharpness);
181
182 CHECK(FUNC(mode_ref_lf_deltas)(ctx, bool_coding_rw, current));
183
184 bc_f(2, log2_token_partitions);
185
186 CHECK(FUNC(quantization_params)(ctx, bool_coding_rw, current));
187
188 if (current->frame_type != VP8_KEY_FRAME) {
189 bc_f(1, refresh_golden_frame);
190 bc_f(1, refresh_alternate_frame);
191 if (!current->refresh_golden_frame)
192 bc_f(2, copy_buffer_to_golden);
193 if (!current->refresh_alternate_frame)
194 bc_f(2, copy_buffer_to_alternate);
195 bc_f(1, ref_frame_sign_bias_golden);
196 bc_f(1, ref_frame_sign_bias_alternate);
197 }
198 bc_f(1, refresh_entropy_probs);
199 if (current->frame_type != VP8_KEY_FRAME)
200 bc_f(1, refresh_last_frame);
201
202 CHECK(FUNC(update_token_probs)(ctx, bool_coding_rw, current));
203
204 bc_f(1, mb_no_skip_coeff);
205 if (current->mb_no_skip_coeff)
206 bc_f(8, prob_skip_false);
207
208 if (current->frame_type != VP8_KEY_FRAME) {
209 bc_f(8, prob_intra);
210 bc_f(8, prob_last);
211 bc_f(8, prob_golden);
212
213 // intra_16x16_prob
214 bc_b(intra_16x16_prob_update);
215 if (current->intra_16x16_prob_update)
216 for (int i = 0; i < 4; i++)
217 bc_fs(8, intra_16x16_prob[i], 1, i);
218
219 // intra_chroma_prob
220 bc_b(intra_chrome_prob_update);
221 if (current->intra_chrome_prob_update)
222 for (int i = 0; i < 3; i++)
223 bc_fs(8, intra_chrome_prob[i], 1, i);
224
225 CHECK(FUNC(update_mv_probs)(ctx, bool_coding_rw, current));
226 }
227
228 return 0;
229}
230
231static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
232 VP8RawFrame *current)
233{
234 HEADER("Frame");
235
236 CHECK(FUNC(frame_tag)(ctx, rw, &current->header));
237
238 return 0;
239}
240
241static int FUNC(compressed_header)(CodedBitstreamContext *ctx,
242 CBSVP8BoolCodingRW *bool_coding_rw,
243 VP8RawFrame *current)
244{
245 CHECK(FUNC(frame_header)(ctx, bool_coding_rw, &current->header));
246
247 return 0;
248}

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