30 #define UNCHECKED_BITSTREAM_READER 1
55 #define H263_MBTYPE_B_VLC_BITS 6
56 #define CBPC_B_VLC_BITS 3
80 s->gb.size_in_bits, 1-
s->no_rounding,
82 s->umvplus ?
" UMV" :
"",
83 s->h263_long_vectors ?
" LONG" :
"",
84 s->h263_plus ?
" +" :
"",
85 s->h263_aic ?
" AIC" :
"",
86 s->alt_inter_vlc ?
" AIV" :
"",
87 s->modified_quant ?
" MQ" :
"",
88 s->loop_filter ?
" LOOP" :
"",
89 s->h263_slice_structured ?
" SS" :
"",
90 s->avctx->framerate.num,
s->avctx->framerate.den
110 static volatile int done = 0;
142 for (
i = 0;
i < 6;
i++)
146 s->mb_x = mb_pos %
s->mb_width;
147 s->mb_y = mb_pos /
s->mb_width;
158 unsigned int val, gob_number;
169 left =
FFMIN(left, 32);
171 for(;left>13; left--){
177 if(
s->h263_slice_structured){
194 s->mb_y=
s->gob_index* gob_number;
199 if(
s->mb_y >=
s->mb_height)
245 s->gb=
s->last_resync_gb;
249 for(;left>16+1+5+5; left-=8){
292 if (!
s->h263_long_vectors) {
340 int cbpc,
i, pred_x, pred_y, mx, my;
342 const int xy=
s->mb_x + 1 +
s->mb_y *
s->mb_stride;
343 const int stride=
s->b8_stride*2;
346 s->block_index[
i]+= 2;
348 s->block_index[
i]+= 1;
356 mot_val =
s->current_picture.motion_val[0][
s->block_index[0]];
357 mot_val[0 ]= mot_val[2 ]=
359 mot_val[1 ]= mot_val[3 ]=
373 if(
s->modified_quant){
380 if ((cbpc & 16) == 0) {
394 mot_val[0 ]= mot_val[2 ]=
396 mot_val[1 ]= mot_val[3 ]=
411 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
421 s->block_index[
i]-= 2;
423 s->block_index[
i]-= 1;
430 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
432 if(
s->modified_quant){
450 scan_table =
s->intra_scantable.permutated;
451 if (
s->h263_aic &&
s->mb_intra) {
456 scan_table =
s->intra_v_scantable.permutated;
458 scan_table =
s->intra_h_scantable.permutated;
460 }
else if (
s->mb_intra) {
465 component = (n <= 3 ? 0 : n - 4 + 1);
466 level =
s->last_dc[component];
467 if (
s->rv10_first_dc_coded[component]) {
473 s->last_dc[component] =
level;
475 s->rv10_first_dc_coded[component] = 1;
484 if((
level&0x7F) == 0){
498 if (
s->mb_intra &&
s->h263_aic)
500 s->block_last_index[n] =
i - 1;
570 s->bdsp.clear_block(
block);
581 if (
s->mb_intra &&
s->h263_aic) {
585 s->block_last_index[n] =
i;
599 memcpy(bli,
s->block_last_index,
sizeof(bli));
601 for (
i = 0;
i < 6;
i++) {
607 memcpy(
s->block_last_index, bli,
sizeof(bli));
617 if (pb_frame == 2 &&
c)
629 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
630 #define tab_bias (tab_size / 2)
633 int xy =
s->block_index[
i];
634 uint16_t time_pp =
s->pp_time;
635 uint16_t time_pb =
s->pb_time;
640 s->mv[0][
i][0] =
s->direct_scale_mv[0][p_mx +
tab_bias];
641 s->mv[1][
i][0] =
s->direct_scale_mv[1][p_mx +
tab_bias];
643 s->mv[0][
i][0] = p_mx * time_pb / time_pp;
644 s->mv[1][
i][0] = p_mx * (time_pb - time_pp) / time_pp;
648 s->mv[0][
i][1] =
s->direct_scale_mv[0][p_my +
tab_bias];
649 s->mv[1][
i][1] =
s->direct_scale_mv[1][p_my +
tab_bias];
651 s->mv[0][
i][1] = p_my * time_pb / time_pp;
652 s->mv[1][
i][1] = p_my * (time_pb - time_pp) / time_pp;
661 const int mb_index =
s->mb_x +
s->mb_y *
s->mb_stride;
663 int colocated_mb_type = p->
mb_type[mb_index];
667 p = &
s->last_picture;
668 colocated_mb_type = p->
mb_type[mb_index];
671 if (
IS_8X8(colocated_mb_type)) {
673 for (
i = 0;
i < 4;
i++)
680 s->mv[0][3][0] =
s->mv[0][0][0];
683 s->mv[0][3][1] =
s->mv[0][0][1];
686 s->mv[1][3][0] =
s->mv[1][0][0];
689 s->mv[1][3][1] =
s->mv[1][0][1];
697 int16_t
block[6][64])
699 int cbpc, cbpy,
i, cbp, pred_x, pred_y, mx, my, dquant;
701 const int xy=
s->mb_x +
s->mb_y *
s->mb_stride;
702 int cbpb = 0, pb_mv_count = 0;
712 s->block_last_index[
i] = -1;
718 s->mb_skipped = !(
s->obmc |
s->loop_filter);
728 s->bdsp.clear_blocks(
s->block[0]);
731 s->mb_intra = ((cbpc & 4) != 0);
732 if (
s->mb_intra)
goto intra;
743 if(
s->alt_inter_vlc==0 || (cbpc & 3)!=3)
746 cbp = (cbpc & 3) | (cbpy << 2);
752 if ((cbpc & 16) == 0) {
775 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
797 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
805 const int stride=
s->b8_stride;
806 int16_t *mot_val0 =
s->current_picture.motion_val[0][2 * (
s->mb_x +
s->mb_y *
stride)];
807 int16_t *mot_val1 =
s->current_picture.motion_val[1][2 * (
s->mb_x +
s->mb_y *
stride)];
811 mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*
stride]= mot_val0[2+2*
stride]=
812 mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*
stride]= mot_val0[3+2*
stride]=
813 mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*
stride]= mot_val1[2+2*
stride]=
814 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*
stride]= mot_val1[3+2*
stride]= 0;
828 s->bdsp.clear_blocks(
s->block[0]);
842 if(
s->alt_inter_vlc==0 || (cbpc & 3)!=3)
845 cbp = (cbpc & 3) | (cbpy << 2);
881 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
886 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*
stride]= mot_val[2+2*
stride]= mx;
887 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*
stride]= mot_val[3+2*
stride]= my;
908 if (
s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
913 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*
stride]= mot_val[2+2*
stride]= mx;
914 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*
stride]= mot_val[3+2*
stride]= my;
918 s->current_picture.mb_type[xy] = mb_type;
928 s->bdsp.clear_blocks(
s->block[0]);
951 cbp = (cbpc & 3) | (cbpy << 2);
956 pb_mv_count += !!
s->pb_frame;
959 while(pb_mv_count--){
965 for (
i = 0;
i < 6;
i++) {
973 if(
s->obmc && !
s->mb_intra){
1005 if (
show_bits(&
s->gb, 2) == 2 &&
s->avctx->frame_number == 0) {
1012 startcode = ((startcode << 8) |
get_bits(&
s->gb, 8)) & 0x003FFFFF;
1014 if(startcode == 0x20)
1018 if (startcode != 0x20) {
1025 i -= (
i - (
s->picture_number & 0xFF) + 128) & ~0xFF;
1027 s->picture_number= (
s->picture_number&~0xFF) +
i;
1066 s->unrestricted_mv =
s->h263_long_vectors ||
s->obmc;
1069 s->chroma_qscale=
s->qscale =
get_bits(&
s->gb, 5);
1074 s->avctx->sample_aspect_ratio= (
AVRational){12,11};
1075 s->avctx->framerate = (
AVRational){ 30000, 1001 };
1096 s->unrestricted_mv =
s->umvplus ||
s->obmc ||
s->loop_filter;
1097 if(
s->avctx->lowres)
1109 if(
s->modified_quant)
1115 }
else if (ufep != 0) {
1122 switch(
s->pict_type){
1140 ff_dlog(
s->avctx,
"aspect: %d\n",
s->aspect_ratio_info);
1156 s->avctx->sample_aspect_ratio.num=
get_bits(&
s->gb, 8);
1157 s->avctx->sample_aspect_ratio.den=
get_bits(&
s->gb, 8);
1164 s->avctx->sample_aspect_ratio= (
AVRational){12,11};
1166 s->avctx->sample_aspect_ratio.den <<=
s->ehc_mode;
1174 s->avctx->framerate.num = 1800000;
1175 s->avctx->framerate.den = 1000 +
get_bits1(&
s->gb);
1176 s->avctx->framerate.den *=
get_bits(&
s->gb, 7);
1177 if(
s->avctx->framerate.den == 0){
1181 gcd=
av_gcd(
s->avctx->framerate.den,
s->avctx->framerate.num);
1182 s->avctx->framerate.den /= gcd;
1183 s->avctx->framerate.num /= gcd;
1185 s->avctx->framerate = (
AVRational){ 30000, 1001 };
1198 if(
s->h263_slice_structured){
1225 s->mb_width = (
s->width + 15) / 16;
1226 s->mb_height = (
s->height + 15) / 16;
1227 s->mb_num =
s->mb_width *
s->mb_height;
1237 s->time =
s->picture_number;
1238 s->pp_time =
s->time -
s->last_non_b_time;
1239 s->last_non_b_time =
s->time;
1241 s->time =
s->picture_number;
1242 s->pb_time =
s->pp_time - (
s->last_non_b_time -
s->time);
1243 if (
s->pp_time <=
s->pb_time ||
1244 s->pp_time <=
s->pp_time -
s->pb_time ||
1256 if(
s->h263_slice_structured){
1273 s->y_dc_scale_table=
1276 s->y_dc_scale_table=
1285 for(
i=0;
i<13;
i++){
static double val(void *priv, double ch)
static const char *const format[]
Macro definitions for various function/variable attributes.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Libavcodec external API header.
#define AV_EF_BITSTREAM
detect bitstream specification deviations
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define FF_DEBUG_PICT_INFO
#define CONFIG_MPEG4_DECODER
#define CONFIG_FLV_DECODER
#define CONFIG_RV10_DECODER
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
#define SKIP_CACHE(name, gb, num)
static int get_sbits(GetBitContext *s, int n)
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 int check_marker(void *logctx, GetBitContext *s, const char *msg)
static const uint8_t * align_get_bits(GetBitContext *s)
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.
void ff_h263_pred_acdc(MpegEncContext *s, int16_t *block, int n)
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
#define FF_ASPECT_EXTENDED
#define INTRA_MCBPC_VLC_BITS
#define INTER_MCBPC_VLC_BITS
av_cold void ff_h263_init_rl_inter(void)
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]
static VLC h263_mbtype_b_vlc
int ff_h263_decode_mba(MpegEncContext *s)
static void preview_obmc(MpegEncContext *s)
read the next MVs for OBMC.
VLC ff_h263_intra_MCBPC_vlc
static int set_direct_mv(MpegEncContext *s)
int ff_h263_resync(MpegEncContext *s)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
void ff_h263_show_pict_info(MpegEncContext *s)
Print picture info if FF_DEBUG_PICT_INFO is set.
int ff_h263_decode_motion(MpegEncContext *s, int pred, int f_code)
static int h263p_decode_umotion(MpegEncContext *s, int pred)
static void set_one_direct_mv(MpegEncContext *s, Picture *p, int i)
VLC ff_h263_inter_MCBPC_vlc
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
#define H263_MBTYPE_B_VLC_BITS
static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
static const int h263_mb_type_b_map[15]
static int h263_skip_b_part(MpegEncContext *s, int cbp)
av_cold void ff_h263_decode_init_vlc(void)
static int h263_decode_gob_header(MpegEncContext *s)
Decode the group of blocks header or slice header.
static void h263_decode_dquant(MpegEncContext *s)
static int h263_decode_block(MpegEncContext *s, int16_t *block, int n, int coded)
int ff_h263_decode_picture_header(MpegEncContext *s)
static const int8_t mv[256][2]
common internal API header
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(Mpeg4DecContext *ctx)
Decode the next video packet.
#define USES_LIST(a, list)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
#define SLICE_END
end marker found
#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
const uint8_t ff_mpeg1_dc_scale_table[128]
#define INIT_VLC_RL(rl, static_size)
#define INIT_FIRST_VLC_RL(rl, static_size)
int ff_rv_decode_dc(MpegEncContext *s, int n)
static const float pred[4]
static int shift(int a, int b)
enum AVPictureType pict_type
Picture type of the frame.
Rational number (pair of numerator and denominator).
int16_t(*[2] motion_val)[2]
uint32_t * mb_type
types and macros are defined in mpegutils.h
RL_VLC_ELEM * rl_vlc[32]
decoding only
VLC_TYPE(* table)[2]
code, bits
#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 uint32_t a, const uint32_t b)
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)