Commit 7bc9090a authored by Michael Niedermayer's avatar Michael Niedermayer

simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now...

simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
more direct use of the new mb_type stuff instead of codec specific stuff
runtime mb_type debug output h264/h263 variants/mpeg1/2/4
error concealment /resilience for mpeg1/2
various minor optimizations

Originally committed as revision 1746 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 84876d36
......@@ -999,6 +999,15 @@ if((y)<(x)){\
#define free please_use_av_free
#define realloc please_use_av_realloc
#define CHECKED_ALLOCZ(p, size)\
{\
p= av_mallocz(size);\
if(p==NULL){\
perror("malloc");\
goto fail;\
}\
}
#endif /* HAVE_AV_CONFIG_H */
#endif /* COMMON_H */
This diff is collapsed.
This diff is collapsed.
......@@ -209,7 +209,7 @@ static int decode_slice(MpegEncContext *s){
MPV_decode_mb(s, s->block);
if(ret<0){
const int xy= s->mb_x + s->mb_y*s->mb_width;
const int xy= s->mb_x + s->mb_y*s->mb_stride;
if(ret==SLICE_END){
//printf("%d %d %d %06X\n", s->mb_x, s->mb_y, s->gb.size*8 - get_bits_count(&s->gb), show_bits(&s->gb, 24));
ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
......@@ -644,12 +644,6 @@ retry:
ff_er_frame_start(s);
/* decode each macroblock */
s->block_wrap[0]=
s->block_wrap[1]=
s->block_wrap[2]=
s->block_wrap[3]= s->mb_width*2 + 2;
s->block_wrap[4]=
s->block_wrap[5]= s->mb_width + 2;
s->mb_x=0;
s->mb_y=0;
......@@ -708,8 +702,8 @@ retry:
for(mb_y=0; mb_y<s->mb_height; mb_y++){
int mb_x;
for(mb_x=0; mb_x<s->mb_width; mb_x++){
const int mb_index= mb_x + mb_y*s->mb_width;
if(s->co_located_type_table[mb_index] == MV_TYPE_8X8){
const int mb_index= mb_x + mb_y*s->mb_stride;
if(IS_8X8(s->current_picture.mb_type[mb_index])){
int i;
for(i=0; i<4; i++){
int sx= mb_x*16 + 4 + 8*(i&1);
......@@ -732,25 +726,14 @@ retry:
}
}
if(s->pict_type==B_TYPE || s->low_delay){
*pict= *(AVFrame*)&s->current_picture;
ff_print_debug_info(s, s->current_picture_ptr);
} else {
*pict= *(AVFrame*)&s->last_picture;
ff_print_debug_info(s, s->last_picture_ptr);
}
if(avctx->debug&FF_DEBUG_QP){
int8_t *qtab= pict->qscale_table;
int x,y;
for(y=0; y<s->mb_height; y++){
for(x=0; x<s->mb_width; x++){
printf("%2d ", qtab[x + y*s->mb_width]);
}
printf("\n");
}
printf("\n");
}
/* Return the Picture timestamp as the frame number */
/* we substract 1 because it is added on utils.c */
......
......@@ -149,8 +149,6 @@ typedef struct H264Context{
uint8_t *rbsp_buffer;
int rbsp_buffer_size;
int mb_stride; ///< stride of some mb tables
int chroma_qp; //QPc
int prev_mb_skiped; //FIXME remove (IMHO not used)
......@@ -355,7 +353,7 @@ static inline void fill_rectangle(void *p, int w, int h, int stride, uint32_t va
static inline void fill_caches(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
int topleft_xy, top_xy, topright_xy, left_xy[2];
int topleft_type, top_type, topright_type, left_type[2];
int left_block[4];
......@@ -366,9 +364,9 @@ static inline void fill_caches(H264Context *h, int mb_type){
if(h->sps.mb_aff){
//FIXME
}else{
topleft_xy = mb_xy-1 - h->mb_stride;
top_xy = mb_xy - h->mb_stride;
topright_xy= mb_xy+1 - h->mb_stride;
topleft_xy = mb_xy-1 - s->mb_stride;
top_xy = mb_xy - s->mb_stride;
topright_xy= mb_xy+1 - s->mb_stride;
left_xy[0] = mb_xy-1;
left_xy[1] = mb_xy-1;
left_block[0]= 0;
......@@ -602,7 +600,7 @@ static inline void fill_caches(H264Context *h, int mb_type){
static inline void write_back_intra_pred_mode(H264Context *h){
MpegEncContext * const s = &h->s;
const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
h->intra4x4_pred_mode[mb_xy][0]= h->intra4x4_pred_mode_cache[7+8*1];
h->intra4x4_pred_mode[mb_xy][1]= h->intra4x4_pred_mode_cache[7+8*2];
......@@ -693,7 +691,7 @@ static inline int pred_intra_mode(H264Context *h, int n){
static inline void write_back_non_zero_count(H264Context *h){
MpegEncContext * const s = &h->s;
const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
h->non_zero_count[mb_xy][0]= h->non_zero_count_cache[4+8*4];
h->non_zero_count[mb_xy][1]= h->non_zero_count_cache[5+8*4];
......@@ -896,7 +894,7 @@ static inline void pred_pskip_motion(H264Context * const h, int * const mx, int
static inline void write_back_motion(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
const int b8_xy= 2*s->mb_x + 2*s->mb_y*h->b8_stride;
int list;
......@@ -1952,7 +1950,7 @@ static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t
qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),
qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg)){
MpegEncContext * const s = &h->s;
const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
const int mb_type= s->current_picture.mb_type[mb_xy];
assert(IS_INTER(mb_type));
......@@ -2122,7 +2120,7 @@ static void free_tables(H264Context *h){
*/
static int alloc_tables(H264Context *h){
MpegEncContext * const s = &h->s;
const int big_mb_num= h->mb_stride * (s->mb_height+1);
const int big_mb_num= s->mb_stride * (s->mb_height+1);
int x,y;
CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t))
......@@ -2130,13 +2128,13 @@ static int alloc_tables(H264Context *h){
CHECKED_ALLOCZ(h->slice_table_base , big_mb_num * sizeof(uint8_t))
memset(h->slice_table_base, -1, big_mb_num * sizeof(uint8_t));
h->slice_table= h->slice_table_base + h->mb_stride + 1;
h->slice_table= h->slice_table_base + s->mb_stride + 1;
CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint16_t));
CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint16_t));
for(y=0; y<s->mb_height; y++){
for(x=0; x<s->mb_width; x++){
const int mb_xy= x + y*h->mb_stride;
const int mb_xy= x + y*s->mb_stride;
const int b_xy = 4*x + 4*y*h->b_stride;
const int b8_xy= 2*x + 2*y*h->b8_stride;
......@@ -2211,7 +2209,7 @@ static void hl_decode_mb(H264Context *h){
MpegEncContext * const s = &h->s;
const int mb_x= s->mb_x;
const int mb_y= s->mb_y;
const int mb_xy= mb_x + mb_y*h->mb_stride;
const int mb_xy= mb_x + mb_y*s->mb_stride;
const int mb_type= s->current_picture.mb_type[mb_xy];
uint8_t *dest_y, *dest_cb, *dest_cr;
int linesize, uvlinesize /*dct_offset*/;
......@@ -2839,7 +2837,6 @@ static int decode_slice_header(H264Context *h){
s->mb_width= h->sps.mb_width;
s->mb_height= h->sps.mb_height;
h->mb_stride= s->mb_width + 1;
h->b_stride= s->mb_width*4;
h->b8_stride= s->mb_width*2;
......@@ -3171,7 +3168,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in
*/
static int decode_mb(H264Context *h){
MpegEncContext * const s = &h->s;
const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
int mb_type, partition_count, cbp;
memset(h->mb, 0, sizeof(int16_t)*24*16); //FIXME avoid if allready clear (move after skip handlong?
......@@ -4164,6 +4161,7 @@ static int decode_frame(AVCodecContext *avctx,
}
*pict= *(AVFrame*)&s->current_picture; //FIXME
ff_print_debug_info(s, s->current_picture_ptr);
assert(pict->data[0]);
//printf("out %d\n", (int)pict->data[0]);
#if 0 //?
......@@ -4183,12 +4181,12 @@ static int decode_frame(AVCodecContext *avctx,
#if 0
static inline void fill_mb_avail(H264Context *h){
MpegEncContext * const s = &h->s;
const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
if(s->mb_y){
h->mb_avail[0]= s->mb_x && h->slice_table[mb_xy - h->mb_stride - 1] == h->slice_num;
h->mb_avail[1]= h->slice_table[mb_xy - h->mb_stride ] == h->slice_num;
h->mb_avail[2]= s->mb_x+1 < s->mb_width && h->slice_table[mb_xy - h->mb_stride + 1] == h->slice_num;
h->mb_avail[0]= s->mb_x && h->slice_table[mb_xy - s->mb_stride - 1] == h->slice_num;
h->mb_avail[1]= h->slice_table[mb_xy - s->mb_stride ] == h->slice_num;
h->mb_avail[2]= s->mb_x+1 < s->mb_width && h->slice_table[mb_xy - s->mb_stride + 1] == h->slice_num;
}else{
h->mb_avail[0]=
h->mb_avail[1]=
......
......@@ -306,6 +306,9 @@ static const uint8_t chroma_dc_scan[4]={
(0+1*2)*16, (1+1*2)*16, //FIXME
};
#define MB_TYPE_REF0 0x40000000
#define IS_REF0(a) ((a)&MB_TYPE_REF0)
typedef struct IMbInfo{
uint16_t type;
uint8_t pred_mode;
......@@ -362,7 +365,7 @@ static const PMbInfo p_sub_mb_type_info[4]={
};
static const PMbInfo b_mb_type_info[23]={
{MB_TYPE_DIRECT , 1, },
{MB_TYPE_DIRECT2 , 1, },
{MB_TYPE_16x16|MB_TYPE_P0L0 , 1, },
{MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, },
{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, },
......@@ -388,7 +391,7 @@ static const PMbInfo b_mb_type_info[23]={
};
static const PMbInfo b_sub_mb_type_info[13]={
{MB_TYPE_DIRECT , 1, },
{MB_TYPE_DIRECT2 , 1, },
{MB_TYPE_16x16|MB_TYPE_P0L0 , 1, },
{MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, },
{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, },
......
......@@ -775,7 +775,7 @@ static inline int sad_hpel_motion_search(MpegEncContext * s,
static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
{
const int xy= s->mb_x + 1 + (s->mb_y + 1)*(s->mb_width + 2);
const int xy= s->mb_x + s->mb_y*s->mb_stride;
s->p_mv_table[xy][0] = mx;
s->p_mv_table[xy][1] = my;
......@@ -1076,10 +1076,10 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
vard = (s->dsp.sse[0](NULL, pix, ppix, s->linesize)+128)>>8;
//printf("%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout);
pic->mb_var [s->mb_width * mb_y + mb_x] = varc;
pic->mc_mb_var[s->mb_width * mb_y + mb_x] = vard;
pic->mb_mean [s->mb_width * mb_y + mb_x] = (sum+128)>>8;
// pic->mb_cmp_score[s->mb_width * mb_y + mb_x] = dmin;
pic->mb_var [s->mb_stride * mb_y + mb_x] = varc;
pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = vard;
pic->mb_mean [s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
// pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin;
pic->mb_var_sum += varc;
pic->mc_mb_var_sum += vard;
//printf("E%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout);
......@@ -1129,7 +1129,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
dmin=dmin4;
}
}
pic->mb_cmp_score[s->mb_width * mb_y + mb_x] = dmin;
pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin;
set_p_mv_tables(s, mx, my, mb_type!=MB_TYPE_INTER4V);
if (vard <= 64 || vard < varc) {
......@@ -1139,7 +1139,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
}
}
s->mb_type[mb_y*s->mb_width + mb_x]= mb_type;
s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type;
}
int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
......@@ -1152,8 +1152,7 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
int P[10][2];
const int shift= 1+s->quarter_sample;
uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
const int mv_stride= s->mb_width + 2;
const int xy= mb_x + 1 + (mb_y + 1)*mv_stride;
const int xy= mb_x + mb_y*s->mb_stride;
assert(s->quarter_sample==0 || s->quarter_sample==1);
......@@ -1178,10 +1177,10 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME
} else {
P_TOP[0] = s->p_mv_table[xy + mv_stride ][0];
P_TOP[1] = s->p_mv_table[xy + mv_stride ][1];
P_TOPRIGHT[0] = s->p_mv_table[xy + mv_stride - 1][0];
P_TOPRIGHT[1] = s->p_mv_table[xy + mv_stride - 1][1];
P_TOP[0] = s->p_mv_table[xy + s->mb_stride ][0];
P_TOP[1] = s->p_mv_table[xy + s->mb_stride ][1];
P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];
P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];
if(P_TOP[1] < (rel_ymin<<shift)) P_TOP[1] = (rel_ymin<<shift);
if(P_TOPRIGHT[0] > (rel_xmax<<shift)) P_TOPRIGHT[0]= (rel_xmax<<shift);
if(P_TOPRIGHT[1] < (rel_ymin<<shift)) P_TOPRIGHT[1]= (rel_ymin<<shift);
......@@ -1210,8 +1209,8 @@ static int ff_estimate_motion_b(MpegEncContext * s,
int pred_x=0, pred_y=0;
int P[10][2];
const int shift= 1+s->quarter_sample;
const int mot_stride = s->mb_width + 2;
const int mot_xy = (mb_y + 1)*mot_stride + mb_x + 1;
const int mot_stride = s->mb_stride;
const int mot_xy = mb_y*mot_stride + mb_x;
uint8_t * const ref_picture= picture->data[0];
uint8_t * const mv_penalty= s->me.mv_penalty[f_code] + MAX_MV;
int mv_scale;
......@@ -1370,8 +1369,8 @@ static inline int check_bidir_mv(MpegEncContext * s,
static inline int bidir_refine(MpegEncContext * s,
int mb_x, int mb_y)
{
const int mot_stride = s->mb_width + 2;
const int xy = (mb_y + 1)*mot_stride + mb_x + 1;
const int mot_stride = s->mb_stride;
const int xy = mb_y *mot_stride + mb_x;
int fbmin;
int pred_fx= s->b_bidir_forw_mv_table[xy-1][0];
int pred_fy= s->b_bidir_forw_mv_table[xy-1][1];
......@@ -1397,8 +1396,8 @@ static inline int direct_search(MpegEncContext * s,
int mb_x, int mb_y)
{
int P[10][2];
const int mot_stride = s->mb_width + 2;
const int mot_xy = (mb_y + 1)*mot_stride + mb_x + 1;
const int mot_stride = s->mb_stride;
const int mot_xy = mb_y*mot_stride + mb_x;
const int shift= 1+s->quarter_sample;
int dmin, i;
const int time_pp= s->pp_time;
......@@ -1410,7 +1409,7 @@ static inline int direct_search(MpegEncContext * s,
ymin= xmin=(-32)>>shift;
ymax= xmax= 31>>shift;
if(s->co_located_type_table[mb_x + mb_y*s->mb_width]==CO_LOCATED_TYPE_4MV){
if(IS_8X8(s->next_picture.mb_type[mot_xy])){
s->mv_type= MV_TYPE_8X8;
}else{
s->mv_type= MV_TYPE_16X16;
......@@ -1526,7 +1525,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
score= ((unsigned)(score*score + 128*256))>>16;
s->current_picture.mc_mb_var_sum += score;
s->current_picture.mc_mb_var[mb_y*s->mb_width + mb_x] = score; //FIXME use SSE
s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
}
if(s->flags&CODEC_FLAG_HQ){
......@@ -1534,7 +1533,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
if(dmin>256*256*16) type&= ~MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB
}
s->mb_type[mb_y*s->mb_width + mb_x]= type;
s->mb_type[mb_y*s->mb_stride + mb_x]= type;
}
/* find best f_code for ME which do unlimited searches */
......@@ -1551,20 +1550,18 @@ int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type)
for(y=0; y<s->mb_height; y++){
int x;
int xy= (y+1)* (s->mb_width+2) + 1;
i= y*s->mb_width;
int xy= y*s->mb_stride;
for(x=0; x<s->mb_width; x++){
if(s->mb_type[i] & type){
if(s->mb_type[xy] & type){
int fcode= FFMAX(fcode_tab[mv_table[xy][0] + MAX_MV],
fcode_tab[mv_table[xy][1] + MAX_MV]);
int j;
for(j=0; j<fcode && j<8; j++){
if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[i] < s->current_picture.mb_var[i])
if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy])
score[j]-= 170;
}
}
i++;
xy++;
}
}
......@@ -1602,23 +1599,18 @@ void ff_fix_long_p_mvs(MpegEncContext * s)
/* clip / convert to intra 16x16 type MVs */
for(y=0; y<s->mb_height; y++){
int x;
int xy= (y+1)* (s->mb_width+2)+1;
int i= y*s->mb_width;
int xy= y*s->mb_stride;
for(x=0; x<s->mb_width; x++){
if(s->mb_type[i]&MB_TYPE_INTER){
if(s->mb_type[xy]&MB_TYPE_INTER){
if( s->p_mv_table[xy][0] >=range || s->p_mv_table[xy][0] <-range
|| s->p_mv_table[xy][1] >=range || s->p_mv_table[xy][1] <-range){
s->mb_type[i] &= ~MB_TYPE_INTER;
s->mb_type[i] |= MB_TYPE_INTRA;
s->mb_type[xy] &= ~MB_TYPE_INTER;
s->mb_type[xy] |= MB_TYPE_INTRA;
s->p_mv_table[xy][0] = 0;
s->p_mv_table[xy][1] = 0;
//clip++;
}
//else
// noclip++;
}
xy++;
i++;
}
}
//printf("%d no:%d %d//\n", clip, noclip, f_code);
......@@ -1628,7 +1620,7 @@ void ff_fix_long_p_mvs(MpegEncContext * s)
/* clip / convert to intra 8x8 type MVs */
for(y=0; y<s->mb_height; y++){
int xy= (y*2 + 1)*wrap + 1;
int i= y*s->mb_width;
int i= y*s->mb_stride;
int x;
for(x=0; x<s->mb_width; x++){
......@@ -1665,10 +1657,9 @@ void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, i
/* clip / convert to intra 16x16 type MVs */
for(y=0; y<s->mb_height; y++){
int x;
int xy= (y+1)* (s->mb_width+2)+1;
int i= y*s->mb_width;
int xy= y*s->mb_stride;
for(x=0; x<s->mb_width; x++){
if (s->mb_type[i] & type){ // RAL: "type" test added...
if (s->mb_type[xy] & type){ // RAL: "type" test added...
if( mv_table[xy][0] >=range || mv_table[xy][0] <-range
|| mv_table[xy][1] >=range || mv_table[xy][1] <-range){
......@@ -1682,7 +1673,6 @@ void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, i
}
}
xy++;
i++;
}
}
}
......@@ -897,8 +897,8 @@ static int RENAME(epzs_motion_search)(MpegEncContext * s, int block,
int map_generation;
const int penalty_factor= s->me.penalty_factor;
const int size=0;
const int ref_mv_stride= s->mb_width+2;
const int ref_mv_xy= 1 + s->mb_x + (s->mb_y + 1)*ref_mv_stride;
const int ref_mv_stride= s->mb_stride;
const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride;
me_cmp_func cmp, chroma_cmp;
LOAD_COMMON(s->mb_x*16, s->mb_y*16);
......@@ -1009,8 +1009,8 @@ static int RENAME(epzs_motion_search4)(MpegEncContext * s, int block,
int map_generation;
const int penalty_factor= s->me.penalty_factor;
const int size=1;
const int ref_mv_stride= s->mb_width+2;
const int ref_mv_xy= 1 + s->mb_x + (s->mb_y + 1)*ref_mv_stride;
const int ref_mv_stride= s->mb_stride;
const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
me_cmp_func cmp, chroma_cmp;
LOAD_COMMON((s->mb_x*2 + (block&1))*8, (s->mb_y*2 + (block>>1))*8);
......
This diff is collapsed.
......@@ -289,80 +289,57 @@ static const uint8_t mbPatTable[63][2] = {
{0xc, 6}
};
#define MB_INTRA 0x01
#define MB_PAT 0x02
#define MB_BACK 0x04
#define MB_FOR 0x08
#define MB_QUANT 0x10
static const uint8_t table_mb_ptype[32][2] = {
{ 0, 0 }, // 0x00
#define MB_TYPE_PAT 0x40000000
#define MB_TYPE_ZERO_MV 0x20000000
#define IS_ZERO_MV(a) ((a)&MB_TYPE_ZERO_MV)
#define IS_PAT(a) ((a)&MB_TYPE_PAT)
static const uint8_t table_mb_ptype[7][2] = {
{ 3, 5 }, // 0x01 MB_INTRA
{ 1, 2 }, // 0x02 MB_PAT
{ 0, 0 }, // 0x03
{ 0, 0 }, // 0x04
{ 0, 0 }, // 0x05
{ 0, 0 }, // 0x06
{ 0, 0 }, // 0x07
{ 1, 3 }, // 0x08 MB_FOR
{ 0, 0 }, // 0x09
{ 1, 1 }, // 0x0A MB_FOR|MB_PAT
{ 0, 0 }, // 0x0B
{ 0, 0 }, // 0x0C
{ 0, 0 }, // 0x0D
{ 0, 0 }, // 0x0E
{ 0, 0 }, // 0x0F
{ 0, 0 }, // 0x10
{ 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
{ 1, 5 }, // 0x12 MB_QUANT|MB_PAT
{ 0, 0 }, // 0x13
{ 0, 0 }, // 0x14
{ 0, 0 }, // 0x15
{ 0, 0 }, // 0x16
{ 0, 0 }, // 0x17
{ 0, 0 }, // 0x18
{ 0, 0 }, // 0x19
{ 2, 5 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
{ 0, 0 }, // 0x1B
{ 0, 0 }, // 0x1C
{ 0, 0 }, // 0x1D
{ 0, 0 }, // 0x1E
{ 0, 0 }, // 0x1F
};
static const uint8_t table_mb_btype[32][2] = {
{ 0, 0 }, // 0x00
static const uint32_t ptype2mb_type[7] = {
MB_TYPE_INTRA,
MB_TYPE_L0 | MB_TYPE_PAT | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
MB_TYPE_L0,
MB_TYPE_L0 | MB_TYPE_PAT,
MB_TYPE_QUANT | MB_TYPE_INTRA,
MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_PAT | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_PAT,
};
static const uint8_t table_mb_btype[11][2] = {
{ 3, 5 }, // 0x01 MB_INTRA
{ 0, 0 }, // 0x02
{ 0, 0 }, // 0x03
{ 2, 3 }, // 0x04 MB_BACK
{ 0, 0 }, // 0x05
{ 3, 3 }, // 0x06 MB_BACK|MB_PAT
{ 0, 0 }, // 0x07
{ 2, 4 }, // 0x08 MB_FOR
{ 0, 0 }, // 0x09
{ 3, 4 }, // 0x0A MB_FOR|MB_PAT
{ 0, 0 }, // 0x0B
{ 2, 2 }, // 0x0C MB_FOR|MB_BACK
{ 0, 0 }, // 0x0D
{ 3, 2 }, // 0x0E MB_FOR|MB_BACK|MB_PAT
{ 0, 0 }, // 0x0F
{ 0, 0 }, // 0x10
{ 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
{ 0, 0 }, // 0x12
{ 0, 0 }, // 0x13
{ 0, 0 }, // 0x14
{ 0, 0 }, // 0x15
{ 2, 6 }, // 0x16 MB_QUANT|MB_BACK|MB_PAT
{ 0, 0 }, // 0x17
{ 0, 0 }, // 0x18
{ 0, 0 }, // 0x19
{ 3, 6 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
{ 0, 0 }, // 0x1B
{ 0, 0 }, // 0x1C
{ 0, 0 }, // 0x1D
{ 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT
{ 0, 0 }, // 0x1F
};
static const uint32_t btype2mb_type[11] = {
MB_TYPE_INTRA,
MB_TYPE_L1,
MB_TYPE_L1 | MB_TYPE_PAT,
MB_TYPE_L0,
MB_TYPE_L0 | MB_TYPE_PAT,
MB_TYPE_L0L1,
MB_TYPE_L0L1 | MB_TYPE_PAT,
MB_TYPE_QUANT | MB_TYPE_INTRA,
MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_PAT,
MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_PAT,
MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_PAT,
};
static const uint8_t mbMotionVectorTable[17][2] = {
......
......@@ -27,10 +27,12 @@
#define MOTION_MARKER 0x1F001
#define DC_MARKER 0x6B001
#define MB_TYPE_B_DIRECT 0
#define MB_TYPE_B_BIDIR 1
#define MB_TYPE_B_BACKW 2
#define MB_TYPE_B_FORW 3
const static int mb_type_b_map[4]= {
MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
MB_TYPE_L0L1 | MB_TYPE_16x16,
MB_TYPE_L1 | MB_TYPE_16x16,
MB_TYPE_L0 | MB_TYPE_16x16,
};
#define VOS_STARTCODE 0x1B0
#define USER_DATA_STARTCODE 0x1B2
......
This diff is collapsed.
......@@ -137,31 +137,40 @@ typedef struct Picture{
int16_t (*motion_val[2])[2];
int8_t *ref_index[2];
uint16_t *mb_type_base;
uint16_t *mb_type; ///< mb_type_base + mb_width + 2
uint32_t *mb_type_base;
uint32_t *mb_type; ///< mb_type_base + mb_width + 2, note: only used for decoding currently
#define MB_TYPE_INTRA4x4 0x0001
#define MB_TYPE_INTRA16x16 0x0002
#define MB_TYPE_INTRA_PCM 0x0004
#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific
#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific
#define MB_TYPE_16x16 0x0008
#define MB_TYPE_16x8 0x0010
#define MB_TYPE_8x16 0x0020
#define MB_TYPE_8x8 0x0040
#define MB_TYPE_INTERLACED 0x0080
#define MB_TYPE_DIRECT2 0x0100 //FIXME
#define MB_TYPE_REF0 0x0200
#define MB_TYPE_GMC2 0x0400 //FIXME
#define MB_TYPE_ACPRED 0x0200
#define MB_TYPE_GMC 0x0400 //FIXME mpeg4 specific
#define MB_TYPE_SKIP 0x0800
#define MB_TYPE_P0L0 0x1000
#define MB_TYPE_P1L0 0x2000
#define MB_TYPE_P0L1 0x4000
#define MB_TYPE_P1L1 0x8000
#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
#define MB_TYPE_QUANT 0x00010000
//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 pat, ...)
#define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4)
#define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)
#define IS_INTRA(a) ((a)&3)
#define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
#define IS_INTRA(a) ((a)&7)
#define IS_INTER(a) ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))
#define IS_SKIP(a) ((a)&MB_TYPE_SKIP)
#define IS_INTRA_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
#define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)
#define IS_DIRECT(a) ((a)&MB_TYPE_DIRECT2)
#define IS_GMC(a) ((a)&MB_TYPE_GMC)
#define IS_16X16(a) ((a)&MB_TYPE_16x16)
#define IS_16X8(a) ((a)&MB_TYPE_16x8)
#define IS_8X16(a) ((a)&MB_TYPE_8x16)
......@@ -170,7 +179,8 @@ typedef struct Picture{
#define IS_SUB_8X4(a) ((a)&MB_TYPE_16x8) //note reused
#define IS_SUB_4X8(a) ((a)&MB_TYPE_8x16) //note reused
#define IS_SUB_4X4(a) ((a)&MB_TYPE_8x8) //note reused
#define IS_REF0(a) ((a)&MB_TYPE_REF0)
#define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED)
#define IS_QUANT(a) ((a)&MB_TYPE_QUANT)
#define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))
#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs
......@@ -283,6 +293,7 @@ typedef struct MpegEncContext {
int picture_in_gop_number; ///< 0-> first pic in gop, ...
int b_frames_since_non_b; ///< used for encoding, relative to not yet reordered input
int mb_width, mb_height; ///< number of MBs horizontally & vertically
int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressng of left & top MBs withoutt sig11
int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replicateion)
int mb_num; ///< number of MBs of a picture
int linesize; ///< line size, in bytes, may be different from width
......@@ -355,7 +366,13 @@ typedef struct MpegEncContext {
DSPContext dsp; ///< pointers for accelerated dsp fucntions
int f_code; ///< forward MV resolution
int b_code; ///< backward MV resolution for B Frames (mpeg4)
int16_t (*motion_val)[2]; ///< used for MV prediction (4MV per MB)
int16_t (*motion_val)[2];
int16_t (*p_mv_table_base)[2];
int16_t (*b_forw_mv_table_base)[2];
int16_t (*b_back_mv_table_base)[2];
int16_t (*b_bidir_forw_mv_table_base)[2];
int16_t (*b_bidir_back_mv_table_base)[2];
int16_t (*b_direct_mv_table_base)[2];
int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) p-frame encoding
int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode b-frame encoding
int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode b-frame encoding
......@@ -396,12 +413,12 @@ typedef struct MpegEncContext {
int mb_x, mb_y;
int mb_skip_run;
int mb_intra;
uint8_t *mb_type; ///< Table for MB type
uint8_t *mb_type; ///< Table for MB type FIXME remove and use picture->mb_type
#define MB_TYPE_INTRA 0x01
#define MB_TYPE_INTER 0x02
#define MB_TYPE_INTER4V 0x04
#define MB_TYPE_SKIPED 0x08
#define MB_TYPE_GMC 0x10
//#define MB_TYPE_GMC 0x10
#define MB_TYPE_DIRECT 0x10
#define MB_TYPE_FORWARD 0x20
......@@ -410,6 +427,8 @@ typedef struct MpegEncContext {
int block_index[6]; ///< index to current MB in block based arrays with edges
int block_wrap[6];
int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
/** matrix transmitted in the bitstream */
uint16_t intra_matrix[64];
......@@ -467,6 +486,7 @@ typedef struct MpegEncContext {
int last_bits; ///< temp var used for calculating the above vars
/* error concealment / resync */
int error_count;
uint8_t *error_status_table; ///< table of the error status of each MB
#define VP_START 1 ///< current MB is the first after a resync marker
#define AC_ERROR 2
......@@ -544,9 +564,6 @@ typedef struct MpegEncContext {
uint8_t *tex_pb_buffer;
uint8_t *pb2_buffer;
int mpeg_quant;
#define CO_LOCATED_TYPE_4MV 1
#define CO_LOCATED_TYPE_FIELDMV 2
int8_t *co_located_type_table; ///< 4mv & field_mv info for next b frame
int16_t (*field_mv_table)[2][2]; ///< used for interlaced b frame decoding
int8_t (*field_select_table)[2]; ///< wtf, no really another table for interlaced b frames
int t_frame; ///< time distance of first I -> B, used for interlaced b frames
......@@ -693,6 +710,7 @@ void ff_emulated_edge_mc(MpegEncContext *s, uint8_t *src, int linesize, int bloc
int src_x, int src_y, int w, int h);
char ff_get_pict_type_char(int pict_type);
int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size);
void ff_print_debug_info(MpegEncContext *s, Picture *pict);
void ff_er_frame_start(MpegEncContext *s);
void ff_er_frame_end(MpegEncContext *s);
......@@ -827,7 +845,7 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s);
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
int ff_h263_resync(MpegEncContext *s);
int ff_h263_get_gob_height(MpegEncContext *s);
void ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
inline int ff_h263_round_chroma(int x);
......
......@@ -27,7 +27,6 @@
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
//#define PRINT_MB
/*
* You can also call this codec : MPEG4 with a twist !
......@@ -1585,13 +1584,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
{
int cbp, code, i;
uint8_t *coded_val;
#ifdef PRINT_MB
if(s->mb_x==0){
printf("\n");
if(s->mb_y==0) printf("\n");
}
#endif
uint32_t * const mb_type_ptr= &s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ];
if (s->pict_type == P_TYPE) {
set_stat(ST_INTER_MB);
......@@ -1606,9 +1599,8 @@ if(s->mb_x==0){
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
s->mb_skiped = 1;
#ifdef PRINT_MB
printf("S ");
#endif
*mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
return 0;
}
}
......@@ -1654,16 +1646,12 @@ printf("S ");
s->mv_type = MV_TYPE_16X16;
s->mv[0][0][0] = mx;
s->mv[0][0][1] = my;
#ifdef PRINT_MB
printf("P ");
#endif
*mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
} else {
//printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24));
set_stat(ST_INTRA_MB);
s->ac_pred = get_bits1(&s->gb);
#ifdef PRINT_MB
printf("%c", s->ac_pred ? 'A' : 'I');
#endif
*mb_type_ptr = MB_TYPE_INTRA;
if(s->inter_intra_pred){
s->h263_aic_dir= get_vlc2(&s->gb, inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
// printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
......@@ -1701,14 +1689,7 @@ static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
/* DC coef */
set_stat(ST_DC);
level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
#ifdef PRINT_MB
{
static int c;
if(n==0) c=0;
if(n==4) printf("%X", c);
c+= c +dc_pred_dir;
}
#endif
if (level < 0){
fprintf(stderr, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
if(s->inter_intra_pred) level=0;
......
......@@ -267,20 +267,21 @@ void ff_wmv2_encode_mb(MpegEncContext * s,
static void parse_mb_skip(Wmv2Context * w){
int mb_x, mb_y;
MpegEncContext * const s= &w->s;
uint32_t * const mb_type= s->current_picture_ptr->mb_type;
w->skip_type= get_bits(&s->gb, 2);
switch(w->skip_type){
case SKIP_TYPE_NONE:
for(mb_y=0; mb_y<s->mb_height; mb_y++){
for(mb_x=0; mb_x<s->mb_width; mb_x++){
s->mb_type[mb_y*s->mb_width + mb_x]= 0;
mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_16x16 | MB_TYPE_L0;
}
}
break;
case SKIP_TYPE_MPEG:
for(mb_y=0; mb_y<s->mb_height; mb_y++){
for(mb_x=0; mb_x<s->mb_width; mb_x++){
s->mb_type[mb_y*s->mb_width + mb_x]= get_bits1(&s->gb) ? MB_TYPE_SKIPED : 0;
mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
}
}
break;
......@@ -288,11 +289,11 @@ static void parse_mb_skip(Wmv2Context * w){
for(mb_y=0; mb_y<s->mb_height; mb_y++){
if(get_bits1(&s->gb)){
for(mb_x=0; mb_x<s->mb_width; mb_x++){
s->mb_type[mb_y*s->mb_width + mb_x]= MB_TYPE_SKIPED;
mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
}
}else{
for(mb_x=0; mb_x<s->mb_width; mb_x++){
s->mb_type[mb_y*s->mb_width + mb_x]= get_bits1(&s->gb) ? MB_TYPE_SKIPED : 0;
mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
}
}
}
......@@ -301,11 +302,11 @@ static void parse_mb_skip(Wmv2Context * w){
for(mb_x=0; mb_x<s->mb_width; mb_x++){
if(get_bits1(&s->gb)){
for(mb_y=0; mb_y<s->mb_height; mb_y++){
s->mb_type[mb_y*s->mb_width + mb_x]= MB_TYPE_SKIPED;
mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
}
}else{
for(mb_y=0; mb_y<s->mb_height; mb_y++){
s->mb_type[mb_y*s->mb_width + mb_x]= get_bits1(&s->gb) ? MB_TYPE_SKIPED : 0;
mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
}
}
}
......@@ -455,12 +456,6 @@ return -1;
s->esc3_level_length= 0;
s->esc3_run_length= 0;
if(s->avctx->debug&FF_DEBUG_SKIP){
for(i=0; i<s->mb_num; i++){
if(i%s->mb_width==0) printf("\n");
printf("%d", s->mb_type[i]);
}
}
s->picture_number++; //FIXME ?
......@@ -712,7 +707,7 @@ static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
if(w->j_type) return 0;
if (s->pict_type == P_TYPE) {
if(s->mb_type[s->mb_y * s->mb_width + s->mb_x]&MB_TYPE_SKIPED){
if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){
/* skip mb */
s->mb_intra = 0;
for(i=0;i<6;i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment