45 #define RV_GET_MAJOR_VER(x) ((x) >> 28)
46 #define RV_GET_MINOR_VER(x) (((x) >> 20) & 0xFF)
47 #define RV_GET_MICRO_VER(x) (((x) >> 12) & 0xFF)
49 #define MAX_VLC_ENTRIES 1023
63 { 0, 0 }, { 1, 0 }, { 255, 0 }, { 3, 1 }, { 254, 1 },
64 { 7, 3 }, { 252, 3 }, { 15, 7 }, { 248, 7 }, { 31, 15 },
65 { 240, 15 }, { 63, 31 }, { 224, 31 }, { 127, 63 }, { 192, 63 },
66 { 255, 127 }, { 128, 127 }, { 127, 255 }, { 128, 255 },
72 1, 0, 2, 4, 8, 16, 32, 0, 64, 0, 128, 0, 256, 0, 512,
76 1, 2, 4, 0, 8, 0, 16, 0, 32, 0, 64, 0, 128, 0, 256,
100 int mb_count, pb_frame, marker, mb_xy;
114 ff_dlog(
s->avctx,
"pict_type=%d pb_frame=%d\n",
s->pict_type, pb_frame);
122 if (
s->qscale == 0) {
128 if (
s->rv10_version == 3) {
133 ff_dlog(
s->avctx,
"DC:%d %d %d\n",
s->last_dc[0],
134 s->last_dc[1],
s->last_dc[2]);
140 mb_xy =
s->mb_x +
s->mb_y *
s->mb_width;
141 if (
show_bits(&
s->gb, 12) == 0 || (mb_xy && mb_xy < s->mb_num)) {
148 mb_count =
s->mb_width *
s->mb_height;
152 s->unrestricted_mv = 1;
160 int seq, mb_pos,
i, ret;
197 if (
s->qscale == 0) {
203 s->loop_filter =
get_bits1(&
s->gb) && !
s->avctx->lowres;
210 rpr_max =
s->avctx->extradata[1] & 7;
213 int rpr_bits =
av_log2(rpr_max) + 1;
218 if (
s->avctx->extradata_size < 8 + 2 *
f) {
223 new_w = 4 * ((
uint8_t *)
s->avctx->extradata)[6 + 2 *
f];
224 new_h = 4 * ((
uint8_t *)
s->avctx->extradata)[7 + 2 *
f];
226 new_w =
rv->orig_width;
227 new_h =
rv->orig_height;
229 if (new_w !=
s->width || new_h !=
s->height || !
s->context_initialized) {
230 AVRational old_aspect =
s->avctx->sample_aspect_ratio;
232 "attempting to change resolution to %dx%d\n", new_w, new_h);
240 if (2 * (int64_t)new_w *
s->height == (int64_t)new_h *
s->width)
242 if ((int64_t)new_w *
s->height == 2 * (int64_t)new_h *
s->width)
264 seq |=
s->time & ~0x7FFF;
265 if (seq -
s->time > 0x4000)
267 if (seq -
s->time < -0x4000)
270 if (seq !=
s->time) {
273 s->pp_time =
s->time -
s->last_non_b_time;
274 s->last_non_b_time =
s->time;
277 s->pb_time =
s->pp_time - (
s->last_non_b_time -
s->time);
281 if (
s->pp_time <=
s->pb_time ||
s->pp_time <=
s->pp_time -
s->pb_time ||
s->pp_time<=0) {
283 "messed up order, possible from seeking? skipping current B-frame\n");
284 #define ERROR_SKIP_FRAME -123
297 s->unrestricted_mv = 1;
299 s->modified_quant = 1;
300 if (!
s->avctx->lowres)
305 "num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n",
306 seq,
s->mb_x,
s->mb_y,
s->pict_type,
s->qscale,
312 return s->mb_width *
s->mb_height - mb_pos;
316 const uint8_t sym_rl[][2],
int sym_rl_elems)
320 unsigned nb_syms = 0, nb_lens = 0;
322 for (
unsigned i = 0;
i < sym_rl_elems;
i++) {
323 unsigned cur_sym = sym_rl[
i][0];
324 for (
unsigned tmp = nb_syms + sym_rl[
i][1]; nb_syms <=
tmp; nb_syms++)
325 syms[nb_syms] = 0xFF & cur_sym--;
328 for (
unsigned i = 0;
i < 15;
i++)
329 for (
unsigned tmp = nb_lens + len_count[
i]; nb_lens <
tmp; nb_lens++)
330 lens[nb_lens] =
i + 2;
367 int major_ver, minor_ver, micro_ver, ret;
396 s->rv10_version = micro_ver ? 3 : 1;
397 s->obmc = micro_ver == 2;
400 if (minor_ver >= 2) {
402 s->avctx->has_b_frames = 1;
439 int buf_size,
int buf_size2,
int whole_size)
443 int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret;
445 active_bits_size = buf_size * 8;
457 if (
s->mb_x >=
s->mb_width ||
458 s->mb_y >=
s->mb_height) {
462 mb_pos =
s->mb_y *
s->mb_width +
s->mb_x;
463 left =
s->mb_width *
s->mb_height - mb_pos;
464 if (mb_count > left) {
469 if (whole_size < s->mb_width *
s->mb_height / 8)
472 if ((
s->mb_x == 0 &&
s->mb_y == 0) || !
s->current_picture_ptr) {
474 if (
s->current_picture_ptr) {
477 s->mb_x =
s->mb_y =
s->resync_mb_x =
s->resync_mb_y = 0;
483 if (
s->current_picture_ptr->f->pict_type !=
s->pict_type) {
490 ff_dlog(avctx,
"qscale=%d\n",
s->qscale);
495 s->first_slice_line = 1;
497 s->first_slice_line = 1;
498 s->resync_mb_x =
s->mb_x;
500 start_mb_x =
s->mb_x;
501 s->resync_mb_y =
s->mb_y;
503 s->y_dc_scale_table =
506 s->y_dc_scale_table =
510 if (
s->modified_quant)
515 s->rv10_first_dc_coded[0] = 0;
516 s->rv10_first_dc_coded[1] = 0;
517 s->rv10_first_dc_coded[2] = 0;
521 s->block_wrap[3] =
s->b8_stride;
523 s->block_wrap[5] =
s->mb_stride;
527 for (
s->mb_num_left = mb_count;
s->mb_num_left > 0;
s->mb_num_left--) {
530 ff_tlog(avctx,
"**mb x=%d y=%d\n",
s->mb_x,
s->mb_y);
549 active_bits_size = buf_size2 * 8;
551 8 * buf_size, active_bits_size);
566 if (++
s->mb_x ==
s->mb_width) {
571 if (
s->mb_x ==
s->resync_mb_x)
572 s->first_slice_line = 0;
580 return active_bits_size;
595 int buf_size = avpkt->
size;
610 slice_count = (*buf++) + 1;
613 if (!slice_count || buf_size <= 8 * slice_count) {
619 slices_hdr = buf + 4;
620 buf += 8 * slice_count;
621 buf_size -= 8 * slice_count;
625 for (
i = 0;
i < slice_count;
i++) {
632 if (
i + 1 == slice_count)
637 if (
i + 2 >= slice_count)
638 size2 = buf_size -
offset;
642 if (
size <= 0 || size2 <= 0 ||
653 if (
s->current_picture_ptr &&
s->mb_y >=
s->mb_height) {
658 if ((ret =
av_frame_ref(pict,
s->current_picture_ptr->f)) < 0)
662 }
else if (
s->last_picture_ptr) {
669 if (
s->last_picture_ptr ||
s->low_delay) {
674 s->current_picture_ptr =
NULL;
static void flush(AVCodecContext *avctx)
#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 av_cold int init(AVCodecContext *avctx)
int ff_init_vlc_from_lengths(VLC *vlc_arg, 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, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
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)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], 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 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.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#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)
int ff_h263_decode_mba(MpegEncContext *s)
void ff_h263_decode_init_vlc(void)
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
const uint8_t ff_aic_dc_scale_table[32]
const uint8_t ff_h263_chroma_qscale_table[32]
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
#define FF_QSCALE_TYPE_MPEG1
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int ff_thread_once(char *control, void(*routine)(void))
static enum AVPixelFormat pix_fmts[]
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
void ff_mpeg_er_frame_start(MpegEncContext *s)
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
void ff_mpv_common_end(MpegEncContext *s)
void ff_mpv_frame_end(MpegEncContext *s)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
void ff_mpeg_flush(AVCodecContext *avctx)
int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
av_cold void ff_mpv_idct_init(MpegEncContext *s)
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
void ff_init_block_index(MpegEncContext *s)
#define SLICE_END
end marker found
#define MV_TYPE_16X16
1 vector for the whole mb
static void ff_update_block_index(MpegEncContext *s)
const uint8_t ff_mpeg1_dc_scale_table[128]
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static const uint16_t table[]
static const uint16_t rv_lum_len_count[15]
static av_cold int rv10_decode_end(AVCodecContext *avctx)
#define RV_GET_MINOR_VER(x)
static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int buf_size2, int whole_size)
static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
static const uint8_t rv_sym_run_len[][2]
static av_cold void rv10_init_static(void)
static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15], const uint8_t sym_rl[][2], int sym_rl_elems)
#define RV_GET_MAJOR_VER(x)
static int rv10_decode_picture_header(MpegEncContext *s)
#define RV_GET_MICRO_VER(x)
static int rv20_decode_picture_header(RVDecContext *rv)
static int rv10_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static const uint16_t rv_chrom_len_count[15]
static av_cold int rv10_decode_init(AVCodecContext *avctx)
int ff_rv_decode_dc(MpegEncContext *s, int n)
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int slice_count
slice count
int frame_number
Frame counter, set by libavcodec.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int coded_width
Bitstream width / height, may be different from width/height e.g.
int * slice_offset
slice offsets in the frame in bytes
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
VLC_TYPE(* table)[2]
code, bits
#define avpriv_request_sample(...)
static const uint8_t offset[127][2]
#define INIT_VLC_STATIC_OVERLONG