Mercurial > libavcodec.hg
annotate h264.c @ 2548:bca31bc0cbae libavcodec
spam
| author | michael |
|---|---|
| date | Sun, 06 Mar 2005 19:59:37 +0000 |
| parents | c5781912ad8a |
| children | 615995277bc5 |
| rev | line source |
|---|---|
| 1168 | 1 /* |
| 2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder | |
| 3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
| 4 * | |
| 5 * This library is free software; you can redistribute it and/or | |
| 6 * modify it under the terms of the GNU Lesser General Public | |
| 7 * License as published by the Free Software Foundation; either | |
| 8 * version 2 of the License, or (at your option) any later version. | |
| 9 * | |
| 10 * This library is distributed in the hope that it will be useful, | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 * Lesser General Public License for more details. | |
| 14 * | |
| 15 * You should have received a copy of the GNU Lesser General Public | |
| 16 * License along with this library; if not, write to the Free Software | |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 * | |
| 19 */ | |
| 20 | |
| 21 /** | |
| 22 * @file h264.c | |
| 23 * H.264 / AVC / MPEG4 part10 codec. | |
| 24 * @author Michael Niedermayer <michaelni@gmx.at> | |
| 25 */ | |
| 26 | |
| 27 #include "common.h" | |
| 28 #include "dsputil.h" | |
| 29 #include "avcodec.h" | |
| 30 #include "mpegvideo.h" | |
| 31 #include "h264data.h" | |
| 32 #include "golomb.h" | |
| 33 | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
34 #include "cabac.h" |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
35 |
| 1168 | 36 #undef NDEBUG |
| 37 #include <assert.h> | |
| 38 | |
| 39 #define interlaced_dct interlaced_dct_is_a_bad_name | |
| 40 #define mb_intra mb_intra_isnt_initalized_see_mb_type | |
| 41 | |
| 42 #define LUMA_DC_BLOCK_INDEX 25 | |
| 43 #define CHROMA_DC_BLOCK_INDEX 26 | |
| 44 | |
| 45 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8 | |
| 46 #define COEFF_TOKEN_VLC_BITS 8 | |
| 47 #define TOTAL_ZEROS_VLC_BITS 9 | |
| 48 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3 | |
| 49 #define RUN_VLC_BITS 3 | |
| 50 #define RUN7_VLC_BITS 6 | |
| 51 | |
| 52 #define MAX_SPS_COUNT 32 | |
| 53 #define MAX_PPS_COUNT 256 | |
| 54 | |
| 55 #define MAX_MMCO_COUNT 66 | |
| 56 | |
| 57 /** | |
| 58 * Sequence parameter set | |
| 59 */ | |
| 60 typedef struct SPS{ | |
| 61 | |
| 62 int profile_idc; | |
| 63 int level_idc; | |
| 64 int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4 | |
| 65 int poc_type; ///< pic_order_cnt_type | |
| 66 int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4 | |
| 67 int delta_pic_order_always_zero_flag; | |
| 68 int offset_for_non_ref_pic; | |
| 69 int offset_for_top_to_bottom_field; | |
| 70 int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle | |
| 71 int ref_frame_count; ///< num_ref_frames | |
| 1371 | 72 int gaps_in_frame_num_allowed_flag; |
| 1168 | 73 int mb_width; ///< frame_width_in_mbs_minus1 + 1 |
| 74 int mb_height; ///< frame_height_in_mbs_minus1 + 1 | |
| 75 int frame_mbs_only_flag; | |
| 76 int mb_aff; ///<mb_adaptive_frame_field_flag | |
| 77 int direct_8x8_inference_flag; | |
| 1371 | 78 int crop; ///< frame_cropping_flag |
| 79 int crop_left; ///< frame_cropping_rect_left_offset | |
| 80 int crop_right; ///< frame_cropping_rect_right_offset | |
| 81 int crop_top; ///< frame_cropping_rect_top_offset | |
| 82 int crop_bottom; ///< frame_cropping_rect_bottom_offset | |
| 1168 | 83 int vui_parameters_present_flag; |
| 1548 | 84 AVRational sar; |
|
2174
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
85 int timing_info_present_flag; |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
86 uint32_t num_units_in_tick; |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
87 uint32_t time_scale; |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
88 int fixed_frame_rate_flag; |
| 1168 | 89 short offset_for_ref_frame[256]; //FIXME dyn aloc? |
| 90 }SPS; | |
| 91 | |
| 92 /** | |
| 93 * Picture parameter set | |
| 94 */ | |
| 95 typedef struct PPS{ | |
| 96 int sps_id; | |
| 97 int cabac; ///< entropy_coding_mode_flag | |
| 98 int pic_order_present; ///< pic_order_present_flag | |
| 99 int slice_group_count; ///< num_slice_groups_minus1 + 1 | |
| 100 int mb_slice_group_map_type; | |
| 101 int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1 | |
| 102 int weighted_pred; ///< weighted_pred_flag | |
| 103 int weighted_bipred_idc; | |
| 104 int init_qp; ///< pic_init_qp_minus26 + 26 | |
| 105 int init_qs; ///< pic_init_qs_minus26 + 26 | |
| 106 int chroma_qp_index_offset; | |
| 107 int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag | |
| 108 int constrained_intra_pred; ///< constrained_intra_pred_flag | |
| 109 int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag | |
| 110 }PPS; | |
| 111 | |
| 112 /** | |
| 113 * Memory management control operation opcode. | |
| 114 */ | |
| 115 typedef enum MMCOOpcode{ | |
| 116 MMCO_END=0, | |
| 117 MMCO_SHORT2UNUSED, | |
| 118 MMCO_LONG2UNUSED, | |
| 119 MMCO_SHORT2LONG, | |
| 120 MMCO_SET_MAX_LONG, | |
| 121 MMCO_RESET, | |
| 122 MMCO_LONG, | |
| 123 } MMCOOpcode; | |
| 124 | |
| 125 /** | |
| 126 * Memory management control operation. | |
| 127 */ | |
| 128 typedef struct MMCO{ | |
| 129 MMCOOpcode opcode; | |
| 130 int short_frame_num; | |
| 131 int long_index; | |
| 132 } MMCO; | |
| 133 | |
| 134 /** | |
| 135 * H264Context | |
| 136 */ | |
| 137 typedef struct H264Context{ | |
| 138 MpegEncContext s; | |
| 139 int nal_ref_idc; | |
| 140 int nal_unit_type; | |
| 141 #define NAL_SLICE 1 | |
| 142 #define NAL_DPA 2 | |
| 143 #define NAL_DPB 3 | |
| 144 #define NAL_DPC 4 | |
| 145 #define NAL_IDR_SLICE 5 | |
| 146 #define NAL_SEI 6 | |
| 147 #define NAL_SPS 7 | |
| 148 #define NAL_PPS 8 | |
| 149 #define NAL_PICTURE_DELIMITER 9 | |
| 150 #define NAL_FILTER_DATA 10 | |
| 151 uint8_t *rbsp_buffer; | |
| 152 int rbsp_buffer_size; | |
| 153 | |
| 2227 | 154 /** |
| 155 * Used to parse AVC variant of h264 | |
| 156 */ | |
| 157 int is_avc; ///< this flag is != 0 if codec is avc1 | |
| 158 int got_avcC; ///< flag used to parse avcC data only once | |
| 159 int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) | |
| 160 | |
| 1168 | 161 int chroma_qp; //QPc |
| 162 | |
| 163 int prev_mb_skiped; //FIXME remove (IMHO not used) | |
| 164 | |
| 165 //prediction stuff | |
| 166 int chroma_pred_mode; | |
| 167 int intra16x16_pred_mode; | |
| 168 | |
| 169 int8_t intra4x4_pred_mode_cache[5*8]; | |
| 170 int8_t (*intra4x4_pred_mode)[8]; | |
| 171 void (*pred4x4 [9+3])(uint8_t *src, uint8_t *topright, int stride);//FIXME move to dsp? | |
| 172 void (*pred8x8 [4+3])(uint8_t *src, int stride); | |
| 173 void (*pred16x16[4+3])(uint8_t *src, int stride); | |
| 174 unsigned int topleft_samples_available; | |
| 175 unsigned int top_samples_available; | |
| 176 unsigned int topright_samples_available; | |
| 177 unsigned int left_samples_available; | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
178 uint8_t (*top_border)[16+2*8]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
179 uint8_t left_border[17+2*9]; |
| 1168 | 180 |
| 181 /** | |
| 182 * non zero coeff count cache. | |
| 183 * is 64 if not available. | |
| 184 */ | |
|
2471
805431763e84
fixing missaligned memory accesses in fill_rectangle()
michael
parents:
2454
diff
changeset
|
185 uint8_t non_zero_count_cache[6*8] __align8; |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
186 uint8_t (*non_zero_count)[16]; |
| 1168 | 187 |
| 188 /** | |
| 189 * Motion vector cache. | |
| 190 */ | |
|
2471
805431763e84
fixing missaligned memory accesses in fill_rectangle()
michael
parents:
2454
diff
changeset
|
191 int16_t mv_cache[2][5*8][2] __align8; |
|
805431763e84
fixing missaligned memory accesses in fill_rectangle()
michael
parents:
2454
diff
changeset
|
192 int8_t ref_cache[2][5*8] __align8; |
| 1168 | 193 #define LIST_NOT_USED -1 //FIXME rename? |
| 194 #define PART_NOT_AVAILABLE -2 | |
| 195 | |
| 196 /** | |
| 197 * is 1 if the specific list MV&references are set to 0,0,-2. | |
| 198 */ | |
| 199 int mv_cache_clean[2]; | |
| 200 | |
| 201 int block_offset[16+8]; | |
| 202 int chroma_subblock_offset[16]; //FIXME remove | |
| 203 | |
| 204 uint16_t *mb2b_xy; //FIXME are these 4 a good idea? | |
| 205 uint16_t *mb2b8_xy; | |
| 2395 | 206 int b_stride; //FIXME use s->b4_stride |
| 1168 | 207 int b8_stride; |
| 208 | |
| 1234 | 209 int halfpel_flag; |
| 210 int thirdpel_flag; | |
| 211 | |
| 1319 | 212 int unknown_svq3_flag; |
| 213 int next_slice_index; | |
| 214 | |
| 1168 | 215 SPS sps_buffer[MAX_SPS_COUNT]; |
| 216 SPS sps; ///< current sps | |
| 217 | |
| 218 PPS pps_buffer[MAX_PPS_COUNT]; | |
| 219 /** | |
| 220 * current pps | |
| 221 */ | |
| 222 PPS pps; //FIXME move tp Picture perhaps? (->no) do we need that? | |
| 223 | |
| 224 int slice_num; | |
| 225 uint8_t *slice_table_base; | |
| 226 uint8_t *slice_table; ///< slice_table_base + mb_stride + 1 | |
| 227 int slice_type; | |
| 228 int slice_type_fixed; | |
| 229 | |
| 230 //interlacing specific flags | |
| 231 int mb_field_decoding_flag; | |
| 232 | |
| 233 int sub_mb_type[4]; | |
| 234 | |
| 235 //POC stuff | |
| 236 int poc_lsb; | |
| 237 int poc_msb; | |
| 238 int delta_poc_bottom; | |
| 239 int delta_poc[2]; | |
| 240 int frame_num; | |
| 241 int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0 | |
| 242 int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0 | |
| 243 int frame_num_offset; ///< for POC type 2 | |
| 244 int prev_frame_num_offset; ///< for POC type 2 | |
| 245 int prev_frame_num; ///< frame_num of the last pic for POC type 1/2 | |
| 246 | |
| 247 /** | |
| 248 * frame_num for frames or 2*frame_num for field pics. | |
| 249 */ | |
| 250 int curr_pic_num; | |
| 251 | |
| 252 /** | |
| 253 * max_frame_num or 2*max_frame_num for field pics. | |
| 254 */ | |
| 255 int max_pic_num; | |
| 256 | |
| 257 //Weighted pred stuff | |
| 2415 | 258 int use_weight; |
| 259 int use_weight_chroma; | |
| 1168 | 260 int luma_log2_weight_denom; |
| 261 int chroma_log2_weight_denom; | |
| 262 int luma_weight[2][16]; | |
| 263 int luma_offset[2][16]; | |
| 264 int chroma_weight[2][16][2]; | |
| 265 int chroma_offset[2][16][2]; | |
| 2415 | 266 int implicit_weight[16][16]; |
| 1168 | 267 |
| 268 //deblock | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
269 int deblocking_filter; ///< disable_deblocking_filter_idc with 1<->0 |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
270 int slice_alpha_c0_offset; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
271 int slice_beta_offset; |
| 1168 | 272 |
| 273 int redundant_pic_count; | |
| 274 | |
| 275 int direct_spatial_mv_pred; | |
| 2396 | 276 int dist_scale_factor[16]; |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
277 int map_col_to_list0[2][16]; |
| 1168 | 278 |
| 279 /** | |
| 280 * num_ref_idx_l0/1_active_minus1 + 1 | |
| 281 */ | |
| 282 int ref_count[2];// FIXME split for AFF | |
| 283 Picture *short_ref[16]; | |
| 284 Picture *long_ref[16]; | |
| 285 Picture default_ref_list[2][32]; | |
| 286 Picture ref_list[2][32]; //FIXME size? | |
| 287 Picture field_ref_list[2][32]; //FIXME size? | |
| 2409 | 288 Picture *delayed_pic[16]; //FIXME size? |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
289 int delayed_output_poc; |
| 1168 | 290 |
| 291 /** | |
| 292 * memory management control operations buffer. | |
| 293 */ | |
| 294 MMCO mmco[MAX_MMCO_COUNT]; | |
| 295 int mmco_index; | |
| 296 | |
| 297 int long_ref_count; ///< number of actual long term references | |
| 298 int short_ref_count; ///< number of actual short term references | |
| 299 | |
| 300 //data partitioning | |
| 301 GetBitContext intra_gb; | |
| 302 GetBitContext inter_gb; | |
| 303 GetBitContext *intra_gb_ptr; | |
| 304 GetBitContext *inter_gb_ptr; | |
| 305 | |
| 306 DCTELEM mb[16*24] __align8; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
307 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
308 /** |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
309 * Cabac |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
310 */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
311 CABACContext cabac; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
312 uint8_t cabac_state[399]; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
313 int cabac_init_idc; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
314 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
315 /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
316 uint16_t *cbp_table; |
| 2314 | 317 int top_cbp; |
| 318 int left_cbp; | |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
319 /* chroma_pred_mode for i4x4 or i16x16, else 0 */ |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
320 uint8_t *chroma_pred_mode_table; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
321 int last_qscale_diff; |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
322 int16_t (*mvd_table[2])[2]; |
|
2471
805431763e84
fixing missaligned memory accesses in fill_rectangle()
michael
parents:
2454
diff
changeset
|
323 int16_t mvd_cache[2][5*8][2] __align8; |
| 2396 | 324 uint8_t *direct_table; |
| 325 uint8_t direct_cache[5*8]; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
326 |
| 1168 | 327 }H264Context; |
| 328 | |
| 329 static VLC coeff_token_vlc[4]; | |
| 330 static VLC chroma_dc_coeff_token_vlc; | |
| 331 | |
| 332 static VLC total_zeros_vlc[15]; | |
| 333 static VLC chroma_dc_total_zeros_vlc[3]; | |
| 334 | |
| 335 static VLC run_vlc[6]; | |
| 336 static VLC run7_vlc; | |
| 337 | |
| 1234 | 338 static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp); |
| 339 static void svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc); | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
340 static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr); |
| 1234 | 341 |
| 1269 | 342 static inline uint32_t pack16to32(int a, int b){ |
| 343 #ifdef WORDS_BIGENDIAN | |
| 344 return (b&0xFFFF) + (a<<16); | |
| 345 #else | |
| 346 return (a&0xFFFF) + (b<<16); | |
| 347 #endif | |
| 348 } | |
| 349 | |
| 1168 | 350 /** |
| 351 * fill a rectangle. | |
| 2392 | 352 * @param h height of the rectangle, should be a constant |
| 353 * @param w width of the rectangle, should be a constant | |
| 1168 | 354 * @param size the size of val (1 or 4), should be a constant |
| 355 */ | |
| 1187 | 356 static inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){ //FIXME ensure this IS inlined |
| 357 uint8_t *p= (uint8_t*)vp; | |
| 1168 | 358 assert(size==1 || size==4); |
| 359 | |
| 360 w *= size; | |
| 361 stride *= size; | |
| 362 | |
|
2471
805431763e84
fixing missaligned memory accesses in fill_rectangle()
michael
parents:
2454
diff
changeset
|
363 assert((((int)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0); |
| 1168 | 364 //FIXME check what gcc generates for 64 bit on x86 and possible write a 32 bit ver of it |
| 365 if(w==2 && h==2){ | |
| 366 *(uint16_t*)(p + 0)= | |
| 367 *(uint16_t*)(p + stride)= size==4 ? val : val*0x0101; | |
| 368 }else if(w==2 && h==4){ | |
| 369 *(uint16_t*)(p + 0*stride)= | |
| 370 *(uint16_t*)(p + 1*stride)= | |
| 371 *(uint16_t*)(p + 2*stride)= | |
| 372 *(uint16_t*)(p + 3*stride)= size==4 ? val : val*0x0101; | |
| 1252 | 373 }else if(w==4 && h==1){ |
| 374 *(uint32_t*)(p + 0*stride)= size==4 ? val : val*0x01010101; | |
| 1168 | 375 }else if(w==4 && h==2){ |
| 376 *(uint32_t*)(p + 0*stride)= | |
| 377 *(uint32_t*)(p + 1*stride)= size==4 ? val : val*0x01010101; | |
| 378 }else if(w==4 && h==4){ | |
| 379 *(uint32_t*)(p + 0*stride)= | |
| 380 *(uint32_t*)(p + 1*stride)= | |
| 381 *(uint32_t*)(p + 2*stride)= | |
| 382 *(uint32_t*)(p + 3*stride)= size==4 ? val : val*0x01010101; | |
| 383 }else if(w==8 && h==1){ | |
| 384 *(uint32_t*)(p + 0)= | |
| 385 *(uint32_t*)(p + 4)= size==4 ? val : val*0x01010101; | |
| 386 }else if(w==8 && h==2){ | |
| 387 *(uint32_t*)(p + 0 + 0*stride)= | |
| 388 *(uint32_t*)(p + 4 + 0*stride)= | |
| 389 *(uint32_t*)(p + 0 + 1*stride)= | |
| 390 *(uint32_t*)(p + 4 + 1*stride)= size==4 ? val : val*0x01010101; | |
| 391 }else if(w==8 && h==4){ | |
| 392 *(uint64_t*)(p + 0*stride)= | |
| 393 *(uint64_t*)(p + 1*stride)= | |
| 394 *(uint64_t*)(p + 2*stride)= | |
| 395 *(uint64_t*)(p + 3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
| 396 }else if(w==16 && h==2){ | |
| 397 *(uint64_t*)(p + 0+0*stride)= | |
| 398 *(uint64_t*)(p + 8+0*stride)= | |
| 399 *(uint64_t*)(p + 0+1*stride)= | |
| 400 *(uint64_t*)(p + 8+1*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
| 401 }else if(w==16 && h==4){ | |
| 402 *(uint64_t*)(p + 0+0*stride)= | |
| 403 *(uint64_t*)(p + 8+0*stride)= | |
| 404 *(uint64_t*)(p + 0+1*stride)= | |
| 405 *(uint64_t*)(p + 8+1*stride)= | |
| 406 *(uint64_t*)(p + 0+2*stride)= | |
| 407 *(uint64_t*)(p + 8+2*stride)= | |
| 408 *(uint64_t*)(p + 0+3*stride)= | |
| 409 *(uint64_t*)(p + 8+3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
| 410 }else | |
| 411 assert(0); | |
| 412 } | |
| 413 | |
| 2449 | 414 static inline void fill_caches(H264Context *h, int mb_type, int for_deblock){ |
| 1168 | 415 MpegEncContext * const s = &h->s; |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
416 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1168 | 417 int topleft_xy, top_xy, topright_xy, left_xy[2]; |
| 418 int topleft_type, top_type, topright_type, left_type[2]; | |
| 419 int left_block[4]; | |
| 420 int i; | |
| 421 | |
| 422 //wow what a mess, why didnt they simplify the interlacing&intra stuff, i cant imagine that these complex rules are worth it | |
| 423 | |
| 424 if(h->sps.mb_aff){ | |
| 425 //FIXME | |
| 1453 | 426 topleft_xy = 0; /* avoid warning */ |
| 427 top_xy = 0; /* avoid warning */ | |
| 428 topright_xy = 0; /* avoid warning */ | |
| 1168 | 429 }else{ |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
430 topleft_xy = mb_xy-1 - s->mb_stride; |
|
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
431 top_xy = mb_xy - s->mb_stride; |
|
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
432 topright_xy= mb_xy+1 - s->mb_stride; |
| 1168 | 433 left_xy[0] = mb_xy-1; |
| 434 left_xy[1] = mb_xy-1; | |
| 435 left_block[0]= 0; | |
| 436 left_block[1]= 1; | |
| 437 left_block[2]= 2; | |
| 438 left_block[3]= 3; | |
| 439 } | |
| 440 | |
| 2449 | 441 if(for_deblock){ |
| 442 topleft_type = h->slice_table[topleft_xy ] < 255 ? s->current_picture.mb_type[topleft_xy] : 0; | |
| 443 top_type = h->slice_table[top_xy ] < 255 ? s->current_picture.mb_type[top_xy] : 0; | |
| 444 topright_type= h->slice_table[topright_xy] < 255 ? s->current_picture.mb_type[topright_xy]: 0; | |
| 445 left_type[0] = h->slice_table[left_xy[0] ] < 255 ? s->current_picture.mb_type[left_xy[0]] : 0; | |
| 446 left_type[1] = h->slice_table[left_xy[1] ] < 255 ? s->current_picture.mb_type[left_xy[1]] : 0; | |
| 447 }else{ | |
| 448 topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0; | |
| 449 top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0; | |
| 450 topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0; | |
| 451 left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0; | |
| 452 left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0; | |
| 453 } | |
| 1168 | 454 |
| 455 if(IS_INTRA(mb_type)){ | |
| 456 h->topleft_samples_available= | |
| 457 h->top_samples_available= | |
| 458 h->left_samples_available= 0xFFFF; | |
| 459 h->topright_samples_available= 0xEEEA; | |
| 460 | |
| 461 if(!IS_INTRA(top_type) && (top_type==0 || h->pps.constrained_intra_pred)){ | |
| 462 h->topleft_samples_available= 0xB3FF; | |
| 463 h->top_samples_available= 0x33FF; | |
| 464 h->topright_samples_available= 0x26EA; | |
| 465 } | |
| 466 for(i=0; i<2; i++){ | |
| 467 if(!IS_INTRA(left_type[i]) && (left_type[i]==0 || h->pps.constrained_intra_pred)){ | |
| 468 h->topleft_samples_available&= 0xDF5F; | |
| 469 h->left_samples_available&= 0x5F5F; | |
| 470 } | |
| 471 } | |
| 472 | |
| 473 if(!IS_INTRA(topleft_type) && (topleft_type==0 || h->pps.constrained_intra_pred)) | |
| 474 h->topleft_samples_available&= 0x7FFF; | |
| 475 | |
| 476 if(!IS_INTRA(topright_type) && (topright_type==0 || h->pps.constrained_intra_pred)) | |
| 477 h->topright_samples_available&= 0xFBFF; | |
| 478 | |
| 479 if(IS_INTRA4x4(mb_type)){ | |
| 480 if(IS_INTRA4x4(top_type)){ | |
| 481 h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4]; | |
| 482 h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5]; | |
| 483 h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6]; | |
| 484 h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3]; | |
| 485 }else{ | |
| 486 int pred; | |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
487 if(!top_type || (IS_INTER(top_type) && h->pps.constrained_intra_pred)) |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
488 pred= -1; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
489 else{ |
| 1168 | 490 pred= 2; |
| 491 } | |
| 492 h->intra4x4_pred_mode_cache[4+8*0]= | |
| 493 h->intra4x4_pred_mode_cache[5+8*0]= | |
| 494 h->intra4x4_pred_mode_cache[6+8*0]= | |
| 495 h->intra4x4_pred_mode_cache[7+8*0]= pred; | |
| 496 } | |
| 497 for(i=0; i<2; i++){ | |
| 498 if(IS_INTRA4x4(left_type[i])){ | |
| 499 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]]; | |
| 500 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]]; | |
| 501 }else{ | |
| 502 int pred; | |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
503 if(!left_type[i] || (IS_INTER(left_type[i]) && h->pps.constrained_intra_pred)) |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
504 pred= -1; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
505 else{ |
| 1168 | 506 pred= 2; |
| 507 } | |
| 508 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= | |
| 509 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred; | |
| 510 } | |
| 511 } | |
| 512 } | |
| 513 } | |
| 514 | |
| 515 | |
| 516 /* | |
| 517 0 . T T. T T T T | |
| 518 1 L . .L . . . . | |
| 519 2 L . .L . . . . | |
| 520 3 . T TL . . . . | |
| 521 4 L . .L . . . . | |
| 522 5 L . .. . . . . | |
| 523 */ | |
| 524 //FIXME constraint_intra_pred & partitioning & nnz (lets hope this is just a typo in the spec) | |
| 525 if(top_type){ | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
526 h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][0]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
527 h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][1]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
528 h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][2]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
529 h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3]; |
| 1168 | 530 |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
531 h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][7]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
532 h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8]; |
| 1168 | 533 |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
534 h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][10]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
535 h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11]; |
| 2314 | 536 |
| 537 h->top_cbp= h->cbp_table[top_xy]; | |
| 1168 | 538 }else{ |
| 539 h->non_zero_count_cache[4+8*0]= | |
| 540 h->non_zero_count_cache[5+8*0]= | |
| 541 h->non_zero_count_cache[6+8*0]= | |
| 542 h->non_zero_count_cache[7+8*0]= | |
| 543 | |
| 544 h->non_zero_count_cache[1+8*0]= | |
| 545 h->non_zero_count_cache[2+8*0]= | |
| 546 | |
| 547 h->non_zero_count_cache[1+8*3]= | |
| 2314 | 548 h->non_zero_count_cache[2+8*3]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
| 549 | |
| 550 if(IS_INTRA(mb_type)) h->top_cbp= 0x1C0; | |
| 551 else h->top_cbp= 0; | |
| 1168 | 552 } |
| 553 | |
| 554 if(left_type[0]){ | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
555 h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][6]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
556 h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][5]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
557 h->non_zero_count_cache[0+8*1]= h->non_zero_count[left_xy[0]][9]; //FIXME left_block |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
558 h->non_zero_count_cache[0+8*4]= h->non_zero_count[left_xy[0]][12]; |
| 2314 | 559 h->left_cbp= h->cbp_table[left_xy[0]]; //FIXME interlacing |
| 1168 | 560 }else{ |
| 561 h->non_zero_count_cache[3+8*1]= | |
| 562 h->non_zero_count_cache[3+8*2]= | |
| 563 h->non_zero_count_cache[0+8*1]= | |
| 2314 | 564 h->non_zero_count_cache[0+8*4]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
| 565 | |
| 566 if(IS_INTRA(mb_type)) h->left_cbp= 0x1C0;//FIXME interlacing | |
| 567 else h->left_cbp= 0; | |
| 1168 | 568 } |
| 569 | |
| 570 if(left_type[1]){ | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
571 h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[1]][4]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
572 h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[1]][3]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
573 h->non_zero_count_cache[0+8*2]= h->non_zero_count[left_xy[1]][8]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
574 h->non_zero_count_cache[0+8*5]= h->non_zero_count[left_xy[1]][11]; |
| 1168 | 575 }else{ |
| 576 h->non_zero_count_cache[3+8*3]= | |
| 577 h->non_zero_count_cache[3+8*4]= | |
| 578 h->non_zero_count_cache[0+8*2]= | |
| 2314 | 579 h->non_zero_count_cache[0+8*5]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
| 1168 | 580 } |
| 581 | |
| 582 #if 1 | |
| 2396 | 583 //FIXME direct mb can skip much of this |
| 584 if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ | |
| 1168 | 585 int list; |
| 586 for(list=0; list<2; list++){ | |
| 2535 | 587 if(!USES_LIST(mb_type, list) && !IS_DIRECT(mb_type) && !for_deblock){ |
| 1168 | 588 /*if(!h->mv_cache_clean[list]){ |
| 589 memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? | |
| 590 memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); | |
| 591 h->mv_cache_clean[list]= 1; | |
| 592 }*/ | |
| 2396 | 593 continue; |
| 1168 | 594 } |
| 595 h->mv_cache_clean[list]= 0; | |
| 596 | |
| 597 if(IS_INTER(topleft_type)){ | |
| 598 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride; | |
| 599 const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + h->b8_stride; | |
| 600 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; | |
| 601 h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; | |
| 602 }else{ | |
| 603 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= 0; | |
| 604 h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
| 605 } | |
| 606 | |
| 607 if(IS_INTER(top_type)){ | |
| 608 const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; | |
| 609 const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride; | |
| 610 *(uint32_t*)h->mv_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 0]; | |
| 611 *(uint32_t*)h->mv_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 1]; | |
| 612 *(uint32_t*)h->mv_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 2]; | |
| 613 *(uint32_t*)h->mv_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 3]; | |
| 614 h->ref_cache[list][scan8[0] + 0 - 1*8]= | |
| 615 h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0]; | |
| 616 h->ref_cache[list][scan8[0] + 2 - 1*8]= | |
| 617 h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1]; | |
| 618 }else{ | |
| 619 *(uint32_t*)h->mv_cache [list][scan8[0] + 0 - 1*8]= | |
| 620 *(uint32_t*)h->mv_cache [list][scan8[0] + 1 - 1*8]= | |
| 621 *(uint32_t*)h->mv_cache [list][scan8[0] + 2 - 1*8]= | |
| 622 *(uint32_t*)h->mv_cache [list][scan8[0] + 3 - 1*8]= 0; | |
| 623 *(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101; | |
| 624 } | |
| 625 | |
| 626 if(IS_INTER(topright_type)){ | |
| 627 const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; | |
| 628 const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride; | |
| 629 *(uint32_t*)h->mv_cache[list][scan8[0] + 4 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; | |
| 630 h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy]; | |
| 631 }else{ | |
| 632 *(uint32_t*)h->mv_cache [list][scan8[0] + 4 - 1*8]= 0; | |
| 633 h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
| 634 } | |
| 635 | |
| 636 //FIXME unify cleanup or sth | |
| 637 if(IS_INTER(left_type[0])){ | |
| 638 const int b_xy= h->mb2b_xy[left_xy[0]] + 3; | |
| 639 const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1; | |
| 640 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 0*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0]]; | |
| 641 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1]]; | |
| 642 h->ref_cache[list][scan8[0] - 1 + 0*8]= | |
| 643 h->ref_cache[list][scan8[0] - 1 + 1*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0]>>1)]; | |
| 644 }else{ | |
| 645 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0*8]= | |
| 646 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 1*8]= 0; | |
| 647 h->ref_cache[list][scan8[0] - 1 + 0*8]= | |
| 648 h->ref_cache[list][scan8[0] - 1 + 1*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
| 649 } | |
| 650 | |
| 651 if(IS_INTER(left_type[1])){ | |
| 652 const int b_xy= h->mb2b_xy[left_xy[1]] + 3; | |
| 653 const int b8_xy= h->mb2b8_xy[left_xy[1]] + 1; | |
| 654 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 2*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[2]]; | |
| 655 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 3*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[3]]; | |
| 656 h->ref_cache[list][scan8[0] - 1 + 2*8]= | |
| 657 h->ref_cache[list][scan8[0] - 1 + 3*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[2]>>1)]; | |
| 658 }else{ | |
| 659 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 2*8]= | |
| 660 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 3*8]= 0; | |
| 661 h->ref_cache[list][scan8[0] - 1 + 2*8]= | |
| 662 h->ref_cache[list][scan8[0] - 1 + 3*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
| 663 } | |
| 664 | |
| 2449 | 665 if(for_deblock) |
| 666 continue; | |
| 667 | |
| 1168 | 668 h->ref_cache[list][scan8[5 ]+1] = |
| 669 h->ref_cache[list][scan8[7 ]+1] = | |
| 670 h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewher else) | |
| 671 h->ref_cache[list][scan8[4 ]] = | |
| 672 h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; | |
| 673 *(uint32_t*)h->mv_cache [list][scan8[5 ]+1]= | |
| 674 *(uint32_t*)h->mv_cache [list][scan8[7 ]+1]= | |
| 675 *(uint32_t*)h->mv_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) | |
| 676 *(uint32_t*)h->mv_cache [list][scan8[4 ]]= | |
| 677 *(uint32_t*)h->mv_cache [list][scan8[12]]= 0; | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
678 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
679 if( h->pps.cabac ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
680 /* XXX beurk, Load mvd */ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
681 if(IS_INTER(topleft_type)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
682 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
683 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
684 }else{ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
685 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 - 1*8]= 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
686 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
687 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
688 if(IS_INTER(top_type)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
689 const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
690 *(uint32_t*)h->mvd_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 0]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
691 *(uint32_t*)h->mvd_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 1]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
692 *(uint32_t*)h->mvd_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 2]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
693 *(uint32_t*)h->mvd_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 3]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
694 }else{ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
695 *(uint32_t*)h->mvd_cache [list][scan8[0] + 0 - 1*8]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
696 *(uint32_t*)h->mvd_cache [list][scan8[0] + 1 - 1*8]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
697 *(uint32_t*)h->mvd_cache [list][scan8[0] + 2 - 1*8]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
698 *(uint32_t*)h->mvd_cache [list][scan8[0] + 3 - 1*8]= 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
699 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
700 if(IS_INTER(left_type[0])){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
701 const int b_xy= h->mb2b_xy[left_xy[0]] + 3; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
702 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 0*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[0]]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
703 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[1]]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
704 }else{ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
705 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 0*8]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
706 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 1*8]= 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
707 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
708 if(IS_INTER(left_type[1])){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
709 const int b_xy= h->mb2b_xy[left_xy[1]] + 3; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
710 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 2*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[2]]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
711 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 3*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[3]]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
712 }else{ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
713 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 2*8]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
714 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 3*8]= 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
715 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
716 *(uint32_t*)h->mvd_cache [list][scan8[5 ]+1]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
717 *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
718 *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
719 *(uint32_t*)h->mvd_cache [list][scan8[4 ]]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
720 *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0; |
| 2396 | 721 |
| 722 if(h->slice_type == B_TYPE){ | |
| 723 fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1); | |
| 724 | |
| 725 if(IS_DIRECT(top_type)){ | |
| 726 *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0x01010101; | |
| 727 }else if(IS_8X8(top_type)){ | |
| 728 int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride; | |
| 729 h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy]; | |
| 730 h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1]; | |
| 731 }else{ | |
| 732 *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0; | |
| 733 } | |
| 734 | |
| 735 //FIXME interlacing | |
| 736 if(IS_DIRECT(left_type[0])){ | |
| 737 h->direct_cache[scan8[0] - 1 + 0*8]= | |
| 738 h->direct_cache[scan8[0] - 1 + 2*8]= 1; | |
| 739 }else if(IS_8X8(left_type[0])){ | |
| 740 int b8_xy = h->mb2b8_xy[left_xy[0]] + 1; | |
| 741 h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[b8_xy]; | |
| 742 h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[b8_xy + h->b8_stride]; | |
| 743 }else{ | |
| 744 h->direct_cache[scan8[0] - 1 + 0*8]= | |
| 745 h->direct_cache[scan8[0] - 1 + 2*8]= 0; | |
| 746 } | |
| 747 } | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
748 } |
| 1168 | 749 } |
| 750 } | |
| 751 #endif | |
| 752 } | |
| 753 | |
| 754 static inline void write_back_intra_pred_mode(H264Context *h){ | |
| 755 MpegEncContext * const s = &h->s; | |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
756 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1168 | 757 |
| 758 h->intra4x4_pred_mode[mb_xy][0]= h->intra4x4_pred_mode_cache[7+8*1]; | |
| 759 h->intra4x4_pred_mode[mb_xy][1]= h->intra4x4_pred_mode_cache[7+8*2]; | |
| 760 h->intra4x4_pred_mode[mb_xy][2]= h->intra4x4_pred_mode_cache[7+8*3]; | |
| 761 h->intra4x4_pred_mode[mb_xy][3]= h->intra4x4_pred_mode_cache[7+8*4]; | |
| 762 h->intra4x4_pred_mode[mb_xy][4]= h->intra4x4_pred_mode_cache[4+8*4]; | |
| 763 h->intra4x4_pred_mode[mb_xy][5]= h->intra4x4_pred_mode_cache[5+8*4]; | |
| 764 h->intra4x4_pred_mode[mb_xy][6]= h->intra4x4_pred_mode_cache[6+8*4]; | |
| 765 } | |
| 766 | |
| 767 /** | |
| 768 * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. | |
| 769 */ | |
| 770 static inline int check_intra4x4_pred_mode(H264Context *h){ | |
| 771 MpegEncContext * const s = &h->s; | |
| 772 static const int8_t top [12]= {-1, 0,LEFT_DC_PRED,-1,-1,-1,-1,-1, 0}; | |
| 773 static const int8_t left[12]= { 0,-1, TOP_DC_PRED, 0,-1,-1,-1, 0,-1,DC_128_PRED}; | |
| 774 int i; | |
| 775 | |
| 776 if(!(h->top_samples_available&0x8000)){ | |
| 777 for(i=0; i<4; i++){ | |
| 778 int status= top[ h->intra4x4_pred_mode_cache[scan8[0] + i] ]; | |
| 779 if(status<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
780 av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y); |
| 1168 | 781 return -1; |
| 782 } else if(status){ | |
| 783 h->intra4x4_pred_mode_cache[scan8[0] + i]= status; | |
| 784 } | |
| 785 } | |
| 786 } | |
| 787 | |
| 788 if(!(h->left_samples_available&0x8000)){ | |
| 789 for(i=0; i<4; i++){ | |
| 790 int status= left[ h->intra4x4_pred_mode_cache[scan8[0] + 8*i] ]; | |
| 791 if(status<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
792 av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y); |
| 1168 | 793 return -1; |
| 794 } else if(status){ | |
| 795 h->intra4x4_pred_mode_cache[scan8[0] + 8*i]= status; | |
| 796 } | |
| 797 } | |
| 798 } | |
| 799 | |
| 800 return 0; | |
| 801 } //FIXME cleanup like next | |
| 802 | |
| 803 /** | |
| 804 * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. | |
| 805 */ | |
| 806 static inline int check_intra_pred_mode(H264Context *h, int mode){ | |
| 807 MpegEncContext * const s = &h->s; | |
| 808 static const int8_t top [7]= {LEFT_DC_PRED8x8, 1,-1,-1}; | |
| 809 static const int8_t left[7]= { TOP_DC_PRED8x8,-1, 2,-1,DC_128_PRED8x8}; | |
| 810 | |
| 2392 | 811 if(mode < 0 || mode > 6) { |
| 812 av_log(h->s.avctx, AV_LOG_ERROR, "out of range intra chroma pred mode at %d %d\n", s->mb_x, s->mb_y); | |
| 2163 | 813 return -1; |
| 2392 | 814 } |
| 2163 | 815 |
| 1168 | 816 if(!(h->top_samples_available&0x8000)){ |
| 817 mode= top[ mode ]; | |
| 818 if(mode<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
819 av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y); |
| 1168 | 820 return -1; |
| 821 } | |
| 822 } | |
| 823 | |
| 824 if(!(h->left_samples_available&0x8000)){ | |
| 825 mode= left[ mode ]; | |
| 826 if(mode<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
827 av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y); |
| 1168 | 828 return -1; |
| 829 } | |
| 830 } | |
| 831 | |
| 832 return mode; | |
| 833 } | |
| 834 | |
| 835 /** | |
| 836 * gets the predicted intra4x4 prediction mode. | |
| 837 */ | |
| 838 static inline int pred_intra_mode(H264Context *h, int n){ | |
| 839 const int index8= scan8[n]; | |
| 840 const int left= h->intra4x4_pred_mode_cache[index8 - 1]; | |
| 841 const int top = h->intra4x4_pred_mode_cache[index8 - 8]; | |
| 842 const int min= FFMIN(left, top); | |
| 843 | |
| 1170 | 844 tprintf("mode:%d %d min:%d\n", left ,top, min); |
| 1168 | 845 |
| 846 if(min<0) return DC_PRED; | |
| 847 else return min; | |
| 848 } | |
| 849 | |
| 850 static inline void write_back_non_zero_count(H264Context *h){ | |
| 851 MpegEncContext * const s = &h->s; | |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
852 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
853 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
854 h->non_zero_count[mb_xy][0]= h->non_zero_count_cache[4+8*4]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
855 h->non_zero_count[mb_xy][1]= h->non_zero_count_cache[5+8*4]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
856 h->non_zero_count[mb_xy][2]= h->non_zero_count_cache[6+8*4]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
857 h->non_zero_count[mb_xy][3]= h->non_zero_count_cache[7+8*4]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
858 h->non_zero_count[mb_xy][4]= h->non_zero_count_cache[7+8*3]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
859 h->non_zero_count[mb_xy][5]= h->non_zero_count_cache[7+8*2]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
860 h->non_zero_count[mb_xy][6]= h->non_zero_count_cache[7+8*1]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
861 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
862 h->non_zero_count[mb_xy][7]= h->non_zero_count_cache[1+8*2]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
863 h->non_zero_count[mb_xy][8]= h->non_zero_count_cache[2+8*2]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
864 h->non_zero_count[mb_xy][9]= h->non_zero_count_cache[2+8*1]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
865 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
866 h->non_zero_count[mb_xy][10]=h->non_zero_count_cache[1+8*5]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
867 h->non_zero_count[mb_xy][11]=h->non_zero_count_cache[2+8*5]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
868 h->non_zero_count[mb_xy][12]=h->non_zero_count_cache[2+8*4]; |
| 1168 | 869 } |
| 870 | |
| 871 /** | |
| 872 * gets the predicted number of non zero coefficients. | |
| 873 * @param n block index | |
| 874 */ | |
| 875 static inline int pred_non_zero_count(H264Context *h, int n){ | |
| 876 const int index8= scan8[n]; | |
| 877 const int left= h->non_zero_count_cache[index8 - 1]; | |
| 878 const int top = h->non_zero_count_cache[index8 - 8]; | |
| 879 int i= left + top; | |
| 880 | |
| 881 if(i<64) i= (i+1)>>1; | |
| 882 | |
| 1170 | 883 tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); |
| 1168 | 884 |
| 885 return i&31; | |
| 886 } | |
| 887 | |
| 1169 | 888 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ |
| 889 const int topright_ref= h->ref_cache[list][ i - 8 + part_width ]; | |
| 890 | |
| 891 if(topright_ref != PART_NOT_AVAILABLE){ | |
| 892 *C= h->mv_cache[list][ i - 8 + part_width ]; | |
| 893 return topright_ref; | |
| 894 }else{ | |
| 1170 | 895 tprintf("topright MV not available\n"); |
| 896 | |
| 1169 | 897 *C= h->mv_cache[list][ i - 8 - 1 ]; |
| 898 return h->ref_cache[list][ i - 8 - 1 ]; | |
| 899 } | |
| 900 } | |
| 901 | |
| 1168 | 902 /** |
| 903 * gets the predicted MV. | |
| 904 * @param n the block index | |
| 905 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) | |
| 906 * @param mx the x component of the predicted motion vector | |
| 907 * @param my the y component of the predicted motion vector | |
| 908 */ | |
| 909 static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){ | |
| 910 const int index8= scan8[n]; | |
| 911 const int top_ref= h->ref_cache[list][ index8 - 8 ]; | |
| 912 const int left_ref= h->ref_cache[list][ index8 - 1 ]; | |
| 913 const int16_t * const A= h->mv_cache[list][ index8 - 1 ]; | |
| 914 const int16_t * const B= h->mv_cache[list][ index8 - 8 ]; | |
| 1169 | 915 const int16_t * C; |
| 916 int diagonal_ref, match_count; | |
| 917 | |
| 1168 | 918 assert(part_width==1 || part_width==2 || part_width==4); |
| 1169 | 919 |
| 1168 | 920 /* mv_cache |
| 921 B . . A T T T T | |
| 922 U . . L . . , . | |
| 923 U . . L . . . . | |
| 924 U . . L . . , . | |
| 925 . . . L . . . . | |
| 926 */ | |
| 1169 | 927 |
| 928 diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); | |
| 929 match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
930 tprintf("pred_motion match_count=%d\n", match_count); |
| 1169 | 931 if(match_count > 1){ //most common |
| 932 *mx= mid_pred(A[0], B[0], C[0]); | |
| 933 *my= mid_pred(A[1], B[1], C[1]); | |
| 934 }else if(match_count==1){ | |
| 935 if(left_ref==ref){ | |
| 936 *mx= A[0]; | |
| 937 *my= A[1]; | |
| 938 }else if(top_ref==ref){ | |
| 939 *mx= B[0]; | |
| 940 *my= B[1]; | |
| 941 }else{ | |
| 942 *mx= C[0]; | |
| 943 *my= C[1]; | |
| 944 } | |
| 945 }else{ | |
| 946 if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ | |
| 947 *mx= A[0]; | |
| 948 *my= A[1]; | |
| 1168 | 949 }else{ |
| 950 *mx= mid_pred(A[0], B[0], C[0]); | |
| 951 *my= mid_pred(A[1], B[1], C[1]); | |
| 952 } | |
| 1169 | 953 } |
| 1168 | 954 |
| 1187 | 955 tprintf("pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 956 } |
| 957 | |
| 958 /** | |
| 959 * gets the directionally predicted 16x8 MV. | |
| 960 * @param n the block index | |
| 961 * @param mx the x component of the predicted motion vector | |
| 962 * @param my the y component of the predicted motion vector | |
| 963 */ | |
| 964 static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ | |
| 965 if(n==0){ | |
| 966 const int top_ref= h->ref_cache[list][ scan8[0] - 8 ]; | |
| 967 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; | |
| 968 | |
|
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
969 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 970 |
| 971 if(top_ref == ref){ | |
| 972 *mx= B[0]; | |
| 973 *my= B[1]; | |
| 974 return; | |
| 975 } | |
| 976 }else{ | |
| 977 const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; | |
| 978 const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; | |
| 979 | |
|
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
980 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 981 |
| 982 if(left_ref == ref){ | |
| 983 *mx= A[0]; | |
| 984 *my= A[1]; | |
| 985 return; | |
| 986 } | |
| 987 } | |
| 988 | |
| 989 //RARE | |
| 990 pred_motion(h, n, 4, list, ref, mx, my); | |
| 991 } | |
| 992 | |
| 993 /** | |
| 994 * gets the directionally predicted 8x16 MV. | |
| 995 * @param n the block index | |
| 996 * @param mx the x component of the predicted motion vector | |
| 997 * @param my the y component of the predicted motion vector | |
| 998 */ | |
| 999 static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ | |
| 1000 if(n==0){ | |
| 1001 const int left_ref= h->ref_cache[list][ scan8[0] - 1 ]; | |
| 1002 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; | |
| 1003 | |
|
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
1004 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 1005 |
| 1006 if(left_ref == ref){ | |
| 1007 *mx= A[0]; | |
| 1008 *my= A[1]; | |
| 1009 return; | |
| 1010 } | |
| 1011 }else{ | |
| 1169 | 1012 const int16_t * C; |
| 1013 int diagonal_ref; | |
| 1014 | |
| 1015 diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); | |
| 1168 | 1016 |
|
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
1017 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 1018 |
| 1169 | 1019 if(diagonal_ref == ref){ |
| 1168 | 1020 *mx= C[0]; |
| 1021 *my= C[1]; | |
| 1022 return; | |
| 1023 } | |
| 1024 } | |
| 1025 | |
| 1026 //RARE | |
| 1027 pred_motion(h, n, 2, list, ref, mx, my); | |
| 1028 } | |
| 1029 | |
| 1030 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){ | |
| 1031 const int top_ref = h->ref_cache[0][ scan8[0] - 8 ]; | |
| 1032 const int left_ref= h->ref_cache[0][ scan8[0] - 1 ]; | |
| 1033 | |
| 2392 | 1034 tprintf("pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y); |
| 1168 | 1035 |
| 1036 if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE | |
| 1037 || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0) | |
| 1038 || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){ | |
| 1039 | |
| 1040 *mx = *my = 0; | |
| 1041 return; | |
| 1042 } | |
| 1043 | |
| 1044 pred_motion(h, 0, 4, 0, 0, mx, my); | |
| 1045 | |
| 1046 return; | |
| 1047 } | |
| 1048 | |
| 2396 | 1049 static inline void direct_dist_scale_factor(H264Context * const h){ |
| 1050 const int poc = h->s.current_picture_ptr->poc; | |
| 1051 const int poc1 = h->ref_list[1][0].poc; | |
| 1052 int i; | |
| 1053 for(i=0; i<h->ref_count[0]; i++){ | |
| 1054 int poc0 = h->ref_list[0][i].poc; | |
| 1055 int td = clip(poc1 - poc0, -128, 127); | |
| 1056 if(td == 0 /* FIXME || pic0 is a long-term ref */){ | |
| 1057 h->dist_scale_factor[i] = 256; | |
| 1058 }else{ | |
| 1059 int tb = clip(poc - poc0, -128, 127); | |
| 1060 int tx = (16384 + (ABS(td) >> 1)) / td; | |
| 1061 h->dist_scale_factor[i] = clip((tb*tx + 32) >> 6, -1024, 1023); | |
| 1062 } | |
| 1063 } | |
| 1064 } | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1065 static inline void direct_ref_list_init(H264Context * const h){ |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1066 MpegEncContext * const s = &h->s; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1067 Picture * const ref1 = &h->ref_list[1][0]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1068 Picture * const cur = s->current_picture_ptr; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1069 int list, i, j; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1070 if(cur->pict_type == I_TYPE) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1071 cur->ref_count[0] = 0; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1072 if(cur->pict_type != B_TYPE) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1073 cur->ref_count[1] = 0; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1074 for(list=0; list<2; list++){ |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1075 cur->ref_count[list] = h->ref_count[list]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1076 for(j=0; j<h->ref_count[list]; j++) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1077 cur->ref_poc[list][j] = h->ref_list[list][j].poc; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1078 } |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1079 if(cur->pict_type != B_TYPE || h->direct_spatial_mv_pred) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1080 return; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1081 for(list=0; list<2; list++){ |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1082 for(i=0; i<ref1->ref_count[list]; i++){ |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1083 const int poc = ref1->ref_poc[list][i]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1084 h->map_col_to_list0[list][i] = PART_NOT_AVAILABLE; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1085 for(j=0; j<h->ref_count[list]; j++) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1086 if(h->ref_list[list][j].poc == poc){ |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1087 h->map_col_to_list0[list][i] = j; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1088 break; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1089 } |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1090 } |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1091 } |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1092 } |
| 2396 | 1093 |
| 1094 static inline void pred_direct_motion(H264Context * const h, int *mb_type){ | |
| 1095 MpegEncContext * const s = &h->s; | |
| 1096 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; | |
| 1097 const int b8_xy = 2*s->mb_x + 2*s->mb_y*h->b8_stride; | |
| 1098 const int b4_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; | |
| 1099 const int mb_type_col = h->ref_list[1][0].mb_type[mb_xy]; | |
| 1100 const int16_t (*l1mv0)[2] = (const int16_t (*)[2]) &h->ref_list[1][0].motion_val[0][b4_xy]; | |
| 1101 const int8_t *l1ref0 = &h->ref_list[1][0].ref_index[0][b8_xy]; | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1102 const int8_t *l1ref1 = &h->ref_list[1][0].ref_index[1][b8_xy]; |
| 2396 | 1103 const int is_b8x8 = IS_8X8(*mb_type); |
| 1104 int sub_mb_type; | |
| 1105 int i8, i4; | |
| 1106 | |
| 1107 if(IS_8X8(mb_type_col) && !h->sps.direct_8x8_inference_flag){ | |
| 1108 /* FIXME save sub mb types from previous frames (or derive from MVs) | |
| 1109 * so we know exactly what block size to use */ | |
| 1110 sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */ | |
| 2536 | 1111 *mb_type = MB_TYPE_8x8|MB_TYPE_L0L1; |
| 2396 | 1112 }else if(!is_b8x8 && (IS_16X16(mb_type_col) || IS_INTRA(mb_type_col))){ |
| 1113 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
| 1114 *mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */ | |
| 1115 }else{ | |
| 1116 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
| 2536 | 1117 *mb_type = MB_TYPE_8x8|MB_TYPE_L0L1; |
| 2396 | 1118 } |
| 1119 if(!is_b8x8) | |
| 1120 *mb_type |= MB_TYPE_DIRECT2; | |
| 1121 | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
1122 tprintf("mb_type = %08x, sub_mb_type = %08x, is_b8x8 = %d, mb_type_col = %08x\n", *mb_type, sub_mb_type, is_b8x8, mb_type_col); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
1123 |
| 2396 | 1124 if(h->direct_spatial_mv_pred){ |
| 1125 int ref[2]; | |
| 1126 int mv[2][2]; | |
| 1127 int list; | |
| 1128 | |
| 1129 /* ref = min(neighbors) */ | |
| 1130 for(list=0; list<2; list++){ | |
| 1131 int refa = h->ref_cache[list][scan8[0] - 1]; | |
| 1132 int refb = h->ref_cache[list][scan8[0] - 8]; | |
| 1133 int refc = h->ref_cache[list][scan8[0] - 8 + 4]; | |
| 1134 if(refc == -2) | |
| 1135 refc = h->ref_cache[list][scan8[0] - 8 - 1]; | |
| 1136 ref[list] = refa; | |
| 1137 if(ref[list] < 0 || (refb < ref[list] && refb >= 0)) | |
| 1138 ref[list] = refb; | |
| 1139 if(ref[list] < 0 || (refc < ref[list] && refc >= 0)) | |
| 1140 ref[list] = refc; | |
| 1141 if(ref[list] < 0) | |
| 1142 ref[list] = -1; | |
| 1143 } | |
| 1144 | |
| 1145 if(ref[0] < 0 && ref[1] < 0){ | |
| 1146 ref[0] = ref[1] = 0; | |
| 1147 mv[0][0] = mv[0][1] = | |
| 1148 mv[1][0] = mv[1][1] = 0; | |
| 1149 }else{ | |
| 1150 for(list=0; list<2; list++){ | |
| 1151 if(ref[list] >= 0) | |
| 1152 pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]); | |
| 1153 else | |
| 1154 mv[list][0] = mv[list][1] = 0; | |
| 1155 } | |
| 1156 } | |
| 1157 | |
| 1158 if(ref[1] < 0){ | |
| 1159 *mb_type &= ~MB_TYPE_P0L1; | |
| 1160 sub_mb_type &= ~MB_TYPE_P0L1; | |
| 1161 }else if(ref[0] < 0){ | |
| 1162 *mb_type &= ~MB_TYPE_P0L0; | |
| 1163 sub_mb_type &= ~MB_TYPE_P0L0; | |
| 1164 } | |
| 1165 | |
| 1166 if(IS_16X16(*mb_type)){ | |
| 1167 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref[0], 1); | |
| 1168 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, ref[1], 1); | |
| 1169 if(!IS_INTRA(mb_type_col) && l1ref0[0] == 0 && | |
| 1170 ABS(l1mv0[0][0]) <= 1 && ABS(l1mv0[0][1]) <= 1){ | |
| 1171 if(ref[0] > 0) | |
| 1172 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
| 1173 else | |
| 1174 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
| 1175 if(ref[1] > 0) | |
| 1176 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
| 1177 else | |
| 1178 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
| 1179 }else{ | |
| 1180 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
| 1181 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
| 1182 } | |
| 1183 }else{ | |
| 1184 for(i8=0; i8<4; i8++){ | |
| 1185 const int x8 = i8&1; | |
| 1186 const int y8 = i8>>1; | |
| 1187 | |
| 1188 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) | |
| 1189 continue; | |
| 1190 h->sub_mb_type[i8] = sub_mb_type; | |
| 1191 | |
| 1192 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
| 1193 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
| 1194 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref[0], 1); | |
| 1195 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, ref[1], 1); | |
| 1196 | |
| 1197 /* col_zero_flag */ | |
| 1198 if(!IS_INTRA(mb_type_col) && l1ref0[x8 + y8*h->b8_stride] == 0){ | |
| 1199 for(i4=0; i4<4; i4++){ | |
| 1200 const int16_t *mv_col = l1mv0[x8*2 + (i4&1) + (y8*2 + (i4>>1))*h->b_stride]; | |
| 1201 if(ABS(mv_col[0]) <= 1 && ABS(mv_col[1]) <= 1){ | |
| 1202 if(ref[0] == 0) | |
| 1203 *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0; | |
| 1204 if(ref[1] == 0) | |
| 1205 *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0; | |
| 1206 } | |
| 1207 } | |
| 1208 } | |
| 1209 } | |
| 1210 } | |
| 1211 }else{ /* direct temporal mv pred */ | |
| 1212 if(IS_16X16(*mb_type)){ | |
| 1213 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); | |
| 1214 if(IS_INTRA(mb_type_col)){ | |
| 1215 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
| 1216 fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
| 1217 fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
| 1218 }else{ | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1219 const int ref0 = l1ref0[0] >= 0 ? h->map_col_to_list0[0][l1ref0[0]] |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1220 : h->map_col_to_list0[1][l1ref1[0]]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1221 assert(ref0 >= 0); |
| 2396 | 1222 const int dist_scale_factor = h->dist_scale_factor[ref0]; |
| 1223 const int16_t *mv_col = l1mv0[0]; | |
| 1224 int mv_l0[2]; | |
| 1225 mv_l0[0] = (dist_scale_factor * mv_col[0] + 128) >> 8; | |
| 1226 mv_l0[1] = (dist_scale_factor * mv_col[1] + 128) >> 8; | |
| 1227 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref0, 1); | |
| 1228 fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv_l0[0],mv_l0[1]), 4); | |
| 1229 fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]), 4); | |
| 1230 } | |
| 1231 }else{ | |
| 1232 for(i8=0; i8<4; i8++){ | |
| 1233 const int x8 = i8&1; | |
| 1234 const int y8 = i8>>1; | |
| 1235 int ref0, dist_scale_factor; | |
| 1236 | |
| 1237 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) | |
| 1238 continue; | |
| 1239 h->sub_mb_type[i8] = sub_mb_type; | |
| 1240 if(IS_INTRA(mb_type_col)){ | |
| 1241 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1); | |
| 1242 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); | |
| 1243 fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); | |
| 1244 fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); | |
| 1245 continue; | |
| 1246 } | |
| 1247 | |
| 1248 ref0 = l1ref0[x8 + y8*h->b8_stride]; | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1249 if(ref0 >= 0) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1250 ref0 = h->map_col_to_list0[0][ref0]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1251 else |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1252 ref0 = h->map_col_to_list0[1][l1ref1[x8 + y8*h->b8_stride]]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
1253 assert(ref0 >= 0); |
| 2396 | 1254 dist_scale_factor = h->dist_scale_factor[ref0]; |
| 1255 | |
| 1256 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1); | |
| 1257 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); | |
| 1258 for(i4=0; i4<4; i4++){ | |
| 1259 const int16_t *mv_col = l1mv0[x8*2 + (i4&1) + (y8*2 + (i4>>1))*h->b_stride]; | |
| 1260 int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]]; | |
| 1261 mv_l0[0] = (dist_scale_factor * mv_col[0] + 128) >> 8; | |
| 1262 mv_l0[1] = (dist_scale_factor * mv_col[1] + 128) >> 8; | |
| 1263 *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = | |
| 1264 pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]); | |
| 1265 } | |
| 1266 } | |
| 1267 } | |
| 1268 } | |
| 1269 } | |
| 1270 | |
| 1168 | 1271 static inline void write_back_motion(H264Context *h, int mb_type){ |
| 1272 MpegEncContext * const s = &h->s; | |
| 1273 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; | |
| 1274 const int b8_xy= 2*s->mb_x + 2*s->mb_y*h->b8_stride; | |
| 1275 int list; | |
| 1276 | |
| 1277 for(list=0; list<2; list++){ | |
| 1278 int y; | |
| 2535 | 1279 if(!USES_LIST(mb_type, list)){ |
| 1168 | 1280 if(1){ //FIXME skip or never read if mb_type doesnt use it |
| 1281 for(y=0; y<4; y++){ | |
| 1282 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= | |
| 1283 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= 0; | |
| 1284 } | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1285 if( h->pps.cabac ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1286 /* FIXME needed ? */ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1287 for(y=0; y<4; y++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1288 *(uint64_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1289 *(uint64_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]= 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1290 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1291 } |
| 1168 | 1292 for(y=0; y<2; y++){ |
|
2365
b76a4977447a
Fixed typo which caused incorrect motion prediction in B-frames. patch by (Loren Merritt <lorenm ta u tod washington tod edu>)
michael
parents:
2336
diff
changeset
|
1293 *(uint16_t*)&s->current_picture.ref_index[list][b8_xy + y*h->b8_stride]= (LIST_NOT_USED&0xFF)*0x0101; |
| 1168 | 1294 } |
| 1295 } | |
| 2396 | 1296 continue; |
| 1168 | 1297 } |
| 1298 | |
| 1299 for(y=0; y<4; y++){ | |
| 1300 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+0 + 8*y]; | |
| 1301 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+2 + 8*y]; | |
| 1302 } | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1303 if( h->pps.cabac ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1304 for(y=0; y<4; y++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1305 *(uint64_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mvd_cache[list][scan8[0]+0 + 8*y]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1306 *(uint64_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mvd_cache[list][scan8[0]+2 + 8*y]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1307 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1308 } |
| 1168 | 1309 for(y=0; y<2; y++){ |
| 1310 s->current_picture.ref_index[list][b8_xy + 0 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+0 + 16*y]; | |
| 1311 s->current_picture.ref_index[list][b8_xy + 1 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+2 + 16*y]; | |
| 1312 } | |
| 1313 } | |
| 2396 | 1314 |
| 1315 if(h->slice_type == B_TYPE && h->pps.cabac){ | |
| 1316 if(IS_8X8(mb_type)){ | |
| 1317 h->direct_table[b8_xy+1+0*h->b8_stride] = IS_DIRECT(h->sub_mb_type[1]) ? 1 : 0; | |
| 1318 h->direct_table[b8_xy+0+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[2]) ? 1 : 0; | |
| 1319 h->direct_table[b8_xy+1+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[3]) ? 1 : 0; | |
| 1320 } | |
| 1321 } | |
| 1168 | 1322 } |
| 1323 | |
| 1324 /** | |
| 1325 * Decodes a network abstraction layer unit. | |
| 1326 * @param consumed is the number of bytes used as input | |
| 1327 * @param length is the length of the array | |
| 1328 * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp ttailing? | |
| 1329 * @returns decoded bytes, might be src+1 if no escapes | |
| 1330 */ | |
| 1331 static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){ | |
| 1332 int i, si, di; | |
| 1333 uint8_t *dst; | |
| 1334 | |
| 1335 // src[0]&0x80; //forbidden bit | |
| 1336 h->nal_ref_idc= src[0]>>5; | |
| 1337 h->nal_unit_type= src[0]&0x1F; | |
| 1338 | |
| 1339 src++; length--; | |
| 1340 #if 0 | |
| 1341 for(i=0; i<length; i++) | |
| 1342 printf("%2X ", src[i]); | |
| 1343 #endif | |
| 1344 for(i=0; i+1<length; i+=2){ | |
| 1345 if(src[i]) continue; | |
| 1346 if(i>0 && src[i-1]==0) i--; | |
| 1347 if(i+2<length && src[i+1]==0 && src[i+2]<=3){ | |
| 1348 if(src[i+2]!=3){ | |
| 1349 /* startcode, so we must be past the end */ | |
| 1350 length=i; | |
| 1351 } | |
| 1352 break; | |
| 1353 } | |
| 1354 } | |
| 1355 | |
| 1356 if(i>=length-1){ //no escaped 0 | |
| 1357 *dst_length= length; | |
| 1358 *consumed= length+1; //+1 for the header | |
| 1359 return src; | |
| 1360 } | |
| 1361 | |
| 1362 h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length); | |
| 1363 dst= h->rbsp_buffer; | |
| 1364 | |
| 1365 //printf("deoding esc\n"); | |
| 1366 si=di=0; | |
| 1367 while(si<length){ | |
| 1368 //remove escapes (very rare 1:2^22) | |
| 1369 if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){ | |
| 1370 if(src[si+2]==3){ //escape | |
| 1371 dst[di++]= 0; | |
| 1372 dst[di++]= 0; | |
| 1373 si+=3; | |
|
1957
54411768fa38
h264 nal decoding fix by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1956
diff
changeset
|
1374 continue; |
| 1168 | 1375 }else //next start code |
| 1376 break; | |
| 1377 } | |
| 1378 | |
| 1379 dst[di++]= src[si++]; | |
| 1380 } | |
| 1381 | |
| 1382 *dst_length= di; | |
| 1383 *consumed= si + 1;//+1 for the header | |
| 1384 //FIXME store exact number of bits in the getbitcontext (its needed for decoding) | |
| 1385 return dst; | |
| 1386 } | |
| 1387 | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1388 #if 0 |
| 1168 | 1389 /** |
| 1390 * @param src the data which should be escaped | |
| 1391 * @param dst the target buffer, dst+1 == src is allowed as a special case | |
| 1392 * @param length the length of the src data | |
| 1393 * @param dst_length the length of the dst array | |
| 1394 * @returns length of escaped data in bytes or -1 if an error occured | |
| 1395 */ | |
| 1396 static int encode_nal(H264Context *h, uint8_t *dst, uint8_t *src, int length, int dst_length){ | |
| 1397 int i, escape_count, si, di; | |
| 1398 uint8_t *temp; | |
| 1399 | |
| 1400 assert(length>=0); | |
| 1401 assert(dst_length>0); | |
| 1402 | |
| 1403 dst[0]= (h->nal_ref_idc<<5) + h->nal_unit_type; | |
| 1404 | |
| 1405 if(length==0) return 1; | |
| 1406 | |
| 1407 escape_count= 0; | |
| 1408 for(i=0; i<length; i+=2){ | |
| 1409 if(src[i]) continue; | |
| 1410 if(i>0 && src[i-1]==0) | |
| 1411 i--; | |
| 1412 if(i+2<length && src[i+1]==0 && src[i+2]<=3){ | |
| 1413 escape_count++; | |
| 1414 i+=2; | |
| 1415 } | |
| 1416 } | |
| 1417 | |
| 1418 if(escape_count==0){ | |
| 1419 if(dst+1 != src) | |
| 1420 memcpy(dst+1, src, length); | |
| 1421 return length + 1; | |
| 1422 } | |
| 1423 | |
| 1424 if(length + escape_count + 1> dst_length) | |
| 1425 return -1; | |
| 1426 | |
| 1427 //this should be damn rare (hopefully) | |
| 1428 | |
| 1429 h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length + escape_count); | |
| 1430 temp= h->rbsp_buffer; | |
| 1431 //printf("encoding esc\n"); | |
| 1432 | |
| 1433 si= 0; | |
| 1434 di= 0; | |
| 1435 while(si < length){ | |
| 1436 if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){ | |
| 1437 temp[di++]= 0; si++; | |
| 1438 temp[di++]= 0; si++; | |
| 1439 temp[di++]= 3; | |
| 1440 temp[di++]= src[si++]; | |
| 1441 } | |
| 1442 else | |
| 1443 temp[di++]= src[si++]; | |
| 1444 } | |
| 1445 memcpy(dst+1, temp, length+escape_count); | |
| 1446 | |
| 1447 assert(di == length+escape_count); | |
| 1448 | |
| 1449 return di + 1; | |
| 1450 } | |
| 1451 | |
| 1452 /** | |
| 1453 * write 1,10,100,1000,... for alignment, yes its exactly inverse to mpeg4 | |
| 1454 */ | |
| 1455 static void encode_rbsp_trailing(PutBitContext *pb){ | |
| 1456 int length; | |
| 1457 put_bits(pb, 1, 1); | |
| 1786 | 1458 length= (-put_bits_count(pb))&7; |
| 1168 | 1459 if(length) put_bits(pb, length, 0); |
| 1460 } | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1461 #endif |
| 1168 | 1462 |
| 1463 /** | |
| 1464 * identifies the exact end of the bitstream | |
| 1465 * @return the length of the trailing, or 0 if damaged | |
| 1466 */ | |
| 1467 static int decode_rbsp_trailing(uint8_t *src){ | |
| 1468 int v= *src; | |
| 1469 int r; | |
| 1470 | |
| 1170 | 1471 tprintf("rbsp trailing %X\n", v); |
| 1168 | 1472 |
| 1473 for(r=1; r<9; r++){ | |
| 1474 if(v&1) return r; | |
| 1475 v>>=1; | |
| 1476 } | |
| 1477 return 0; | |
| 1478 } | |
| 1479 | |
| 1480 /** | |
| 1481 * idct tranforms the 16 dc values and dequantize them. | |
| 1482 * @param qp quantization parameter | |
| 1483 */ | |
| 1484 static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp){ | |
| 1485 const int qmul= dequant_coeff[qp][0]; | |
| 1486 #define stride 16 | |
| 1487 int i; | |
| 1488 int temp[16]; //FIXME check if this is a good idea | |
| 1489 static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride}; | |
| 1490 static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride}; | |
| 1491 | |
| 1492 //memset(block, 64, 2*256); | |
| 1493 //return; | |
| 1494 for(i=0; i<4; i++){ | |
| 1495 const int offset= y_offset[i]; | |
| 1496 const int z0= block[offset+stride*0] + block[offset+stride*4]; | |
| 1497 const int z1= block[offset+stride*0] - block[offset+stride*4]; | |
| 1498 const int z2= block[offset+stride*1] - block[offset+stride*5]; | |
| 1499 const int z3= block[offset+stride*1] + block[offset+stride*5]; | |
| 1500 | |
| 1501 temp[4*i+0]= z0+z3; | |
| 1502 temp[4*i+1]= z1+z2; | |
| 1503 temp[4*i+2]= z1-z2; | |
| 1504 temp[4*i+3]= z0-z3; | |
| 1505 } | |
| 1506 | |
| 1507 for(i=0; i<4; i++){ | |
| 1508 const int offset= x_offset[i]; | |
| 1509 const int z0= temp[4*0+i] + temp[4*2+i]; | |
| 1510 const int z1= temp[4*0+i] - temp[4*2+i]; | |
| 1511 const int z2= temp[4*1+i] - temp[4*3+i]; | |
| 1512 const int z3= temp[4*1+i] + temp[4*3+i]; | |
| 1513 | |
| 1514 block[stride*0 +offset]= ((z0 + z3)*qmul + 2)>>2; //FIXME think about merging this into decode_resdual | |
| 1515 block[stride*2 +offset]= ((z1 + z2)*qmul + 2)>>2; | |
| 1516 block[stride*8 +offset]= ((z1 - z2)*qmul + 2)>>2; | |
| 1517 block[stride*10+offset]= ((z0 - z3)*qmul + 2)>>2; | |
| 1518 } | |
| 1519 } | |
| 1520 | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1521 #if 0 |
| 1168 | 1522 /** |
| 1523 * dct tranforms the 16 dc values. | |
| 1524 * @param qp quantization parameter ??? FIXME | |
| 1525 */ | |
| 1526 static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){ | |
| 1527 // const int qmul= dequant_coeff[qp][0]; | |
| 1528 int i; | |
| 1529 int temp[16]; //FIXME check if this is a good idea | |
| 1530 static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride}; | |
| 1531 static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride}; | |
| 1532 | |
| 1533 for(i=0; i<4; i++){ | |
| 1534 const int offset= y_offset[i]; | |
| 1535 const int z0= block[offset+stride*0] + block[offset+stride*4]; | |
| 1536 const int z1= block[offset+stride*0] - block[offset+stride*4]; | |
| 1537 const int z2= block[offset+stride*1] - block[offset+stride*5]; | |
| 1538 const int z3= block[offset+stride*1] + block[offset+stride*5]; | |
| 1539 | |
| 1540 temp[4*i+0]= z0+z3; | |
| 1541 temp[4*i+1]= z1+z2; | |
| 1542 temp[4*i+2]= z1-z2; | |
| 1543 temp[4*i+3]= z0-z3; | |
| 1544 } | |
| 1545 | |
| 1546 for(i=0; i<4; i++){ | |
| 1547 const int offset= x_offset[i]; | |
| 1548 const int z0= temp[4*0+i] + temp[4*2+i]; | |
| 1549 const int z1= temp[4*0+i] - temp[4*2+i]; | |
| 1550 const int z2= temp[4*1+i] - temp[4*3+i]; | |
| 1551 const int z3= temp[4*1+i] + temp[4*3+i]; | |
| 1552 | |
| 1553 block[stride*0 +offset]= (z0 + z3)>>1; | |
| 1554 block[stride*2 +offset]= (z1 + z2)>>1; | |
| 1555 block[stride*8 +offset]= (z1 - z2)>>1; | |
| 1556 block[stride*10+offset]= (z0 - z3)>>1; | |
| 1557 } | |
| 1558 } | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1559 #endif |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1560 |
| 1168 | 1561 #undef xStride |
| 1562 #undef stride | |
| 1563 | |
| 1564 static void chroma_dc_dequant_idct_c(DCTELEM *block, int qp){ | |
| 1565 const int qmul= dequant_coeff[qp][0]; | |
| 1566 const int stride= 16*2; | |
| 1567 const int xStride= 16; | |
| 1568 int a,b,c,d,e; | |
| 1569 | |
| 1570 a= block[stride*0 + xStride*0]; | |
| 1571 b= block[stride*0 + xStride*1]; | |
| 1572 c= block[stride*1 + xStride*0]; | |
| 1573 d= block[stride*1 + xStride*1]; | |
| 1574 | |
| 1575 e= a-b; | |
| 1576 a= a+b; | |
| 1577 b= c-d; | |
| 1578 c= c+d; | |
| 1579 | |
| 1580 block[stride*0 + xStride*0]= ((a+c)*qmul + 0)>>1; | |
| 1581 block[stride*0 + xStride*1]= ((e+b)*qmul + 0)>>1; | |
| 1582 block[stride*1 + xStride*0]= ((a-c)*qmul + 0)>>1; | |
| 1583 block[stride*1 + xStride*1]= ((e-b)*qmul + 0)>>1; | |
| 1584 } | |
| 1585 | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1586 #if 0 |
| 1168 | 1587 static void chroma_dc_dct_c(DCTELEM *block){ |
| 1588 const int stride= 16*2; | |
| 1589 const int xStride= 16; | |
| 1590 int a,b,c,d,e; | |
| 1591 | |
| 1592 a= block[stride*0 + xStride*0]; | |
| 1593 b= block[stride*0 + xStride*1]; | |
| 1594 c= block[stride*1 + xStride*0]; | |
| 1595 d= block[stride*1 + xStride*1]; | |
| 1596 | |
| 1597 e= a-b; | |
| 1598 a= a+b; | |
| 1599 b= c-d; | |
| 1600 c= c+d; | |
| 1601 | |
| 1602 block[stride*0 + xStride*0]= (a+c); | |
| 1603 block[stride*0 + xStride*1]= (e+b); | |
| 1604 block[stride*1 + xStride*0]= (a-c); | |
| 1605 block[stride*1 + xStride*1]= (e-b); | |
| 1606 } | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1607 #endif |
| 1168 | 1608 |
| 1609 /** | |
| 1610 * gets the chroma qp. | |
| 1611 */ | |
| 1612 static inline int get_chroma_qp(H264Context *h, int qscale){ | |
| 1613 | |
| 1614 return chroma_qp[clip(qscale + h->pps.chroma_qp_index_offset, 0, 51)]; | |
| 1615 } | |
| 1616 | |
| 1617 | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1618 #if 0 |
| 1168 | 1619 static void h264_diff_dct_c(DCTELEM *block, uint8_t *src1, uint8_t *src2, int stride){ |
| 1620 int i; | |
| 1621 //FIXME try int temp instead of block | |
| 1622 | |
| 1623 for(i=0; i<4; i++){ | |
| 1624 const int d0= src1[0 + i*stride] - src2[0 + i*stride]; | |
| 1625 const int d1= src1[1 + i*stride] - src2[1 + i*stride]; | |
| 1626 const int d2= src1[2 + i*stride] - src2[2 + i*stride]; | |
| 1627 const int d3= src1[3 + i*stride] - src2[3 + i*stride]; | |
| 1628 const int z0= d0 + d3; | |
| 1629 const int z3= d0 - d3; | |
| 1630 const int z1= d1 + d2; | |
| 1631 const int z2= d1 - d2; | |
| 1632 | |
| 1633 block[0 + 4*i]= z0 + z1; | |
| 1634 block[1 + 4*i]= 2*z3 + z2; | |
| 1635 block[2 + 4*i]= z0 - z1; | |
| 1636 block[3 + 4*i]= z3 - 2*z2; | |
| 1637 } | |
| 1638 | |
| 1639 for(i=0; i<4; i++){ | |
| 1640 const int z0= block[0*4 + i] + block[3*4 + i]; | |
| 1641 const int z3= block[0*4 + i] - block[3*4 + i]; | |
| 1642 const int z1= block[1*4 + i] + block[2*4 + i]; | |
| 1643 const int z2= block[1*4 + i] - block[2*4 + i]; | |
| 1644 | |
| 1645 block[0*4 + i]= z0 + z1; | |
| 1646 block[1*4 + i]= 2*z3 + z2; | |
| 1647 block[2*4 + i]= z0 - z1; | |
| 1648 block[3*4 + i]= z3 - 2*z2; | |
| 1649 } | |
| 1650 } | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1651 #endif |
| 1168 | 1652 |
| 1653 //FIXME need to check that this doesnt overflow signed 32 bit for low qp, iam not sure, its very close | |
| 1654 //FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away) | |
| 1655 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int seperate_dc){ | |
| 1656 int i; | |
| 1657 const int * const quant_table= quant_coeff[qscale]; | |
| 1658 const int bias= intra ? (1<<QUANT_SHIFT)/3 : (1<<QUANT_SHIFT)/6; | |
| 1659 const unsigned int threshold1= (1<<QUANT_SHIFT) - bias - 1; | |
| 1660 const unsigned int threshold2= (threshold1<<1); | |
| 1661 int last_non_zero; | |
| 1662 | |
| 1663 if(seperate_dc){ | |
| 1664 if(qscale<=18){ | |
| 1665 //avoid overflows | |
| 1666 const int dc_bias= intra ? (1<<(QUANT_SHIFT-2))/3 : (1<<(QUANT_SHIFT-2))/6; | |
| 1667 const unsigned int dc_threshold1= (1<<(QUANT_SHIFT-2)) - dc_bias - 1; | |
| 1668 const unsigned int dc_threshold2= (dc_threshold1<<1); | |
| 1669 | |
| 1670 int level= block[0]*quant_coeff[qscale+18][0]; | |
| 1671 if(((unsigned)(level+dc_threshold1))>dc_threshold2){ | |
| 1672 if(level>0){ | |
| 1673 level= (dc_bias + level)>>(QUANT_SHIFT-2); | |
| 1674 block[0]= level; | |
| 1675 }else{ | |
| 1676 level= (dc_bias - level)>>(QUANT_SHIFT-2); | |
| 1677 block[0]= -level; | |
| 1678 } | |
| 1679 // last_non_zero = i; | |
| 1680 }else{ | |
| 1681 block[0]=0; | |
| 1682 } | |
| 1683 }else{ | |
| 1684 const int dc_bias= intra ? (1<<(QUANT_SHIFT+1))/3 : (1<<(QUANT_SHIFT+1))/6; | |
| 1685 const unsigned int dc_threshold1= (1<<(QUANT_SHIFT+1)) - dc_bias - 1; | |
| 1686 const unsigned int dc_threshold2= (dc_threshold1<<1); | |
| 1687 | |
| 1688 int level= block[0]*quant_table[0]; | |
| 1689 if(((unsigned)(level+dc_threshold1))>dc_threshold2){ | |
| 1690 if(level>0){ | |
| 1691 level= (dc_bias + level)>>(QUANT_SHIFT+1); | |
| 1692 block[0]= level; | |
| 1693 }else{ | |
| 1694 level= (dc_bias - level)>>(QUANT_SHIFT+1); | |
| 1695 block[0]= -level; | |
| 1696 } | |
| 1697 // last_non_zero = i; | |
| 1698 }else{ | |
| 1699 block[0]=0; | |
| 1700 } | |
| 1701 } | |
| 1702 last_non_zero= 0; | |
| 1703 i=1; | |
| 1704 }else{ | |
| 1705 last_non_zero= -1; | |
| 1706 i=0; | |
| 1707 } | |
| 1708 | |
| 1709 for(; i<16; i++){ | |
| 1710 const int j= scantable[i]; | |
| 1711 int level= block[j]*quant_table[j]; | |
| 1712 | |
| 1713 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
| 1714 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
| 1715 if(((unsigned)(level+threshold1))>threshold2){ | |
| 1716 if(level>0){ | |
| 1717 level= (bias + level)>>QUANT_SHIFT; | |
| 1718 block[j]= level; | |
| 1719 }else{ | |
| 1720 level= (bias - level)>>QUANT_SHIFT; | |
| 1721 block[j]= -level; | |
| 1722 } | |
| 1723 last_non_zero = i; | |
| 1724 }else{ | |
| 1725 block[j]=0; | |
| 1726 } | |
| 1727 } | |
| 1728 | |
| 1729 return last_non_zero; | |
| 1730 } | |
| 1731 | |
| 1732 static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1733 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
| 1734 ((uint32_t*)(src+0*stride))[0]= a; | |
| 1735 ((uint32_t*)(src+1*stride))[0]= a; | |
| 1736 ((uint32_t*)(src+2*stride))[0]= a; | |
| 1737 ((uint32_t*)(src+3*stride))[0]= a; | |
| 1738 } | |
| 1739 | |
| 1740 static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1741 ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101; | |
| 1742 ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101; | |
| 1743 ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101; | |
| 1744 ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101; | |
| 1745 } | |
| 1746 | |
| 1747 static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1748 const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] | |
| 1749 + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3; | |
| 1750 | |
| 1751 ((uint32_t*)(src+0*stride))[0]= | |
| 1752 ((uint32_t*)(src+1*stride))[0]= | |
| 1753 ((uint32_t*)(src+2*stride))[0]= | |
| 1754 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
| 1755 } | |
| 1756 | |
| 1757 static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1758 const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2; | |
| 1759 | |
| 1760 ((uint32_t*)(src+0*stride))[0]= | |
| 1761 ((uint32_t*)(src+1*stride))[0]= | |
| 1762 ((uint32_t*)(src+2*stride))[0]= | |
| 1763 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
| 1764 } | |
| 1765 | |
| 1766 static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1767 const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2; | |
| 1768 | |
| 1769 ((uint32_t*)(src+0*stride))[0]= | |
| 1770 ((uint32_t*)(src+1*stride))[0]= | |
| 1771 ((uint32_t*)(src+2*stride))[0]= | |
| 1772 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
| 1773 } | |
| 1774 | |
| 1775 static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1776 ((uint32_t*)(src+0*stride))[0]= | |
| 1777 ((uint32_t*)(src+1*stride))[0]= | |
| 1778 ((uint32_t*)(src+2*stride))[0]= | |
| 1779 ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U; | |
| 1780 } | |
| 1781 | |
| 1782 | |
| 1783 #define LOAD_TOP_RIGHT_EDGE\ | |
| 1784 const int t4= topright[0];\ | |
| 1785 const int t5= topright[1];\ | |
| 1786 const int t6= topright[2];\ | |
| 1787 const int t7= topright[3];\ | |
| 1788 | |
| 1789 #define LOAD_LEFT_EDGE\ | |
| 1790 const int l0= src[-1+0*stride];\ | |
| 1791 const int l1= src[-1+1*stride];\ | |
| 1792 const int l2= src[-1+2*stride];\ | |
| 1793 const int l3= src[-1+3*stride];\ | |
| 1794 | |
| 1795 #define LOAD_TOP_EDGE\ | |
| 1796 const int t0= src[ 0-1*stride];\ | |
| 1797 const int t1= src[ 1-1*stride];\ | |
| 1798 const int t2= src[ 2-1*stride];\ | |
| 1799 const int t3= src[ 3-1*stride];\ | |
| 1800 | |
| 1801 static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1802 const int lt= src[-1-1*stride]; | |
| 1803 LOAD_TOP_EDGE | |
| 1804 LOAD_LEFT_EDGE | |
| 1805 | |
| 1806 src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2; | |
| 1807 src[0+2*stride]= | |
| 1808 src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2; | |
| 1809 src[0+1*stride]= | |
| 1810 src[1+2*stride]= | |
| 1811 src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2; | |
| 1812 src[0+0*stride]= | |
| 1813 src[1+1*stride]= | |
| 1814 src[2+2*stride]= | |
| 1815 src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
| 1816 src[1+0*stride]= | |
| 1817 src[2+1*stride]= | |
| 1818 src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
| 1819 src[2+0*stride]= | |
| 1820 src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
| 1821 src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
| 1282 | 1822 } |
| 1168 | 1823 |
| 1824 static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1825 LOAD_TOP_EDGE | |
| 1826 LOAD_TOP_RIGHT_EDGE | |
| 1827 // LOAD_LEFT_EDGE | |
| 1828 | |
| 1829 src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2; | |
| 1830 src[1+0*stride]= | |
| 1831 src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2; | |
| 1832 src[2+0*stride]= | |
| 1833 src[1+1*stride]= | |
| 1834 src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2; | |
| 1835 src[3+0*stride]= | |
| 1836 src[2+1*stride]= | |
| 1837 src[1+2*stride]= | |
| 1838 src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2; | |
| 1839 src[3+1*stride]= | |
| 1840 src[2+2*stride]= | |
| 1841 src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2; | |
| 1842 src[3+2*stride]= | |
| 1843 src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2; | |
| 1844 src[3+3*stride]=(t6 + 3*t7 + 2)>>2; | |
| 1282 | 1845 } |
| 1168 | 1846 |
| 1847 static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1848 const int lt= src[-1-1*stride]; | |
| 1849 LOAD_TOP_EDGE | |
| 1850 LOAD_LEFT_EDGE | |
| 1851 const __attribute__((unused)) int unu= l3; | |
| 1852 | |
| 1853 src[0+0*stride]= | |
| 1854 src[1+2*stride]=(lt + t0 + 1)>>1; | |
| 1855 src[1+0*stride]= | |
| 1856 src[2+2*stride]=(t0 + t1 + 1)>>1; | |
| 1857 src[2+0*stride]= | |
| 1858 src[3+2*stride]=(t1 + t2 + 1)>>1; | |
| 1859 src[3+0*stride]=(t2 + t3 + 1)>>1; | |
| 1860 src[0+1*stride]= | |
| 1861 src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
| 1862 src[1+1*stride]= | |
| 1863 src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
| 1864 src[2+1*stride]= | |
| 1865 src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
| 1866 src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
| 1867 src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; | |
| 1868 src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
| 1282 | 1869 } |
| 1168 | 1870 |
| 1871 static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1872 LOAD_TOP_EDGE | |
| 1873 LOAD_TOP_RIGHT_EDGE | |
| 1874 const __attribute__((unused)) int unu= t7; | |
| 1875 | |
| 1876 src[0+0*stride]=(t0 + t1 + 1)>>1; | |
| 1877 src[1+0*stride]= | |
| 1878 src[0+2*stride]=(t1 + t2 + 1)>>1; | |
| 1879 src[2+0*stride]= | |
| 1880 src[1+2*stride]=(t2 + t3 + 1)>>1; | |
| 1881 src[3+0*stride]= | |
| 1882 src[2+2*stride]=(t3 + t4+ 1)>>1; | |
| 1883 src[3+2*stride]=(t4 + t5+ 1)>>1; | |
| 1884 src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
| 1885 src[1+1*stride]= | |
| 1886 src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
| 1887 src[2+1*stride]= | |
| 1888 src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; | |
| 1889 src[3+1*stride]= | |
| 1890 src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; | |
| 1891 src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2; | |
| 1282 | 1892 } |
| 1168 | 1893 |
| 1894 static void pred4x4_horizontal_up_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1895 LOAD_LEFT_EDGE | |
| 1896 | |
| 1897 src[0+0*stride]=(l0 + l1 + 1)>>1; | |
| 1898 src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
| 1899 src[2+0*stride]= | |
| 1900 src[0+1*stride]=(l1 + l2 + 1)>>1; | |
| 1901 src[3+0*stride]= | |
| 1902 src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2; | |
| 1903 src[2+1*stride]= | |
| 1904 src[0+2*stride]=(l2 + l3 + 1)>>1; | |
| 1905 src[3+1*stride]= | |
| 1906 src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2; | |
| 1907 src[3+2*stride]= | |
| 1908 src[1+3*stride]= | |
| 1909 src[0+3*stride]= | |
| 1910 src[2+2*stride]= | |
| 1911 src[2+3*stride]= | |
| 1912 src[3+3*stride]=l3; | |
| 1282 | 1913 } |
| 1168 | 1914 |
| 1915 static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1916 const int lt= src[-1-1*stride]; | |
| 1917 LOAD_TOP_EDGE | |
| 1918 LOAD_LEFT_EDGE | |
| 1919 const __attribute__((unused)) int unu= t3; | |
| 1920 | |
| 1921 src[0+0*stride]= | |
| 1922 src[2+1*stride]=(lt + l0 + 1)>>1; | |
| 1923 src[1+0*stride]= | |
| 1924 src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
| 1925 src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
| 1926 src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
| 1927 src[0+1*stride]= | |
| 1928 src[2+2*stride]=(l0 + l1 + 1)>>1; | |
| 1929 src[1+1*stride]= | |
| 1930 src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2; | |
| 1931 src[0+2*stride]= | |
| 1932 src[2+3*stride]=(l1 + l2+ 1)>>1; | |
| 1933 src[1+2*stride]= | |
| 1934 src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
| 1935 src[0+3*stride]=(l2 + l3 + 1)>>1; | |
| 1936 src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2; | |
| 1282 | 1937 } |
| 1168 | 1938 |
| 1939 static void pred16x16_vertical_c(uint8_t *src, int stride){ | |
| 1940 int i; | |
| 1941 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
| 1942 const uint32_t b= ((uint32_t*)(src-stride))[1]; | |
| 1943 const uint32_t c= ((uint32_t*)(src-stride))[2]; | |
| 1944 const uint32_t d= ((uint32_t*)(src-stride))[3]; | |
| 1945 | |
| 1946 for(i=0; i<16; i++){ | |
| 1947 ((uint32_t*)(src+i*stride))[0]= a; | |
| 1948 ((uint32_t*)(src+i*stride))[1]= b; | |
| 1949 ((uint32_t*)(src+i*stride))[2]= c; | |
| 1950 ((uint32_t*)(src+i*stride))[3]= d; | |
| 1951 } | |
| 1952 } | |
| 1953 | |
| 1954 static void pred16x16_horizontal_c(uint8_t *src, int stride){ | |
| 1955 int i; | |
| 1956 | |
| 1957 for(i=0; i<16; i++){ | |
| 1958 ((uint32_t*)(src+i*stride))[0]= | |
| 1959 ((uint32_t*)(src+i*stride))[1]= | |
| 1960 ((uint32_t*)(src+i*stride))[2]= | |
| 1961 ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101; | |
| 1962 } | |
| 1963 } | |
| 1964 | |
| 1965 static void pred16x16_dc_c(uint8_t *src, int stride){ | |
| 1966 int i, dc=0; | |
| 1967 | |
| 1968 for(i=0;i<16; i++){ | |
| 1969 dc+= src[-1+i*stride]; | |
| 1970 } | |
| 1971 | |
| 1972 for(i=0;i<16; i++){ | |
| 1973 dc+= src[i-stride]; | |
| 1974 } | |
| 1975 | |
| 1976 dc= 0x01010101*((dc + 16)>>5); | |
| 1977 | |
| 1978 for(i=0; i<16; i++){ | |
| 1979 ((uint32_t*)(src+i*stride))[0]= | |
| 1980 ((uint32_t*)(src+i*stride))[1]= | |
| 1981 ((uint32_t*)(src+i*stride))[2]= | |
| 1982 ((uint32_t*)(src+i*stride))[3]= dc; | |
| 1983 } | |
| 1984 } | |
| 1985 | |
| 1986 static void pred16x16_left_dc_c(uint8_t *src, int stride){ | |
| 1987 int i, dc=0; | |
| 1988 | |
| 1989 for(i=0;i<16; i++){ | |
| 1990 dc+= src[-1+i*stride]; | |
| 1991 } | |
| 1992 | |
| 1993 dc= 0x01010101*((dc + 8)>>4); | |
| 1994 | |
| 1995 for(i=0; i<16; i++){ | |
| 1996 ((uint32_t*)(src+i*stride))[0]= | |
| 1997 ((uint32_t*)(src+i*stride))[1]= | |
| 1998 ((uint32_t*)(src+i*stride))[2]= | |
| 1999 ((uint32_t*)(src+i*stride))[3]= dc; | |
| 2000 } | |
| 2001 } | |
| 2002 | |
| 2003 static void pred16x16_top_dc_c(uint8_t *src, int stride){ | |
| 2004 int i, dc=0; | |
| 2005 | |
| 2006 for(i=0;i<16; i++){ | |
| 2007 dc+= src[i-stride]; | |
| 2008 } | |
| 2009 dc= 0x01010101*((dc + 8)>>4); | |
| 2010 | |
| 2011 for(i=0; i<16; i++){ | |
| 2012 ((uint32_t*)(src+i*stride))[0]= | |
| 2013 ((uint32_t*)(src+i*stride))[1]= | |
| 2014 ((uint32_t*)(src+i*stride))[2]= | |
| 2015 ((uint32_t*)(src+i*stride))[3]= dc; | |
| 2016 } | |
| 2017 } | |
| 2018 | |
| 2019 static void pred16x16_128_dc_c(uint8_t *src, int stride){ | |
| 2020 int i; | |
| 2021 | |
| 2022 for(i=0; i<16; i++){ | |
| 2023 ((uint32_t*)(src+i*stride))[0]= | |
| 2024 ((uint32_t*)(src+i*stride))[1]= | |
| 2025 ((uint32_t*)(src+i*stride))[2]= | |
| 2026 ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U; | |
| 2027 } | |
| 2028 } | |
| 2029 | |
| 1234 | 2030 static inline void pred16x16_plane_compat_c(uint8_t *src, int stride, const int svq3){ |
|
1184
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2031 int i, j, k; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2032 int a; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2033 uint8_t *cm = cropTbl + MAX_NEG_CROP; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2034 const uint8_t * const src0 = src+7-stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2035 const uint8_t *src1 = src+8*stride-1; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2036 const uint8_t *src2 = src1-2*stride; // == src+6*stride-1; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2037 int H = src0[1] - src0[-1]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2038 int V = src1[0] - src2[ 0]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2039 for(k=2; k<=8; ++k) { |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2040 src1 += stride; src2 -= stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2041 H += k*(src0[k] - src0[-k]); |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2042 V += k*(src1[0] - src2[ 0]); |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2043 } |
| 1234 | 2044 if(svq3){ |
| 2045 H = ( 5*(H/4) ) / 16; | |
| 2046 V = ( 5*(V/4) ) / 16; | |
|
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
2047 |
|
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
2048 /* required for 100% accuracy */ |
|
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
2049 i = H; H = V; V = i; |
| 1234 | 2050 }else{ |
| 2051 H = ( 5*H+32 ) >> 6; | |
| 2052 V = ( 5*V+32 ) >> 6; | |
| 2053 } | |
|
1184
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2054 |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2055 a = 16*(src1[0] + src2[16] + 1) - 7*(V+H); |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2056 for(j=16; j>0; --j) { |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2057 int b = a; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2058 a += V; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2059 for(i=-16; i<0; i+=4) { |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2060 src[16+i] = cm[ (b ) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2061 src[17+i] = cm[ (b+ H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2062 src[18+i] = cm[ (b+2*H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2063 src[19+i] = cm[ (b+3*H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2064 b += 4*H; |
| 1168 | 2065 } |
|
1184
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2066 src += stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2067 } |
| 1168 | 2068 } |
| 2069 | |
| 1234 | 2070 static void pred16x16_plane_c(uint8_t *src, int stride){ |
| 2071 pred16x16_plane_compat_c(src, stride, 0); | |
| 2072 } | |
| 2073 | |
| 1168 | 2074 static void pred8x8_vertical_c(uint8_t *src, int stride){ |
| 2075 int i; | |
| 2076 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
| 2077 const uint32_t b= ((uint32_t*)(src-stride))[1]; | |
| 2078 | |
| 2079 for(i=0; i<8; i++){ | |
| 2080 ((uint32_t*)(src+i*stride))[0]= a; | |
| 2081 ((uint32_t*)(src+i*stride))[1]= b; | |
| 2082 } | |
| 2083 } | |
| 2084 | |
| 2085 static void pred8x8_horizontal_c(uint8_t *src, int stride){ | |
| 2086 int i; | |
| 2087 | |
| 2088 for(i=0; i<8; i++){ | |
| 2089 ((uint32_t*)(src+i*stride))[0]= | |
| 2090 ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101; | |
| 2091 } | |
| 2092 } | |
| 2093 | |
| 2094 static void pred8x8_128_dc_c(uint8_t *src, int stride){ | |
| 2095 int i; | |
| 2096 | |
| 2097 for(i=0; i<4; i++){ | |
| 2098 ((uint32_t*)(src+i*stride))[0]= | |
| 2099 ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; | |
| 2100 } | |
| 2101 for(i=4; i<8; i++){ | |
| 2102 ((uint32_t*)(src+i*stride))[0]= | |
| 2103 ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; | |
| 2104 } | |
| 2105 } | |
| 2106 | |
| 2107 static void pred8x8_left_dc_c(uint8_t *src, int stride){ | |
| 2108 int i; | |
| 2109 int dc0, dc2; | |
| 2110 | |
| 2111 dc0=dc2=0; | |
| 2112 for(i=0;i<4; i++){ | |
| 2113 dc0+= src[-1+i*stride]; | |
| 2114 dc2+= src[-1+(i+4)*stride]; | |
| 2115 } | |
| 2116 dc0= 0x01010101*((dc0 + 2)>>2); | |
| 2117 dc2= 0x01010101*((dc2 + 2)>>2); | |
| 2118 | |
| 2119 for(i=0; i<4; i++){ | |
| 2120 ((uint32_t*)(src+i*stride))[0]= | |
| 2121 ((uint32_t*)(src+i*stride))[1]= dc0; | |
| 2122 } | |
| 2123 for(i=4; i<8; i++){ | |
| 2124 ((uint32_t*)(src+i*stride))[0]= | |
| 2125 ((uint32_t*)(src+i*stride))[1]= dc2; | |
| 2126 } | |
| 2127 } | |
| 2128 | |
| 2129 static void pred8x8_top_dc_c(uint8_t *src, int stride){ | |
| 2130 int i; | |
| 2131 int dc0, dc1; | |
| 2132 | |
| 2133 dc0=dc1=0; | |
| 2134 for(i=0;i<4; i++){ | |
| 2135 dc0+= src[i-stride]; | |
| 2136 dc1+= src[4+i-stride]; | |
| 2137 } | |
| 2138 dc0= 0x01010101*((dc0 + 2)>>2); | |
| 2139 dc1= 0x01010101*((dc1 + 2)>>2); | |
| 2140 | |
| 2141 for(i=0; i<4; i++){ | |
| 2142 ((uint32_t*)(src+i*stride))[0]= dc0; | |
| 2143 ((uint32_t*)(src+i*stride))[1]= dc1; | |
| 2144 } | |
| 2145 for(i=4; i<8; i++){ | |
| 2146 ((uint32_t*)(src+i*stride))[0]= dc0; | |
| 2147 ((uint32_t*)(src+i*stride))[1]= dc1; | |
| 2148 } | |
| 2149 } | |
| 2150 | |
| 2151 | |
| 2152 static void pred8x8_dc_c(uint8_t *src, int stride){ | |
| 2153 int i; | |
| 2154 int dc0, dc1, dc2, dc3; | |
| 2155 | |
| 2156 dc0=dc1=dc2=0; | |
| 2157 for(i=0;i<4; i++){ | |
| 2158 dc0+= src[-1+i*stride] + src[i-stride]; | |
| 2159 dc1+= src[4+i-stride]; | |
| 2160 dc2+= src[-1+(i+4)*stride]; | |
| 2161 } | |
| 2162 dc3= 0x01010101*((dc1 + dc2 + 4)>>3); | |
| 2163 dc0= 0x01010101*((dc0 + 4)>>3); | |
| 2164 dc1= 0x01010101*((dc1 + 2)>>2); | |
| 2165 dc2= 0x01010101*((dc2 + 2)>>2); | |
| 2166 | |
| 2167 for(i=0; i<4; i++){ | |
| 2168 ((uint32_t*)(src+i*stride))[0]= dc0; | |
| 2169 ((uint32_t*)(src+i*stride))[1]= dc1; | |
| 2170 } | |
| 2171 for(i=4; i<8; i++){ | |
| 2172 ((uint32_t*)(src+i*stride))[0]= dc2; | |
| 2173 ((uint32_t*)(src+i*stride))[1]= dc3; | |
| 2174 } | |
| 2175 } | |
| 2176 | |
| 2177 static void pred8x8_plane_c(uint8_t *src, int stride){ | |
|
1184
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2178 int j, k; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2179 int a; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2180 uint8_t *cm = cropTbl + MAX_NEG_CROP; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2181 const uint8_t * const src0 = src+3-stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2182 const uint8_t *src1 = src+4*stride-1; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2183 const uint8_t *src2 = src1-2*stride; // == src+2*stride-1; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2184 int H = src0[1] - src0[-1]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2185 int V = src1[0] - src2[ 0]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2186 for(k=2; k<=4; ++k) { |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2187 src1 += stride; src2 -= stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2188 H += k*(src0[k] - src0[-k]); |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2189 V += k*(src1[0] - src2[ 0]); |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2190 } |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2191 H = ( 17*H+16 ) >> 5; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2192 V = ( 17*V+16 ) >> 5; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2193 |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2194 a = 16*(src1[0] + src2[8]+1) - 3*(V+H); |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2195 for(j=8; j>0; --j) { |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2196 int b = a; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2197 a += V; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2198 src[0] = cm[ (b ) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2199 src[1] = cm[ (b+ H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2200 src[2] = cm[ (b+2*H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2201 src[3] = cm[ (b+3*H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2202 src[4] = cm[ (b+4*H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2203 src[5] = cm[ (b+5*H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2204 src[6] = cm[ (b+6*H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2205 src[7] = cm[ (b+7*H) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2206 src += stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2207 } |
| 1168 | 2208 } |
| 2209 | |
| 2210 static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list, | |
| 2211 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
| 2212 int src_x_offset, int src_y_offset, | |
| 2213 qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op){ | |
| 2214 MpegEncContext * const s = &h->s; | |
| 2215 const int mx= h->mv_cache[list][ scan8[n] ][0] + src_x_offset*8; | |
| 2216 const int my= h->mv_cache[list][ scan8[n] ][1] + src_y_offset*8; | |
| 2217 const int luma_xy= (mx&3) + ((my&3)<<2); | |
| 2218 uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*s->linesize; | |
| 2219 uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*s->uvlinesize; | |
| 2220 uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*s->uvlinesize; | |
| 2221 int extra_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; //FIXME increase edge?, IMHO not worth it | |
| 2222 int extra_height= extra_width; | |
| 2223 int emu=0; | |
| 2224 const int full_mx= mx>>2; | |
| 2225 const int full_my= my>>2; | |
| 2226 | |
| 2227 assert(pic->data[0]); | |
| 2228 | |
| 2229 if(mx&7) extra_width -= 3; | |
| 2230 if(my&7) extra_height -= 3; | |
| 2231 | |
| 2232 if( full_mx < 0-extra_width | |
| 2233 || full_my < 0-extra_height | |
| 2234 || full_mx + 16/*FIXME*/ > s->width + extra_width | |
| 2235 || full_my + 16/*FIXME*/ > s->height + extra_height){ | |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
2236 ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*s->linesize, s->linesize, 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, s->width, s->height); |
| 1168 | 2237 src_y= s->edge_emu_buffer + 2 + 2*s->linesize; |
| 2238 emu=1; | |
| 2239 } | |
| 2240 | |
| 2241 qpix_op[luma_xy](dest_y, src_y, s->linesize); //FIXME try variable height perhaps? | |
| 2242 if(!square){ | |
| 2243 qpix_op[luma_xy](dest_y + delta, src_y + delta, s->linesize); | |
| 2244 } | |
| 2245 | |
| 2246 if(s->flags&CODEC_FLAG_GRAY) return; | |
| 2247 | |
| 2248 if(emu){ | |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
2249 ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, s->uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), s->width>>1, s->height>>1); |
| 1168 | 2250 src_cb= s->edge_emu_buffer; |
| 2251 } | |
| 2252 chroma_op(dest_cb, src_cb, s->uvlinesize, chroma_height, mx&7, my&7); | |
| 2253 | |
| 2254 if(emu){ | |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
2255 ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, s->uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), s->width>>1, s->height>>1); |
| 1168 | 2256 src_cr= s->edge_emu_buffer; |
| 2257 } | |
| 2258 chroma_op(dest_cr, src_cr, s->uvlinesize, chroma_height, mx&7, my&7); | |
| 2259 } | |
| 2260 | |
| 2415 | 2261 static inline void mc_part_std(H264Context *h, int n, int square, int chroma_height, int delta, |
| 1168 | 2262 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
| 2263 int x_offset, int y_offset, | |
| 2264 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, | |
| 2265 qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, | |
| 2266 int list0, int list1){ | |
| 2267 MpegEncContext * const s = &h->s; | |
| 2268 qpel_mc_func *qpix_op= qpix_put; | |
| 2269 h264_chroma_mc_func chroma_op= chroma_put; | |
| 2270 | |
| 2271 dest_y += 2*x_offset + 2*y_offset*s-> linesize; | |
| 2272 dest_cb += x_offset + y_offset*s->uvlinesize; | |
| 2273 dest_cr += x_offset + y_offset*s->uvlinesize; | |
| 2274 x_offset += 8*s->mb_x; | |
| 2275 y_offset += 8*s->mb_y; | |
| 2276 | |
| 2277 if(list0){ | |
| 1169 | 2278 Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ]; |
| 1168 | 2279 mc_dir_part(h, ref, n, square, chroma_height, delta, 0, |
| 2280 dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2281 qpix_op, chroma_op); | |
| 2282 | |
| 2283 qpix_op= qpix_avg; | |
| 2284 chroma_op= chroma_avg; | |
| 2285 } | |
| 2286 | |
| 2287 if(list1){ | |
| 1169 | 2288 Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ]; |
| 1168 | 2289 mc_dir_part(h, ref, n, square, chroma_height, delta, 1, |
| 2290 dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2291 qpix_op, chroma_op); | |
| 2292 } | |
| 2293 } | |
| 2294 | |
| 2415 | 2295 static inline void mc_part_weighted(H264Context *h, int n, int square, int chroma_height, int delta, |
| 2296 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
| 2297 int x_offset, int y_offset, | |
| 2298 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, | |
| 2299 h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op, | |
| 2300 h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg, | |
| 2301 int list0, int list1){ | |
| 2302 MpegEncContext * const s = &h->s; | |
| 2303 | |
| 2304 dest_y += 2*x_offset + 2*y_offset*s-> linesize; | |
| 2305 dest_cb += x_offset + y_offset*s->uvlinesize; | |
| 2306 dest_cr += x_offset + y_offset*s->uvlinesize; | |
| 2307 x_offset += 8*s->mb_x; | |
| 2308 y_offset += 8*s->mb_y; | |
| 2309 | |
| 2310 if(list0 && list1){ | |
| 2311 /* don't optimize for luma-only case, since B-frames usually | |
| 2312 * use implicit weights => chroma too. */ | |
| 2313 uint8_t *tmp_cb = s->obmc_scratchpad; | |
| 2314 uint8_t *tmp_cr = tmp_cb + 8*s->uvlinesize; | |
| 2315 uint8_t *tmp_y = tmp_cr + 8*s->uvlinesize; | |
| 2316 int refn0 = h->ref_cache[0][ scan8[n] ]; | |
| 2317 int refn1 = h->ref_cache[1][ scan8[n] ]; | |
| 2318 | |
| 2319 mc_dir_part(h, &h->ref_list[0][refn0], n, square, chroma_height, delta, 0, | |
| 2320 dest_y, dest_cb, dest_cr, | |
| 2321 x_offset, y_offset, qpix_put, chroma_put); | |
| 2322 mc_dir_part(h, &h->ref_list[1][refn1], n, square, chroma_height, delta, 1, | |
| 2323 tmp_y, tmp_cb, tmp_cr, | |
| 2324 x_offset, y_offset, qpix_put, chroma_put); | |
| 2325 | |
| 2326 if(h->use_weight == 2){ | |
| 2327 int weight0 = h->implicit_weight[refn0][refn1]; | |
| 2328 int weight1 = 64 - weight0; | |
| 2329 luma_weight_avg( dest_y, tmp_y, s-> linesize, 5, weight0, weight1, 0, 0); | |
| 2330 chroma_weight_avg(dest_cb, tmp_cb, s->uvlinesize, 5, weight0, weight1, 0, 0); | |
| 2331 chroma_weight_avg(dest_cr, tmp_cr, s->uvlinesize, 5, weight0, weight1, 0, 0); | |
| 2332 }else{ | |
| 2333 luma_weight_avg(dest_y, tmp_y, s->linesize, h->luma_log2_weight_denom, | |
| 2334 h->luma_weight[0][refn0], h->luma_weight[1][refn1], | |
| 2335 h->luma_offset[0][refn0], h->luma_offset[1][refn1]); | |
| 2336 chroma_weight_avg(dest_cb, tmp_cb, s->uvlinesize, h->chroma_log2_weight_denom, | |
| 2337 h->chroma_weight[0][refn0][0], h->chroma_weight[1][refn1][0], | |
| 2338 h->chroma_offset[0][refn0][0], h->chroma_offset[1][refn1][0]); | |
| 2339 chroma_weight_avg(dest_cr, tmp_cr, s->uvlinesize, h->chroma_log2_weight_denom, | |
| 2340 h->chroma_weight[0][refn0][1], h->chroma_weight[1][refn1][1], | |
| 2341 h->chroma_offset[0][refn0][1], h->chroma_offset[1][refn1][1]); | |
| 2342 } | |
| 2343 }else{ | |
| 2344 int list = list1 ? 1 : 0; | |
| 2345 int refn = h->ref_cache[list][ scan8[n] ]; | |
| 2346 Picture *ref= &h->ref_list[list][refn]; | |
| 2347 mc_dir_part(h, ref, n, square, chroma_height, delta, list, | |
| 2348 dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2349 qpix_put, chroma_put); | |
| 2350 | |
| 2351 luma_weight_op(dest_y, s->linesize, h->luma_log2_weight_denom, | |
| 2352 h->luma_weight[list][refn], h->luma_offset[list][refn]); | |
| 2353 if(h->use_weight_chroma){ | |
| 2354 chroma_weight_op(dest_cb, s->uvlinesize, h->chroma_log2_weight_denom, | |
| 2355 h->chroma_weight[list][refn][0], h->chroma_offset[list][refn][0]); | |
| 2356 chroma_weight_op(dest_cr, s->uvlinesize, h->chroma_log2_weight_denom, | |
| 2357 h->chroma_weight[list][refn][1], h->chroma_offset[list][refn][1]); | |
| 2358 } | |
| 2359 } | |
| 2360 } | |
| 2361 | |
| 2362 static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta, | |
| 2363 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
| 2364 int x_offset, int y_offset, | |
| 2365 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, | |
| 2366 qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, | |
| 2367 h264_weight_func *weight_op, h264_biweight_func *weight_avg, | |
| 2368 int list0, int list1){ | |
| 2369 if((h->use_weight==2 && list0 && list1 | |
| 2370 && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ] != 32)) | |
| 2371 || h->use_weight==1) | |
| 2372 mc_part_weighted(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr, | |
| 2373 x_offset, y_offset, qpix_put, chroma_put, | |
| 2374 weight_op[0], weight_op[3], weight_avg[0], weight_avg[3], list0, list1); | |
| 2375 else | |
| 2376 mc_part_std(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr, | |
| 2377 x_offset, y_offset, qpix_put, chroma_put, qpix_avg, chroma_avg, list0, list1); | |
| 2378 } | |
| 2379 | |
| 1168 | 2380 static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
| 2381 qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put), | |
| 2415 | 2382 qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg), |
| 2383 h264_weight_func *weight_op, h264_biweight_func *weight_avg){ | |
| 1168 | 2384 MpegEncContext * const s = &h->s; |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
2385 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1168 | 2386 const int mb_type= s->current_picture.mb_type[mb_xy]; |
| 2387 | |
| 2388 assert(IS_INTER(mb_type)); | |
| 2389 | |
| 2390 if(IS_16X16(mb_type)){ | |
| 2391 mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0, | |
| 2392 qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0], | |
| 2415 | 2393 &weight_op[0], &weight_avg[0], |
| 1168 | 2394 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); |
| 2395 }else if(IS_16X8(mb_type)){ | |
| 2396 mc_part(h, 0, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 0, | |
| 2397 qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0], | |
| 2415 | 2398 &weight_op[1], &weight_avg[1], |
| 1168 | 2399 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); |
| 2400 mc_part(h, 8, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 4, | |
| 2401 qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0], | |
| 2415 | 2402 &weight_op[1], &weight_avg[1], |
| 1168 | 2403 IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1)); |
| 2404 }else if(IS_8X16(mb_type)){ | |
| 2405 mc_part(h, 0, 0, 8, 8*s->linesize, dest_y, dest_cb, dest_cr, 0, 0, | |
| 2406 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
| 2415 | 2407 &weight_op[2], &weight_avg[2], |
| 1168 | 2408 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); |
| 2409 mc_part(h, 4, 0, 8, 8*s->linesize, dest_y, dest_cb, dest_cr, 4, 0, | |
| 2410 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
| 2415 | 2411 &weight_op[2], &weight_avg[2], |
| 1168 | 2412 IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1)); |
| 2413 }else{ | |
| 2414 int i; | |
| 2415 | |
| 2416 assert(IS_8X8(mb_type)); | |
| 2417 | |
| 2418 for(i=0; i<4; i++){ | |
| 2419 const int sub_mb_type= h->sub_mb_type[i]; | |
| 2420 const int n= 4*i; | |
| 2421 int x_offset= (i&1)<<2; | |
| 2422 int y_offset= (i&2)<<1; | |
| 2423 | |
| 2424 if(IS_SUB_8X8(sub_mb_type)){ | |
| 2425 mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2426 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
| 2415 | 2427 &weight_op[3], &weight_avg[3], |
| 1168 | 2428 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
| 2429 }else if(IS_SUB_8X4(sub_mb_type)){ | |
| 2430 mc_part(h, n , 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2431 qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1], | |
| 2415 | 2432 &weight_op[4], &weight_avg[4], |
| 1168 | 2433 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
| 2434 mc_part(h, n+2, 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset+2, | |
| 2435 qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1], | |
| 2415 | 2436 &weight_op[4], &weight_avg[4], |
| 1168 | 2437 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
| 2438 }else if(IS_SUB_4X8(sub_mb_type)){ | |
| 2439 mc_part(h, n , 0, 4, 4*s->linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2440 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
| 2415 | 2441 &weight_op[5], &weight_avg[5], |
| 1168 | 2442 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
| 2443 mc_part(h, n+1, 0, 4, 4*s->linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset, | |
| 2444 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
| 2415 | 2445 &weight_op[5], &weight_avg[5], |
| 1168 | 2446 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
| 2447 }else{ | |
| 2448 int j; | |
| 2449 assert(IS_SUB_4X4(sub_mb_type)); | |
| 2450 for(j=0; j<4; j++){ | |
| 2451 int sub_x_offset= x_offset + 2*(j&1); | |
| 2452 int sub_y_offset= y_offset + (j&2); | |
| 2453 mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset, | |
| 2454 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
| 2415 | 2455 &weight_op[6], &weight_avg[6], |
| 1168 | 2456 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
| 2457 } | |
| 2458 } | |
| 2459 } | |
| 2460 } | |
| 2461 } | |
| 2462 | |
| 2463 static void decode_init_vlc(H264Context *h){ | |
| 2464 static int done = 0; | |
| 2465 | |
| 2466 if (!done) { | |
| 2467 int i; | |
| 2468 done = 1; | |
| 2469 | |
| 2470 init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5, | |
| 2471 &chroma_dc_coeff_token_len [0], 1, 1, | |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2472 &chroma_dc_coeff_token_bits[0], 1, 1, 1); |
| 1168 | 2473 |
| 2474 for(i=0; i<4; i++){ | |
| 2475 init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17, | |
| 2476 &coeff_token_len [i][0], 1, 1, | |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2477 &coeff_token_bits[i][0], 1, 1, 1); |
| 1168 | 2478 } |
| 2479 | |
| 2480 for(i=0; i<3; i++){ | |
| 2481 init_vlc(&chroma_dc_total_zeros_vlc[i], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4, | |
| 2482 &chroma_dc_total_zeros_len [i][0], 1, 1, | |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2483 &chroma_dc_total_zeros_bits[i][0], 1, 1, 1); |
| 1168 | 2484 } |
| 2485 for(i=0; i<15; i++){ | |
| 2486 init_vlc(&total_zeros_vlc[i], TOTAL_ZEROS_VLC_BITS, 16, | |
| 2487 &total_zeros_len [i][0], 1, 1, | |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2488 &total_zeros_bits[i][0], 1, 1, 1); |
| 1168 | 2489 } |
| 2490 | |
| 2491 for(i=0; i<6; i++){ | |
| 2492 init_vlc(&run_vlc[i], RUN_VLC_BITS, 7, | |
| 2493 &run_len [i][0], 1, 1, | |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2494 &run_bits[i][0], 1, 1, 1); |
| 1168 | 2495 } |
| 2496 init_vlc(&run7_vlc, RUN7_VLC_BITS, 16, | |
| 2497 &run_len [6][0], 1, 1, | |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2498 &run_bits[6][0], 1, 1, 1); |
| 1168 | 2499 } |
| 2500 } | |
| 2501 | |
| 2502 /** | |
| 2503 * Sets the intra prediction function pointers. | |
| 2504 */ | |
| 2505 static void init_pred_ptrs(H264Context *h){ | |
| 2506 // MpegEncContext * const s = &h->s; | |
| 2507 | |
| 2508 h->pred4x4[VERT_PRED ]= pred4x4_vertical_c; | |
| 2509 h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c; | |
| 2510 h->pred4x4[DC_PRED ]= pred4x4_dc_c; | |
| 2511 h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c; | |
| 2512 h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c; | |
| 2513 h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c; | |
| 2514 h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c; | |
| 2515 h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c; | |
| 2516 h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c; | |
| 2517 h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c; | |
| 2518 h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c; | |
| 2519 h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c; | |
| 2520 | |
| 2521 h->pred8x8[DC_PRED8x8 ]= pred8x8_dc_c; | |
| 2522 h->pred8x8[VERT_PRED8x8 ]= pred8x8_vertical_c; | |
| 2523 h->pred8x8[HOR_PRED8x8 ]= pred8x8_horizontal_c; | |
| 2524 h->pred8x8[PLANE_PRED8x8 ]= pred8x8_plane_c; | |
| 2525 h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c; | |
| 2526 h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c; | |
| 2527 h->pred8x8[DC_128_PRED8x8 ]= pred8x8_128_dc_c; | |
| 2528 | |
| 2529 h->pred16x16[DC_PRED8x8 ]= pred16x16_dc_c; | |
| 2530 h->pred16x16[VERT_PRED8x8 ]= pred16x16_vertical_c; | |
| 2531 h->pred16x16[HOR_PRED8x8 ]= pred16x16_horizontal_c; | |
| 2532 h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_c; | |
| 2533 h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c; | |
| 2534 h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c; | |
| 2535 h->pred16x16[DC_128_PRED8x8 ]= pred16x16_128_dc_c; | |
| 2536 } | |
| 2537 | |
| 2538 static void free_tables(H264Context *h){ | |
| 2539 av_freep(&h->intra4x4_pred_mode); | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2540 av_freep(&h->chroma_pred_mode_table); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2541 av_freep(&h->cbp_table); |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
2542 av_freep(&h->mvd_table[0]); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
2543 av_freep(&h->mvd_table[1]); |
| 2396 | 2544 av_freep(&h->direct_table); |
| 1168 | 2545 av_freep(&h->non_zero_count); |
| 2546 av_freep(&h->slice_table_base); | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2547 av_freep(&h->top_border); |
| 1168 | 2548 h->slice_table= NULL; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2549 |
| 1168 | 2550 av_freep(&h->mb2b_xy); |
| 2551 av_freep(&h->mb2b8_xy); | |
| 2415 | 2552 |
| 2553 av_freep(&h->s.obmc_scratchpad); | |
| 1168 | 2554 } |
| 2555 | |
| 2556 /** | |
| 2557 * allocates tables. | |
| 2558 * needs widzh/height | |
| 2559 */ | |
| 2560 static int alloc_tables(H264Context *h){ | |
| 2561 MpegEncContext * const s = &h->s; | |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
2562 const int big_mb_num= s->mb_stride * (s->mb_height+1); |
| 1168 | 2563 int x,y; |
| 2564 | |
| 2565 CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t)) | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2566 |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2567 CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t)) |
| 1168 | 2568 CHECKED_ALLOCZ(h->slice_table_base , big_mb_num * sizeof(uint8_t)) |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2569 CHECKED_ALLOCZ(h->top_border , s->mb_width * (16+8+8) * sizeof(uint8_t)) |
| 2336 | 2570 CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t)) |
| 1168 | 2571 |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2572 if( h->pps.cabac ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2573 CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
2574 CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
2575 CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); |
| 2396 | 2576 CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t)); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2577 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2578 |
| 1168 | 2579 memset(h->slice_table_base, -1, big_mb_num * sizeof(uint8_t)); |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
2580 h->slice_table= h->slice_table_base + s->mb_stride + 1; |
| 1168 | 2581 |
| 2582 CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint16_t)); | |
| 2583 CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint16_t)); | |
| 2584 for(y=0; y<s->mb_height; y++){ | |
| 2585 for(x=0; x<s->mb_width; x++){ | |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
2586 const int mb_xy= x + y*s->mb_stride; |
| 1168 | 2587 const int b_xy = 4*x + 4*y*h->b_stride; |
| 2588 const int b8_xy= 2*x + 2*y*h->b8_stride; | |
| 2589 | |
| 2590 h->mb2b_xy [mb_xy]= b_xy; | |
| 2591 h->mb2b8_xy[mb_xy]= b8_xy; | |
| 2592 } | |
| 2593 } | |
| 2415 | 2594 |
| 2417 | 2595 s->obmc_scratchpad = NULL; |
| 2596 | |
| 1168 | 2597 return 0; |
| 2598 fail: | |
| 2599 free_tables(h); | |
| 2600 return -1; | |
| 2601 } | |
| 2602 | |
| 2603 static void common_init(H264Context *h){ | |
| 2604 MpegEncContext * const s = &h->s; | |
| 2605 | |
| 2606 s->width = s->avctx->width; | |
| 2607 s->height = s->avctx->height; | |
| 2608 s->codec_id= s->avctx->codec->id; | |
| 2609 | |
| 2610 init_pred_ptrs(h); | |
| 2611 | |
| 1698 | 2612 s->unrestricted_mv=1; |
| 1168 | 2613 s->decode=1; //FIXME |
| 2614 } | |
| 2615 | |
| 2616 static int decode_init(AVCodecContext *avctx){ | |
| 2617 H264Context *h= avctx->priv_data; | |
| 2618 MpegEncContext * const s = &h->s; | |
| 2619 | |
| 1892 | 2620 MPV_decode_defaults(s); |
| 2621 | |
| 1168 | 2622 s->avctx = avctx; |
| 2623 common_init(h); | |
| 2624 | |
| 2625 s->out_format = FMT_H264; | |
| 2626 s->workaround_bugs= avctx->workaround_bugs; | |
| 2627 | |
| 2628 // set defaults | |
| 2629 // s->decode_mb= ff_h263_decode_mb; | |
| 2630 s->low_delay= 1; | |
| 2631 avctx->pix_fmt= PIX_FMT_YUV420P; | |
| 2632 | |
| 2633 decode_init_vlc(h); | |
| 2634 | |
|
2547
c5781912ad8a
improved detection of "AVC1" style H.264 patch by (M?ns Rullg?rd <mru inprovide com>)
michael
parents:
2538
diff
changeset
|
2635 if(avctx->extradata_size > 0 && avctx->extradata && |
|
c5781912ad8a
improved detection of "AVC1" style H.264 patch by (M?ns Rullg?rd <mru inprovide com>)
michael
parents:
2538
diff
changeset
|
2636 *(char *)avctx->extradata == 1){ |
| 2227 | 2637 h->is_avc = 1; |
| 2638 h->got_avcC = 0; | |
|
2547
c5781912ad8a
improved detection of "AVC1" style H.264 patch by (M?ns Rullg?rd <mru inprovide com>)
michael
parents:
2538
diff
changeset
|
2639 } else { |
|
c5781912ad8a
improved detection of "AVC1" style H.264 patch by (M?ns Rullg?rd <mru inprovide com>)
michael
parents:
2538
diff
changeset
|
2640 h->is_avc = 0; |
| 2227 | 2641 } |
| 2642 | |
| 1168 | 2643 return 0; |
| 2644 } | |
| 2645 | |
| 2646 static void frame_start(H264Context *h){ | |
| 2647 MpegEncContext * const s = &h->s; | |
| 2648 int i; | |
| 2649 | |
| 2650 MPV_frame_start(s, s->avctx); | |
| 2651 ff_er_frame_start(s); | |
| 2652 | |
| 2653 assert(s->linesize && s->uvlinesize); | |
| 2654 | |
| 2655 for(i=0; i<16; i++){ | |
| 2656 h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3); | |
| 2657 h->chroma_subblock_offset[i]= 2*((scan8[i] - scan8[0])&7) + 2*s->uvlinesize*((scan8[i] - scan8[0])>>3); | |
| 2658 } | |
| 2659 for(i=0; i<4; i++){ | |
| 2660 h->block_offset[16+i]= | |
| 2661 h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3); | |
| 2662 } | |
| 2663 | |
|
2416
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2664 /* can't be in alloc_tables because linesize isn't known there. |
|
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2665 * FIXME: redo bipred weight to not require extra buffer? */ |
|
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2666 if(!s->obmc_scratchpad) |
|
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2667 s->obmc_scratchpad = av_malloc(16*s->linesize + 2*8*s->uvlinesize); |
|
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2668 |
| 1168 | 2669 // s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1; |
| 2670 } | |
| 2671 | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2672 static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize){ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2673 MpegEncContext * const s = &h->s; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2674 int i; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2675 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2676 src_y -= linesize; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2677 src_cb -= uvlinesize; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2678 src_cr -= uvlinesize; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2679 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2680 h->left_border[0]= h->top_border[s->mb_x][15]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2681 for(i=1; i<17; i++){ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2682 h->left_border[i]= src_y[15+i* linesize]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2683 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2684 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2685 *(uint64_t*)(h->top_border[s->mb_x]+0)= *(uint64_t*)(src_y + 16*linesize); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2686 *(uint64_t*)(h->top_border[s->mb_x]+8)= *(uint64_t*)(src_y +8+16*linesize); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2687 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2688 if(!(s->flags&CODEC_FLAG_GRAY)){ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2689 h->left_border[17 ]= h->top_border[s->mb_x][16+7]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2690 h->left_border[17+9]= h->top_border[s->mb_x][24+7]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2691 for(i=1; i<9; i++){ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2692 h->left_border[i+17 ]= src_cb[7+i*uvlinesize]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2693 h->left_border[i+17+9]= src_cr[7+i*uvlinesize]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2694 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2695 *(uint64_t*)(h->top_border[s->mb_x]+16)= *(uint64_t*)(src_cb+8*uvlinesize); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2696 *(uint64_t*)(h->top_border[s->mb_x]+24)= *(uint64_t*)(src_cr+8*uvlinesize); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2697 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2698 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2699 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2700 static inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int xchg){ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2701 MpegEncContext * const s = &h->s; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2702 int temp8, i; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2703 uint64_t temp64; |
|
2200
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2704 int deblock_left = (s->mb_x > 0); |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2705 int deblock_top = (s->mb_y > 0); |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2706 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2707 src_y -= linesize + 1; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2708 src_cb -= uvlinesize + 1; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2709 src_cr -= uvlinesize + 1; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2710 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2711 #define XCHG(a,b,t,xchg)\ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2712 t= a;\ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2713 if(xchg)\ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2714 a= b;\ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2715 b= t; |
|
2200
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2716 |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2717 if(deblock_left){ |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2718 for(i = !deblock_top; i<17; i++){ |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2719 XCHG(h->left_border[i ], src_y [i* linesize], temp8, xchg); |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2720 } |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2721 } |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2722 |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2723 if(deblock_top){ |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2724 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg); |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2725 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1); |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2726 } |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2727 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2728 if(!(s->flags&CODEC_FLAG_GRAY)){ |
|
2200
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2729 if(deblock_left){ |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2730 for(i = !deblock_top; i<9; i++){ |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2731 XCHG(h->left_border[i+17 ], src_cb[i*uvlinesize], temp8, xchg); |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2732 XCHG(h->left_border[i+17+9], src_cr[i*uvlinesize], temp8, xchg); |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2733 } |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2734 } |
|
2200
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2735 if(deblock_top){ |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2736 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1); |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2737 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1); |
|
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2738 } |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2739 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2740 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2741 |
| 1168 | 2742 static void hl_decode_mb(H264Context *h){ |
| 2743 MpegEncContext * const s = &h->s; | |
| 2744 const int mb_x= s->mb_x; | |
| 2745 const int mb_y= s->mb_y; | |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
2746 const int mb_xy= mb_x + mb_y*s->mb_stride; |
| 1168 | 2747 const int mb_type= s->current_picture.mb_type[mb_xy]; |
| 2748 uint8_t *dest_y, *dest_cb, *dest_cr; | |
| 2749 int linesize, uvlinesize /*dct_offset*/; | |
| 2750 int i; | |
| 2751 | |
| 2752 if(!s->decode) | |
| 2753 return; | |
| 2754 | |
| 2755 if(s->mb_skiped){ | |
| 2756 } | |
| 2757 | |
| 2758 dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16; | |
| 2759 dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
| 2760 dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
| 2761 | |
| 2762 if (h->mb_field_decoding_flag) { | |
| 2763 linesize = s->linesize * 2; | |
| 2764 uvlinesize = s->uvlinesize * 2; | |
| 2765 if(mb_y&1){ //FIXME move out of this func? | |
| 2766 dest_y -= s->linesize*15; | |
| 2767 dest_cb-= s->linesize*7; | |
| 2768 dest_cr-= s->linesize*7; | |
| 2769 } | |
| 2770 } else { | |
| 2771 linesize = s->linesize; | |
| 2772 uvlinesize = s->uvlinesize; | |
| 2773 // dct_offset = s->linesize * 16; | |
| 2774 } | |
| 2775 | |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2776 if (IS_INTRA_PCM(mb_type)) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2777 unsigned int x, y; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2778 |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2779 // The pixels are stored in h->mb array in the same order as levels, |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2780 // copy them in output in the correct order. |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2781 for(i=0; i<16; i++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2782 for (y=0; y<4; y++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2783 for (x=0; x<4; x++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2784 *(dest_y + h->block_offset[i] + y*linesize + x) = h->mb[i*16+y*4+x]; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2785 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2786 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2787 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2788 for(i=16; i<16+4; i++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2789 for (y=0; y<4; y++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2790 for (x=0; x<4; x++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2791 *(dest_cb + h->block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x]; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2792 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2793 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2794 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2795 for(i=20; i<20+4; i++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2796 for (y=0; y<4; y++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2797 for (x=0; x<4; x++) { |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2798 *(dest_cr + h->block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x]; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2799 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2800 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
2801 } |
|
2509
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2802 } else { |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2803 if(IS_INTRA(mb_type)){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2804 if(h->deblocking_filter) |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2805 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2806 |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2807 if(!(s->flags&CODEC_FLAG_GRAY)){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2808 h->pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2809 h->pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2810 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2811 |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2812 if(IS_INTRA4x4(mb_type)){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2813 if(!s->encoding){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2814 for(i=0; i<16; i++){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2815 uint8_t * const ptr= dest_y + h->block_offset[i]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2816 uint8_t *topright; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2817 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2818 int tr; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2819 |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2820 if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2821 const int topright_avail= (h->topright_samples_available<<i)&0x8000; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2822 assert(mb_y || linesize <= h->block_offset[i]); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2823 if(!topright_avail){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2824 tr= ptr[3 - linesize]*0x01010101; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2825 topright= (uint8_t*) &tr; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2826 }else if(i==5 && h->deblocking_filter){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2827 tr= *(uint32_t*)h->top_border[mb_x+1]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2828 topright= (uint8_t*) &tr; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2829 }else |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2830 topright= ptr + 4 - linesize; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2831 }else |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2832 topright= NULL; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2833 |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2834 h->pred4x4[ dir ](ptr, topright, linesize); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2835 if(h->non_zero_count_cache[ scan8[i] ]){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2836 if(s->codec_id == CODEC_ID_H264) |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2837 s->dsp.h264_idct_add(ptr, h->mb + i*16, linesize); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2838 else |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2839 svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2840 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2841 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2842 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2843 }else{ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2844 h->pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2845 if(s->codec_id == CODEC_ID_H264) |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2846 h264_luma_dc_dequant_idct_c(h->mb, s->qscale); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2847 else |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2848 svq3_luma_dc_dequant_idct_c(h->mb, s->qscale); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2849 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2850 if(h->deblocking_filter) |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2851 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2852 }else if(s->codec_id == CODEC_ID_H264){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2853 hl_motion(h, dest_y, dest_cb, dest_cr, |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2854 s->dsp.put_h264_qpel_pixels_tab, s->dsp.put_h264_chroma_pixels_tab, |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2855 s->dsp.avg_h264_qpel_pixels_tab, s->dsp.avg_h264_chroma_pixels_tab, |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2856 s->dsp.weight_h264_pixels_tab, s->dsp.biweight_h264_pixels_tab); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2857 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2858 |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2859 |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2860 if(!IS_INTRA4x4(mb_type)){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2861 if(s->codec_id == CODEC_ID_H264){ |
| 1168 | 2862 for(i=0; i<16; i++){ |
|
2509
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2863 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2864 uint8_t * const ptr= dest_y + h->block_offset[i]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2865 s->dsp.h264_idct_add(ptr, h->mb + i*16, linesize); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2866 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2867 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2868 }else{ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2869 for(i=0; i<16; i++){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2870 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2871 uint8_t * const ptr= dest_y + h->block_offset[i]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2872 svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0); |
| 1234 | 2873 } |
| 1168 | 2874 } |
| 2875 } | |
|
2509
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2876 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2877 |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2878 if(!(s->flags&CODEC_FLAG_GRAY)){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2879 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2880 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2881 if(s->codec_id == CODEC_ID_H264){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2882 for(i=16; i<16+4; i++){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2883 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2884 uint8_t * const ptr= dest_cb + h->block_offset[i]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2885 s->dsp.h264_idct_add(ptr, h->mb + i*16, uvlinesize); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2886 } |
| 1250 | 2887 } |
|
2509
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2888 for(i=20; i<20+4; i++){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2889 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2890 uint8_t * const ptr= dest_cr + h->block_offset[i]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2891 s->dsp.h264_idct_add(ptr, h->mb + i*16, uvlinesize); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2892 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2893 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2894 }else{ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2895 for(i=16; i<16+4; i++){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2896 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2897 uint8_t * const ptr= dest_cb + h->block_offset[i]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2898 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2899 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2900 } |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2901 for(i=20; i<20+4; i++){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2902 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2903 uint8_t * const ptr= dest_cr + h->block_offset[i]; |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2904 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); |
|
b3b06ba8787c
remove goto and reindent patch by (Loic Le Loarer <lll+ffmpeg m4x org>)
michael
parents:
2504
diff
changeset
|
2905 } |
| 1250 | 2906 } |
| 1168 | 2907 } |
| 2908 } | |
| 2909 } | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2910 if(h->deblocking_filter) { |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2911 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize); |
| 2449 | 2912 fill_caches(h, mb_type, 1); //FIXME dont fill stuff which isnt used by filter_mb |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2913 filter_mb(h, mb_x, mb_y, dest_y, dest_cb, dest_cr); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2914 } |
| 1168 | 2915 } |
| 2916 | |
| 2917 /** | |
| 2918 * fills the default_ref_list. | |
| 2919 */ | |
| 2920 static int fill_default_ref_list(H264Context *h){ | |
| 2921 MpegEncContext * const s = &h->s; | |
| 2922 int i; | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2923 int smallest_poc_greater_than_current = -1; |
| 1168 | 2924 Picture sorted_short_ref[16]; |
| 2925 | |
| 2926 if(h->slice_type==B_TYPE){ | |
| 2927 int out_i; | |
| 2928 int limit= -1; | |
| 2929 | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2930 /* sort frame according to poc in B slice */ |
| 1168 | 2931 for(out_i=0; out_i<h->short_ref_count; out_i++){ |
| 2932 int best_i=-1; | |
|
2255
507690ff49a2
assertion when playing AVC/H.264 streams fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2254
diff
changeset
|
2933 int best_poc=INT_MAX; |
| 1168 | 2934 |
| 2935 for(i=0; i<h->short_ref_count; i++){ | |
| 2936 const int poc= h->short_ref[i]->poc; | |
| 2937 if(poc > limit && poc < best_poc){ | |
| 2938 best_poc= poc; | |
| 2939 best_i= i; | |
| 2940 } | |
| 2941 } | |
| 2942 | |
| 2943 assert(best_i != -1); | |
| 2944 | |
| 2945 limit= best_poc; | |
| 2946 sorted_short_ref[out_i]= *h->short_ref[best_i]; | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2947 tprintf("sorted poc: %d->%d poc:%d fn:%d\n", best_i, out_i, sorted_short_ref[out_i].poc, sorted_short_ref[out_i].frame_num); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2948 if (-1 == smallest_poc_greater_than_current) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2949 if (h->short_ref[best_i]->poc >= s->current_picture_ptr->poc) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2950 smallest_poc_greater_than_current = out_i; |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2951 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2952 } |
| 1168 | 2953 } |
| 2954 } | |
| 2955 | |
| 2956 if(s->picture_structure == PICT_FRAME){ | |
| 2957 if(h->slice_type==B_TYPE){ | |
| 2958 int list; | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2959 tprintf("current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2960 |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2961 // find the largest poc |
| 1168 | 2962 for(list=0; list<2; list++){ |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2963 int index = 0; |
| 2447 | 2964 int j= -99; |
| 2965 int step= list ? -1 : 1; | |
| 2966 | |
| 2967 for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++, j+=step) { | |
| 2968 while(j<0 || j>= h->short_ref_count){ | |
| 2969 step = -step; | |
| 2970 j= smallest_poc_greater_than_current + (step>>1); | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2971 } |
| 2447 | 2972 if(sorted_short_ref[j].reference != 3) continue; |
| 2973 h->default_ref_list[list][index ]= sorted_short_ref[j]; | |
| 2974 h->default_ref_list[list][index++].pic_id= sorted_short_ref[j].frame_num; | |
| 1168 | 2975 } |
| 2976 | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2977 for(i = 0; i < 16 && index < h->ref_count[ list ]; i++){ |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2978 if(h->long_ref[i] == NULL) continue; |
| 1168 | 2979 if(h->long_ref[i]->reference != 3) continue; |
| 2980 | |
| 2981 h->default_ref_list[ list ][index ]= *h->long_ref[i]; | |
| 2982 h->default_ref_list[ list ][index++].pic_id= i;; | |
| 2983 } | |
| 2984 | |
| 2447 | 2985 if(list && (smallest_poc_greater_than_current<=0 || smallest_poc_greater_than_current>=h->short_ref_count) && (1 < index)){ |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2986 // swap the two first elements of L1 when |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2987 // L0 and L1 are identical |
| 1168 | 2988 Picture temp= h->default_ref_list[1][0]; |
| 2989 h->default_ref_list[1][0] = h->default_ref_list[1][1]; | |
| 2990 h->default_ref_list[1][0] = temp; | |
| 2991 } | |
| 2992 | |
| 2993 if(index < h->ref_count[ list ]) | |
| 2994 memset(&h->default_ref_list[list][index], 0, sizeof(Picture)*(h->ref_count[ list ] - index)); | |
| 2995 } | |
| 2996 }else{ | |
| 2997 int index=0; | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
2998 for(i=0; i<h->short_ref_count; i++){ |
| 1168 | 2999 if(h->short_ref[i]->reference != 3) continue; //FIXME refernce field shit |
| 3000 h->default_ref_list[0][index ]= *h->short_ref[i]; | |
| 3001 h->default_ref_list[0][index++].pic_id= h->short_ref[i]->frame_num; | |
| 3002 } | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3003 for(i = 0; i < 16; i++){ |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3004 if(h->long_ref[i] == NULL) continue; |
| 1168 | 3005 if(h->long_ref[i]->reference != 3) continue; |
| 3006 h->default_ref_list[0][index ]= *h->long_ref[i]; | |
| 3007 h->default_ref_list[0][index++].pic_id= i;; | |
| 3008 } | |
| 3009 if(index < h->ref_count[0]) | |
| 3010 memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index)); | |
| 3011 } | |
| 3012 }else{ //FIELD | |
| 3013 if(h->slice_type==B_TYPE){ | |
| 3014 }else{ | |
| 3015 //FIXME second field balh | |
| 3016 } | |
| 3017 } | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3018 #ifdef TRACE |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3019 for (i=0; i<h->ref_count[0]; i++) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3020 tprintf("List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3021 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3022 if(h->slice_type==B_TYPE){ |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3023 for (i=0; i<h->ref_count[1]; i++) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3024 tprintf("List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[0][i].data[0]); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3025 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3026 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3027 #endif |
| 1168 | 3028 return 0; |
| 3029 } | |
| 3030 | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3031 static void print_short_term(H264Context *h); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3032 static void print_long_term(H264Context *h); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3033 |
| 1168 | 3034 static int decode_ref_pic_list_reordering(H264Context *h){ |
| 3035 MpegEncContext * const s = &h->s; | |
| 3036 int list; | |
| 3037 | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3038 print_short_term(h); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3039 print_long_term(h); |
| 1168 | 3040 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move beofre func |
| 3041 | |
| 3042 for(list=0; list<2; list++){ | |
| 3043 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); | |
| 3044 | |
| 3045 if(get_bits1(&s->gb)){ | |
| 3046 int pred= h->curr_pic_num; | |
| 3047 int index; | |
| 3048 | |
| 3049 for(index=0; ; index++){ | |
| 3050 int reordering_of_pic_nums_idc= get_ue_golomb(&s->gb); | |
| 3051 int pic_id; | |
| 3052 int i; | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3053 Picture *ref = NULL; |
| 1168 | 3054 |
|
2284
6d26e105f68f
h.264 ref list reordering bugfix patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2272
diff
changeset
|
3055 if(reordering_of_pic_nums_idc==3) |
|
6d26e105f68f
h.264 ref list reordering bugfix patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2272
diff
changeset
|
3056 break; |
| 1168 | 3057 |
| 3058 if(index >= h->ref_count[list]){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3059 av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); |
| 1168 | 3060 return -1; |
| 3061 } | |
| 3062 | |
| 3063 if(reordering_of_pic_nums_idc<3){ | |
| 3064 if(reordering_of_pic_nums_idc<2){ | |
| 3065 const int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; | |
| 3066 | |
| 3067 if(abs_diff_pic_num >= h->max_pic_num){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3068 av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); |
| 1168 | 3069 return -1; |
| 3070 } | |
| 3071 | |
| 3072 if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num; | |
| 3073 else pred+= abs_diff_pic_num; | |
| 3074 pred &= h->max_pic_num - 1; | |
| 3075 | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3076 for(i= h->short_ref_count-1; i>=0; i--){ |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3077 ref = h->short_ref[i]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3078 if(ref->data[0] != NULL && ref->frame_num == pred && ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer |
| 1168 | 3079 break; |
| 3080 } | |
| 3081 }else{ | |
| 3082 pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3083 ref = h->long_ref[pic_id]; |
| 1168 | 3084 } |
| 3085 | |
|
2485
2844b8cf4e11
H.264 multiplce instance in reference list patch by (Loic <lll+ffmpeg m4x org )
michael
parents:
2484
diff
changeset
|
3086 if (i < 0) { |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3087 av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); |
| 1168 | 3088 memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3089 } else { |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3090 h->ref_list[list][index]= *ref; |
| 1168 | 3091 } |
|
2284
6d26e105f68f
h.264 ref list reordering bugfix patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2272
diff
changeset
|
3092 }else{ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3093 av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); |
| 1168 | 3094 return -1; |
| 3095 } | |
| 3096 } | |
| 3097 } | |
| 3098 | |
| 3099 if(h->slice_type!=B_TYPE) break; | |
| 3100 } | |
| 2396 | 3101 |
| 3102 if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred) | |
| 3103 direct_dist_scale_factor(h); | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3104 direct_ref_list_init(h); |
| 1168 | 3105 return 0; |
| 3106 } | |
| 3107 | |
| 3108 static int pred_weight_table(H264Context *h){ | |
| 3109 MpegEncContext * const s = &h->s; | |
| 3110 int list, i; | |
| 2415 | 3111 int luma_def, chroma_def; |
| 1168 | 3112 |
| 2415 | 3113 h->use_weight= 0; |
| 3114 h->use_weight_chroma= 0; | |
| 1168 | 3115 h->luma_log2_weight_denom= get_ue_golomb(&s->gb); |
| 3116 h->chroma_log2_weight_denom= get_ue_golomb(&s->gb); | |
| 2415 | 3117 luma_def = 1<<h->luma_log2_weight_denom; |
| 3118 chroma_def = 1<<h->chroma_log2_weight_denom; | |
| 1168 | 3119 |
| 3120 for(list=0; list<2; list++){ | |
| 3121 for(i=0; i<h->ref_count[list]; i++){ | |
| 3122 int luma_weight_flag, chroma_weight_flag; | |
| 3123 | |
| 3124 luma_weight_flag= get_bits1(&s->gb); | |
| 3125 if(luma_weight_flag){ | |
| 3126 h->luma_weight[list][i]= get_se_golomb(&s->gb); | |
| 3127 h->luma_offset[list][i]= get_se_golomb(&s->gb); | |
| 2415 | 3128 if( h->luma_weight[list][i] != luma_def |
| 3129 || h->luma_offset[list][i] != 0) | |
| 3130 h->use_weight= 1; | |
| 3131 }else{ | |
| 3132 h->luma_weight[list][i]= luma_def; | |
| 3133 h->luma_offset[list][i]= 0; | |
| 1168 | 3134 } |
| 3135 | |
| 3136 chroma_weight_flag= get_bits1(&s->gb); | |
| 3137 if(chroma_weight_flag){ | |
| 3138 int j; | |
| 3139 for(j=0; j<2; j++){ | |
| 3140 h->chroma_weight[list][i][j]= get_se_golomb(&s->gb); | |
| 3141 h->chroma_offset[list][i][j]= get_se_golomb(&s->gb); | |
| 2415 | 3142 if( h->chroma_weight[list][i][j] != chroma_def |
| 3143 || h->chroma_offset[list][i][j] != 0) | |
| 3144 h->use_weight_chroma= 1; | |
| 3145 } | |
| 3146 }else{ | |
| 3147 int j; | |
| 3148 for(j=0; j<2; j++){ | |
| 3149 h->chroma_weight[list][i][j]= chroma_def; | |
| 3150 h->chroma_offset[list][i][j]= 0; | |
| 1168 | 3151 } |
| 3152 } | |
| 3153 } | |
| 3154 if(h->slice_type != B_TYPE) break; | |
| 3155 } | |
| 2415 | 3156 h->use_weight= h->use_weight || h->use_weight_chroma; |
| 1168 | 3157 return 0; |
| 3158 } | |
| 3159 | |
| 2415 | 3160 static void implicit_weight_table(H264Context *h){ |
| 3161 MpegEncContext * const s = &h->s; | |
| 3162 int ref0, ref1; | |
| 3163 int cur_poc = s->current_picture_ptr->poc; | |
| 3164 | |
| 3165 if( h->ref_count[0] == 1 && h->ref_count[1] == 1 | |
| 3166 && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){ | |
| 3167 h->use_weight= 0; | |
| 3168 h->use_weight_chroma= 0; | |
| 3169 return; | |
| 3170 } | |
| 3171 | |
| 3172 h->use_weight= 2; | |
| 3173 h->use_weight_chroma= 2; | |
| 3174 h->luma_log2_weight_denom= 5; | |
| 3175 h->chroma_log2_weight_denom= 5; | |
| 3176 | |
| 3177 /* FIXME: MBAFF */ | |
| 3178 for(ref0=0; ref0 < h->ref_count[0]; ref0++){ | |
| 3179 int poc0 = h->ref_list[0][ref0].poc; | |
| 3180 for(ref1=0; ref1 < h->ref_count[1]; ref1++){ | |
| 2519 | 3181 int poc1 = h->ref_list[1][ref1].poc; |
| 2415 | 3182 int td = clip(poc1 - poc0, -128, 127); |
| 3183 if(td){ | |
| 3184 int tb = clip(cur_poc - poc0, -128, 127); | |
| 3185 int tx = (16384 + (ABS(td) >> 1)) / td; | |
| 3186 int dist_scale_factor = clip((tb*tx + 32) >> 6, -1024, 1023) >> 2; | |
| 3187 if(dist_scale_factor < -64 || dist_scale_factor > 128) | |
| 3188 h->implicit_weight[ref0][ref1] = 32; | |
| 3189 else | |
| 3190 h->implicit_weight[ref0][ref1] = 64 - dist_scale_factor; | |
| 3191 }else | |
| 3192 h->implicit_weight[ref0][ref1] = 32; | |
| 3193 } | |
| 3194 } | |
| 3195 } | |
| 3196 | |
| 1168 | 3197 /** |
| 2392 | 3198 * instantaneous decoder refresh. |
| 1168 | 3199 */ |
| 3200 static void idr(H264Context *h){ | |
| 2409 | 3201 int i,j; |
| 3202 | |
| 3203 #define CHECK_DELAY(pic) \ | |
| 3204 for(j = 0; h->delayed_pic[j]; j++) \ | |
| 3205 if(pic == h->delayed_pic[j]){ \ | |
| 3206 pic->reference=1; \ | |
| 3207 break; \ | |
| 3208 } | |
| 1168 | 3209 |
|
2484
a3188eb4266c
correct long term picture management patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2471
diff
changeset
|
3210 for(i=0; i<16; i++){ |
|
a3188eb4266c
correct long term picture management patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2471
diff
changeset
|
3211 if (h->long_ref[i] != NULL) { |
|
a3188eb4266c
correct long term picture management patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2471
diff
changeset
|
3212 h->long_ref[i]->reference=0; |
|
a3188eb4266c
correct long term picture management patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2471
diff
changeset
|
3213 CHECK_DELAY(h->long_ref[i]); |
|
a3188eb4266c
correct long term picture management patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2471
diff
changeset
|
3214 h->long_ref[i]= NULL; |
|
a3188eb4266c
correct long term picture management patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2471
diff
changeset
|
3215 } |
| 1168 | 3216 } |
| 3217 h->long_ref_count=0; | |
| 3218 | |
| 3219 for(i=0; i<h->short_ref_count; i++){ | |
| 3220 h->short_ref[i]->reference=0; | |
| 2409 | 3221 CHECK_DELAY(h->short_ref[i]); |
| 1168 | 3222 h->short_ref[i]= NULL; |
| 3223 } | |
| 3224 h->short_ref_count=0; | |
| 3225 } | |
| 2409 | 3226 #undef CHECK_DELAY |
| 1168 | 3227 |
| 3228 /** | |
| 3229 * | |
| 3230 * @return the removed picture or NULL if an error occures | |
| 3231 */ | |
| 3232 static Picture * remove_short(H264Context *h, int frame_num){ | |
| 1169 | 3233 MpegEncContext * const s = &h->s; |
| 1168 | 3234 int i; |
| 3235 | |
| 1169 | 3236 if(s->avctx->debug&FF_DEBUG_MMCO) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3237 av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); |
| 1169 | 3238 |
| 1168 | 3239 for(i=0; i<h->short_ref_count; i++){ |
| 3240 Picture *pic= h->short_ref[i]; | |
| 1169 | 3241 if(s->avctx->debug&FF_DEBUG_MMCO) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3242 av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); |
| 1168 | 3243 if(pic->frame_num == frame_num){ |
| 3244 h->short_ref[i]= NULL; | |
| 3245 memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*)); | |
| 3246 h->short_ref_count--; | |
| 3247 return pic; | |
| 3248 } | |
| 3249 } | |
| 3250 return NULL; | |
| 3251 } | |
| 3252 | |
| 3253 /** | |
| 3254 * | |
| 3255 * @return the removed picture or NULL if an error occures | |
| 3256 */ | |
| 3257 static Picture * remove_long(H264Context *h, int i){ | |
| 3258 Picture *pic; | |
| 3259 | |
| 3260 pic= h->long_ref[i]; | |
| 3261 h->long_ref[i]= NULL; | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3262 if(pic) h->long_ref_count--; |
| 1168 | 3263 |
| 3264 return pic; | |
| 3265 } | |
| 3266 | |
| 3267 /** | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3268 * print short term list |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3269 */ |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3270 static void print_short_term(H264Context *h) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3271 uint32_t i; |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3272 if(h->s.avctx->debug&FF_DEBUG_MMCO) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3273 av_log(h->s.avctx, AV_LOG_DEBUG, "short term list:\n"); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3274 for(i=0; i<h->short_ref_count; i++){ |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3275 Picture *pic= h->short_ref[i]; |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3276 av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3277 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3278 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3279 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3280 |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3281 /** |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3282 * print long term list |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3283 */ |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3284 static void print_long_term(H264Context *h) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3285 uint32_t i; |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3286 if(h->s.avctx->debug&FF_DEBUG_MMCO) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3287 av_log(h->s.avctx, AV_LOG_DEBUG, "long term list:\n"); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3288 for(i = 0; i < 16; i++){ |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3289 Picture *pic= h->long_ref[i]; |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3290 if (pic) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3291 av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3292 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3293 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3294 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3295 } |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3296 |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3297 /** |
| 1168 | 3298 * Executes the reference picture marking (memory management control operations). |
| 3299 */ | |
| 3300 static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |
| 3301 MpegEncContext * const s = &h->s; | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3302 int i, j; |
| 1168 | 3303 int current_is_long=0; |
| 3304 Picture *pic; | |
| 3305 | |
| 3306 if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3307 av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); |
| 1168 | 3308 |
| 3309 for(i=0; i<mmco_count; i++){ | |
| 3310 if(s->avctx->debug&FF_DEBUG_MMCO) | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3311 av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_frame_num, h->mmco[i].long_index); |
| 1168 | 3312 |
| 3313 switch(mmco[i].opcode){ | |
| 3314 case MMCO_SHORT2UNUSED: | |
| 3315 pic= remove_short(h, mmco[i].short_frame_num); | |
| 3316 if(pic==NULL) return -1; | |
| 3317 pic->reference= 0; | |
| 3318 break; | |
| 3319 case MMCO_SHORT2LONG: | |
| 3320 pic= remove_long(h, mmco[i].long_index); | |
| 3321 if(pic) pic->reference=0; | |
| 3322 | |
| 3323 h->long_ref[ mmco[i].long_index ]= remove_short(h, mmco[i].short_frame_num); | |
| 3324 h->long_ref[ mmco[i].long_index ]->long_ref=1; | |
|
2484
a3188eb4266c
correct long term picture management patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2471
diff
changeset
|
3325 h->long_ref_count++; |
| 1168 | 3326 break; |
| 3327 case MMCO_LONG2UNUSED: | |
| 3328 pic= remove_long(h, mmco[i].long_index); | |
| 3329 if(pic==NULL) return -1; | |
| 3330 pic->reference= 0; | |
| 3331 break; | |
| 3332 case MMCO_LONG: | |
| 3333 pic= remove_long(h, mmco[i].long_index); | |
| 3334 if(pic) pic->reference=0; | |
| 3335 | |
| 3336 h->long_ref[ mmco[i].long_index ]= s->current_picture_ptr; | |
| 3337 h->long_ref[ mmco[i].long_index ]->long_ref=1; | |
| 3338 h->long_ref_count++; | |
| 3339 | |
| 3340 current_is_long=1; | |
| 3341 break; | |
| 3342 case MMCO_SET_MAX_LONG: | |
| 3343 assert(mmco[i].long_index <= 16); | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3344 // just remove the long term which index is greater than new max |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3345 for(j = mmco[i].long_index; j<16; j++){ |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3346 pic = remove_long(h, j); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3347 if (pic) pic->reference=0; |
| 1168 | 3348 } |
| 3349 break; | |
| 3350 case MMCO_RESET: | |
| 3351 while(h->short_ref_count){ | |
| 3352 pic= remove_short(h, h->short_ref[0]->frame_num); | |
| 3353 pic->reference=0; | |
| 3354 } | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3355 for(j = 0; j < 16; j++) { |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3356 pic= remove_long(h, j); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3357 if(pic) pic->reference=0; |
| 1168 | 3358 } |
| 3359 break; | |
| 3360 default: assert(0); | |
| 3361 } | |
| 3362 } | |
| 3363 | |
| 3364 if(!current_is_long){ | |
| 3365 pic= remove_short(h, s->current_picture_ptr->frame_num); | |
| 3366 if(pic){ | |
| 3367 pic->reference=0; | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3368 av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); |
| 1168 | 3369 } |
| 3370 | |
| 3371 if(h->short_ref_count) | |
| 1169 | 3372 memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); |
| 3373 | |
| 3374 h->short_ref[0]= s->current_picture_ptr; | |
| 1168 | 3375 h->short_ref[0]->long_ref=0; |
| 3376 h->short_ref_count++; | |
| 3377 } | |
| 3378 | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3379 print_short_term(h); |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3380 print_long_term(h); |
| 1168 | 3381 return 0; |
| 3382 } | |
| 3383 | |
| 3384 static int decode_ref_pic_marking(H264Context *h){ | |
| 3385 MpegEncContext * const s = &h->s; | |
| 3386 int i; | |
| 3387 | |
| 3388 if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields | |
| 3389 s->broken_link= get_bits1(&s->gb) -1; | |
| 3390 h->mmco[0].long_index= get_bits1(&s->gb) - 1; // current_long_term_idx | |
| 3391 if(h->mmco[0].long_index == -1) | |
| 3392 h->mmco_index= 0; | |
| 3393 else{ | |
| 3394 h->mmco[0].opcode= MMCO_LONG; | |
| 3395 h->mmco_index= 1; | |
| 3396 } | |
| 3397 }else{ | |
| 3398 if(get_bits1(&s->gb)){ // adaptive_ref_pic_marking_mode_flag | |
|
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
3399 for(i= 0; i<MAX_MMCO_COUNT; i++) { |
| 1168 | 3400 MMCOOpcode opcode= get_ue_golomb(&s->gb);; |
| 3401 | |
| 3402 h->mmco[i].opcode= opcode; | |
| 3403 if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){ | |
| 3404 h->mmco[i].short_frame_num= (h->frame_num - get_ue_golomb(&s->gb) - 1) & ((1<<h->sps.log2_max_frame_num)-1); //FIXME fields | |
| 3405 /* if(h->mmco[i].short_frame_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_frame_num ] == NULL){ | |
| 3406 fprintf(stderr, "illegal short ref in memory management control operation %d\n", mmco); | |
| 3407 return -1; | |
| 3408 }*/ | |
| 3409 } | |
| 3410 if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){ | |
| 3411 h->mmco[i].long_index= get_ue_golomb(&s->gb); | |
| 3412 if(/*h->mmco[i].long_index >= h->long_ref_count || h->long_ref[ h->mmco[i].long_index ] == NULL*/ h->mmco[i].long_index >= 16){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3413 av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); |
| 1168 | 3414 return -1; |
| 3415 } | |
| 3416 } | |
| 3417 | |
| 3418 if(opcode > MMCO_LONG){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3419 av_log(h->s.avctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", opcode); |
| 1168 | 3420 return -1; |
| 3421 } | |
|
2255
507690ff49a2
assertion when playing AVC/H.264 streams fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2254
diff
changeset
|
3422 if(opcode == MMCO_END) |
|
507690ff49a2
assertion when playing AVC/H.264 streams fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2254
diff
changeset
|
3423 break; |
| 1168 | 3424 } |
| 3425 h->mmco_index= i; | |
| 3426 }else{ | |
| 3427 assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); | |
| 3428 | |
| 3429 if(h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count){ //FIXME fields | |
| 3430 h->mmco[0].opcode= MMCO_SHORT2UNUSED; | |
| 3431 h->mmco[0].short_frame_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num; | |
| 3432 h->mmco_index= 1; | |
| 3433 }else | |
| 3434 h->mmco_index= 0; | |
| 3435 } | |
| 3436 } | |
| 3437 | |
| 3438 return 0; | |
| 3439 } | |
| 3440 | |
| 3441 static int init_poc(H264Context *h){ | |
| 3442 MpegEncContext * const s = &h->s; | |
| 3443 const int max_frame_num= 1<<h->sps.log2_max_frame_num; | |
| 3444 int field_poc[2]; | |
| 3445 | |
| 3446 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
| 3447 h->frame_num_offset= 0; | |
| 3448 }else{ | |
| 3449 if(h->frame_num < h->prev_frame_num) | |
| 3450 h->frame_num_offset= h->prev_frame_num_offset + max_frame_num; | |
| 3451 else | |
| 3452 h->frame_num_offset= h->prev_frame_num_offset; | |
| 3453 } | |
| 3454 | |
| 3455 if(h->sps.poc_type==0){ | |
| 3456 const int max_poc_lsb= 1<<h->sps.log2_max_poc_lsb; | |
| 3457 | |
| 3458 if (h->poc_lsb < h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb/2) | |
| 3459 h->poc_msb = h->prev_poc_msb + max_poc_lsb; | |
| 3460 else if(h->poc_lsb > h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb/2) | |
| 3461 h->poc_msb = h->prev_poc_msb - max_poc_lsb; | |
| 3462 else | |
| 3463 h->poc_msb = h->prev_poc_msb; | |
| 3464 //printf("poc: %d %d\n", h->poc_msb, h->poc_lsb); | |
| 3465 field_poc[0] = | |
| 3466 field_poc[1] = h->poc_msb + h->poc_lsb; | |
| 3467 if(s->picture_structure == PICT_FRAME) | |
| 3468 field_poc[1] += h->delta_poc_bottom; | |
| 3469 }else if(h->sps.poc_type==1){ | |
| 3470 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc; | |
| 3471 int i; | |
| 3472 | |
| 3473 if(h->sps.poc_cycle_length != 0) | |
| 3474 abs_frame_num = h->frame_num_offset + h->frame_num; | |
| 3475 else | |
| 3476 abs_frame_num = 0; | |
| 3477 | |
| 3478 if(h->nal_ref_idc==0 && abs_frame_num > 0) | |
| 3479 abs_frame_num--; | |
| 3480 | |
| 3481 expected_delta_per_poc_cycle = 0; | |
| 3482 for(i=0; i < h->sps.poc_cycle_length; i++) | |
| 3483 expected_delta_per_poc_cycle += h->sps.offset_for_ref_frame[ i ]; //FIXME integrate during sps parse | |
| 3484 | |
| 3485 if(abs_frame_num > 0){ | |
| 3486 int poc_cycle_cnt = (abs_frame_num - 1) / h->sps.poc_cycle_length; | |
| 3487 int frame_num_in_poc_cycle = (abs_frame_num - 1) % h->sps.poc_cycle_length; | |
| 3488 | |
| 3489 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle; | |
| 3490 for(i = 0; i <= frame_num_in_poc_cycle; i++) | |
| 3491 expectedpoc = expectedpoc + h->sps.offset_for_ref_frame[ i ]; | |
| 3492 } else | |
| 3493 expectedpoc = 0; | |
| 3494 | |
| 3495 if(h->nal_ref_idc == 0) | |
| 3496 expectedpoc = expectedpoc + h->sps.offset_for_non_ref_pic; | |
| 3497 | |
| 3498 field_poc[0] = expectedpoc + h->delta_poc[0]; | |
| 3499 field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field; | |
| 3500 | |
| 3501 if(s->picture_structure == PICT_FRAME) | |
| 3502 field_poc[1] += h->delta_poc[1]; | |
| 3503 }else{ | |
| 3504 int poc; | |
| 3505 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
| 3506 poc= 0; | |
| 3507 }else{ | |
| 3508 if(h->nal_ref_idc) poc= 2*(h->frame_num_offset + h->frame_num); | |
| 3509 else poc= 2*(h->frame_num_offset + h->frame_num) - 1; | |
| 3510 } | |
| 3511 field_poc[0]= poc; | |
| 3512 field_poc[1]= poc; | |
| 3513 } | |
| 3514 | |
| 3515 if(s->picture_structure != PICT_BOTTOM_FIELD) | |
| 3516 s->current_picture_ptr->field_poc[0]= field_poc[0]; | |
| 3517 if(s->picture_structure != PICT_TOP_FIELD) | |
| 3518 s->current_picture_ptr->field_poc[1]= field_poc[1]; | |
| 3519 if(s->picture_structure == PICT_FRAME) // FIXME field pix? | |
| 3520 s->current_picture_ptr->poc= FFMIN(field_poc[0], field_poc[1]); | |
| 3521 | |
| 3522 return 0; | |
| 3523 } | |
| 3524 | |
| 3525 /** | |
| 3526 * decodes a slice header. | |
| 3527 * this will allso call MPV_common_init() and frame_start() as needed | |
| 3528 */ | |
| 3529 static int decode_slice_header(H264Context *h){ | |
| 3530 MpegEncContext * const s = &h->s; | |
| 3531 int first_mb_in_slice, pps_id; | |
| 3532 int num_ref_idx_active_override_flag; | |
| 3533 static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; | |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3534 int slice_type; |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3535 int default_ref_list_done = 0; |
| 1168 | 3536 |
| 3537 s->current_picture.reference= h->nal_ref_idc != 0; | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
3538 s->dropable= h->nal_ref_idc == 0; |
| 1168 | 3539 |
| 3540 first_mb_in_slice= get_ue_golomb(&s->gb); | |
| 3541 | |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3542 slice_type= get_ue_golomb(&s->gb); |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3543 if(slice_type > 9){ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3544 av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); |
| 2392 | 3545 return -1; |
| 1168 | 3546 } |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3547 if(slice_type > 4){ |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3548 slice_type -= 5; |
| 1168 | 3549 h->slice_type_fixed=1; |
| 3550 }else | |
| 3551 h->slice_type_fixed=0; | |
| 3552 | |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3553 slice_type= slice_type_map[ slice_type ]; |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3554 if (slice_type == I_TYPE |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3555 || (h->slice_num != 0 && slice_type == h->slice_type) ) { |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3556 default_ref_list_done = 1; |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3557 } |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3558 h->slice_type= slice_type; |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3559 |
| 1168 | 3560 s->pict_type= h->slice_type; // to make a few old func happy, its wrong though |
| 3561 | |
| 3562 pps_id= get_ue_golomb(&s->gb); | |
| 3563 if(pps_id>255){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3564 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); |
| 1168 | 3565 return -1; |
| 3566 } | |
| 3567 h->pps= h->pps_buffer[pps_id]; | |
| 1174 | 3568 if(h->pps.slice_group_count == 0){ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3569 av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\n"); |
| 1174 | 3570 return -1; |
| 3571 } | |
| 3572 | |
| 1168 | 3573 h->sps= h->sps_buffer[ h->pps.sps_id ]; |
| 1174 | 3574 if(h->sps.log2_max_frame_num == 0){ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3575 av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n"); |
| 1174 | 3576 return -1; |
| 3577 } | |
| 1168 | 3578 |
| 3579 s->mb_width= h->sps.mb_width; | |
| 3580 s->mb_height= h->sps.mb_height; | |
| 3581 | |
| 2395 | 3582 h->b_stride= s->mb_width*4 + 1; |
| 3583 h->b8_stride= s->mb_width*2 + 1; | |
| 1168 | 3584 |
| 2392 | 3585 s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width; |
| 3586 s->resync_mb_y = s->mb_y = first_mb_in_slice / s->mb_width; //FIXME AFFW | |
| 1168 | 3587 |
| 1371 | 3588 s->width = 16*s->mb_width - 2*(h->sps.crop_left + h->sps.crop_right ); |
| 1168 | 3589 if(h->sps.frame_mbs_only_flag) |
| 1371 | 3590 s->height= 16*s->mb_height - 2*(h->sps.crop_top + h->sps.crop_bottom); |
| 1168 | 3591 else |
| 1371 | 3592 s->height= 16*s->mb_height - 4*(h->sps.crop_top + h->sps.crop_bottom); //FIXME recheck |
| 1168 | 3593 |
| 3594 if (s->context_initialized | |
| 1548 | 3595 && ( s->width != s->avctx->width || s->height != s->avctx->height)) { |
| 1168 | 3596 free_tables(h); |
| 3597 MPV_common_end(s); | |
| 3598 } | |
| 3599 if (!s->context_initialized) { | |
| 3600 if (MPV_common_init(s) < 0) | |
| 3601 return -1; | |
| 3602 | |
| 3603 alloc_tables(h); | |
| 3604 | |
| 3605 s->avctx->width = s->width; | |
| 3606 s->avctx->height = s->height; | |
| 1548 | 3607 s->avctx->sample_aspect_ratio= h->sps.sar; |
| 2440 | 3608 if(!s->avctx->sample_aspect_ratio.den) |
| 3609 s->avctx->sample_aspect_ratio.den = 1; | |
|
2174
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3610 |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3611 if(h->sps.timing_info_present_flag && h->sps.fixed_frame_rate_flag){ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3612 s->avctx->frame_rate = h->sps.time_scale; |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3613 s->avctx->frame_rate_base = h->sps.num_units_in_tick; |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3614 } |
| 1168 | 3615 } |
| 3616 | |
| 2392 | 3617 if(h->slice_num == 0){ |
| 1168 | 3618 frame_start(h); |
| 3619 } | |
| 3620 | |
| 1169 | 3621 s->current_picture_ptr->frame_num= //FIXME frame_num cleanup |
| 1168 | 3622 h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); |
| 3623 | |
| 3624 if(h->sps.frame_mbs_only_flag){ | |
| 3625 s->picture_structure= PICT_FRAME; | |
| 3626 }else{ | |
| 3627 if(get_bits1(&s->gb)) //field_pic_flag | |
| 3628 s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag | |
| 3629 else | |
| 3630 s->picture_structure= PICT_FRAME; | |
| 3631 } | |
| 3632 | |
| 3633 if(s->picture_structure==PICT_FRAME){ | |
| 3634 h->curr_pic_num= h->frame_num; | |
| 3635 h->max_pic_num= 1<< h->sps.log2_max_frame_num; | |
| 3636 }else{ | |
| 3637 h->curr_pic_num= 2*h->frame_num; | |
| 3638 h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1); | |
| 3639 } | |
| 3640 | |
| 3641 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
| 1453 | 3642 get_ue_golomb(&s->gb); /* idr_pic_id */ |
| 1168 | 3643 } |
| 3644 | |
| 3645 if(h->sps.poc_type==0){ | |
| 3646 h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb); | |
| 3647 | |
| 3648 if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){ | |
| 3649 h->delta_poc_bottom= get_se_golomb(&s->gb); | |
| 3650 } | |
| 3651 } | |
| 3652 | |
| 3653 if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){ | |
| 3654 h->delta_poc[0]= get_se_golomb(&s->gb); | |
| 3655 | |
| 3656 if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME) | |
| 3657 h->delta_poc[1]= get_se_golomb(&s->gb); | |
| 3658 } | |
| 3659 | |
| 3660 init_poc(h); | |
| 3661 | |
| 3662 if(h->pps.redundant_pic_cnt_present){ | |
| 3663 h->redundant_pic_count= get_ue_golomb(&s->gb); | |
| 3664 } | |
| 3665 | |
| 3666 //set defaults, might be overriden a few line later | |
| 3667 h->ref_count[0]= h->pps.ref_count[0]; | |
| 3668 h->ref_count[1]= h->pps.ref_count[1]; | |
| 3669 | |
| 3670 if(h->slice_type == P_TYPE || h->slice_type == SP_TYPE || h->slice_type == B_TYPE){ | |
| 3671 if(h->slice_type == B_TYPE){ | |
| 3672 h->direct_spatial_mv_pred= get_bits1(&s->gb); | |
| 3673 } | |
| 3674 num_ref_idx_active_override_flag= get_bits1(&s->gb); | |
| 3675 | |
| 3676 if(num_ref_idx_active_override_flag){ | |
| 3677 h->ref_count[0]= get_ue_golomb(&s->gb) + 1; | |
| 3678 if(h->slice_type==B_TYPE) | |
| 3679 h->ref_count[1]= get_ue_golomb(&s->gb) + 1; | |
| 3680 | |
| 3681 if(h->ref_count[0] > 32 || h->ref_count[1] > 32){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3682 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); |
| 1168 | 3683 return -1; |
| 3684 } | |
| 3685 } | |
| 3686 } | |
| 3687 | |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
3688 if(!default_ref_list_done){ |
| 1168 | 3689 fill_default_ref_list(h); |
| 3690 } | |
| 3691 | |
| 3692 decode_ref_pic_list_reordering(h); | |
| 3693 | |
| 3694 if( (h->pps.weighted_pred && (h->slice_type == P_TYPE || h->slice_type == SP_TYPE )) | |
| 3695 || (h->pps.weighted_bipred_idc==1 && h->slice_type==B_TYPE ) ) | |
| 3696 pred_weight_table(h); | |
| 2415 | 3697 else if(h->pps.weighted_bipred_idc==2 && h->slice_type==B_TYPE) |
| 3698 implicit_weight_table(h); | |
| 3699 else | |
| 3700 h->use_weight = 0; | |
| 1168 | 3701 |
| 3702 if(s->current_picture.reference) | |
| 3703 decode_ref_pic_marking(h); | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3704 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3705 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE && h->pps.cabac ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3706 h->cabac_init_idc = get_ue_golomb(&s->gb); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3707 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3708 h->last_qscale_diff = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3709 s->qscale = h->pps.init_qp + get_se_golomb(&s->gb); |
| 1898 | 3710 if(s->qscale<0 || s->qscale>51){ |
| 3711 av_log(s->avctx, AV_LOG_ERROR, "QP %d out of range\n", s->qscale); | |
| 3712 return -1; | |
| 3713 } | |
|
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
3714 h->chroma_qp = get_chroma_qp(h, s->qscale); |
| 1168 | 3715 //FIXME qscale / qp ... stuff |
| 3716 if(h->slice_type == SP_TYPE){ | |
| 1453 | 3717 get_bits1(&s->gb); /* sp_for_switch_flag */ |
| 1168 | 3718 } |
| 3719 if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){ | |
| 1453 | 3720 get_se_golomb(&s->gb); /* slice_qs_delta */ |
| 1168 | 3721 } |
| 3722 | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3723 h->deblocking_filter = 1; |
| 1898 | 3724 h->slice_alpha_c0_offset = 0; |
| 3725 h->slice_beta_offset = 0; | |
| 1168 | 3726 if( h->pps.deblocking_filter_parameters_present ) { |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3727 h->deblocking_filter= get_ue_golomb(&s->gb); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3728 if(h->deblocking_filter < 2) |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3729 h->deblocking_filter^= 1; // 1<->0 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3730 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3731 if( h->deblocking_filter ) { |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3732 h->slice_alpha_c0_offset = get_se_golomb(&s->gb) << 1; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3733 h->slice_beta_offset = get_se_golomb(&s->gb) << 1; |
| 1168 | 3734 } |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3735 } |
| 1168 | 3736 |
| 3737 #if 0 //FMO | |
| 3738 if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5) | |
| 3739 slice_group_change_cycle= get_bits(&s->gb, ?); | |
| 3740 #endif | |
| 3741 | |
| 2392 | 3742 h->slice_num++; |
| 3743 | |
| 1168 | 3744 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ |
| 2415 | 3745 av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d mb:%d %c pps:%d frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d weight:%d%s\n", |
| 2392 | 3746 h->slice_num, first_mb_in_slice, |
| 1264 | 3747 av_get_pict_type_char(h->slice_type), |
| 1168 | 3748 pps_id, h->frame_num, |
| 3749 s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1], | |
| 3750 h->ref_count[0], h->ref_count[1], | |
| 3751 s->qscale, | |
| 2415 | 3752 h->deblocking_filter, |
| 3753 h->use_weight, | |
| 3754 h->use_weight==1 && h->use_weight_chroma ? "c" : "" | |
| 1168 | 3755 ); |
| 3756 } | |
| 3757 | |
| 3758 return 0; | |
| 3759 } | |
| 3760 | |
| 3761 /** | |
| 3762 * | |
| 3763 */ | |
| 3764 static inline int get_level_prefix(GetBitContext *gb){ | |
| 3765 unsigned int buf; | |
| 3766 int log; | |
| 3767 | |
| 3768 OPEN_READER(re, gb); | |
| 3769 UPDATE_CACHE(re, gb); | |
| 3770 buf=GET_CACHE(re, gb); | |
| 3771 | |
| 3772 log= 32 - av_log2(buf); | |
| 3773 #ifdef TRACE | |
| 3774 print_bin(buf>>(32-log), log); | |
|
2272
cd43603c46f9
move h264 idct to its own file and call via function pointer in DspContext
michael
parents:
2255
diff
changeset
|
3775 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d lpr @%5d in %s get_level_prefix\n", buf>>(32-log), log, log-1, get_bits_count(gb), __FILE__); |
| 1168 | 3776 #endif |
| 3777 | |
| 3778 LAST_SKIP_BITS(re, gb, log); | |
| 3779 CLOSE_READER(re, gb); | |
| 3780 | |
| 3781 return log-1; | |
| 3782 } | |
| 3783 | |
| 3784 /** | |
| 3785 * decodes a residual block. | |
| 3786 * @param n block index | |
| 3787 * @param scantable scantable | |
| 3788 * @param max_coeff number of coefficients in the block | |
| 3789 * @return <0 if an error occured | |
| 3790 */ | |
| 3791 static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, int qp, int max_coeff){ | |
| 3792 MpegEncContext * const s = &h->s; | |
| 3793 const uint16_t *qmul= dequant_coeff[qp]; | |
| 3794 static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}; | |
| 3795 int level[16], run[16]; | |
| 3796 int suffix_length, zeros_left, coeff_num, coeff_token, total_coeff, i, trailing_ones; | |
| 3797 | |
| 3798 //FIXME put trailing_onex into the context | |
| 3799 | |
| 3800 if(n == CHROMA_DC_BLOCK_INDEX){ | |
| 3801 coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1); | |
| 3802 total_coeff= coeff_token>>2; | |
| 3803 }else{ | |
| 3804 if(n == LUMA_DC_BLOCK_INDEX){ | |
| 3805 total_coeff= pred_non_zero_count(h, 0); | |
| 3806 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); | |
| 3807 total_coeff= coeff_token>>2; | |
| 3808 }else{ | |
| 3809 total_coeff= pred_non_zero_count(h, n); | |
| 3810 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); | |
| 3811 total_coeff= coeff_token>>2; | |
| 3812 h->non_zero_count_cache[ scan8[n] ]= total_coeff; | |
| 3813 } | |
| 3814 } | |
| 3815 | |
| 3816 //FIXME set last_non_zero? | |
| 3817 | |
| 3818 if(total_coeff==0) | |
| 3819 return 0; | |
| 3820 | |
| 3821 trailing_ones= coeff_token&3; | |
| 1170 | 3822 tprintf("trailing:%d, total:%d\n", trailing_ones, total_coeff); |
| 1168 | 3823 assert(total_coeff<=16); |
| 3824 | |
| 3825 for(i=0; i<trailing_ones; i++){ | |
| 3826 level[i]= 1 - 2*get_bits1(gb); | |
| 3827 } | |
| 3828 | |
| 3829 suffix_length= total_coeff > 10 && trailing_ones < 3; | |
| 3830 | |
| 3831 for(; i<total_coeff; i++){ | |
| 3832 const int prefix= get_level_prefix(gb); | |
| 3833 int level_code, mask; | |
| 3834 | |
| 3835 if(prefix<14){ //FIXME try to build a large unified VLC table for all this | |
| 3836 if(suffix_length) | |
| 3837 level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part | |
| 3838 else | |
| 3839 level_code= (prefix<<suffix_length); //part | |
| 3840 }else if(prefix==14){ | |
| 3841 if(suffix_length) | |
| 3842 level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part | |
| 3843 else | |
| 3844 level_code= prefix + get_bits(gb, 4); //part | |
| 3845 }else if(prefix==15){ | |
| 3846 level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part | |
| 3847 if(suffix_length==0) level_code+=15; //FIXME doesnt make (much)sense | |
| 3848 }else{ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3849 av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y); |
| 1168 | 3850 return -1; |
| 3851 } | |
| 3852 | |
| 3853 if(i==trailing_ones && i<3) level_code+= 2; //FIXME split first iteration | |
| 3854 | |
| 3855 mask= -(level_code&1); | |
| 3856 level[i]= (((2+level_code)>>1) ^ mask) - mask; | |
| 3857 | |
| 3858 if(suffix_length==0) suffix_length=1; //FIXME split first iteration | |
| 3859 | |
| 3860 #if 1 | |
| 3861 if(ABS(level[i]) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++; | |
| 3862 #else | |
| 3863 if((2+level_code)>>1) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++; | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3864 /* ? == prefix > 2 or sth */ |
| 1168 | 3865 #endif |
| 1170 | 3866 tprintf("level: %d suffix_length:%d\n", level[i], suffix_length); |
| 1168 | 3867 } |
| 3868 | |
| 3869 if(total_coeff == max_coeff) | |
| 3870 zeros_left=0; | |
| 3871 else{ | |
| 3872 if(n == CHROMA_DC_BLOCK_INDEX) | |
| 3873 zeros_left= get_vlc2(gb, chroma_dc_total_zeros_vlc[ total_coeff-1 ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1); | |
| 3874 else | |
| 3875 zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff-1 ].table, TOTAL_ZEROS_VLC_BITS, 1); | |
| 3876 } | |
| 3877 | |
| 3878 for(i=0; i<total_coeff-1; i++){ | |
| 3879 if(zeros_left <=0) | |
| 3880 break; | |
| 3881 else if(zeros_left < 7){ | |
| 3882 run[i]= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1); | |
| 3883 }else{ | |
| 3884 run[i]= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); | |
| 3885 } | |
| 3886 zeros_left -= run[i]; | |
| 3887 } | |
| 3888 | |
| 3889 if(zeros_left<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3890 av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); |
| 1168 | 3891 return -1; |
| 3892 } | |
| 3893 | |
| 3894 for(; i<total_coeff-1; i++){ | |
| 3895 run[i]= 0; | |
| 3896 } | |
| 3897 | |
| 3898 run[i]= zeros_left; | |
| 3899 | |
| 3900 coeff_num=-1; | |
| 3901 if(n > 24){ | |
| 3902 for(i=total_coeff-1; i>=0; i--){ //FIXME merge into rundecode? | |
| 3903 int j; | |
| 3904 | |
| 3905 coeff_num += run[i] + 1; //FIXME add 1 earlier ? | |
| 3906 j= scantable[ coeff_num ]; | |
| 3907 | |
| 3908 block[j]= level[i]; | |
| 3909 } | |
| 3910 }else{ | |
| 3911 for(i=total_coeff-1; i>=0; i--){ //FIXME merge into rundecode? | |
| 3912 int j; | |
| 3913 | |
| 3914 coeff_num += run[i] + 1; //FIXME add 1 earlier ? | |
| 3915 j= scantable[ coeff_num ]; | |
| 3916 | |
| 3917 block[j]= level[i] * qmul[j]; | |
| 3918 // printf("%d %d ", block[j], qmul[j]); | |
| 3919 } | |
| 3920 } | |
| 3921 return 0; | |
| 3922 } | |
| 3923 | |
| 3924 /** | |
| 2396 | 3925 * decodes a P_SKIP or B_SKIP macroblock |
| 3926 */ | |
| 3927 static void decode_mb_skip(H264Context *h){ | |
| 3928 MpegEncContext * const s = &h->s; | |
| 3929 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; | |
| 3930 int mb_type; | |
| 3931 | |
| 3932 memset(h->non_zero_count[mb_xy], 0, 16); | |
| 3933 memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui | |
| 3934 | |
| 3935 if( h->slice_type == B_TYPE ) | |
| 3936 { | |
| 3937 // just for fill_caches. pred_direct_motion will set the real mb_type | |
| 3938 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; | |
| 3939 //FIXME mbaff | |
| 3940 | |
| 2449 | 3941 fill_caches(h, mb_type, 0); //FIXME check what is needed and what not ... |
| 2396 | 3942 pred_direct_motion(h, &mb_type); |
| 3943 if(h->pps.cabac){ | |
| 3944 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
| 3945 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
| 3946 } | |
| 3947 } | |
| 3948 else | |
| 3949 { | |
| 3950 int mx, my; | |
| 3951 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP; | |
| 3952 | |
| 3953 if(h->sps.mb_aff && s->mb_skip_run==0 && (s->mb_y&1)==0){ | |
| 3954 h->mb_field_decoding_flag= get_bits1(&s->gb); | |
| 3955 } | |
| 3956 if(h->mb_field_decoding_flag) | |
| 3957 mb_type|= MB_TYPE_INTERLACED; | |
| 3958 | |
| 2449 | 3959 fill_caches(h, mb_type, 0); //FIXME check what is needed and what not ... |
| 2396 | 3960 pred_pskip_motion(h, &mx, &my); |
| 3961 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
| 3962 fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); | |
| 3963 if(h->pps.cabac) | |
| 3964 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
| 3965 } | |
| 3966 | |
| 3967 write_back_motion(h, mb_type); | |
| 3968 s->current_picture.mb_type[mb_xy]= mb_type|MB_TYPE_SKIP; | |
| 3969 s->current_picture.qscale_table[mb_xy]= s->qscale; | |
| 3970 h->slice_table[ mb_xy ]= h->slice_num; | |
| 3971 h->prev_mb_skiped= 1; | |
| 3972 } | |
| 3973 | |
| 3974 /** | |
| 1168 | 3975 * decodes a macroblock |
| 3976 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed | |
| 3977 */ | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3978 static int decode_mb_cavlc(H264Context *h){ |
| 1168 | 3979 MpegEncContext * const s = &h->s; |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
3980 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1169 | 3981 int mb_type, partition_count, cbp; |
| 1168 | 3982 |
| 1252 | 3983 s->dsp.clear_blocks(h->mb); //FIXME avoid if allready clear (move after skip handlong? |
| 1168 | 3984 |
| 1170 | 3985 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); |
| 1453 | 3986 cbp = 0; /* avoid warning. FIXME: find a solution without slowing |
| 3987 down the code */ | |
| 1168 | 3988 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ |
| 3989 if(s->mb_skip_run==-1) | |
| 3990 s->mb_skip_run= get_ue_golomb(&s->gb); | |
| 3991 | |
| 3992 if (s->mb_skip_run--) { | |
| 2396 | 3993 decode_mb_skip(h); |
| 1168 | 3994 return 0; |
| 3995 } | |
| 3996 } | |
| 3997 if(h->sps.mb_aff /* && !field pic FIXME needed? */){ | |
| 3998 if((s->mb_y&1)==0) | |
| 3999 h->mb_field_decoding_flag = get_bits1(&s->gb); | |
| 4000 }else | |
| 4001 h->mb_field_decoding_flag=0; //FIXME som ed note ?! | |
| 4002 | |
| 4003 h->prev_mb_skiped= 0; | |
| 4004 | |
| 4005 mb_type= get_ue_golomb(&s->gb); | |
| 4006 if(h->slice_type == B_TYPE){ | |
| 4007 if(mb_type < 23){ | |
| 4008 partition_count= b_mb_type_info[mb_type].partition_count; | |
| 4009 mb_type= b_mb_type_info[mb_type].type; | |
| 4010 }else{ | |
| 4011 mb_type -= 23; | |
| 4012 goto decode_intra_mb; | |
| 4013 } | |
| 4014 }else if(h->slice_type == P_TYPE /*|| h->slice_type == SP_TYPE */){ | |
| 4015 if(mb_type < 5){ | |
| 4016 partition_count= p_mb_type_info[mb_type].partition_count; | |
| 4017 mb_type= p_mb_type_info[mb_type].type; | |
| 4018 }else{ | |
| 4019 mb_type -= 5; | |
| 4020 goto decode_intra_mb; | |
| 4021 } | |
| 4022 }else{ | |
| 4023 assert(h->slice_type == I_TYPE); | |
| 4024 decode_intra_mb: | |
| 4025 if(mb_type > 25){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4026 av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice to large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y); |
| 1168 | 4027 return -1; |
| 4028 } | |
| 4029 partition_count=0; | |
| 4030 cbp= i_mb_type_info[mb_type].cbp; | |
| 4031 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; | |
| 4032 mb_type= i_mb_type_info[mb_type].type; | |
| 4033 } | |
| 4034 | |
| 4035 if(h->mb_field_decoding_flag) | |
| 4036 mb_type |= MB_TYPE_INTERLACED; | |
| 4037 | |
| 4038 s->current_picture.mb_type[mb_xy]= mb_type; | |
| 4039 h->slice_table[ mb_xy ]= h->slice_num; | |
| 4040 | |
| 4041 if(IS_INTRA_PCM(mb_type)){ | |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4042 unsigned int x, y; |
| 1168 | 4043 |
| 4044 // we assume these blocks are very rare so we dont optimize it | |
| 4045 align_get_bits(&s->gb); | |
| 4046 | |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4047 // The pixels are stored in the same order as levels in h->mb array. |
| 1168 | 4048 for(y=0; y<16; y++){ |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4049 const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3); |
| 1168 | 4050 for(x=0; x<16; x++){ |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4051 tprintf("LUMA ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4052 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= get_bits(&s->gb, 8); |
| 1168 | 4053 } |
| 4054 } | |
| 4055 for(y=0; y<8; y++){ | |
| 4056 const int index= 256 + 4*(y&3) + 32*(y>>2); | |
| 4057 for(x=0; x<8; x++){ | |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4058 tprintf("CHROMA U ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4059 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); |
| 1168 | 4060 } |
| 4061 } | |
| 4062 for(y=0; y<8; y++){ | |
| 4063 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); | |
| 4064 for(x=0; x<8; x++){ | |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4065 tprintf("CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4066 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); |
| 1168 | 4067 } |
| 4068 } | |
| 4069 | |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4070 // In deblocking, the quantiser is 0 |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4071 s->current_picture.qscale_table[mb_xy]= 0; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4072 h->chroma_qp = get_chroma_qp(h, 0); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4073 // All coeffs are presents |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4074 memset(h->non_zero_count[mb_xy], 16, 16); |
| 1168 | 4075 |
| 4076 return 0; | |
| 4077 } | |
| 4078 | |
| 2449 | 4079 fill_caches(h, mb_type, 0); |
| 1168 | 4080 |
| 4081 //mb_pred | |
| 4082 if(IS_INTRA(mb_type)){ | |
| 4083 // init_top_left_availability(h); | |
| 4084 if(IS_INTRA4x4(mb_type)){ | |
| 4085 int i; | |
| 4086 | |
| 4087 // fill_intra4x4_pred_table(h); | |
| 4088 for(i=0; i<16; i++){ | |
| 4089 const int mode_coded= !get_bits1(&s->gb); | |
| 4090 const int predicted_mode= pred_intra_mode(h, i); | |
| 4091 int mode; | |
| 4092 | |
| 4093 if(mode_coded){ | |
| 4094 const int rem_mode= get_bits(&s->gb, 3); | |
| 4095 if(rem_mode<predicted_mode) | |
| 4096 mode= rem_mode; | |
| 4097 else | |
| 4098 mode= rem_mode + 1; | |
| 4099 }else{ | |
| 4100 mode= predicted_mode; | |
| 4101 } | |
| 4102 | |
| 4103 h->intra4x4_pred_mode_cache[ scan8[i] ] = mode; | |
| 4104 } | |
| 4105 write_back_intra_pred_mode(h); | |
| 4106 if( check_intra4x4_pred_mode(h) < 0) | |
| 4107 return -1; | |
| 4108 }else{ | |
| 4109 h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode); | |
| 4110 if(h->intra16x16_pred_mode < 0) | |
| 4111 return -1; | |
| 4112 } | |
| 4113 h->chroma_pred_mode= get_ue_golomb(&s->gb); | |
| 4114 | |
| 4115 h->chroma_pred_mode= check_intra_pred_mode(h, h->chroma_pred_mode); | |
| 4116 if(h->chroma_pred_mode < 0) | |
| 4117 return -1; | |
| 4118 }else if(partition_count==4){ | |
| 4119 int i, j, sub_partition_count[4], list, ref[2][4]; | |
| 4120 | |
| 4121 if(h->slice_type == B_TYPE){ | |
| 4122 for(i=0; i<4; i++){ | |
| 4123 h->sub_mb_type[i]= get_ue_golomb(&s->gb); | |
| 4124 if(h->sub_mb_type[i] >=13){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4125 av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %d out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); |
| 1168 | 4126 return -1; |
| 4127 } | |
| 4128 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | |
| 4129 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; | |
| 4130 } | |
| 2396 | 4131 if( IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1]) |
| 4132 || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) | |
| 4133 pred_direct_motion(h, &mb_type); | |
| 1168 | 4134 }else{ |
| 4135 assert(h->slice_type == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ? | |
| 4136 for(i=0; i<4; i++){ | |
| 4137 h->sub_mb_type[i]= get_ue_golomb(&s->gb); | |
| 4138 if(h->sub_mb_type[i] >=4){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4139 av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %d out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); |
| 1168 | 4140 return -1; |
| 4141 } | |
| 4142 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | |
| 4143 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; | |
| 4144 } | |
| 4145 } | |
| 4146 | |
| 4147 for(list=0; list<2; list++){ | |
| 4148 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | |
| 4149 if(ref_count == 0) continue; | |
| 4150 for(i=0; i<4; i++){ | |
| 2396 | 4151 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
| 4152 if(IS_DIR(h->sub_mb_type[i], 0, list)){ | |
| 1168 | 4153 ref[list][i] = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip? |
| 4154 }else{ | |
| 4155 //FIXME | |
| 4156 ref[list][i] = -1; | |
| 4157 } | |
| 4158 } | |
| 4159 } | |
| 4160 | |
| 4161 for(list=0; list<2; list++){ | |
| 4162 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | |
| 4163 if(ref_count == 0) continue; | |
| 4164 | |
| 4165 for(i=0; i<4; i++){ | |
| 2396 | 4166 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
| 1168 | 4167 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]= |
| 4168 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; | |
| 4169 | |
| 2396 | 4170 if(IS_DIR(h->sub_mb_type[i], 0, list)){ |
| 1168 | 4171 const int sub_mb_type= h->sub_mb_type[i]; |
| 4172 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; | |
| 4173 for(j=0; j<sub_partition_count[i]; j++){ | |
| 4174 int mx, my; | |
| 4175 const int index= 4*i + block_width*j; | |
| 4176 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; | |
| 4177 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |
| 4178 mx += get_se_golomb(&s->gb); | |
| 4179 my += get_se_golomb(&s->gb); | |
| 1170 | 4180 tprintf("final mv:%d %d\n", mx, my); |
| 4181 | |
| 1168 | 4182 if(IS_SUB_8X8(sub_mb_type)){ |
| 4183 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= | |
| 4184 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; | |
| 4185 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= | |
| 4186 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; | |
| 4187 }else if(IS_SUB_8X4(sub_mb_type)){ | |
| 4188 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mx; | |
| 4189 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= my; | |
| 4190 }else if(IS_SUB_4X8(sub_mb_type)){ | |
| 4191 mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mx; | |
| 4192 mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= my; | |
| 4193 }else{ | |
| 4194 assert(IS_SUB_4X4(sub_mb_type)); | |
| 4195 mv_cache[ 0 ][0]= mx; | |
| 4196 mv_cache[ 0 ][1]= my; | |
| 4197 } | |
| 4198 } | |
| 4199 }else{ | |
| 4200 uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0]; | |
| 4201 p[0] = p[1]= | |
| 4202 p[8] = p[9]= 0; | |
| 4203 } | |
| 4204 } | |
| 4205 } | |
| 2396 | 4206 }else if(IS_DIRECT(mb_type)){ |
| 4207 pred_direct_motion(h, &mb_type); | |
| 4208 s->current_picture.mb_type[mb_xy]= mb_type; | |
| 4209 }else{ | |
| 1168 | 4210 int list, mx, my, i; |
| 4211 //FIXME we should set ref_idx_l? to 0 if we use that later ... | |
| 4212 if(IS_16X16(mb_type)){ | |
| 4213 for(list=0; list<2; list++){ | |
| 2392 | 4214 if(h->ref_count[list]>0){ |
| 1168 | 4215 if(IS_DIR(mb_type, 0, list)){ |
| 4216 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
| 4217 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1); | |
| 2523 | 4218 }else |
| 4219 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, (LIST_NOT_USED&0xFF), 1); | |
| 1168 | 4220 } |
| 4221 } | |
| 4222 for(list=0; list<2; list++){ | |
| 4223 if(IS_DIR(mb_type, 0, list)){ | |
| 4224 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |
| 4225 mx += get_se_golomb(&s->gb); | |
| 4226 my += get_se_golomb(&s->gb); | |
| 1170 | 4227 tprintf("final mv:%d %d\n", mx, my); |
| 4228 | |
| 1269 | 4229 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); |
| 2523 | 4230 }else |
| 4231 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4); | |
| 1168 | 4232 } |
| 4233 } | |
| 4234 else if(IS_16X8(mb_type)){ | |
| 4235 for(list=0; list<2; list++){ | |
| 4236 if(h->ref_count[list]>0){ | |
| 4237 for(i=0; i<2; i++){ | |
| 4238 if(IS_DIR(mb_type, i, list)){ | |
| 4239 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
| 4240 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); | |
| 2523 | 4241 }else |
| 2396 | 4242 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); |
| 1168 | 4243 } |
| 4244 } | |
| 4245 } | |
| 4246 for(list=0; list<2; list++){ | |
| 4247 for(i=0; i<2; i++){ | |
| 4248 if(IS_DIR(mb_type, i, list)){ | |
| 4249 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |
| 4250 mx += get_se_golomb(&s->gb); | |
| 4251 my += get_se_golomb(&s->gb); | |
| 1170 | 4252 tprintf("final mv:%d %d\n", mx, my); |
| 4253 | |
| 1269 | 4254 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); |
| 2396 | 4255 }else |
| 4256 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); | |
| 1168 | 4257 } |
| 4258 } | |
| 4259 }else{ | |
| 4260 assert(IS_8X16(mb_type)); | |
| 4261 for(list=0; list<2; list++){ | |
| 4262 if(h->ref_count[list]>0){ | |
| 4263 for(i=0; i<2; i++){ | |
| 4264 if(IS_DIR(mb_type, i, list)){ //FIXME optimize | |
| 4265 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
| 4266 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); | |
| 2523 | 4267 }else |
| 2396 | 4268 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); |
| 1168 | 4269 } |
| 4270 } | |
| 4271 } | |
| 4272 for(list=0; list<2; list++){ | |
| 4273 for(i=0; i<2; i++){ | |
| 4274 if(IS_DIR(mb_type, i, list)){ | |
| 4275 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |
| 4276 mx += get_se_golomb(&s->gb); | |
| 4277 my += get_se_golomb(&s->gb); | |
| 1170 | 4278 tprintf("final mv:%d %d\n", mx, my); |
| 4279 | |
| 1269 | 4280 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); |
| 2396 | 4281 }else |
| 4282 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); | |
| 1168 | 4283 } |
| 4284 } | |
| 4285 } | |
| 4286 } | |
| 4287 | |
| 4288 if(IS_INTER(mb_type)) | |
| 4289 write_back_motion(h, mb_type); | |
| 4290 | |
| 4291 if(!IS_INTRA16x16(mb_type)){ | |
| 4292 cbp= get_ue_golomb(&s->gb); | |
| 4293 if(cbp > 47){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4294 av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%d) at %d %d\n", cbp, s->mb_x, s->mb_y); |
| 1168 | 4295 return -1; |
| 4296 } | |
| 4297 | |
| 4298 if(IS_INTRA4x4(mb_type)) | |
| 4299 cbp= golomb_to_intra4x4_cbp[cbp]; | |
| 4300 else | |
| 4301 cbp= golomb_to_inter_cbp[cbp]; | |
| 4302 } | |
| 4303 | |
| 4304 if(cbp || IS_INTRA16x16(mb_type)){ | |
| 4305 int i8x8, i4x4, chroma_idx; | |
| 4306 int chroma_qp, dquant; | |
| 4307 GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; | |
| 4308 const uint8_t *scan, *dc_scan; | |
| 4309 | |
| 4310 // fill_non_zero_count_cache(h); | |
| 4311 | |
| 4312 if(IS_INTERLACED(mb_type)){ | |
| 4313 scan= field_scan; | |
| 4314 dc_scan= luma_dc_field_scan; | |
| 4315 }else{ | |
| 4316 scan= zigzag_scan; | |
| 4317 dc_scan= luma_dc_zigzag_scan; | |
| 4318 } | |
| 4319 | |
| 4320 dquant= get_se_golomb(&s->gb); | |
| 4321 | |
| 4322 if( dquant > 25 || dquant < -26 ){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4323 av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); |
| 1168 | 4324 return -1; |
| 4325 } | |
| 4326 | |
| 4327 s->qscale += dquant; | |
| 4328 if(((unsigned)s->qscale) > 51){ | |
| 4329 if(s->qscale<0) s->qscale+= 52; | |
| 4330 else s->qscale-= 52; | |
| 4331 } | |
| 4332 | |
| 4333 h->chroma_qp= chroma_qp= get_chroma_qp(h, s->qscale); | |
| 4334 if(IS_INTRA16x16(mb_type)){ | |
| 4335 if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, s->qscale, 16) < 0){ | |
| 4336 return -1; //FIXME continue if partotioned and other retirn -1 too | |
| 4337 } | |
| 4338 | |
| 4339 assert((cbp&15) == 0 || (cbp&15) == 15); | |
| 4340 | |
| 4341 if(cbp&15){ | |
| 4342 for(i8x8=0; i8x8<4; i8x8++){ | |
| 4343 for(i4x4=0; i4x4<4; i4x4++){ | |
| 4344 const int index= i4x4 + 4*i8x8; | |
| 4345 if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, s->qscale, 15) < 0 ){ | |
| 4346 return -1; | |
| 4347 } | |
| 4348 } | |
| 4349 } | |
| 4350 }else{ | |
| 1636 | 4351 fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); |
| 1168 | 4352 } |
| 4353 }else{ | |
| 4354 for(i8x8=0; i8x8<4; i8x8++){ | |
| 4355 if(cbp & (1<<i8x8)){ | |
| 4356 for(i4x4=0; i4x4<4; i4x4++){ | |
| 4357 const int index= i4x4 + 4*i8x8; | |
| 4358 | |
| 4359 if( decode_residual(h, gb, h->mb + 16*index, index, scan, s->qscale, 16) <0 ){ | |
| 4360 return -1; | |
| 4361 } | |
| 4362 } | |
| 4363 }else{ | |
| 4364 uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; | |
| 4365 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; | |
| 4366 } | |
| 4367 } | |
| 4368 } | |
| 4369 | |
| 4370 if(cbp&0x30){ | |
| 4371 for(chroma_idx=0; chroma_idx<2; chroma_idx++) | |
| 4372 if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, chroma_qp, 4) < 0){ | |
| 4373 return -1; | |
| 4374 } | |
| 4375 } | |
| 4376 | |
| 4377 if(cbp&0x20){ | |
| 4378 for(chroma_idx=0; chroma_idx<2; chroma_idx++){ | |
| 4379 for(i4x4=0; i4x4<4; i4x4++){ | |
| 4380 const int index= 16 + 4*chroma_idx + i4x4; | |
| 4381 if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, chroma_qp, 15) < 0){ | |
| 4382 return -1; | |
| 4383 } | |
| 4384 } | |
| 4385 } | |
| 4386 }else{ | |
| 4387 uint8_t * const nnz= &h->non_zero_count_cache[0]; | |
| 4388 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = | |
| 4389 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; | |
| 4390 } | |
| 4391 }else{ | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4392 uint8_t * const nnz= &h->non_zero_count_cache[0]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4393 fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4394 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4395 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; |
| 1168 | 4396 } |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4397 s->current_picture.qscale_table[mb_xy]= s->qscale; |
| 1168 | 4398 write_back_non_zero_count(h); |
| 4399 | |
| 4400 return 0; | |
| 4401 } | |
| 4402 | |
| 2312 | 4403 static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) { |
| 4404 uint8_t *state= &h->cabac_state[ctx_base]; | |
| 4405 int mb_type; | |
| 4406 | |
| 4407 if(intra_slice){ | |
| 4408 MpegEncContext * const s = &h->s; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4409 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4410 const int mba_xy = mb_xy - 1; |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4411 const int mbb_xy = mb_xy - s->mb_stride; |
| 2312 | 4412 int ctx=0; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4413 if( h->slice_table[mba_xy] == h->slice_num && !IS_INTRA4x4( s->current_picture.mb_type[mba_xy] ) ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4414 ctx++; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4415 if( h->slice_table[mbb_xy] == h->slice_num && !IS_INTRA4x4( s->current_picture.mb_type[mbb_xy] ) ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4416 ctx++; |
| 2312 | 4417 if( get_cabac( &h->cabac, &state[ctx] ) == 0 ) |
| 4418 return 0; /* I4x4 */ | |
| 4419 state += 2; | |
| 4420 }else{ | |
| 4421 if( get_cabac( &h->cabac, &state[0] ) == 0 ) | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4422 return 0; /* I4x4 */ |
| 2312 | 4423 } |
| 4424 | |
| 4425 if( get_cabac_terminate( &h->cabac ) ) | |
| 4426 return 25; /* PCM */ | |
| 4427 | |
| 4428 mb_type = 1; /* I16x16 */ | |
| 4429 if( get_cabac( &h->cabac, &state[1] ) ) | |
| 4430 mb_type += 12; /* cbp_luma != 0 */ | |
| 4431 | |
| 4432 if( get_cabac( &h->cabac, &state[2] ) ) { | |
| 4433 if( get_cabac( &h->cabac, &state[2+intra_slice] ) ) | |
| 4434 mb_type += 4 * 2; /* cbp_chroma == 2 */ | |
| 4435 else | |
| 4436 mb_type += 4 * 1; /* cbp_chroma == 1 */ | |
| 4437 } | |
| 4438 if( get_cabac( &h->cabac, &state[3+intra_slice] ) ) | |
| 4439 mb_type += 2; | |
| 4440 if( get_cabac( &h->cabac, &state[3+2*intra_slice] ) ) | |
| 4441 mb_type += 1; | |
| 4442 return mb_type; | |
| 4443 } | |
| 4444 | |
| 4445 static int decode_cabac_mb_type( H264Context *h ) { | |
| 4446 MpegEncContext * const s = &h->s; | |
| 4447 | |
| 4448 if( h->slice_type == I_TYPE ) { | |
| 4449 return decode_cabac_intra_mb_type(h, 3, 1); | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4450 } else if( h->slice_type == P_TYPE ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4451 if( get_cabac( &h->cabac, &h->cabac_state[14] ) == 0 ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4452 /* P-type */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4453 if( get_cabac( &h->cabac, &h->cabac_state[15] ) == 0 ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4454 if( get_cabac( &h->cabac, &h->cabac_state[16] ) == 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4455 return 0; /* P_L0_D16x16; */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4456 else |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4457 return 3; /* P_8x8; */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4458 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4459 if( get_cabac( &h->cabac, &h->cabac_state[17] ) == 0 ) |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4460 return 2; /* P_L0_D8x16; */ |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4461 else |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4462 return 1; /* P_L0_D16x8; */ |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4463 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4464 } else { |
| 2312 | 4465 return decode_cabac_intra_mb_type(h, 17, 0) + 5; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4466 } |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4467 } else if( h->slice_type == B_TYPE ) { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4468 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4469 const int mba_xy = mb_xy - 1; |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4470 const int mbb_xy = mb_xy - s->mb_stride; |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4471 int ctx = 0; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4472 int bits; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4473 |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4474 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] ) |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4475 && !IS_DIRECT( s->current_picture.mb_type[mba_xy] ) ) |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4476 ctx++; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4477 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ) |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4478 && !IS_DIRECT( s->current_picture.mb_type[mbb_xy] ) ) |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4479 ctx++; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4480 |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4481 if( !get_cabac( &h->cabac, &h->cabac_state[27+ctx] ) ) |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4482 return 0; /* B_Direct_16x16 */ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4483 |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4484 if( !get_cabac( &h->cabac, &h->cabac_state[27+3] ) ) { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4485 return 1 + get_cabac( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4486 } |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4487 |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4488 bits = get_cabac( &h->cabac, &h->cabac_state[27+4] ) << 3; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4489 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 2; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4490 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 1; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4491 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ); |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4492 if( bits < 8 ) |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4493 return bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4494 else if( bits == 13 ) { |
| 2312 | 4495 return decode_cabac_intra_mb_type(h, 32, 0) + 23; |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4496 } else if( bits == 14 ) |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4497 return 11; /* B_L1_L0_8x16 */ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4498 else if( bits == 15 ) |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4499 return 22; /* B_8x8 */ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4500 |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4501 bits= ( bits<<1 ) | get_cabac( &h->cabac, &h->cabac_state[27+5] ); |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4502 return bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */ |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4503 } else { |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4504 /* TODO SI/SP frames? */ |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4505 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4506 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4507 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4508 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4509 static int decode_cabac_mb_skip( H264Context *h) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4510 MpegEncContext * const s = &h->s; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4511 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4512 const int mba_xy = mb_xy - 1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4513 const int mbb_xy = mb_xy - s->mb_stride; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4514 int ctx = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4515 |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4516 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] )) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4517 ctx++; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4518 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] )) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4519 ctx++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4520 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4521 if( h->slice_type == P_TYPE || h->slice_type == SP_TYPE) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4522 return get_cabac( &h->cabac, &h->cabac_state[11+ctx] ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4523 else /* B-frame */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4524 return get_cabac( &h->cabac, &h->cabac_state[24+ctx] ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4525 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4526 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4527 static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4528 int mode = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4529 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4530 if( get_cabac( &h->cabac, &h->cabac_state[68] ) ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4531 return pred_mode; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4532 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4533 if( get_cabac( &h->cabac, &h->cabac_state[69] ) ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4534 mode += 1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4535 if( get_cabac( &h->cabac, &h->cabac_state[69] ) ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4536 mode += 2; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4537 if( get_cabac( &h->cabac, &h->cabac_state[69] ) ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4538 mode += 4; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4539 if( mode >= pred_mode ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4540 return mode + 1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4541 else |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4542 return mode; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4543 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4544 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4545 static int decode_cabac_mb_chroma_pre_mode( H264Context *h) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4546 MpegEncContext * const s = &h->s; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4547 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4548 const int mba_xy = mb_xy - 1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4549 const int mbb_xy = mb_xy - s->mb_stride; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4550 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4551 int ctx = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4552 |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4553 /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */ |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4554 if( h->slice_table[mba_xy] == h->slice_num && h->chroma_pred_mode_table[mba_xy] != 0 ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4555 ctx++; |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4556 |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4557 if( h->slice_table[mbb_xy] == h->slice_num && h->chroma_pred_mode_table[mbb_xy] != 0 ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4558 ctx++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4559 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4560 if( get_cabac( &h->cabac, &h->cabac_state[64+ctx] ) == 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4561 return 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4562 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4563 if( get_cabac( &h->cabac, &h->cabac_state[64+3] ) == 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4564 return 1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4565 if( get_cabac( &h->cabac, &h->cabac_state[64+3] ) == 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4566 return 2; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4567 else |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4568 return 3; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4569 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4570 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4571 static const uint8_t block_idx_x[16] = { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4572 0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4573 }; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4574 static const uint8_t block_idx_y[16] = { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4575 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4576 }; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4577 static const uint8_t block_idx_xy[4][4] = { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4578 { 0, 2, 8, 10}, |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4579 { 1, 3, 9, 11}, |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4580 { 4, 6, 12, 14}, |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4581 { 5, 7, 13, 15} |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4582 }; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4583 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4584 static int decode_cabac_mb_cbp_luma( H264Context *h) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4585 MpegEncContext * const s = &h->s; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4586 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4587 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4588 int cbp = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4589 int i8x8; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4590 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4591 h->cbp_table[mb_xy] = 0; /* FIXME aaahahahah beurk */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4592 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4593 for( i8x8 = 0; i8x8 < 4; i8x8++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4594 int mba_xy = -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4595 int mbb_xy = -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4596 int x, y; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4597 int ctx = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4598 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4599 x = block_idx_x[4*i8x8]; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4600 y = block_idx_y[4*i8x8]; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4601 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4602 if( x > 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4603 mba_xy = mb_xy; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4604 else if( s->mb_x > 0 ) { |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4605 mba_xy = mb_xy - 1; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4606 if (h->slice_table[mba_xy] != h->slice_num) { |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4607 mba_xy = -1; |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4608 } |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4609 } |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4610 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4611 if( y > 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4612 mbb_xy = mb_xy; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4613 else if( s->mb_y > 0 ) { |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4614 mbb_xy = mb_xy - s->mb_stride; |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4615 if (h->slice_table[mbb_xy] != h->slice_num) { |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4616 mbb_xy = -1; |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4617 } |
|
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4618 } |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4619 |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4620 /* No need to test for skip as we put 0 for skip block */ |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4621 if( mba_xy >= 0 ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4622 int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4623 if( ((h->cbp_table[mba_xy] >> i8x8a)&0x01) == 0 ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4624 ctx++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4625 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4626 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4627 if( mbb_xy >= 0 ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4628 int i8x8b = block_idx_xy[x][(y-1)&0x03]/4; |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4629 if( ((h->cbp_table[mbb_xy] >> i8x8b)&0x01) == 0 ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4630 ctx += 2; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4631 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4632 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4633 if( get_cabac( &h->cabac, &h->cabac_state[73 + ctx] ) ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4634 cbp |= 1 << i8x8; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4635 h->cbp_table[mb_xy] = cbp; /* FIXME aaahahahah beurk */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4636 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4637 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4638 return cbp; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4639 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4640 static int decode_cabac_mb_cbp_chroma( H264Context *h) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4641 int ctx; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4642 int cbp_a, cbp_b; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4643 |
| 2314 | 4644 cbp_a = (h->left_cbp>>4)&0x03; |
| 4645 cbp_b = (h-> top_cbp>>4)&0x03; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4646 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4647 ctx = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4648 if( cbp_a > 0 ) ctx++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4649 if( cbp_b > 0 ) ctx += 2; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4650 if( get_cabac( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4651 return 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4652 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4653 ctx = 4; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4654 if( cbp_a == 2 ) ctx++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4655 if( cbp_b == 2 ) ctx += 2; |
| 2314 | 4656 return 1 + get_cabac( &h->cabac, &h->cabac_state[77 + ctx] ); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4657 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4658 static int decode_cabac_mb_dqp( H264Context *h) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4659 MpegEncContext * const s = &h->s; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4660 int mbn_xy; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4661 int ctx = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4662 int val = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4663 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4664 if( s->mb_x > 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4665 mbn_xy = s->mb_x + s->mb_y*s->mb_stride - 1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4666 else |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4667 mbn_xy = s->mb_width - 1 + (s->mb_y-1)*s->mb_stride; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4668 |
|
2498
4d6d056a00c6
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
michael
parents:
2485
diff
changeset
|
4669 if( h->last_qscale_diff != 0 && ( IS_INTRA16x16(s->current_picture.mb_type[mbn_xy] ) || (h->cbp_table[mbn_xy]&0x3f) ) ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4670 ctx++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4671 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4672 while( get_cabac( &h->cabac, &h->cabac_state[60 + ctx] ) ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4673 if( ctx < 2 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4674 ctx = 2; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4675 else |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4676 ctx = 3; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4677 val++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4678 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4679 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4680 if( val&0x01 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4681 return (val + 1)/2; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4682 else |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4683 return -(val + 1)/2; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4684 } |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4685 static int decode_cabac_p_mb_sub_type( H264Context *h ) { |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4686 if( get_cabac( &h->cabac, &h->cabac_state[21] ) ) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4687 return 0; /* 8x8 */ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4688 if( !get_cabac( &h->cabac, &h->cabac_state[22] ) ) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4689 return 1; /* 8x4 */ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4690 if( get_cabac( &h->cabac, &h->cabac_state[23] ) ) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4691 return 2; /* 4x8 */ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4692 return 3; /* 4x4 */ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4693 } |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4694 static int decode_cabac_b_mb_sub_type( H264Context *h ) { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4695 int type; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4696 if( !get_cabac( &h->cabac, &h->cabac_state[36] ) ) |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4697 return 0; /* B_Direct_8x8 */ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4698 if( !get_cabac( &h->cabac, &h->cabac_state[37] ) ) |
|
2311
cdbb2f30e08b
small typo patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
2310
diff
changeset
|
4699 return 1 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L0_8x8, B_L1_8x8 */ |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4700 type = 3; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4701 if( get_cabac( &h->cabac, &h->cabac_state[38] ) ) { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4702 if( get_cabac( &h->cabac, &h->cabac_state[39] ) ) |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4703 return 11 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L1_4x4, B_Bi_4x4 */ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4704 type += 4; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4705 } |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4706 type += 2*get_cabac( &h->cabac, &h->cabac_state[39] ); |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4707 type += get_cabac( &h->cabac, &h->cabac_state[39] ); |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4708 return type; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4709 } |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4710 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4711 static int decode_cabac_mb_ref( H264Context *h, int list, int n ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4712 int refa = h->ref_cache[list][scan8[n] - 1]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4713 int refb = h->ref_cache[list][scan8[n] - 8]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4714 int ref = 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4715 int ctx = 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4716 |
| 2396 | 4717 if( h->slice_type == B_TYPE) { |
| 4718 if( refa > 0 && !h->direct_cache[scan8[n] - 1] ) | |
| 4719 ctx++; | |
| 4720 if( refb > 0 && !h->direct_cache[scan8[n] - 8] ) | |
| 4721 ctx += 2; | |
| 4722 } else { | |
| 4723 if( refa > 0 ) | |
| 4724 ctx++; | |
| 4725 if( refb > 0 ) | |
| 4726 ctx += 2; | |
| 4727 } | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4728 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4729 while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4730 ref++; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4731 if( ctx < 4 ) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4732 ctx = 4; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4733 else |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4734 ctx = 5; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4735 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4736 return ref; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4737 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4738 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4739 static int decode_cabac_mb_mvd( H264Context *h, int list, int n, int l ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4740 int amvd = abs( h->mvd_cache[list][scan8[n] - 1][l] ) + |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4741 abs( h->mvd_cache[list][scan8[n] - 8][l] ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4742 int ctxbase = (l == 0) ? 40 : 47; |
| 2317 | 4743 int ctx, mvd; |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4744 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4745 if( amvd < 3 ) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4746 ctx = 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4747 else if( amvd > 32 ) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4748 ctx = 2; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4749 else |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4750 ctx = 1; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4751 |
| 2317 | 4752 if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+ctx])) |
| 4753 return 0; | |
| 4754 | |
| 4755 mvd= 1; | |
| 4756 ctx= 3; | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4757 while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase+ctx] ) ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4758 mvd++; |
| 2317 | 4759 if( ctx < 6 ) |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4760 ctx++; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4761 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4762 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4763 if( mvd >= 9 ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4764 int k = 3; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4765 while( get_cabac_bypass( &h->cabac ) ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4766 mvd += 1 << k; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4767 k++; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4768 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4769 while( k-- ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4770 if( get_cabac_bypass( &h->cabac ) ) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4771 mvd += 1 << k; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4772 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4773 } |
| 2317 | 4774 if( get_cabac_bypass( &h->cabac ) ) return -mvd; |
| 4775 else return mvd; | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4776 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4777 |
| 2316 | 4778 static int inline get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) { |
| 2314 | 4779 int nza, nzb; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4780 int ctx = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4781 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4782 if( cat == 0 ) { |
| 2314 | 4783 nza = h->left_cbp&0x100; |
| 4784 nzb = h-> top_cbp&0x100; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4785 } else if( cat == 1 || cat == 2 ) { |
| 2314 | 4786 nza = h->non_zero_count_cache[scan8[idx] - 1]; |
| 4787 nzb = h->non_zero_count_cache[scan8[idx] - 8]; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4788 } else if( cat == 3 ) { |
| 2314 | 4789 nza = (h->left_cbp>>(6+idx))&0x01; |
| 4790 nzb = (h-> top_cbp>>(6+idx))&0x01; | |
| 4791 } else { | |
| 4792 assert(cat == 4); | |
| 4793 nza = h->non_zero_count_cache[scan8[16+idx] - 1]; | |
| 4794 nzb = h->non_zero_count_cache[scan8[16+idx] - 8]; | |
| 4795 } | |
| 4796 | |
| 4797 if( nza > 0 ) | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4798 ctx++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4799 |
| 2314 | 4800 if( nzb > 0 ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4801 ctx += 2; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4802 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4803 return ctx + 4 * cat; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4804 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4805 |
| 2316 | 4806 static int inline decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int qp, int max_coeff) { |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4807 const int mb_xy = h->s.mb_x + h->s.mb_y*h->s.mb_stride; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4808 const uint16_t *qmul= dequant_coeff[qp]; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4809 static const int significant_coeff_flag_offset[5] = { 0, 15, 29, 44, 47 }; |
| 2313 | 4810 static const int coeff_abs_level_m1_offset[5] = {227+ 0, 227+10, 227+20, 227+30, 227+39 }; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4811 |
| 2313 | 4812 int index[16]; |
| 4813 | |
| 4814 int i, last; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4815 int coeff_count = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4816 |
| 2316 | 4817 int abslevel1 = 1; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4818 int abslevelgt1 = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4819 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4820 /* cat: 0-> DC 16x16 n = 0 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4821 * 1-> AC 16x16 n = luma4x4idx |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4822 * 2-> Luma4x4 n = luma4x4idx |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4823 * 3-> DC Chroma n = iCbCr |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4824 * 4-> AC Chroma n = 4 * iCbCr + chroma4x4idx |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4825 */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4826 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4827 /* read coded block flag */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4828 if( get_cabac( &h->cabac, &h->cabac_state[85 + get_cabac_cbf_ctx( h, cat, n ) ] ) == 0 ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4829 if( cat == 1 || cat == 2 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4830 h->non_zero_count_cache[scan8[n]] = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4831 else if( cat == 4 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4832 h->non_zero_count_cache[scan8[16+n]] = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4833 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4834 return 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4835 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4836 |
| 2313 | 4837 for(last= 0; last < max_coeff - 1; last++) { |
| 4838 if( get_cabac( &h->cabac, &h->cabac_state[105+significant_coeff_flag_offset[cat]+last] )) { | |
| 4839 index[coeff_count++] = last; | |
| 4840 if( get_cabac( &h->cabac, &h->cabac_state[166+significant_coeff_flag_offset[cat]+last] ) ) { | |
| 4841 last= max_coeff; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4842 break; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4843 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4844 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4845 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4846 if( last == max_coeff -1 ) { |
| 2313 | 4847 index[coeff_count++] = last; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4848 } |
| 2316 | 4849 assert(coeff_count > 0); |
| 4850 | |
| 4851 if( cat == 0 ) | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4852 h->cbp_table[mb_xy] |= 0x100; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4853 else if( cat == 1 || cat == 2 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4854 h->non_zero_count_cache[scan8[n]] = coeff_count; |
| 2316 | 4855 else if( cat == 3 ) |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4856 h->cbp_table[mb_xy] |= 0x40 << n; |
| 2316 | 4857 else { |
| 4858 assert( cat == 4 ); | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4859 h->non_zero_count_cache[scan8[16+n]] = coeff_count; |
| 2316 | 4860 } |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4861 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4862 for( i = coeff_count - 1; i >= 0; i-- ) { |
| 2316 | 4863 int ctx = (abslevelgt1 != 0 ? 0 : FFMIN( 4, abslevel1 )) + coeff_abs_level_m1_offset[cat]; |
| 4864 int j= scantable[index[i]]; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4865 |
| 2313 | 4866 if( get_cabac( &h->cabac, &h->cabac_state[ctx] ) == 0 ) { |
| 2316 | 4867 if( cat == 0 || cat == 3 ) { |
| 4868 if( get_cabac_bypass( &h->cabac ) ) block[j] = -1; | |
| 4869 else block[j] = 1; | |
| 4870 }else{ | |
| 4871 if( get_cabac_bypass( &h->cabac ) ) block[j] = -qmul[j]; | |
| 4872 else block[j] = qmul[j]; | |
| 4873 } | |
| 2313 | 4874 |
| 4875 abslevel1++; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4876 } else { |
| 2313 | 4877 int coeff_abs = 2; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4878 ctx = 5 + FFMIN( 4, abslevelgt1 ) + coeff_abs_level_m1_offset[cat]; |
| 2313 | 4879 while( coeff_abs < 15 && get_cabac( &h->cabac, &h->cabac_state[ctx] ) ) { |
| 4880 coeff_abs++; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4881 } |
| 2313 | 4882 |
| 4883 if( coeff_abs >= 15 ) { | |
| 4884 int j = 0; | |
| 4885 while( get_cabac_bypass( &h->cabac ) ) { | |
| 4886 coeff_abs += 1 << j; | |
| 4887 j++; | |
| 4888 } | |
| 4889 | |
| 4890 while( j-- ) { | |
| 4891 if( get_cabac_bypass( &h->cabac ) ) | |
| 4892 coeff_abs += 1 << j ; | |
| 4893 } | |
| 4894 } | |
| 4895 | |
| 2316 | 4896 if( cat == 0 || cat == 3 ) { |
| 4897 if( get_cabac_bypass( &h->cabac ) ) block[j] = -coeff_abs; | |
| 4898 else block[j] = coeff_abs; | |
| 4899 }else{ | |
| 4900 if( get_cabac_bypass( &h->cabac ) ) block[j] = -coeff_abs * qmul[j]; | |
| 4901 else block[j] = coeff_abs * qmul[j]; | |
| 4902 } | |
| 2313 | 4903 |
| 4904 abslevelgt1++; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4905 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4906 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4907 return 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4908 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4909 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4910 /** |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4911 * decodes a macroblock |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4912 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4913 */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4914 static int decode_mb_cabac(H264Context *h) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4915 MpegEncContext * const s = &h->s; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4916 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4917 int mb_type, partition_count, cbp = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4918 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4919 s->dsp.clear_blocks(h->mb); //FIXME avoid if allready clear (move after skip handlong?) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4920 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4921 if( h->sps.mb_aff ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4922 av_log( h->s.avctx, AV_LOG_ERROR, "Fields not supported with CABAC\n" ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4923 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4924 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4925 |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
4926 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4927 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4928 /* read skip flags */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4929 if( decode_cabac_mb_skip( h ) ) { |
| 2396 | 4930 decode_mb_skip(h); |
| 4931 | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4932 h->cbp_table[mb_xy] = 0; |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4933 h->chroma_pred_mode_table[mb_xy] = 0; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4934 h->last_qscale_diff = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4935 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4936 return 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4937 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4938 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4939 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4940 h->prev_mb_skiped = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4941 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4942 if( ( mb_type = decode_cabac_mb_type( h ) ) < 0 ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4943 av_log( h->s.avctx, AV_LOG_ERROR, "decode_cabac_mb_type failed\n" ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4944 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4945 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4946 |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4947 if( h->slice_type == B_TYPE ) { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4948 if( mb_type < 23 ){ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4949 partition_count= b_mb_type_info[mb_type].partition_count; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4950 mb_type= b_mb_type_info[mb_type].type; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4951 }else{ |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4952 mb_type -= 23; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4953 goto decode_intra_mb; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4954 } |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4955 } else if( h->slice_type == P_TYPE ) { |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4956 if( mb_type < 5) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4957 partition_count= p_mb_type_info[mb_type].partition_count; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4958 mb_type= p_mb_type_info[mb_type].type; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4959 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4960 mb_type -= 5; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4961 goto decode_intra_mb; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4962 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4963 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4964 assert(h->slice_type == I_TYPE); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4965 decode_intra_mb: |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4966 partition_count = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4967 cbp= i_mb_type_info[mb_type].cbp; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4968 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4969 mb_type= i_mb_type_info[mb_type].type; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4970 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4971 #if 0 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4972 if(h->mb_field_decoding_flag) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4973 mb_type |= MB_TYPE_INTERLACED; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4974 #endif |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4975 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4976 s->current_picture.mb_type[mb_xy]= mb_type; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4977 h->slice_table[ mb_xy ]= h->slice_num; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4978 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4979 if(IS_INTRA_PCM(mb_type)) { |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4980 const uint8_t *ptr; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4981 unsigned int x, y; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4982 |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4983 // We assume these blocks are very rare so we dont optimize it. |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4984 // FIXME The two following lines get the bitstream position in the cabac |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4985 // decode, I think it should be done by a function in cabac.h (or cabac.c). |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4986 ptr= h->cabac.bytestream; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4987 if (h->cabac.low&0x1) ptr-=CABAC_BITS/8; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4988 |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4989 // The pixels are stored in the same order as levels in h->mb array. |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4990 for(y=0; y<16; y++){ |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4991 const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4992 for(x=0; x<16; x++){ |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4993 tprintf("LUMA ICPM LEVEL (%3d)\n", *ptr); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4994 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4995 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4996 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4997 for(y=0; y<8; y++){ |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4998 const int index= 256 + 4*(y&3) + 32*(y>>2); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
4999 for(x=0; x<8; x++){ |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5000 tprintf("CHROMA U ICPM LEVEL (%3d)\n", *ptr); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5001 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5002 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5003 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5004 for(y=0; y<8; y++){ |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5005 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5006 for(x=0; x<8; x++){ |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5007 tprintf("CHROMA V ICPM LEVEL (%3d)\n", *ptr); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5008 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5009 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5010 } |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5011 |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5012 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5013 |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5014 // All blocks are presents |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5015 h->cbp_table[mb_xy] = 0x1ef; |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
5016 h->chroma_pred_mode_table[mb_xy] = 0; |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5017 // In deblocking, the quantiser is 0 |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5018 s->current_picture.qscale_table[mb_xy]= 0; |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5019 h->chroma_qp = get_chroma_qp(h, 0); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5020 // All coeffs are presents |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5021 memset(h->non_zero_count[mb_xy], 16, 16); |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5022 return 0; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5023 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5024 |
| 2449 | 5025 fill_caches(h, mb_type, 0); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5026 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5027 if( IS_INTRA( mb_type ) ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5028 if( IS_INTRA4x4( mb_type ) ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5029 int i; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5030 for( i = 0; i < 16; i++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5031 int pred = pred_intra_mode( h, i ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5032 h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5033 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5034 //av_log( s->avctx, AV_LOG_ERROR, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[ scan8[i] ] ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5035 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5036 write_back_intra_pred_mode(h); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5037 if( check_intra4x4_pred_mode(h) < 0 ) return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5038 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5039 h->intra16x16_pred_mode= check_intra_pred_mode( h, h->intra16x16_pred_mode ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5040 if( h->intra16x16_pred_mode < 0 ) return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5041 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5042 h->chroma_pred_mode_table[mb_xy] = |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5043 h->chroma_pred_mode = decode_cabac_mb_chroma_pre_mode( h ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5044 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5045 h->chroma_pred_mode= check_intra_pred_mode( h, h->chroma_pred_mode ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5046 if( h->chroma_pred_mode < 0 ) return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5047 } else if( partition_count == 4 ) { |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5048 int i, j, sub_partition_count[4], list, ref[2][4]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5049 |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5050 if( h->slice_type == B_TYPE ) { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5051 for( i = 0; i < 4; i++ ) { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5052 h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h ); |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5053 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5054 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5055 } |
| 2396 | 5056 if( IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1]) |
| 5057 || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) { | |
| 5058 pred_direct_motion(h, &mb_type); | |
| 5059 if( h->ref_count[0] > 1 || h->ref_count[1] > 1 ) { | |
| 5060 for( i = 0; i < 4; i++ ) | |
| 5061 if( IS_DIRECT(h->sub_mb_type[i]) ) | |
| 5062 fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, 1, 1 ); | |
| 5063 } | |
| 5064 } | |
|
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5065 } else { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5066 for( i = 0; i < 4; i++ ) { |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5067 h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h ); |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5068 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5069 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
|
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
5070 } |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5071 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5072 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5073 for( list = 0; list < 2; list++ ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5074 if( h->ref_count[list] > 0 ) { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5075 for( i = 0; i < 4; i++ ) { |
| 2396 | 5076 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
| 5077 if(IS_DIR(h->sub_mb_type[i], 0, list)){ | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5078 if( h->ref_count[list] > 1 ) |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5079 ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5080 else |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5081 ref[list][i] = 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5082 } else { |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5083 ref[list][i] = -1; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5084 } |
| 2110 | 5085 h->ref_cache[list][ scan8[4*i]+1 ]= |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5086 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5087 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5088 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5089 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5090 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5091 for(list=0; list<2; list++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5092 for(i=0; i<4; i++){ |
| 2396 | 5093 if(IS_DIRECT(h->sub_mb_type[i])){ |
| 5094 fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4); | |
| 5095 continue; | |
| 5096 } | |
| 2110 | 5097 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]; |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5098 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5099 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5100 const int sub_mb_type= h->sub_mb_type[i]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5101 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5102 for(j=0; j<sub_partition_count[i]; j++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5103 int mpx, mpy; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5104 int mx, my; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5105 const int index= 4*i + block_width*j; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5106 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5107 int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5108 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mpx, &mpy); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5109 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5110 mx = mpx + decode_cabac_mb_mvd( h, list, index, 0 ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5111 my = mpy + decode_cabac_mb_mvd( h, list, index, 1 ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5112 tprintf("final mv:%d %d\n", mx, my); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5113 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5114 if(IS_SUB_8X8(sub_mb_type)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5115 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5116 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5117 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5118 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5119 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5120 mvd_cache[ 0 ][0]= mvd_cache[ 1 ][0]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5121 mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mx - mpx; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5122 mvd_cache[ 0 ][1]= mvd_cache[ 1 ][1]= |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5123 mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= my - mpy; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5124 }else if(IS_SUB_8X4(sub_mb_type)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5125 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mx; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5126 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= my; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5127 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5128 mvd_cache[ 0 ][0]= mvd_cache[ 1 ][0]= mx- mpx; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5129 mvd_cache[ 0 ][1]= mvd_cache[ 1 ][1]= my - mpy; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5130 }else if(IS_SUB_4X8(sub_mb_type)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5131 mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mx; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5132 mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= my; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5133 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5134 mvd_cache[ 0 ][0]= mvd_cache[ 8 ][0]= mx - mpx; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5135 mvd_cache[ 0 ][1]= mvd_cache[ 8 ][1]= my - mpy; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5136 }else{ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5137 assert(IS_SUB_4X4(sub_mb_type)); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5138 mv_cache[ 0 ][0]= mx; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5139 mv_cache[ 0 ][1]= my; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5140 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5141 mvd_cache[ 0 ][0]= mx - mpx; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5142 mvd_cache[ 0 ][1]= my - mpy; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5143 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5144 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5145 }else{ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5146 uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5147 uint32_t *pd= (uint32_t *)&h->mvd_cache[list][ scan8[4*i] ][0]; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5148 p[0] = p[1] = p[8] = p[9] = 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5149 pd[0]= pd[1]= pd[8]= pd[9]= 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5150 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5151 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5152 } |
| 2396 | 5153 } else if( IS_DIRECT(mb_type) ) { |
| 5154 pred_direct_motion(h, &mb_type); | |
| 5155 s->current_picture.mb_type[mb_xy]= mb_type; | |
| 5156 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
| 5157 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
| 5158 } else { | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5159 int list, mx, my, i, mpx, mpy; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5160 if(IS_16X16(mb_type)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5161 for(list=0; list<2; list++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5162 if(IS_DIR(mb_type, 0, list)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5163 if(h->ref_count[list] > 0 ){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5164 const int ref = h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 0 ) : 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5165 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5166 } |
| 2523 | 5167 }else |
| 5168 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1); | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5169 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5170 for(list=0; list<2; list++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5171 if(IS_DIR(mb_type, 0, list)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5172 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mpx, &mpy); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5173 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5174 mx = mpx + decode_cabac_mb_mvd( h, list, 0, 0 ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5175 my = mpy + decode_cabac_mb_mvd( h, list, 0, 1 ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5176 tprintf("final mv:%d %d\n", mx, my); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5177 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5178 fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx-mpx,my-mpy), 4); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5179 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); |
| 2523 | 5180 }else |
| 5181 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4); | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5182 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5183 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5184 else if(IS_16X8(mb_type)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5185 for(list=0; list<2; list++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5186 if(h->ref_count[list]>0){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5187 for(i=0; i<2; i++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5188 if(IS_DIR(mb_type, i, list)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5189 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5190 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1); |
| 2396 | 5191 }else |
| 5192 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5193 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5194 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5195 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5196 for(list=0; list<2; list++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5197 for(i=0; i<2; i++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5198 if(IS_DIR(mb_type, i, list)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5199 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5200 mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5201 my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5202 tprintf("final mv:%d %d\n", mx, my); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5203 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5204 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx-mpx,my-mpy), 4); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5205 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); |
| 2523 | 5206 }else{ |
| 2396 | 5207 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); |
| 5208 fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5209 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5210 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5211 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5212 }else{ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5213 assert(IS_8X16(mb_type)); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5214 for(list=0; list<2; list++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5215 if(h->ref_count[list]>0){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5216 for(i=0; i<2; i++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5217 if(IS_DIR(mb_type, i, list)){ //FIXME optimize |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5218 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 0; |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5219 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1); |
| 2396 | 5220 }else |
| 5221 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5222 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5223 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5224 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5225 for(list=0; list<2; list++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5226 for(i=0; i<2; i++){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5227 if(IS_DIR(mb_type, i, list)){ |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5228 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5229 mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5230 my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 ); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5231 |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5232 tprintf("final mv:%d %d\n", mx, my); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5233 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx-mpx,my-mpy), 4); |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5234 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); |
| 2523 | 5235 }else{ |
| 2396 | 5236 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); |
| 5237 fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); | |
|
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5238 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5239 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5240 } |
|
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5241 } |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5242 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5243 |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
5244 if( IS_INTER( mb_type ) ) { |
|
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
5245 h->chroma_pred_mode_table[mb_xy] = 0; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5246 write_back_motion( h, mb_type ); |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
5247 } |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5248 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5249 if( !IS_INTRA16x16( mb_type ) ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5250 cbp = decode_cabac_mb_cbp_luma( h ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5251 cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5252 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5253 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5254 h->cbp_table[mb_xy] = cbp; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5255 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5256 if( cbp || IS_INTRA16x16( mb_type ) ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5257 const uint8_t *scan, *dc_scan; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5258 int dqp; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5259 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5260 if(IS_INTERLACED(mb_type)){ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5261 scan= field_scan; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5262 dc_scan= luma_dc_field_scan; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5263 }else{ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5264 scan= zigzag_scan; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5265 dc_scan= luma_dc_zigzag_scan; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5266 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5267 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5268 h->last_qscale_diff = dqp = decode_cabac_mb_dqp( h ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5269 s->qscale += dqp; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5270 if(((unsigned)s->qscale) > 51){ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5271 if(s->qscale<0) s->qscale+= 52; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5272 else s->qscale-= 52; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5273 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5274 h->chroma_qp = get_chroma_qp(h, s->qscale); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5275 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5276 if( IS_INTRA16x16( mb_type ) ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5277 int i; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5278 //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5279 if( decode_cabac_residual( h, h->mb, 0, 0, dc_scan, s->qscale, 16) < 0) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5280 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5281 if( cbp&15 ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5282 for( i = 0; i < 16; i++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5283 //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5284 if( decode_cabac_residual(h, h->mb + 16*i, 1, i, scan + 1, s->qscale, 15) < 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5285 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5286 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5287 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5288 fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5289 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5290 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5291 int i8x8, i4x4; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5292 for( i8x8 = 0; i8x8 < 4; i8x8++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5293 if( cbp & (1<<i8x8) ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5294 for( i4x4 = 0; i4x4 < 4; i4x4++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5295 const int index = 4*i8x8 + i4x4; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5296 //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5297 if( decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, s->qscale, 16) < 0 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5298 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5299 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5300 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5301 uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5302 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5303 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5304 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5305 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5306 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5307 if( cbp&0x30 ){ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5308 int c; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5309 for( c = 0; c < 2; c++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5310 //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5311 if( decode_cabac_residual(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, h->chroma_qp, 4) < 0) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5312 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5313 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5314 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5315 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5316 if( cbp&0x20 ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5317 int c, i; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5318 for( c = 0; c < 2; c++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5319 for( i = 0; i < 4; i++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5320 const int index = 16 + 4 * c + i; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5321 //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5322 if( decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, h->chroma_qp, 15) < 0) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5323 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5324 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5325 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5326 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5327 uint8_t * const nnz= &h->non_zero_count_cache[0]; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5328 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5329 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5330 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5331 } else { |
| 2315 | 5332 uint8_t * const nnz= &h->non_zero_count_cache[0]; |
| 5333 fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); | |
| 5334 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = | |
| 5335 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5336 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5337 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5338 s->current_picture.qscale_table[mb_xy]= s->qscale; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5339 write_back_non_zero_count(h); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5340 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5341 return 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5342 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5343 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5344 |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5345 static void filter_mb_edgev( H264Context *h, uint8_t *pix, int stride, int bS[4], int qp ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5346 int i, d; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5347 const int index_a = clip( qp + h->slice_alpha_c0_offset, 0, 51 ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5348 const int alpha = alpha_table[index_a]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5349 const int beta = beta_table[clip( qp + h->slice_beta_offset, 0, 51 )]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5350 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5351 for( i = 0; i < 4; i++ ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5352 if( bS[i] == 0 ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5353 pix += 4 * stride; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5354 continue; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5355 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5356 |
| 1898 | 5357 if( bS[i] < 4 ) { |
| 5358 const int tc0 = tc0_table[index_a][bS[i] - 1]; | |
| 5359 /* 4px edge length */ | |
| 5360 for( d = 0; d < 4; d++ ) { | |
| 5361 const int p0 = pix[-1]; | |
| 5362 const int p1 = pix[-2]; | |
| 5363 const int p2 = pix[-3]; | |
| 5364 const int q0 = pix[0]; | |
| 5365 const int q1 = pix[1]; | |
| 5366 const int q2 = pix[2]; | |
| 5367 | |
| 5368 if( ABS( p0 - q0 ) < alpha && | |
| 5369 ABS( p1 - p0 ) < beta && | |
| 5370 ABS( q1 - q0 ) < beta ) { | |
| 5371 int tc = tc0; | |
| 5372 int i_delta; | |
| 5373 | |
| 5374 if( ABS( p2 - p0 ) < beta ) { | |
| 5375 pix[-2] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 5376 tc++; | |
| 5377 } | |
| 5378 if( ABS( q2 - q0 ) < beta ) { | |
| 5379 pix[1] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 5380 tc++; | |
| 5381 } | |
| 5382 | |
| 5383 i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 5384 pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */ | |
| 5385 pix[0] = clip_uint8( q0 - i_delta ); /* q0' */ | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5386 } |
| 1898 | 5387 pix += stride; |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5388 } |
| 1898 | 5389 }else{ |
| 5390 /* 4px edge length */ | |
| 5391 for( d = 0; d < 4; d++ ) { | |
| 5392 const int p0 = pix[-1]; | |
| 5393 const int p1 = pix[-2]; | |
| 5394 const int p2 = pix[-3]; | |
| 5395 | |
| 5396 const int q0 = pix[0]; | |
| 5397 const int q1 = pix[1]; | |
| 5398 const int q2 = pix[2]; | |
| 5399 | |
| 5400 if( ABS( p0 - q0 ) < alpha && | |
| 5401 ABS( p1 - p0 ) < beta && | |
| 5402 ABS( q1 - q0 ) < beta ) { | |
| 5403 | |
| 5404 if(ABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ | |
| 5405 if( ABS( p2 - p0 ) < beta) | |
| 5406 { | |
| 5407 const int p3 = pix[-4]; | |
| 5408 /* p0', p1', p2' */ | |
| 5409 pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; | |
| 5410 pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; | |
| 5411 pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; | |
| 5412 } else { | |
| 5413 /* p0' */ | |
| 5414 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 5415 } | |
| 5416 if( ABS( q2 - q0 ) < beta) | |
| 5417 { | |
| 5418 const int q3 = pix[3]; | |
| 5419 /* q0', q1', q2' */ | |
| 5420 pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; | |
| 5421 pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; | |
| 5422 pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; | |
| 5423 } else { | |
| 5424 /* q0' */ | |
| 5425 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 5426 } | |
| 5427 }else{ | |
| 5428 /* p0', q0' */ | |
| 5429 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 5430 pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 5431 } | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5432 } |
| 1898 | 5433 pix += stride; |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5434 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5435 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5436 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5437 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5438 static void filter_mb_edgecv( H264Context *h, uint8_t *pix, int stride, int bS[4], int qp ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5439 int i, d; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5440 const int index_a = clip( qp + h->slice_alpha_c0_offset, 0, 51 ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5441 const int alpha = alpha_table[index_a]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5442 const int beta = beta_table[clip( qp + h->slice_beta_offset, 0, 51 )]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5443 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5444 for( i = 0; i < 4; i++ ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5445 if( bS[i] == 0 ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5446 pix += 2 * stride; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5447 continue; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5448 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5449 |
| 1898 | 5450 if( bS[i] < 4 ) { |
| 5451 const int tc = tc0_table[index_a][bS[i] - 1] + 1; | |
| 5452 /* 2px edge length (because we use same bS than the one for luma) */ | |
| 5453 for( d = 0; d < 2; d++ ){ | |
| 5454 const int p0 = pix[-1]; | |
| 5455 const int p1 = pix[-2]; | |
| 5456 const int q0 = pix[0]; | |
| 5457 const int q1 = pix[1]; | |
| 5458 | |
| 5459 if( ABS( p0 - q0 ) < alpha && | |
| 5460 ABS( p1 - p0 ) < beta && | |
| 5461 ABS( q1 - q0 ) < beta ) { | |
| 5462 const int i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 5463 | |
| 5464 pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */ | |
| 5465 pix[0] = clip_uint8( q0 - i_delta ); /* q0' */ | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
5466 //tprintf("filter_mb_edgecv i:%d d:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, qp, index_a, alpha, beta, tc, bS[i], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); |
| 1898 | 5467 } |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5468 pix += stride; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5469 } |
| 1898 | 5470 }else{ |
| 5471 /* 2px edge length (because we use same bS than the one for luma) */ | |
| 5472 for( d = 0; d < 2; d++ ){ | |
| 5473 const int p0 = pix[-1]; | |
| 5474 const int p1 = pix[-2]; | |
| 5475 const int q0 = pix[0]; | |
| 5476 const int q1 = pix[1]; | |
| 5477 | |
| 5478 if( ABS( p0 - q0 ) < alpha && | |
| 5479 ABS( p1 - p0 ) < beta && | |
| 5480 ABS( q1 - q0 ) < beta ) { | |
| 5481 | |
| 5482 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ | |
| 5483 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ | |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
5484 //tprintf("filter_mb_edgecv i:%d d:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); |
| 1898 | 5485 } |
| 5486 pix += stride; | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5487 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5488 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5489 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5490 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5491 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5492 static void filter_mb_edgeh( H264Context *h, uint8_t *pix, int stride, int bS[4], int qp ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5493 int i, d; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5494 const int index_a = clip( qp + h->slice_alpha_c0_offset, 0, 51 ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5495 const int alpha = alpha_table[index_a]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5496 const int beta = beta_table[clip( qp + h->slice_beta_offset, 0, 51 )]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5497 const int pix_next = stride; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5498 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5499 for( i = 0; i < 4; i++ ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5500 if( bS[i] == 0 ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5501 pix += 4; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5502 continue; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5503 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5504 |
| 1898 | 5505 if( bS[i] < 4 ) { |
| 5506 const int tc0 = tc0_table[index_a][bS[i] - 1]; | |
| 5507 /* 4px edge length */ | |
| 5508 for( d = 0; d < 4; d++ ) { | |
| 5509 const int p0 = pix[-1*pix_next]; | |
| 5510 const int p1 = pix[-2*pix_next]; | |
| 5511 const int p2 = pix[-3*pix_next]; | |
| 5512 const int q0 = pix[0]; | |
| 5513 const int q1 = pix[1*pix_next]; | |
| 5514 const int q2 = pix[2*pix_next]; | |
| 5515 | |
| 5516 if( ABS( p0 - q0 ) < alpha && | |
| 5517 ABS( p1 - p0 ) < beta && | |
| 5518 ABS( q1 - q0 ) < beta ) { | |
| 5519 | |
| 5520 int tc = tc0; | |
| 5521 int i_delta; | |
| 5522 | |
| 5523 if( ABS( p2 - p0 ) < beta ) { | |
| 5524 pix[-2*pix_next] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 5525 tc++; | |
| 5526 } | |
| 5527 if( ABS( q2 - q0 ) < beta ) { | |
| 5528 pix[pix_next] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 5529 tc++; | |
| 5530 } | |
| 5531 | |
| 5532 i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 5533 pix[-pix_next] = clip_uint8( p0 + i_delta ); /* p0' */ | |
| 5534 pix[0] = clip_uint8( q0 - i_delta ); /* q0' */ | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5535 } |
| 1898 | 5536 pix++; |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5537 } |
| 1898 | 5538 }else{ |
| 5539 /* 4px edge length */ | |
| 5540 for( d = 0; d < 4; d++ ) { | |
| 5541 const int p0 = pix[-1*pix_next]; | |
| 5542 const int p1 = pix[-2*pix_next]; | |
| 5543 const int p2 = pix[-3*pix_next]; | |
| 5544 const int q0 = pix[0]; | |
| 5545 const int q1 = pix[1*pix_next]; | |
| 5546 const int q2 = pix[2*pix_next]; | |
| 5547 | |
| 5548 if( ABS( p0 - q0 ) < alpha && | |
| 5549 ABS( p1 - p0 ) < beta && | |
| 5550 ABS( q1 - q0 ) < beta ) { | |
| 5551 | |
| 5552 const int p3 = pix[-4*pix_next]; | |
| 5553 const int q3 = pix[ 3*pix_next]; | |
| 5554 | |
| 5555 if(ABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ | |
| 5556 if( ABS( p2 - p0 ) < beta) { | |
| 5557 /* p0', p1', p2' */ | |
| 5558 pix[-1*pix_next] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; | |
| 5559 pix[-2*pix_next] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; | |
| 5560 pix[-3*pix_next] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; | |
| 5561 } else { | |
| 5562 /* p0' */ | |
| 5563 pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 5564 } | |
| 5565 if( ABS( q2 - q0 ) < beta) { | |
| 5566 /* q0', q1', q2' */ | |
| 5567 pix[0*pix_next] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; | |
| 5568 pix[1*pix_next] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; | |
| 5569 pix[2*pix_next] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; | |
| 5570 } else { | |
| 5571 /* q0' */ | |
| 5572 pix[0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 5573 } | |
| 5574 }else{ | |
| 5575 /* p0', q0' */ | |
| 5576 pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 5577 pix[ 0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 5578 } | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5579 } |
| 1898 | 5580 pix++; |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5581 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5582 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5583 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5584 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5585 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5586 static void filter_mb_edgech( H264Context *h, uint8_t *pix, int stride, int bS[4], int qp ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5587 int i, d; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5588 const int index_a = clip( qp + h->slice_alpha_c0_offset, 0, 51 ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5589 const int alpha = alpha_table[index_a]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5590 const int beta = beta_table[clip( qp + h->slice_beta_offset, 0, 51 )]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5591 const int pix_next = stride; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5592 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5593 for( i = 0; i < 4; i++ ) |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5594 { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5595 if( bS[i] == 0 ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5596 pix += 2; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5597 continue; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5598 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5599 |
| 1898 | 5600 if( bS[i] < 4 ) { |
| 5601 int tc = tc0_table[index_a][bS[i] - 1] + 1; | |
| 5602 /* 2px edge length (see deblocking_filter_edgecv) */ | |
| 5603 for( d = 0; d < 2; d++ ) { | |
| 5604 const int p0 = pix[-1*pix_next]; | |
| 5605 const int p1 = pix[-2*pix_next]; | |
| 5606 const int q0 = pix[0]; | |
| 5607 const int q1 = pix[1*pix_next]; | |
| 5608 | |
| 5609 if( ABS( p0 - q0 ) < alpha && | |
| 5610 ABS( p1 - p0 ) < beta && | |
| 5611 ABS( q1 - q0 ) < beta ) { | |
| 5612 | |
| 5613 int i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 5614 | |
| 5615 pix[-pix_next] = clip_uint8( p0 + i_delta ); /* p0' */ | |
| 5616 pix[0] = clip_uint8( q0 - i_delta ); /* q0' */ | |
| 5617 } | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5618 pix++; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5619 } |
| 1898 | 5620 }else{ |
| 5621 /* 2px edge length (see deblocking_filter_edgecv) */ | |
| 5622 for( d = 0; d < 2; d++ ) { | |
| 5623 const int p0 = pix[-1*pix_next]; | |
| 5624 const int p1 = pix[-2*pix_next]; | |
| 5625 const int q0 = pix[0]; | |
| 5626 const int q1 = pix[1*pix_next]; | |
| 5627 | |
| 5628 if( ABS( p0 - q0 ) < alpha && | |
| 5629 ABS( p1 - p0 ) < beta && | |
| 5630 ABS( q1 - q0 ) < beta ) { | |
| 5631 | |
| 5632 pix[-pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ | |
| 5633 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ | |
| 5634 } | |
| 5635 pix++; | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5636 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5637 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5638 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5639 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5640 |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5641 static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr) { |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5642 MpegEncContext * const s = &h->s; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5643 const int mb_xy= mb_x + mb_y*s->mb_stride; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5644 int linesize, uvlinesize; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5645 int dir; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5646 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5647 /* FIXME Implement deblocking filter for field MB */ |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5648 if( h->sps.mb_aff ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5649 return; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5650 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5651 linesize = s->linesize; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5652 uvlinesize = s->uvlinesize; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5653 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5654 /* dir : 0 -> vertical edge, 1 -> horizontal edge */ |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5655 for( dir = 0; dir < 2; dir++ ) |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5656 { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5657 int edge; |
| 2454 | 5658 const int mbm_xy = dir == 0 ? mb_xy -1 : mb_xy - s->mb_stride; |
| 5659 int start = h->slice_table[mbm_xy] == 255 ? 1 : 0; | |
| 5660 | |
| 5661 if (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_table[mb_xy]) | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5662 start = 1; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5663 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5664 /* Calculate bS */ |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5665 for( edge = start; edge < 4; edge++ ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5666 /* mbn_xy: neighbour macroblock (how that works for field ?) */ |
| 2454 | 5667 int mbn_xy = edge > 0 ? mb_xy : mbm_xy; |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5668 int bS[4]; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5669 int qp; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5670 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5671 if( IS_INTRA( s->current_picture.mb_type[mb_xy] ) || |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5672 IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5673 bS[0] = bS[1] = bS[2] = bS[3] = ( edge == 0 ? 4 : 3 ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5674 } else { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5675 int i; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5676 for( i = 0; i < 4; i++ ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5677 int x = dir == 0 ? edge : i; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5678 int y = dir == 0 ? i : edge; |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5679 int b_idx= 8 + 4 + x + 8*y; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5680 int bn_idx= b_idx - (dir ? 8:1); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5681 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5682 if( h->non_zero_count_cache[b_idx] != 0 || |
| 2449 | 5683 h->non_zero_count_cache[bn_idx] != 0 ) { |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5684 bS[i] = 2; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5685 } |
| 2523 | 5686 else |
| 5687 { | |
| 5688 /* FIXME: A given frame may occupy more than one position in | |
| 5689 * the reference list. So we should compare the frame numbers, | |
| 5690 * not the indices in the ref list. */ | |
| 5691 int l; | |
| 5692 bS[i] = 0; | |
| 5693 for( l = 0; l < 1 + (h->slice_type == B_TYPE); l++ ) { | |
| 5694 if( h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] || | |
| 5695 ABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 || | |
| 5696 ABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= 4 ) { | |
| 5697 bS[i] = 1; | |
| 5698 break; | |
| 5699 } | |
| 5700 } | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5701 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5702 } |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5703 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5704 if(bS[0]+bS[1]+bS[2]+bS[3] == 0) |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5705 continue; |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5706 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5707 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5708 /* Filter edge */ |
|
2504
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5709 // Do not use s->qscale as luma quantiser because it has not the same |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5710 // value in IPCM macroblocks. |
|
f12657081093
INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org)
michael
parents:
2498
diff
changeset
|
5711 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
5712 //tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]); |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5713 if( dir == 0 ) { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5714 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); |
| 1898 | 5715 if( (edge&1) == 0 ) { |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5716 int chroma_qp = ( h->chroma_qp + |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5717 get_chroma_qp( h, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5718 filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, chroma_qp ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5719 filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, chroma_qp ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5720 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5721 } else { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5722 filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp ); |
| 1898 | 5723 if( (edge&1) == 0 ) { |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5724 int chroma_qp = ( h->chroma_qp + |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5725 get_chroma_qp( h, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5726 filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, chroma_qp ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5727 filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, chroma_qp ); |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5728 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5729 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5730 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5731 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5732 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5733 |
| 1168 | 5734 static int decode_slice(H264Context *h){ |
| 5735 MpegEncContext * const s = &h->s; | |
| 5736 const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F; | |
| 5737 | |
| 5738 s->mb_skip_run= -1; | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5739 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5740 if( h->pps.cabac ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5741 int i; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5742 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5743 /* realign */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5744 align_get_bits( &s->gb ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5745 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5746 /* init cabac */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5747 ff_init_cabac_states( &h->cabac, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64 ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5748 ff_init_cabac_decoder( &h->cabac, |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5749 s->gb.buffer + get_bits_count(&s->gb)/8, |
| 2116 | 5750 ( s->gb.size_in_bits - get_bits_count(&s->gb) + 7)/8); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5751 /* calculate pre-state */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5752 for( i= 0; i < 399; i++ ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5753 int pre; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5754 if( h->slice_type == I_TYPE ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5755 pre = clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5756 else |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5757 pre = clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5758 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5759 if( pre <= 63 ) |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5760 h->cabac_state[i] = 2 * ( 63 - pre ) + 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5761 else |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5762 h->cabac_state[i] = 2 * ( pre - 64 ) + 1; |
| 1168 | 5763 } |
| 5764 | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5765 for(;;){ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5766 int ret = decode_mb_cabac(h); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5767 int eos = get_cabac_terminate( &h->cabac ); /* End of Slice flag */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5768 |
| 2163 | 5769 if(ret>=0) hl_decode_mb(h); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5770 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5771 /* XXX: useless as decode_mb_cabac it doesn't support that ... */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5772 if( ret >= 0 && h->sps.mb_aff ) { //FIXME optimal? or let mb_decode decode 16x32 ? |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5773 s->mb_y++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5774 |
| 2163 | 5775 if(ret>=0) ret = decode_mb_cabac(h); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5776 eos = get_cabac_terminate( &h->cabac ); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5777 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5778 hl_decode_mb(h); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5779 s->mb_y--; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5780 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5781 |
| 2116 | 5782 if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 1) { |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5783 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5784 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5785 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5786 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5787 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5788 if( ++s->mb_x >= s->mb_width ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5789 s->mb_x = 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5790 ff_draw_horiz_band(s, 16*s->mb_y, 16); |
| 2392 | 5791 ++s->mb_y; |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5792 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5793 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5794 if( eos || s->mb_y >= s->mb_height ) { |
| 2392 | 5795 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5796 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5797 return 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5798 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5799 #if 0 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5800 /* TODO test over-reading in cabac code */ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5801 else if( read too much in h->cabac ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5802 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5803 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5804 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5805 #endif |
| 1168 | 5806 } |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5807 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5808 } else { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5809 for(;;){ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5810 int ret = decode_mb_cavlc(h); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5811 |
| 2163 | 5812 if(ret>=0) hl_decode_mb(h); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5813 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5814 if(ret>=0 && h->sps.mb_aff){ //FIXME optimal? or let mb_decode decode 16x32 ? |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5815 s->mb_y++; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5816 ret = decode_mb_cavlc(h); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5817 |
| 2163 | 5818 if(ret>=0) hl_decode_mb(h); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5819 s->mb_y--; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5820 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5821 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5822 if(ret<0){ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5823 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5824 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5825 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5826 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5827 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5828 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5829 if(++s->mb_x >= s->mb_width){ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5830 s->mb_x=0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5831 ff_draw_horiz_band(s, 16*s->mb_y, 16); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5832 if(++s->mb_y >= s->mb_height){ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5833 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5834 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5835 if(get_bits_count(&s->gb) == s->gb.size_in_bits ) { |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5836 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5837 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5838 return 0; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5839 }else{ |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5840 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5841 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5842 return -1; |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5843 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5844 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5845 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5846 |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5847 if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){ |
| 2392 | 5848 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5849 if(get_bits_count(&s->gb) == s->gb.size_in_bits ){ |
| 1168 | 5850 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); |
| 5851 | |
| 5852 return 0; | |
| 5853 }else{ | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5854 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); |
| 1168 | 5855 |
| 5856 return -1; | |
| 5857 } | |
| 5858 } | |
| 5859 } | |
|
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5860 } |
|
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5861 |
| 1168 | 5862 #if 0 |
| 5863 for(;s->mb_y < s->mb_height; s->mb_y++){ | |
| 5864 for(;s->mb_x < s->mb_width; s->mb_x++){ | |
| 5865 int ret= decode_mb(h); | |
| 5866 | |
| 5867 hl_decode_mb(h); | |
| 5868 | |
| 5869 if(ret<0){ | |
| 5870 fprintf(stderr, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); | |
| 5871 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); | |
| 5872 | |
| 5873 return -1; | |
| 5874 } | |
| 5875 | |
| 5876 if(++s->mb_x >= s->mb_width){ | |
| 5877 s->mb_x=0; | |
| 5878 if(++s->mb_y >= s->mb_height){ | |
| 5879 if(get_bits_count(s->gb) == s->gb.size_in_bits){ | |
| 5880 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); | |
| 5881 | |
| 5882 return 0; | |
| 5883 }else{ | |
| 5884 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); | |
| 5885 | |
| 5886 return -1; | |
| 5887 } | |
| 5888 } | |
| 5889 } | |
| 5890 | |
| 5891 if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){ | |
| 5892 if(get_bits_count(s->gb) == s->gb.size_in_bits){ | |
| 5893 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); | |
| 5894 | |
| 5895 return 0; | |
| 5896 }else{ | |
| 5897 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); | |
| 5898 | |
| 5899 return -1; | |
| 5900 } | |
| 5901 } | |
| 5902 } | |
| 5903 s->mb_x=0; | |
| 5904 ff_draw_horiz_band(s, 16*s->mb_y, 16); | |
| 5905 } | |
| 5906 #endif | |
| 5907 return -1; //not reached | |
| 5908 } | |
| 5909 | |
| 5910 static inline int decode_vui_parameters(H264Context *h, SPS *sps){ | |
| 5911 MpegEncContext * const s = &h->s; | |
| 5912 int aspect_ratio_info_present_flag, aspect_ratio_idc; | |
| 5913 | |
| 5914 aspect_ratio_info_present_flag= get_bits1(&s->gb); | |
| 5915 | |
| 5916 if( aspect_ratio_info_present_flag ) { | |
| 5917 aspect_ratio_idc= get_bits(&s->gb, 8); | |
| 5918 if( aspect_ratio_idc == EXTENDED_SAR ) { | |
| 1548 | 5919 sps->sar.num= get_bits(&s->gb, 16); |
| 5920 sps->sar.den= get_bits(&s->gb, 16); | |
| 1168 | 5921 }else if(aspect_ratio_idc < 16){ |
| 1548 | 5922 sps->sar= pixel_aspect[aspect_ratio_idc]; |
| 1168 | 5923 }else{ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
5924 av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); |
| 1168 | 5925 return -1; |
| 5926 } | |
| 5927 }else{ | |
| 1548 | 5928 sps->sar.num= |
| 5929 sps->sar.den= 0; | |
| 1168 | 5930 } |
| 5931 // s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height); | |
|
2174
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5932 |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5933 if(get_bits1(&s->gb)){ /* overscan_info_present_flag */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5934 get_bits1(&s->gb); /* overscan_appropriate_flag */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5935 } |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5936 |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5937 if(get_bits1(&s->gb)){ /* video_signal_type_present_flag */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5938 get_bits(&s->gb, 3); /* video_format */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5939 get_bits1(&s->gb); /* video_full_range_flag */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5940 if(get_bits1(&s->gb)){ /* colour_description_present_flag */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5941 get_bits(&s->gb, 8); /* colour_primaries */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5942 get_bits(&s->gb, 8); /* transfer_characteristics */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5943 get_bits(&s->gb, 8); /* matrix_coefficients */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5944 } |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5945 } |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5946 |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5947 if(get_bits1(&s->gb)){ /* chroma_location_info_present_flag */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5948 get_ue_golomb(&s->gb); /* chroma_sample_location_type_top_field */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5949 get_ue_golomb(&s->gb); /* chroma_sample_location_type_bottom_field */ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5950 } |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5951 |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5952 sps->timing_info_present_flag = get_bits1(&s->gb); |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5953 if(sps->timing_info_present_flag){ |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5954 sps->num_units_in_tick = get_bits_long(&s->gb, 32); |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5955 sps->time_scale = get_bits_long(&s->gb, 32); |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5956 sps->fixed_frame_rate_flag = get_bits1(&s->gb); |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5957 } |
|
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (M?ns Rullg?rd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5958 |
| 1168 | 5959 #if 0 |
| 5960 | nal_hrd_parameters_present_flag |0 |u(1) | | |
| 5961 | if( nal_hrd_parameters_present_flag = = 1) | | | | |
| 5962 | hrd_parameters( ) | | | | |
| 5963 | vcl_hrd_parameters_present_flag |0 |u(1) | | |
| 5964 | if( vcl_hrd_parameters_present_flag = = 1) | | | | |
| 5965 | hrd_parameters( ) | | | | |
| 5966 | if( ( nal_hrd_parameters_present_flag = = 1 | || | | | |
| 5967 | | | | | |
| 5968 |( vcl_hrd_parameters_present_flag = = 1 ) ) | | | | |
| 5969 | low_delay_hrd_flag |0 |u(1) | | |
| 5970 | bitstream_restriction_flag |0 |u(1) | | |
| 5971 | if( bitstream_restriction_flag ) { |0 |u(1) | | |
| 5972 | motion_vectors_over_pic_boundaries_flag |0 |u(1) | | |
| 5973 | max_bytes_per_pic_denom |0 |ue(v) | | |
| 5974 | max_bits_per_mb_denom |0 |ue(v) | | |
| 5975 | log2_max_mv_length_horizontal |0 |ue(v) | | |
| 5976 | log2_max_mv_length_vertical |0 |ue(v) | | |
| 5977 | num_reorder_frames |0 |ue(v) | | |
| 5978 | max_dec_frame_buffering |0 |ue(v) | | |
| 5979 | } | | | | |
| 5980 |} | | | | |
| 5981 #endif | |
| 5982 return 0; | |
| 5983 } | |
| 5984 | |
| 5985 static inline int decode_seq_parameter_set(H264Context *h){ | |
| 5986 MpegEncContext * const s = &h->s; | |
| 1371 | 5987 int profile_idc, level_idc; |
| 1168 | 5988 int sps_id, i; |
| 5989 SPS *sps; | |
| 5990 | |
| 5991 profile_idc= get_bits(&s->gb, 8); | |
| 1371 | 5992 get_bits1(&s->gb); //constraint_set0_flag |
| 5993 get_bits1(&s->gb); //constraint_set1_flag | |
| 5994 get_bits1(&s->gb); //constraint_set2_flag | |
| 2312 | 5995 get_bits1(&s->gb); //constraint_set3_flag |
| 5996 get_bits(&s->gb, 4); // reserved | |
| 1168 | 5997 level_idc= get_bits(&s->gb, 8); |
| 5998 sps_id= get_ue_golomb(&s->gb); | |
| 5999 | |
| 6000 sps= &h->sps_buffer[ sps_id ]; | |
| 6001 sps->profile_idc= profile_idc; | |
| 6002 sps->level_idc= level_idc; | |
| 2312 | 6003 |
| 1168 | 6004 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; |
| 6005 sps->poc_type= get_ue_golomb(&s->gb); | |
| 6006 | |
| 6007 if(sps->poc_type == 0){ //FIXME #define | |
| 6008 sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4; | |
| 6009 } else if(sps->poc_type == 1){//FIXME #define | |
| 6010 sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); | |
| 6011 sps->offset_for_non_ref_pic= get_se_golomb(&s->gb); | |
| 6012 sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb); | |
| 6013 sps->poc_cycle_length= get_ue_golomb(&s->gb); | |
| 6014 | |
| 6015 for(i=0; i<sps->poc_cycle_length; i++) | |
| 6016 sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); | |
| 6017 } | |
| 6018 if(sps->poc_type > 2){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
6019 av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); |
| 1168 | 6020 return -1; |
| 6021 } | |
| 6022 | |
| 6023 sps->ref_frame_count= get_ue_golomb(&s->gb); | |
|
2254
0dfe4e32b19c
H.264 max reference pictures fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2227
diff
changeset
|
6024 if(sps->ref_frame_count > MAX_PICTURE_COUNT-2){ |
|
0dfe4e32b19c
H.264 max reference pictures fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2227
diff
changeset
|
6025 av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); |
|
0dfe4e32b19c
H.264 max reference pictures fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2227
diff
changeset
|
6026 } |
| 1371 | 6027 sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); |
| 1168 | 6028 sps->mb_width= get_ue_golomb(&s->gb) + 1; |
| 6029 sps->mb_height= get_ue_golomb(&s->gb) + 1; | |
| 2422 | 6030 if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 || |
| 6031 avcodec_check_dimensions(NULL, 16*sps->mb_width, 16*sps->mb_height)) | |
| 6032 return -1; | |
| 6033 | |
| 1168 | 6034 sps->frame_mbs_only_flag= get_bits1(&s->gb); |
| 6035 if(!sps->frame_mbs_only_flag) | |
| 6036 sps->mb_aff= get_bits1(&s->gb); | |
| 6037 else | |
| 6038 sps->mb_aff= 0; | |
| 6039 | |
| 6040 sps->direct_8x8_inference_flag= get_bits1(&s->gb); | |
| 6041 | |
| 1371 | 6042 sps->crop= get_bits1(&s->gb); |
| 6043 if(sps->crop){ | |
| 6044 sps->crop_left = get_ue_golomb(&s->gb); | |
| 6045 sps->crop_right = get_ue_golomb(&s->gb); | |
| 6046 sps->crop_top = get_ue_golomb(&s->gb); | |
| 6047 sps->crop_bottom= get_ue_golomb(&s->gb); | |
| 6048 if(sps->crop_left || sps->crop_top){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
6049 av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completly supported, this could look slightly wrong ...\n"); |
| 1371 | 6050 } |
| 6051 }else{ | |
| 6052 sps->crop_left = | |
| 6053 sps->crop_right = | |
| 6054 sps->crop_top = | |
| 6055 sps->crop_bottom= 0; | |
| 6056 } | |
| 6057 | |
| 1168 | 6058 sps->vui_parameters_present_flag= get_bits1(&s->gb); |
| 6059 if( sps->vui_parameters_present_flag ) | |
| 6060 decode_vui_parameters(h, sps); | |
| 6061 | |
| 6062 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
6063 av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%d profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s\n", |
| 1168 | 6064 sps_id, sps->profile_idc, sps->level_idc, |
| 6065 sps->poc_type, | |
| 6066 sps->ref_frame_count, | |
| 6067 sps->mb_width, sps->mb_height, | |
| 6068 sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"), | |
| 6069 sps->direct_8x8_inference_flag ? "8B8" : "", | |
| 1371 | 6070 sps->crop_left, sps->crop_right, |
| 6071 sps->crop_top, sps->crop_bottom, | |
| 1168 | 6072 sps->vui_parameters_present_flag ? "VUI" : "" |
| 6073 ); | |
| 6074 } | |
| 6075 return 0; | |
| 6076 } | |
| 6077 | |
| 6078 static inline int decode_picture_parameter_set(H264Context *h){ | |
| 6079 MpegEncContext * const s = &h->s; | |
| 6080 int pps_id= get_ue_golomb(&s->gb); | |
| 6081 PPS *pps= &h->pps_buffer[pps_id]; | |
| 6082 | |
| 6083 pps->sps_id= get_ue_golomb(&s->gb); | |
| 6084 pps->cabac= get_bits1(&s->gb); | |
| 6085 pps->pic_order_present= get_bits1(&s->gb); | |
| 6086 pps->slice_group_count= get_ue_golomb(&s->gb) + 1; | |
| 6087 if(pps->slice_group_count > 1 ){ | |
| 6088 pps->mb_slice_group_map_type= get_ue_golomb(&s->gb); | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
6089 av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); |
| 1168 | 6090 switch(pps->mb_slice_group_map_type){ |
| 6091 case 0: | |
| 6092 #if 0 | |
| 6093 | for( i = 0; i <= num_slice_groups_minus1; i++ ) | | | | |
| 6094 | run_length[ i ] |1 |ue(v) | | |
| 6095 #endif | |
| 6096 break; | |
| 6097 case 2: | |
| 6098 #if 0 | |
| 6099 | for( i = 0; i < num_slice_groups_minus1; i++ ) | | | | |
| 6100 |{ | | | | |
| 6101 | top_left_mb[ i ] |1 |ue(v) | | |
| 6102 | bottom_right_mb[ i ] |1 |ue(v) | | |
| 6103 | } | | | | |
| 6104 #endif | |
| 6105 break; | |
| 6106 case 3: | |
| 6107 case 4: | |
| 6108 case 5: | |
| 6109 #if 0 | |
| 6110 | slice_group_change_direction_flag |1 |u(1) | | |
| 6111 | slice_group_change_rate_minus1 |1 |ue(v) | | |
| 6112 #endif | |
| 6113 break; | |
| 6114 case 6: | |
| 6115 #if 0 | |
| 6116 | slice_group_id_cnt_minus1 |1 |ue(v) | | |
| 6117 | for( i = 0; i <= slice_group_id_cnt_minus1; i++ | | | | |
| 6118 |) | | | | |
| 6119 | slice_group_id[ i ] |1 |u(v) | | |
| 6120 #endif | |
| 1214 | 6121 break; |
| 1168 | 6122 } |
| 6123 } | |
| 6124 pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; | |
| 6125 pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; | |
| 6126 if(pps->ref_count[0] > 32 || pps->ref_count[1] > 32){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
6127 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); |
| 1168 | 6128 return -1; |
| 6129 } | |
| 6130 | |
| 6131 pps->weighted_pred= get_bits1(&s->gb); | |
| 6132 pps->weighted_bipred_idc= get_bits(&s->gb, 2); | |
| 6133 pps->init_qp= get_se_golomb(&s->gb) + 26; | |
| 6134 pps->init_qs= get_se_golomb(&s->gb) + 26; | |
| 6135 pps->chroma_qp_index_offset= get_se_golomb(&s->gb); | |
| 6136 pps->deblocking_filter_parameters_present= get_bits1(&s->gb); | |
| 6137 pps->constrained_intra_pred= get_bits1(&s->gb); | |
| 6138 pps->redundant_pic_cnt_present = get_bits1(&s->gb); | |
| 6139 | |
| 6140 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
6141 av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%d sps:%d %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d %s %s %s\n", |
| 1168 | 6142 pps_id, pps->sps_id, |
| 6143 pps->cabac ? "CABAC" : "CAVLC", | |
| 6144 pps->slice_group_count, | |
| 6145 pps->ref_count[0], pps->ref_count[1], | |
| 6146 pps->weighted_pred ? "weighted" : "", | |
| 6147 pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset, | |
| 6148 pps->deblocking_filter_parameters_present ? "LPAR" : "", | |
| 6149 pps->constrained_intra_pred ? "CONSTR" : "", | |
| 1371 | 6150 pps->redundant_pic_cnt_present ? "REDU" : "" |
| 1168 | 6151 ); |
| 6152 } | |
| 6153 | |
| 6154 return 0; | |
| 6155 } | |
| 6156 | |
| 6157 /** | |
| 6158 * finds the end of the current frame in the bitstream. | |
| 6159 * @return the position of the first byte of the next frame, or -1 | |
| 6160 */ | |
| 2392 | 6161 static int find_frame_end(H264Context *h, const uint8_t *buf, int buf_size){ |
| 1187 | 6162 int i; |
| 1168 | 6163 uint32_t state; |
| 2392 | 6164 ParseContext *pc = &(h->s.parse_context); |
| 1168 | 6165 //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); |
| 6166 // mb_addr= pc->mb_addr - 1; | |
| 6167 state= pc->state; | |
| 2392 | 6168 for(i=0; i<=buf_size; i++){ |
| 1168 | 6169 if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){ |
| 2392 | 6170 tprintf("find_frame_end new startcode = %08x, frame_start_found = %d, pos = %d\n", state, pc->frame_start_found, i); |
| 1168 | 6171 if(pc->frame_start_found){ |
| 2392 | 6172 // If there isn't one more byte in the buffer |
| 6173 // the test on first_mb_in_slice cannot be done yet | |
| 6174 // do it at next call. | |
| 6175 if (i >= buf_size) break; | |
| 6176 if (buf[i] & 0x80) { | |
| 6177 // first_mb_in_slice is 0, probably the first nal of a new | |
| 6178 // slice | |
| 6179 tprintf("find_frame_end frame_end_found, state = %08x, pos = %d\n", state, i); | |
| 6180 pc->state=-1; | |
| 6181 pc->frame_start_found= 0; | |
| 6182 return i-4; | |
| 6183 } | |
| 1168 | 6184 } |
| 2392 | 6185 pc->frame_start_found = 1; |
| 1168 | 6186 } |
| 2392 | 6187 if (i<buf_size) |
| 6188 state= (state<<8) | buf[i]; | |
| 1168 | 6189 } |
| 6190 | |
| 6191 pc->state= state; | |
| 1219 | 6192 return END_NOT_FOUND; |
| 1168 | 6193 } |
| 6194 | |
| 1988 | 6195 static int h264_parse(AVCodecParserContext *s, |
| 6196 AVCodecContext *avctx, | |
| 6197 uint8_t **poutbuf, int *poutbuf_size, | |
| 6198 const uint8_t *buf, int buf_size) | |
| 6199 { | |
| 2392 | 6200 H264Context *h = s->priv_data; |
| 6201 ParseContext *pc = &h->s.parse_context; | |
| 1988 | 6202 int next; |
| 6203 | |
| 2392 | 6204 next= find_frame_end(h, buf, buf_size); |
| 1988 | 6205 |
| 6206 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { | |
| 6207 *poutbuf = NULL; | |
| 6208 *poutbuf_size = 0; | |
| 6209 return buf_size; | |
| 6210 } | |
| 6211 | |
| 6212 *poutbuf = (uint8_t *)buf; | |
| 6213 *poutbuf_size = buf_size; | |
| 6214 return next; | |
| 6215 } | |
| 6216 | |
| 1168 | 6217 static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ |
| 6218 MpegEncContext * const s = &h->s; | |
| 6219 AVCodecContext * const avctx= s->avctx; | |
| 6220 int buf_index=0; | |
| 1322 | 6221 #if 0 |
| 1168 | 6222 int i; |
| 6223 for(i=0; i<32; i++){ | |
| 6224 printf("%X ", buf[i]); | |
| 6225 } | |
| 6226 #endif | |
| 2392 | 6227 h->slice_num = 0; |
| 1168 | 6228 for(;;){ |
| 6229 int consumed; | |
| 6230 int dst_length; | |
| 6231 int bit_length; | |
| 6232 uint8_t *ptr; | |
| 2227 | 6233 int i, nalsize = 0; |
| 1168 | 6234 |
| 2227 | 6235 if(h->is_avc) { |
| 6236 if(buf_index >= buf_size) break; | |
| 6237 nalsize = 0; | |
| 6238 for(i = 0; i < h->nal_length_size; i++) | |
| 6239 nalsize = (nalsize << 8) | buf[buf_index++]; | |
| 6240 } else { | |
| 1168 | 6241 // start code prefix search |
| 6242 for(; buf_index + 3 < buf_size; buf_index++){ | |
| 6243 // this should allways succeed in the first iteration | |
| 6244 if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1) | |
| 6245 break; | |
| 6246 } | |
| 6247 | |
| 6248 if(buf_index+3 >= buf_size) break; | |
| 6249 | |
| 6250 buf_index+=3; | |
| 2227 | 6251 } |
| 1168 | 6252 |
|
2401
46898a9fd6dc
Fix avc1 if there is nore than one nal per mov frame
rtognimp
parents:
2396
diff
changeset
|
6253 ptr= decode_nal(h, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index); |
| 1168 | 6254 if(ptr[dst_length - 1] == 0) dst_length--; |
| 6255 bit_length= 8*dst_length - decode_rbsp_trailing(ptr + dst_length - 1); | |
| 6256 | |
| 6257 if(s->avctx->debug&FF_DEBUG_STARTCODE){ | |
|
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
6258 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", h->nal_unit_type, buf_index, buf_size, dst_length); |
| 1168 | 6259 } |
| 6260 | |
| 2227 | 6261 if (h->is_avc && (nalsize != consumed)) |
| 6262 av_log(h->s.avctx, AV_LOG_ERROR, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize); | |
| 6263 | |
| 1168 | 6264 buf_index += consumed; |
| 6265 | |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
6266 if( s->hurry_up == 1 && h->nal_ref_idc == 0 ) |
| 1168 | 6267 continue; |
| 6268 | |
| 6269 switch(h->nal_unit_type){ | |
| 6270 case NAL_IDR_SLICE: | |
| 6271 idr(h); //FIXME ensure we dont loose some frames if there is reordering | |
| 6272 case NAL_SLICE: | |
| 6273 init_get_bits(&s->gb, ptr, bit_length); | |
| 6274 h->intra_gb_ptr= | |
| 6275 h->inter_gb_ptr= &s->gb; | |
| 6276 s->data_partitioning = 0; | |
| 6277 | |
| 6278 if(decode_slice_header(h) < 0) return -1; | |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
6279 if(h->redundant_pic_count==0 && s->hurry_up < 5 ) |
| 1168 | 6280 decode_slice(h); |
| 6281 break; | |
| 6282 case NAL_DPA: | |
| 6283 init_get_bits(&s->gb, ptr, bit_length); | |
| 6284 h->intra_gb_ptr= | |
| 6285 h->inter_gb_ptr= NULL; | |
| 6286 s->data_partitioning = 1; | |
| 6287 | |
| 6288 if(decode_slice_header(h) < 0) return -1; | |
| 6289 break; | |
| 6290 case NAL_DPB: | |
| 6291 init_get_bits(&h->intra_gb, ptr, bit_length); | |
| 6292 h->intra_gb_ptr= &h->intra_gb; | |
| 6293 break; | |
| 6294 case NAL_DPC: | |
| 6295 init_get_bits(&h->inter_gb, ptr, bit_length); | |
| 6296 h->inter_gb_ptr= &h->inter_gb; | |
| 1174 | 6297 |
|
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
6298 if(h->redundant_pic_count==0 && h->intra_gb_ptr && s->data_partitioning && s->hurry_up < 5 ) |
| 1168 | 6299 decode_slice(h); |
| 6300 break; | |
| 6301 case NAL_SEI: | |
| 6302 break; | |
| 6303 case NAL_SPS: | |
| 6304 init_get_bits(&s->gb, ptr, bit_length); | |
| 6305 decode_seq_parameter_set(h); | |
| 6306 | |
| 6307 if(s->flags& CODEC_FLAG_LOW_DELAY) | |
| 6308 s->low_delay=1; | |
| 6309 | |
| 2538 | 6310 if(avctx->has_b_frames < 2) |
| 6311 avctx->has_b_frames= !s->low_delay; | |
| 1168 | 6312 break; |
| 6313 case NAL_PPS: | |
| 6314 init_get_bits(&s->gb, ptr, bit_length); | |
| 6315 | |
| 6316 decode_picture_parameter_set(h); | |
| 6317 | |
| 6318 break; | |
| 6319 case NAL_PICTURE_DELIMITER: | |
| 6320 break; | |
| 6321 case NAL_FILTER_DATA: | |
| 6322 break; | |
| 2099 | 6323 default: |
| 6324 av_log(avctx, AV_LOG_ERROR, "Unknown NAL code: %d\n", h->nal_unit_type); | |
| 1168 | 6325 } |
| 6326 | |
| 6327 //FIXME move after where irt is set | |
| 6328 s->current_picture.pict_type= s->pict_type; | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6329 s->current_picture.key_frame= s->pict_type == I_TYPE && h->nal_unit_type == NAL_IDR_SLICE; |
| 1168 | 6330 } |
| 6331 | |
| 1174 | 6332 if(!s->current_picture_ptr) return buf_index; //no frame |
| 6333 | |
| 1168 | 6334 h->prev_frame_num_offset= h->frame_num_offset; |
| 6335 h->prev_frame_num= h->frame_num; | |
| 6336 if(s->current_picture_ptr->reference){ | |
| 6337 h->prev_poc_msb= h->poc_msb; | |
| 6338 h->prev_poc_lsb= h->poc_lsb; | |
| 6339 } | |
| 6340 if(s->current_picture_ptr->reference) | |
| 6341 execute_ref_pic_marking(h, h->mmco, h->mmco_index); | |
| 6342 | |
| 6343 ff_er_frame_end(s); | |
|
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
6344 |
| 1168 | 6345 MPV_frame_end(s); |
| 6346 | |
| 6347 return buf_index; | |
| 6348 } | |
| 6349 | |
| 6350 /** | |
| 6351 * retunrs the number of bytes consumed for building the current frame | |
| 6352 */ | |
| 6353 static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){ | |
| 6354 if(s->flags&CODEC_FLAG_TRUNCATED){ | |
| 6355 pos -= s->parse_context.last_index; | |
| 6356 if(pos<0) pos=0; // FIXME remove (uneeded?) | |
| 6357 | |
| 6358 return pos; | |
| 6359 }else{ | |
| 6360 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) | |
| 6361 if(pos+10>buf_size) pos=buf_size; // oops ;) | |
| 6362 | |
| 6363 return pos; | |
| 6364 } | |
| 6365 } | |
| 6366 | |
| 6367 static int decode_frame(AVCodecContext *avctx, | |
| 6368 void *data, int *data_size, | |
| 6369 uint8_t *buf, int buf_size) | |
| 6370 { | |
| 6371 H264Context *h = avctx->priv_data; | |
| 6372 MpegEncContext *s = &h->s; | |
| 6373 AVFrame *pict = data; | |
| 6374 int buf_index; | |
| 6375 | |
| 6376 s->flags= avctx->flags; | |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1706
diff
changeset
|
6377 s->flags2= avctx->flags2; |
| 1168 | 6378 |
| 6379 /* no supplementary picture */ | |
| 6380 if (buf_size == 0) { | |
| 6381 return 0; | |
| 6382 } | |
| 6383 | |
| 6384 if(s->flags&CODEC_FLAG_TRUNCATED){ | |
| 2392 | 6385 int next= find_frame_end(h, buf, buf_size); |
| 1168 | 6386 |
| 1988 | 6387 if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 ) |
| 1168 | 6388 return buf_size; |
| 6389 //printf("next:%d buf_size:%d last_index:%d\n", next, buf_size, s->parse_context.last_index); | |
| 6390 } | |
| 6391 | |
| 2227 | 6392 if(h->is_avc && !h->got_avcC) { |
| 6393 int i, cnt, nalsize; | |
| 6394 unsigned char *p = avctx->extradata; | |
| 6395 if(avctx->extradata_size < 7) { | |
| 6396 av_log(avctx, AV_LOG_ERROR, "avcC too short\n"); | |
| 6397 return -1; | |
| 6398 } | |
| 6399 if(*p != 1) { | |
| 6400 av_log(avctx, AV_LOG_ERROR, "Unknown avcC version %d\n", *p); | |
| 6401 return -1; | |
| 6402 } | |
| 6403 /* sps and pps in the avcC always have length coded with 2 bytes, | |
| 6404 so put a fake nal_length_size = 2 while parsing them */ | |
| 6405 h->nal_length_size = 2; | |
| 6406 // Decode sps from avcC | |
| 6407 cnt = *(p+5) & 0x1f; // Number of sps | |
| 6408 p += 6; | |
| 6409 for (i = 0; i < cnt; i++) { | |
| 6410 nalsize = BE_16(p) + 2; | |
| 6411 if(decode_nal_units(h, p, nalsize) != nalsize) { | |
| 6412 av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n", i); | |
| 6413 return -1; | |
| 6414 } | |
| 6415 p += nalsize; | |
| 6416 } | |
| 6417 // Decode pps from avcC | |
| 6418 cnt = *(p++); // Number of pps | |
| 6419 for (i = 0; i < cnt; i++) { | |
| 6420 nalsize = BE_16(p) + 2; | |
| 6421 if(decode_nal_units(h, p, nalsize) != nalsize) { | |
| 6422 av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n", i); | |
| 6423 return -1; | |
| 6424 } | |
| 6425 p += nalsize; | |
| 6426 } | |
| 6427 // Now store right nal length size, that will be use to parse all other nals | |
| 6428 h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1; | |
| 6429 // Do not reparse avcC | |
| 6430 h->got_avcC = 1; | |
| 6431 } | |
| 6432 | |
| 6433 if(!h->is_avc && s->avctx->extradata_size && s->picture_number==0){ | |
| 1168 | 6434 if(0 < decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) ) |
| 6435 return -1; | |
| 6436 } | |
| 6437 | |
| 6438 buf_index=decode_nal_units(h, buf, buf_size); | |
| 6439 if(buf_index < 0) | |
| 6440 return -1; | |
| 6441 | |
| 6442 //FIXME do something with unavailable reference frames | |
| 6443 | |
| 6444 // if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_index, buf_size); | |
| 1174 | 6445 if(!s->current_picture_ptr){ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
6446 av_log(h->s.avctx, AV_LOG_DEBUG, "error, NO frame\n"); |
| 1174 | 6447 return -1; |
| 6448 } | |
| 6449 | |
| 2409 | 6450 { |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
6451 //#define DECODE_ORDER |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
6452 Picture *out = s->current_picture_ptr; |
|
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
6453 #ifndef DECODE_ORDER |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6454 /* Sort B-frames into display order */ |
| 2409 | 6455 Picture *cur = s->current_picture_ptr; |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6456 int out_idx = 0; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6457 int pics = 0; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6458 int i; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6459 out = NULL; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6460 |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6461 while(h->delayed_pic[pics]) pics++; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6462 h->delayed_pic[pics++] = cur; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6463 out = h->delayed_pic[0]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6464 for(i=0; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame; i++) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6465 if(!out || h->delayed_pic[i]->poc < out->poc){ |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6466 out = h->delayed_pic[i]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6467 out_idx = i; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6468 } |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6469 if(cur->reference == 0) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6470 cur->reference = 1; |
| 2538 | 6471 for(i=0; h->delayed_pic[i]; i++) |
| 6472 if(h->delayed_pic[i]->key_frame) | |
| 6473 h->delayed_output_poc = -1; | |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6474 if(pics > FFMAX(1, s->avctx->has_b_frames)){ |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6475 if(out->reference == 1) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6476 out->reference = 0; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6477 for(i=out_idx; h->delayed_pic[i]; i++) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6478 h->delayed_pic[i] = h->delayed_pic[i+1]; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6479 } |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6480 |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6481 if((h->delayed_output_poc >=0 && h->delayed_output_poc > cur->poc) |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6482 || (s->low_delay && (cur->pict_type == B_TYPE |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6483 || (!h->sps.gaps_in_frame_num_allowed_flag |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6484 && cur->poc - out->poc > 2)))){ |
| 2409 | 6485 s->low_delay = 0; |
|
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6486 s->avctx->has_b_frames++; |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6487 } |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6488 |
|
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2536
diff
changeset
|
6489 h->delayed_output_poc = out->poc; |
|
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
6490 #endif |
| 2409 | 6491 |
| 6492 *pict= *(AVFrame*)out; | |
| 6493 } | |
| 6494 | |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1698
diff
changeset
|
6495 ff_print_debug_info(s, pict); |
| 1168 | 6496 assert(pict->data[0]); |
| 6497 //printf("out %d\n", (int)pict->data[0]); | |
| 6498 #if 0 //? | |
| 6499 | |
| 6500 /* Return the Picture timestamp as the frame number */ | |
| 6501 /* we substract 1 because it is added on utils.c */ | |
| 6502 avctx->frame_number = s->picture_number - 1; | |
| 6503 #endif | |
| 6504 #if 0 | |
| 6505 /* dont output the last pic after seeking */ | |
| 6506 if(s->last_picture_ptr || s->low_delay) | |
| 2392 | 6507 //Note this isnt a issue as a IDR pic should flush the buffers |
| 1168 | 6508 #endif |
| 6509 *data_size = sizeof(AVFrame); | |
| 6510 return get_consumed_bytes(s, buf_index, buf_size); | |
| 6511 } | |
| 6512 #if 0 | |
| 6513 static inline void fill_mb_avail(H264Context *h){ | |
| 6514 MpegEncContext * const s = &h->s; | |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
6515 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1168 | 6516 |
| 6517 if(s->mb_y){ | |
|
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
6518 h->mb_avail[0]= s->mb_x && h->slice_table[mb_xy - s->mb_stride - 1] == h->slice_num; |
|
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
6519 h->mb_avail[1]= h->slice_table[mb_xy - s->mb_stride ] == h->slice_num; |
|
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1174
diff
changeset
|
6520 h->mb_avail[2]= s->mb_x+1 < s->mb_width && h->slice_table[mb_xy - s->mb_stride + 1] == h->slice_num; |
| 1168 | 6521 }else{ |
| 6522 h->mb_avail[0]= | |
| 6523 h->mb_avail[1]= | |
| 6524 h->mb_avail[2]= 0; | |
| 6525 } | |
| 6526 h->mb_avail[3]= s->mb_x && h->slice_table[mb_xy - 1] == h->slice_num; | |
| 6527 h->mb_avail[4]= 1; //FIXME move out | |
| 6528 h->mb_avail[5]= 0; //FIXME move out | |
| 6529 } | |
| 6530 #endif | |
| 6531 | |
| 6532 #if 0 //selftest | |
| 6533 #define COUNT 8000 | |
| 6534 #define SIZE (COUNT*40) | |
| 6535 int main(){ | |
| 6536 int i; | |
| 6537 uint8_t temp[SIZE]; | |
| 6538 PutBitContext pb; | |
| 6539 GetBitContext gb; | |
| 6540 // int int_temp[10000]; | |
| 6541 DSPContext dsp; | |
| 6542 AVCodecContext avctx; | |
| 6543 | |
| 6544 dsputil_init(&dsp, &avctx); | |
| 6545 | |
|
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1453
diff
changeset
|
6546 init_put_bits(&pb, temp, SIZE); |
| 1168 | 6547 printf("testing unsigned exp golomb\n"); |
| 6548 for(i=0; i<COUNT; i++){ | |
| 6549 START_TIMER | |
| 6550 set_ue_golomb(&pb, i); | |
| 6551 STOP_TIMER("set_ue_golomb"); | |
| 6552 } | |
| 6553 flush_put_bits(&pb); | |
| 6554 | |
| 6555 init_get_bits(&gb, temp, 8*SIZE); | |
| 6556 for(i=0; i<COUNT; i++){ | |
| 6557 int j, s; | |
| 6558 | |
| 6559 s= show_bits(&gb, 24); | |
| 6560 | |
| 6561 START_TIMER | |
| 6562 j= get_ue_golomb(&gb); | |
| 6563 if(j != i){ | |
| 6564 printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); | |
| 6565 // return -1; | |
| 6566 } | |
| 6567 STOP_TIMER("get_ue_golomb"); | |
| 6568 } | |
| 6569 | |
| 6570 | |
| 1524 | 6571 init_put_bits(&pb, temp, SIZE); |
| 1168 | 6572 printf("testing signed exp golomb\n"); |
| 6573 for(i=0; i<COUNT; i++){ | |
| 6574 START_TIMER | |
| 6575 set_se_golomb(&pb, i - COUNT/2); | |
| 6576 STOP_TIMER("set_se_golomb"); | |
| 6577 } | |
| 6578 flush_put_bits(&pb); | |
| 6579 | |
| 6580 init_get_bits(&gb, temp, 8*SIZE); | |
| 6581 for(i=0; i<COUNT; i++){ | |
| 6582 int j, s; | |
| 6583 | |
| 6584 s= show_bits(&gb, 24); | |
| 6585 | |
| 6586 START_TIMER | |
| 6587 j= get_se_golomb(&gb); | |
| 6588 if(j != i - COUNT/2){ | |
| 6589 printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); | |
| 6590 // return -1; | |
| 6591 } | |
| 6592 STOP_TIMER("get_se_golomb"); | |
| 6593 } | |
| 6594 | |
| 6595 printf("testing 4x4 (I)DCT\n"); | |
| 6596 | |
| 6597 DCTELEM block[16]; | |
| 6598 uint8_t src[16], ref[16]; | |
| 6599 uint64_t error= 0, max_error=0; | |
| 6600 | |
| 6601 for(i=0; i<COUNT; i++){ | |
| 6602 int j; | |
| 6603 // printf("%d %d %d\n", r1, r2, (r2-r1)*16); | |
| 6604 for(j=0; j<16; j++){ | |
| 6605 ref[j]= random()%255; | |
| 6606 src[j]= random()%255; | |
| 6607 } | |
| 6608 | |
| 6609 h264_diff_dct_c(block, src, ref, 4); | |
| 6610 | |
| 6611 //normalize | |
| 6612 for(j=0; j<16; j++){ | |
| 6613 // printf("%d ", block[j]); | |
| 6614 block[j]= block[j]*4; | |
| 6615 if(j&1) block[j]= (block[j]*4 + 2)/5; | |
| 6616 if(j&4) block[j]= (block[j]*4 + 2)/5; | |
| 6617 } | |
| 6618 // printf("\n"); | |
| 6619 | |
|
2272
cd43603c46f9
move h264 idct to its own file and call via function pointer in DspContext
michael
parents:
2255
diff
changeset
|
6620 s->dsp.h264_idct_add(ref, block, 4); |
| 1168 | 6621 /* for(j=0; j<16; j++){ |
| 6622 printf("%d ", ref[j]); | |
| 6623 } | |
| 6624 printf("\n");*/ | |
| 6625 | |
| 6626 for(j=0; j<16; j++){ | |
| 6627 int diff= ABS(src[j] - ref[j]); | |
| 6628 | |
| 6629 error+= diff*diff; | |
| 6630 max_error= FFMAX(max_error, diff); | |
| 6631 } | |
| 6632 } | |
| 6633 printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error ); | |
| 6634 #if 0 | |
| 6635 printf("testing quantizer\n"); | |
| 6636 for(qp=0; qp<52; qp++){ | |
| 6637 for(i=0; i<16; i++) | |
| 6638 src1_block[i]= src2_block[i]= random()%255; | |
| 6639 | |
| 6640 } | |
| 6641 #endif | |
| 6642 printf("Testing NAL layer\n"); | |
| 6643 | |
| 6644 uint8_t bitstream[COUNT]; | |
| 6645 uint8_t nal[COUNT*2]; | |
| 6646 H264Context h; | |
| 6647 memset(&h, 0, sizeof(H264Context)); | |
| 6648 | |
| 6649 for(i=0; i<COUNT; i++){ | |
| 6650 int zeros= i; | |
| 6651 int nal_length; | |
| 6652 int consumed; | |
| 6653 int out_length; | |
| 6654 uint8_t *out; | |
| 6655 int j; | |
| 6656 | |
| 6657 for(j=0; j<COUNT; j++){ | |
| 6658 bitstream[j]= (random() % 255) + 1; | |
| 6659 } | |
| 6660 | |
| 6661 for(j=0; j<zeros; j++){ | |
| 6662 int pos= random() % COUNT; | |
| 6663 while(bitstream[pos] == 0){ | |
| 6664 pos++; | |
| 6665 pos %= COUNT; | |
| 6666 } | |
| 6667 bitstream[pos]=0; | |
| 6668 } | |
| 6669 | |
| 6670 START_TIMER | |
| 6671 | |
| 6672 nal_length= encode_nal(&h, nal, bitstream, COUNT, COUNT*2); | |
| 6673 if(nal_length<0){ | |
| 6674 printf("encoding failed\n"); | |
| 6675 return -1; | |
| 6676 } | |
| 6677 | |
| 6678 out= decode_nal(&h, nal, &out_length, &consumed, nal_length); | |
| 6679 | |
| 6680 STOP_TIMER("NAL") | |
| 6681 | |
| 6682 if(out_length != COUNT){ | |
| 6683 printf("incorrect length %d %d\n", out_length, COUNT); | |
| 6684 return -1; | |
| 6685 } | |
| 6686 | |
| 6687 if(consumed != nal_length){ | |
| 6688 printf("incorrect consumed length %d %d\n", nal_length, consumed); | |
| 6689 return -1; | |
| 6690 } | |
| 6691 | |
| 6692 if(memcmp(bitstream, out, COUNT)){ | |
| 6693 printf("missmatch\n"); | |
| 6694 return -1; | |
| 6695 } | |
| 6696 } | |
| 6697 | |
| 6698 printf("Testing RBSP\n"); | |
| 6699 | |
| 6700 | |
| 6701 return 0; | |
| 6702 } | |
| 6703 #endif | |
| 6704 | |
| 6705 | |
| 6706 static int decode_end(AVCodecContext *avctx) | |
| 6707 { | |
| 6708 H264Context *h = avctx->priv_data; | |
| 6709 MpegEncContext *s = &h->s; | |
| 6710 | |
| 6711 free_tables(h); //FIXME cleanup init stuff perhaps | |
| 6712 MPV_common_end(s); | |
| 6713 | |
| 6714 // memset(h, 0, sizeof(H264Context)); | |
| 6715 | |
| 6716 return 0; | |
| 6717 } | |
| 6718 | |
| 6719 | |
| 6720 AVCodec h264_decoder = { | |
| 6721 "h264", | |
| 6722 CODEC_TYPE_VIDEO, | |
| 6723 CODEC_ID_H264, | |
| 6724 sizeof(H264Context), | |
| 6725 decode_init, | |
| 6726 NULL, | |
| 6727 decode_end, | |
| 6728 decode_frame, | |
| 2453 | 6729 /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, |
| 1168 | 6730 }; |
| 6731 | |
| 1988 | 6732 AVCodecParser h264_parser = { |
| 6733 { CODEC_ID_H264 }, | |
| 2392 | 6734 sizeof(H264Context), |
| 1988 | 6735 NULL, |
| 6736 h264_parse, | |
| 6737 ff_parse_close, | |
| 6738 }; | |
| 6739 | |
| 1234 | 6740 #include "svq3.c" |
