00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "mpegvideo.h"
00024 #include "mpeg4video.h"
00025 #include "mpeg4data.h"
00026
00027 uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3];
00028
00029 int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){
00030 switch(s->pict_type){
00031 case AV_PICTURE_TYPE_I:
00032 return 16;
00033 case AV_PICTURE_TYPE_P:
00034 case AV_PICTURE_TYPE_S:
00035 return s->f_code+15;
00036 case AV_PICTURE_TYPE_B:
00037 return FFMAX3(s->f_code, s->b_code, 2) + 15;
00038 default:
00039 return -1;
00040 }
00041 }
00042
00043 void ff_mpeg4_clean_buffers(MpegEncContext *s)
00044 {
00045 int c_wrap, c_xy, l_wrap, l_xy;
00046
00047 l_wrap= s->b8_stride;
00048 l_xy= (2*s->mb_y-1)*l_wrap + s->mb_x*2 - 1;
00049 c_wrap= s->mb_stride;
00050 c_xy= (s->mb_y-1)*c_wrap + s->mb_x - 1;
00051
00052 #if 0
00053
00054 memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*2+1);
00055 memsetw(s->dc_val[1] + c_xy, 1024, c_wrap+1);
00056 memsetw(s->dc_val[2] + c_xy, 1024, c_wrap+1);
00057 #endif
00058
00059
00060 memset(s->ac_val[0] + l_xy, 0, (l_wrap*2+1)*16*sizeof(int16_t));
00061 memset(s->ac_val[1] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t));
00062 memset(s->ac_val[2] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t));
00063
00064
00065
00066
00067
00068 s->last_mv[0][0][0]=
00069 s->last_mv[0][0][1]=
00070 s->last_mv[1][0][0]=
00071 s->last_mv[1][0][1]= 0;
00072 }
00073
00074 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
00075 #define tab_bias (tab_size/2)
00076
00077
00078 void ff_mpeg4_init_direct_mv(MpegEncContext *s){
00079 int i;
00080 for(i=0; i<tab_size; i++){
00081 s->direct_scale_mv[0][i] = (i-tab_bias)*s->pb_time/s->pp_time;
00082 s->direct_scale_mv[1][i] = (i-tab_bias)*(s->pb_time-s->pp_time)/s->pp_time;
00083 }
00084 }
00085
00086 static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my, int i){
00087 int xy= s->block_index[i];
00088 uint16_t time_pp= s->pp_time;
00089 uint16_t time_pb= s->pb_time;
00090 int p_mx, p_my;
00091
00092 p_mx = s->next_picture.f.motion_val[0][xy][0];
00093 if((unsigned)(p_mx + tab_bias) < tab_size){
00094 s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx;
00095 s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
00096 : s->direct_scale_mv[1][p_mx + tab_bias];
00097 }else{
00098 s->mv[0][i][0] = p_mx*time_pb/time_pp + mx;
00099 s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
00100 : p_mx*(time_pb - time_pp)/time_pp;
00101 }
00102 p_my = s->next_picture.f.motion_val[0][xy][1];
00103 if((unsigned)(p_my + tab_bias) < tab_size){
00104 s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my;
00105 s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
00106 : s->direct_scale_mv[1][p_my + tab_bias];
00107 }else{
00108 s->mv[0][i][1] = p_my*time_pb/time_pp + my;
00109 s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
00110 : p_my*(time_pb - time_pp)/time_pp;
00111 }
00112 }
00113
00114 #undef tab_size
00115 #undef tab_bias
00116
00121 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){
00122 const int mb_index= s->mb_x + s->mb_y*s->mb_stride;
00123 const int colocated_mb_type = s->next_picture.f.mb_type[mb_index];
00124 uint16_t time_pp;
00125 uint16_t time_pb;
00126 int i;
00127
00128
00129
00130
00131 if(IS_8X8(colocated_mb_type)){
00132 s->mv_type = MV_TYPE_8X8;
00133 for(i=0; i<4; i++){
00134 ff_mpeg4_set_one_direct_mv(s, mx, my, i);
00135 }
00136 return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1;
00137 } else if(IS_INTERLACED(colocated_mb_type)){
00138 s->mv_type = MV_TYPE_FIELD;
00139 for(i=0; i<2; i++){
00140 int field_select = s->next_picture.f.ref_index[0][4 * mb_index + 2 * i];
00141 s->field_select[0][i]= field_select;
00142 s->field_select[1][i]= i;
00143 if(s->top_field_first){
00144 time_pp= s->pp_field_time - field_select + i;
00145 time_pb= s->pb_field_time - field_select + i;
00146 }else{
00147 time_pp= s->pp_field_time + field_select - i;
00148 time_pb= s->pb_field_time + field_select - i;
00149 }
00150 s->mv[0][i][0] = s->p_field_mv_table[i][0][mb_index][0]*time_pb/time_pp + mx;
00151 s->mv[0][i][1] = s->p_field_mv_table[i][0][mb_index][1]*time_pb/time_pp + my;
00152 s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->p_field_mv_table[i][0][mb_index][0]
00153 : s->p_field_mv_table[i][0][mb_index][0]*(time_pb - time_pp)/time_pp;
00154 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->p_field_mv_table[i][0][mb_index][1]
00155 : s->p_field_mv_table[i][0][mb_index][1]*(time_pb - time_pp)/time_pp;
00156 }
00157 return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED;
00158 }else{
00159 ff_mpeg4_set_one_direct_mv(s, mx, my, 0);
00160 s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->mv[0][0][0];
00161 s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->mv[0][0][1];
00162 s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = s->mv[1][0][0];
00163 s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = s->mv[1][0][1];
00164 if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample)
00165 s->mv_type= MV_TYPE_16X16;
00166 else
00167 s->mv_type= MV_TYPE_8X8;
00168 return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1;
00169 }
00170 }