• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/h263.h

Go to the documentation of this file.
00001 /*
00002  * H263 internal header
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 // The defines below define the number of bits that are read at once for
00030 // reading vlc values. Changing these may improve speed and data cache needs
00031 // be aware though that decreasing them may need the number of stages that is
00032 // passed to get_vlc* to be increased.
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 uint16_t ff_mba_max[6];
00063 extern 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         /* modulo encoding */
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 int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64],
00204                             int motion_x, int motion_y, int mb_type){
00205     int cbp=0, i;
00206 
00207     if(s->flags & CODEC_FLAG_CBP_RD){
00208         int score=0;
00209         const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
00210 
00211         for(i=0; i<6; i++){
00212             if(s->coded_score[i] < 0){
00213                 score += s->coded_score[i];
00214                 cbp |= 1 << (5 - i);
00215             }
00216         }
00217 
00218         if(cbp){
00219             int zero_score= -6;
00220             if ((motion_x | motion_y | s->dquant | mb_type) == 0){
00221                 zero_score-= 4; //2*MV + mb_type + cbp bit
00222             }
00223 
00224             zero_score*= lambda;
00225             if(zero_score <= score){
00226                 cbp=0;
00227             }
00228         }
00229 
00230         for (i = 0; i < 6; i++) {
00231             if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
00232                 s->block_last_index[i]= -1;
00233                 s->dsp.clear_block(s->block[i]);
00234             }
00235         }
00236     }else{
00237         for (i = 0; i < 6; i++) {
00238             if (s->block_last_index[i] >= 0)
00239                 cbp |= 1 << (5 - i);
00240         }
00241     }
00242     return cbp;
00243 }
00244 
00245 static inline void memsetw(short *tab, int val, int n)
00246 {
00247     int i;
00248     for(i=0;i<n;i++)
00249         tab[i] = val;
00250 }
00251 #endif

Generated on Fri Sep 16 2011 17:17:37 for FFmpeg by  doxygen 1.7.1