38 #define H261_MBA_VLC_BITS 8
39 #define H261_MTYPE_VLC_BITS 6
40 #define H261_MV_VLC_BITS 7
41 #define H261_CBP_VLC_BITS 9
42 #define TCOEFF_VLC_BITS 9
43 #define MBA_STUFFING 33
44 #define MBA_STARTCODE 34
81 h->gob_start_code_skipped = 0;
97 if (!
h->gob_start_code_skipped) {
107 h->gob_start_code_skipped = 0;
113 if (
s->mb_height == 18) {
114 if ((
h->gob_number <= 0) || (
h->gob_number > 12))
117 if ((
h->gob_number != 1) && (
h->gob_number != 3) &&
118 (
h->gob_number != 5))
126 if (
s->qscale == 0) {
151 if (
h->gob_start_code_skipped) {
162 s->gb =
s->last_resync_gb;
166 for (; left > 15 + 1 + 4 + 5; left -= 8) {
194 for (
i = mba1;
i < mba2;
i++) {
197 s->mb_x = ((
h->gob_number - 1) % 2) * 11 +
i % 11;
198 s->mb_y = ((
h->gob_number - 1) / 2) * 3 +
i / 11;
199 xy =
s->mb_x +
s->mb_y *
s->mb_stride;
203 for (j = 0; j < 6; j++)
204 s->block_last_index[j] = -1;
214 if (
s->current_picture.motion_val[0]) {
215 int b_stride = 2*
s->mb_width + 1;
216 int b_xy = 2 *
s->mb_x + (2 *
s->mb_y) * b_stride;
217 s->current_picture.motion_val[0][b_xy][0] =
s->mv[0][0][0];
218 s->current_picture.motion_val[0][b_xy][1] =
s->mv[0][0][1];
228 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
239 mv_diff =
mvmap[mv_diff];
270 scan_table =
s->intra_scantable.permutated;
275 if ((
level & 0x7F) == 0) {
302 s->block_last_index[n] =
i - 1;
326 }
else if (
level == 0) {
345 s->block_last_index[n] =
i;
363 h->gob_start_code_skipped = 1;
368 if (
h->mba_diff < 0) {
377 h->current_mba +=
h->mba_diff;
382 s->mb_x = ((
h->gob_number - 1) % 2) * 11 + ((
h->current_mba - 1) % 11);
383 s->mb_y = ((
h->gob_number - 1) / 2) * 3 + ((
h->current_mba - 1) / 11);
384 xy =
s->mb_x +
s->mb_y *
s->mb_stride;
414 if ((
h->current_mba == 1) || (
h->current_mba == 12) ||
415 (
h->current_mba == 23) || (
h->mba_diff != 1)) {
440 s->mv[0][0][0] =
h->current_mv_x * 2;
441 s->mv[0][0][1] =
h->current_mv_y * 2;
443 if (
s->current_picture.motion_val[0]) {
444 int b_stride = 2*
s->mb_width + 1;
445 int b_xy = 2 *
s->mb_x + (2 *
s->mb_y) * b_stride;
446 s->current_picture.motion_val[0][b_xy][0] =
s->mv[0][0][0];
447 s->current_picture.motion_val[0][b_xy][1] =
s->mv[0][0][1];
453 s->bdsp.clear_blocks(
s->block[0]);
454 for (
i = 0;
i < 6;
i++) {
460 for (
i = 0;
i < 6;
i++)
461 s->block_last_index[
i] = -1;
477 uint32_t startcode = 0;
480 startcode = ((startcode << 1) |
get_bits(&
s->gb, 1)) & 0x000FFFFF;
482 if (startcode == 0x10)
486 if (startcode != 0x10) {
493 if (
i < (
s->picture_number & 31))
495 s->picture_number = (
s->picture_number & ~31) +
i;
497 s->avctx->framerate = (
AVRational) { 30000, 1001 };
519 s->mb_num =
s->mb_width *
s->mb_height;
554 s->mb_x +
s->mb_y *
s->mb_stride);
559 h->current_mba -
h->mba_diff,
574 if (
pos + 10 > buf_size)
584 int buf_size = avpkt->
size;
591 ff_dlog(avctx,
"bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
593 h->gob_start_code_skipped = 0;
598 if (!
s->context_initialized)
614 if (!
s->context_initialized) {
626 s->current_picture.f->pict_type =
s->pict_type;
643 while (
h->gob_number < (
s->mb_height == 18 ? 12 : 5)) {
650 av_assert0(
s->current_picture.f->pict_type ==
s->current_picture_ptr->f->pict_type);
651 av_assert0(
s->current_picture.f->pict_type ==
s->pict_type);
653 if ((ret =
av_frame_ref(pict,
s->current_picture_ptr->f)) < 0)
static double val(void *priv, double ch)
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define AV_EF_BITSTREAM
detect bitstream specification deviations
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
static av_cold int init(AVCodecContext *avctx)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define SKIP_CACHE(name, gb, num)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define CLOSE_READER(name, gb)
static int get_bits_left(GetBitContext *gb)
#define SHOW_UBITS(name, gb, num)
static unsigned int get_bits1(GetBitContext *s)
#define SHOW_SBITS(name, gb, num)
#define OPEN_READER(name, gb)
static void skip_bits(GetBitContext *s, int n)
static int skip_1stop_8data_bits(GetBitContext *gb)
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
#define UPDATE_CACHE(name, gb)
static int get_bits_count(const GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define SKIP_COUNTER(name, gb, num)
static const uint8_t * align_get_bits(GetBitContext *s)
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_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_NONREF
discard all non reference
#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_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
const int ff_h261_mtype_map[10]
RLTable ff_h261_rl_tcoeff
const uint8_t ff_h261_mv_tab[17][2]
const uint8_t ff_h261_mtype_bits[10]
const uint8_t ff_h261_mtype_code[10]
const uint8_t ff_h261_mba_code[35]
const uint8_t ff_h261_cbp_tab[63][2]
const uint8_t ff_h261_mba_bits[35]
static VLC h261_mtype_vlc
static int h261_decode_gob(H261Context *h)
static int h261_decode_gob_header(H261Context *h)
Decode the group of blocks header or slice header.
static int get_consumed_bytes(MpegEncContext *s, int buf_size)
returns the number of bytes consumed for building the current frame
static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
Decode skipped macroblocks.
#define H261_MTYPE_VLC_BITS
static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
Decode a macroblock.
#define H261_MBA_VLC_BITS
static av_cold int h261_decode_end(AVCodecContext *avctx)
static int h261_resync(H261Context *h)
Decode the group of blocks / video packet header.
static av_cold int h261_decode_init(AVCodecContext *avctx)
#define H261_CBP_VLC_BITS
static int h261_decode_picture_header(H261Context *h)
Decode the H.261 picture header.
static av_cold void h261_decode_init_static(void)
static const int mvmap[17]
static int h261_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int decode_mv_component(GetBitContext *gb, int v)
static int h261_decode_mb(H261Context *h)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
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.
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))
#define check(x, y, S, v)
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.
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)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define INIT_FIRST_VLC_RL(rl, static_size)
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int frame_number
Frame counter, set by libavcodec.
int coded_width
Bitstream width / height, may be different from width/height e.g.
enum AVDiscard skip_frame
Skip decoding for selected frames.
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).
RL_VLC_ELEM * rl_vlc[32]
decoding only
VLC_TYPE(* table)[2]
code, bits
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)