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

libavcodec/h264.h

Go to the documentation of this file.
00001 /*
00002  * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
00003  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00028 #ifndef AVCODEC_H264_H
00029 #define AVCODEC_H264_H
00030 
00031 #include "libavutil/intreadwrite.h"
00032 #include "dsputil.h"
00033 #include "cabac.h"
00034 #include "mpegvideo.h"
00035 #include "h264dsp.h"
00036 #include "h264pred.h"
00037 #include "rectangle.h"
00038 
00039 #define interlaced_dct interlaced_dct_is_a_bad_name
00040 #define mb_intra mb_intra_is_not_initialized_see_mb_type
00041 
00042 #define LUMA_DC_BLOCK_INDEX   25
00043 #define CHROMA_DC_BLOCK_INDEX 26
00044 
00045 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
00046 #define COEFF_TOKEN_VLC_BITS           8
00047 #define TOTAL_ZEROS_VLC_BITS           9
00048 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
00049 #define RUN_VLC_BITS                   3
00050 #define RUN7_VLC_BITS                  6
00051 
00052 #define MAX_SPS_COUNT 32
00053 #define MAX_PPS_COUNT 256
00054 
00055 #define MAX_MMCO_COUNT 66
00056 
00057 #define MAX_DELAYED_PIC_COUNT 16
00058 
00059 /* Compiling in interlaced support reduces the speed
00060  * of progressive decoding by about 2%. */
00061 #define ALLOW_INTERLACE
00062 
00063 #define ALLOW_NOCHROMA
00064 
00065 #define FMO 0
00066 
00071 #define MAX_SLICES 16
00072 
00073 #ifdef ALLOW_INTERLACE
00074 #define MB_MBAFF h->mb_mbaff
00075 #define MB_FIELD h->mb_field_decoding_flag
00076 #define FRAME_MBAFF h->mb_aff_frame
00077 #define FIELD_PICTURE (s->picture_structure != PICT_FRAME)
00078 #else
00079 #define MB_MBAFF 0
00080 #define MB_FIELD 0
00081 #define FRAME_MBAFF 0
00082 #define FIELD_PICTURE 0
00083 #undef  IS_INTERLACED
00084 #define IS_INTERLACED(mb_type) 0
00085 #endif
00086 #define FIELD_OR_MBAFF_PICTURE (FRAME_MBAFF || FIELD_PICTURE)
00087 
00088 #ifdef ALLOW_NOCHROMA
00089 #define CHROMA h->sps.chroma_format_idc
00090 #else
00091 #define CHROMA 1
00092 #endif
00093 
00094 #ifndef CABAC
00095 #define CABAC h->pps.cabac
00096 #endif
00097 
00098 #define EXTENDED_SAR          255
00099 
00100 #define MB_TYPE_REF0       MB_TYPE_ACPRED //dirty but it fits in 16 bit
00101 #define MB_TYPE_8x8DCT     0x01000000
00102 #define IS_REF0(a)         ((a) & MB_TYPE_REF0)
00103 #define IS_8x8DCT(a)       ((a) & MB_TYPE_8x8DCT)
00104 
00109 #define DELAYED_PIC_REF 4
00110 
00111 
00112 /* NAL unit types */
00113 enum {
00114     NAL_SLICE=1,
00115     NAL_DPA,
00116     NAL_DPB,
00117     NAL_DPC,
00118     NAL_IDR_SLICE,
00119     NAL_SEI,
00120     NAL_SPS,
00121     NAL_PPS,
00122     NAL_AUD,
00123     NAL_END_SEQUENCE,
00124     NAL_END_STREAM,
00125     NAL_FILLER_DATA,
00126     NAL_SPS_EXT,
00127     NAL_AUXILIARY_SLICE=19
00128 };
00129 
00133 typedef enum {
00134     SEI_BUFFERING_PERIOD             =  0, 
00135     SEI_TYPE_PIC_TIMING              =  1, 
00136     SEI_TYPE_USER_DATA_UNREGISTERED  =  5, 
00137     SEI_TYPE_RECOVERY_POINT          =  6  
00138 } SEI_Type;
00139 
00143 typedef enum {
00144     SEI_PIC_STRUCT_FRAME             = 0, 
00145     SEI_PIC_STRUCT_TOP_FIELD         = 1, 
00146     SEI_PIC_STRUCT_BOTTOM_FIELD      = 2, 
00147     SEI_PIC_STRUCT_TOP_BOTTOM        = 3, 
00148     SEI_PIC_STRUCT_BOTTOM_TOP        = 4, 
00149     SEI_PIC_STRUCT_TOP_BOTTOM_TOP    = 5, 
00150     SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6, 
00151     SEI_PIC_STRUCT_FRAME_DOUBLING    = 7, 
00152     SEI_PIC_STRUCT_FRAME_TRIPLING    = 8  
00153 } SEI_PicStructType;
00154 
00158 typedef struct SPS{
00159 
00160     int profile_idc;
00161     int level_idc;
00162     int chroma_format_idc;
00163     int transform_bypass;              
00164     int log2_max_frame_num;            
00165     int poc_type;                      
00166     int log2_max_poc_lsb;              
00167     int delta_pic_order_always_zero_flag;
00168     int offset_for_non_ref_pic;
00169     int offset_for_top_to_bottom_field;
00170     int poc_cycle_length;              
00171     int ref_frame_count;               
00172     int gaps_in_frame_num_allowed_flag;
00173     int mb_width;                      
00174     int mb_height;                     
00175     int frame_mbs_only_flag;
00176     int mb_aff;                        
00177     int direct_8x8_inference_flag;
00178     int crop;                   
00179     unsigned int crop_left;            
00180     unsigned int crop_right;           
00181     unsigned int crop_top;             
00182     unsigned int crop_bottom;          
00183     int vui_parameters_present_flag;
00184     AVRational sar;
00185     int video_signal_type_present_flag;
00186     int full_range;
00187     int colour_description_present_flag;
00188     enum AVColorPrimaries color_primaries;
00189     enum AVColorTransferCharacteristic color_trc;
00190     enum AVColorSpace colorspace;
00191     int timing_info_present_flag;
00192     uint32_t num_units_in_tick;
00193     uint32_t time_scale;
00194     int fixed_frame_rate_flag;
00195     short offset_for_ref_frame[256]; //FIXME dyn aloc?
00196     int bitstream_restriction_flag;
00197     int num_reorder_frames;
00198     int scaling_matrix_present;
00199     uint8_t scaling_matrix4[6][16];
00200     uint8_t scaling_matrix8[2][64];
00201     int nal_hrd_parameters_present_flag;
00202     int vcl_hrd_parameters_present_flag;
00203     int pic_struct_present_flag;
00204     int time_offset_length;
00205     int cpb_cnt;                       
00206     int initial_cpb_removal_delay_length; 
00207     int cpb_removal_delay_length;      
00208     int dpb_output_delay_length;       
00209     int bit_depth_luma;                
00210     int bit_depth_chroma;              
00211     int residual_color_transform_flag; 
00212 }SPS;
00213 
00217 typedef struct PPS{
00218     unsigned int sps_id;
00219     int cabac;                  
00220     int pic_order_present;      
00221     int slice_group_count;      
00222     int mb_slice_group_map_type;
00223     unsigned int ref_count[2];  
00224     int weighted_pred;          
00225     int weighted_bipred_idc;
00226     int init_qp;                
00227     int init_qs;                
00228     int chroma_qp_index_offset[2];
00229     int deblocking_filter_parameters_present; 
00230     int constrained_intra_pred; 
00231     int redundant_pic_cnt_present; 
00232     int transform_8x8_mode;     
00233     uint8_t scaling_matrix4[6][16];
00234     uint8_t scaling_matrix8[2][64];
00235     uint8_t chroma_qp_table[2][64];  
00236     int chroma_qp_diff;
00237 }PPS;
00238 
00242 typedef enum MMCOOpcode{
00243     MMCO_END=0,
00244     MMCO_SHORT2UNUSED,
00245     MMCO_LONG2UNUSED,
00246     MMCO_SHORT2LONG,
00247     MMCO_SET_MAX_LONG,
00248     MMCO_RESET,
00249     MMCO_LONG,
00250 } MMCOOpcode;
00251 
00255 typedef struct MMCO{
00256     MMCOOpcode opcode;
00257     int short_pic_num;  
00258     int long_arg;       
00259 } MMCO;
00260 
00264 typedef struct H264Context{
00265     MpegEncContext s;
00266     H264DSPContext h264dsp;
00267     int chroma_qp[2]; //QPc
00268 
00269     int qp_thresh;      
00270 
00271     int prev_mb_skipped;
00272     int next_mb_skipped;
00273 
00274     //prediction stuff
00275     int chroma_pred_mode;
00276     int intra16x16_pred_mode;
00277 
00278     int topleft_mb_xy;
00279     int top_mb_xy;
00280     int topright_mb_xy;
00281     int left_mb_xy[2];
00282 
00283     int topleft_type;
00284     int top_type;
00285     int topright_type;
00286     int left_type[2];
00287 
00288     const uint8_t * left_block;
00289     int topleft_partition;
00290 
00291     int8_t intra4x4_pred_mode_cache[5*8];
00292     int8_t (*intra4x4_pred_mode);
00293     H264PredContext hpc;
00294     unsigned int topleft_samples_available;
00295     unsigned int top_samples_available;
00296     unsigned int topright_samples_available;
00297     unsigned int left_samples_available;
00298     uint8_t (*top_borders[2])[16+2*8];
00299 
00304     DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[6*8];
00305 
00306     /*
00307     .UU.YYYY
00308     .UU.YYYY
00309     .vv.YYYY
00310     .VV.YYYY
00311     */
00312     uint8_t (*non_zero_count)[32];
00313 
00317     DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5*8][2];
00318     DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5*8];
00319 #define LIST_NOT_USED -1 //FIXME rename?
00320 #define PART_NOT_AVAILABLE -2
00321 
00325     int mv_cache_clean[2];
00326 
00330     int neighbor_transform_size;
00331 
00336     int block_offset[2*(16+8)];
00337 
00338     uint32_t *mb2b_xy; //FIXME are these 4 a good idea?
00339     uint32_t *mb2br_xy;
00340     int b_stride; //FIXME use s->b4_stride
00341 
00342     int mb_linesize;   
00343     int mb_uvlinesize;
00344 
00345     int emu_edge_width;
00346     int emu_edge_height;
00347 
00348     SPS sps; 
00349 
00353     PPS pps; //FIXME move to Picture perhaps? (->no) do we need that?
00354 
00355     uint32_t dequant4_buffer[6][52][16]; //FIXME should these be moved down?
00356     uint32_t dequant8_buffer[2][52][64];
00357     uint32_t (*dequant4_coeff[6])[16];
00358     uint32_t (*dequant8_coeff[2])[64];
00359 
00360     int slice_num;
00361     uint16_t *slice_table;     
00362     int slice_type;
00363     int slice_type_nos;        
00364     int slice_type_fixed;
00365 
00366     //interlacing specific flags
00367     int mb_aff_frame;
00368     int mb_field_decoding_flag;
00369     int mb_mbaff;              
00370 
00371     DECLARE_ALIGNED(8, uint16_t, sub_mb_type)[4];
00372 
00373     //Weighted pred stuff
00374     int use_weight;
00375     int use_weight_chroma;
00376     int luma_log2_weight_denom;
00377     int chroma_log2_weight_denom;
00378     //The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss
00379     int luma_weight[48][2][2];
00380     int chroma_weight[48][2][2][2];
00381     int implicit_weight[48][48][2];
00382 
00383     int direct_spatial_mv_pred;
00384     int col_parity;
00385     int col_fieldoff;
00386     int dist_scale_factor[16];
00387     int dist_scale_factor_field[2][32];
00388     int map_col_to_list0[2][16+32];
00389     int map_col_to_list0_field[2][2][16+32];
00390 
00394     unsigned int ref_count[2];   
00395     unsigned int list_count;
00396     uint8_t *list_counts;            
00397     Picture ref_list[2][48];         
00400     int ref2frm[MAX_SLICES][2][64];  
00401 
00402     //data partitioning
00403     GetBitContext intra_gb;
00404     GetBitContext inter_gb;
00405     GetBitContext *intra_gb_ptr;
00406     GetBitContext *inter_gb_ptr;
00407 
00408     DECLARE_ALIGNED(16, DCTELEM, mb)[16*24];
00409     DCTELEM mb_padding[256];        
00410 
00414     CABACContext cabac;
00415     uint8_t      cabac_state[460];
00416 
00417     /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */
00418     uint16_t     *cbp_table;
00419     int cbp;
00420     int top_cbp;
00421     int left_cbp;
00422     /* chroma_pred_mode for i4x4 or i16x16, else 0 */
00423     uint8_t     *chroma_pred_mode_table;
00424     int         last_qscale_diff;
00425     uint8_t     (*mvd_table[2])[2];
00426     DECLARE_ALIGNED(16, uint8_t, mvd_cache)[2][5*8][2];
00427     uint8_t     *direct_table;
00428     uint8_t     direct_cache[5*8];
00429 
00430     uint8_t zigzag_scan[16];
00431     uint8_t zigzag_scan8x8[64];
00432     uint8_t zigzag_scan8x8_cavlc[64];
00433     uint8_t field_scan[16];
00434     uint8_t field_scan8x8[64];
00435     uint8_t field_scan8x8_cavlc[64];
00436     const uint8_t *zigzag_scan_q0;
00437     const uint8_t *zigzag_scan8x8_q0;
00438     const uint8_t *zigzag_scan8x8_cavlc_q0;
00439     const uint8_t *field_scan_q0;
00440     const uint8_t *field_scan8x8_q0;
00441     const uint8_t *field_scan8x8_cavlc_q0;
00442 
00443     int x264_build;
00444 
00445     int mb_xy;
00446 
00447     int is_complex;
00448 
00449     //deblock
00450     int deblocking_filter;         
00451     int slice_alpha_c0_offset;
00452     int slice_beta_offset;
00453 
00454 //=============================================================
00455     //Things below are not used in the MB or more inner code
00456 
00457     int nal_ref_idc;
00458     int nal_unit_type;
00459     uint8_t *rbsp_buffer[2];
00460     unsigned int rbsp_buffer_size[2];
00461 
00465     int is_avc; 
00466     int nal_length_size; 
00467 
00468     SPS *sps_buffers[MAX_SPS_COUNT];
00469     PPS *pps_buffers[MAX_PPS_COUNT];
00470 
00471     int dequant_coeff_pps;     
00472 
00473     uint16_t *slice_table_base;
00474 
00475 
00476     //POC stuff
00477     int poc_lsb;
00478     int poc_msb;
00479     int delta_poc_bottom;
00480     int delta_poc[2];
00481     int frame_num;
00482     int prev_poc_msb;             
00483     int prev_poc_lsb;             
00484     int frame_num_offset;         
00485     int prev_frame_num_offset;    
00486     int prev_frame_num;           
00487 
00491     int curr_pic_num;
00492 
00496     int max_pic_num;
00497 
00498     int redundant_pic_count;
00499 
00500     Picture *short_ref[32];
00501     Picture *long_ref[32];
00502     Picture default_ref_list[2][32]; 
00503     Picture *delayed_pic[MAX_DELAYED_PIC_COUNT+2]; //FIXME size?
00504     int outputed_poc;
00505 
00509     MMCO mmco[MAX_MMCO_COUNT];
00510     int mmco_index;
00511 
00512     int long_ref_count;  
00513     int short_ref_count; 
00514 
00515     int          cabac_init_idc;
00516 
00521     struct H264Context *thread_context[MAX_THREADS];
00522 
00526     int current_slice;
00527 
00534     int max_contexts;
00535 
00540     int single_decode_warning;
00541 
00542     int last_slice_type;
00548     SEI_PicStructType sei_pic_struct;
00549 
00556     int prev_interlaced_frame;
00557 
00563     int sei_ct_type;
00564 
00568     int sei_dpb_output_delay;
00569 
00573     int sei_cpb_removal_delay;
00574 
00582     int sei_recovery_frame_cnt;
00583 
00584     int luma_weight_flag[2];   
00585     int chroma_weight_flag[2]; 
00586 
00587     // Timestamp stuff
00588     int sei_buffering_period_present;  
00589     int initial_cpb_removal_delay[32]; 
00590 
00591     //SVQ3 specific fields
00592     int halfpel_flag;
00593     int thirdpel_flag;
00594     int unknown_svq3_flag;
00595     int next_slice_index;
00596     uint32_t svq3_watermark_key;
00597 }H264Context;
00598 
00599 
00600 extern const uint8_t ff_h264_chroma_qp[52];
00601 
00602 void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp);
00603 
00604 void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc);
00605 
00609 int ff_h264_decode_sei(H264Context *h);
00610 
00614 int ff_h264_decode_seq_parameter_set(H264Context *h);
00615 
00619 int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length);
00620 
00628 const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length);
00629 
00634 int ff_h264_decode_rbsp_trailing(H264Context *h, const uint8_t *src);
00635 
00639 av_cold void ff_h264_free_context(H264Context *h);
00640 
00644 int ff_h264_get_slice_type(const H264Context *h);
00645 
00650 int ff_h264_alloc_tables(H264Context *h);
00651 
00655 int ff_h264_fill_default_ref_list(H264Context *h);
00656 
00657 int ff_h264_decode_ref_pic_list_reordering(H264Context *h);
00658 void ff_h264_fill_mbaff_ref_list(H264Context *h);
00659 void ff_h264_remove_all_refs(H264Context *h);
00660 
00664 int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count);
00665 
00666 int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb);
00667 
00668 
00672 int ff_h264_check_intra4x4_pred_mode(H264Context *h);
00673 
00677 int ff_h264_check_intra_pred_mode(H264Context *h, int mode);
00678 
00679 void ff_h264_write_back_intra_pred_mode(H264Context *h);
00680 void ff_h264_hl_decode_mb(H264Context *h);
00681 int ff_h264_frame_start(H264Context *h);
00682 av_cold int ff_h264_decode_init(AVCodecContext *avctx);
00683 av_cold int ff_h264_decode_end(AVCodecContext *avctx);
00684 av_cold void ff_h264_decode_init_vlc(void);
00685 
00690 int ff_h264_decode_mb_cavlc(H264Context *h);
00691 
00696 int ff_h264_decode_mb_cabac(H264Context *h);
00697 
00698 void ff_h264_init_cabac_states(H264Context *h);
00699 
00700 void ff_h264_direct_dist_scale_factor(H264Context * const h);
00701 void ff_h264_direct_ref_list_init(H264Context * const h);
00702 void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type);
00703 
00704 void ff_h264_filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize);
00705 void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize);
00706 
00712 void ff_h264_reset_sei(H264Context *h);
00713 
00714 
00715 /*
00716 o-o o-o
00717  / / /
00718 o-o o-o
00719  ,---'
00720 o-o o-o
00721  / / /
00722 o-o o-o
00723 */
00724 //This table must be here because scan8[constant] must be known at compiletime
00725 static const uint8_t scan8[16 + 2*4]={
00726  4+1*8, 5+1*8, 4+2*8, 5+2*8,
00727  6+1*8, 7+1*8, 6+2*8, 7+2*8,
00728  4+3*8, 5+3*8, 4+4*8, 5+4*8,
00729  6+3*8, 7+3*8, 6+4*8, 7+4*8,
00730  1+1*8, 2+1*8,
00731  1+2*8, 2+2*8,
00732  1+4*8, 2+4*8,
00733  1+5*8, 2+5*8,
00734 };
00735 
00736 static av_always_inline uint32_t pack16to32(int a, int b){
00737 #if HAVE_BIGENDIAN
00738    return (b&0xFFFF) + (a<<16);
00739 #else
00740    return (a&0xFFFF) + (b<<16);
00741 #endif
00742 }
00743 
00744 static av_always_inline uint16_t pack8to16(int a, int b){
00745 #if HAVE_BIGENDIAN
00746    return (b&0xFF) + (a<<8);
00747 #else
00748    return (a&0xFF) + (b<<8);
00749 #endif
00750 }
00751 
00755 static inline int get_chroma_qp(H264Context *h, int t, int qscale){
00756     return h->pps.chroma_qp_table[t][qscale];
00757 }
00758 
00759 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my);
00760 
00761 static void fill_decode_neighbors(H264Context *h, int mb_type){
00762     MpegEncContext * const s = &h->s;
00763     const int mb_xy= h->mb_xy;
00764     int topleft_xy, top_xy, topright_xy, left_xy[2];
00765     static const uint8_t left_block_options[4][16]={
00766         {0,1,2,3,7,10,8,11,7+0*8, 7+1*8, 7+2*8, 7+3*8, 2+0*8, 2+3*8, 2+1*8, 2+2*8},
00767         {2,2,3,3,8,11,8,11,7+2*8, 7+2*8, 7+3*8, 7+3*8, 2+1*8, 2+2*8, 2+1*8, 2+2*8},
00768         {0,0,1,1,7,10,7,10,7+0*8, 7+0*8, 7+1*8, 7+1*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8},
00769         {0,2,0,2,7,10,7,10,7+0*8, 7+2*8, 7+0*8, 7+2*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8}
00770     };
00771 
00772     h->topleft_partition= -1;
00773 
00774     top_xy     = mb_xy  - (s->mb_stride << MB_FIELD);
00775 
00776     /* Wow, what a mess, why didn't they simplify the interlacing & intra
00777      * stuff, I can't imagine that these complex rules are worth it. */
00778 
00779     topleft_xy = top_xy - 1;
00780     topright_xy= top_xy + 1;
00781     left_xy[1] = left_xy[0] = mb_xy-1;
00782     h->left_block = left_block_options[0];
00783     if(FRAME_MBAFF){
00784         const int left_mb_field_flag     = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);
00785         const int curr_mb_field_flag     = IS_INTERLACED(mb_type);
00786         if(s->mb_y&1){
00787             if (left_mb_field_flag != curr_mb_field_flag) {
00788                 left_xy[1] = left_xy[0] = mb_xy - s->mb_stride - 1;
00789                 if (curr_mb_field_flag) {
00790                     left_xy[1] += s->mb_stride;
00791                     h->left_block = left_block_options[3];
00792                 } else {
00793                     topleft_xy += s->mb_stride;
00794                     // take top left mv from the middle of the mb, as opposed to all other modes which use the bottom right partition
00795                     h->topleft_partition = 0;
00796                     h->left_block = left_block_options[1];
00797                 }
00798             }
00799         }else{
00800             if(curr_mb_field_flag){
00801                 topleft_xy  += s->mb_stride & (((s->current_picture.mb_type[top_xy - 1]>>7)&1)-1);
00802                 topright_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy + 1]>>7)&1)-1);
00803                 top_xy      += s->mb_stride & (((s->current_picture.mb_type[top_xy    ]>>7)&1)-1);
00804             }
00805             if (left_mb_field_flag != curr_mb_field_flag) {
00806                 if (curr_mb_field_flag) {
00807                     left_xy[1] += s->mb_stride;
00808                     h->left_block = left_block_options[3];
00809                 } else {
00810                     h->left_block = left_block_options[2];
00811                 }
00812             }
00813         }
00814     }
00815 
00816     h->topleft_mb_xy = topleft_xy;
00817     h->top_mb_xy     = top_xy;
00818     h->topright_mb_xy= topright_xy;
00819     h->left_mb_xy[0] = left_xy[0];
00820     h->left_mb_xy[1] = left_xy[1];
00821     //FIXME do we need all in the context?
00822 
00823     h->topleft_type = s->current_picture.mb_type[topleft_xy] ;
00824     h->top_type     = s->current_picture.mb_type[top_xy]     ;
00825     h->topright_type= s->current_picture.mb_type[topright_xy];
00826     h->left_type[0] = s->current_picture.mb_type[left_xy[0]] ;
00827     h->left_type[1] = s->current_picture.mb_type[left_xy[1]] ;
00828 
00829     if(FMO){
00830     if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0;
00831     if(h->slice_table[top_xy     ] != h->slice_num) h->top_type     = 0;
00832     if(h->slice_table[left_xy[0] ] != h->slice_num) h->left_type[0] = h->left_type[1] = 0;
00833     }else{
00834         if(h->slice_table[topleft_xy ] != h->slice_num){
00835             h->topleft_type = 0;
00836             if(h->slice_table[top_xy     ] != h->slice_num) h->top_type     = 0;
00837             if(h->slice_table[left_xy[0] ] != h->slice_num) h->left_type[0] = h->left_type[1] = 0;
00838         }
00839     }
00840     if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;
00841 }
00842 
00843 static void fill_decode_caches(H264Context *h, int mb_type){
00844     MpegEncContext * const s = &h->s;
00845     int topleft_xy, top_xy, topright_xy, left_xy[2];
00846     int topleft_type, top_type, topright_type, left_type[2];
00847     const uint8_t * left_block= h->left_block;
00848     int i;
00849 
00850     topleft_xy   = h->topleft_mb_xy ;
00851     top_xy       = h->top_mb_xy     ;
00852     topright_xy  = h->topright_mb_xy;
00853     left_xy[0]   = h->left_mb_xy[0] ;
00854     left_xy[1]   = h->left_mb_xy[1] ;
00855     topleft_type = h->topleft_type  ;
00856     top_type     = h->top_type      ;
00857     topright_type= h->topright_type ;
00858     left_type[0] = h->left_type[0]  ;
00859     left_type[1] = h->left_type[1]  ;
00860 
00861     if(!IS_SKIP(mb_type)){
00862         if(IS_INTRA(mb_type)){
00863             int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
00864             h->topleft_samples_available=
00865             h->top_samples_available=
00866             h->left_samples_available= 0xFFFF;
00867             h->topright_samples_available= 0xEEEA;
00868 
00869             if(!(top_type & type_mask)){
00870                 h->topleft_samples_available= 0xB3FF;
00871                 h->top_samples_available= 0x33FF;
00872                 h->topright_samples_available= 0x26EA;
00873             }
00874             if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){
00875                 if(IS_INTERLACED(mb_type)){
00876                     if(!(left_type[0] & type_mask)){
00877                         h->topleft_samples_available&= 0xDFFF;
00878                         h->left_samples_available&= 0x5FFF;
00879                     }
00880                     if(!(left_type[1] & type_mask)){
00881                         h->topleft_samples_available&= 0xFF5F;
00882                         h->left_samples_available&= 0xFF5F;
00883                     }
00884                 }else{
00885                     int left_typei = s->current_picture.mb_type[left_xy[0] + s->mb_stride];
00886 
00887                     assert(left_xy[0] == left_xy[1]);
00888                     if(!((left_typei & type_mask) && (left_type[0] & type_mask))){
00889                         h->topleft_samples_available&= 0xDF5F;
00890                         h->left_samples_available&= 0x5F5F;
00891                     }
00892                 }
00893             }else{
00894                 if(!(left_type[0] & type_mask)){
00895                     h->topleft_samples_available&= 0xDF5F;
00896                     h->left_samples_available&= 0x5F5F;
00897                 }
00898             }
00899 
00900             if(!(topleft_type & type_mask))
00901                 h->topleft_samples_available&= 0x7FFF;
00902 
00903             if(!(topright_type & type_mask))
00904                 h->topright_samples_available&= 0xFBFF;
00905 
00906             if(IS_INTRA4x4(mb_type)){
00907                 if(IS_INTRA4x4(top_type)){
00908                     AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
00909                 }else{
00910                     h->intra4x4_pred_mode_cache[4+8*0]=
00911                     h->intra4x4_pred_mode_cache[5+8*0]=
00912                     h->intra4x4_pred_mode_cache[6+8*0]=
00913                     h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);
00914                 }
00915                 for(i=0; i<2; i++){
00916                     if(IS_INTRA4x4(left_type[i])){
00917                         int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[i]];
00918                         h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];
00919                         h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];
00920                     }else{
00921                         h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
00922                         h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[i] & type_mask);
00923                     }
00924                 }
00925             }
00926         }
00927 
00928 
00929 /*
00930 0 . T T. T T T T
00931 1 L . .L . . . .
00932 2 L . .L . . . .
00933 3 . T TL . . . .
00934 4 L . .L . . . .
00935 5 L . .. . . . .
00936 */
00937 //FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec)
00938     if(top_type){
00939         AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]);
00940             h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8];
00941             h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8];
00942 
00943             h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8];
00944             h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8];
00945     }else {
00946             h->non_zero_count_cache[1+8*0]=
00947             h->non_zero_count_cache[2+8*0]=
00948 
00949             h->non_zero_count_cache[1+8*3]=
00950             h->non_zero_count_cache[2+8*3]=
00951             AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040);
00952     }
00953 
00954     for (i=0; i<2; i++) {
00955         if(left_type[i]){
00956             h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]];
00957             h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]];
00958                 h->non_zero_count_cache[0+8*1 +   8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]];
00959                 h->non_zero_count_cache[0+8*4 +   8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]];
00960         }else{
00961                 h->non_zero_count_cache[3+8*1 + 2*8*i]=
00962                 h->non_zero_count_cache[3+8*2 + 2*8*i]=
00963                 h->non_zero_count_cache[0+8*1 +   8*i]=
00964                 h->non_zero_count_cache[0+8*4 +   8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;
00965         }
00966     }
00967 
00968     if( CABAC ) {
00969         // top_cbp
00970         if(top_type) {
00971             h->top_cbp = h->cbp_table[top_xy];
00972         } else {
00973             h->top_cbp = IS_INTRA(mb_type) ? 0x1CF : 0x00F;
00974         }
00975         // left_cbp
00976         if (left_type[0]) {
00977             h->left_cbp = (h->cbp_table[left_xy[0]] & 0x1f0)
00978                         |  ((h->cbp_table[left_xy[0]]>>(left_block[0]&(~1)))&2)
00979                         | (((h->cbp_table[left_xy[1]]>>(left_block[2]&(~1)))&2) << 2);
00980         } else {
00981             h->left_cbp = IS_INTRA(mb_type) ? 0x1CF : 0x00F;
00982         }
00983     }
00984     }
00985 
00986 #if 1
00987     if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
00988         int list;
00989         for(list=0; list<h->list_count; list++){
00990             if(!USES_LIST(mb_type, list)){
00991                 /*if(!h->mv_cache_clean[list]){
00992                     memset(h->mv_cache [list],  0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all?
00993                     memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t));
00994                     h->mv_cache_clean[list]= 1;
00995                 }*/
00996                 continue;
00997             }
00998             assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
00999 
01000             h->mv_cache_clean[list]= 0;
01001 
01002             if(USES_LIST(top_type, list)){
01003                 const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;
01004                 AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);
01005                     h->ref_cache[list][scan8[0] + 0 - 1*8]=
01006                     h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 2];
01007                     h->ref_cache[list][scan8[0] + 2 - 1*8]=
01008                     h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 3];
01009             }else{
01010                 AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);
01011                 AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);
01012             }
01013 
01014             if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){
01015             for(i=0; i<2; i++){
01016                 int cache_idx = scan8[0] - 1 + i*2*8;
01017                 if(USES_LIST(left_type[i], list)){
01018                     const int b_xy= h->mb2b_xy[left_xy[i]] + 3;
01019                     const int b8_xy= 4*left_xy[i] + 1;
01020                     AV_COPY32(h->mv_cache[list][cache_idx  ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]);
01021                     AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]);
01022                         h->ref_cache[list][cache_idx  ]= s->current_picture.ref_index[list][b8_xy + (left_block[0+i*2]&~1)];
01023                         h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + (left_block[1+i*2]&~1)];
01024                 }else{
01025                     AV_ZERO32(h->mv_cache [list][cache_idx  ]);
01026                     AV_ZERO32(h->mv_cache [list][cache_idx+8]);
01027                     h->ref_cache[list][cache_idx  ]=
01028                     h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;
01029                 }
01030             }
01031             }else{
01032                 if(USES_LIST(left_type[0], list)){
01033                     const int b_xy= h->mb2b_xy[left_xy[0]] + 3;
01034                     const int b8_xy= 4*left_xy[0] + 1;
01035                     AV_COPY32(h->mv_cache[list][scan8[0] - 1], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0]]);
01036                     h->ref_cache[list][scan8[0] - 1]= s->current_picture.ref_index[list][b8_xy + (left_block[0]&~1)];
01037                 }else{
01038                     AV_ZERO32(h->mv_cache [list][scan8[0] - 1]);
01039                     h->ref_cache[list][scan8[0] - 1]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
01040                 }
01041             }
01042 
01043             if(USES_LIST(topright_type, list)){
01044                 const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride;
01045                 AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]);
01046                 h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][4*topright_xy + 2];
01047             }else{
01048                 AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]);
01049                 h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
01050             }
01051             if(h->ref_cache[list][scan8[0] + 4 - 1*8] < 0){
01052                 if(USES_LIST(topleft_type, list)){
01053                     const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride);
01054                     const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);
01055                     AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]);
01056                     h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy];
01057                 }else{
01058                     AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]);
01059                     h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
01060                 }
01061             }
01062 
01063             if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
01064                 continue;
01065 
01066             if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) {
01067             h->ref_cache[list][scan8[4 ]] =
01068             h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE;
01069             AV_ZERO32(h->mv_cache [list][scan8[4 ]]);
01070             AV_ZERO32(h->mv_cache [list][scan8[12]]);
01071 
01072             if( CABAC ) {
01073                 /* XXX beurk, Load mvd */
01074                 if(USES_LIST(top_type, list)){
01075                     const int b_xy= h->mb2br_xy[top_xy];
01076                     AV_COPY64(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]);
01077                 }else{
01078                     AV_ZERO64(h->mvd_cache[list][scan8[0] + 0 - 1*8]);
01079                 }
01080                 if(USES_LIST(left_type[0], list)){
01081                     const int b_xy= h->mb2br_xy[left_xy[0]] + 6;
01082                     AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy - left_block[0]]);
01083                     AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy - left_block[1]]);
01084                 }else{
01085                     AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 0*8]);
01086                     AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 1*8]);
01087                 }
01088                 if(USES_LIST(left_type[1], list)){
01089                     const int b_xy= h->mb2br_xy[left_xy[1]] + 6;
01090                     AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy - left_block[2]]);
01091                     AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy - left_block[3]]);
01092                 }else{
01093                     AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 2*8]);
01094                     AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 3*8]);
01095                 }
01096                 AV_ZERO16(h->mvd_cache [list][scan8[4 ]]);
01097                 AV_ZERO16(h->mvd_cache [list][scan8[12]]);
01098                 if(h->slice_type_nos == FF_B_TYPE){
01099                     fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1);
01100 
01101                     if(IS_DIRECT(top_type)){
01102                         AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));
01103                     }else if(IS_8X8(top_type)){
01104                         int b8_xy = 4*top_xy;
01105                         h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy + 2];
01106                         h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 3];
01107                     }else{
01108                         AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1));
01109                     }
01110 
01111                     if(IS_DIRECT(left_type[0]))
01112                         h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1;
01113                     else if(IS_8X8(left_type[0]))
01114                         h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[4*left_xy[0] + 1 + (left_block[0]&~1)];
01115                     else
01116                         h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1;
01117 
01118                     if(IS_DIRECT(left_type[1]))
01119                         h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1;
01120                     else if(IS_8X8(left_type[1]))
01121                         h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[4*left_xy[1] + 1 + (left_block[2]&~1)];
01122                     else
01123                         h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1;
01124                 }
01125             }
01126             }
01127             if(FRAME_MBAFF){
01128 #define MAP_MVS\
01129                     MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\
01130                     MAP_F2F(scan8[0] + 0 - 1*8, top_type)\
01131                     MAP_F2F(scan8[0] + 1 - 1*8, top_type)\
01132                     MAP_F2F(scan8[0] + 2 - 1*8, top_type)\
01133                     MAP_F2F(scan8[0] + 3 - 1*8, top_type)\
01134                     MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\
01135                     MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\
01136                     MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\
01137                     MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\
01138                     MAP_F2F(scan8[0] - 1 + 3*8, left_type[1])
01139                 if(MB_FIELD){
01140 #define MAP_F2F(idx, mb_type)\
01141                     if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
01142                         h->ref_cache[list][idx] <<= 1;\
01143                         h->mv_cache[list][idx][1] /= 2;\
01144                         h->mvd_cache[list][idx][1] >>=1;\
01145                     }
01146                     MAP_MVS
01147 #undef MAP_F2F
01148                 }else{
01149 #define MAP_F2F(idx, mb_type)\
01150                     if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
01151                         h->ref_cache[list][idx] >>= 1;\
01152                         h->mv_cache[list][idx][1] <<= 1;\
01153                         h->mvd_cache[list][idx][1] <<= 1;\
01154                     }
01155                     MAP_MVS
01156 #undef MAP_F2F
01157                 }
01158             }
01159         }
01160     }
01161 #endif
01162 
01163         h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]);
01164 }
01165 
01169 static inline int pred_intra_mode(H264Context *h, int n){
01170     const int index8= scan8[n];
01171     const int left= h->intra4x4_pred_mode_cache[index8 - 1];
01172     const int top = h->intra4x4_pred_mode_cache[index8 - 8];
01173     const int min= FFMIN(left, top);
01174 
01175     tprintf(h->s.avctx, "mode:%d %d min:%d\n", left ,top, min);
01176 
01177     if(min<0) return DC_PRED;
01178     else      return min;
01179 }
01180 
01181 static inline void write_back_non_zero_count(H264Context *h){
01182     const int mb_xy= h->mb_xy;
01183 
01184     AV_COPY64(&h->non_zero_count[mb_xy][ 0], &h->non_zero_count_cache[0+8*1]);
01185     AV_COPY64(&h->non_zero_count[mb_xy][ 8], &h->non_zero_count_cache[0+8*2]);
01186     AV_COPY32(&h->non_zero_count[mb_xy][16], &h->non_zero_count_cache[0+8*5]);
01187     AV_COPY32(&h->non_zero_count[mb_xy][20], &h->non_zero_count_cache[4+8*3]);
01188     AV_COPY64(&h->non_zero_count[mb_xy][24], &h->non_zero_count_cache[0+8*4]);
01189 }
01190 
01191 static inline void write_back_motion(H264Context *h, int mb_type){
01192     MpegEncContext * const s = &h->s;
01193     const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; //try mb2b(8)_xy
01194     const int b8_xy= 4*h->mb_xy;
01195     int list;
01196 
01197     if(!USES_LIST(mb_type, 0))
01198         fill_rectangle(&s->current_picture.ref_index[0][b8_xy], 2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
01199 
01200     for(list=0; list<h->list_count; list++){
01201         int y, b_stride;
01202         int16_t (*mv_dst)[2];
01203         int16_t (*mv_src)[2];
01204 
01205         if(!USES_LIST(mb_type, list))
01206             continue;
01207 
01208         b_stride = h->b_stride;
01209         mv_dst   = &s->current_picture.motion_val[list][b_xy];
01210         mv_src   = &h->mv_cache[list][scan8[0]];
01211         for(y=0; y<4; y++){
01212             AV_COPY128(mv_dst + y*b_stride, mv_src + 8*y);
01213         }
01214         if( CABAC ) {
01215             uint8_t (*mvd_dst)[2] = &h->mvd_table[list][FMO ? 8*h->mb_xy : h->mb2br_xy[h->mb_xy]];
01216             uint8_t (*mvd_src)[2] = &h->mvd_cache[list][scan8[0]];
01217             if(IS_SKIP(mb_type))
01218                 AV_ZERO128(mvd_dst);
01219             else{
01220             AV_COPY64(mvd_dst, mvd_src + 8*3);
01221                 AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8*0);
01222                 AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8*1);
01223                 AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8*2);
01224             }
01225         }
01226 
01227         {
01228             int8_t *ref_index = &s->current_picture.ref_index[list][b8_xy];
01229             ref_index[0+0*2]= h->ref_cache[list][scan8[0]];
01230             ref_index[1+0*2]= h->ref_cache[list][scan8[4]];
01231             ref_index[0+1*2]= h->ref_cache[list][scan8[8]];
01232             ref_index[1+1*2]= h->ref_cache[list][scan8[12]];
01233         }
01234     }
01235 
01236     if(h->slice_type_nos == FF_B_TYPE && CABAC){
01237         if(IS_8X8(mb_type)){
01238             uint8_t *direct_table = &h->direct_table[4*h->mb_xy];
01239             direct_table[1] = h->sub_mb_type[1]>>1;
01240             direct_table[2] = h->sub_mb_type[2]>>1;
01241             direct_table[3] = h->sub_mb_type[3]>>1;
01242         }
01243     }
01244 }
01245 
01246 static inline int get_dct8x8_allowed(H264Context *h){
01247     if(h->sps.direct_8x8_inference_flag)
01248         return !(AV_RN64A(h->sub_mb_type) & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8                )*0x0001000100010001ULL));
01249     else
01250         return !(AV_RN64A(h->sub_mb_type) & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8|MB_TYPE_DIRECT2)*0x0001000100010001ULL));
01251 }
01252 
01256 static void decode_mb_skip(H264Context *h){
01257     MpegEncContext * const s = &h->s;
01258     const int mb_xy= h->mb_xy;
01259     int mb_type=0;
01260 
01261     memset(h->non_zero_count[mb_xy], 0, 32);
01262     memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui
01263 
01264     if(MB_FIELD)
01265         mb_type|= MB_TYPE_INTERLACED;
01266 
01267     if( h->slice_type_nos == FF_B_TYPE )
01268     {
01269         // just for fill_caches. pred_direct_motion will set the real mb_type
01270         mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;
01271         if(h->direct_spatial_mv_pred){
01272             fill_decode_neighbors(h, mb_type);
01273         fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ...
01274         }
01275         ff_h264_pred_direct_motion(h, &mb_type);
01276         mb_type|= MB_TYPE_SKIP;
01277     }
01278     else
01279     {
01280         int mx, my;
01281         mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP;
01282 
01283         fill_decode_neighbors(h, mb_type);
01284         fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ...
01285         pred_pskip_motion(h, &mx, &my);
01286         fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
01287         fill_rectangle(  h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4);
01288     }
01289 
01290     write_back_motion(h, mb_type);
01291     s->current_picture.mb_type[mb_xy]= mb_type;
01292     s->current_picture.qscale_table[mb_xy]= s->qscale;
01293     h->slice_table[ mb_xy ]= h->slice_num;
01294     h->prev_mb_skipped= 1;
01295 }
01296 
01297 #include "h264_mvpred.h" //For pred_pskip_motion()
01298 
01299 #endif /* AVCODEC_H264_H */

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