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

libavcodec/mpeg4video.h

Go to the documentation of this file.
00001 /*
00002  * MPEG4 encoder/decoder internal header.
00003  * Copyright (c) 2000,2001 Fabrice Bellard
00004  * Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 // shapes
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 // aspect_ratio_info
00046 #define EXTENDED_PAR 15
00047 
00048 //vol_sprite_usage / sprite_enable
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 /* dc encoding for mpeg4 */
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 /* Note this is identical to the intra rvlc except that it is reordered. */
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 /* these matrixes will be permuted for the idct */
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     /* find prediction */
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     /* B C
00149      * A X
00150      */
00151     a = dc_val[ - 1];
00152     b = dc_val[ - 1 - wrap];
00153     c = dc_val[ - wrap];
00154 
00155     /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */
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; /* top */
00168     } else {
00169         pred = a;
00170         *dir_ptr = 0; /* left */
00171     }
00172     /* we assume pred is positive */
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

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