• 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 RLTable rvlc_rl_inter;
00070 extern RLTable rvlc_rl_intra;
00071 
00072 extern const uint16_t sprite_trajectory_tab[15][2];
00073 extern const uint8_t mb_type_b_tab[4][2];
00074 
00075 /* these matrixes will be permuted for the idct */
00076 extern const int16_t ff_mpeg4_default_intra_matrix[64];
00077 extern const int16_t ff_mpeg4_default_non_intra_matrix[64];
00078 
00079 extern const uint8_t ff_mpeg4_y_dc_scale_table[32];
00080 extern const uint8_t ff_mpeg4_c_dc_scale_table[32];
00081 extern const uint16_t ff_mpeg4_resync_prefix[8];
00082 
00083 extern const uint8_t mpeg4_dc_threshold[8];
00084 
00085 void mpeg4_encode_mb(MpegEncContext *s,
00086                     DCTELEM block[6][64],
00087                     int motion_x, int motion_y);
00088 void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
00089                    int dir);
00090 void ff_set_mpeg4_time(MpegEncContext * s);
00091 void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
00092 
00093 int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb);
00094 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
00095 void ff_mpeg4_clean_buffers(MpegEncContext *s);
00096 void ff_mpeg4_stuffing(PutBitContext * pbc);
00097 void ff_mpeg4_init_partitions(MpegEncContext *s);
00098 void ff_mpeg4_merge_partitions(MpegEncContext *s);
00099 void ff_clean_mpeg4_qscales(MpegEncContext *s);
00100 int ff_mpeg4_decode_partitions(MpegEncContext *s);
00101 int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
00102 int mpeg4_decode_video_packet_header(MpegEncContext *s);
00103 void ff_mpeg4_init_direct_mv(MpegEncContext *s);
00104 
00109 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
00110 
00111 extern uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3];
00112 
00113 
00114 #if 0 //3IV1 is quite rare and it slows things down a tiny bit
00115 #define IS_3IV1 s->codec_tag == AV_RL32("3IV1")
00116 #else
00117 #define IS_3IV1 0
00118 #endif
00119 
00120 
00128 static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding)
00129 {
00130     int a, b, c, wrap, pred, scale, ret;
00131     int16_t *dc_val;
00132 
00133     /* find prediction */
00134     if (n < 4) {
00135         scale = s->y_dc_scale;
00136     } else {
00137         scale = s->c_dc_scale;
00138     }
00139     if(IS_3IV1)
00140         scale= 8;
00141 
00142     wrap= s->block_wrap[n];
00143     dc_val = s->dc_val[0] + s->block_index[n];
00144 
00145     /* B C
00146      * A X
00147      */
00148     a = dc_val[ - 1];
00149     b = dc_val[ - 1 - wrap];
00150     c = dc_val[ - wrap];
00151 
00152     /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */
00153     if(s->first_slice_line && n!=3){
00154         if(n!=2) b=c= 1024;
00155         if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024;
00156     }
00157     if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){
00158         if(n==0 || n==4 || n==5)
00159             b=1024;
00160     }
00161 
00162     if (abs(a - b) < abs(b - c)) {
00163         pred = c;
00164         *dir_ptr = 1; /* top */
00165     } else {
00166         pred = a;
00167         *dir_ptr = 0; /* left */
00168     }
00169     /* we assume pred is positive */
00170     pred = FASTDIV((pred + (scale >> 1)), scale);
00171 
00172     if(encoding){
00173         ret = level - pred;
00174     }else{
00175         level += pred;
00176         ret= level;
00177         if(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)){
00178             if(level<0){
00179                 av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y);
00180                 return -1;
00181             }
00182             if(level*scale > 2048 + scale){
00183                 av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y);
00184                 return -1;
00185             }
00186         }
00187     }
00188     level *=scale;
00189     if(level&(~2047)){
00190         if(level<0)
00191             level=0;
00192         else if(!(s->workaround_bugs&FF_BUG_DC_CLIP))
00193             level=2047;
00194     }
00195     dc_val[0]= level;
00196 
00197     return ret;
00198 }
00199 #endif /* AVCODEC_MPEG4VIDEO_H */
Generated on Fri Feb 1 2013 14:34:39 for FFmpeg by doxygen 1.7.1