FFmpeg
Loading...
Searching...
No Matches
rv10.c
Go to the documentation of this file.
1/*
2 * RV10/RV20 decoder
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file
25 * RV10/RV20 decoder
26 */
27
28#include <inttypes.h>
29
30#include "libavutil/imgutils.h"
31#include "libavutil/thread.h"
32
33#include "avcodec.h"
34#include "codec_internal.h"
35#include "decode.h"
36#include "error_resilience.h"
37#include "h263.h"
38#include "h263data.h"
39#include "h263dec.h"
40#include "mpeg_er.h"
41#include "mpegvideo.h"
42#include "mpegvideodec.h"
43#include "mpeg4video.h"
44#include "mpegvideodata.h"
45#include "rv10dec.h"
46
47#define RV_GET_MAJOR_VER(x) ((x) >> 28)
48#define RV_GET_MINOR_VER(x) (((x) >> 20) & 0xFF)
49#define RV_GET_MICRO_VER(x) (((x) >> 12) & 0xFF)
50
51#define MAX_VLC_ENTRIES 1023 // Note: Does not include the skip entries.
52#define DC_VLC_BITS 9
53
59
60/* (run, length) encoded value for the symbols table. The actual symbols
61 * are run..run - length (mod 256).
62 * The last two entries in the following table apply to luma only.
63 * The skip values are not included in this list. */
64static const uint8_t rv_sym_run_len[][2] = {
65 { 0, 0 }, { 1, 0 }, { 255, 0 }, { 3, 1 }, { 254, 1 },
66 { 7, 3 }, { 252, 3 }, { 15, 7 }, { 248, 7 }, { 31, 15 },
67 { 240, 15 }, { 63, 31 }, { 224, 31 }, { 127, 63 }, { 192, 63 },
68 { 255, 127 }, { 128, 127 }, { 127, 255 }, { 128, 255 },
69};
70
71/* entry[i] of the following tables gives
72 * the number of VLC codes of length i + 2. */
73static const uint16_t rv_lum_len_count[15] = {
74 1, 0, 2, 4, 8, 16, 32, 0, 64, 0, 128, 0, 256, 0, 512,
75};
76
77static const uint16_t rv_chrom_len_count[15] = {
78 1, 2, 4, 0, 8, 0, 16, 0, 32, 0, 64, 0, 128, 0, 256,
79};
80
81static VLCElem rv_dc_lum[1472], rv_dc_chrom[992];
82
84{
85 int code;
86
87 if (n < 4) {
88 code = get_vlc2(&h->gb, rv_dc_lum, DC_VLC_BITS, 2);
89 } else {
91 if (code < 0) {
92 av_log(h->c.avctx, AV_LOG_ERROR, "chroma dc error\n");
93 return -1;
94 }
95 }
96 return code;
97}
98
99/* read RV 1.0 compatible frame header */
101{
102 int mb_count, pb_frame, marker, mb_xy;
103
104 marker = get_bits1(&h->gb);
105
106 if (get_bits1(&h->gb))
107 h->c.pict_type = AV_PICTURE_TYPE_P;
108 else
109 h->c.pict_type = AV_PICTURE_TYPE_I;
110
111 if (!marker)
112 av_log(h->c.avctx, AV_LOG_ERROR, "marker missing\n");
113
114 pb_frame = get_bits1(&h->gb);
115
116 ff_dlog(h->c.avctx, "pict_type=%d pb_frame=%d\n", h->c.pict_type, pb_frame);
117
118 if (pb_frame) {
119 avpriv_request_sample(h->c.avctx, "PB-frame");
121 }
122
123 h->c.qscale = get_bits(&h->gb, 5);
124 if (h->c.qscale == 0) {
125 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
126 return AVERROR_INVALIDDATA;
127 }
128
129 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
130 if (h->rv10_version == 3) {
131 /* specific MPEG like DC coding not used */
132 h->last_dc[0] = get_bits(&h->gb, 8);
133 h->last_dc[1] = get_bits(&h->gb, 8);
134 h->last_dc[2] = get_bits(&h->gb, 8);
135 ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->last_dc[0],
136 h->last_dc[1], h->last_dc[2]);
137 }
138 }
139 /* if multiple packets per frame are sent, the position at which
140 * to display the macroblocks is coded here */
141
142 mb_xy = h->c.mb_x + h->c.mb_y * h->c.mb_width;
143 if (show_bits(&h->gb, 12) == 0 || (mb_xy && mb_xy < h->c.mb_num)) {
144 h->c.mb_x = get_bits(&h->gb, 6); /* mb_x */
145 h->c.mb_y = get_bits(&h->gb, 6); /* mb_y */
146 mb_count = get_bits(&h->gb, 12);
147 } else {
148 h->c.mb_x = 0;
149 h->c.mb_y = 0;
150 mb_count = h->c.mb_width * h->c.mb_height;
151 }
152 skip_bits(&h->gb, 3); /* ignored */
153
154 return mb_count;
155}
156
157static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
158{
159 static const enum AVPictureType pict_types[] =
160 { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */,
162 H263DecContext *const h = &rv->h;
163 int seq, mb_pos, ret;
164 int rpr_max;
165
166 h->c.pict_type = pict_types[get_bits(&h->gb, 2)];
167
168 if (h->c.low_delay && h->c.pict_type == AV_PICTURE_TYPE_B) {
169 av_log(h->c.avctx, AV_LOG_ERROR, "low delay B\n");
170 return -1;
171 }
172 if (!h->c.last_pic.ptr && h->c.pict_type == AV_PICTURE_TYPE_B) {
173 av_log(h->c.avctx, AV_LOG_ERROR, "early B-frame\n");
174 return AVERROR_INVALIDDATA;
175 }
176
177 if (get_bits1(&h->gb)) {
178 av_log(h->c.avctx, AV_LOG_ERROR, "reserved bit set\n");
179 return AVERROR_INVALIDDATA;
180 }
181
182 h->c.qscale = get_bits(&h->gb, 5);
183 if (h->c.qscale == 0) {
184 av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
185 return AVERROR_INVALIDDATA;
186 }
187
188 if (RV_GET_MINOR_VER(rv->sub_id) >= 2)
189 h->loop_filter = get_bits1(&h->gb) && !h->c.avctx->lowres;
190
191 if (RV_GET_MINOR_VER(rv->sub_id) <= 1)
192 seq = get_bits(&h->gb, 8) << 7;
193 else
194 seq = get_bits(&h->gb, 13) << 2;
195
196 rpr_max = h->c.avctx->extradata[1] & 7;
197 if (rpr_max) {
198 int f, new_w, new_h;
199 int rpr_bits = av_log2(rpr_max) + 1;
200
201 f = get_bits(&h->gb, rpr_bits);
202
203 if (f) {
204 if (h->c.avctx->extradata_size < 8 + 2 * f) {
205 av_log(h->c.avctx, AV_LOG_ERROR, "Extradata too small.\n");
206 return AVERROR_INVALIDDATA;
207 }
208
209 new_w = 4 * h->c.avctx->extradata[6 + 2 * f];
210 new_h = 4 * h->c.avctx->extradata[7 + 2 * f];
211 } else {
212 new_w = rv->orig_width;
213 new_h = rv->orig_height;
214 }
215 if (new_w != h->c.width || new_h != h->c.height || !h->c.context_initialized) {
216 AVRational old_aspect = h->c.avctx->sample_aspect_ratio;
217 av_log(h->c.avctx, AV_LOG_DEBUG,
218 "attempting to change resolution to %dx%d\n", new_w, new_h);
219 if (av_image_check_size(new_w, new_h, 0, h->c.avctx) < 0)
220 return AVERROR_INVALIDDATA;
221
222 if (whole_size < (new_w + 15)/16 * ((new_h + 15)/16) / 8)
223 return AVERROR_INVALIDDATA;
224
225 ff_mpv_common_end(&h->c);
226
227 // attempt to keep aspect during typical resolution switches
228 if (!old_aspect.num)
229 old_aspect = (AVRational){1, 1};
230 if (2 * (int64_t)new_w * h->c.height == (int64_t)new_h * h->c.width)
231 h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1});
232 if ((int64_t)new_w * h->c.height == 2 * (int64_t)new_h * h->c.width)
233 h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2});
234
235 ret = ff_set_dimensions(h->c.avctx, new_w, new_h);
236 if (ret < 0)
237 return ret;
238
239 h->c.width = new_w;
240 h->c.height = new_h;
241 if ((ret = ff_mpv_common_init(&h->c)) < 0)
242 return ret;
243 }
244
245 if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
246 av_log(h->c.avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max);
247 }
248 }
249 if (av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx) < 0)
250 return AVERROR_INVALIDDATA;
251
252 mb_pos = ff_h263_decode_mba(h);
253
254 seq |= h->c.time & ~0x7FFF;
255 if (seq - h->c.time > 0x4000)
256 seq -= 0x8000;
257 if (seq - h->c.time < -0x4000)
258 seq += 0x8000;
259
260 if (seq != h->c.time) {
261 if (h->c.pict_type != AV_PICTURE_TYPE_B) {
262 h->c.time = seq;
263 h->c.pp_time = h->c.time - h->c.last_non_b_time;
264 h->c.last_non_b_time = h->c.time;
265 } else {
266 h->c.time = seq;
267 h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
268 }
269 }
270 if (h->c.pict_type == AV_PICTURE_TYPE_B) {
271 if (h->c.pp_time <=h->c.pb_time || h->c.pp_time <= h->c.pp_time - h->c.pb_time || h->c.pp_time<=0) {
272 av_log(h->c.avctx, AV_LOG_DEBUG,
273 "messed up order, possible from seeking? skipping current B-frame\n");
274#define ERROR_SKIP_FRAME -123
275 return ERROR_SKIP_FRAME;
276 }
278 }
279
280 h->c.no_rounding = get_bits1(&h->gb);
281
282 if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && h->c.pict_type == AV_PICTURE_TYPE_B)
283 // binary decoder reads 3+2 bits here but they don't seem to be used
284 skip_bits(&h->gb, 5);
285
286 h->c.h263_aic = h->c.pict_type == AV_PICTURE_TYPE_I;
287 if (h->c.h263_aic) {
288 h->c.y_dc_scale_table =
289 h->c.c_dc_scale_table = ff_aic_dc_scale_table;
290 } else {
291 h->c.y_dc_scale_table =
292 h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table;
293 }
294 if (!h->c.avctx->lowres)
295 h->loop_filter = 1;
296
297 if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
298 av_log(h->c.avctx, AV_LOG_INFO,
299 "num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n",
300 seq, h->c.mb_x, h->c.mb_y, h->c.pict_type, h->c.qscale,
301 h->c.no_rounding);
302 }
303
304 av_assert0(h->c.pict_type != AV_PICTURE_TYPE_B || !h->c.low_delay);
305
306 return h->c.mb_width * h->c.mb_height - mb_pos;
307}
308
309static av_cold void rv10_build_vlc(VLCElem vlc[], int table_size,
310 const uint16_t len_count[15],
311 const uint8_t sym_rl[][2], int sym_rl_elems)
312{
313 uint16_t syms[MAX_VLC_ENTRIES];
314 uint8_t lens[MAX_VLC_ENTRIES];
315 unsigned nb_syms = 0, nb_lens = 0;
316
317 for (unsigned i = 0; i < sym_rl_elems; i++) {
318 unsigned cur_sym = sym_rl[i][0];
319 for (unsigned tmp = nb_syms + sym_rl[i][1]; nb_syms <= tmp; nb_syms++)
320 syms[nb_syms] = 0xFF & cur_sym--;
321 }
322
323 for (unsigned i = 0; i < 15; i++)
324 for (unsigned tmp = nb_lens + len_count[i]; nb_lens < tmp; nb_lens++)
325 lens[nb_lens] = i + 2;
326 av_assert1(nb_lens == nb_syms);
327 ff_vlc_init_table_from_lengths(vlc, table_size, DC_VLC_BITS, nb_lens,
328 lens, 1, syms, 2, 2, 0, 0);
329}
330
331static av_cold void rv10_init_static(void)
332{
335 for (int i = 0; i < 1 << (DC_VLC_BITS - 7 /* Length of skip prefix */); i++) {
336 /* All codes beginning with 0x7F have the same length and value.
337 * Modifying the table directly saves us the useless subtables. */
338 rv_dc_lum[(0x7F << (DC_VLC_BITS - 7)) + i].sym = 255;
339 rv_dc_lum[(0x7F << (DC_VLC_BITS - 7)) + i].len = 18;
340 }
343 for (int i = 0; i < 1 << (DC_VLC_BITS - 9 /* Length of skip prefix */); i++) {
344 /* Same as above. */
345 rv_dc_chrom[(0x1FE << (DC_VLC_BITS - 9)) + i].sym = 255;
346 rv_dc_chrom[(0x1FE << (DC_VLC_BITS - 9)) + i].len = 18;
347 }
348}
349
351{
352 static AVOnce init_static_once = AV_ONCE_INIT;
353 RVDecContext *rv = avctx->priv_data;
354 H263DecContext *const h = &rv->h;
355 int major_ver, minor_ver, micro_ver, ret;
356
357 if (avctx->extradata_size < 8) {
358 av_log(avctx, AV_LOG_ERROR, "Extradata is too small.\n");
359 return AVERROR_INVALIDDATA;
360 }
361 if ((ret = av_image_check_size(avctx->coded_width,
362 avctx->coded_height, 0, avctx)) < 0)
363 return ret;
364
365 ret = ff_h263_decode_init(avctx);
366 if (ret < 0)
367 return ret;
368
369 rv->orig_width = avctx->coded_width;
370 rv->orig_height = avctx->coded_height;
371
372 h->h263_long_vectors = avctx->extradata[3] & 1;
373 rv->sub_id = AV_RB32A(avctx->extradata + 4);
374 if (avctx->codec_id == AV_CODEC_ID_RV20) {
375 h->modified_quant = 1;
376 h->c.chroma_qscale_table = ff_h263_chroma_qscale_table;
377 }
378
379 major_ver = RV_GET_MAJOR_VER(rv->sub_id);
380 minor_ver = RV_GET_MINOR_VER(rv->sub_id);
381 micro_ver = RV_GET_MICRO_VER(rv->sub_id);
382
383 switch (major_ver) {
384 case 1:
385 h->rv10_version = micro_ver ? 3 : 1;
386 h->c.obmc = micro_ver == 2;
387 break;
388 case 2:
389 if (minor_ver >= 2) {
390 h->c.low_delay = 0;
391 avctx->has_b_frames = 1;
392 }
393 break;
394 default:
395 av_log(avctx, AV_LOG_ERROR, "unknown header %X\n", rv->sub_id);
396 avpriv_request_sample(avctx, "RV1/2 version");
398 }
399
400 if (avctx->debug & FF_DEBUG_PICT_INFO) {
401 av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%"PRIX32"\n", rv->sub_id,
402 AV_RL32A(avctx->extradata));
403 }
404
405 /* init static VLCs */
406 ff_thread_once(&init_static_once, rv10_init_static);
407
408 return 0;
409}
410
411static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
412 int buf_size, int buf_size2, int whole_size)
413{
414 RVDecContext *rv = avctx->priv_data;
415 H263DecContext *const h = &rv->h;
416 int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret;
417
418 if ((ret = init_get_bits8(&h->gb, buf, FFMAX(buf_size, buf_size2))) < 0)
419 return ret;
420 active_bits_size = buf_size * 8;
421 if (h->c.codec_id == AV_CODEC_ID_RV10)
422 mb_count = rv10_decode_picture_header(h);
423 else
424 mb_count = rv20_decode_picture_header(rv, whole_size);
425 if (mb_count < 0) {
426 if (mb_count != ERROR_SKIP_FRAME)
427 av_log(h->c.avctx, AV_LOG_ERROR, "HEADER ERROR\n");
428 return AVERROR_INVALIDDATA;
429 }
430
431 if (h->c.mb_x >= h->c.mb_width ||
432 h->c.mb_y >= h->c.mb_height) {
433 av_log(h->c.avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", h->c.mb_x, h->c.mb_y);
434 return AVERROR_INVALIDDATA;
435 }
436 mb_pos = h->c.mb_y * h->c.mb_width + h->c.mb_x;
437 left = h->c.mb_width * h->c.mb_height - mb_pos;
438 if (mb_count > left) {
439 av_log(h->c.avctx, AV_LOG_ERROR, "COUNT ERROR\n");
440 return AVERROR_INVALIDDATA;
441 }
442
443 if (whole_size < h->c.mb_width * h->c.mb_height / 8)
444 return AVERROR_INVALIDDATA;
445
446 if ((h->c.mb_x == 0 && h->c.mb_y == 0) || !h->c.cur_pic.ptr) {
447 // FIXME write parser so we always have complete frames?
448 if (h->c.cur_pic.ptr) {
449 ff_er_frame_end(&h->c.er, NULL);
450 ff_mpv_frame_end(&h->c);
451 h->c.mb_x = h->c.mb_y = h->c.resync_mb_x = h->c.resync_mb_y = 0;
452 }
453 if ((ret = ff_mpv_frame_start(&h->c, avctx)) < 0)
454 return ret;
455 ff_mpv_er_frame_start_ext(&h->c, 0, h->c.pp_time, h->c.pb_time);
456 } else {
457 if (h->c.cur_pic.ptr->f->pict_type != h->c.pict_type) {
458 av_log(h->c.avctx, AV_LOG_ERROR, "Slice type mismatch\n");
459 return AVERROR_INVALIDDATA;
460 }
461 }
462
463
464 ff_dlog(avctx, "qscale=%d\n", h->c.qscale);
465
466 /* default quantization values */
467 if (h->c.codec_id == AV_CODEC_ID_RV10) {
468 if (h->c.mb_y == 0)
469 h->c.first_slice_line = 1;
470 } else {
471 h->c.first_slice_line = 1;
472 h->c.resync_mb_x = h->c.mb_x;
473 }
474 start_mb_x = h->c.mb_x;
475 h->c.resync_mb_y = h->c.mb_y;
476
477 ff_set_qscale(&h->c, h->c.qscale);
478
479 h->rv10_first_dc_coded[0] = 0;
480 h->rv10_first_dc_coded[1] = 0;
481 h->rv10_first_dc_coded[2] = 0;
483
484 /* decode each macroblock */
485 for (h->mb_num_left = mb_count; h->mb_num_left > 0; h->mb_num_left--) {
486 int ret;
487 ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
488 ff_tlog(avctx, "**mb x=%d y=%d\n", h->c.mb_x, h->c.mb_y);
489
490 h->c.mv_dir = MV_DIR_FORWARD;
491 h->c.mv_type = MV_TYPE_16X16;
492 ret = ff_h263_decode_mb(h);
493
494 // Repeat the slice end check from ff_h263_decode_mb with our active
495 // bitstream size
496 if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->gb)) {
497 int v = show_bits(&h->gb, 16);
498
499 if (get_bits_count(&h->gb) + 16 > active_bits_size)
500 v >>= get_bits_count(&h->gb) + 16 - active_bits_size;
501
502 if (!v)
503 ret = SLICE_END;
504 }
505 if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&h->gb) &&
506 8 * buf_size2 >= get_bits_count(&h->gb)) {
507 active_bits_size = buf_size2 * 8;
508 av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
509 8 * buf_size, active_bits_size);
510 ret = SLICE_OK;
511 }
512
513 if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->gb)) {
514 av_log(h->c.avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", h->c.mb_x,
515 h->c.mb_y);
516 return AVERROR_INVALIDDATA;
517 }
518 if (h->c.pict_type != AV_PICTURE_TYPE_B)
520 ff_mpv_reconstruct_mb(&h->c, h->block);
521 if (h->loop_filter)
523
524 if (++h->c.mb_x == h->c.mb_width) {
525 h->c.mb_x = 0;
526 h->c.mb_y++;
528 }
529 if (h->c.mb_x == h->c.resync_mb_x)
530 h->c.first_slice_line = 0;
531 if (ret == SLICE_END)
532 break;
533 }
534
535 ff_er_add_slice(&h->c.er, start_mb_x, h->c.resync_mb_y, h->c.mb_x - 1, h->c.mb_y,
536 ER_MB_END);
537
538 return active_bits_size;
539}
540
541static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
542{
543 return AV_RL32(buf + n * 8);
544}
545
546static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict,
547 int *got_frame, AVPacket *avpkt)
548{
549 const uint8_t *buf = avpkt->data;
550 int buf_size = avpkt->size;
551 MpegEncContext *s = avctx->priv_data;
552 int i, ret;
553 int slice_count;
554 const uint8_t *slices_hdr = NULL;
555
556 ff_dlog(avctx, "*****frame %"PRId64" size=%d\n", avctx->frame_num, buf_size);
557
558 /* no supplementary picture */
559 if (buf_size == 0) {
560 return 0;
561 }
562
563 slice_count = (*buf++) + 1;
564 buf_size--;
565
566 if (!slice_count || buf_size <= 8 * slice_count) {
567 av_log(avctx, AV_LOG_ERROR, "Invalid slice count: %d.\n",
568 slice_count);
569 return AVERROR_INVALIDDATA;
570 }
571
572 slices_hdr = buf + 4;
573 buf += 8 * slice_count;
574 buf_size -= 8 * slice_count;
575
576 for (i = 0; i < slice_count; i++) {
577 unsigned offset = get_slice_offset(avctx, slices_hdr, i);
578 int size, size2;
579
580 if (offset >= buf_size)
581 return AVERROR_INVALIDDATA;
582
583 if (i + 1 == slice_count)
584 size = buf_size - offset;
585 else
586 size = get_slice_offset(avctx, slices_hdr, i + 1) - offset;
587
588 if (i + 2 >= slice_count)
589 size2 = buf_size - offset;
590 else
591 size2 = get_slice_offset(avctx, slices_hdr, i + 2) - offset;
592
593 if (size <= 0 || size2 <= 0 ||
594 offset + FFMAX(size, size2) > buf_size)
595 return AVERROR_INVALIDDATA;
596
597 if ((ret = rv10_decode_packet(avctx, buf + offset, size, size2, buf_size)) < 0)
598 return ret;
599
600 if (ret > 8 * size)
601 i++;
602 }
603
604 if (s->cur_pic.ptr && s->mb_y >= s->mb_height) {
605 ff_er_frame_end(&s->er, NULL);
607
608 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
609 if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
610 return ret;
611 ff_print_debug_info(s, s->cur_pic.ptr, pict);
613 } else if (s->last_pic.ptr) {
614 if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0)
615 return ret;
616 ff_print_debug_info(s, s->last_pic.ptr, pict);
618 }
619
620 if (s->last_pic.ptr || s->low_delay) {
621 *got_frame = 1;
622 }
623
624 // so we can detect if frame_end was not called (find some nicer solution...)
625 ff_mpv_unref_picture(&s->cur_pic);
626 }
627
628 return avpkt->size;
629}
630
632 .p.name = "rv10",
633 CODEC_LONG_NAME("RealVideo 1.0"),
634 .p.type = AVMEDIA_TYPE_VIDEO,
635 .p.id = AV_CODEC_ID_RV10,
636 .priv_data_size = sizeof(RVDecContext),
639 .close = ff_mpv_decode_close,
640 .p.capabilities = AV_CODEC_CAP_DR1,
641 .p.max_lowres = 3,
642 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
643};
644
646 .p.name = "rv20",
647 CODEC_LONG_NAME("RealVideo 2.0"),
648 .p.type = AVMEDIA_TYPE_VIDEO,
649 .p.id = AV_CODEC_ID_RV20,
650 .priv_data_size = sizeof(RVDecContext),
653 .close = ff_mpv_decode_close,
654 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
655 .flush = ff_mpeg_flush,
656 .p.max_lowres = 3,
657 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
658};
const FFCodec ff_rv20_decoder
Definition rv10.c:645
const FFCodec ff_rv10_decoder
Definition rv10.c:631
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
#define FF_DEBUG_PICT_INFO
Definition avcodec.h:1393
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
#define MAX_VLC_ENTRIES
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
void ff_er_frame_end(ERContext *s, int *decode_error_flags)
Indicate that a frame has finished decoding and perform error concealment in case it has been enabled...
#define ER_MB_END
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition get_bits.h:645
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static int get_bits_count(const GetBitContext *s)
Definition get_bits.h:254
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition get_bits.h:373
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_RV10
Definition codec_id.h:55
@ AV_CODEC_ID_RV20
Definition codec_id.h:56
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition frame.c:278
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition rational.c:80
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition imgutils.c:318
AVPictureType
Definition avutil.h:276
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition avutil.h:280
void ff_h263_update_motion_val(MpegEncContext *s)
Definition h263.c:56
void ff_h263_loop_filter(MpegEncContext *s)
Definition h263.c:97
const uint8_t ff_aic_dc_scale_table[32]
Definition h263data.c:245
const uint8_t ff_h263_chroma_qscale_table[32]
Definition h263data.c:260
H.263 tables.
int ff_h263_decode_mb(H263DecContext *const h)
Definition ituh263dec.c:784
int ff_h263_decode_mba(H263DecContext *const h)
Definition ituh263dec.c:142
misc image utilities
#define av_log2
Definition intmath.h:84
#define DC_VLC_BITS
Definition intrax8.c:41
#define AV_RL32(p)
#define AV_RL32A(p)
#define AV_RB32A(p)
unsigned offset
Definition libaomenc.c:763
#define SLICE_END
end marker found
Definition h261dec.c:42
#define SLICE_OK
Definition h261dec.c:40
#define SLICE_ERROR
Definition h261dec.c:41
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition h263dec.c:94
#define av_cold
Definition attributes.h:117
#define AVOnce
Definition thread.h:202
static int ff_thread_once(char *control, void(*routine)(void))
Definition thread.h:205
#define AV_ONCE_INIT
Definition thread.h:203
#define FFMAX(a, b)
Definition macros.h:47
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
Definition mpeg4video.c:73
static void ff_mpv_er_frame_start_ext(MPVContext *const s, int partitioned_frame, uint16_t pp_time, uint16_t pb_time)
Definition mpeg_er.h:27
void ff_mpv_unref_picture(MPVWorkPicture *pic)
Definition mpegpicture.c:98
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition mpegvideo.c:359
av_cold void ff_mpv_common_end(MpegEncContext *s)
Definition mpegvideo.c:428
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition mpegvideo.c:505
void ff_init_block_index(MpegEncContext *s)
Definition mpegvideo.c:472
mpegvideo header.
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
Definition mpegvideo.h:335
#define MV_DIR_FORWARD
Definition mpegvideo.h:168
#define MV_TYPE_16X16
1 vector for the whole mb
Definition mpegvideo.h:172
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
av_cold void ff_mpeg_flush(AVCodecContext *avctx)
void ff_mpv_frame_end(MpegEncContext *s)
int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const MPVPicture *p, int qp_type)
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64])
static const uint8_t *const ff_mpeg1_dc_scale_table
mpegvideo decoder header.
#define FF_MPV_QSCALE_TYPE_MPEG1
static const uint16_t rv_lum_len_count[15]
Definition rv10.c:73
#define RV_GET_MINOR_VER(x)
Definition rv10.c:48
static int rv10_decode_picture_header(H263DecContext *const h)
Definition rv10.c:100
static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int buf_size2, int whole_size)
Definition rv10.c:411
static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
Definition rv10.c:157
static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
Definition rv10.c:541
static av_cold void rv10_build_vlc(VLCElem vlc[], int table_size, const uint16_t len_count[15], const uint8_t sym_rl[][2], int sym_rl_elems)
Definition rv10.c:309
static const uint8_t rv_sym_run_len[][2]
Definition rv10.c:64
static av_cold void rv10_init_static(void)
Definition rv10.c:331
#define RV_GET_MAJOR_VER(x)
Definition rv10.c:47
static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition rv10.c:546
int ff_rv_decode_dc(H263DecContext *const h, int n)
Definition rv10.c:83
#define ERROR_SKIP_FRAME
static VLCElem rv_dc_chrom[992]
Definition rv10.c:81
#define RV_GET_MICRO_VER(x)
Definition rv10.c:49
static const uint16_t rv_chrom_len_count[15]
Definition rv10.c:77
static VLCElem rv_dc_lum[1472]
Definition rv10.c:81
static av_cold int rv10_decode_init(AVCodecContext *avctx)
Definition rv10.c:350
#define FF_ARRAY_ELEMS(a)
const uint8_t * code
Definition spdifenc.c:433
main external API structure.
Definition avcodec.h:443
int debug
debug
Definition avcodec.h:1392
int64_t frame_num
Frame counter, set by libavcodec.
Definition avcodec.h:1883
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition avcodec.h:709
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
enum AVCodecID codec_id
Definition avcodec.h:453
int extradata_size
Definition avcodec.h:527
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:619
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
MpegEncContext.
Definition mpegvideo.h:67
int orig_height
Definition rv10.c:57
int orig_width
Definition rv10.c:57
H263DecContext h
Definition rv10.c:55
int sub_id
Definition rv10.c:56
Definition vlc.h:32
#define ff_dlog(a,...)
#define avpriv_request_sample(...)
#define ff_tlog(a,...)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
int size
av_cold void ff_vlc_init_table_from_lengths(VLCElem table[], int table_size, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
Definition vlc.c:353
int len
static double c[64]