00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef AVCODEC_H263_H
00021 #define AVCODEC_H263_H
00022
00023 #include <stdint.h>
00024 #include "libavutil/rational.h"
00025 #include "get_bits.h"
00026 #include "mpegvideo.h"
00027 #include "rl.h"
00028
00029
00030
00031
00032
00033 #define INTRA_MCBPC_VLC_BITS 6
00034 #define INTER_MCBPC_VLC_BITS 7
00035 #define CBPY_VLC_BITS 6
00036 #define TEX_VLC_BITS 9
00037
00038 extern const AVRational ff_h263_pixel_aspect[16];
00039 extern const uint8_t ff_h263_cbpy_tab[16][2];
00040
00041 extern const uint8_t cbpc_b_tab[4][2];
00042
00043 extern const uint8_t mvtab[33][2];
00044
00045 extern const uint8_t ff_h263_intra_MCBPC_code[9];
00046 extern const uint8_t ff_h263_intra_MCBPC_bits[9];
00047
00048 extern const uint8_t ff_h263_inter_MCBPC_code[28];
00049 extern const uint8_t ff_h263_inter_MCBPC_bits[28];
00050 extern const uint8_t h263_mbtype_b_tab[15][2];
00051
00052 extern VLC ff_h263_intra_MCBPC_vlc;
00053 extern VLC ff_h263_inter_MCBPC_vlc;
00054 extern VLC ff_h263_cbpy_vlc;
00055
00056 extern RLTable ff_h263_rl_inter;
00057
00058 extern RLTable rl_intra_aic;
00059
00060 extern const uint16_t h263_format[8][2];
00061 extern const uint8_t modified_quant_tab[2][32];
00062 extern const uint16_t ff_mba_max[6];
00063 extern const uint8_t ff_mba_length[7];
00064
00065 extern uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
00066
00067
00068 int h263_decode_motion(MpegEncContext * s, int pred, int f_code);
00069 av_const int ff_h263_aspect_to_info(AVRational aspect);
00070 int ff_h263_decode_init(AVCodecContext *avctx);
00071 int ff_h263_decode_frame(AVCodecContext *avctx,
00072 void *data, int *data_size,
00073 AVPacket *avpkt);
00074 int ff_h263_decode_end(AVCodecContext *avctx);
00075 void h263_encode_mb(MpegEncContext *s,
00076 DCTELEM block[6][64],
00077 int motion_x, int motion_y);
00078 void h263_encode_picture_header(MpegEncContext *s, int picture_number);
00079 void h263_encode_gob_header(MpegEncContext * s, int mb_line);
00080 int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
00081 int *px, int *py);
00082 void h263_encode_init(MpegEncContext *s);
00083 void h263_decode_init_vlc(MpegEncContext *s);
00084 int h263_decode_picture_header(MpegEncContext *s);
00085 int ff_h263_decode_gob_header(MpegEncContext *s);
00086 void ff_h263_update_motion_val(MpegEncContext * s);
00087 void ff_h263_loop_filter(MpegEncContext * s);
00088 int ff_h263_decode_mba(MpegEncContext *s);
00089 void ff_h263_encode_mba(MpegEncContext *s);
00090 void ff_init_qscale_tab(MpegEncContext *s);
00091 int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr);
00092 void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n);
00093
00094
00098 void ff_h263_show_pict_info(MpegEncContext *s);
00099
00100 int ff_intel_h263_decode_picture_header(MpegEncContext *s);
00101 int ff_h263_decode_mb(MpegEncContext *s,
00102 DCTELEM block[6][64]);
00103
00109 int av_const h263_get_picture_format(int width, int height);
00110
00111 void ff_clean_h263_qscales(MpegEncContext *s);
00112 int ff_h263_resync(MpegEncContext *s);
00113 const uint8_t *ff_h263_find_resync_marker(const uint8_t *p, const uint8_t *end);
00114 int ff_h263_get_gob_height(MpegEncContext *s);
00115 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code);
00116
00117
00118 static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){
00119 int l, bit_size, code;
00120
00121 if (val == 0) {
00122 return mvtab[0][1];
00123 } else {
00124 bit_size = f_code - 1;
00125
00126 l= INT_BIT - 6 - bit_size;
00127 val = (val<<l)>>l;
00128 val--;
00129 code = (val >> bit_size) + 1;
00130
00131 return mvtab[code][1] + 1 + bit_size;
00132 }
00133 }
00134
00135 static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){
00136 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
00137 skip_put_bits(&s->pb,
00138 h263_get_motion_length(s, x, f_code)
00139 +h263_get_motion_length(s, y, f_code));
00140 }else{
00141 ff_h263_encode_motion(s, x, f_code);
00142 ff_h263_encode_motion(s, y, f_code);
00143 }
00144 }
00145
00146 static inline int get_p_cbp(MpegEncContext * s,
00147 DCTELEM block[6][64],
00148 int motion_x, int motion_y){
00149 int cbp, i;
00150
00151 if(s->flags & CODEC_FLAG_CBP_RD){
00152 int best_cbpy_score= INT_MAX;
00153 int best_cbpc_score= INT_MAX;
00154 int cbpc = (-1), cbpy= (-1);
00155 const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0);
00156 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
00157
00158 for(i=0; i<4; i++){
00159 int score= ff_h263_inter_MCBPC_bits[i + offset] * lambda;
00160 if(i&1) score += s->coded_score[5];
00161 if(i&2) score += s->coded_score[4];
00162
00163 if(score < best_cbpc_score){
00164 best_cbpc_score= score;
00165 cbpc= i;
00166 }
00167 }
00168
00169 for(i=0; i<16; i++){
00170 int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda;
00171 if(i&1) score += s->coded_score[3];
00172 if(i&2) score += s->coded_score[2];
00173 if(i&4) score += s->coded_score[1];
00174 if(i&8) score += s->coded_score[0];
00175
00176 if(score < best_cbpy_score){
00177 best_cbpy_score= score;
00178 cbpy= i;
00179 }
00180 }
00181 cbp= cbpc + 4*cbpy;
00182 if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){
00183 if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0)
00184 cbp= 0;
00185 }
00186
00187 for (i = 0; i < 6; i++) {
00188 if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
00189 s->block_last_index[i]= -1;
00190 s->dsp.clear_block(s->block[i]);
00191 }
00192 }
00193 }else{
00194 cbp= 0;
00195 for (i = 0; i < 6; i++) {
00196 if (s->block_last_index[i] >= 0)
00197 cbp |= 1 << (5 - i);
00198 }
00199 }
00200 return cbp;
00201 }
00202
00203 static inline void memsetw(short *tab, int val, int n)
00204 {
00205 int i;
00206 for(i=0;i<n;i++)
00207 tab[i] = val;
00208 }
00209
00210 #endif