00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 MAX_SPS_COUNT 32
00043 #define MAX_PPS_COUNT 256
00044
00045 #define MAX_MMCO_COUNT 66
00046
00047 #define MAX_DELAYED_PIC_COUNT 16
00048
00049 #define MAX_MBPAIR_SIZE (256*1024) // a tighter bound could be calculated if someone cares about a few bytes
00050
00051
00052
00053 #define ALLOW_INTERLACE
00054
00055 #define FMO 0
00056
00061 #define MAX_SLICES 16
00062
00063 #ifdef ALLOW_INTERLACE
00064 #define MB_MBAFF h->mb_mbaff
00065 #define MB_FIELD h->mb_field_decoding_flag
00066 #define FRAME_MBAFF h->mb_aff_frame
00067 #define FIELD_PICTURE (s->picture_structure != PICT_FRAME)
00068 #define LEFT_MBS 2
00069 #define LTOP 0
00070 #define LBOT 1
00071 #define LEFT(i) (i)
00072 #else
00073 #define MB_MBAFF 0
00074 #define MB_FIELD 0
00075 #define FRAME_MBAFF 0
00076 #define FIELD_PICTURE 0
00077 #undef IS_INTERLACED
00078 #define IS_INTERLACED(mb_type) 0
00079 #define LEFT_MBS 1
00080 #define LTOP 0
00081 #define LBOT 0
00082 #define LEFT(i) 0
00083 #endif
00084 #define FIELD_OR_MBAFF_PICTURE (FRAME_MBAFF || FIELD_PICTURE)
00085
00086 #ifndef CABAC
00087 #define CABAC h->pps.cabac
00088 #endif
00089
00090 #define CHROMA (h->sps.chroma_format_idc)
00091 #define CHROMA422 (h->sps.chroma_format_idc == 2)
00092 #define CHROMA444 (h->sps.chroma_format_idc == 3)
00093
00094 #define EXTENDED_SAR 255
00095
00096 #define MB_TYPE_REF0 MB_TYPE_ACPRED // dirty but it fits in 16 bit
00097 #define MB_TYPE_8x8DCT 0x01000000
00098 #define IS_REF0(a) ((a) & MB_TYPE_REF0)
00099 #define IS_8x8DCT(a) ((a) & MB_TYPE_8x8DCT)
00100
00105 #define DELAYED_PIC_REF 4
00106
00107 #define QP_MAX_NUM (51 + 4*6) // The maximum supported qp
00108
00109
00110 enum {
00111 NAL_SLICE = 1,
00112 NAL_DPA,
00113 NAL_DPB,
00114 NAL_DPC,
00115 NAL_IDR_SLICE,
00116 NAL_SEI,
00117 NAL_SPS,
00118 NAL_PPS,
00119 NAL_AUD,
00120 NAL_END_SEQUENCE,
00121 NAL_END_STREAM,
00122 NAL_FILLER_DATA,
00123 NAL_SPS_EXT,
00124 NAL_AUXILIARY_SLICE = 19
00125 };
00126
00130 typedef enum {
00131 SEI_BUFFERING_PERIOD = 0,
00132 SEI_TYPE_PIC_TIMING = 1,
00133 SEI_TYPE_USER_DATA_UNREGISTERED = 5,
00134 SEI_TYPE_RECOVERY_POINT = 6
00135 } SEI_Type;
00136
00140 typedef enum {
00141 SEI_PIC_STRUCT_FRAME = 0,
00142 SEI_PIC_STRUCT_TOP_FIELD = 1,
00143 SEI_PIC_STRUCT_BOTTOM_FIELD = 2,
00144 SEI_PIC_STRUCT_TOP_BOTTOM = 3,
00145 SEI_PIC_STRUCT_BOTTOM_TOP = 4,
00146 SEI_PIC_STRUCT_TOP_BOTTOM_TOP = 5,
00147 SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6,
00148 SEI_PIC_STRUCT_FRAME_DOUBLING = 7,
00149 SEI_PIC_STRUCT_FRAME_TRIPLING = 8
00150 } SEI_PicStructType;
00151
00155 typedef struct SPS {
00156 int profile_idc;
00157 int level_idc;
00158 int chroma_format_idc;
00159 int transform_bypass;
00160 int log2_max_frame_num;
00161 int poc_type;
00162 int log2_max_poc_lsb;
00163 int delta_pic_order_always_zero_flag;
00164 int offset_for_non_ref_pic;
00165 int offset_for_top_to_bottom_field;
00166 int poc_cycle_length;
00167 int ref_frame_count;
00168 int gaps_in_frame_num_allowed_flag;
00169 int mb_width;
00170 int mb_height;
00171 int frame_mbs_only_flag;
00172 int mb_aff;
00173 int direct_8x8_inference_flag;
00174 int crop;
00175 unsigned int crop_left;
00176 unsigned int crop_right;
00177 unsigned int crop_top;
00178 unsigned int crop_bottom;
00179 int vui_parameters_present_flag;
00180 AVRational sar;
00181 int video_signal_type_present_flag;
00182 int full_range;
00183 int colour_description_present_flag;
00184 enum AVColorPrimaries color_primaries;
00185 enum AVColorTransferCharacteristic color_trc;
00186 enum AVColorSpace colorspace;
00187 int timing_info_present_flag;
00188 uint32_t num_units_in_tick;
00189 uint32_t time_scale;
00190 int fixed_frame_rate_flag;
00191 short offset_for_ref_frame[256];
00192 int bitstream_restriction_flag;
00193 int num_reorder_frames;
00194 int scaling_matrix_present;
00195 uint8_t scaling_matrix4[6][16];
00196 uint8_t scaling_matrix8[6][64];
00197 int nal_hrd_parameters_present_flag;
00198 int vcl_hrd_parameters_present_flag;
00199 int pic_struct_present_flag;
00200 int time_offset_length;
00201 int cpb_cnt;
00202 int initial_cpb_removal_delay_length;
00203 int cpb_removal_delay_length;
00204 int dpb_output_delay_length;
00205 int bit_depth_luma;
00206 int bit_depth_chroma;
00207 int residual_color_transform_flag;
00208 int constraint_set_flags;
00209 } SPS;
00210
00214 typedef struct PPS {
00215 unsigned int sps_id;
00216 int cabac;
00217 int pic_order_present;
00218 int slice_group_count;
00219 int mb_slice_group_map_type;
00220 unsigned int ref_count[2];
00221 int weighted_pred;
00222 int weighted_bipred_idc;
00223 int init_qp;
00224 int init_qs;
00225 int chroma_qp_index_offset[2];
00226 int deblocking_filter_parameters_present;
00227 int constrained_intra_pred;
00228 int redundant_pic_cnt_present;
00229 int transform_8x8_mode;
00230 uint8_t scaling_matrix4[6][16];
00231 uint8_t scaling_matrix8[6][64];
00232 uint8_t chroma_qp_table[2][QP_MAX_NUM+1];
00233 int chroma_qp_diff;
00234 } PPS;
00235
00239 typedef enum MMCOOpcode {
00240 MMCO_END = 0,
00241 MMCO_SHORT2UNUSED,
00242 MMCO_LONG2UNUSED,
00243 MMCO_SHORT2LONG,
00244 MMCO_SET_MAX_LONG,
00245 MMCO_RESET,
00246 MMCO_LONG,
00247 } MMCOOpcode;
00248
00252 typedef struct MMCO {
00253 MMCOOpcode opcode;
00254 int short_pic_num;
00255 int long_arg;
00256 } MMCO;
00257
00261 typedef struct H264Context {
00262 MpegEncContext s;
00263 H264DSPContext h264dsp;
00264 int pixel_shift;
00265 int chroma_qp[2];
00266
00267 int qp_thresh;
00268
00269 int prev_mb_skipped;
00270 int next_mb_skipped;
00271
00272
00273 int chroma_pred_mode;
00274 int intra16x16_pred_mode;
00275
00276 int topleft_mb_xy;
00277 int top_mb_xy;
00278 int topright_mb_xy;
00279 int left_mb_xy[LEFT_MBS];
00280
00281 int topleft_type;
00282 int top_type;
00283 int topright_type;
00284 int left_type[LEFT_MBS];
00285
00286 const uint8_t *left_block;
00287 int topleft_partition;
00288
00289 int8_t intra4x4_pred_mode_cache[5 * 8];
00290 int8_t(*intra4x4_pred_mode);
00291 H264PredContext hpc;
00292 unsigned int topleft_samples_available;
00293 unsigned int top_samples_available;
00294 unsigned int topright_samples_available;
00295 unsigned int left_samples_available;
00296 uint8_t (*top_borders[2])[(16 * 3) * 2];
00297
00302 DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15 * 8];
00303
00304 uint8_t (*non_zero_count)[48];
00305
00309 DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5 * 8][2];
00310 DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5 * 8];
00311 #define LIST_NOT_USED -1 // FIXME rename?
00312 #define PART_NOT_AVAILABLE -2
00313
00317 int neighbor_transform_size;
00318
00323 int block_offset[2 * (16 * 3)];
00324
00325 uint32_t *mb2b_xy;
00326 uint32_t *mb2br_xy;
00327 int b_stride;
00328
00329 int mb_linesize;
00330 int mb_uvlinesize;
00331
00332 int emu_edge_width;
00333 int emu_edge_height;
00334
00335 SPS sps;
00336
00340 PPS pps;
00341
00342 uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16];
00343 uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
00344 uint32_t(*dequant4_coeff[6])[16];
00345 uint32_t(*dequant8_coeff[6])[64];
00346
00347 int slice_num;
00348 uint16_t *slice_table;
00349 int slice_type;
00350 int slice_type_nos;
00351 int slice_type_fixed;
00352
00353
00354 int mb_aff_frame;
00355 int mb_field_decoding_flag;
00356 int mb_mbaff;
00357
00358 DECLARE_ALIGNED(8, uint16_t, sub_mb_type)[4];
00359
00360
00361 int use_weight;
00362 int use_weight_chroma;
00363 int luma_log2_weight_denom;
00364 int chroma_log2_weight_denom;
00365
00366 int luma_weight[48][2][2];
00367 int chroma_weight[48][2][2][2];
00368 int implicit_weight[48][48][2];
00369
00370 int direct_spatial_mv_pred;
00371 int col_parity;
00372 int col_fieldoff;
00373 int dist_scale_factor[16];
00374 int dist_scale_factor_field[2][32];
00375 int map_col_to_list0[2][16 + 32];
00376 int map_col_to_list0_field[2][2][16 + 32];
00377
00381 unsigned int ref_count[2];
00382 unsigned int list_count;
00383 uint8_t *list_counts;
00384 Picture ref_list[2][48];
00387 int ref2frm[MAX_SLICES][2][64];
00388
00389
00390 GetBitContext intra_gb;
00391 GetBitContext inter_gb;
00392 GetBitContext *intra_gb_ptr;
00393 GetBitContext *inter_gb_ptr;
00394
00395 DECLARE_ALIGNED(16, DCTELEM, mb)[16 * 48 * 2];
00396 DECLARE_ALIGNED(16, DCTELEM, mb_luma_dc)[3][16 * 2];
00397 DCTELEM mb_padding[256 * 2];
00398
00402 CABACContext cabac;
00403 uint8_t cabac_state[1024];
00404
00405
00406 uint16_t *cbp_table;
00407 int cbp;
00408 int top_cbp;
00409 int left_cbp;
00410
00411 uint8_t *chroma_pred_mode_table;
00412 int last_qscale_diff;
00413 uint8_t (*mvd_table[2])[2];
00414 DECLARE_ALIGNED(16, uint8_t, mvd_cache)[2][5 * 8][2];
00415 uint8_t *direct_table;
00416 uint8_t direct_cache[5 * 8];
00417
00418 uint8_t zigzag_scan[16];
00419 uint8_t zigzag_scan8x8[64];
00420 uint8_t zigzag_scan8x8_cavlc[64];
00421 uint8_t field_scan[16];
00422 uint8_t field_scan8x8[64];
00423 uint8_t field_scan8x8_cavlc[64];
00424 uint8_t zigzag_scan_q0[16];
00425 uint8_t zigzag_scan8x8_q0[64];
00426 uint8_t zigzag_scan8x8_cavlc_q0[64];
00427 uint8_t field_scan_q0[16];
00428 uint8_t field_scan8x8_q0[64];
00429 uint8_t field_scan8x8_cavlc_q0[64];
00430
00431 int x264_build;
00432
00433 int mb_xy;
00434
00435 int is_complex;
00436
00437
00438 int deblocking_filter;
00439 int slice_alpha_c0_offset;
00440 int slice_beta_offset;
00441
00442
00443
00444
00445 int nal_ref_idc;
00446 int nal_unit_type;
00447 uint8_t *rbsp_buffer[2];
00448 unsigned int rbsp_buffer_size[2];
00449
00453 int is_avc;
00454 int nal_length_size;
00455 int got_first;
00456
00457 SPS *sps_buffers[MAX_SPS_COUNT];
00458 PPS *pps_buffers[MAX_PPS_COUNT];
00459
00460 int dequant_coeff_pps;
00461
00462 uint16_t *slice_table_base;
00463
00464
00465 int poc_lsb;
00466 int poc_msb;
00467 int delta_poc_bottom;
00468 int delta_poc[2];
00469 int frame_num;
00470 int prev_poc_msb;
00471 int prev_poc_lsb;
00472 int frame_num_offset;
00473 int prev_frame_num_offset;
00474 int prev_frame_num;
00475
00479 int curr_pic_num;
00480
00484 int max_pic_num;
00485
00486 int redundant_pic_count;
00487
00488 Picture *short_ref[32];
00489 Picture *long_ref[32];
00490 Picture default_ref_list[2][32];
00491 Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2];
00492 int last_pocs[MAX_DELAYED_PIC_COUNT];
00493 Picture *next_output_pic;
00494 int outputed_poc;
00495 int next_outputed_poc;
00496
00500 MMCO mmco[MAX_MMCO_COUNT];
00501 int mmco_index;
00502 int mmco_reset;
00503
00504 int long_ref_count;
00505 int short_ref_count;
00506
00507 int cabac_init_idc;
00508
00513 struct H264Context *thread_context[MAX_THREADS];
00514
00518 int current_slice;
00519
00526 int max_contexts;
00527
00532 int single_decode_warning;
00533
00534 int last_slice_type;
00540 SEI_PicStructType sei_pic_struct;
00541
00548 int prev_interlaced_frame;
00549
00555 int sei_ct_type;
00556
00560 int sei_dpb_output_delay;
00561
00565 int sei_cpb_removal_delay;
00566
00574 int sei_recovery_frame_cnt;
00581 int recovery_frame;
00582
00583 int luma_weight_flag[2];
00584 int chroma_weight_flag[2];
00585
00586
00587 int sei_buffering_period_present;
00588 int initial_cpb_removal_delay[32];
00589
00590 int cur_chroma_format_idc;
00591
00592 int16_t slice_row[MAX_SLICES];
00593
00594 int sync;
00595
00596 uint8_t parse_history[4];
00597 int parse_history_count;
00598 int parse_last_mb;
00599 } H264Context;
00600
00601 extern const uint8_t ff_h264_chroma_qp[5][QP_MAX_NUM + 1];
00602 extern const uint16_t ff_h264_mb_sizes[4];
00603
00607 int ff_h264_decode_sei(H264Context *h);
00608
00612 int ff_h264_decode_seq_parameter_set(H264Context *h);
00613
00617 int ff_h264_get_profile(SPS *sps);
00618
00622 int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length);
00623
00632 const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src,
00633 int *dst_length, int *consumed, int length);
00634
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 void ff_generate_sliding_window_mmcos(H264Context *h);
00669
00674 int ff_h264_check_intra4x4_pred_mode(H264Context *h);
00675
00680 int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma);
00681
00682 void ff_h264_hl_decode_mb(H264Context *h);
00683 int ff_h264_frame_start(H264Context *h);
00684 int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size);
00685 av_cold int ff_h264_decode_init(AVCodecContext *avctx);
00686 av_cold void ff_h264_decode_init_vlc(void);
00687
00692 int ff_h264_decode_mb_cavlc(H264Context *h);
00693
00698 int ff_h264_decode_mb_cabac(H264Context *h);
00699
00700 void ff_h264_init_cabac_states(H264Context *h);
00701
00702 void ff_h264_direct_dist_scale_factor(H264Context *const h);
00703 void ff_h264_direct_ref_list_init(H264Context *const h);
00704 void ff_h264_pred_direct_motion(H264Context *const h, int *mb_type);
00705
00706 void ff_h264_filter_mb_fast(H264Context *h, int mb_x, int mb_y,
00707 uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
00708 unsigned int linesize, unsigned int uvlinesize);
00709 void ff_h264_filter_mb(H264Context *h, int mb_x, int mb_y,
00710 uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
00711 unsigned int linesize, unsigned int uvlinesize);
00712
00718 void ff_h264_reset_sei(H264Context *h);
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750 #define LUMA_DC_BLOCK_INDEX 48
00751 #define CHROMA_DC_BLOCK_INDEX 49
00752
00753
00754 static const uint8_t scan8[16 * 3 + 3] = {
00755 4 + 1 * 8, 5 + 1 * 8, 4 + 2 * 8, 5 + 2 * 8,
00756 6 + 1 * 8, 7 + 1 * 8, 6 + 2 * 8, 7 + 2 * 8,
00757 4 + 3 * 8, 5 + 3 * 8, 4 + 4 * 8, 5 + 4 * 8,
00758 6 + 3 * 8, 7 + 3 * 8, 6 + 4 * 8, 7 + 4 * 8,
00759 4 + 6 * 8, 5 + 6 * 8, 4 + 7 * 8, 5 + 7 * 8,
00760 6 + 6 * 8, 7 + 6 * 8, 6 + 7 * 8, 7 + 7 * 8,
00761 4 + 8 * 8, 5 + 8 * 8, 4 + 9 * 8, 5 + 9 * 8,
00762 6 + 8 * 8, 7 + 8 * 8, 6 + 9 * 8, 7 + 9 * 8,
00763 4 + 11 * 8, 5 + 11 * 8, 4 + 12 * 8, 5 + 12 * 8,
00764 6 + 11 * 8, 7 + 11 * 8, 6 + 12 * 8, 7 + 12 * 8,
00765 4 + 13 * 8, 5 + 13 * 8, 4 + 14 * 8, 5 + 14 * 8,
00766 6 + 13 * 8, 7 + 13 * 8, 6 + 14 * 8, 7 + 14 * 8,
00767 0 + 0 * 8, 0 + 5 * 8, 0 + 10 * 8
00768 };
00769
00770 static av_always_inline uint32_t pack16to32(int a, int b)
00771 {
00772 #if HAVE_BIGENDIAN
00773 return (b & 0xFFFF) + (a << 16);
00774 #else
00775 return (a & 0xFFFF) + (b << 16);
00776 #endif
00777 }
00778
00779 static av_always_inline uint16_t pack8to16(int a, int b)
00780 {
00781 #if HAVE_BIGENDIAN
00782 return (b & 0xFF) + (a << 8);
00783 #else
00784 return (a & 0xFF) + (b << 8);
00785 #endif
00786 }
00787
00791 static av_always_inline int get_chroma_qp(H264Context *h, int t, int qscale)
00792 {
00793 return h->pps.chroma_qp_table[t][qscale];
00794 }
00795
00799 static av_always_inline int pred_intra_mode(H264Context *h, int n)
00800 {
00801 const int index8 = scan8[n];
00802 const int left = h->intra4x4_pred_mode_cache[index8 - 1];
00803 const int top = h->intra4x4_pred_mode_cache[index8 - 8];
00804 const int min = FFMIN(left, top);
00805
00806 tprintf(h->s.avctx, "mode:%d %d min:%d\n", left, top, min);
00807
00808 if (min < 0)
00809 return DC_PRED;
00810 else
00811 return min;
00812 }
00813
00814 static av_always_inline void write_back_intra_pred_mode(H264Context *h)
00815 {
00816 int8_t *i4x4 = h->intra4x4_pred_mode + h->mb2br_xy[h->mb_xy];
00817 int8_t *i4x4_cache = h->intra4x4_pred_mode_cache;
00818
00819 AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
00820 i4x4[4] = i4x4_cache[7 + 8 * 3];
00821 i4x4[5] = i4x4_cache[7 + 8 * 2];
00822 i4x4[6] = i4x4_cache[7 + 8 * 1];
00823 }
00824
00825 static av_always_inline void write_back_non_zero_count(H264Context *h)
00826 {
00827 const int mb_xy = h->mb_xy;
00828 uint8_t *nnz = h->non_zero_count[mb_xy];
00829 uint8_t *nnz_cache = h->non_zero_count_cache;
00830
00831 AV_COPY32(&nnz[ 0], &nnz_cache[4 + 8 * 1]);
00832 AV_COPY32(&nnz[ 4], &nnz_cache[4 + 8 * 2]);
00833 AV_COPY32(&nnz[ 8], &nnz_cache[4 + 8 * 3]);
00834 AV_COPY32(&nnz[12], &nnz_cache[4 + 8 * 4]);
00835 AV_COPY32(&nnz[16], &nnz_cache[4 + 8 * 6]);
00836 AV_COPY32(&nnz[20], &nnz_cache[4 + 8 * 7]);
00837 AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]);
00838 AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]);
00839
00840 if (!h->s.chroma_y_shift) {
00841 AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]);
00842 AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]);
00843 AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]);
00844 AV_COPY32(&nnz[44], &nnz_cache[4 + 8 * 14]);
00845 }
00846 }
00847
00848 static av_always_inline void write_back_motion_list(H264Context *h,
00849 MpegEncContext *const s,
00850 int b_stride,
00851 int b_xy, int b8_xy,
00852 int mb_type, int list)
00853 {
00854 int16_t(*mv_dst)[2] = &s->current_picture.f.motion_val[list][b_xy];
00855 int16_t(*mv_src)[2] = &h->mv_cache[list][scan8[0]];
00856 AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0);
00857 AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1);
00858 AV_COPY128(mv_dst + 2 * b_stride, mv_src + 8 * 2);
00859 AV_COPY128(mv_dst + 3 * b_stride, mv_src + 8 * 3);
00860 if (CABAC) {
00861 uint8_t (*mvd_dst)[2] = &h->mvd_table[list][FMO ? 8 * h->mb_xy
00862 : h->mb2br_xy[h->mb_xy]];
00863 uint8_t(*mvd_src)[2] = &h->mvd_cache[list][scan8[0]];
00864 if (IS_SKIP(mb_type)) {
00865 AV_ZERO128(mvd_dst);
00866 } else {
00867 AV_COPY64(mvd_dst, mvd_src + 8 * 3);
00868 AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8 * 0);
00869 AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8 * 1);
00870 AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8 * 2);
00871 }
00872 }
00873
00874 {
00875 int8_t *ref_index = &s->current_picture.f.ref_index[list][b8_xy];
00876 int8_t *ref_cache = h->ref_cache[list];
00877 ref_index[0 + 0 * 2] = ref_cache[scan8[0]];
00878 ref_index[1 + 0 * 2] = ref_cache[scan8[4]];
00879 ref_index[0 + 1 * 2] = ref_cache[scan8[8]];
00880 ref_index[1 + 1 * 2] = ref_cache[scan8[12]];
00881 }
00882 }
00883
00884 static av_always_inline void write_back_motion(H264Context *h, int mb_type)
00885 {
00886 MpegEncContext *const s = &h->s;
00887 const int b_stride = h->b_stride;
00888 const int b_xy = 4 * s->mb_x + 4 * s->mb_y * h->b_stride;
00889 const int b8_xy = 4 * h->mb_xy;
00890
00891 if (USES_LIST(mb_type, 0)) {
00892 write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 0);
00893 } else {
00894 fill_rectangle(&s->current_picture.f.ref_index[0][b8_xy],
00895 2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
00896 }
00897 if (USES_LIST(mb_type, 1))
00898 write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 1);
00899
00900 if (h->slice_type_nos == AV_PICTURE_TYPE_B && CABAC) {
00901 if (IS_8X8(mb_type)) {
00902 uint8_t *direct_table = &h->direct_table[4 * h->mb_xy];
00903 direct_table[1] = h->sub_mb_type[1] >> 1;
00904 direct_table[2] = h->sub_mb_type[2] >> 1;
00905 direct_table[3] = h->sub_mb_type[3] >> 1;
00906 }
00907 }
00908 }
00909
00910 static av_always_inline int get_dct8x8_allowed(H264Context *h)
00911 {
00912 if (h->sps.direct_8x8_inference_flag)
00913 return !(AV_RN64A(h->sub_mb_type) &
00914 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8) *
00915 0x0001000100010001ULL));
00916 else
00917 return !(AV_RN64A(h->sub_mb_type) &
00918 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8 | MB_TYPE_DIRECT2) *
00919 0x0001000100010001ULL));
00920 }
00921
00922 #endif