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)
51#define MAX_VLC_ENTRIES 1023
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 },
74 1, 0, 2, 4, 8, 16, 32, 0, 64, 0, 128, 0, 256, 0, 512,
78 1, 2, 4, 0, 8, 0, 16, 0, 32, 0, 64, 0, 128, 0, 256,
102 int mb_count, pb_frame, marker, mb_xy;
116 ff_dlog(
h->c.avctx,
"pict_type=%d pb_frame=%d\n",
h->c.pict_type, pb_frame);
124 if (
h->c.qscale == 0) {
130 if (
h->rv10_version == 3) {
135 ff_dlog(
h->c.avctx,
"DC:%d %d %d\n",
h->last_dc[0],
136 h->last_dc[1],
h->last_dc[2]);
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)) {
150 mb_count =
h->c.mb_width *
h->c.mb_height;
163 int seq, mb_pos, ret;
166 h->c.pict_type = pict_types[
get_bits(&
h->gb, 2)];
183 if (
h->c.qscale == 0) {
189 h->loop_filter =
get_bits1(&
h->gb) && !
h->c.avctx->lowres;
196 rpr_max =
h->c.avctx->extradata[1] & 7;
199 int rpr_bits =
av_log2(rpr_max) + 1;
204 if (
h->c.avctx->extradata_size < 8 + 2 *
f) {
209 new_w = 4 *
h->c.avctx->extradata[6 + 2 *
f];
210 new_h = 4 *
h->c.avctx->extradata[7 + 2 *
f];
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;
218 "attempting to change resolution to %dx%d\n", new_w, new_h);
222 if (whole_size < (new_w + 15)/16 * ((new_h + 15)/16) / 8)
254 seq |=
h->c.time & ~0x7FFF;
255 if (seq -
h->c.time > 0x4000)
257 if (seq -
h->c.time < -0x4000)
260 if (seq !=
h->c.time) {
263 h->c.pp_time =
h->c.time -
h->c.last_non_b_time;
264 h->c.last_non_b_time =
h->c.time;
267 h->c.pb_time =
h->c.pp_time - (
h->c.last_non_b_time -
h->c.time);
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) {
273 "messed up order, possible from seeking? skipping current B-frame\n");
274#define ERROR_SKIP_FRAME -123
288 h->c.y_dc_scale_table =
291 h->c.y_dc_scale_table =
294 if (!
h->c.avctx->lowres)
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,
306 return h->c.mb_width *
h->c.mb_height - mb_pos;
310 const uint16_t len_count[15],
311 const uint8_t sym_rl[][2],
int sym_rl_elems)
315 unsigned nb_syms = 0, nb_lens = 0;
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--;
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;
328 lens, 1, syms, 2, 2, 0, 0);
355 int major_ver, minor_ver, micro_ver, ret;
372 h->h263_long_vectors = avctx->
extradata[3] & 1;
375 h->modified_quant = 1;
385 h->rv10_version = micro_ver ? 3 : 1;
386 h->c.obmc = micro_ver == 2;
389 if (minor_ver >= 2) {
412 int buf_size,
int buf_size2,
int whole_size)
416 int mb_count, mb_pos,
left, start_mb_x, active_bits_size, ret;
420 active_bits_size = buf_size * 8;
431 if (
h->c.mb_x >=
h->c.mb_width ||
432 h->c.mb_y >=
h->c.mb_height) {
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) {
443 if (whole_size < h->
c.mb_width *
h->c.mb_height / 8)
446 if ((
h->c.mb_x == 0 &&
h->c.mb_y == 0) || !
h->c.cur_pic.ptr) {
448 if (
h->c.cur_pic.ptr) {
451 h->c.mb_x =
h->c.mb_y =
h->c.resync_mb_x =
h->c.resync_mb_y = 0;
457 if (
h->c.cur_pic.ptr->f->pict_type !=
h->c.pict_type) {
464 ff_dlog(avctx,
"qscale=%d\n",
h->c.qscale);
469 h->c.first_slice_line = 1;
471 h->c.first_slice_line = 1;
472 h->c.resync_mb_x =
h->c.mb_x;
474 start_mb_x =
h->c.mb_x;
475 h->c.resync_mb_y =
h->c.mb_y;
479 h->rv10_first_dc_coded[0] = 0;
480 h->rv10_first_dc_coded[1] = 0;
481 h->rv10_first_dc_coded[2] = 0;
485 for (
h->mb_num_left = mb_count;
h->mb_num_left > 0;
h->mb_num_left--) {
488 ff_tlog(avctx,
"**mb x=%d y=%d\n",
h->c.mb_x,
h->c.mb_y);
507 active_bits_size = buf_size2 * 8;
509 8 * buf_size, active_bits_size);
524 if (++
h->c.mb_x ==
h->c.mb_width) {
529 if (
h->c.mb_x ==
h->c.resync_mb_x)
530 h->c.first_slice_line = 0;
538 return active_bits_size;
549 const uint8_t *buf = avpkt->
data;
550 int buf_size = avpkt->
size;
554 const uint8_t *slices_hdr =
NULL;
556 ff_dlog(avctx,
"*****frame %"PRId64
" size=%d\n", avctx->
frame_num, buf_size);
563 slice_count = (*buf++) + 1;
566 if (!slice_count || buf_size <= 8 * slice_count) {
572 slices_hdr = buf + 4;
573 buf += 8 * slice_count;
574 buf_size -= 8 * slice_count;
576 for (
i = 0;
i < slice_count;
i++) {
583 if (
i + 1 == slice_count)
588 if (
i + 2 >= slice_count)
589 size2 = buf_size -
offset;
593 if (
size <= 0 || size2 <= 0 ||
604 if (
s->cur_pic.ptr &&
s->mb_y >=
s->mb_height) {
613 }
else if (
s->last_pic.ptr) {
620 if (
s->last_pic.ptr ||
s->low_delay) {
const FFCodec ff_rv20_decoder
const FFCodec ff_rv10_decoder
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_DEBUG_PICT_INFO
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)
#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...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
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...
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
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...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
void ff_h263_update_motion_val(MpegEncContext *s)
void ff_h263_loop_filter(MpegEncContext *s)
const uint8_t ff_aic_dc_scale_table[32]
const uint8_t ff_h263_chroma_qscale_table[32]
int ff_h263_decode_mb(H263DecContext *const h)
int ff_h263_decode_mba(H263DecContext *const h)
#define SLICE_END
end marker found
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
static int ff_thread_once(char *control, void(*routine)(void))
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
static void ff_mpv_er_frame_start_ext(MPVContext *const s, int partitioned_frame, uint16_t pp_time, uint16_t pb_time)
void ff_mpv_unref_picture(MPVWorkPicture *pic)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
av_cold void ff_mpv_common_end(MpegEncContext *s)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
void ff_init_block_index(MpegEncContext *s)
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
#define MV_TYPE_16X16
1 vector for the whole mb
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]
#define RV_GET_MINOR_VER(x)
static int rv10_decode_picture_header(H263DecContext *const h)
static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int buf_size2, int whole_size)
static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
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)
static const uint8_t rv_sym_run_len[][2]
static av_cold void rv10_init_static(void)
#define RV_GET_MAJOR_VER(x)
static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
int ff_rv_decode_dc(H263DecContext *const h, int n)
static VLCElem rv_dc_chrom[992]
#define RV_GET_MICRO_VER(x)
static const uint16_t rv_chrom_len_count[15]
static VLCElem rv_dc_lum[1472]
static av_cold int rv10_decode_init(AVCodecContext *avctx)
#define FF_ARRAY_ELEMS(a)
main external API structure.
int64_t frame_num
Frame counter, set by libavcodec.
int has_b_frames
Size of the frame reordering buffer in the decoder.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int coded_width
Bitstream width / height, may be different from width/height e.g.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
#define avpriv_request_sample(...)
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)