mirror of https://github.com/FFmpeg/FFmpeg.git
Originally committed as revision 21079 to svn://svn.ffmpeg.org/ffmpeg/trunkrelease/0.6
parent
84f0aba18d
commit
ca334dd14b
14 changed files with 4332 additions and 4103 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,178 @@ |
||||
/*
|
||||
* H263 internal header |
||||
* |
||||
* This file is part of FFmpeg. |
||||
* |
||||
* FFmpeg is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU Lesser General Public |
||||
* License as published by the Free Software Foundation; either |
||||
* version 2.1 of the License, or (at your option) any later version. |
||||
* |
||||
* FFmpeg is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
* Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public |
||||
* License along with FFmpeg; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
#ifndef AVCODEC_H263_H |
||||
#define AVCODEC_H263_H |
||||
|
||||
// The defines below define the number of bits that are read at once for
|
||||
// reading vlc values. Changing these may improve speed and data cache needs
|
||||
// be aware though that decreasing them may need the number of stages that is
|
||||
// passed to get_vlc* to be increased.
|
||||
#define INTRA_MCBPC_VLC_BITS 6 |
||||
#define INTER_MCBPC_VLC_BITS 7 |
||||
#define CBPY_VLC_BITS 6 |
||||
#define TEX_VLC_BITS 9 |
||||
|
||||
extern const AVRational ff_h263_pixel_aspect[16]; |
||||
extern const uint8_t cbpy_tab[16][2]; |
||||
|
||||
extern const uint8_t mvtab[33][2]; |
||||
|
||||
extern const uint8_t intra_MCBPC_code[9]; |
||||
extern const uint8_t intra_MCBPC_bits[9]; |
||||
|
||||
extern const uint8_t inter_MCBPC_code[28]; |
||||
extern const uint8_t inter_MCBPC_bits[28]; |
||||
|
||||
extern VLC intra_MCBPC_vlc; |
||||
extern VLC inter_MCBPC_vlc; |
||||
extern VLC cbpy_vlc; |
||||
|
||||
extern RLTable rl_inter; |
||||
|
||||
int h263_decode_motion(MpegEncContext * s, int pred, int f_code); |
||||
av_const int ff_h263_aspect_to_info(AVRational aspect); |
||||
|
||||
static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){ |
||||
int l, bit_size, code; |
||||
|
||||
if (val == 0) { |
||||
return mvtab[0][1]; |
||||
} else { |
||||
bit_size = f_code - 1; |
||||
/* modulo encoding */ |
||||
l= INT_BIT - 6 - bit_size; |
||||
val = (val<<l)>>l; |
||||
val--; |
||||
code = (val >> bit_size) + 1; |
||||
|
||||
return mvtab[code][1] + 1 + bit_size; |
||||
} |
||||
} |
||||
|
||||
static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){ |
||||
if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ |
||||
skip_put_bits(&s->pb, |
||||
h263_get_motion_length(s, x, f_code) |
||||
+h263_get_motion_length(s, y, f_code)); |
||||
}else{ |
||||
ff_h263_encode_motion(s, x, f_code); |
||||
ff_h263_encode_motion(s, y, f_code); |
||||
} |
||||
} |
||||
|
||||
static inline int get_p_cbp(MpegEncContext * s, |
||||
DCTELEM block[6][64], |
||||
int motion_x, int motion_y){ |
||||
int cbp, i; |
||||
|
||||
if(s->flags & CODEC_FLAG_CBP_RD){ |
||||
int best_cbpy_score= INT_MAX; |
||||
int best_cbpc_score= INT_MAX; |
||||
int cbpc = (-1), cbpy= (-1); |
||||
const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0); |
||||
const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); |
||||
|
||||
for(i=0; i<4; i++){ |
||||
int score= inter_MCBPC_bits[i + offset] * lambda; |
||||
if(i&1) score += s->coded_score[5]; |
||||
if(i&2) score += s->coded_score[4]; |
||||
|
||||
if(score < best_cbpc_score){ |
||||
best_cbpc_score= score; |
||||
cbpc= i; |
||||
} |
||||
} |
||||
|
||||
for(i=0; i<16; i++){ |
||||
int score= cbpy_tab[i ^ 0xF][1] * lambda; |
||||
if(i&1) score += s->coded_score[3]; |
||||
if(i&2) score += s->coded_score[2]; |
||||
if(i&4) score += s->coded_score[1]; |
||||
if(i&8) score += s->coded_score[0]; |
||||
|
||||
if(score < best_cbpy_score){ |
||||
best_cbpy_score= score; |
||||
cbpy= i; |
||||
} |
||||
} |
||||
cbp= cbpc + 4*cbpy; |
||||
if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){ |
||||
if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0) |
||||
cbp= 0; |
||||
} |
||||
|
||||
for (i = 0; i < 6; i++) { |
||||
if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ |
||||
s->block_last_index[i]= -1; |
||||
s->dsp.clear_block(s->block[i]); |
||||
} |
||||
} |
||||
}else{ |
||||
cbp= 0; |
||||
for (i = 0; i < 6; i++) { |
||||
if (s->block_last_index[i] >= 0) |
||||
cbp |= 1 << (5 - i); |
||||
} |
||||
} |
||||
return cbp; |
||||
} |
||||
|
||||
static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], |
||||
int motion_x, int motion_y, int mb_type){ |
||||
int cbp=0, i; |
||||
|
||||
if(s->flags & CODEC_FLAG_CBP_RD){ |
||||
int score=0; |
||||
const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); |
||||
|
||||
for(i=0; i<6; i++){ |
||||
if(s->coded_score[i] < 0){ |
||||
score += s->coded_score[i]; |
||||
cbp |= 1 << (5 - i); |
||||
} |
||||
} |
||||
|
||||
if(cbp){ |
||||
int zero_score= -6; |
||||
if ((motion_x | motion_y | s->dquant | mb_type) == 0){ |
||||
zero_score-= 4; //2*MV + mb_type + cbp bit
|
||||
} |
||||
|
||||
zero_score*= lambda; |
||||
if(zero_score <= score){ |
||||
cbp=0; |
||||
} |
||||
} |
||||
|
||||
for (i = 0; i < 6; i++) { |
||||
if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ |
||||
s->block_last_index[i]= -1; |
||||
s->dsp.clear_block(s->block[i]); |
||||
} |
||||
} |
||||
}else{ |
||||
for (i = 0; i < 6; i++) { |
||||
if (s->block_last_index[i] >= 0) |
||||
cbp |= 1 << (5 - i); |
||||
} |
||||
} |
||||
return cbp; |
||||
} |
||||
#endif |
@ -0,0 +1,72 @@ |
||||
/*
|
||||
* MPEG4 decoder / encoder common code. |
||||
* Copyright (c) 2000,2001 Fabrice Bellard |
||||
* Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at> |
||||
* |
||||
* This file is part of FFmpeg. |
||||
* |
||||
* FFmpeg is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU Lesser General Public |
||||
* License as published by the Free Software Foundation; either |
||||
* version 2.1 of the License, or (at your option) any later version. |
||||
* |
||||
* FFmpeg is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
* Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public |
||||
* License along with FFmpeg; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
#include "mpegvideo.h" |
||||
#include "mpeg4video.h" |
||||
#include "mpeg4data.h" |
||||
|
||||
uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3]; |
||||
|
||||
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){ |
||||
switch(s->pict_type){ |
||||
case FF_I_TYPE: |
||||
return 16; |
||||
case FF_P_TYPE: |
||||
case FF_S_TYPE: |
||||
return s->f_code+15; |
||||
case FF_B_TYPE: |
||||
return FFMAX3(s->f_code, s->b_code, 2) + 15; |
||||
default: |
||||
return -1; |
||||
} |
||||
} |
||||
|
||||
void ff_mpeg4_clean_buffers(MpegEncContext *s) |
||||
{ |
||||
int c_wrap, c_xy, l_wrap, l_xy; |
||||
|
||||
l_wrap= s->b8_stride; |
||||
l_xy= (2*s->mb_y-1)*l_wrap + s->mb_x*2 - 1; |
||||
c_wrap= s->mb_stride; |
||||
c_xy= (s->mb_y-1)*c_wrap + s->mb_x - 1; |
||||
|
||||
#if 0 |
||||
/* clean DC */ |
||||
memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*2+1); |
||||
memsetw(s->dc_val[1] + c_xy, 1024, c_wrap+1); |
||||
memsetw(s->dc_val[2] + c_xy, 1024, c_wrap+1); |
||||
#endif |
||||
|
||||
/* clean AC */ |
||||
memset(s->ac_val[0] + l_xy, 0, (l_wrap*2+1)*16*sizeof(int16_t)); |
||||
memset(s->ac_val[1] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t)); |
||||
memset(s->ac_val[2] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t)); |
||||
|
||||
/* clean MV */ |
||||
// we can't clear the MVs as they might be needed by a b frame
|
||||
// memset(s->motion_val + l_xy, 0, (l_wrap*2+1)*2*sizeof(int16_t));
|
||||
// memset(s->motion_val, 0, 2*sizeof(int16_t)*(2 + s->mb_width*2)*(2 + s->mb_height*2));
|
||||
s->last_mv[0][0][0]= |
||||
s->last_mv[0][0][1]= |
||||
s->last_mv[1][0][0]= |
||||
s->last_mv[1][0][1]= 0; |
||||
} |
@ -0,0 +1,197 @@ |
||||
/*
|
||||
* MPEG4 encoder/decoder internal header. |
||||
* Copyright (c) 2000,2001 Fabrice Bellard |
||||
* Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at> |
||||
* |
||||
* This file is part of FFmpeg. |
||||
* |
||||
* FFmpeg is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU Lesser General Public |
||||
* License as published by the Free Software Foundation; either |
||||
* version 2.1 of the License, or (at your option) any later version. |
||||
* |
||||
* FFmpeg is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
* Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public |
||||
* License along with FFmpeg; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
#ifndef AVCODEC_MPEG4VIDEO_H |
||||
#define AVCODEC_MPEG4VIDEO_H |
||||
|
||||
// shapes
|
||||
#define RECT_SHAPE 0 |
||||
#define BIN_SHAPE 1 |
||||
#define BIN_ONLY_SHAPE 2 |
||||
#define GRAY_SHAPE 3 |
||||
|
||||
#define SIMPLE_VO_TYPE 1 |
||||
#define CORE_VO_TYPE 3 |
||||
#define MAIN_VO_TYPE 4 |
||||
#define NBIT_VO_TYPE 5 |
||||
#define ARTS_VO_TYPE 10 |
||||
#define ACE_VO_TYPE 12 |
||||
#define ADV_SIMPLE_VO_TYPE 17 |
||||
|
||||
// aspect_ratio_info
|
||||
#define EXTENDED_PAR 15 |
||||
|
||||
//vol_sprite_usage / sprite_enable
|
||||
#define STATIC_SPRITE 1 |
||||
#define GMC_SPRITE 2 |
||||
|
||||
#define MOTION_MARKER 0x1F001 |
||||
#define DC_MARKER 0x6B001 |
||||
|
||||
#define VOS_STARTCODE 0x1B0 |
||||
#define USER_DATA_STARTCODE 0x1B2 |
||||
#define GOP_STARTCODE 0x1B3 |
||||
#define VISUAL_OBJ_STARTCODE 0x1B5 |
||||
#define VOP_STARTCODE 0x1B6 |
||||
|
||||
/* dc encoding for mpeg4 */ |
||||
extern const uint8_t DCtab_lum[13][2]; |
||||
extern const uint8_t DCtab_chrom[13][2]; |
||||
|
||||
extern const uint16_t intra_vlc[103][2]; |
||||
extern const int8_t intra_level[102]; |
||||
extern const int8_t intra_run[102]; |
||||
extern RLTable rl_intra; |
||||
|
||||
/* Note this is identical to the intra rvlc except that it is reordered. */ |
||||
extern const uint16_t inter_rvlc[170][2]; |
||||
extern const int8_t inter_rvlc_run[169]; |
||||
extern const int8_t inter_rvlc_level[169]; |
||||
extern RLTable rvlc_rl_inter; |
||||
|
||||
extern const uint16_t intra_rvlc[170][2]; |
||||
extern const int8_t intra_rvlc_run[169]; |
||||
extern const int8_t intra_rvlc_level[169]; |
||||
extern RLTable rvlc_rl_intra; |
||||
|
||||
extern const uint16_t sprite_trajectory_tab[15][2]; |
||||
extern const uint8_t mb_type_b_tab[4][2]; |
||||
extern const AVRational pixel_aspect[16]; |
||||
|
||||
/* these matrixes will be permuted for the idct */ |
||||
extern const int16_t ff_mpeg4_default_intra_matrix[64]; |
||||
extern const int16_t ff_mpeg4_default_non_intra_matrix[64]; |
||||
|
||||
extern const uint8_t ff_mpeg4_y_dc_scale_table[32]; |
||||
extern const uint8_t ff_mpeg4_c_dc_scale_table[32]; |
||||
extern const uint16_t ff_mpeg4_resync_prefix[8]; |
||||
|
||||
extern const uint8_t mpeg4_dc_threshold[8]; |
||||
|
||||
void mpeg4_encode_mb(MpegEncContext *s, |
||||
DCTELEM block[6][64], |
||||
int motion_x, int motion_y); |
||||
void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, |
||||
int dir); |
||||
void ff_set_mpeg4_time(MpegEncContext * s); |
||||
void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); |
||||
|
||||
int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb); |
||||
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s); |
||||
void ff_mpeg4_clean_buffers(MpegEncContext *s); |
||||
void ff_mpeg4_stuffing(PutBitContext * pbc); |
||||
void ff_mpeg4_init_partitions(MpegEncContext *s); |
||||
void ff_mpeg4_merge_partitions(MpegEncContext *s); |
||||
void ff_clean_mpeg4_qscales(MpegEncContext *s); |
||||
int ff_mpeg4_decode_partitions(MpegEncContext *s); |
||||
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s); |
||||
int mpeg4_decode_video_packet_header(MpegEncContext *s); |
||||
|
||||
extern uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3]; |
||||
|
||||
|
||||
#if 0 //3IV1 is quite rare and it slows things down a tiny bit
|
||||
#define IS_3IV1 s->codec_tag == AV_RL32("3IV1") |
||||
#else |
||||
#define IS_3IV1 0 |
||||
#endif |
||||
|
||||
|
||||
/**
|
||||
* predicts the dc. |
||||
* encoding quantized level -> quantized diff |
||||
* decoding quantized diff -> quantized level |
||||
* @param n block index (0-3 are luma, 4-5 are chroma) |
||||
* @param dir_ptr pointer to an integer where the prediction direction will be stored |
||||
*/ |
||||
static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding) |
||||
{ |
||||
int a, b, c, wrap, pred, scale, ret; |
||||
int16_t *dc_val; |
||||
|
||||
/* find prediction */ |
||||
if (n < 4) { |
||||
scale = s->y_dc_scale; |
||||
} else { |
||||
scale = s->c_dc_scale; |
||||
} |
||||
if(IS_3IV1) |
||||
scale= 8; |
||||
|
||||
wrap= s->block_wrap[n]; |
||||
dc_val = s->dc_val[0] + s->block_index[n]; |
||||
|
||||
/* B C
|
||||
* A X |
||||
*/ |
||||
a = dc_val[ - 1]; |
||||
b = dc_val[ - 1 - wrap]; |
||||
c = dc_val[ - wrap]; |
||||
|
||||
/* outside slice handling (we can't do that by memset as we need the dc for error resilience) */ |
||||
if(s->first_slice_line && n!=3){ |
||||
if(n!=2) b=c= 1024; |
||||
if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024; |
||||
} |
||||
if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){ |
||||
if(n==0 || n==4 || n==5) |
||||
b=1024; |
||||
} |
||||
|
||||
if (abs(a - b) < abs(b - c)) { |
||||
pred = c; |
||||
*dir_ptr = 1; /* top */ |
||||
} else { |
||||
pred = a; |
||||
*dir_ptr = 0; /* left */ |
||||
} |
||||
/* we assume pred is positive */ |
||||
pred = FASTDIV((pred + (scale >> 1)), scale); |
||||
|
||||
if(encoding){ |
||||
ret = level - pred; |
||||
}else{ |
||||
level += pred; |
||||
ret= level; |
||||
if(s->error_recognition>=3){ |
||||
if(level<0){ |
||||
av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y); |
||||
return -1; |
||||
} |
||||
if(level*scale > 2048 + scale){ |
||||
av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y); |
||||
return -1; |
||||
} |
||||
} |
||||
} |
||||
level *=scale; |
||||
if(level&(~2047)){ |
||||
if(level<0) |
||||
level=0; |
||||
else if(!(s->workaround_bugs&FF_BUG_DC_CLIP)) |
||||
level=2047; |
||||
} |
||||
dc_val[0]= level; |
||||
|
||||
return ret; |
||||
} |
||||
#endif |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue