30#define UNCHECKED_BITSTREAM_READER 1
32#include "config_components.h"
59#define H263_MBTYPE_B_VLC_BITS 6
60#define CBPC_B_VLC_BITS 3
85 h->gb.size_in_bits, 1-
h->c.no_rounding,
86 h->c.obmc ?
" AP" :
"",
87 h->umvplus ?
" UMV" :
"",
88 h->h263_long_vectors ?
" LONG" :
"",
89 h263_plus ?
" +" :
"",
90 h->c.h263_aic ?
" AIC" :
"",
91 h->alt_inter_vlc ?
" AIV" :
"",
92 h->modified_quant ?
" MQ" :
"",
93 h->loop_filter ?
" LOOP" :
"",
94 h->h263_slice_structured ?
" SS" :
"",
95 h->c.avctx->framerate.num,
h->c.avctx->framerate.den);
146 for (
i = 0;
i < 6;
i++)
150 h->c.mb_x = mb_pos %
h->c.mb_width;
151 h->c.mb_y = mb_pos /
h->c.mb_width;
162 unsigned int val, gob_number;
182 if (
h->h263_slice_structured) {
188 if (
h->c.mb_num > 1583)
199 h->c.mb_y =
h->gob_index* gob_number;
204 if (
h->c.mb_y >=
h->c.mb_height)
243#if CONFIG_MPEG4_DECODER
253 h->gb =
h->last_resync_gb;
262#if CONFIG_MPEG4_DECODER
302 if (!
h->h263_long_vectors) {
351 int cbpc,
i, pred_x, pred_y,
mx,
my;
353 const int xy =
h->c.mb_x + 1 +
h->c.mb_y *
h->c.mb_stride;
354 const int stride =
h->c.b8_stride * 2;
357 h->c.block_index[
i] += 2;
359 h->c.block_index[
i] += 1;
367 mot_val =
h->c.cur_pic.motion_val[0][
h->c.block_index[0]];
368 mot_val[0 ]= mot_val[2 ]=
370 mot_val[1 ]= mot_val[3 ]=
387 if ((cbpc & 16) == 0) {
401 mot_val[0 ]= mot_val[2 ]=
403 mot_val[1 ]= mot_val[3 ]=
418 if (
h->umvplus && (
mx - pred_x) == 1 && (
my - pred_y) == 1)
428 h->c.block_index[
i] -= 2;
430 h->c.block_index[
i] -= 1;
438 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
441 if (
h->modified_quant) {
447 qscale =
h->c.qscale + quant_tab[
get_bits(&
h->gb, 2)];
454 const int xy =
s->block_index[n];
455 int16_t *
const dc_val =
s->dc_val + xy;
456 int16_t *
const ac_val = (
s->ac_val + xy)[0];
474 if (
s->first_slice_line && n != 3) {
476 if (n != 1 &&
s->mb_x ==
s->resync_mb_x)
a= 1024;
481 if (
s->h263_aic_dir) {
484 int16_t *
const ac_val2 = ac_val - 16;
485 for (
int i = 1;
i < 8;
i++) {
486 block[
s->idsp.idct_permutation[
i << 3]] += ac_val2[
i];
493 int16_t *
const ac_val2 = ac_val - 16 *
wrap;
494 for (
int i = 1;
i < 8;
i++) {
495 block[
s->idsp.idct_permutation[
i]] += ac_val2[
i + 8];
502 if (
a != 1024 &&
c != 1024)
522 for (
int i = 1;
i < 8;
i++)
523 ac_val[
i] =
block[
s->idsp.idct_permutation[
i << 3]];
525 for (
int i = 1;
i < 8;
i++)
526 ac_val[8 +
i] =
block[
s->idsp.idct_permutation[
i]];
534 const uint8_t *scan_table;
537 scan_table =
h->c.intra_scantable.permutated;
538 if (
h->c.h263_aic &&
h->c.mb_intra) {
544 if (
h->c.h263_aic_dir)
545 scan_table =
h->permutated_intra_v_scantable;
547 scan_table =
h->permutated_intra_h_scantable;
549 }
else if (
h->c.mb_intra) {
553 int component = (n <= 3 ? 0 : n - 4 + 1);
554 level =
h->last_dc[component];
555 if (
h->rv10_first_dc_coded[component]) {
561 h->last_dc[component] =
level;
563 h->rv10_first_dc_coded[component] = 1;
572 if((
level&0x7F) == 0){
587 h->c.block_last_index[n] =
i - 1;
601 h->c.mb_x,
h->c.mb_y);
605 if (CONFIG_FLV_DECODER &&
h->flv) {
658 h->c.bdsp.clear_block(
block);
662 h->c.mb_x,
h->c.mb_y,
h->c.mb_intra);
669 if (
h->c.mb_intra &&
h->c.h263_aic) {
673 h->c.block_last_index[n] =
i;
687 memcpy(bli,
h->c.block_last_index,
sizeof(bli));
689 for (
i = 0;
i < 6;
i++) {
695 memcpy(
h->c.block_last_index, bli,
sizeof(bli));
705 if (pb_frame == 2 &&
c)
717#define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
718#define tab_bias (tab_size / 2)
721 int xy =
s->block_index[
i];
722 uint16_t time_pp =
s->pp_time;
723 uint16_t time_pb =
s->pb_time;
726 p_mx = p->motion_val[0][xy][0];
728 s->mv[0][
i][0] =
s->direct_scale_mv[0][p_mx +
tab_bias];
729 s->mv[1][
i][0] =
s->direct_scale_mv[1][p_mx +
tab_bias];
731 s->mv[0][
i][0] = p_mx * time_pb / time_pp;
732 s->mv[1][
i][0] = p_mx * (time_pb - time_pp) / time_pp;
734 p_my = p->motion_val[0][xy][1];
736 s->mv[0][
i][1] =
s->direct_scale_mv[0][p_my +
tab_bias];
737 s->mv[1][
i][1] =
s->direct_scale_mv[1][p_my +
tab_bias];
739 s->mv[0][
i][1] = p_my * time_pb / time_pp;
740 s->mv[1][
i][1] = p_my * (time_pb - time_pp) / time_pp;
749 const int mb_index =
s->mb_x +
s->mb_y *
s->mb_stride;
751 int colocated_mb_type = p->mb_type[mb_index];
756 colocated_mb_type = p->mb_type[mb_index];
759 if (
IS_8X8(colocated_mb_type)) {
761 for (
i = 0;
i < 4;
i++)
768 s->mv[0][3][0] =
s->mv[0][0][0];
771 s->mv[0][3][1] =
s->mv[0][0][1];
774 s->mv[1][3][0] =
s->mv[1][0][0];
777 s->mv[1][3][1] =
s->mv[1][0][1];
786 int cbpc, cbpy,
i, cbp, pred_x, pred_y,
mx,
my, dquant;
788 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
789 int cbpb = 0, pb_mv_count = 0;
799 h->c.block_last_index[
i] = -1;
803 h->c.mv[0][0][0] = 0;
804 h->c.mv[0][0][1] = 0;
805 h->c.mb_skipped = !(
h->c.obmc |
h->loop_filter);
811 h->c.mb_x,
h->c.mb_y);
816 h->c.bdsp.clear_blocks(
h->block[0]);
819 h->c.mb_intra = ((cbpc & 4) != 0);
829 h->c.mb_x,
h->c.mb_y);
833 if (!
h->alt_inter_vlc|| (cbpc & 3)!=3)
836 cbp = (cbpc & 3) | (cbpy << 2);
842 if ((cbpc & 16) == 0) {
862 h->c.mv[0][0][0] =
mx;
863 h->c.mv[0][0][1] =
my;
865 if (
h->umvplus && (
mx - pred_x) == 1 && (
my - pred_y) == 1)
885 h->c.mv[0][
i][0] =
mx;
886 h->c.mv[0][
i][1] =
my;
887 if (
h->umvplus && (
mx - pred_x) == 1 && (
my - pred_y) == 1)
895 const int stride =
h->c.b8_stride;
896 int16_t *mot_val0 =
h->c.cur_pic.motion_val[0][2 * (
h->c.mb_x +
h->c.mb_y *
stride)];
897 int16_t *mot_val1 =
h->c.cur_pic.motion_val[1][2 * (
h->c.mb_x +
h->c.mb_y *
stride)];
901 mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*
stride]= mot_val0[2+2*
stride]=
902 mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*
stride]= mot_val0[3+2*
stride]=
903 mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*
stride]= mot_val1[2+2*
stride]=
904 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*
stride]= mot_val1[3+2*
stride]= 0;
911 h->c.mb_x,
h->c.mb_y);
918 h->c.bdsp.clear_blocks(
h->block[0]);
929 h->c.mb_x,
h->c.mb_y);
933 if (!
h->alt_inter_vlc || (cbpc & 3)!=3)
936 cbp = (cbpc & 3) | (cbpy << 2);
972 if (
h->umvplus && (
mx - pred_x) == 1 && (
my - pred_y) == 1)
975 h->c.mv[0][0][0] =
mx;
976 h->c.mv[0][0][1] =
my;
977 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*
stride]= mot_val[2+2*
stride]=
mx;
978 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*
stride]= mot_val[3+2*
stride]=
my;
999 if (
h->umvplus && (
mx - pred_x) == 1 && (
my - pred_y) == 1)
1002 h->c.mv[1][0][0] =
mx;
1003 h->c.mv[1][0][1] =
my;
1004 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*
stride]= mot_val[2+2*
stride]=
mx;
1005 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*
stride]= mot_val[3+2*
stride]=
my;
1009 h->c.cur_pic.mb_type[xy] = mb_type;
1015 h->c.mb_x,
h->c.mb_y);
1020 h->c.bdsp.clear_blocks(
h->block[0]);
1026 if (
h->c.h263_aic) {
1041 h->c.mb_x,
h->c.mb_y);
1044 cbp = (cbpc & 3) | (cbpy << 2);
1049 pb_mv_count += !!
h->pb_frame;
1052 while(pb_mv_count--){
1058 for (
i = 0;
i < 6;
i++) {
1066 if (
h->c.obmc && !
h->c.mb_intra) {
1068 h->c.mb_x + 1 <
h->c.mb_width &&
h->mb_num_left != 1)
1099 if (
show_bits(&
h->gb, 2) == 2 &&
h->c.avctx->frame_num == 0) {
1103 uint32_t startcode =
get_bits(&
h->gb, 22-8);
1106 startcode = ((startcode << 8) |
get_bits(&
h->gb, 8)) & 0x003FFFFF;
1108 if(startcode == 0x20)
1112 if (startcode != 0x20) {
1119 i -= (
i - (
h->picture_number & 0xFF) + 128) & ~0xFF;
1121 h->picture_number = (
h->picture_number&~0xFF) +
i;
1162 h->c.chroma_qscale =
h->c.qscale =
get_bits(&
h->gb, 5);
1167 h->c.avctx->sample_aspect_ratio= (
AVRational){12,11};
1168 h->c.avctx->framerate = (
AVRational){ 30000, 1001 };
1189 if (
h->c.avctx->lowres)
1201 if (
h->modified_quant)
1207 }
else if (ufep != 0) {
1214 switch (
h->c.pict_type) {
1231 int aspect_ratio_info =
get_bits(&
h->gb, 4);
1232 ff_dlog(
h->c.avctx,
"aspect: %d\n", aspect_ratio_info);
1248 h->c.avctx->sample_aspect_ratio.num =
get_bits(&
h->gb, 8);
1249 h->c.avctx->sample_aspect_ratio.den =
get_bits(&
h->gb, 8);
1256 h->c.avctx->sample_aspect_ratio = (
AVRational){12,11};
1258 h->c.avctx->sample_aspect_ratio.den <<=
h->ehc_mode;
1264 if (
h->custom_pcf) {
1265 h->c.avctx->framerate.num = 1800000;
1266 h->c.avctx->framerate.den = 1000 +
get_bits1(&
h->gb);
1267 h->c.avctx->framerate.den *=
get_bits(&
h->gb, 7);
1268 if (
h->c.avctx->framerate.den == 0) {
1272 int gcd =
av_gcd(
h->c.avctx->framerate.den,
h->c.avctx->framerate.num);
1273 h->c.avctx->framerate.den /= gcd;
1274 h->c.avctx->framerate.num /= gcd;
1276 h->c.avctx->framerate = (
AVRational){ 30000, 1001 };
1288 if (
h->h263_slice_structured) {
1316 h->c.mb_width = (
h->c.width + 15U) / 16;
1317 h->c.mb_height = (
h->c.height + 15U) / 16;
1318 h->c.mb_num =
h->c.mb_width *
h->c.mb_height;
1330 h->c.time =
h->picture_number;
1331 h->c.pp_time =
h->c.time -
h->c.last_non_b_time;
1332 h->c.last_non_b_time =
h->c.time;
1334 h->c.time =
h->picture_number;
1335 h->c.pb_time =
h->c.pp_time - (
h->c.last_non_b_time -
h->c.time);
1336 if (
h->c.pp_time <=
h->c.pb_time ||
1337 h->c.pp_time <=
h->c.pp_time -
h->c.pb_time ||
1338 h->c.pp_time <= 0) {
1349 if (
h->h263_slice_structured) {
1364 if (
h->c.h263_aic) {
1365 h->c.y_dc_scale_table =
1368 h->c.y_dc_scale_table =
1378 for(
i=0;
i<13;
i++){
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
static double val(void *priv, double ch)
static const char *const format[]
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
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 AV_EF_BITSTREAM
detect bitstream specification deviations
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
#define SKIP_CACHE(name, gb, num)
static int get_sbits(GetBitContext *s, int n)
#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 const uint8_t * align_get_bits(GetBitContext *s)
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 unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define AV_CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
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...
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
#define FF_ASPECT_EXTENDED
#define H263_GOB_HEIGHT(h)
const uint8_t ff_mba_length[7]
const uint8_t ff_h263_mbtype_b_tab[15][2]
const uint8_t ff_aic_dc_scale_table[32]
const uint8_t ff_cbpc_b_tab[4][2]
const AVRational ff_h263_pixel_aspect[16]
const uint8_t ff_h263_intra_MCBPC_bits[9]
const uint8_t ff_h263_chroma_qscale_table[32]
const uint8_t ff_h263_inter_MCBPC_code[28]
const uint8_t ff_mvtab[33][2]
const uint8_t ff_h263_inter_MCBPC_bits[28]
const uint8_t ff_modified_quant_tab[2][32]
const uint16_t ff_mba_max[6]
const uint8_t ff_h263_intra_MCBPC_code[9]
const uint8_t ff_h263_cbpy_tab[16][2]
const uint16_t ff_h263_format[8][2]
VLCElem ff_h263_inter_MCBPC_vlc[]
VLCElem ff_h263_cbpy_vlc[]
#define INTRA_MCBPC_VLC_BITS
VLCElem ff_h263_intra_MCBPC_vlc[]
#define INTER_MCBPC_VLC_BITS
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static VLCElem cbpc_b_vlc[8]
static void set_one_direct_mv(MpegEncContext *s, const MPVPicture *p, int i)
static av_cold void h263_decode_init_vlc(void)
static void h263_decode_dquant(H263DecContext *const h)
static int set_direct_mv(MpegEncContext *s)
int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
static int h263p_decode_umotion(H263DecContext *const h, int pred)
static const int16_t h263_mb_type_b_map[15]
static int h263_decode_block(H263DecContext *const h, int16_t block[64], int n, int coded)
int ff_h263_decode_picture_header(H263DecContext *const h)
static VLCElem h263_mbtype_b_vlc[80]
#define H263_MBTYPE_B_VLC_BITS
int ff_h263_decode_mb(H263DecContext *const h)
static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
static int h263_skip_b_part(H263DecContext *const h, int cbp)
static void preview_obmc(H263DecContext *const h)
read the next MVs for OBMC.
av_cold void ff_h263_decode_init_vlc(void)
void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
Print picture info if FF_DEBUG_PICT_INFO is set.
int ff_h263_decode_mba(H263DecContext *const h)
static int h263_decode_gob_header(H263DecContext *const h)
Decode the group of blocks header or slice header.
static void h263_pred_acdc(MpegEncContext *s, int16_t *block, int n)
int ff_h263_resync(H263DecContext *const h)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
static const int8_t mv[256][2]
static int shift(int a, int b)
#define SLICE_END
end marker found
Macro definitions for various function/variable attributes.
common internal API header
static int ff_thread_once(char *control, void(*routine)(void))
static av_const int sign_extend(int val, unsigned bits)
#define LOCAL_ALIGNED_32(t, v,...)
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
Decode the next video packet.
#define MB_TYPE_BACKWARD_MV
#define HAS_BACKWARD_MV(a)
#define HAS_FORWARD_MV(a)
#define MB_TYPE_FORWARD_MV
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (MPEG-4)
#define MV_TYPE_16X16
1 vector for the whole mb
static const uint8_t *const ff_mpeg1_dc_scale_table
mpegvideo decoder header.
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
static void FUNC pred_dc(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride, int log2_size, int c_idx)
#define VLC_INIT_RL(rl, static_size)
#define INIT_FIRST_VLC_RL(rl, static_size)
int ff_rv_decode_dc(H263DecContext *const h, int n)
static const float pred[4]
Rational number (pair of numerator and denominator).
RL_VLC_ELEM * rl_vlc[32]
decoding only
#define avpriv_request_sample(...)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
#define VLC_INIT_STATIC_SPARSE_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, symbols, symbols_wrap, symbols_size, flags)