00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef AVCODEC_MPEG4VIDEO_H
00024 #define AVCODEC_MPEG4VIDEO_H
00025
00026 #include <stdint.h>
00027 #include "get_bits.h"
00028 #include "mpegvideo.h"
00029 #include "rl.h"
00030
00031
00032 #define RECT_SHAPE 0
00033 #define BIN_SHAPE 1
00034 #define BIN_ONLY_SHAPE 2
00035 #define GRAY_SHAPE 3
00036
00037 #define SIMPLE_VO_TYPE 1
00038 #define CORE_VO_TYPE 3
00039 #define MAIN_VO_TYPE 4
00040 #define NBIT_VO_TYPE 5
00041 #define ARTS_VO_TYPE 10
00042 #define ACE_VO_TYPE 12
00043 #define ADV_SIMPLE_VO_TYPE 17
00044
00045
00046 #define EXTENDED_PAR 15
00047
00048
00049 #define STATIC_SPRITE 1
00050 #define GMC_SPRITE 2
00051
00052 #define MOTION_MARKER 0x1F001
00053 #define DC_MARKER 0x6B001
00054
00055 #define VOS_STARTCODE 0x1B0
00056 #define USER_DATA_STARTCODE 0x1B2
00057 #define GOP_STARTCODE 0x1B3
00058 #define VISUAL_OBJ_STARTCODE 0x1B5
00059 #define VOP_STARTCODE 0x1B6
00060
00061
00062 extern const uint8_t ff_mpeg4_DCtab_lum[13][2];
00063 extern const uint8_t ff_mpeg4_DCtab_chrom[13][2];
00064
00065 extern const uint16_t ff_mpeg4_intra_vlc[103][2];
00066 extern RLTable ff_mpeg4_rl_intra;
00067
00068
00069 extern const uint16_t inter_rvlc[170][2];
00070 extern RLTable rvlc_rl_inter;
00071
00072 extern const uint16_t intra_rvlc[170][2];
00073 extern RLTable rvlc_rl_intra;
00074
00075 extern const uint16_t sprite_trajectory_tab[15][2];
00076 extern const uint8_t mb_type_b_tab[4][2];
00077
00078
00079 extern const int16_t ff_mpeg4_default_intra_matrix[64];
00080 extern const int16_t ff_mpeg4_default_non_intra_matrix[64];
00081
00082 extern const uint8_t ff_mpeg4_y_dc_scale_table[32];
00083 extern const uint8_t ff_mpeg4_c_dc_scale_table[32];
00084 extern const uint16_t ff_mpeg4_resync_prefix[8];
00085
00086 extern const uint8_t mpeg4_dc_threshold[8];
00087
00088 void mpeg4_encode_mb(MpegEncContext *s,
00089 DCTELEM block[6][64],
00090 int motion_x, int motion_y);
00091 void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
00092 int dir);
00093 void ff_set_mpeg4_time(MpegEncContext * s);
00094 void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
00095
00096 int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb);
00097 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
00098 void ff_mpeg4_clean_buffers(MpegEncContext *s);
00099 void ff_mpeg4_stuffing(PutBitContext * pbc);
00100 void ff_mpeg4_init_partitions(MpegEncContext *s);
00101 void ff_mpeg4_merge_partitions(MpegEncContext *s);
00102 void ff_clean_mpeg4_qscales(MpegEncContext *s);
00103 int ff_mpeg4_decode_partitions(MpegEncContext *s);
00104 int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
00105 int mpeg4_decode_video_packet_header(MpegEncContext *s);
00106 void ff_mpeg4_init_direct_mv(MpegEncContext *s);
00107
00112 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
00113
00114 extern uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3];
00115
00116
00117 #if 0 //3IV1 is quite rare and it slows things down a tiny bit
00118 #define IS_3IV1 s->codec_tag == AV_RL32("3IV1")
00119 #else
00120 #define IS_3IV1 0
00121 #endif
00122
00123
00131 static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding)
00132 {
00133 int a, b, c, wrap, pred, scale, ret;
00134 int16_t *dc_val;
00135
00136
00137 if (n < 4) {
00138 scale = s->y_dc_scale;
00139 } else {
00140 scale = s->c_dc_scale;
00141 }
00142 if(IS_3IV1)
00143 scale= 8;
00144
00145 wrap= s->block_wrap[n];
00146 dc_val = s->dc_val[0] + s->block_index[n];
00147
00148
00149
00150
00151 a = dc_val[ - 1];
00152 b = dc_val[ - 1 - wrap];
00153 c = dc_val[ - wrap];
00154
00155
00156 if(s->first_slice_line && n!=3){
00157 if(n!=2) b=c= 1024;
00158 if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024;
00159 }
00160 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){
00161 if(n==0 || n==4 || n==5)
00162 b=1024;
00163 }
00164
00165 if (abs(a - b) < abs(b - c)) {
00166 pred = c;
00167 *dir_ptr = 1;
00168 } else {
00169 pred = a;
00170 *dir_ptr = 0;
00171 }
00172
00173 pred = FASTDIV((pred + (scale >> 1)), scale);
00174
00175 if(encoding){
00176 ret = level - pred;
00177 }else{
00178 level += pred;
00179 ret= level;
00180 if(s->error_recognition>=3){
00181 if(level<0){
00182 av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y);
00183 return -1;
00184 }
00185 if(level*scale > 2048 + scale){
00186 av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y);
00187 return -1;
00188 }
00189 }
00190 }
00191 level *=scale;
00192 if(level&(~2047)){
00193 if(level<0)
00194 level=0;
00195 else if(!(s->workaround_bugs&FF_BUG_DC_CLIP))
00196 level=2047;
00197 }
00198 dc_val[0]= level;
00199
00200 return ret;
00201 }
00202 #endif