Mercurial > libavcodec.hg
annotate h264.c @ 1899:379a18a7131f libavcodec
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
| author | michael |
|---|---|
| date | Sat, 20 Mar 2004 16:40:20 +0000 |
| parents | 7d2907127da3 |
| children | e20fd60b215c |
| 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 | |
| 34 #undef NDEBUG | |
| 35 #include <assert.h> | |
| 36 | |
| 37 #define interlaced_dct interlaced_dct_is_a_bad_name | |
| 38 #define mb_intra mb_intra_isnt_initalized_see_mb_type | |
| 39 | |
| 40 #define LUMA_DC_BLOCK_INDEX 25 | |
| 41 #define CHROMA_DC_BLOCK_INDEX 26 | |
| 42 | |
| 43 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8 | |
| 44 #define COEFF_TOKEN_VLC_BITS 8 | |
| 45 #define TOTAL_ZEROS_VLC_BITS 9 | |
| 46 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3 | |
| 47 #define RUN_VLC_BITS 3 | |
| 48 #define RUN7_VLC_BITS 6 | |
| 49 | |
| 50 #define MAX_SPS_COUNT 32 | |
| 51 #define MAX_PPS_COUNT 256 | |
| 52 | |
| 53 #define MAX_MMCO_COUNT 66 | |
| 54 | |
| 55 /** | |
| 56 * Sequence parameter set | |
| 57 */ | |
| 58 typedef struct SPS{ | |
| 59 | |
| 60 int profile_idc; | |
| 61 int level_idc; | |
| 62 int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4 | |
| 63 int poc_type; ///< pic_order_cnt_type | |
| 64 int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4 | |
| 65 int delta_pic_order_always_zero_flag; | |
| 66 int offset_for_non_ref_pic; | |
| 67 int offset_for_top_to_bottom_field; | |
| 68 int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle | |
| 69 int ref_frame_count; ///< num_ref_frames | |
| 1371 | 70 int gaps_in_frame_num_allowed_flag; |
| 1168 | 71 int mb_width; ///< frame_width_in_mbs_minus1 + 1 |
| 72 int mb_height; ///< frame_height_in_mbs_minus1 + 1 | |
| 73 int frame_mbs_only_flag; | |
| 74 int mb_aff; ///<mb_adaptive_frame_field_flag | |
| 75 int direct_8x8_inference_flag; | |
| 1371 | 76 int crop; ///< frame_cropping_flag |
| 77 int crop_left; ///< frame_cropping_rect_left_offset | |
| 78 int crop_right; ///< frame_cropping_rect_right_offset | |
| 79 int crop_top; ///< frame_cropping_rect_top_offset | |
| 80 int crop_bottom; ///< frame_cropping_rect_bottom_offset | |
| 1168 | 81 int vui_parameters_present_flag; |
| 1548 | 82 AVRational sar; |
| 1168 | 83 short offset_for_ref_frame[256]; //FIXME dyn aloc? |
| 84 }SPS; | |
| 85 | |
| 86 /** | |
| 87 * Picture parameter set | |
| 88 */ | |
| 89 typedef struct PPS{ | |
| 90 int sps_id; | |
| 91 int cabac; ///< entropy_coding_mode_flag | |
| 92 int pic_order_present; ///< pic_order_present_flag | |
| 93 int slice_group_count; ///< num_slice_groups_minus1 + 1 | |
| 94 int mb_slice_group_map_type; | |
| 95 int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1 | |
| 96 int weighted_pred; ///< weighted_pred_flag | |
| 97 int weighted_bipred_idc; | |
| 98 int init_qp; ///< pic_init_qp_minus26 + 26 | |
| 99 int init_qs; ///< pic_init_qs_minus26 + 26 | |
| 100 int chroma_qp_index_offset; | |
| 101 int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag | |
| 102 int constrained_intra_pred; ///< constrained_intra_pred_flag | |
| 103 int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag | |
| 104 }PPS; | |
| 105 | |
| 106 /** | |
| 107 * Memory management control operation opcode. | |
| 108 */ | |
| 109 typedef enum MMCOOpcode{ | |
| 110 MMCO_END=0, | |
| 111 MMCO_SHORT2UNUSED, | |
| 112 MMCO_LONG2UNUSED, | |
| 113 MMCO_SHORT2LONG, | |
| 114 MMCO_SET_MAX_LONG, | |
| 115 MMCO_RESET, | |
| 116 MMCO_LONG, | |
| 117 } MMCOOpcode; | |
| 118 | |
| 119 /** | |
| 120 * Memory management control operation. | |
| 121 */ | |
| 122 typedef struct MMCO{ | |
| 123 MMCOOpcode opcode; | |
| 124 int short_frame_num; | |
| 125 int long_index; | |
| 126 } MMCO; | |
| 127 | |
| 128 /** | |
| 129 * H264Context | |
| 130 */ | |
| 131 typedef struct H264Context{ | |
| 132 MpegEncContext s; | |
| 133 int nal_ref_idc; | |
| 134 int nal_unit_type; | |
| 135 #define NAL_SLICE 1 | |
| 136 #define NAL_DPA 2 | |
| 137 #define NAL_DPB 3 | |
| 138 #define NAL_DPC 4 | |
| 139 #define NAL_IDR_SLICE 5 | |
| 140 #define NAL_SEI 6 | |
| 141 #define NAL_SPS 7 | |
| 142 #define NAL_PPS 8 | |
| 143 #define NAL_PICTURE_DELIMITER 9 | |
| 144 #define NAL_FILTER_DATA 10 | |
| 145 uint8_t *rbsp_buffer; | |
| 146 int rbsp_buffer_size; | |
| 147 | |
| 148 int chroma_qp; //QPc | |
| 149 | |
| 150 int prev_mb_skiped; //FIXME remove (IMHO not used) | |
| 151 | |
| 152 //prediction stuff | |
| 153 int chroma_pred_mode; | |
| 154 int intra16x16_pred_mode; | |
| 155 | |
| 156 int8_t intra4x4_pred_mode_cache[5*8]; | |
| 157 int8_t (*intra4x4_pred_mode)[8]; | |
| 158 void (*pred4x4 [9+3])(uint8_t *src, uint8_t *topright, int stride);//FIXME move to dsp? | |
| 159 void (*pred8x8 [4+3])(uint8_t *src, int stride); | |
| 160 void (*pred16x16[4+3])(uint8_t *src, int stride); | |
| 161 unsigned int topleft_samples_available; | |
| 162 unsigned int top_samples_available; | |
| 163 unsigned int topright_samples_available; | |
| 164 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
|
165 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
|
166 uint8_t left_border[17+2*9]; |
| 1168 | 167 |
| 168 /** | |
| 169 * non zero coeff count cache. | |
| 170 * is 64 if not available. | |
| 171 */ | |
| 172 uint8_t non_zero_count_cache[6*8]; | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
173 uint8_t (*non_zero_count)[16]; |
| 1168 | 174 |
| 175 /** | |
| 176 * Motion vector cache. | |
| 177 */ | |
| 178 int16_t mv_cache[2][5*8][2]; | |
| 179 int8_t ref_cache[2][5*8]; | |
| 180 #define LIST_NOT_USED -1 //FIXME rename? | |
| 181 #define PART_NOT_AVAILABLE -2 | |
| 182 | |
| 183 /** | |
| 184 * is 1 if the specific list MV&references are set to 0,0,-2. | |
| 185 */ | |
| 186 int mv_cache_clean[2]; | |
| 187 | |
| 188 int block_offset[16+8]; | |
| 189 int chroma_subblock_offset[16]; //FIXME remove | |
| 190 | |
| 191 uint16_t *mb2b_xy; //FIXME are these 4 a good idea? | |
| 192 uint16_t *mb2b8_xy; | |
| 193 int b_stride; | |
| 194 int b8_stride; | |
| 195 | |
| 1234 | 196 int halfpel_flag; |
| 197 int thirdpel_flag; | |
| 198 | |
| 1319 | 199 int unknown_svq3_flag; |
| 200 int next_slice_index; | |
| 201 | |
| 1168 | 202 SPS sps_buffer[MAX_SPS_COUNT]; |
| 203 SPS sps; ///< current sps | |
| 204 | |
| 205 PPS pps_buffer[MAX_PPS_COUNT]; | |
| 206 /** | |
| 207 * current pps | |
| 208 */ | |
| 209 PPS pps; //FIXME move tp Picture perhaps? (->no) do we need that? | |
| 210 | |
| 211 int slice_num; | |
| 212 uint8_t *slice_table_base; | |
| 213 uint8_t *slice_table; ///< slice_table_base + mb_stride + 1 | |
| 214 int slice_type; | |
| 215 int slice_type_fixed; | |
| 216 | |
| 217 //interlacing specific flags | |
| 218 int mb_field_decoding_flag; | |
| 219 | |
| 220 int sub_mb_type[4]; | |
| 221 | |
| 222 //POC stuff | |
| 223 int poc_lsb; | |
| 224 int poc_msb; | |
| 225 int delta_poc_bottom; | |
| 226 int delta_poc[2]; | |
| 227 int frame_num; | |
| 228 int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0 | |
| 229 int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0 | |
| 230 int frame_num_offset; ///< for POC type 2 | |
| 231 int prev_frame_num_offset; ///< for POC type 2 | |
| 232 int prev_frame_num; ///< frame_num of the last pic for POC type 1/2 | |
| 233 | |
| 234 /** | |
| 235 * frame_num for frames or 2*frame_num for field pics. | |
| 236 */ | |
| 237 int curr_pic_num; | |
| 238 | |
| 239 /** | |
| 240 * max_frame_num or 2*max_frame_num for field pics. | |
| 241 */ | |
| 242 int max_pic_num; | |
| 243 | |
| 244 //Weighted pred stuff | |
| 245 int luma_log2_weight_denom; | |
| 246 int chroma_log2_weight_denom; | |
| 247 int luma_weight[2][16]; | |
| 248 int luma_offset[2][16]; | |
| 249 int chroma_weight[2][16][2]; | |
| 250 int chroma_offset[2][16][2]; | |
| 251 | |
| 252 //deblock | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
253 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
|
254 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
|
255 int slice_beta_offset; |
| 1168 | 256 |
| 257 int redundant_pic_count; | |
| 258 | |
| 259 int direct_spatial_mv_pred; | |
| 260 | |
| 261 /** | |
| 262 * num_ref_idx_l0/1_active_minus1 + 1 | |
| 263 */ | |
| 264 int ref_count[2];// FIXME split for AFF | |
| 265 Picture *short_ref[16]; | |
| 266 Picture *long_ref[16]; | |
| 267 Picture default_ref_list[2][32]; | |
| 268 Picture ref_list[2][32]; //FIXME size? | |
| 269 Picture field_ref_list[2][32]; //FIXME size? | |
| 270 | |
| 271 /** | |
| 272 * memory management control operations buffer. | |
| 273 */ | |
| 274 MMCO mmco[MAX_MMCO_COUNT]; | |
| 275 int mmco_index; | |
| 276 | |
| 277 int long_ref_count; ///< number of actual long term references | |
| 278 int short_ref_count; ///< number of actual short term references | |
| 279 | |
| 280 //data partitioning | |
| 281 GetBitContext intra_gb; | |
| 282 GetBitContext inter_gb; | |
| 283 GetBitContext *intra_gb_ptr; | |
| 284 GetBitContext *inter_gb_ptr; | |
| 285 | |
| 286 DCTELEM mb[16*24] __align8; | |
| 287 }H264Context; | |
| 288 | |
| 289 static VLC coeff_token_vlc[4]; | |
| 290 static VLC chroma_dc_coeff_token_vlc; | |
| 291 | |
| 292 static VLC total_zeros_vlc[15]; | |
| 293 static VLC chroma_dc_total_zeros_vlc[3]; | |
| 294 | |
| 295 static VLC run_vlc[6]; | |
| 296 static VLC run7_vlc; | |
| 297 | |
| 1234 | 298 static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp); |
| 299 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
|
300 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 | 301 |
| 1269 | 302 static inline uint32_t pack16to32(int a, int b){ |
| 303 #ifdef WORDS_BIGENDIAN | |
| 304 return (b&0xFFFF) + (a<<16); | |
| 305 #else | |
| 306 return (a&0xFFFF) + (b<<16); | |
| 307 #endif | |
| 308 } | |
| 309 | |
| 1168 | 310 /** |
| 311 * fill a rectangle. | |
| 312 * @param h height of the recatangle, should be a constant | |
| 313 * @param w width of the recatangle, should be a constant | |
| 314 * @param size the size of val (1 or 4), should be a constant | |
| 315 */ | |
| 1187 | 316 static inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){ //FIXME ensure this IS inlined |
| 317 uint8_t *p= (uint8_t*)vp; | |
| 1168 | 318 assert(size==1 || size==4); |
| 319 | |
| 320 w *= size; | |
| 321 stride *= size; | |
| 322 | |
| 323 //FIXME check what gcc generates for 64 bit on x86 and possible write a 32 bit ver of it | |
| 324 if(w==2 && h==2){ | |
| 325 *(uint16_t*)(p + 0)= | |
| 326 *(uint16_t*)(p + stride)= size==4 ? val : val*0x0101; | |
| 327 }else if(w==2 && h==4){ | |
| 328 *(uint16_t*)(p + 0*stride)= | |
| 329 *(uint16_t*)(p + 1*stride)= | |
| 330 *(uint16_t*)(p + 2*stride)= | |
| 331 *(uint16_t*)(p + 3*stride)= size==4 ? val : val*0x0101; | |
| 1252 | 332 }else if(w==4 && h==1){ |
| 333 *(uint32_t*)(p + 0*stride)= size==4 ? val : val*0x01010101; | |
| 1168 | 334 }else if(w==4 && h==2){ |
| 335 *(uint32_t*)(p + 0*stride)= | |
| 336 *(uint32_t*)(p + 1*stride)= size==4 ? val : val*0x01010101; | |
| 337 }else if(w==4 && h==4){ | |
| 338 *(uint32_t*)(p + 0*stride)= | |
| 339 *(uint32_t*)(p + 1*stride)= | |
| 340 *(uint32_t*)(p + 2*stride)= | |
| 341 *(uint32_t*)(p + 3*stride)= size==4 ? val : val*0x01010101; | |
| 342 }else if(w==8 && h==1){ | |
| 343 *(uint32_t*)(p + 0)= | |
| 344 *(uint32_t*)(p + 4)= size==4 ? val : val*0x01010101; | |
| 345 }else if(w==8 && h==2){ | |
| 346 *(uint32_t*)(p + 0 + 0*stride)= | |
| 347 *(uint32_t*)(p + 4 + 0*stride)= | |
| 348 *(uint32_t*)(p + 0 + 1*stride)= | |
| 349 *(uint32_t*)(p + 4 + 1*stride)= size==4 ? val : val*0x01010101; | |
| 350 }else if(w==8 && h==4){ | |
| 351 *(uint64_t*)(p + 0*stride)= | |
| 352 *(uint64_t*)(p + 1*stride)= | |
| 353 *(uint64_t*)(p + 2*stride)= | |
| 354 *(uint64_t*)(p + 3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
| 355 }else if(w==16 && h==2){ | |
| 356 *(uint64_t*)(p + 0+0*stride)= | |
| 357 *(uint64_t*)(p + 8+0*stride)= | |
| 358 *(uint64_t*)(p + 0+1*stride)= | |
| 359 *(uint64_t*)(p + 8+1*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
| 360 }else if(w==16 && h==4){ | |
| 361 *(uint64_t*)(p + 0+0*stride)= | |
| 362 *(uint64_t*)(p + 8+0*stride)= | |
| 363 *(uint64_t*)(p + 0+1*stride)= | |
| 364 *(uint64_t*)(p + 8+1*stride)= | |
| 365 *(uint64_t*)(p + 0+2*stride)= | |
| 366 *(uint64_t*)(p + 8+2*stride)= | |
| 367 *(uint64_t*)(p + 0+3*stride)= | |
| 368 *(uint64_t*)(p + 8+3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
| 369 }else | |
| 370 assert(0); | |
| 371 } | |
| 372 | |
| 373 static inline void fill_caches(H264Context *h, int mb_type){ | |
| 374 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
|
375 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1168 | 376 int topleft_xy, top_xy, topright_xy, left_xy[2]; |
| 377 int topleft_type, top_type, topright_type, left_type[2]; | |
| 378 int left_block[4]; | |
| 379 int i; | |
| 380 | |
| 381 //wow what a mess, why didnt they simplify the interlacing&intra stuff, i cant imagine that these complex rules are worth it | |
| 382 | |
| 383 if(h->sps.mb_aff){ | |
| 384 //FIXME | |
| 1453 | 385 topleft_xy = 0; /* avoid warning */ |
| 386 top_xy = 0; /* avoid warning */ | |
| 387 topright_xy = 0; /* avoid warning */ | |
| 1168 | 388 }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
|
389 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
|
390 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
|
391 topright_xy= mb_xy+1 - s->mb_stride; |
| 1168 | 392 left_xy[0] = mb_xy-1; |
| 393 left_xy[1] = mb_xy-1; | |
| 394 left_block[0]= 0; | |
| 395 left_block[1]= 1; | |
| 396 left_block[2]= 2; | |
| 397 left_block[3]= 3; | |
| 398 } | |
| 399 | |
| 400 topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0; | |
| 401 top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0; | |
| 402 topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0; | |
| 403 left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0; | |
| 404 left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0; | |
| 405 | |
| 406 if(IS_INTRA(mb_type)){ | |
| 407 h->topleft_samples_available= | |
| 408 h->top_samples_available= | |
| 409 h->left_samples_available= 0xFFFF; | |
| 410 h->topright_samples_available= 0xEEEA; | |
| 411 | |
| 412 if(!IS_INTRA(top_type) && (top_type==0 || h->pps.constrained_intra_pred)){ | |
| 413 h->topleft_samples_available= 0xB3FF; | |
| 414 h->top_samples_available= 0x33FF; | |
| 415 h->topright_samples_available= 0x26EA; | |
| 416 } | |
| 417 for(i=0; i<2; i++){ | |
| 418 if(!IS_INTRA(left_type[i]) && (left_type[i]==0 || h->pps.constrained_intra_pred)){ | |
| 419 h->topleft_samples_available&= 0xDF5F; | |
| 420 h->left_samples_available&= 0x5F5F; | |
| 421 } | |
| 422 } | |
| 423 | |
| 424 if(!IS_INTRA(topleft_type) && (topleft_type==0 || h->pps.constrained_intra_pred)) | |
| 425 h->topleft_samples_available&= 0x7FFF; | |
| 426 | |
| 427 if(!IS_INTRA(topright_type) && (topright_type==0 || h->pps.constrained_intra_pred)) | |
| 428 h->topright_samples_available&= 0xFBFF; | |
| 429 | |
| 430 if(IS_INTRA4x4(mb_type)){ | |
| 431 if(IS_INTRA4x4(top_type)){ | |
| 432 h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4]; | |
| 433 h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5]; | |
| 434 h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6]; | |
| 435 h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3]; | |
| 436 }else{ | |
| 437 int pred; | |
| 438 if(IS_INTRA16x16(top_type) || (IS_INTER(top_type) && !h->pps.constrained_intra_pred)) | |
| 439 pred= 2; | |
| 440 else{ | |
| 441 pred= -1; | |
| 442 } | |
| 443 h->intra4x4_pred_mode_cache[4+8*0]= | |
| 444 h->intra4x4_pred_mode_cache[5+8*0]= | |
| 445 h->intra4x4_pred_mode_cache[6+8*0]= | |
| 446 h->intra4x4_pred_mode_cache[7+8*0]= pred; | |
| 447 } | |
| 448 for(i=0; i<2; i++){ | |
| 449 if(IS_INTRA4x4(left_type[i])){ | |
| 450 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]]; | |
| 451 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]]; | |
| 452 }else{ | |
| 453 int pred; | |
| 454 if(IS_INTRA16x16(left_type[i]) || (IS_INTER(left_type[i]) && !h->pps.constrained_intra_pred)) | |
| 455 pred= 2; | |
| 456 else{ | |
| 457 pred= -1; | |
| 458 } | |
| 459 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= | |
| 460 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred; | |
| 461 } | |
| 462 } | |
| 463 } | |
| 464 } | |
| 465 | |
| 466 | |
| 467 /* | |
| 468 0 . T T. T T T T | |
| 469 1 L . .L . . . . | |
| 470 2 L . .L . . . . | |
| 471 3 . T TL . . . . | |
| 472 4 L . .L . . . . | |
| 473 5 L . .. . . . . | |
| 474 */ | |
| 475 //FIXME constraint_intra_pred & partitioning & nnz (lets hope this is just a typo in the spec) | |
| 476 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
|
477 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
|
478 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
|
479 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
|
480 h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3]; |
| 1168 | 481 |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
482 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
|
483 h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8]; |
| 1168 | 484 |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
485 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
|
486 h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11]; |
| 1168 | 487 }else{ |
| 488 h->non_zero_count_cache[4+8*0]= | |
| 489 h->non_zero_count_cache[5+8*0]= | |
| 490 h->non_zero_count_cache[6+8*0]= | |
| 491 h->non_zero_count_cache[7+8*0]= | |
| 492 | |
| 493 h->non_zero_count_cache[1+8*0]= | |
| 494 h->non_zero_count_cache[2+8*0]= | |
| 495 | |
| 496 h->non_zero_count_cache[1+8*3]= | |
| 497 h->non_zero_count_cache[2+8*3]= 64; | |
| 498 } | |
| 499 | |
| 500 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
|
501 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
|
502 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
|
503 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
|
504 h->non_zero_count_cache[0+8*4]= h->non_zero_count[left_xy[0]][12]; |
| 1168 | 505 }else{ |
| 506 h->non_zero_count_cache[3+8*1]= | |
| 507 h->non_zero_count_cache[3+8*2]= | |
| 508 h->non_zero_count_cache[0+8*1]= | |
| 509 h->non_zero_count_cache[0+8*4]= 64; | |
| 510 } | |
| 511 | |
| 512 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
|
513 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
|
514 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
|
515 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
|
516 h->non_zero_count_cache[0+8*5]= h->non_zero_count[left_xy[1]][11]; |
| 1168 | 517 }else{ |
| 518 h->non_zero_count_cache[3+8*3]= | |
| 519 h->non_zero_count_cache[3+8*4]= | |
| 520 h->non_zero_count_cache[0+8*2]= | |
| 521 h->non_zero_count_cache[0+8*5]= 64; | |
| 522 } | |
| 523 | |
| 524 #if 1 | |
| 525 if(IS_INTER(mb_type)){ | |
| 526 int list; | |
| 527 for(list=0; list<2; list++){ | |
| 528 if((!IS_8X8(mb_type)) && !USES_LIST(mb_type, list)){ | |
| 529 /*if(!h->mv_cache_clean[list]){ | |
| 530 memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? | |
| 531 memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); | |
| 532 h->mv_cache_clean[list]= 1; | |
| 533 }*/ | |
| 534 continue; //FIXME direct mode ... | |
| 535 } | |
| 536 h->mv_cache_clean[list]= 0; | |
| 537 | |
| 538 if(IS_INTER(topleft_type)){ | |
| 539 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride; | |
| 540 const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + h->b8_stride; | |
| 541 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; | |
| 542 h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; | |
| 543 }else{ | |
| 544 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= 0; | |
| 545 h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
| 546 } | |
| 547 | |
| 548 if(IS_INTER(top_type)){ | |
| 549 const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; | |
| 550 const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride; | |
| 551 *(uint32_t*)h->mv_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 0]; | |
| 552 *(uint32_t*)h->mv_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 1]; | |
| 553 *(uint32_t*)h->mv_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 2]; | |
| 554 *(uint32_t*)h->mv_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 3]; | |
| 555 h->ref_cache[list][scan8[0] + 0 - 1*8]= | |
| 556 h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0]; | |
| 557 h->ref_cache[list][scan8[0] + 2 - 1*8]= | |
| 558 h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1]; | |
| 559 }else{ | |
| 560 *(uint32_t*)h->mv_cache [list][scan8[0] + 0 - 1*8]= | |
| 561 *(uint32_t*)h->mv_cache [list][scan8[0] + 1 - 1*8]= | |
| 562 *(uint32_t*)h->mv_cache [list][scan8[0] + 2 - 1*8]= | |
| 563 *(uint32_t*)h->mv_cache [list][scan8[0] + 3 - 1*8]= 0; | |
| 564 *(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101; | |
| 565 } | |
| 566 | |
| 567 if(IS_INTER(topright_type)){ | |
| 568 const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; | |
| 569 const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride; | |
| 570 *(uint32_t*)h->mv_cache[list][scan8[0] + 4 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; | |
| 571 h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy]; | |
| 572 }else{ | |
| 573 *(uint32_t*)h->mv_cache [list][scan8[0] + 4 - 1*8]= 0; | |
| 574 h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
| 575 } | |
| 576 | |
| 577 //FIXME unify cleanup or sth | |
| 578 if(IS_INTER(left_type[0])){ | |
| 579 const int b_xy= h->mb2b_xy[left_xy[0]] + 3; | |
| 580 const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1; | |
| 581 *(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]]; | |
| 582 *(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]]; | |
| 583 h->ref_cache[list][scan8[0] - 1 + 0*8]= | |
| 584 h->ref_cache[list][scan8[0] - 1 + 1*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0]>>1)]; | |
| 585 }else{ | |
| 586 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0*8]= | |
| 587 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 1*8]= 0; | |
| 588 h->ref_cache[list][scan8[0] - 1 + 0*8]= | |
| 589 h->ref_cache[list][scan8[0] - 1 + 1*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
| 590 } | |
| 591 | |
| 592 if(IS_INTER(left_type[1])){ | |
| 593 const int b_xy= h->mb2b_xy[left_xy[1]] + 3; | |
| 594 const int b8_xy= h->mb2b8_xy[left_xy[1]] + 1; | |
| 595 *(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]]; | |
| 596 *(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]]; | |
| 597 h->ref_cache[list][scan8[0] - 1 + 2*8]= | |
| 598 h->ref_cache[list][scan8[0] - 1 + 3*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[2]>>1)]; | |
| 599 }else{ | |
| 600 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 2*8]= | |
| 601 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 3*8]= 0; | |
| 602 h->ref_cache[list][scan8[0] - 1 + 2*8]= | |
| 603 h->ref_cache[list][scan8[0] - 1 + 3*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
| 604 } | |
| 605 | |
| 606 h->ref_cache[list][scan8[5 ]+1] = | |
| 607 h->ref_cache[list][scan8[7 ]+1] = | |
| 608 h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewher else) | |
| 609 h->ref_cache[list][scan8[4 ]] = | |
| 610 h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; | |
| 611 *(uint32_t*)h->mv_cache [list][scan8[5 ]+1]= | |
| 612 *(uint32_t*)h->mv_cache [list][scan8[7 ]+1]= | |
| 613 *(uint32_t*)h->mv_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) | |
| 614 *(uint32_t*)h->mv_cache [list][scan8[4 ]]= | |
| 615 *(uint32_t*)h->mv_cache [list][scan8[12]]= 0; | |
| 616 } | |
| 617 //FIXME | |
| 618 | |
| 619 } | |
| 620 #endif | |
| 621 } | |
| 622 | |
| 623 static inline void write_back_intra_pred_mode(H264Context *h){ | |
| 624 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
|
625 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1168 | 626 |
| 627 h->intra4x4_pred_mode[mb_xy][0]= h->intra4x4_pred_mode_cache[7+8*1]; | |
| 628 h->intra4x4_pred_mode[mb_xy][1]= h->intra4x4_pred_mode_cache[7+8*2]; | |
| 629 h->intra4x4_pred_mode[mb_xy][2]= h->intra4x4_pred_mode_cache[7+8*3]; | |
| 630 h->intra4x4_pred_mode[mb_xy][3]= h->intra4x4_pred_mode_cache[7+8*4]; | |
| 631 h->intra4x4_pred_mode[mb_xy][4]= h->intra4x4_pred_mode_cache[4+8*4]; | |
| 632 h->intra4x4_pred_mode[mb_xy][5]= h->intra4x4_pred_mode_cache[5+8*4]; | |
| 633 h->intra4x4_pred_mode[mb_xy][6]= h->intra4x4_pred_mode_cache[6+8*4]; | |
| 634 } | |
| 635 | |
| 636 /** | |
| 637 * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. | |
| 638 */ | |
| 639 static inline int check_intra4x4_pred_mode(H264Context *h){ | |
| 640 MpegEncContext * const s = &h->s; | |
| 641 static const int8_t top [12]= {-1, 0,LEFT_DC_PRED,-1,-1,-1,-1,-1, 0}; | |
| 642 static const int8_t left[12]= { 0,-1, TOP_DC_PRED, 0,-1,-1,-1, 0,-1,DC_128_PRED}; | |
| 643 int i; | |
| 644 | |
| 645 if(!(h->top_samples_available&0x8000)){ | |
| 646 for(i=0; i<4; i++){ | |
| 647 int status= top[ h->intra4x4_pred_mode_cache[scan8[0] + i] ]; | |
| 648 if(status<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
649 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 | 650 return -1; |
| 651 } else if(status){ | |
| 652 h->intra4x4_pred_mode_cache[scan8[0] + i]= status; | |
| 653 } | |
| 654 } | |
| 655 } | |
| 656 | |
| 657 if(!(h->left_samples_available&0x8000)){ | |
| 658 for(i=0; i<4; i++){ | |
| 659 int status= left[ h->intra4x4_pred_mode_cache[scan8[0] + 8*i] ]; | |
| 660 if(status<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
661 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 | 662 return -1; |
| 663 } else if(status){ | |
| 664 h->intra4x4_pred_mode_cache[scan8[0] + 8*i]= status; | |
| 665 } | |
| 666 } | |
| 667 } | |
| 668 | |
| 669 return 0; | |
| 670 } //FIXME cleanup like next | |
| 671 | |
| 672 /** | |
| 673 * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. | |
| 674 */ | |
| 675 static inline int check_intra_pred_mode(H264Context *h, int mode){ | |
| 676 MpegEncContext * const s = &h->s; | |
| 677 static const int8_t top [7]= {LEFT_DC_PRED8x8, 1,-1,-1}; | |
| 678 static const int8_t left[7]= { TOP_DC_PRED8x8,-1, 2,-1,DC_128_PRED8x8}; | |
| 679 | |
| 680 if(!(h->top_samples_available&0x8000)){ | |
| 681 mode= top[ mode ]; | |
| 682 if(mode<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
683 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 | 684 return -1; |
| 685 } | |
| 686 } | |
| 687 | |
| 688 if(!(h->left_samples_available&0x8000)){ | |
| 689 mode= left[ mode ]; | |
| 690 if(mode<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
691 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 | 692 return -1; |
| 693 } | |
| 694 } | |
| 695 | |
| 696 return mode; | |
| 697 } | |
| 698 | |
| 699 /** | |
| 700 * gets the predicted intra4x4 prediction mode. | |
| 701 */ | |
| 702 static inline int pred_intra_mode(H264Context *h, int n){ | |
| 703 const int index8= scan8[n]; | |
| 704 const int left= h->intra4x4_pred_mode_cache[index8 - 1]; | |
| 705 const int top = h->intra4x4_pred_mode_cache[index8 - 8]; | |
| 706 const int min= FFMIN(left, top); | |
| 707 | |
| 1170 | 708 tprintf("mode:%d %d min:%d\n", left ,top, min); |
| 1168 | 709 |
| 710 if(min<0) return DC_PRED; | |
| 711 else return min; | |
| 712 } | |
| 713 | |
| 714 static inline void write_back_non_zero_count(H264Context *h){ | |
| 715 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
|
716 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
|
717 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
718 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
|
719 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
|
720 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
|
721 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
|
722 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
|
723 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
|
724 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
|
725 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
726 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
|
727 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
|
728 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
|
729 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
730 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
|
731 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
|
732 h->non_zero_count[mb_xy][12]=h->non_zero_count_cache[2+8*4]; |
| 1168 | 733 } |
| 734 | |
| 735 /** | |
| 736 * gets the predicted number of non zero coefficients. | |
| 737 * @param n block index | |
| 738 */ | |
| 739 static inline int pred_non_zero_count(H264Context *h, int n){ | |
| 740 const int index8= scan8[n]; | |
| 741 const int left= h->non_zero_count_cache[index8 - 1]; | |
| 742 const int top = h->non_zero_count_cache[index8 - 8]; | |
| 743 int i= left + top; | |
| 744 | |
| 745 if(i<64) i= (i+1)>>1; | |
| 746 | |
| 1170 | 747 tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); |
| 1168 | 748 |
| 749 return i&31; | |
| 750 } | |
| 751 | |
| 1169 | 752 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ |
| 753 const int topright_ref= h->ref_cache[list][ i - 8 + part_width ]; | |
| 754 | |
| 755 if(topright_ref != PART_NOT_AVAILABLE){ | |
| 756 *C= h->mv_cache[list][ i - 8 + part_width ]; | |
| 757 return topright_ref; | |
| 758 }else{ | |
| 1170 | 759 tprintf("topright MV not available\n"); |
| 760 | |
| 1169 | 761 *C= h->mv_cache[list][ i - 8 - 1 ]; |
| 762 return h->ref_cache[list][ i - 8 - 1 ]; | |
| 763 } | |
| 764 } | |
| 765 | |
| 1168 | 766 /** |
| 767 * gets the predicted MV. | |
| 768 * @param n the block index | |
| 769 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) | |
| 770 * @param mx the x component of the predicted motion vector | |
| 771 * @param my the y component of the predicted motion vector | |
| 772 */ | |
| 773 static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){ | |
| 774 const int index8= scan8[n]; | |
| 775 const int top_ref= h->ref_cache[list][ index8 - 8 ]; | |
| 776 const int left_ref= h->ref_cache[list][ index8 - 1 ]; | |
| 777 const int16_t * const A= h->mv_cache[list][ index8 - 1 ]; | |
| 778 const int16_t * const B= h->mv_cache[list][ index8 - 8 ]; | |
| 1169 | 779 const int16_t * C; |
| 780 int diagonal_ref, match_count; | |
| 781 | |
| 1168 | 782 assert(part_width==1 || part_width==2 || part_width==4); |
| 1169 | 783 |
| 1168 | 784 /* mv_cache |
| 785 B . . A T T T T | |
| 786 U . . L . . , . | |
| 787 U . . L . . . . | |
| 788 U . . L . . , . | |
| 789 . . . L . . . . | |
| 790 */ | |
| 1169 | 791 |
| 792 diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); | |
| 793 match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); | |
| 794 if(match_count > 1){ //most common | |
| 795 *mx= mid_pred(A[0], B[0], C[0]); | |
| 796 *my= mid_pred(A[1], B[1], C[1]); | |
| 797 }else if(match_count==1){ | |
| 798 if(left_ref==ref){ | |
| 799 *mx= A[0]; | |
| 800 *my= A[1]; | |
| 801 }else if(top_ref==ref){ | |
| 802 *mx= B[0]; | |
| 803 *my= B[1]; | |
| 804 }else{ | |
| 805 *mx= C[0]; | |
| 806 *my= C[1]; | |
| 807 } | |
| 808 }else{ | |
| 809 if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ | |
| 810 *mx= A[0]; | |
| 811 *my= A[1]; | |
| 1168 | 812 }else{ |
| 813 *mx= mid_pred(A[0], B[0], C[0]); | |
| 814 *my= mid_pred(A[1], B[1], C[1]); | |
| 815 } | |
| 1169 | 816 } |
| 1168 | 817 |
| 1187 | 818 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 | 819 } |
| 820 | |
| 821 /** | |
| 822 * gets the directionally predicted 16x8 MV. | |
| 823 * @param n the block index | |
| 824 * @param mx the x component of the predicted motion vector | |
| 825 * @param my the y component of the predicted motion vector | |
| 826 */ | |
| 827 static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ | |
| 828 if(n==0){ | |
| 829 const int top_ref= h->ref_cache[list][ scan8[0] - 8 ]; | |
| 830 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; | |
| 831 | |
| 1187 | 832 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 833 |
| 834 if(top_ref == ref){ | |
| 835 *mx= B[0]; | |
| 836 *my= B[1]; | |
| 837 return; | |
| 838 } | |
| 839 }else{ | |
| 840 const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; | |
| 841 const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; | |
| 842 | |
| 1187 | 843 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 844 |
| 845 if(left_ref == ref){ | |
| 846 *mx= A[0]; | |
| 847 *my= A[1]; | |
| 848 return; | |
| 849 } | |
| 850 } | |
| 851 | |
| 852 //RARE | |
| 853 pred_motion(h, n, 4, list, ref, mx, my); | |
| 854 } | |
| 855 | |
| 856 /** | |
| 857 * gets the directionally predicted 8x16 MV. | |
| 858 * @param n the block index | |
| 859 * @param mx the x component of the predicted motion vector | |
| 860 * @param my the y component of the predicted motion vector | |
| 861 */ | |
| 862 static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ | |
| 863 if(n==0){ | |
| 864 const int left_ref= h->ref_cache[list][ scan8[0] - 1 ]; | |
| 865 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; | |
| 866 | |
| 1187 | 867 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 868 |
| 869 if(left_ref == ref){ | |
| 870 *mx= A[0]; | |
| 871 *my= A[1]; | |
| 872 return; | |
| 873 } | |
| 874 }else{ | |
| 1169 | 875 const int16_t * C; |
| 876 int diagonal_ref; | |
| 877 | |
| 878 diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); | |
| 1168 | 879 |
| 1187 | 880 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); |
| 1168 | 881 |
| 1169 | 882 if(diagonal_ref == ref){ |
| 1168 | 883 *mx= C[0]; |
| 884 *my= C[1]; | |
| 885 return; | |
| 886 } | |
| 887 } | |
| 888 | |
| 889 //RARE | |
| 890 pred_motion(h, n, 2, list, ref, mx, my); | |
| 891 } | |
| 892 | |
| 893 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){ | |
| 894 const int top_ref = h->ref_cache[0][ scan8[0] - 8 ]; | |
| 895 const int left_ref= h->ref_cache[0][ scan8[0] - 1 ]; | |
| 896 | |
| 1187 | 897 tprintf("pred_pskip: (%d) (%d) at %2d %2d", top_ref, left_ref, h->s.mb_x, h->s.mb_y); |
| 1168 | 898 |
| 899 if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE | |
| 900 || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0) | |
| 901 || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){ | |
| 902 | |
| 903 *mx = *my = 0; | |
| 904 return; | |
| 905 } | |
| 906 | |
| 907 pred_motion(h, 0, 4, 0, 0, mx, my); | |
| 908 | |
| 909 return; | |
| 910 } | |
| 911 | |
| 912 static inline void write_back_motion(H264Context *h, int mb_type){ | |
| 913 MpegEncContext * const s = &h->s; | |
| 914 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; | |
| 915 const int b8_xy= 2*s->mb_x + 2*s->mb_y*h->b8_stride; | |
| 916 int list; | |
| 917 | |
| 918 for(list=0; list<2; list++){ | |
| 919 int y; | |
| 920 if((!IS_8X8(mb_type)) && !USES_LIST(mb_type, list)){ | |
| 921 if(1){ //FIXME skip or never read if mb_type doesnt use it | |
| 922 for(y=0; y<4; y++){ | |
| 923 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= | |
| 924 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= 0; | |
| 925 } | |
| 926 for(y=0; y<2; y++){ | |
| 927 *(uint16_t*)s->current_picture.motion_val[list][b8_xy + y*h->b8_stride]= (LIST_NOT_USED&0xFF)*0x0101; | |
| 928 } | |
| 929 } | |
| 930 continue; //FIXME direct mode ... | |
| 931 } | |
| 932 | |
| 933 for(y=0; y<4; y++){ | |
| 934 *(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]; | |
| 935 *(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]; | |
| 936 } | |
| 937 for(y=0; y<2; y++){ | |
| 938 s->current_picture.ref_index[list][b8_xy + 0 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+0 + 16*y]; | |
| 939 s->current_picture.ref_index[list][b8_xy + 1 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+2 + 16*y]; | |
| 940 } | |
| 941 } | |
| 942 } | |
| 943 | |
| 944 /** | |
| 945 * Decodes a network abstraction layer unit. | |
| 946 * @param consumed is the number of bytes used as input | |
| 947 * @param length is the length of the array | |
| 948 * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp ttailing? | |
| 949 * @returns decoded bytes, might be src+1 if no escapes | |
| 950 */ | |
| 951 static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){ | |
| 952 int i, si, di; | |
| 953 uint8_t *dst; | |
| 954 | |
| 955 // src[0]&0x80; //forbidden bit | |
| 956 h->nal_ref_idc= src[0]>>5; | |
| 957 h->nal_unit_type= src[0]&0x1F; | |
| 958 | |
| 959 src++; length--; | |
| 960 #if 0 | |
| 961 for(i=0; i<length; i++) | |
| 962 printf("%2X ", src[i]); | |
| 963 #endif | |
| 964 for(i=0; i+1<length; i+=2){ | |
| 965 if(src[i]) continue; | |
| 966 if(i>0 && src[i-1]==0) i--; | |
| 967 if(i+2<length && src[i+1]==0 && src[i+2]<=3){ | |
| 968 if(src[i+2]!=3){ | |
| 969 /* startcode, so we must be past the end */ | |
| 970 length=i; | |
| 971 } | |
| 972 break; | |
| 973 } | |
| 974 } | |
| 975 | |
| 976 if(i>=length-1){ //no escaped 0 | |
| 977 *dst_length= length; | |
| 978 *consumed= length+1; //+1 for the header | |
| 979 return src; | |
| 980 } | |
| 981 | |
| 982 h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length); | |
| 983 dst= h->rbsp_buffer; | |
| 984 | |
| 985 //printf("deoding esc\n"); | |
| 986 si=di=0; | |
| 987 while(si<length){ | |
| 988 //remove escapes (very rare 1:2^22) | |
| 989 if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){ | |
| 990 if(src[si+2]==3){ //escape | |
| 991 dst[di++]= 0; | |
| 992 dst[di++]= 0; | |
| 993 si+=3; | |
| 994 }else //next start code | |
| 995 break; | |
| 996 } | |
| 997 | |
| 998 dst[di++]= src[si++]; | |
| 999 } | |
| 1000 | |
| 1001 *dst_length= di; | |
| 1002 *consumed= si + 1;//+1 for the header | |
| 1003 //FIXME store exact number of bits in the getbitcontext (its needed for decoding) | |
| 1004 return dst; | |
| 1005 } | |
| 1006 | |
| 1007 /** | |
| 1008 * @param src the data which should be escaped | |
| 1009 * @param dst the target buffer, dst+1 == src is allowed as a special case | |
| 1010 * @param length the length of the src data | |
| 1011 * @param dst_length the length of the dst array | |
| 1012 * @returns length of escaped data in bytes or -1 if an error occured | |
| 1013 */ | |
| 1014 static int encode_nal(H264Context *h, uint8_t *dst, uint8_t *src, int length, int dst_length){ | |
| 1015 int i, escape_count, si, di; | |
| 1016 uint8_t *temp; | |
| 1017 | |
| 1018 assert(length>=0); | |
| 1019 assert(dst_length>0); | |
| 1020 | |
| 1021 dst[0]= (h->nal_ref_idc<<5) + h->nal_unit_type; | |
| 1022 | |
| 1023 if(length==0) return 1; | |
| 1024 | |
| 1025 escape_count= 0; | |
| 1026 for(i=0; i<length; i+=2){ | |
| 1027 if(src[i]) continue; | |
| 1028 if(i>0 && src[i-1]==0) | |
| 1029 i--; | |
| 1030 if(i+2<length && src[i+1]==0 && src[i+2]<=3){ | |
| 1031 escape_count++; | |
| 1032 i+=2; | |
| 1033 } | |
| 1034 } | |
| 1035 | |
| 1036 if(escape_count==0){ | |
| 1037 if(dst+1 != src) | |
| 1038 memcpy(dst+1, src, length); | |
| 1039 return length + 1; | |
| 1040 } | |
| 1041 | |
| 1042 if(length + escape_count + 1> dst_length) | |
| 1043 return -1; | |
| 1044 | |
| 1045 //this should be damn rare (hopefully) | |
| 1046 | |
| 1047 h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length + escape_count); | |
| 1048 temp= h->rbsp_buffer; | |
| 1049 //printf("encoding esc\n"); | |
| 1050 | |
| 1051 si= 0; | |
| 1052 di= 0; | |
| 1053 while(si < length){ | |
| 1054 if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){ | |
| 1055 temp[di++]= 0; si++; | |
| 1056 temp[di++]= 0; si++; | |
| 1057 temp[di++]= 3; | |
| 1058 temp[di++]= src[si++]; | |
| 1059 } | |
| 1060 else | |
| 1061 temp[di++]= src[si++]; | |
| 1062 } | |
| 1063 memcpy(dst+1, temp, length+escape_count); | |
| 1064 | |
| 1065 assert(di == length+escape_count); | |
| 1066 | |
| 1067 return di + 1; | |
| 1068 } | |
| 1069 | |
| 1070 /** | |
| 1071 * write 1,10,100,1000,... for alignment, yes its exactly inverse to mpeg4 | |
| 1072 */ | |
| 1073 static void encode_rbsp_trailing(PutBitContext *pb){ | |
| 1074 int length; | |
| 1075 put_bits(pb, 1, 1); | |
| 1786 | 1076 length= (-put_bits_count(pb))&7; |
| 1168 | 1077 if(length) put_bits(pb, length, 0); |
| 1078 } | |
| 1079 | |
| 1080 /** | |
| 1081 * identifies the exact end of the bitstream | |
| 1082 * @return the length of the trailing, or 0 if damaged | |
| 1083 */ | |
| 1084 static int decode_rbsp_trailing(uint8_t *src){ | |
| 1085 int v= *src; | |
| 1086 int r; | |
| 1087 | |
| 1170 | 1088 tprintf("rbsp trailing %X\n", v); |
| 1168 | 1089 |
| 1090 for(r=1; r<9; r++){ | |
| 1091 if(v&1) return r; | |
| 1092 v>>=1; | |
| 1093 } | |
| 1094 return 0; | |
| 1095 } | |
| 1096 | |
| 1097 /** | |
| 1098 * idct tranforms the 16 dc values and dequantize them. | |
| 1099 * @param qp quantization parameter | |
| 1100 */ | |
| 1101 static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp){ | |
| 1102 const int qmul= dequant_coeff[qp][0]; | |
| 1103 #define stride 16 | |
| 1104 int i; | |
| 1105 int temp[16]; //FIXME check if this is a good idea | |
| 1106 static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride}; | |
| 1107 static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride}; | |
| 1108 | |
| 1109 //memset(block, 64, 2*256); | |
| 1110 //return; | |
| 1111 for(i=0; i<4; i++){ | |
| 1112 const int offset= y_offset[i]; | |
| 1113 const int z0= block[offset+stride*0] + block[offset+stride*4]; | |
| 1114 const int z1= block[offset+stride*0] - block[offset+stride*4]; | |
| 1115 const int z2= block[offset+stride*1] - block[offset+stride*5]; | |
| 1116 const int z3= block[offset+stride*1] + block[offset+stride*5]; | |
| 1117 | |
| 1118 temp[4*i+0]= z0+z3; | |
| 1119 temp[4*i+1]= z1+z2; | |
| 1120 temp[4*i+2]= z1-z2; | |
| 1121 temp[4*i+3]= z0-z3; | |
| 1122 } | |
| 1123 | |
| 1124 for(i=0; i<4; i++){ | |
| 1125 const int offset= x_offset[i]; | |
| 1126 const int z0= temp[4*0+i] + temp[4*2+i]; | |
| 1127 const int z1= temp[4*0+i] - temp[4*2+i]; | |
| 1128 const int z2= temp[4*1+i] - temp[4*3+i]; | |
| 1129 const int z3= temp[4*1+i] + temp[4*3+i]; | |
| 1130 | |
| 1131 block[stride*0 +offset]= ((z0 + z3)*qmul + 2)>>2; //FIXME think about merging this into decode_resdual | |
| 1132 block[stride*2 +offset]= ((z1 + z2)*qmul + 2)>>2; | |
| 1133 block[stride*8 +offset]= ((z1 - z2)*qmul + 2)>>2; | |
| 1134 block[stride*10+offset]= ((z0 - z3)*qmul + 2)>>2; | |
| 1135 } | |
| 1136 } | |
| 1137 | |
| 1138 /** | |
| 1139 * dct tranforms the 16 dc values. | |
| 1140 * @param qp quantization parameter ??? FIXME | |
| 1141 */ | |
| 1142 static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){ | |
| 1143 // const int qmul= dequant_coeff[qp][0]; | |
| 1144 int i; | |
| 1145 int temp[16]; //FIXME check if this is a good idea | |
| 1146 static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride}; | |
| 1147 static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride}; | |
| 1148 | |
| 1149 for(i=0; i<4; i++){ | |
| 1150 const int offset= y_offset[i]; | |
| 1151 const int z0= block[offset+stride*0] + block[offset+stride*4]; | |
| 1152 const int z1= block[offset+stride*0] - block[offset+stride*4]; | |
| 1153 const int z2= block[offset+stride*1] - block[offset+stride*5]; | |
| 1154 const int z3= block[offset+stride*1] + block[offset+stride*5]; | |
| 1155 | |
| 1156 temp[4*i+0]= z0+z3; | |
| 1157 temp[4*i+1]= z1+z2; | |
| 1158 temp[4*i+2]= z1-z2; | |
| 1159 temp[4*i+3]= z0-z3; | |
| 1160 } | |
| 1161 | |
| 1162 for(i=0; i<4; i++){ | |
| 1163 const int offset= x_offset[i]; | |
| 1164 const int z0= temp[4*0+i] + temp[4*2+i]; | |
| 1165 const int z1= temp[4*0+i] - temp[4*2+i]; | |
| 1166 const int z2= temp[4*1+i] - temp[4*3+i]; | |
| 1167 const int z3= temp[4*1+i] + temp[4*3+i]; | |
| 1168 | |
| 1169 block[stride*0 +offset]= (z0 + z3)>>1; | |
| 1170 block[stride*2 +offset]= (z1 + z2)>>1; | |
| 1171 block[stride*8 +offset]= (z1 - z2)>>1; | |
| 1172 block[stride*10+offset]= (z0 - z3)>>1; | |
| 1173 } | |
| 1174 } | |
| 1175 #undef xStride | |
| 1176 #undef stride | |
| 1177 | |
| 1178 static void chroma_dc_dequant_idct_c(DCTELEM *block, int qp){ | |
| 1179 const int qmul= dequant_coeff[qp][0]; | |
| 1180 const int stride= 16*2; | |
| 1181 const int xStride= 16; | |
| 1182 int a,b,c,d,e; | |
| 1183 | |
| 1184 a= block[stride*0 + xStride*0]; | |
| 1185 b= block[stride*0 + xStride*1]; | |
| 1186 c= block[stride*1 + xStride*0]; | |
| 1187 d= block[stride*1 + xStride*1]; | |
| 1188 | |
| 1189 e= a-b; | |
| 1190 a= a+b; | |
| 1191 b= c-d; | |
| 1192 c= c+d; | |
| 1193 | |
| 1194 block[stride*0 + xStride*0]= ((a+c)*qmul + 0)>>1; | |
| 1195 block[stride*0 + xStride*1]= ((e+b)*qmul + 0)>>1; | |
| 1196 block[stride*1 + xStride*0]= ((a-c)*qmul + 0)>>1; | |
| 1197 block[stride*1 + xStride*1]= ((e-b)*qmul + 0)>>1; | |
| 1198 } | |
| 1199 | |
| 1200 static void chroma_dc_dct_c(DCTELEM *block){ | |
| 1201 const int stride= 16*2; | |
| 1202 const int xStride= 16; | |
| 1203 int a,b,c,d,e; | |
| 1204 | |
| 1205 a= block[stride*0 + xStride*0]; | |
| 1206 b= block[stride*0 + xStride*1]; | |
| 1207 c= block[stride*1 + xStride*0]; | |
| 1208 d= block[stride*1 + xStride*1]; | |
| 1209 | |
| 1210 e= a-b; | |
| 1211 a= a+b; | |
| 1212 b= c-d; | |
| 1213 c= c+d; | |
| 1214 | |
| 1215 block[stride*0 + xStride*0]= (a+c); | |
| 1216 block[stride*0 + xStride*1]= (e+b); | |
| 1217 block[stride*1 + xStride*0]= (a-c); | |
| 1218 block[stride*1 + xStride*1]= (e-b); | |
| 1219 } | |
| 1220 | |
| 1221 /** | |
| 1222 * gets the chroma qp. | |
| 1223 */ | |
| 1224 static inline int get_chroma_qp(H264Context *h, int qscale){ | |
| 1225 | |
| 1226 return chroma_qp[clip(qscale + h->pps.chroma_qp_index_offset, 0, 51)]; | |
| 1227 } | |
| 1228 | |
| 1229 | |
| 1230 /** | |
| 1231 * | |
| 1232 */ | |
| 1233 static void h264_add_idct_c(uint8_t *dst, DCTELEM *block, int stride){ | |
| 1234 int i; | |
| 1235 uint8_t *cm = cropTbl + MAX_NEG_CROP; | |
| 1236 | |
| 1237 block[0] += 32; | |
| 1238 #if 1 | |
| 1239 for(i=0; i<4; i++){ | |
| 1240 const int z0= block[i + 4*0] + block[i + 4*2]; | |
| 1241 const int z1= block[i + 4*0] - block[i + 4*2]; | |
| 1242 const int z2= (block[i + 4*1]>>1) - block[i + 4*3]; | |
| 1243 const int z3= block[i + 4*1] + (block[i + 4*3]>>1); | |
| 1244 | |
| 1245 block[i + 4*0]= z0 + z3; | |
| 1246 block[i + 4*1]= z1 + z2; | |
| 1247 block[i + 4*2]= z1 - z2; | |
| 1248 block[i + 4*3]= z0 - z3; | |
| 1249 } | |
| 1250 | |
| 1251 for(i=0; i<4; i++){ | |
| 1252 const int z0= block[0 + 4*i] + block[2 + 4*i]; | |
| 1253 const int z1= block[0 + 4*i] - block[2 + 4*i]; | |
| 1254 const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i]; | |
| 1255 const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1); | |
| 1256 | |
| 1257 dst[0 + i*stride]= cm[ dst[0 + i*stride] + ((z0 + z3) >> 6) ]; | |
| 1258 dst[1 + i*stride]= cm[ dst[1 + i*stride] + ((z1 + z2) >> 6) ]; | |
| 1259 dst[2 + i*stride]= cm[ dst[2 + i*stride] + ((z1 - z2) >> 6) ]; | |
| 1260 dst[3 + i*stride]= cm[ dst[3 + i*stride] + ((z0 - z3) >> 6) ]; | |
| 1261 } | |
| 1262 #else | |
| 1263 for(i=0; i<4; i++){ | |
| 1264 const int z0= block[0 + 4*i] + block[2 + 4*i]; | |
| 1265 const int z1= block[0 + 4*i] - block[2 + 4*i]; | |
| 1266 const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i]; | |
| 1267 const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1); | |
| 1268 | |
| 1269 block[0 + 4*i]= z0 + z3; | |
| 1270 block[1 + 4*i]= z1 + z2; | |
| 1271 block[2 + 4*i]= z1 - z2; | |
| 1272 block[3 + 4*i]= z0 - z3; | |
| 1273 } | |
| 1274 | |
| 1275 for(i=0; i<4; i++){ | |
| 1276 const int z0= block[i + 4*0] + block[i + 4*2]; | |
| 1277 const int z1= block[i + 4*0] - block[i + 4*2]; | |
| 1278 const int z2= (block[i + 4*1]>>1) - block[i + 4*3]; | |
| 1279 const int z3= block[i + 4*1] + (block[i + 4*3]>>1); | |
| 1280 | |
| 1281 dst[i + 0*stride]= cm[ dst[i + 0*stride] + ((z0 + z3) >> 6) ]; | |
| 1282 dst[i + 1*stride]= cm[ dst[i + 1*stride] + ((z1 + z2) >> 6) ]; | |
| 1283 dst[i + 2*stride]= cm[ dst[i + 2*stride] + ((z1 - z2) >> 6) ]; | |
| 1284 dst[i + 3*stride]= cm[ dst[i + 3*stride] + ((z0 - z3) >> 6) ]; | |
| 1285 } | |
| 1286 #endif | |
| 1287 } | |
| 1288 | |
| 1289 static void h264_diff_dct_c(DCTELEM *block, uint8_t *src1, uint8_t *src2, int stride){ | |
| 1290 int i; | |
| 1291 //FIXME try int temp instead of block | |
| 1292 | |
| 1293 for(i=0; i<4; i++){ | |
| 1294 const int d0= src1[0 + i*stride] - src2[0 + i*stride]; | |
| 1295 const int d1= src1[1 + i*stride] - src2[1 + i*stride]; | |
| 1296 const int d2= src1[2 + i*stride] - src2[2 + i*stride]; | |
| 1297 const int d3= src1[3 + i*stride] - src2[3 + i*stride]; | |
| 1298 const int z0= d0 + d3; | |
| 1299 const int z3= d0 - d3; | |
| 1300 const int z1= d1 + d2; | |
| 1301 const int z2= d1 - d2; | |
| 1302 | |
| 1303 block[0 + 4*i]= z0 + z1; | |
| 1304 block[1 + 4*i]= 2*z3 + z2; | |
| 1305 block[2 + 4*i]= z0 - z1; | |
| 1306 block[3 + 4*i]= z3 - 2*z2; | |
| 1307 } | |
| 1308 | |
| 1309 for(i=0; i<4; i++){ | |
| 1310 const int z0= block[0*4 + i] + block[3*4 + i]; | |
| 1311 const int z3= block[0*4 + i] - block[3*4 + i]; | |
| 1312 const int z1= block[1*4 + i] + block[2*4 + i]; | |
| 1313 const int z2= block[1*4 + i] - block[2*4 + i]; | |
| 1314 | |
| 1315 block[0*4 + i]= z0 + z1; | |
| 1316 block[1*4 + i]= 2*z3 + z2; | |
| 1317 block[2*4 + i]= z0 - z1; | |
| 1318 block[3*4 + i]= z3 - 2*z2; | |
| 1319 } | |
| 1320 } | |
| 1321 | |
| 1322 //FIXME need to check that this doesnt overflow signed 32 bit for low qp, iam not sure, its very close | |
| 1323 //FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away) | |
| 1324 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int seperate_dc){ | |
| 1325 int i; | |
| 1326 const int * const quant_table= quant_coeff[qscale]; | |
| 1327 const int bias= intra ? (1<<QUANT_SHIFT)/3 : (1<<QUANT_SHIFT)/6; | |
| 1328 const unsigned int threshold1= (1<<QUANT_SHIFT) - bias - 1; | |
| 1329 const unsigned int threshold2= (threshold1<<1); | |
| 1330 int last_non_zero; | |
| 1331 | |
| 1332 if(seperate_dc){ | |
| 1333 if(qscale<=18){ | |
| 1334 //avoid overflows | |
| 1335 const int dc_bias= intra ? (1<<(QUANT_SHIFT-2))/3 : (1<<(QUANT_SHIFT-2))/6; | |
| 1336 const unsigned int dc_threshold1= (1<<(QUANT_SHIFT-2)) - dc_bias - 1; | |
| 1337 const unsigned int dc_threshold2= (dc_threshold1<<1); | |
| 1338 | |
| 1339 int level= block[0]*quant_coeff[qscale+18][0]; | |
| 1340 if(((unsigned)(level+dc_threshold1))>dc_threshold2){ | |
| 1341 if(level>0){ | |
| 1342 level= (dc_bias + level)>>(QUANT_SHIFT-2); | |
| 1343 block[0]= level; | |
| 1344 }else{ | |
| 1345 level= (dc_bias - level)>>(QUANT_SHIFT-2); | |
| 1346 block[0]= -level; | |
| 1347 } | |
| 1348 // last_non_zero = i; | |
| 1349 }else{ | |
| 1350 block[0]=0; | |
| 1351 } | |
| 1352 }else{ | |
| 1353 const int dc_bias= intra ? (1<<(QUANT_SHIFT+1))/3 : (1<<(QUANT_SHIFT+1))/6; | |
| 1354 const unsigned int dc_threshold1= (1<<(QUANT_SHIFT+1)) - dc_bias - 1; | |
| 1355 const unsigned int dc_threshold2= (dc_threshold1<<1); | |
| 1356 | |
| 1357 int level= block[0]*quant_table[0]; | |
| 1358 if(((unsigned)(level+dc_threshold1))>dc_threshold2){ | |
| 1359 if(level>0){ | |
| 1360 level= (dc_bias + level)>>(QUANT_SHIFT+1); | |
| 1361 block[0]= level; | |
| 1362 }else{ | |
| 1363 level= (dc_bias - level)>>(QUANT_SHIFT+1); | |
| 1364 block[0]= -level; | |
| 1365 } | |
| 1366 // last_non_zero = i; | |
| 1367 }else{ | |
| 1368 block[0]=0; | |
| 1369 } | |
| 1370 } | |
| 1371 last_non_zero= 0; | |
| 1372 i=1; | |
| 1373 }else{ | |
| 1374 last_non_zero= -1; | |
| 1375 i=0; | |
| 1376 } | |
| 1377 | |
| 1378 for(; i<16; i++){ | |
| 1379 const int j= scantable[i]; | |
| 1380 int level= block[j]*quant_table[j]; | |
| 1381 | |
| 1382 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
| 1383 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
| 1384 if(((unsigned)(level+threshold1))>threshold2){ | |
| 1385 if(level>0){ | |
| 1386 level= (bias + level)>>QUANT_SHIFT; | |
| 1387 block[j]= level; | |
| 1388 }else{ | |
| 1389 level= (bias - level)>>QUANT_SHIFT; | |
| 1390 block[j]= -level; | |
| 1391 } | |
| 1392 last_non_zero = i; | |
| 1393 }else{ | |
| 1394 block[j]=0; | |
| 1395 } | |
| 1396 } | |
| 1397 | |
| 1398 return last_non_zero; | |
| 1399 } | |
| 1400 | |
| 1401 static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1402 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
| 1403 ((uint32_t*)(src+0*stride))[0]= a; | |
| 1404 ((uint32_t*)(src+1*stride))[0]= a; | |
| 1405 ((uint32_t*)(src+2*stride))[0]= a; | |
| 1406 ((uint32_t*)(src+3*stride))[0]= a; | |
| 1407 } | |
| 1408 | |
| 1409 static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1410 ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101; | |
| 1411 ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101; | |
| 1412 ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101; | |
| 1413 ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101; | |
| 1414 } | |
| 1415 | |
| 1416 static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1417 const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] | |
| 1418 + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3; | |
| 1419 | |
| 1420 ((uint32_t*)(src+0*stride))[0]= | |
| 1421 ((uint32_t*)(src+1*stride))[0]= | |
| 1422 ((uint32_t*)(src+2*stride))[0]= | |
| 1423 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
| 1424 } | |
| 1425 | |
| 1426 static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1427 const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2; | |
| 1428 | |
| 1429 ((uint32_t*)(src+0*stride))[0]= | |
| 1430 ((uint32_t*)(src+1*stride))[0]= | |
| 1431 ((uint32_t*)(src+2*stride))[0]= | |
| 1432 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
| 1433 } | |
| 1434 | |
| 1435 static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1436 const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2; | |
| 1437 | |
| 1438 ((uint32_t*)(src+0*stride))[0]= | |
| 1439 ((uint32_t*)(src+1*stride))[0]= | |
| 1440 ((uint32_t*)(src+2*stride))[0]= | |
| 1441 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
| 1442 } | |
| 1443 | |
| 1444 static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1445 ((uint32_t*)(src+0*stride))[0]= | |
| 1446 ((uint32_t*)(src+1*stride))[0]= | |
| 1447 ((uint32_t*)(src+2*stride))[0]= | |
| 1448 ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U; | |
| 1449 } | |
| 1450 | |
| 1451 | |
| 1452 #define LOAD_TOP_RIGHT_EDGE\ | |
| 1453 const int t4= topright[0];\ | |
| 1454 const int t5= topright[1];\ | |
| 1455 const int t6= topright[2];\ | |
| 1456 const int t7= topright[3];\ | |
| 1457 | |
| 1458 #define LOAD_LEFT_EDGE\ | |
| 1459 const int l0= src[-1+0*stride];\ | |
| 1460 const int l1= src[-1+1*stride];\ | |
| 1461 const int l2= src[-1+2*stride];\ | |
| 1462 const int l3= src[-1+3*stride];\ | |
| 1463 | |
| 1464 #define LOAD_TOP_EDGE\ | |
| 1465 const int t0= src[ 0-1*stride];\ | |
| 1466 const int t1= src[ 1-1*stride];\ | |
| 1467 const int t2= src[ 2-1*stride];\ | |
| 1468 const int t3= src[ 3-1*stride];\ | |
| 1469 | |
| 1470 static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1471 const int lt= src[-1-1*stride]; | |
| 1472 LOAD_TOP_EDGE | |
| 1473 LOAD_LEFT_EDGE | |
| 1474 | |
| 1475 src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2; | |
| 1476 src[0+2*stride]= | |
| 1477 src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2; | |
| 1478 src[0+1*stride]= | |
| 1479 src[1+2*stride]= | |
| 1480 src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2; | |
| 1481 src[0+0*stride]= | |
| 1482 src[1+1*stride]= | |
| 1483 src[2+2*stride]= | |
| 1484 src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
| 1485 src[1+0*stride]= | |
| 1486 src[2+1*stride]= | |
| 1487 src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
| 1488 src[2+0*stride]= | |
| 1489 src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
| 1490 src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
| 1282 | 1491 } |
| 1168 | 1492 |
| 1493 static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1494 LOAD_TOP_EDGE | |
| 1495 LOAD_TOP_RIGHT_EDGE | |
| 1496 // LOAD_LEFT_EDGE | |
| 1497 | |
| 1498 src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2; | |
| 1499 src[1+0*stride]= | |
| 1500 src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2; | |
| 1501 src[2+0*stride]= | |
| 1502 src[1+1*stride]= | |
| 1503 src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2; | |
| 1504 src[3+0*stride]= | |
| 1505 src[2+1*stride]= | |
| 1506 src[1+2*stride]= | |
| 1507 src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2; | |
| 1508 src[3+1*stride]= | |
| 1509 src[2+2*stride]= | |
| 1510 src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2; | |
| 1511 src[3+2*stride]= | |
| 1512 src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2; | |
| 1513 src[3+3*stride]=(t6 + 3*t7 + 2)>>2; | |
| 1282 | 1514 } |
| 1168 | 1515 |
| 1516 static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1517 const int lt= src[-1-1*stride]; | |
| 1518 LOAD_TOP_EDGE | |
| 1519 LOAD_LEFT_EDGE | |
| 1520 const __attribute__((unused)) int unu= l3; | |
| 1521 | |
| 1522 src[0+0*stride]= | |
| 1523 src[1+2*stride]=(lt + t0 + 1)>>1; | |
| 1524 src[1+0*stride]= | |
| 1525 src[2+2*stride]=(t0 + t1 + 1)>>1; | |
| 1526 src[2+0*stride]= | |
| 1527 src[3+2*stride]=(t1 + t2 + 1)>>1; | |
| 1528 src[3+0*stride]=(t2 + t3 + 1)>>1; | |
| 1529 src[0+1*stride]= | |
| 1530 src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
| 1531 src[1+1*stride]= | |
| 1532 src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
| 1533 src[2+1*stride]= | |
| 1534 src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
| 1535 src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
| 1536 src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; | |
| 1537 src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
| 1282 | 1538 } |
| 1168 | 1539 |
| 1540 static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1541 LOAD_TOP_EDGE | |
| 1542 LOAD_TOP_RIGHT_EDGE | |
| 1543 const __attribute__((unused)) int unu= t7; | |
| 1544 | |
| 1545 src[0+0*stride]=(t0 + t1 + 1)>>1; | |
| 1546 src[1+0*stride]= | |
| 1547 src[0+2*stride]=(t1 + t2 + 1)>>1; | |
| 1548 src[2+0*stride]= | |
| 1549 src[1+2*stride]=(t2 + t3 + 1)>>1; | |
| 1550 src[3+0*stride]= | |
| 1551 src[2+2*stride]=(t3 + t4+ 1)>>1; | |
| 1552 src[3+2*stride]=(t4 + t5+ 1)>>1; | |
| 1553 src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
| 1554 src[1+1*stride]= | |
| 1555 src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
| 1556 src[2+1*stride]= | |
| 1557 src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; | |
| 1558 src[3+1*stride]= | |
| 1559 src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; | |
| 1560 src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2; | |
| 1282 | 1561 } |
| 1168 | 1562 |
| 1563 static void pred4x4_horizontal_up_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1564 LOAD_LEFT_EDGE | |
| 1565 | |
| 1566 src[0+0*stride]=(l0 + l1 + 1)>>1; | |
| 1567 src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
| 1568 src[2+0*stride]= | |
| 1569 src[0+1*stride]=(l1 + l2 + 1)>>1; | |
| 1570 src[3+0*stride]= | |
| 1571 src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2; | |
| 1572 src[2+1*stride]= | |
| 1573 src[0+2*stride]=(l2 + l3 + 1)>>1; | |
| 1574 src[3+1*stride]= | |
| 1575 src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2; | |
| 1576 src[3+2*stride]= | |
| 1577 src[1+3*stride]= | |
| 1578 src[0+3*stride]= | |
| 1579 src[2+2*stride]= | |
| 1580 src[2+3*stride]= | |
| 1581 src[3+3*stride]=l3; | |
| 1282 | 1582 } |
| 1168 | 1583 |
| 1584 static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){ | |
| 1585 const int lt= src[-1-1*stride]; | |
| 1586 LOAD_TOP_EDGE | |
| 1587 LOAD_LEFT_EDGE | |
| 1588 const __attribute__((unused)) int unu= t3; | |
| 1589 | |
| 1590 src[0+0*stride]= | |
| 1591 src[2+1*stride]=(lt + l0 + 1)>>1; | |
| 1592 src[1+0*stride]= | |
| 1593 src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
| 1594 src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
| 1595 src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
| 1596 src[0+1*stride]= | |
| 1597 src[2+2*stride]=(l0 + l1 + 1)>>1; | |
| 1598 src[1+1*stride]= | |
| 1599 src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2; | |
| 1600 src[0+2*stride]= | |
| 1601 src[2+3*stride]=(l1 + l2+ 1)>>1; | |
| 1602 src[1+2*stride]= | |
| 1603 src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
| 1604 src[0+3*stride]=(l2 + l3 + 1)>>1; | |
| 1605 src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2; | |
| 1282 | 1606 } |
| 1168 | 1607 |
| 1608 static void pred16x16_vertical_c(uint8_t *src, int stride){ | |
| 1609 int i; | |
| 1610 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
| 1611 const uint32_t b= ((uint32_t*)(src-stride))[1]; | |
| 1612 const uint32_t c= ((uint32_t*)(src-stride))[2]; | |
| 1613 const uint32_t d= ((uint32_t*)(src-stride))[3]; | |
| 1614 | |
| 1615 for(i=0; i<16; i++){ | |
| 1616 ((uint32_t*)(src+i*stride))[0]= a; | |
| 1617 ((uint32_t*)(src+i*stride))[1]= b; | |
| 1618 ((uint32_t*)(src+i*stride))[2]= c; | |
| 1619 ((uint32_t*)(src+i*stride))[3]= d; | |
| 1620 } | |
| 1621 } | |
| 1622 | |
| 1623 static void pred16x16_horizontal_c(uint8_t *src, int stride){ | |
| 1624 int i; | |
| 1625 | |
| 1626 for(i=0; i<16; i++){ | |
| 1627 ((uint32_t*)(src+i*stride))[0]= | |
| 1628 ((uint32_t*)(src+i*stride))[1]= | |
| 1629 ((uint32_t*)(src+i*stride))[2]= | |
| 1630 ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101; | |
| 1631 } | |
| 1632 } | |
| 1633 | |
| 1634 static void pred16x16_dc_c(uint8_t *src, int stride){ | |
| 1635 int i, dc=0; | |
| 1636 | |
| 1637 for(i=0;i<16; i++){ | |
| 1638 dc+= src[-1+i*stride]; | |
| 1639 } | |
| 1640 | |
| 1641 for(i=0;i<16; i++){ | |
| 1642 dc+= src[i-stride]; | |
| 1643 } | |
| 1644 | |
| 1645 dc= 0x01010101*((dc + 16)>>5); | |
| 1646 | |
| 1647 for(i=0; i<16; i++){ | |
| 1648 ((uint32_t*)(src+i*stride))[0]= | |
| 1649 ((uint32_t*)(src+i*stride))[1]= | |
| 1650 ((uint32_t*)(src+i*stride))[2]= | |
| 1651 ((uint32_t*)(src+i*stride))[3]= dc; | |
| 1652 } | |
| 1653 } | |
| 1654 | |
| 1655 static void pred16x16_left_dc_c(uint8_t *src, int stride){ | |
| 1656 int i, dc=0; | |
| 1657 | |
| 1658 for(i=0;i<16; i++){ | |
| 1659 dc+= src[-1+i*stride]; | |
| 1660 } | |
| 1661 | |
| 1662 dc= 0x01010101*((dc + 8)>>4); | |
| 1663 | |
| 1664 for(i=0; i<16; i++){ | |
| 1665 ((uint32_t*)(src+i*stride))[0]= | |
| 1666 ((uint32_t*)(src+i*stride))[1]= | |
| 1667 ((uint32_t*)(src+i*stride))[2]= | |
| 1668 ((uint32_t*)(src+i*stride))[3]= dc; | |
| 1669 } | |
| 1670 } | |
| 1671 | |
| 1672 static void pred16x16_top_dc_c(uint8_t *src, int stride){ | |
| 1673 int i, dc=0; | |
| 1674 | |
| 1675 for(i=0;i<16; i++){ | |
| 1676 dc+= src[i-stride]; | |
| 1677 } | |
| 1678 dc= 0x01010101*((dc + 8)>>4); | |
| 1679 | |
| 1680 for(i=0; i<16; i++){ | |
| 1681 ((uint32_t*)(src+i*stride))[0]= | |
| 1682 ((uint32_t*)(src+i*stride))[1]= | |
| 1683 ((uint32_t*)(src+i*stride))[2]= | |
| 1684 ((uint32_t*)(src+i*stride))[3]= dc; | |
| 1685 } | |
| 1686 } | |
| 1687 | |
| 1688 static void pred16x16_128_dc_c(uint8_t *src, int stride){ | |
| 1689 int i; | |
| 1690 | |
| 1691 for(i=0; i<16; i++){ | |
| 1692 ((uint32_t*)(src+i*stride))[0]= | |
| 1693 ((uint32_t*)(src+i*stride))[1]= | |
| 1694 ((uint32_t*)(src+i*stride))[2]= | |
| 1695 ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U; | |
| 1696 } | |
| 1697 } | |
| 1698 | |
| 1234 | 1699 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
|
1700 int i, j, k; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1701 int a; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1702 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
|
1703 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
|
1704 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
|
1705 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
|
1706 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
|
1707 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
|
1708 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
|
1709 src1 += stride; src2 -= stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1710 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
|
1711 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
|
1712 } |
| 1234 | 1713 if(svq3){ |
| 1714 H = ( 5*(H/4) ) / 16; | |
| 1715 V = ( 5*(V/4) ) / 16; | |
|
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
1716 |
|
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
1717 /* required for 100% accuracy */ |
|
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
1718 i = H; H = V; V = i; |
| 1234 | 1719 }else{ |
| 1720 H = ( 5*H+32 ) >> 6; | |
| 1721 V = ( 5*V+32 ) >> 6; | |
| 1722 } | |
|
1184
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1723 |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1724 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
|
1725 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
|
1726 int b = a; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1727 a += V; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1728 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
|
1729 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
|
1730 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
|
1731 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
|
1732 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
|
1733 b += 4*H; |
| 1168 | 1734 } |
|
1184
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1735 src += stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1736 } |
| 1168 | 1737 } |
| 1738 | |
| 1234 | 1739 static void pred16x16_plane_c(uint8_t *src, int stride){ |
| 1740 pred16x16_plane_compat_c(src, stride, 0); | |
| 1741 } | |
| 1742 | |
| 1168 | 1743 static void pred8x8_vertical_c(uint8_t *src, int stride){ |
| 1744 int i; | |
| 1745 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
| 1746 const uint32_t b= ((uint32_t*)(src-stride))[1]; | |
| 1747 | |
| 1748 for(i=0; i<8; i++){ | |
| 1749 ((uint32_t*)(src+i*stride))[0]= a; | |
| 1750 ((uint32_t*)(src+i*stride))[1]= b; | |
| 1751 } | |
| 1752 } | |
| 1753 | |
| 1754 static void pred8x8_horizontal_c(uint8_t *src, int stride){ | |
| 1755 int i; | |
| 1756 | |
| 1757 for(i=0; i<8; i++){ | |
| 1758 ((uint32_t*)(src+i*stride))[0]= | |
| 1759 ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101; | |
| 1760 } | |
| 1761 } | |
| 1762 | |
| 1763 static void pred8x8_128_dc_c(uint8_t *src, int stride){ | |
| 1764 int i; | |
| 1765 | |
| 1766 for(i=0; i<4; i++){ | |
| 1767 ((uint32_t*)(src+i*stride))[0]= | |
| 1768 ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; | |
| 1769 } | |
| 1770 for(i=4; i<8; i++){ | |
| 1771 ((uint32_t*)(src+i*stride))[0]= | |
| 1772 ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; | |
| 1773 } | |
| 1774 } | |
| 1775 | |
| 1776 static void pred8x8_left_dc_c(uint8_t *src, int stride){ | |
| 1777 int i; | |
| 1778 int dc0, dc2; | |
| 1779 | |
| 1780 dc0=dc2=0; | |
| 1781 for(i=0;i<4; i++){ | |
| 1782 dc0+= src[-1+i*stride]; | |
| 1783 dc2+= src[-1+(i+4)*stride]; | |
| 1784 } | |
| 1785 dc0= 0x01010101*((dc0 + 2)>>2); | |
| 1786 dc2= 0x01010101*((dc2 + 2)>>2); | |
| 1787 | |
| 1788 for(i=0; i<4; i++){ | |
| 1789 ((uint32_t*)(src+i*stride))[0]= | |
| 1790 ((uint32_t*)(src+i*stride))[1]= dc0; | |
| 1791 } | |
| 1792 for(i=4; i<8; i++){ | |
| 1793 ((uint32_t*)(src+i*stride))[0]= | |
| 1794 ((uint32_t*)(src+i*stride))[1]= dc2; | |
| 1795 } | |
| 1796 } | |
| 1797 | |
| 1798 static void pred8x8_top_dc_c(uint8_t *src, int stride){ | |
| 1799 int i; | |
| 1800 int dc0, dc1; | |
| 1801 | |
| 1802 dc0=dc1=0; | |
| 1803 for(i=0;i<4; i++){ | |
| 1804 dc0+= src[i-stride]; | |
| 1805 dc1+= src[4+i-stride]; | |
| 1806 } | |
| 1807 dc0= 0x01010101*((dc0 + 2)>>2); | |
| 1808 dc1= 0x01010101*((dc1 + 2)>>2); | |
| 1809 | |
| 1810 for(i=0; i<4; i++){ | |
| 1811 ((uint32_t*)(src+i*stride))[0]= dc0; | |
| 1812 ((uint32_t*)(src+i*stride))[1]= dc1; | |
| 1813 } | |
| 1814 for(i=4; i<8; i++){ | |
| 1815 ((uint32_t*)(src+i*stride))[0]= dc0; | |
| 1816 ((uint32_t*)(src+i*stride))[1]= dc1; | |
| 1817 } | |
| 1818 } | |
| 1819 | |
| 1820 | |
| 1821 static void pred8x8_dc_c(uint8_t *src, int stride){ | |
| 1822 int i; | |
| 1823 int dc0, dc1, dc2, dc3; | |
| 1824 | |
| 1825 dc0=dc1=dc2=0; | |
| 1826 for(i=0;i<4; i++){ | |
| 1827 dc0+= src[-1+i*stride] + src[i-stride]; | |
| 1828 dc1+= src[4+i-stride]; | |
| 1829 dc2+= src[-1+(i+4)*stride]; | |
| 1830 } | |
| 1831 dc3= 0x01010101*((dc1 + dc2 + 4)>>3); | |
| 1832 dc0= 0x01010101*((dc0 + 4)>>3); | |
| 1833 dc1= 0x01010101*((dc1 + 2)>>2); | |
| 1834 dc2= 0x01010101*((dc2 + 2)>>2); | |
| 1835 | |
| 1836 for(i=0; i<4; i++){ | |
| 1837 ((uint32_t*)(src+i*stride))[0]= dc0; | |
| 1838 ((uint32_t*)(src+i*stride))[1]= dc1; | |
| 1839 } | |
| 1840 for(i=4; i<8; i++){ | |
| 1841 ((uint32_t*)(src+i*stride))[0]= dc2; | |
| 1842 ((uint32_t*)(src+i*stride))[1]= dc3; | |
| 1843 } | |
| 1844 } | |
| 1845 | |
| 1846 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
|
1847 int j, k; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1848 int a; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1849 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
|
1850 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
|
1851 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
|
1852 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
|
1853 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
|
1854 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
|
1855 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
|
1856 src1 += stride; src2 -= stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1857 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
|
1858 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
|
1859 } |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1860 H = ( 17*H+16 ) >> 5; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1861 V = ( 17*V+16 ) >> 5; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1862 |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1863 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
|
1864 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
|
1865 int b = a; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1866 a += V; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1867 src[0] = cm[ (b ) >> 5 ]; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1868 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
|
1869 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
|
1870 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
|
1871 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
|
1872 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
|
1873 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
|
1874 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
|
1875 src += stride; |
|
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1876 } |
| 1168 | 1877 } |
| 1878 | |
| 1879 static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list, | |
| 1880 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
| 1881 int src_x_offset, int src_y_offset, | |
| 1882 qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op){ | |
| 1883 MpegEncContext * const s = &h->s; | |
| 1884 const int mx= h->mv_cache[list][ scan8[n] ][0] + src_x_offset*8; | |
| 1885 const int my= h->mv_cache[list][ scan8[n] ][1] + src_y_offset*8; | |
| 1886 const int luma_xy= (mx&3) + ((my&3)<<2); | |
| 1887 uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*s->linesize; | |
| 1888 uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*s->uvlinesize; | |
| 1889 uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*s->uvlinesize; | |
| 1890 int extra_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; //FIXME increase edge?, IMHO not worth it | |
| 1891 int extra_height= extra_width; | |
| 1892 int emu=0; | |
| 1893 const int full_mx= mx>>2; | |
| 1894 const int full_my= my>>2; | |
| 1895 | |
| 1896 assert(pic->data[0]); | |
| 1897 | |
| 1898 if(mx&7) extra_width -= 3; | |
| 1899 if(my&7) extra_height -= 3; | |
| 1900 | |
| 1901 if( full_mx < 0-extra_width | |
| 1902 || full_my < 0-extra_height | |
| 1903 || full_mx + 16/*FIXME*/ > s->width + extra_width | |
| 1904 || full_my + 16/*FIXME*/ > s->height + extra_height){ | |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
1905 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 | 1906 src_y= s->edge_emu_buffer + 2 + 2*s->linesize; |
| 1907 emu=1; | |
| 1908 } | |
| 1909 | |
| 1910 qpix_op[luma_xy](dest_y, src_y, s->linesize); //FIXME try variable height perhaps? | |
| 1911 if(!square){ | |
| 1912 qpix_op[luma_xy](dest_y + delta, src_y + delta, s->linesize); | |
| 1913 } | |
| 1914 | |
| 1915 if(s->flags&CODEC_FLAG_GRAY) return; | |
| 1916 | |
| 1917 if(emu){ | |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
1918 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 | 1919 src_cb= s->edge_emu_buffer; |
| 1920 } | |
| 1921 chroma_op(dest_cb, src_cb, s->uvlinesize, chroma_height, mx&7, my&7); | |
| 1922 | |
| 1923 if(emu){ | |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
1924 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 | 1925 src_cr= s->edge_emu_buffer; |
| 1926 } | |
| 1927 chroma_op(dest_cr, src_cr, s->uvlinesize, chroma_height, mx&7, my&7); | |
| 1928 } | |
| 1929 | |
| 1930 static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta, | |
| 1931 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
| 1932 int x_offset, int y_offset, | |
| 1933 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, | |
| 1934 qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, | |
| 1935 int list0, int list1){ | |
| 1936 MpegEncContext * const s = &h->s; | |
| 1937 qpel_mc_func *qpix_op= qpix_put; | |
| 1938 h264_chroma_mc_func chroma_op= chroma_put; | |
| 1939 | |
| 1940 dest_y += 2*x_offset + 2*y_offset*s-> linesize; | |
| 1941 dest_cb += x_offset + y_offset*s->uvlinesize; | |
| 1942 dest_cr += x_offset + y_offset*s->uvlinesize; | |
| 1943 x_offset += 8*s->mb_x; | |
| 1944 y_offset += 8*s->mb_y; | |
| 1945 | |
| 1946 if(list0){ | |
| 1169 | 1947 Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ]; |
| 1168 | 1948 mc_dir_part(h, ref, n, square, chroma_height, delta, 0, |
| 1949 dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 1950 qpix_op, chroma_op); | |
| 1951 | |
| 1952 qpix_op= qpix_avg; | |
| 1953 chroma_op= chroma_avg; | |
| 1954 } | |
| 1955 | |
| 1956 if(list1){ | |
| 1169 | 1957 Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ]; |
| 1168 | 1958 mc_dir_part(h, ref, n, square, chroma_height, delta, 1, |
| 1959 dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 1960 qpix_op, chroma_op); | |
| 1961 } | |
| 1962 } | |
| 1963 | |
| 1964 static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
| 1965 qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put), | |
| 1966 qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg)){ | |
| 1967 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
|
1968 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1168 | 1969 const int mb_type= s->current_picture.mb_type[mb_xy]; |
| 1970 | |
| 1971 assert(IS_INTER(mb_type)); | |
| 1972 | |
| 1973 if(IS_16X16(mb_type)){ | |
| 1974 mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0, | |
| 1975 qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0], | |
| 1976 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); | |
| 1977 }else if(IS_16X8(mb_type)){ | |
| 1978 mc_part(h, 0, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 0, | |
| 1979 qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0], | |
| 1980 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); | |
| 1981 mc_part(h, 8, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 4, | |
| 1982 qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0], | |
| 1983 IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1)); | |
| 1984 }else if(IS_8X16(mb_type)){ | |
| 1985 mc_part(h, 0, 0, 8, 8*s->linesize, dest_y, dest_cb, dest_cr, 0, 0, | |
| 1986 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
| 1987 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); | |
| 1988 mc_part(h, 4, 0, 8, 8*s->linesize, dest_y, dest_cb, dest_cr, 4, 0, | |
| 1989 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
| 1990 IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1)); | |
| 1991 }else{ | |
| 1992 int i; | |
| 1993 | |
| 1994 assert(IS_8X8(mb_type)); | |
| 1995 | |
| 1996 for(i=0; i<4; i++){ | |
| 1997 const int sub_mb_type= h->sub_mb_type[i]; | |
| 1998 const int n= 4*i; | |
| 1999 int x_offset= (i&1)<<2; | |
| 2000 int y_offset= (i&2)<<1; | |
| 2001 | |
| 2002 if(IS_SUB_8X8(sub_mb_type)){ | |
| 2003 mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2004 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
| 2005 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); | |
| 2006 }else if(IS_SUB_8X4(sub_mb_type)){ | |
| 2007 mc_part(h, n , 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2008 qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1], | |
| 2009 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); | |
| 2010 mc_part(h, n+2, 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset+2, | |
| 2011 qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1], | |
| 2012 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); | |
| 2013 }else if(IS_SUB_4X8(sub_mb_type)){ | |
| 2014 mc_part(h, n , 0, 4, 4*s->linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
| 2015 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
| 2016 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); | |
| 2017 mc_part(h, n+1, 0, 4, 4*s->linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset, | |
| 2018 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
| 2019 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); | |
| 2020 }else{ | |
| 2021 int j; | |
| 2022 assert(IS_SUB_4X4(sub_mb_type)); | |
| 2023 for(j=0; j<4; j++){ | |
| 2024 int sub_x_offset= x_offset + 2*(j&1); | |
| 2025 int sub_y_offset= y_offset + (j&2); | |
| 2026 mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset, | |
| 2027 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
| 2028 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); | |
| 2029 } | |
| 2030 } | |
| 2031 } | |
| 2032 } | |
| 2033 } | |
| 2034 | |
| 2035 static void decode_init_vlc(H264Context *h){ | |
| 2036 static int done = 0; | |
| 2037 | |
| 2038 if (!done) { | |
| 2039 int i; | |
| 2040 done = 1; | |
| 2041 | |
| 2042 init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5, | |
| 2043 &chroma_dc_coeff_token_len [0], 1, 1, | |
| 2044 &chroma_dc_coeff_token_bits[0], 1, 1); | |
| 2045 | |
| 2046 for(i=0; i<4; i++){ | |
| 2047 init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17, | |
| 2048 &coeff_token_len [i][0], 1, 1, | |
| 2049 &coeff_token_bits[i][0], 1, 1); | |
| 2050 } | |
| 2051 | |
| 2052 for(i=0; i<3; i++){ | |
| 2053 init_vlc(&chroma_dc_total_zeros_vlc[i], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4, | |
| 2054 &chroma_dc_total_zeros_len [i][0], 1, 1, | |
| 2055 &chroma_dc_total_zeros_bits[i][0], 1, 1); | |
| 2056 } | |
| 2057 for(i=0; i<15; i++){ | |
| 2058 init_vlc(&total_zeros_vlc[i], TOTAL_ZEROS_VLC_BITS, 16, | |
| 2059 &total_zeros_len [i][0], 1, 1, | |
| 2060 &total_zeros_bits[i][0], 1, 1); | |
| 2061 } | |
| 2062 | |
| 2063 for(i=0; i<6; i++){ | |
| 2064 init_vlc(&run_vlc[i], RUN_VLC_BITS, 7, | |
| 2065 &run_len [i][0], 1, 1, | |
| 2066 &run_bits[i][0], 1, 1); | |
| 2067 } | |
| 2068 init_vlc(&run7_vlc, RUN7_VLC_BITS, 16, | |
| 2069 &run_len [6][0], 1, 1, | |
| 2070 &run_bits[6][0], 1, 1); | |
| 2071 } | |
| 2072 } | |
| 2073 | |
| 2074 /** | |
| 2075 * Sets the intra prediction function pointers. | |
| 2076 */ | |
| 2077 static void init_pred_ptrs(H264Context *h){ | |
| 2078 // MpegEncContext * const s = &h->s; | |
| 2079 | |
| 2080 h->pred4x4[VERT_PRED ]= pred4x4_vertical_c; | |
| 2081 h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c; | |
| 2082 h->pred4x4[DC_PRED ]= pred4x4_dc_c; | |
| 2083 h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c; | |
| 2084 h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c; | |
| 2085 h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c; | |
| 2086 h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c; | |
| 2087 h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c; | |
| 2088 h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c; | |
| 2089 h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c; | |
| 2090 h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c; | |
| 2091 h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c; | |
| 2092 | |
| 2093 h->pred8x8[DC_PRED8x8 ]= pred8x8_dc_c; | |
| 2094 h->pred8x8[VERT_PRED8x8 ]= pred8x8_vertical_c; | |
| 2095 h->pred8x8[HOR_PRED8x8 ]= pred8x8_horizontal_c; | |
| 2096 h->pred8x8[PLANE_PRED8x8 ]= pred8x8_plane_c; | |
| 2097 h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c; | |
| 2098 h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c; | |
| 2099 h->pred8x8[DC_128_PRED8x8 ]= pred8x8_128_dc_c; | |
| 2100 | |
| 2101 h->pred16x16[DC_PRED8x8 ]= pred16x16_dc_c; | |
| 2102 h->pred16x16[VERT_PRED8x8 ]= pred16x16_vertical_c; | |
| 2103 h->pred16x16[HOR_PRED8x8 ]= pred16x16_horizontal_c; | |
| 2104 h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_c; | |
| 2105 h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c; | |
| 2106 h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c; | |
| 2107 h->pred16x16[DC_128_PRED8x8 ]= pred16x16_128_dc_c; | |
| 2108 } | |
| 2109 | |
| 2110 static void free_tables(H264Context *h){ | |
| 2111 av_freep(&h->intra4x4_pred_mode); | |
| 2112 av_freep(&h->non_zero_count); | |
| 2113 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
|
2114 av_freep(&h->top_border); |
| 1168 | 2115 h->slice_table= NULL; |
| 2116 | |
| 2117 av_freep(&h->mb2b_xy); | |
| 2118 av_freep(&h->mb2b8_xy); | |
| 2119 } | |
| 2120 | |
| 2121 /** | |
| 2122 * allocates tables. | |
| 2123 * needs widzh/height | |
| 2124 */ | |
| 2125 static int alloc_tables(H264Context *h){ | |
| 2126 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
|
2127 const int big_mb_num= s->mb_stride * (s->mb_height+1); |
| 1168 | 2128 int x,y; |
| 2129 | |
| 2130 CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * 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
|
2131 CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t)) |
| 1168 | 2132 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
|
2133 CHECKED_ALLOCZ(h->top_border , s->mb_width * (16+8+8) * sizeof(uint8_t)) |
| 1168 | 2134 |
| 2135 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
|
2136 h->slice_table= h->slice_table_base + s->mb_stride + 1; |
| 1168 | 2137 |
| 2138 CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint16_t)); | |
| 2139 CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint16_t)); | |
| 2140 for(y=0; y<s->mb_height; y++){ | |
| 2141 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
|
2142 const int mb_xy= x + y*s->mb_stride; |
| 1168 | 2143 const int b_xy = 4*x + 4*y*h->b_stride; |
| 2144 const int b8_xy= 2*x + 2*y*h->b8_stride; | |
| 2145 | |
| 2146 h->mb2b_xy [mb_xy]= b_xy; | |
| 2147 h->mb2b8_xy[mb_xy]= b8_xy; | |
| 2148 } | |
| 2149 } | |
| 2150 | |
| 2151 return 0; | |
| 2152 fail: | |
| 2153 free_tables(h); | |
| 2154 return -1; | |
| 2155 } | |
| 2156 | |
| 2157 static void common_init(H264Context *h){ | |
| 2158 MpegEncContext * const s = &h->s; | |
| 2159 | |
| 2160 s->width = s->avctx->width; | |
| 2161 s->height = s->avctx->height; | |
| 2162 s->codec_id= s->avctx->codec->id; | |
| 2163 | |
| 2164 init_pred_ptrs(h); | |
| 2165 | |
| 1698 | 2166 s->unrestricted_mv=1; |
| 1168 | 2167 s->decode=1; //FIXME |
| 2168 } | |
| 2169 | |
| 2170 static int decode_init(AVCodecContext *avctx){ | |
| 2171 H264Context *h= avctx->priv_data; | |
| 2172 MpegEncContext * const s = &h->s; | |
| 2173 | |
| 1892 | 2174 MPV_decode_defaults(s); |
| 2175 | |
| 1168 | 2176 s->avctx = avctx; |
| 2177 common_init(h); | |
| 2178 | |
| 2179 s->out_format = FMT_H264; | |
| 2180 s->workaround_bugs= avctx->workaround_bugs; | |
| 2181 | |
| 2182 // set defaults | |
| 2183 // s->decode_mb= ff_h263_decode_mb; | |
| 2184 s->low_delay= 1; | |
| 2185 avctx->pix_fmt= PIX_FMT_YUV420P; | |
| 2186 | |
| 2187 decode_init_vlc(h); | |
| 2188 | |
| 2189 return 0; | |
| 2190 } | |
| 2191 | |
| 2192 static void frame_start(H264Context *h){ | |
| 2193 MpegEncContext * const s = &h->s; | |
| 2194 int i; | |
| 2195 | |
| 2196 MPV_frame_start(s, s->avctx); | |
| 2197 ff_er_frame_start(s); | |
| 2198 h->mmco_index=0; | |
| 2199 | |
| 2200 assert(s->linesize && s->uvlinesize); | |
| 2201 | |
| 2202 for(i=0; i<16; i++){ | |
| 2203 h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3); | |
| 2204 h->chroma_subblock_offset[i]= 2*((scan8[i] - scan8[0])&7) + 2*s->uvlinesize*((scan8[i] - scan8[0])>>3); | |
| 2205 } | |
| 2206 for(i=0; i<4; i++){ | |
| 2207 h->block_offset[16+i]= | |
| 2208 h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3); | |
| 2209 } | |
| 2210 | |
| 2211 // s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1; | |
| 2212 } | |
| 2213 | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2214 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
|
2215 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
|
2216 int i; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2217 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2218 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
|
2219 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
|
2220 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
|
2221 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2222 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
|
2223 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
|
2224 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
|
2225 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2226 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2227 *(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
|
2228 *(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
|
2229 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2230 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
|
2231 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
|
2232 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
|
2233 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
|
2234 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
|
2235 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
|
2236 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2237 *(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
|
2238 *(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
|
2239 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2240 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2241 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2242 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
|
2243 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
|
2244 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
|
2245 uint64_t temp64; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2246 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2247 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
|
2248 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
|
2249 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
|
2250 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2251 #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
|
2252 t= a;\ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2253 if(xchg)\ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2254 a= b;\ |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2255 b= t; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2256 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2257 for(i=0; 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
|
2258 XCHG(h->left_border[i ], src_y [i* linesize], temp8, xchg); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2259 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2260 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2261 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2262 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2263 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2264 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
|
2265 for(i=0; 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
|
2266 XCHG(h->left_border[i+17 ], src_cb[i*uvlinesize], temp8, xchg); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2267 XCHG(h->left_border[i+17+9], src_cr[i*uvlinesize], temp8, xchg); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2268 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2269 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2270 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2271 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2272 } |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2273 |
| 1168 | 2274 static void hl_decode_mb(H264Context *h){ |
| 2275 MpegEncContext * const s = &h->s; | |
| 2276 const int mb_x= s->mb_x; | |
| 2277 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
|
2278 const int mb_xy= mb_x + mb_y*s->mb_stride; |
| 1168 | 2279 const int mb_type= s->current_picture.mb_type[mb_xy]; |
| 2280 uint8_t *dest_y, *dest_cb, *dest_cr; | |
| 2281 int linesize, uvlinesize /*dct_offset*/; | |
| 2282 int i; | |
| 2283 | |
| 2284 if(!s->decode) | |
| 2285 return; | |
| 2286 | |
| 2287 if(s->mb_skiped){ | |
| 2288 } | |
| 2289 | |
| 2290 dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16; | |
| 2291 dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
| 2292 dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
| 2293 | |
| 2294 if (h->mb_field_decoding_flag) { | |
| 2295 linesize = s->linesize * 2; | |
| 2296 uvlinesize = s->uvlinesize * 2; | |
| 2297 if(mb_y&1){ //FIXME move out of this func? | |
| 2298 dest_y -= s->linesize*15; | |
| 2299 dest_cb-= s->linesize*7; | |
| 2300 dest_cr-= s->linesize*7; | |
| 2301 } | |
| 2302 } else { | |
| 2303 linesize = s->linesize; | |
| 2304 uvlinesize = s->uvlinesize; | |
| 2305 // dct_offset = s->linesize * 16; | |
| 2306 } | |
| 2307 | |
| 2308 if(IS_INTRA(mb_type)){ | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2309 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
|
2310 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2311 |
| 1168 | 2312 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 2313 h->pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize); | |
| 2314 h->pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize); | |
| 2315 } | |
| 2316 | |
| 2317 if(IS_INTRA4x4(mb_type)){ | |
| 2318 if(!s->encoding){ | |
| 2319 for(i=0; i<16; i++){ | |
| 2320 uint8_t * const ptr= dest_y + h->block_offset[i]; | |
| 2321 uint8_t *topright= ptr + 4 - linesize; | |
| 2322 const int topright_avail= (h->topright_samples_available<<i)&0x8000; | |
| 2323 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; | |
| 2324 int tr; | |
| 2325 | |
| 2326 if(!topright_avail){ | |
| 2327 tr= ptr[3 - linesize]*0x01010101; | |
| 2328 topright= (uint8_t*) &tr; | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2329 }else if(i==5 && 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
|
2330 tr= *(uint32_t*)h->top_border[mb_x+1]; |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2331 topright= (uint8_t*) &tr; |
| 1168 | 2332 } |
| 2333 | |
| 2334 h->pred4x4[ dir ](ptr, topright, linesize); | |
| 1234 | 2335 if(h->non_zero_count_cache[ scan8[i] ]){ |
| 2336 if(s->codec_id == CODEC_ID_H264) | |
| 2337 h264_add_idct_c(ptr, h->mb + i*16, linesize); | |
| 2338 else | |
| 2339 svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0); | |
| 2340 } | |
| 1168 | 2341 } |
| 2342 } | |
| 2343 }else{ | |
| 2344 h->pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize); | |
| 1234 | 2345 if(s->codec_id == CODEC_ID_H264) |
| 2346 h264_luma_dc_dequant_idct_c(h->mb, s->qscale); | |
| 2347 else | |
| 2348 svq3_luma_dc_dequant_idct_c(h->mb, s->qscale); | |
| 1168 | 2349 } |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2350 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
|
2351 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0); |
| 1234 | 2352 }else if(s->codec_id == CODEC_ID_H264){ |
| 1168 | 2353 hl_motion(h, dest_y, dest_cb, dest_cr, |
| 2354 s->dsp.put_h264_qpel_pixels_tab, s->dsp.put_h264_chroma_pixels_tab, | |
| 2355 s->dsp.avg_h264_qpel_pixels_tab, s->dsp.avg_h264_chroma_pixels_tab); | |
| 2356 } | |
| 2357 | |
| 2358 | |
| 2359 if(!IS_INTRA4x4(mb_type)){ | |
| 1250 | 2360 if(s->codec_id == CODEC_ID_H264){ |
| 2361 for(i=0; i<16; i++){ | |
| 2362 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below | |
| 2363 uint8_t * const ptr= dest_y + h->block_offset[i]; | |
| 1234 | 2364 h264_add_idct_c(ptr, h->mb + i*16, linesize); |
| 1250 | 2365 } |
| 2366 } | |
| 2367 }else{ | |
| 2368 for(i=0; i<16; i++){ | |
| 2369 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below | |
| 2370 uint8_t * const ptr= dest_y + h->block_offset[i]; | |
| 1234 | 2371 svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0); |
| 1250 | 2372 } |
| 1168 | 2373 } |
| 2374 } | |
| 2375 } | |
| 2376 | |
| 2377 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
| 2378 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp); | |
| 2379 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp); | |
| 1250 | 2380 if(s->codec_id == CODEC_ID_H264){ |
| 2381 for(i=16; i<16+4; i++){ | |
| 2382 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ | |
| 2383 uint8_t * const ptr= dest_cb + h->block_offset[i]; | |
| 1234 | 2384 h264_add_idct_c(ptr, h->mb + i*16, uvlinesize); |
| 1250 | 2385 } |
| 2386 } | |
| 2387 for(i=20; i<20+4; i++){ | |
| 2388 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ | |
| 2389 uint8_t * const ptr= dest_cr + h->block_offset[i]; | |
| 2390 h264_add_idct_c(ptr, h->mb + i*16, uvlinesize); | |
| 2391 } | |
| 1168 | 2392 } |
| 1250 | 2393 }else{ |
| 2394 for(i=16; i<16+4; i++){ | |
| 2395 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ | |
| 2396 uint8_t * const ptr= dest_cb + h->block_offset[i]; | |
| 1234 | 2397 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); |
| 1250 | 2398 } |
| 2399 } | |
| 2400 for(i=20; i<20+4; i++){ | |
| 2401 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ | |
| 2402 uint8_t * const ptr= dest_cr + h->block_offset[i]; | |
| 2403 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); | |
| 2404 } | |
| 1168 | 2405 } |
| 2406 } | |
| 2407 } | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2408 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
|
2409 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize); |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2410 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
|
2411 } |
| 1168 | 2412 } |
| 2413 | |
| 2414 static void decode_mb_cabac(H264Context *h){ | |
| 2415 // MpegEncContext * const s = &h->s; | |
| 2416 } | |
| 2417 | |
| 2418 /** | |
| 2419 * fills the default_ref_list. | |
| 2420 */ | |
| 2421 static int fill_default_ref_list(H264Context *h){ | |
| 2422 MpegEncContext * const s = &h->s; | |
| 2423 int i; | |
| 2424 Picture sorted_short_ref[16]; | |
| 2425 | |
| 2426 if(h->slice_type==B_TYPE){ | |
| 2427 int out_i; | |
| 2428 int limit= -1; | |
| 2429 | |
| 2430 for(out_i=0; out_i<h->short_ref_count; out_i++){ | |
| 2431 int best_i=-1; | |
| 2432 int best_poc=-1; | |
| 2433 | |
| 2434 for(i=0; i<h->short_ref_count; i++){ | |
| 2435 const int poc= h->short_ref[i]->poc; | |
| 2436 if(poc > limit && poc < best_poc){ | |
| 2437 best_poc= poc; | |
| 2438 best_i= i; | |
| 2439 } | |
| 2440 } | |
| 2441 | |
| 2442 assert(best_i != -1); | |
| 2443 | |
| 2444 limit= best_poc; | |
| 2445 sorted_short_ref[out_i]= *h->short_ref[best_i]; | |
| 2446 } | |
| 2447 } | |
| 2448 | |
| 2449 if(s->picture_structure == PICT_FRAME){ | |
| 2450 if(h->slice_type==B_TYPE){ | |
| 2451 const int current_poc= s->current_picture_ptr->poc; | |
| 2452 int list; | |
| 2453 | |
| 2454 for(list=0; list<2; list++){ | |
| 2455 int index=0; | |
| 2456 | |
| 2457 for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++){ | |
| 2458 const int i2= list ? h->short_ref_count - i - 1 : i; | |
| 2459 const int poc= sorted_short_ref[i2].poc; | |
| 2460 | |
| 2461 if(sorted_short_ref[i2].reference != 3) continue; //FIXME refernce field shit | |
| 2462 | |
| 2463 if((list==1 && poc > current_poc) || (list==0 && poc < current_poc)){ | |
| 2464 h->default_ref_list[list][index ]= sorted_short_ref[i2]; | |
| 2465 h->default_ref_list[list][index++].pic_id= sorted_short_ref[i2].frame_num; | |
| 2466 } | |
| 2467 } | |
| 2468 | |
| 2469 for(i=0; i<h->long_ref_count && index < h->ref_count[ list ]; i++){ | |
| 2470 if(h->long_ref[i]->reference != 3) continue; | |
| 2471 | |
| 2472 h->default_ref_list[ list ][index ]= *h->long_ref[i]; | |
| 2473 h->default_ref_list[ list ][index++].pic_id= i;; | |
| 2474 } | |
| 2475 | |
| 2476 if(h->long_ref_count > 1 && h->short_ref_count==0){ | |
| 2477 Picture temp= h->default_ref_list[1][0]; | |
| 2478 h->default_ref_list[1][0] = h->default_ref_list[1][1]; | |
| 2479 h->default_ref_list[1][0] = temp; | |
| 2480 } | |
| 2481 | |
| 2482 if(index < h->ref_count[ list ]) | |
| 2483 memset(&h->default_ref_list[list][index], 0, sizeof(Picture)*(h->ref_count[ list ] - index)); | |
| 2484 } | |
| 2485 }else{ | |
| 2486 int index=0; | |
| 2487 for(i=0; i<h->short_ref_count && index < h->ref_count[0]; i++){ | |
| 2488 if(h->short_ref[i]->reference != 3) continue; //FIXME refernce field shit | |
| 2489 h->default_ref_list[0][index ]= *h->short_ref[i]; | |
| 2490 h->default_ref_list[0][index++].pic_id= h->short_ref[i]->frame_num; | |
| 2491 } | |
| 2492 for(i=0; i<h->long_ref_count && index < h->ref_count[0]; i++){ | |
| 2493 if(h->long_ref[i]->reference != 3) continue; | |
| 2494 h->default_ref_list[0][index ]= *h->long_ref[i]; | |
| 2495 h->default_ref_list[0][index++].pic_id= i;; | |
| 2496 } | |
| 2497 if(index < h->ref_count[0]) | |
| 2498 memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index)); | |
| 2499 } | |
| 2500 }else{ //FIELD | |
| 2501 if(h->slice_type==B_TYPE){ | |
| 2502 }else{ | |
| 2503 //FIXME second field balh | |
| 2504 } | |
| 2505 } | |
| 2506 return 0; | |
| 2507 } | |
| 2508 | |
| 2509 static int decode_ref_pic_list_reordering(H264Context *h){ | |
| 2510 MpegEncContext * const s = &h->s; | |
| 2511 int list; | |
| 2512 | |
| 2513 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move beofre func | |
| 2514 | |
| 2515 for(list=0; list<2; list++){ | |
| 2516 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); | |
| 2517 | |
| 2518 if(get_bits1(&s->gb)){ | |
| 2519 int pred= h->curr_pic_num; | |
| 2520 int index; | |
| 2521 | |
| 2522 for(index=0; ; index++){ | |
| 2523 int reordering_of_pic_nums_idc= get_ue_golomb(&s->gb); | |
| 2524 int pic_id; | |
| 2525 int i; | |
| 2526 | |
| 2527 | |
| 2528 if(index >= h->ref_count[list]){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
2529 av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); |
| 1168 | 2530 return -1; |
| 2531 } | |
| 2532 | |
| 2533 if(reordering_of_pic_nums_idc<3){ | |
| 2534 if(reordering_of_pic_nums_idc<2){ | |
| 2535 const int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; | |
| 2536 | |
| 2537 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
|
2538 av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); |
| 1168 | 2539 return -1; |
| 2540 } | |
| 2541 | |
| 2542 if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num; | |
| 2543 else pred+= abs_diff_pic_num; | |
| 2544 pred &= h->max_pic_num - 1; | |
| 2545 | |
| 2546 for(i= h->ref_count[list]-1; i>=index; i--){ | |
| 2547 if(h->ref_list[list][i].pic_id == pred && h->ref_list[list][i].long_ref==0) | |
| 2548 break; | |
| 2549 } | |
| 2550 }else{ | |
| 2551 pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx | |
| 2552 | |
| 2553 for(i= h->ref_count[list]-1; i>=index; i--){ | |
| 2554 if(h->ref_list[list][i].pic_id == pic_id && h->ref_list[list][i].long_ref==1) | |
| 2555 break; | |
| 2556 } | |
| 2557 } | |
| 2558 | |
| 2559 if(i < index){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
2560 av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); |
| 1168 | 2561 memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME |
| 2562 }else if(i > index){ | |
| 2563 Picture tmp= h->ref_list[list][i]; | |
| 2564 for(; i>index; i--){ | |
| 2565 h->ref_list[list][i]= h->ref_list[list][i-1]; | |
| 2566 } | |
| 2567 h->ref_list[list][index]= tmp; | |
| 2568 } | |
| 2569 }else if(reordering_of_pic_nums_idc==3) | |
| 2570 break; | |
| 2571 else{ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
2572 av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); |
| 1168 | 2573 return -1; |
| 2574 } | |
| 2575 } | |
| 2576 } | |
| 2577 | |
| 2578 if(h->slice_type!=B_TYPE) break; | |
| 2579 } | |
| 2580 return 0; | |
| 2581 } | |
| 2582 | |
| 2583 static int pred_weight_table(H264Context *h){ | |
| 2584 MpegEncContext * const s = &h->s; | |
| 2585 int list, i; | |
| 2586 | |
| 2587 h->luma_log2_weight_denom= get_ue_golomb(&s->gb); | |
| 2588 h->chroma_log2_weight_denom= get_ue_golomb(&s->gb); | |
| 2589 | |
| 2590 for(list=0; list<2; list++){ | |
| 2591 for(i=0; i<h->ref_count[list]; i++){ | |
| 2592 int luma_weight_flag, chroma_weight_flag; | |
| 2593 | |
| 2594 luma_weight_flag= get_bits1(&s->gb); | |
| 2595 if(luma_weight_flag){ | |
| 2596 h->luma_weight[list][i]= get_se_golomb(&s->gb); | |
| 2597 h->luma_offset[list][i]= get_se_golomb(&s->gb); | |
| 2598 } | |
| 2599 | |
| 2600 chroma_weight_flag= get_bits1(&s->gb); | |
| 2601 if(chroma_weight_flag){ | |
| 2602 int j; | |
| 2603 for(j=0; j<2; j++){ | |
| 2604 h->chroma_weight[list][i][j]= get_se_golomb(&s->gb); | |
| 2605 h->chroma_offset[list][i][j]= get_se_golomb(&s->gb); | |
| 2606 } | |
| 2607 } | |
| 2608 } | |
| 2609 if(h->slice_type != B_TYPE) break; | |
| 2610 } | |
| 2611 return 0; | |
| 2612 } | |
| 2613 | |
| 2614 /** | |
| 2615 * instantaneos decoder refresh. | |
| 2616 */ | |
| 2617 static void idr(H264Context *h){ | |
| 2618 int i; | |
| 2619 | |
| 2620 for(i=0; i<h->long_ref_count; i++){ | |
| 2621 h->long_ref[i]->reference=0; | |
| 2622 h->long_ref[i]= NULL; | |
| 2623 } | |
| 2624 h->long_ref_count=0; | |
| 2625 | |
| 2626 for(i=0; i<h->short_ref_count; i++){ | |
| 2627 h->short_ref[i]->reference=0; | |
| 2628 h->short_ref[i]= NULL; | |
| 2629 } | |
| 2630 h->short_ref_count=0; | |
| 2631 } | |
| 2632 | |
| 2633 /** | |
| 2634 * | |
| 2635 * @return the removed picture or NULL if an error occures | |
| 2636 */ | |
| 2637 static Picture * remove_short(H264Context *h, int frame_num){ | |
| 1169 | 2638 MpegEncContext * const s = &h->s; |
| 1168 | 2639 int i; |
| 2640 | |
| 1169 | 2641 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
|
2642 av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); |
| 1169 | 2643 |
| 1168 | 2644 for(i=0; i<h->short_ref_count; i++){ |
| 2645 Picture *pic= h->short_ref[i]; | |
| 1169 | 2646 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
|
2647 av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); |
| 1168 | 2648 if(pic->frame_num == frame_num){ |
| 2649 h->short_ref[i]= NULL; | |
| 2650 memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*)); | |
| 2651 h->short_ref_count--; | |
| 2652 return pic; | |
| 2653 } | |
| 2654 } | |
| 2655 return NULL; | |
| 2656 } | |
| 2657 | |
| 2658 /** | |
| 2659 * | |
| 2660 * @return the removed picture or NULL if an error occures | |
| 2661 */ | |
| 2662 static Picture * remove_long(H264Context *h, int i){ | |
| 2663 Picture *pic; | |
| 2664 | |
| 2665 if(i >= h->long_ref_count) return NULL; | |
| 2666 pic= h->long_ref[i]; | |
| 2667 if(pic==NULL) return NULL; | |
| 2668 | |
| 2669 h->long_ref[i]= NULL; | |
| 2670 memmove(&h->long_ref[i], &h->long_ref[i+1], (h->long_ref_count - i - 1)*sizeof(Picture*)); | |
| 2671 h->long_ref_count--; | |
| 2672 | |
| 2673 return pic; | |
| 2674 } | |
| 2675 | |
| 2676 /** | |
| 2677 * Executes the reference picture marking (memory management control operations). | |
| 2678 */ | |
| 2679 static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |
| 2680 MpegEncContext * const s = &h->s; | |
| 2681 int i; | |
| 2682 int current_is_long=0; | |
| 2683 Picture *pic; | |
| 2684 | |
| 2685 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
|
2686 av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); |
| 1168 | 2687 |
| 2688 for(i=0; i<mmco_count; i++){ | |
| 2689 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
|
2690 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 | 2691 |
| 2692 switch(mmco[i].opcode){ | |
| 2693 case MMCO_SHORT2UNUSED: | |
| 2694 pic= remove_short(h, mmco[i].short_frame_num); | |
| 2695 if(pic==NULL) return -1; | |
| 2696 pic->reference= 0; | |
| 2697 break; | |
| 2698 case MMCO_SHORT2LONG: | |
| 2699 pic= remove_long(h, mmco[i].long_index); | |
| 2700 if(pic) pic->reference=0; | |
| 2701 | |
| 2702 h->long_ref[ mmco[i].long_index ]= remove_short(h, mmco[i].short_frame_num); | |
| 2703 h->long_ref[ mmco[i].long_index ]->long_ref=1; | |
| 2704 break; | |
| 2705 case MMCO_LONG2UNUSED: | |
| 2706 pic= remove_long(h, mmco[i].long_index); | |
| 2707 if(pic==NULL) return -1; | |
| 2708 pic->reference= 0; | |
| 2709 break; | |
| 2710 case MMCO_LONG: | |
| 2711 pic= remove_long(h, mmco[i].long_index); | |
| 2712 if(pic) pic->reference=0; | |
| 2713 | |
| 2714 h->long_ref[ mmco[i].long_index ]= s->current_picture_ptr; | |
| 2715 h->long_ref[ mmco[i].long_index ]->long_ref=1; | |
| 2716 h->long_ref_count++; | |
| 2717 | |
| 2718 current_is_long=1; | |
| 2719 break; | |
| 2720 case MMCO_SET_MAX_LONG: | |
| 2721 assert(mmco[i].long_index <= 16); | |
| 2722 while(mmco[i].long_index < h->long_ref_count){ | |
| 2723 pic= remove_long(h, mmco[i].long_index); | |
| 2724 pic->reference=0; | |
| 2725 } | |
| 2726 while(mmco[i].long_index > h->long_ref_count){ | |
| 2727 h->long_ref[ h->long_ref_count++ ]= NULL; | |
| 2728 } | |
| 2729 break; | |
| 2730 case MMCO_RESET: | |
| 2731 while(h->short_ref_count){ | |
| 2732 pic= remove_short(h, h->short_ref[0]->frame_num); | |
| 2733 pic->reference=0; | |
| 2734 } | |
| 2735 while(h->long_ref_count){ | |
| 2736 pic= remove_long(h, h->long_ref_count-1); | |
| 2737 pic->reference=0; | |
| 2738 } | |
| 2739 break; | |
| 2740 default: assert(0); | |
| 2741 } | |
| 2742 } | |
| 2743 | |
| 2744 if(!current_is_long){ | |
| 2745 pic= remove_short(h, s->current_picture_ptr->frame_num); | |
| 2746 if(pic){ | |
| 2747 pic->reference=0; | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
2748 av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); |
| 1168 | 2749 } |
| 2750 | |
| 2751 if(h->short_ref_count) | |
| 1169 | 2752 memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); |
| 2753 | |
| 2754 h->short_ref[0]= s->current_picture_ptr; | |
| 1168 | 2755 h->short_ref[0]->long_ref=0; |
| 2756 h->short_ref_count++; | |
| 2757 } | |
| 2758 | |
| 2759 return 0; | |
| 2760 } | |
| 2761 | |
| 2762 static int decode_ref_pic_marking(H264Context *h){ | |
| 2763 MpegEncContext * const s = &h->s; | |
| 2764 int i; | |
| 2765 | |
| 2766 if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields | |
| 2767 s->broken_link= get_bits1(&s->gb) -1; | |
| 2768 h->mmco[0].long_index= get_bits1(&s->gb) - 1; // current_long_term_idx | |
| 2769 if(h->mmco[0].long_index == -1) | |
| 2770 h->mmco_index= 0; | |
| 2771 else{ | |
| 2772 h->mmco[0].opcode= MMCO_LONG; | |
| 2773 h->mmco_index= 1; | |
| 2774 } | |
| 2775 }else{ | |
| 2776 if(get_bits1(&s->gb)){ // adaptive_ref_pic_marking_mode_flag | |
| 2777 for(i= h->mmco_index; i<MAX_MMCO_COUNT; i++) { | |
| 2778 MMCOOpcode opcode= get_ue_golomb(&s->gb);; | |
| 2779 | |
| 2780 h->mmco[i].opcode= opcode; | |
| 2781 if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){ | |
| 2782 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 | |
| 2783 /* if(h->mmco[i].short_frame_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_frame_num ] == NULL){ | |
| 2784 fprintf(stderr, "illegal short ref in memory management control operation %d\n", mmco); | |
| 2785 return -1; | |
| 2786 }*/ | |
| 2787 } | |
| 2788 if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){ | |
| 2789 h->mmco[i].long_index= get_ue_golomb(&s->gb); | |
| 2790 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
|
2791 av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); |
| 1168 | 2792 return -1; |
| 2793 } | |
| 2794 } | |
| 2795 | |
| 2796 if(opcode > MMCO_LONG){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
2797 av_log(h->s.avctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", opcode); |
| 1168 | 2798 return -1; |
| 2799 } | |
| 2800 } | |
| 2801 h->mmco_index= i; | |
| 2802 }else{ | |
| 2803 assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); | |
| 2804 | |
| 2805 if(h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count){ //FIXME fields | |
| 2806 h->mmco[0].opcode= MMCO_SHORT2UNUSED; | |
| 2807 h->mmco[0].short_frame_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num; | |
| 2808 h->mmco_index= 1; | |
| 2809 }else | |
| 2810 h->mmco_index= 0; | |
| 2811 } | |
| 2812 } | |
| 2813 | |
| 2814 return 0; | |
| 2815 } | |
| 2816 | |
| 2817 static int init_poc(H264Context *h){ | |
| 2818 MpegEncContext * const s = &h->s; | |
| 2819 const int max_frame_num= 1<<h->sps.log2_max_frame_num; | |
| 2820 int field_poc[2]; | |
| 2821 | |
| 2822 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
| 2823 h->frame_num_offset= 0; | |
| 2824 }else{ | |
| 2825 if(h->frame_num < h->prev_frame_num) | |
| 2826 h->frame_num_offset= h->prev_frame_num_offset + max_frame_num; | |
| 2827 else | |
| 2828 h->frame_num_offset= h->prev_frame_num_offset; | |
| 2829 } | |
| 2830 | |
| 2831 if(h->sps.poc_type==0){ | |
| 2832 const int max_poc_lsb= 1<<h->sps.log2_max_poc_lsb; | |
| 2833 | |
| 2834 if (h->poc_lsb < h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb/2) | |
| 2835 h->poc_msb = h->prev_poc_msb + max_poc_lsb; | |
| 2836 else if(h->poc_lsb > h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb/2) | |
| 2837 h->poc_msb = h->prev_poc_msb - max_poc_lsb; | |
| 2838 else | |
| 2839 h->poc_msb = h->prev_poc_msb; | |
| 2840 //printf("poc: %d %d\n", h->poc_msb, h->poc_lsb); | |
| 2841 field_poc[0] = | |
| 2842 field_poc[1] = h->poc_msb + h->poc_lsb; | |
| 2843 if(s->picture_structure == PICT_FRAME) | |
| 2844 field_poc[1] += h->delta_poc_bottom; | |
| 2845 }else if(h->sps.poc_type==1){ | |
| 2846 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc; | |
| 2847 int i; | |
| 2848 | |
| 2849 if(h->sps.poc_cycle_length != 0) | |
| 2850 abs_frame_num = h->frame_num_offset + h->frame_num; | |
| 2851 else | |
| 2852 abs_frame_num = 0; | |
| 2853 | |
| 2854 if(h->nal_ref_idc==0 && abs_frame_num > 0) | |
| 2855 abs_frame_num--; | |
| 2856 | |
| 2857 expected_delta_per_poc_cycle = 0; | |
| 2858 for(i=0; i < h->sps.poc_cycle_length; i++) | |
| 2859 expected_delta_per_poc_cycle += h->sps.offset_for_ref_frame[ i ]; //FIXME integrate during sps parse | |
| 2860 | |
| 2861 if(abs_frame_num > 0){ | |
| 2862 int poc_cycle_cnt = (abs_frame_num - 1) / h->sps.poc_cycle_length; | |
| 2863 int frame_num_in_poc_cycle = (abs_frame_num - 1) % h->sps.poc_cycle_length; | |
| 2864 | |
| 2865 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle; | |
| 2866 for(i = 0; i <= frame_num_in_poc_cycle; i++) | |
| 2867 expectedpoc = expectedpoc + h->sps.offset_for_ref_frame[ i ]; | |
| 2868 } else | |
| 2869 expectedpoc = 0; | |
| 2870 | |
| 2871 if(h->nal_ref_idc == 0) | |
| 2872 expectedpoc = expectedpoc + h->sps.offset_for_non_ref_pic; | |
| 2873 | |
| 2874 field_poc[0] = expectedpoc + h->delta_poc[0]; | |
| 2875 field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field; | |
| 2876 | |
| 2877 if(s->picture_structure == PICT_FRAME) | |
| 2878 field_poc[1] += h->delta_poc[1]; | |
| 2879 }else{ | |
| 2880 int poc; | |
| 2881 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
| 2882 poc= 0; | |
| 2883 }else{ | |
| 2884 if(h->nal_ref_idc) poc= 2*(h->frame_num_offset + h->frame_num); | |
| 2885 else poc= 2*(h->frame_num_offset + h->frame_num) - 1; | |
| 2886 } | |
| 2887 field_poc[0]= poc; | |
| 2888 field_poc[1]= poc; | |
| 2889 } | |
| 2890 | |
| 2891 if(s->picture_structure != PICT_BOTTOM_FIELD) | |
| 2892 s->current_picture_ptr->field_poc[0]= field_poc[0]; | |
| 2893 if(s->picture_structure != PICT_TOP_FIELD) | |
| 2894 s->current_picture_ptr->field_poc[1]= field_poc[1]; | |
| 2895 if(s->picture_structure == PICT_FRAME) // FIXME field pix? | |
| 2896 s->current_picture_ptr->poc= FFMIN(field_poc[0], field_poc[1]); | |
| 2897 | |
| 2898 return 0; | |
| 2899 } | |
| 2900 | |
| 2901 /** | |
| 2902 * decodes a slice header. | |
| 2903 * this will allso call MPV_common_init() and frame_start() as needed | |
| 2904 */ | |
| 2905 static int decode_slice_header(H264Context *h){ | |
| 2906 MpegEncContext * const s = &h->s; | |
| 2907 int first_mb_in_slice, pps_id; | |
| 2908 int num_ref_idx_active_override_flag; | |
| 2909 static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; | |
| 2910 | |
| 2911 s->current_picture.reference= h->nal_ref_idc != 0; | |
| 2912 | |
| 2913 first_mb_in_slice= get_ue_golomb(&s->gb); | |
| 2914 | |
| 2915 h->slice_type= get_ue_golomb(&s->gb); | |
| 2916 if(h->slice_type > 9){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
2917 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); |
| 1168 | 2918 } |
| 2919 if(h->slice_type > 4){ | |
| 2920 h->slice_type -= 5; | |
| 2921 h->slice_type_fixed=1; | |
| 2922 }else | |
| 2923 h->slice_type_fixed=0; | |
| 2924 | |
| 2925 h->slice_type= slice_type_map[ h->slice_type ]; | |
| 2926 | |
| 2927 s->pict_type= h->slice_type; // to make a few old func happy, its wrong though | |
| 2928 | |
| 2929 pps_id= get_ue_golomb(&s->gb); | |
| 2930 if(pps_id>255){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
2931 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); |
| 1168 | 2932 return -1; |
| 2933 } | |
| 2934 h->pps= h->pps_buffer[pps_id]; | |
| 1174 | 2935 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
|
2936 av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\n"); |
| 1174 | 2937 return -1; |
| 2938 } | |
| 2939 | |
| 1168 | 2940 h->sps= h->sps_buffer[ h->pps.sps_id ]; |
| 1174 | 2941 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
|
2942 av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n"); |
| 1174 | 2943 return -1; |
| 2944 } | |
| 1168 | 2945 |
| 2946 s->mb_width= h->sps.mb_width; | |
| 2947 s->mb_height= h->sps.mb_height; | |
| 2948 | |
| 2949 h->b_stride= s->mb_width*4; | |
| 2950 h->b8_stride= s->mb_width*2; | |
| 2951 | |
| 2952 s->mb_x = first_mb_in_slice % s->mb_width; | |
| 2953 s->mb_y = first_mb_in_slice / s->mb_width; //FIXME AFFW | |
| 2954 | |
| 1371 | 2955 s->width = 16*s->mb_width - 2*(h->sps.crop_left + h->sps.crop_right ); |
| 1168 | 2956 if(h->sps.frame_mbs_only_flag) |
| 1371 | 2957 s->height= 16*s->mb_height - 2*(h->sps.crop_top + h->sps.crop_bottom); |
| 1168 | 2958 else |
| 1371 | 2959 s->height= 16*s->mb_height - 4*(h->sps.crop_top + h->sps.crop_bottom); //FIXME recheck |
| 1168 | 2960 |
| 2961 if (s->context_initialized | |
| 1548 | 2962 && ( s->width != s->avctx->width || s->height != s->avctx->height)) { |
| 1168 | 2963 free_tables(h); |
| 2964 MPV_common_end(s); | |
| 2965 } | |
| 2966 if (!s->context_initialized) { | |
| 2967 if (MPV_common_init(s) < 0) | |
| 2968 return -1; | |
| 2969 | |
| 2970 alloc_tables(h); | |
| 2971 | |
| 2972 s->avctx->width = s->width; | |
| 2973 s->avctx->height = s->height; | |
| 1548 | 2974 s->avctx->sample_aspect_ratio= h->sps.sar; |
| 1168 | 2975 } |
| 2976 | |
| 2977 if(first_mb_in_slice == 0){ | |
| 2978 frame_start(h); | |
| 2979 } | |
| 2980 | |
| 1169 | 2981 s->current_picture_ptr->frame_num= //FIXME frame_num cleanup |
| 1168 | 2982 h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); |
| 2983 | |
| 2984 if(h->sps.frame_mbs_only_flag){ | |
| 2985 s->picture_structure= PICT_FRAME; | |
| 2986 }else{ | |
| 2987 if(get_bits1(&s->gb)) //field_pic_flag | |
| 2988 s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag | |
| 2989 else | |
| 2990 s->picture_structure= PICT_FRAME; | |
| 2991 } | |
| 2992 | |
| 2993 if(s->picture_structure==PICT_FRAME){ | |
| 2994 h->curr_pic_num= h->frame_num; | |
| 2995 h->max_pic_num= 1<< h->sps.log2_max_frame_num; | |
| 2996 }else{ | |
| 2997 h->curr_pic_num= 2*h->frame_num; | |
| 2998 h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1); | |
| 2999 } | |
| 3000 | |
| 3001 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
| 1453 | 3002 get_ue_golomb(&s->gb); /* idr_pic_id */ |
| 1168 | 3003 } |
| 3004 | |
| 3005 if(h->sps.poc_type==0){ | |
| 3006 h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb); | |
| 3007 | |
| 3008 if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){ | |
| 3009 h->delta_poc_bottom= get_se_golomb(&s->gb); | |
| 3010 } | |
| 3011 } | |
| 3012 | |
| 3013 if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){ | |
| 3014 h->delta_poc[0]= get_se_golomb(&s->gb); | |
| 3015 | |
| 3016 if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME) | |
| 3017 h->delta_poc[1]= get_se_golomb(&s->gb); | |
| 3018 } | |
| 3019 | |
| 3020 init_poc(h); | |
| 3021 | |
| 3022 if(h->pps.redundant_pic_cnt_present){ | |
| 3023 h->redundant_pic_count= get_ue_golomb(&s->gb); | |
| 3024 } | |
| 3025 | |
| 3026 //set defaults, might be overriden a few line later | |
| 3027 h->ref_count[0]= h->pps.ref_count[0]; | |
| 3028 h->ref_count[1]= h->pps.ref_count[1]; | |
| 3029 | |
| 3030 if(h->slice_type == P_TYPE || h->slice_type == SP_TYPE || h->slice_type == B_TYPE){ | |
| 3031 if(h->slice_type == B_TYPE){ | |
| 3032 h->direct_spatial_mv_pred= get_bits1(&s->gb); | |
| 3033 } | |
| 3034 num_ref_idx_active_override_flag= get_bits1(&s->gb); | |
| 3035 | |
| 3036 if(num_ref_idx_active_override_flag){ | |
| 3037 h->ref_count[0]= get_ue_golomb(&s->gb) + 1; | |
| 3038 if(h->slice_type==B_TYPE) | |
| 3039 h->ref_count[1]= get_ue_golomb(&s->gb) + 1; | |
| 3040 | |
| 3041 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
|
3042 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); |
| 1168 | 3043 return -1; |
| 3044 } | |
| 3045 } | |
| 3046 } | |
| 3047 | |
| 3048 if(first_mb_in_slice == 0){ | |
| 3049 fill_default_ref_list(h); | |
| 3050 } | |
| 3051 | |
| 3052 decode_ref_pic_list_reordering(h); | |
| 3053 | |
| 3054 if( (h->pps.weighted_pred && (h->slice_type == P_TYPE || h->slice_type == SP_TYPE )) | |
| 3055 || (h->pps.weighted_bipred_idc==1 && h->slice_type==B_TYPE ) ) | |
| 3056 pred_weight_table(h); | |
| 3057 | |
| 3058 if(s->current_picture.reference) | |
| 3059 decode_ref_pic_marking(h); | |
| 3060 //FIXME CABAC stuff | |
| 3061 | |
| 3062 s->qscale = h->pps.init_qp + get_se_golomb(&s->gb); //slice_qp_delta | |
| 1898 | 3063 if(s->qscale<0 || s->qscale>51){ |
| 3064 av_log(s->avctx, AV_LOG_ERROR, "QP %d out of range\n", s->qscale); | |
| 3065 return -1; | |
| 3066 } | |
| 1168 | 3067 //FIXME qscale / qp ... stuff |
| 3068 if(h->slice_type == SP_TYPE){ | |
| 1453 | 3069 get_bits1(&s->gb); /* sp_for_switch_flag */ |
| 1168 | 3070 } |
| 3071 if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){ | |
| 1453 | 3072 get_se_golomb(&s->gb); /* slice_qs_delta */ |
| 1168 | 3073 } |
| 3074 | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3075 h->deblocking_filter = 1; |
| 1898 | 3076 h->slice_alpha_c0_offset = 0; |
| 3077 h->slice_beta_offset = 0; | |
| 1168 | 3078 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
|
3079 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
|
3080 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
|
3081 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
|
3082 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3083 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
|
3084 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
|
3085 h->slice_beta_offset = get_se_golomb(&s->gb) << 1; |
| 1168 | 3086 } |
|
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
|
3087 } |
| 1168 | 3088 |
| 3089 #if 0 //FMO | |
| 3090 if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5) | |
| 3091 slice_group_change_cycle= get_bits(&s->gb, ?); | |
| 3092 #endif | |
| 3093 | |
| 3094 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
|
3095 av_log(h->s.avctx, AV_LOG_DEBUG, "mb:%d %c pps:%d frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d\n", |
| 1168 | 3096 first_mb_in_slice, |
| 1264 | 3097 av_get_pict_type_char(h->slice_type), |
| 1168 | 3098 pps_id, h->frame_num, |
| 3099 s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1], | |
| 3100 h->ref_count[0], h->ref_count[1], | |
| 3101 s->qscale, | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3102 h->deblocking_filter |
| 1168 | 3103 ); |
| 3104 } | |
| 3105 | |
| 3106 return 0; | |
| 3107 } | |
| 3108 | |
| 3109 /** | |
| 3110 * | |
| 3111 */ | |
| 3112 static inline int get_level_prefix(GetBitContext *gb){ | |
| 3113 unsigned int buf; | |
| 3114 int log; | |
| 3115 | |
| 3116 OPEN_READER(re, gb); | |
| 3117 UPDATE_CACHE(re, gb); | |
| 3118 buf=GET_CACHE(re, gb); | |
| 3119 | |
| 3120 log= 32 - av_log2(buf); | |
| 3121 #ifdef TRACE | |
| 3122 print_bin(buf>>(32-log), log); | |
| 3123 printf("%5d %2d %3d lpr @%5d in %s get_level_prefix\n", buf>>(32-log), log, log-1, get_bits_count(gb), __FILE__); | |
| 3124 #endif | |
| 3125 | |
| 3126 LAST_SKIP_BITS(re, gb, log); | |
| 3127 CLOSE_READER(re, gb); | |
| 3128 | |
| 3129 return log-1; | |
| 3130 } | |
| 3131 | |
| 3132 /** | |
| 3133 * decodes a residual block. | |
| 3134 * @param n block index | |
| 3135 * @param scantable scantable | |
| 3136 * @param max_coeff number of coefficients in the block | |
| 3137 * @return <0 if an error occured | |
| 3138 */ | |
| 3139 static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, int qp, int max_coeff){ | |
| 3140 MpegEncContext * const s = &h->s; | |
| 3141 const uint16_t *qmul= dequant_coeff[qp]; | |
| 3142 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}; | |
| 3143 int level[16], run[16]; | |
| 3144 int suffix_length, zeros_left, coeff_num, coeff_token, total_coeff, i, trailing_ones; | |
| 3145 | |
| 3146 //FIXME put trailing_onex into the context | |
| 3147 | |
| 3148 if(n == CHROMA_DC_BLOCK_INDEX){ | |
| 3149 coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1); | |
| 3150 total_coeff= coeff_token>>2; | |
| 3151 }else{ | |
| 3152 if(n == LUMA_DC_BLOCK_INDEX){ | |
| 3153 total_coeff= pred_non_zero_count(h, 0); | |
| 3154 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); | |
| 3155 total_coeff= coeff_token>>2; | |
| 3156 }else{ | |
| 3157 total_coeff= pred_non_zero_count(h, n); | |
| 3158 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); | |
| 3159 total_coeff= coeff_token>>2; | |
| 3160 h->non_zero_count_cache[ scan8[n] ]= total_coeff; | |
| 3161 } | |
| 3162 } | |
| 3163 | |
| 3164 //FIXME set last_non_zero? | |
| 3165 | |
| 3166 if(total_coeff==0) | |
| 3167 return 0; | |
| 3168 | |
| 3169 trailing_ones= coeff_token&3; | |
| 1170 | 3170 tprintf("trailing:%d, total:%d\n", trailing_ones, total_coeff); |
| 1168 | 3171 assert(total_coeff<=16); |
| 3172 | |
| 3173 for(i=0; i<trailing_ones; i++){ | |
| 3174 level[i]= 1 - 2*get_bits1(gb); | |
| 3175 } | |
| 3176 | |
| 3177 suffix_length= total_coeff > 10 && trailing_ones < 3; | |
| 3178 | |
| 3179 for(; i<total_coeff; i++){ | |
| 3180 const int prefix= get_level_prefix(gb); | |
| 3181 int level_code, mask; | |
| 3182 | |
| 3183 if(prefix<14){ //FIXME try to build a large unified VLC table for all this | |
| 3184 if(suffix_length) | |
| 3185 level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part | |
| 3186 else | |
| 3187 level_code= (prefix<<suffix_length); //part | |
| 3188 }else if(prefix==14){ | |
| 3189 if(suffix_length) | |
| 3190 level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part | |
| 3191 else | |
| 3192 level_code= prefix + get_bits(gb, 4); //part | |
| 3193 }else if(prefix==15){ | |
| 3194 level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part | |
| 3195 if(suffix_length==0) level_code+=15; //FIXME doesnt make (much)sense | |
| 3196 }else{ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3197 av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y); |
| 1168 | 3198 return -1; |
| 3199 } | |
| 3200 | |
| 3201 if(i==trailing_ones && i<3) level_code+= 2; //FIXME split first iteration | |
| 3202 | |
| 3203 mask= -(level_code&1); | |
| 3204 level[i]= (((2+level_code)>>1) ^ mask) - mask; | |
| 3205 | |
| 3206 if(suffix_length==0) suffix_length=1; //FIXME split first iteration | |
| 3207 | |
| 3208 #if 1 | |
| 3209 if(ABS(level[i]) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++; | |
| 3210 #else | |
| 3211 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
|
3212 /* ? == prefix > 2 or sth */ |
| 1168 | 3213 #endif |
| 1170 | 3214 tprintf("level: %d suffix_length:%d\n", level[i], suffix_length); |
| 1168 | 3215 } |
| 3216 | |
| 3217 if(total_coeff == max_coeff) | |
| 3218 zeros_left=0; | |
| 3219 else{ | |
| 3220 if(n == CHROMA_DC_BLOCK_INDEX) | |
| 3221 zeros_left= get_vlc2(gb, chroma_dc_total_zeros_vlc[ total_coeff-1 ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1); | |
| 3222 else | |
| 3223 zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff-1 ].table, TOTAL_ZEROS_VLC_BITS, 1); | |
| 3224 } | |
| 3225 | |
| 3226 for(i=0; i<total_coeff-1; i++){ | |
| 3227 if(zeros_left <=0) | |
| 3228 break; | |
| 3229 else if(zeros_left < 7){ | |
| 3230 run[i]= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1); | |
| 3231 }else{ | |
| 3232 run[i]= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); | |
| 3233 } | |
| 3234 zeros_left -= run[i]; | |
| 3235 } | |
| 3236 | |
| 3237 if(zeros_left<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3238 av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); |
| 1168 | 3239 return -1; |
| 3240 } | |
| 3241 | |
| 3242 for(; i<total_coeff-1; i++){ | |
| 3243 run[i]= 0; | |
| 3244 } | |
| 3245 | |
| 3246 run[i]= zeros_left; | |
| 3247 | |
| 3248 coeff_num=-1; | |
| 3249 if(n > 24){ | |
| 3250 for(i=total_coeff-1; i>=0; i--){ //FIXME merge into rundecode? | |
| 3251 int j; | |
| 3252 | |
| 3253 coeff_num += run[i] + 1; //FIXME add 1 earlier ? | |
| 3254 j= scantable[ coeff_num ]; | |
| 3255 | |
| 3256 block[j]= level[i]; | |
| 3257 } | |
| 3258 }else{ | |
| 3259 for(i=total_coeff-1; i>=0; i--){ //FIXME merge into rundecode? | |
| 3260 int j; | |
| 3261 | |
| 3262 coeff_num += run[i] + 1; //FIXME add 1 earlier ? | |
| 3263 j= scantable[ coeff_num ]; | |
| 3264 | |
| 3265 block[j]= level[i] * qmul[j]; | |
| 3266 // printf("%d %d ", block[j], qmul[j]); | |
| 3267 } | |
| 3268 } | |
| 3269 return 0; | |
| 3270 } | |
| 3271 | |
| 3272 /** | |
| 3273 * decodes a macroblock | |
| 3274 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed | |
| 3275 */ | |
| 3276 static int decode_mb(H264Context *h){ | |
| 3277 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
|
3278 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1169 | 3279 int mb_type, partition_count, cbp; |
| 1168 | 3280 |
| 1252 | 3281 s->dsp.clear_blocks(h->mb); //FIXME avoid if allready clear (move after skip handlong? |
| 1168 | 3282 |
| 1170 | 3283 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); |
| 1453 | 3284 cbp = 0; /* avoid warning. FIXME: find a solution without slowing |
| 3285 down the code */ | |
| 1168 | 3286 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ |
| 3287 if(s->mb_skip_run==-1) | |
| 3288 s->mb_skip_run= get_ue_golomb(&s->gb); | |
| 3289 | |
| 3290 if (s->mb_skip_run--) { | |
| 1187 | 3291 int mx, my; |
| 1168 | 3292 /* skip mb */ |
| 3293 //FIXME b frame | |
| 3294 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0; | |
| 3295 | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3296 memset(h->non_zero_count[mb_xy], 0, 16); |
| 1168 | 3297 memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui |
| 3298 | |
| 3299 if(h->sps.mb_aff && s->mb_skip_run==0 && (s->mb_y&1)==0){ | |
| 3300 h->mb_field_decoding_flag= get_bits1(&s->gb); | |
| 3301 } | |
| 3302 | |
| 3303 if(h->mb_field_decoding_flag) | |
| 3304 mb_type|= MB_TYPE_INTERLACED; | |
| 3305 | |
| 3306 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | |
| 3307 pred_pskip_motion(h, &mx, &my); | |
| 3308 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
| 1269 | 3309 fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); |
| 1168 | 3310 write_back_motion(h, mb_type); |
| 3311 | |
| 3312 s->current_picture.mb_type[mb_xy]= mb_type; //FIXME SKIP type | |
|
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
|
3313 s->current_picture.qscale_table[mb_xy]= s->qscale; |
| 1168 | 3314 h->slice_table[ mb_xy ]= h->slice_num; |
| 3315 | |
| 3316 h->prev_mb_skiped= 1; | |
| 3317 return 0; | |
| 3318 } | |
| 3319 } | |
| 3320 if(h->sps.mb_aff /* && !field pic FIXME needed? */){ | |
| 3321 if((s->mb_y&1)==0) | |
| 3322 h->mb_field_decoding_flag = get_bits1(&s->gb); | |
| 3323 }else | |
| 3324 h->mb_field_decoding_flag=0; //FIXME som ed note ?! | |
| 3325 | |
| 3326 h->prev_mb_skiped= 0; | |
| 3327 | |
| 3328 mb_type= get_ue_golomb(&s->gb); | |
| 3329 if(h->slice_type == B_TYPE){ | |
| 3330 if(mb_type < 23){ | |
| 3331 partition_count= b_mb_type_info[mb_type].partition_count; | |
| 3332 mb_type= b_mb_type_info[mb_type].type; | |
| 3333 }else{ | |
| 3334 mb_type -= 23; | |
| 3335 goto decode_intra_mb; | |
| 3336 } | |
| 3337 }else if(h->slice_type == P_TYPE /*|| h->slice_type == SP_TYPE */){ | |
| 3338 if(mb_type < 5){ | |
| 3339 partition_count= p_mb_type_info[mb_type].partition_count; | |
| 3340 mb_type= p_mb_type_info[mb_type].type; | |
| 3341 }else{ | |
| 3342 mb_type -= 5; | |
| 3343 goto decode_intra_mb; | |
| 3344 } | |
| 3345 }else{ | |
| 3346 assert(h->slice_type == I_TYPE); | |
| 3347 decode_intra_mb: | |
| 3348 if(mb_type > 25){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3349 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 | 3350 return -1; |
| 3351 } | |
| 3352 partition_count=0; | |
| 3353 cbp= i_mb_type_info[mb_type].cbp; | |
| 3354 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; | |
| 3355 mb_type= i_mb_type_info[mb_type].type; | |
| 3356 } | |
| 3357 | |
| 3358 if(h->mb_field_decoding_flag) | |
| 3359 mb_type |= MB_TYPE_INTERLACED; | |
| 3360 | |
| 3361 s->current_picture.mb_type[mb_xy]= mb_type; | |
| 3362 h->slice_table[ mb_xy ]= h->slice_num; | |
| 3363 | |
| 3364 if(IS_INTRA_PCM(mb_type)){ | |
| 3365 const uint8_t *ptr; | |
| 1187 | 3366 int x, y; |
| 1168 | 3367 |
| 3368 // we assume these blocks are very rare so we dont optimize it | |
| 3369 align_get_bits(&s->gb); | |
| 3370 | |
| 3371 ptr= s->gb.buffer + get_bits_count(&s->gb); | |
| 3372 | |
| 3373 for(y=0; y<16; y++){ | |
| 3374 const int index= 4*(y&3) + 64*(y>>2); | |
| 3375 for(x=0; x<16; x++){ | |
| 3376 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); | |
| 3377 } | |
| 3378 } | |
| 3379 for(y=0; y<8; y++){ | |
| 3380 const int index= 256 + 4*(y&3) + 32*(y>>2); | |
| 3381 for(x=0; x<8; x++){ | |
| 3382 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); | |
| 3383 } | |
| 3384 } | |
| 3385 for(y=0; y<8; y++){ | |
| 3386 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); | |
| 3387 for(x=0; x<8; x++){ | |
| 3388 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); | |
| 3389 } | |
| 3390 } | |
| 3391 | |
| 3392 skip_bits(&s->gb, 384); //FIXME check /fix the bitstream readers | |
| 3393 | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3394 //FIXME deblock filter, non_zero_count_cache init ... |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3395 memset(h->non_zero_count[mb_xy], 16, 16); |
|
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
|
3396 s->current_picture.qscale_table[mb_xy]= s->qscale; |
| 1168 | 3397 |
| 3398 return 0; | |
| 3399 } | |
| 3400 | |
| 3401 fill_caches(h, mb_type); | |
| 3402 | |
| 3403 //mb_pred | |
| 3404 if(IS_INTRA(mb_type)){ | |
| 3405 // init_top_left_availability(h); | |
| 3406 if(IS_INTRA4x4(mb_type)){ | |
| 3407 int i; | |
| 3408 | |
| 3409 // fill_intra4x4_pred_table(h); | |
| 3410 for(i=0; i<16; i++){ | |
| 3411 const int mode_coded= !get_bits1(&s->gb); | |
| 3412 const int predicted_mode= pred_intra_mode(h, i); | |
| 3413 int mode; | |
| 3414 | |
| 3415 if(mode_coded){ | |
| 3416 const int rem_mode= get_bits(&s->gb, 3); | |
| 3417 if(rem_mode<predicted_mode) | |
| 3418 mode= rem_mode; | |
| 3419 else | |
| 3420 mode= rem_mode + 1; | |
| 3421 }else{ | |
| 3422 mode= predicted_mode; | |
| 3423 } | |
| 3424 | |
| 3425 h->intra4x4_pred_mode_cache[ scan8[i] ] = mode; | |
| 3426 } | |
| 3427 write_back_intra_pred_mode(h); | |
| 3428 if( check_intra4x4_pred_mode(h) < 0) | |
| 3429 return -1; | |
| 3430 }else{ | |
| 3431 h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode); | |
| 3432 if(h->intra16x16_pred_mode < 0) | |
| 3433 return -1; | |
| 3434 } | |
| 3435 h->chroma_pred_mode= get_ue_golomb(&s->gb); | |
| 3436 | |
| 3437 h->chroma_pred_mode= check_intra_pred_mode(h, h->chroma_pred_mode); | |
| 3438 if(h->chroma_pred_mode < 0) | |
| 3439 return -1; | |
| 3440 }else if(partition_count==4){ | |
| 3441 int i, j, sub_partition_count[4], list, ref[2][4]; | |
| 3442 | |
| 3443 if(h->slice_type == B_TYPE){ | |
| 3444 for(i=0; i<4; i++){ | |
| 3445 h->sub_mb_type[i]= get_ue_golomb(&s->gb); | |
| 3446 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
|
3447 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 | 3448 return -1; |
| 3449 } | |
| 3450 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | |
| 3451 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; | |
| 3452 } | |
| 3453 }else{ | |
| 3454 assert(h->slice_type == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ? | |
| 3455 for(i=0; i<4; i++){ | |
| 3456 h->sub_mb_type[i]= get_ue_golomb(&s->gb); | |
| 3457 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
|
3458 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 | 3459 return -1; |
| 3460 } | |
| 3461 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | |
| 3462 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; | |
| 3463 } | |
| 3464 } | |
| 3465 | |
| 3466 for(list=0; list<2; list++){ | |
| 3467 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | |
| 3468 if(ref_count == 0) continue; | |
| 3469 for(i=0; i<4; i++){ | |
| 3470 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ | |
| 3471 ref[list][i] = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip? | |
| 3472 }else{ | |
| 3473 //FIXME | |
| 3474 ref[list][i] = -1; | |
| 3475 } | |
| 3476 } | |
| 3477 } | |
| 3478 | |
| 3479 for(list=0; list<2; list++){ | |
| 3480 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | |
| 3481 if(ref_count == 0) continue; | |
| 3482 | |
| 3483 for(i=0; i<4; i++){ | |
| 3484 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]= | |
| 3485 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; | |
| 3486 | |
| 3487 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ | |
| 3488 const int sub_mb_type= h->sub_mb_type[i]; | |
| 3489 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; | |
| 3490 for(j=0; j<sub_partition_count[i]; j++){ | |
| 3491 int mx, my; | |
| 3492 const int index= 4*i + block_width*j; | |
| 3493 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; | |
| 3494 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |
| 3495 mx += get_se_golomb(&s->gb); | |
| 3496 my += get_se_golomb(&s->gb); | |
| 1170 | 3497 tprintf("final mv:%d %d\n", mx, my); |
| 3498 | |
| 1168 | 3499 if(IS_SUB_8X8(sub_mb_type)){ |
| 3500 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= | |
| 3501 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; | |
| 3502 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= | |
| 3503 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; | |
| 3504 }else if(IS_SUB_8X4(sub_mb_type)){ | |
| 3505 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mx; | |
| 3506 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= my; | |
| 3507 }else if(IS_SUB_4X8(sub_mb_type)){ | |
| 3508 mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mx; | |
| 3509 mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= my; | |
| 3510 }else{ | |
| 3511 assert(IS_SUB_4X4(sub_mb_type)); | |
| 3512 mv_cache[ 0 ][0]= mx; | |
| 3513 mv_cache[ 0 ][1]= my; | |
| 3514 } | |
| 3515 } | |
| 3516 }else{ | |
| 3517 uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0]; | |
| 3518 p[0] = p[1]= | |
| 3519 p[8] = p[9]= 0; | |
| 3520 } | |
| 3521 } | |
| 3522 } | |
| 3523 }else if(!IS_DIRECT(mb_type)){ | |
| 3524 int list, mx, my, i; | |
| 3525 //FIXME we should set ref_idx_l? to 0 if we use that later ... | |
| 3526 if(IS_16X16(mb_type)){ | |
| 3527 for(list=0; list<2; list++){ | |
| 3528 if(h->ref_count[0]>0){ | |
| 3529 if(IS_DIR(mb_type, 0, list)){ | |
| 3530 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
| 3531 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1); | |
| 3532 } | |
| 3533 } | |
| 3534 } | |
| 3535 for(list=0; list<2; list++){ | |
| 3536 if(IS_DIR(mb_type, 0, list)){ | |
| 3537 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |
| 3538 mx += get_se_golomb(&s->gb); | |
| 3539 my += get_se_golomb(&s->gb); | |
| 1170 | 3540 tprintf("final mv:%d %d\n", mx, my); |
| 3541 | |
| 1269 | 3542 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); |
| 1168 | 3543 } |
| 3544 } | |
| 3545 } | |
| 3546 else if(IS_16X8(mb_type)){ | |
| 3547 for(list=0; list<2; list++){ | |
| 3548 if(h->ref_count[list]>0){ | |
| 3549 for(i=0; i<2; i++){ | |
| 3550 if(IS_DIR(mb_type, i, list)){ | |
| 3551 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
| 3552 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); | |
| 3553 } | |
| 3554 } | |
| 3555 } | |
| 3556 } | |
| 3557 for(list=0; list<2; list++){ | |
| 3558 for(i=0; i<2; i++){ | |
| 3559 if(IS_DIR(mb_type, i, list)){ | |
| 3560 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |
| 3561 mx += get_se_golomb(&s->gb); | |
| 3562 my += get_se_golomb(&s->gb); | |
| 1170 | 3563 tprintf("final mv:%d %d\n", mx, my); |
| 3564 | |
| 1269 | 3565 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); |
| 1168 | 3566 } |
| 3567 } | |
| 3568 } | |
| 3569 }else{ | |
| 3570 assert(IS_8X16(mb_type)); | |
| 3571 for(list=0; list<2; list++){ | |
| 3572 if(h->ref_count[list]>0){ | |
| 3573 for(i=0; i<2; i++){ | |
| 3574 if(IS_DIR(mb_type, i, list)){ //FIXME optimize | |
| 3575 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
| 3576 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); | |
| 3577 } | |
| 3578 } | |
| 3579 } | |
| 3580 } | |
| 3581 for(list=0; list<2; list++){ | |
| 3582 for(i=0; i<2; i++){ | |
| 3583 if(IS_DIR(mb_type, i, list)){ | |
| 3584 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |
| 3585 mx += get_se_golomb(&s->gb); | |
| 3586 my += get_se_golomb(&s->gb); | |
| 1170 | 3587 tprintf("final mv:%d %d\n", mx, my); |
| 3588 | |
| 1269 | 3589 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); |
| 1168 | 3590 } |
| 3591 } | |
| 3592 } | |
| 3593 } | |
| 3594 } | |
| 3595 | |
| 3596 if(IS_INTER(mb_type)) | |
| 3597 write_back_motion(h, mb_type); | |
| 3598 | |
| 3599 if(!IS_INTRA16x16(mb_type)){ | |
| 3600 cbp= get_ue_golomb(&s->gb); | |
| 3601 if(cbp > 47){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3602 av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%d) at %d %d\n", cbp, s->mb_x, s->mb_y); |
| 1168 | 3603 return -1; |
| 3604 } | |
| 3605 | |
| 3606 if(IS_INTRA4x4(mb_type)) | |
| 3607 cbp= golomb_to_intra4x4_cbp[cbp]; | |
| 3608 else | |
| 3609 cbp= golomb_to_inter_cbp[cbp]; | |
| 3610 } | |
| 3611 | |
| 3612 if(cbp || IS_INTRA16x16(mb_type)){ | |
| 3613 int i8x8, i4x4, chroma_idx; | |
| 3614 int chroma_qp, dquant; | |
| 3615 GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; | |
| 3616 const uint8_t *scan, *dc_scan; | |
| 3617 | |
| 3618 // fill_non_zero_count_cache(h); | |
| 3619 | |
| 3620 if(IS_INTERLACED(mb_type)){ | |
| 3621 scan= field_scan; | |
| 3622 dc_scan= luma_dc_field_scan; | |
| 3623 }else{ | |
| 3624 scan= zigzag_scan; | |
| 3625 dc_scan= luma_dc_zigzag_scan; | |
| 3626 } | |
| 3627 | |
| 3628 dquant= get_se_golomb(&s->gb); | |
| 3629 | |
| 3630 if( dquant > 25 || dquant < -26 ){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3631 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 | 3632 return -1; |
| 3633 } | |
| 3634 | |
| 3635 s->qscale += dquant; | |
| 3636 if(((unsigned)s->qscale) > 51){ | |
| 3637 if(s->qscale<0) s->qscale+= 52; | |
| 3638 else s->qscale-= 52; | |
| 3639 } | |
| 3640 | |
| 3641 h->chroma_qp= chroma_qp= get_chroma_qp(h, s->qscale); | |
| 3642 if(IS_INTRA16x16(mb_type)){ | |
| 3643 if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, s->qscale, 16) < 0){ | |
| 3644 return -1; //FIXME continue if partotioned and other retirn -1 too | |
| 3645 } | |
| 3646 | |
| 3647 assert((cbp&15) == 0 || (cbp&15) == 15); | |
| 3648 | |
| 3649 if(cbp&15){ | |
| 3650 for(i8x8=0; i8x8<4; i8x8++){ | |
| 3651 for(i4x4=0; i4x4<4; i4x4++){ | |
| 3652 const int index= i4x4 + 4*i8x8; | |
| 3653 if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, s->qscale, 15) < 0 ){ | |
| 3654 return -1; | |
| 3655 } | |
| 3656 } | |
| 3657 } | |
| 3658 }else{ | |
| 1636 | 3659 fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); |
| 1168 | 3660 } |
| 3661 }else{ | |
| 3662 for(i8x8=0; i8x8<4; i8x8++){ | |
| 3663 if(cbp & (1<<i8x8)){ | |
| 3664 for(i4x4=0; i4x4<4; i4x4++){ | |
| 3665 const int index= i4x4 + 4*i8x8; | |
| 3666 | |
| 3667 if( decode_residual(h, gb, h->mb + 16*index, index, scan, s->qscale, 16) <0 ){ | |
| 3668 return -1; | |
| 3669 } | |
| 3670 } | |
| 3671 }else{ | |
| 3672 uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; | |
| 3673 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; | |
| 3674 } | |
| 3675 } | |
| 3676 } | |
| 3677 | |
| 3678 if(cbp&0x30){ | |
| 3679 for(chroma_idx=0; chroma_idx<2; chroma_idx++) | |
| 3680 if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, chroma_qp, 4) < 0){ | |
| 3681 return -1; | |
| 3682 } | |
| 3683 } | |
| 3684 | |
| 3685 if(cbp&0x20){ | |
| 3686 for(chroma_idx=0; chroma_idx<2; chroma_idx++){ | |
| 3687 for(i4x4=0; i4x4<4; i4x4++){ | |
| 3688 const int index= 16 + 4*chroma_idx + i4x4; | |
| 3689 if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, chroma_qp, 15) < 0){ | |
| 3690 return -1; | |
| 3691 } | |
| 3692 } | |
| 3693 } | |
| 3694 }else{ | |
| 3695 uint8_t * const nnz= &h->non_zero_count_cache[0]; | |
| 3696 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = | |
| 3697 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; | |
| 3698 } | |
| 3699 }else{ | |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3700 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
|
3701 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
|
3702 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
|
3703 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; |
| 1168 | 3704 } |
|
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
|
3705 s->current_picture.qscale_table[mb_xy]= s->qscale; |
| 1168 | 3706 write_back_non_zero_count(h); |
| 3707 | |
| 3708 return 0; | |
| 3709 } | |
| 3710 | |
|
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
|
3711 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
|
3712 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
|
3713 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
|
3714 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
|
3715 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
|
3716 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3717 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
|
3718 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
|
3719 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
|
3720 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
|
3721 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3722 |
| 1898 | 3723 if( bS[i] < 4 ) { |
| 3724 const int tc0 = tc0_table[index_a][bS[i] - 1]; | |
| 3725 /* 4px edge length */ | |
| 3726 for( d = 0; d < 4; d++ ) { | |
| 3727 const int p0 = pix[-1]; | |
| 3728 const int p1 = pix[-2]; | |
| 3729 const int p2 = pix[-3]; | |
| 3730 const int q0 = pix[0]; | |
| 3731 const int q1 = pix[1]; | |
| 3732 const int q2 = pix[2]; | |
| 3733 | |
| 3734 if( ABS( p0 - q0 ) < alpha && | |
| 3735 ABS( p1 - p0 ) < beta && | |
| 3736 ABS( q1 - q0 ) < beta ) { | |
| 3737 int tc = tc0; | |
| 3738 int i_delta; | |
| 3739 | |
| 3740 if( ABS( p2 - p0 ) < beta ) { | |
| 3741 pix[-2] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 3742 tc++; | |
| 3743 } | |
| 3744 if( ABS( q2 - q0 ) < beta ) { | |
| 3745 pix[1] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 3746 tc++; | |
| 3747 } | |
| 3748 | |
| 3749 i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 3750 pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */ | |
| 3751 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
|
3752 } |
| 1898 | 3753 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
|
3754 } |
| 1898 | 3755 }else{ |
| 3756 /* 4px edge length */ | |
| 3757 for( d = 0; d < 4; d++ ) { | |
| 3758 const int p0 = pix[-1]; | |
| 3759 const int p1 = pix[-2]; | |
| 3760 const int p2 = pix[-3]; | |
| 3761 | |
| 3762 const int q0 = pix[0]; | |
| 3763 const int q1 = pix[1]; | |
| 3764 const int q2 = pix[2]; | |
| 3765 | |
| 3766 if( ABS( p0 - q0 ) < alpha && | |
| 3767 ABS( p1 - p0 ) < beta && | |
| 3768 ABS( q1 - q0 ) < beta ) { | |
| 3769 | |
| 3770 if(ABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ | |
| 3771 if( ABS( p2 - p0 ) < beta) | |
| 3772 { | |
| 3773 const int p3 = pix[-4]; | |
| 3774 /* p0', p1', p2' */ | |
| 3775 pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; | |
| 3776 pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; | |
| 3777 pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; | |
| 3778 } else { | |
| 3779 /* p0' */ | |
| 3780 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 3781 } | |
| 3782 if( ABS( q2 - q0 ) < beta) | |
| 3783 { | |
| 3784 const int q3 = pix[3]; | |
| 3785 /* q0', q1', q2' */ | |
| 3786 pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; | |
| 3787 pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; | |
| 3788 pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; | |
| 3789 } else { | |
| 3790 /* q0' */ | |
| 3791 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 3792 } | |
| 3793 }else{ | |
| 3794 /* p0', q0' */ | |
| 3795 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 3796 pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 3797 } | |
|
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
|
3798 } |
| 1898 | 3799 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
|
3800 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3801 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3802 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3803 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3804 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
|
3805 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
|
3806 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
|
3807 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
|
3808 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
|
3809 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3810 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
|
3811 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
|
3812 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
|
3813 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
|
3814 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3815 |
| 1898 | 3816 if( bS[i] < 4 ) { |
| 3817 const int tc = tc0_table[index_a][bS[i] - 1] + 1; | |
| 3818 /* 2px edge length (because we use same bS than the one for luma) */ | |
| 3819 for( d = 0; d < 2; d++ ){ | |
| 3820 const int p0 = pix[-1]; | |
| 3821 const int p1 = pix[-2]; | |
| 3822 const int q0 = pix[0]; | |
| 3823 const int q1 = pix[1]; | |
| 3824 | |
| 3825 if( ABS( p0 - q0 ) < alpha && | |
| 3826 ABS( p1 - p0 ) < beta && | |
| 3827 ABS( q1 - q0 ) < beta ) { | |
| 3828 const int i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 3829 | |
| 3830 pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */ | |
| 3831 pix[0] = clip_uint8( q0 - i_delta ); /* q0' */ | |
| 3832 } | |
|
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
|
3833 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
|
3834 } |
| 1898 | 3835 }else{ |
| 3836 /* 2px edge length (because we use same bS than the one for luma) */ | |
| 3837 for( d = 0; d < 2; d++ ){ | |
| 3838 const int p0 = pix[-1]; | |
| 3839 const int p1 = pix[-2]; | |
| 3840 const int q0 = pix[0]; | |
| 3841 const int q1 = pix[1]; | |
| 3842 | |
| 3843 if( ABS( p0 - q0 ) < alpha && | |
| 3844 ABS( p1 - p0 ) < beta && | |
| 3845 ABS( q1 - q0 ) < beta ) { | |
| 3846 | |
| 3847 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ | |
| 3848 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ | |
| 3849 } | |
| 3850 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
|
3851 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3852 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3853 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3854 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3855 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3856 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
|
3857 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
|
3858 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
|
3859 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
|
3860 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
|
3861 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
|
3862 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3863 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
|
3864 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
|
3865 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
|
3866 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
|
3867 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3868 |
| 1898 | 3869 if( bS[i] < 4 ) { |
| 3870 const int tc0 = tc0_table[index_a][bS[i] - 1]; | |
| 3871 /* 4px edge length */ | |
| 3872 for( d = 0; d < 4; d++ ) { | |
| 3873 const int p0 = pix[-1*pix_next]; | |
| 3874 const int p1 = pix[-2*pix_next]; | |
| 3875 const int p2 = pix[-3*pix_next]; | |
| 3876 const int q0 = pix[0]; | |
| 3877 const int q1 = pix[1*pix_next]; | |
| 3878 const int q2 = pix[2*pix_next]; | |
| 3879 | |
| 3880 if( ABS( p0 - q0 ) < alpha && | |
| 3881 ABS( p1 - p0 ) < beta && | |
| 3882 ABS( q1 - q0 ) < beta ) { | |
| 3883 | |
| 3884 int tc = tc0; | |
| 3885 int i_delta; | |
| 3886 | |
| 3887 if( ABS( p2 - p0 ) < beta ) { | |
| 3888 pix[-2*pix_next] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 3889 tc++; | |
| 3890 } | |
| 3891 if( ABS( q2 - q0 ) < beta ) { | |
| 3892 pix[pix_next] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); | |
| 3893 tc++; | |
| 3894 } | |
| 3895 | |
| 3896 i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 3897 pix[-pix_next] = clip_uint8( p0 + i_delta ); /* p0' */ | |
| 3898 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
|
3899 } |
| 1898 | 3900 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
|
3901 } |
| 1898 | 3902 }else{ |
| 3903 /* 4px edge length */ | |
| 3904 for( d = 0; d < 4; d++ ) { | |
| 3905 const int p0 = pix[-1*pix_next]; | |
| 3906 const int p1 = pix[-2*pix_next]; | |
| 3907 const int p2 = pix[-3*pix_next]; | |
| 3908 const int q0 = pix[0]; | |
| 3909 const int q1 = pix[1*pix_next]; | |
| 3910 const int q2 = pix[2*pix_next]; | |
| 3911 | |
| 3912 if( ABS( p0 - q0 ) < alpha && | |
| 3913 ABS( p1 - p0 ) < beta && | |
| 3914 ABS( q1 - q0 ) < beta ) { | |
| 3915 | |
| 3916 const int p3 = pix[-4*pix_next]; | |
| 3917 const int q3 = pix[ 3*pix_next]; | |
| 3918 | |
| 3919 if(ABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ | |
| 3920 if( ABS( p2 - p0 ) < beta) { | |
| 3921 /* p0', p1', p2' */ | |
| 3922 pix[-1*pix_next] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; | |
| 3923 pix[-2*pix_next] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; | |
| 3924 pix[-3*pix_next] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; | |
| 3925 } else { | |
| 3926 /* p0' */ | |
| 3927 pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 3928 } | |
| 3929 if( ABS( q2 - q0 ) < beta) { | |
| 3930 /* q0', q1', q2' */ | |
| 3931 pix[0*pix_next] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; | |
| 3932 pix[1*pix_next] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; | |
| 3933 pix[2*pix_next] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; | |
| 3934 } else { | |
| 3935 /* q0' */ | |
| 3936 pix[0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 3937 } | |
| 3938 }else{ | |
| 3939 /* p0', q0' */ | |
| 3940 pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
| 3941 pix[ 0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
| 3942 } | |
|
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
|
3943 } |
| 1898 | 3944 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
|
3945 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3946 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3947 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3948 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3949 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3950 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
|
3951 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
|
3952 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
|
3953 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
|
3954 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
|
3955 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
|
3956 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3957 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
|
3958 { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3959 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
|
3960 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
|
3961 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
|
3962 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
3963 |
| 1898 | 3964 if( bS[i] < 4 ) { |
| 3965 int tc = tc0_table[index_a][bS[i] - 1] + 1; | |
| 3966 /* 2px edge length (see deblocking_filter_edgecv) */ | |
| 3967 for( d = 0; d < 2; d++ ) { | |
| 3968 const int p0 = pix[-1*pix_next]; | |
| 3969 const int p1 = pix[-2*pix_next]; | |
| 3970 const int q0 = pix[0]; | |
| 3971 const int q1 = pix[1*pix_next]; | |
| 3972 | |
| 3973 if( ABS( p0 - q0 ) < alpha && | |
| 3974 ABS( p1 - p0 ) < beta && | |
| 3975 ABS( q1 - q0 ) < beta ) { | |
| 3976 | |
| 3977 int i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
| 3978 | |
| 3979 pix[-pix_next] = clip_uint8( p0 + i_delta ); /* p0' */ | |
| 3980 pix[0] = clip_uint8( q0 - i_delta ); /* q0' */ | |
| 3981 } | |
|
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
|
3982 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
|
3983 } |
| 1898 | 3984 }else{ |
| 3985 /* 2px edge length (see deblocking_filter_edgecv) */ | |
| 3986 for( d = 0; d < 2; d++ ) { | |
| 3987 const int p0 = pix[-1*pix_next]; | |
| 3988 const int p1 = pix[-2*pix_next]; | |
| 3989 const int q0 = pix[0]; | |
| 3990 const int q1 = pix[1*pix_next]; | |
| 3991 | |
| 3992 if( ABS( p0 - q0 ) < alpha && | |
| 3993 ABS( p1 - p0 ) < beta && | |
| 3994 ABS( q1 - q0 ) < beta ) { | |
| 3995 | |
| 3996 pix[-pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ | |
| 3997 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ | |
| 3998 } | |
| 3999 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
|
4000 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4001 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4002 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4003 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4004 |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4005 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
|
4006 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
|
4007 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
|
4008 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
|
4009 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
|
4010 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4011 /* 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
|
4012 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
|
4013 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
|
4014 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4015 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
|
4016 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
|
4017 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4018 /* 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
|
4019 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
|
4020 { |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4021 int start = 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
|
4022 int 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
|
4023 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4024 /* test picture boundary */ |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4025 if( ( dir == 0 && mb_x == 0 ) || ( dir == 1 && mb_y == 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
|
4026 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
|
4027 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4028 /* FIXME test slice boundary */ |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4029 if( h->deblocking_filter == 2 ) { |
|
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
|
4030 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4031 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4032 /* 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
|
4033 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
|
4034 /* mbn_xy: neighbour macroblock (how that works for field ?) */ |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4035 int mbn_xy = edge > 0 ? mb_xy : ( dir == 0 ? mb_xy -1 : mb_xy - 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
|
4036 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
|
4037 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
|
4038 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4039 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
|
4040 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
|
4041 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
|
4042 } 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
|
4043 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
|
4044 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
|
4045 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
|
4046 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
|
4047 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
|
4048 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
|
4049 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4050 if( h->non_zero_count_cache[b_idx] != 0 || |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4051 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
|
4052 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
|
4053 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4054 else if( h->slice_type == P_TYPE ) { |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4055 if( h->ref_cache[0][b_idx] != h->ref_cache[0][bn_idx] || |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4056 ABS( h->mv_cache[0][b_idx][0] - h->mv_cache[0][bn_idx][0] ) >= 4 || |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4057 ABS( h->mv_cache[0][b_idx][1] - h->mv_cache[0][bn_idx][1] ) >= 4 ) |
|
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
|
4058 bS[i] = 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
|
4059 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
|
4060 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
|
4061 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4062 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
|
4063 /* FIXME Add support for B frame */ |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4064 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
|
4065 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4066 } |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4067 |
|
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4068 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
|
4069 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
|
4070 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4071 |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4072 /* Filter edge */ |
|
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4073 qp = ( s->qscale + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; |
|
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
|
4074 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
|
4075 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); |
| 1898 | 4076 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
|
4077 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
|
4078 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
|
4079 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
|
4080 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
|
4081 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4082 } 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
|
4083 filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp ); |
| 1898 | 4084 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
|
4085 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
|
4086 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
|
4087 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
|
4088 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
|
4089 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4090 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4091 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4092 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4093 } |
|
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
4094 |
| 1168 | 4095 static int decode_slice(H264Context *h){ |
| 4096 MpegEncContext * const s = &h->s; | |
| 4097 const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F; | |
| 4098 | |
| 4099 s->mb_skip_run= -1; | |
| 4100 | |
| 4101 #if 1 | |
| 4102 for(;;){ | |
| 4103 int ret= decode_mb(h); | |
| 4104 | |
| 4105 hl_decode_mb(h); | |
| 4106 | |
| 4107 if(ret>=0 && h->sps.mb_aff){ //FIXME optimal? or let mb_decode decode 16x32 ? | |
| 4108 s->mb_y++; | |
| 4109 ret= decode_mb(h); | |
| 4110 | |
| 4111 hl_decode_mb(h); | |
| 4112 s->mb_y--; | |
| 4113 } | |
| 4114 | |
| 4115 if(ret<0){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4116 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); |
| 1168 | 4117 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); |
| 4118 | |
| 4119 return -1; | |
| 4120 } | |
| 4121 | |
| 4122 if(++s->mb_x >= s->mb_width){ | |
| 4123 s->mb_x=0; | |
| 4124 ff_draw_horiz_band(s, 16*s->mb_y, 16); | |
| 4125 if(++s->mb_y >= s->mb_height){ | |
| 1170 | 4126 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); |
| 4127 | |
| 1168 | 4128 if(get_bits_count(&s->gb) == s->gb.size_in_bits){ |
| 4129 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); | |
| 4130 | |
| 4131 return 0; | |
| 4132 }else{ | |
| 4133 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); | |
| 4134 | |
| 4135 return -1; | |
| 4136 } | |
| 4137 } | |
| 4138 } | |
| 4139 | |
| 4140 if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){ | |
| 4141 if(get_bits_count(&s->gb) == s->gb.size_in_bits){ | |
| 4142 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); | |
| 4143 | |
| 4144 return 0; | |
| 4145 }else{ | |
| 4146 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); | |
| 4147 | |
| 4148 return -1; | |
| 4149 } | |
| 4150 } | |
| 4151 } | |
| 4152 #endif | |
| 4153 #if 0 | |
| 4154 for(;s->mb_y < s->mb_height; s->mb_y++){ | |
| 4155 for(;s->mb_x < s->mb_width; s->mb_x++){ | |
| 4156 int ret= decode_mb(h); | |
| 4157 | |
| 4158 hl_decode_mb(h); | |
| 4159 | |
| 4160 if(ret<0){ | |
| 4161 fprintf(stderr, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); | |
| 4162 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); | |
| 4163 | |
| 4164 return -1; | |
| 4165 } | |
| 4166 | |
| 4167 if(++s->mb_x >= s->mb_width){ | |
| 4168 s->mb_x=0; | |
| 4169 if(++s->mb_y >= s->mb_height){ | |
| 4170 if(get_bits_count(s->gb) == s->gb.size_in_bits){ | |
| 4171 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); | |
| 4172 | |
| 4173 return 0; | |
| 4174 }else{ | |
| 4175 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); | |
| 4176 | |
| 4177 return -1; | |
| 4178 } | |
| 4179 } | |
| 4180 } | |
| 4181 | |
| 4182 if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){ | |
| 4183 if(get_bits_count(s->gb) == s->gb.size_in_bits){ | |
| 4184 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); | |
| 4185 | |
| 4186 return 0; | |
| 4187 }else{ | |
| 4188 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); | |
| 4189 | |
| 4190 return -1; | |
| 4191 } | |
| 4192 } | |
| 4193 } | |
| 4194 s->mb_x=0; | |
| 4195 ff_draw_horiz_band(s, 16*s->mb_y, 16); | |
| 4196 } | |
| 4197 #endif | |
| 4198 return -1; //not reached | |
| 4199 } | |
| 4200 | |
| 4201 static inline int decode_vui_parameters(H264Context *h, SPS *sps){ | |
| 4202 MpegEncContext * const s = &h->s; | |
| 4203 int aspect_ratio_info_present_flag, aspect_ratio_idc; | |
| 4204 | |
| 4205 aspect_ratio_info_present_flag= get_bits1(&s->gb); | |
| 4206 | |
| 4207 if( aspect_ratio_info_present_flag ) { | |
| 4208 aspect_ratio_idc= get_bits(&s->gb, 8); | |
| 4209 if( aspect_ratio_idc == EXTENDED_SAR ) { | |
| 1548 | 4210 sps->sar.num= get_bits(&s->gb, 16); |
| 4211 sps->sar.den= get_bits(&s->gb, 16); | |
| 1168 | 4212 }else if(aspect_ratio_idc < 16){ |
| 1548 | 4213 sps->sar= pixel_aspect[aspect_ratio_idc]; |
| 1168 | 4214 }else{ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4215 av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); |
| 1168 | 4216 return -1; |
| 4217 } | |
| 4218 }else{ | |
| 1548 | 4219 sps->sar.num= |
| 4220 sps->sar.den= 0; | |
| 1168 | 4221 } |
| 4222 // s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height); | |
| 4223 #if 0 | |
| 4224 | overscan_info_present_flag |0 |u(1) | | |
| 4225 | if( overscan_info_present_flag ) | | | | |
| 4226 | overscan_appropriate_flag |0 |u(1) | | |
| 4227 | video_signal_type_present_flag |0 |u(1) | | |
| 4228 | if( video_signal_type_present_flag ) { | | | | |
| 4229 | video_format |0 |u(3) | | |
| 4230 | video_full_range_flag |0 |u(1) | | |
| 4231 | colour_description_present_flag |0 |u(1) | | |
| 4232 | if( colour_description_present_flag ) { | | | | |
| 4233 | colour_primaries |0 |u(8) | | |
| 4234 | transfer_characteristics |0 |u(8) | | |
| 4235 | matrix_coefficients |0 |u(8) | | |
| 4236 | } | | | | |
| 4237 | } | | | | |
| 4238 | chroma_location_info_present_flag |0 |u(1) | | |
| 4239 | if ( chroma_location_info_present_flag ) { | | | | |
| 4240 | chroma_sample_location_type_top_field |0 |ue(v) | | |
| 4241 | chroma_sample_location_type_bottom_field |0 |ue(v) | | |
| 4242 | } | | | | |
| 4243 | timing_info_present_flag |0 |u(1) | | |
| 4244 | if( timing_info_present_flag ) { | | | | |
| 4245 | num_units_in_tick |0 |u(32) | | |
| 4246 | time_scale |0 |u(32) | | |
| 4247 | fixed_frame_rate_flag |0 |u(1) | | |
| 4248 | } | | | | |
| 4249 | nal_hrd_parameters_present_flag |0 |u(1) | | |
| 4250 | if( nal_hrd_parameters_present_flag = = 1) | | | | |
| 4251 | hrd_parameters( ) | | | | |
| 4252 | vcl_hrd_parameters_present_flag |0 |u(1) | | |
| 4253 | if( vcl_hrd_parameters_present_flag = = 1) | | | | |
| 4254 | hrd_parameters( ) | | | | |
| 4255 | if( ( nal_hrd_parameters_present_flag = = 1 | || | | | |
| 4256 | | | | | |
| 4257 |( vcl_hrd_parameters_present_flag = = 1 ) ) | | | | |
| 4258 | low_delay_hrd_flag |0 |u(1) | | |
| 4259 | bitstream_restriction_flag |0 |u(1) | | |
| 4260 | if( bitstream_restriction_flag ) { |0 |u(1) | | |
| 4261 | motion_vectors_over_pic_boundaries_flag |0 |u(1) | | |
| 4262 | max_bytes_per_pic_denom |0 |ue(v) | | |
| 4263 | max_bits_per_mb_denom |0 |ue(v) | | |
| 4264 | log2_max_mv_length_horizontal |0 |ue(v) | | |
| 4265 | log2_max_mv_length_vertical |0 |ue(v) | | |
| 4266 | num_reorder_frames |0 |ue(v) | | |
| 4267 | max_dec_frame_buffering |0 |ue(v) | | |
| 4268 | } | | | | |
| 4269 |} | | | | |
| 4270 #endif | |
| 4271 return 0; | |
| 4272 } | |
| 4273 | |
| 4274 static inline int decode_seq_parameter_set(H264Context *h){ | |
| 4275 MpegEncContext * const s = &h->s; | |
| 1371 | 4276 int profile_idc, level_idc; |
| 1168 | 4277 int sps_id, i; |
| 4278 SPS *sps; | |
| 4279 | |
| 4280 profile_idc= get_bits(&s->gb, 8); | |
| 1371 | 4281 get_bits1(&s->gb); //constraint_set0_flag |
| 4282 get_bits1(&s->gb); //constraint_set1_flag | |
| 4283 get_bits1(&s->gb); //constraint_set2_flag | |
| 4284 get_bits(&s->gb, 5); // reserved | |
| 1168 | 4285 level_idc= get_bits(&s->gb, 8); |
| 4286 sps_id= get_ue_golomb(&s->gb); | |
| 4287 | |
| 4288 sps= &h->sps_buffer[ sps_id ]; | |
| 4289 sps->profile_idc= profile_idc; | |
| 4290 sps->level_idc= level_idc; | |
| 4291 | |
| 4292 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; | |
| 4293 sps->poc_type= get_ue_golomb(&s->gb); | |
| 4294 | |
| 4295 if(sps->poc_type == 0){ //FIXME #define | |
| 4296 sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4; | |
| 4297 } else if(sps->poc_type == 1){//FIXME #define | |
| 4298 sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); | |
| 4299 sps->offset_for_non_ref_pic= get_se_golomb(&s->gb); | |
| 4300 sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb); | |
| 4301 sps->poc_cycle_length= get_ue_golomb(&s->gb); | |
| 4302 | |
| 4303 for(i=0; i<sps->poc_cycle_length; i++) | |
| 4304 sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); | |
| 4305 } | |
| 4306 if(sps->poc_type > 2){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4307 av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); |
| 1168 | 4308 return -1; |
| 4309 } | |
| 4310 | |
| 4311 sps->ref_frame_count= get_ue_golomb(&s->gb); | |
| 1371 | 4312 sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); |
| 1168 | 4313 sps->mb_width= get_ue_golomb(&s->gb) + 1; |
| 4314 sps->mb_height= get_ue_golomb(&s->gb) + 1; | |
| 4315 sps->frame_mbs_only_flag= get_bits1(&s->gb); | |
| 4316 if(!sps->frame_mbs_only_flag) | |
| 4317 sps->mb_aff= get_bits1(&s->gb); | |
| 4318 else | |
| 4319 sps->mb_aff= 0; | |
| 4320 | |
| 4321 sps->direct_8x8_inference_flag= get_bits1(&s->gb); | |
| 4322 | |
| 1371 | 4323 sps->crop= get_bits1(&s->gb); |
| 4324 if(sps->crop){ | |
| 4325 sps->crop_left = get_ue_golomb(&s->gb); | |
| 4326 sps->crop_right = get_ue_golomb(&s->gb); | |
| 4327 sps->crop_top = get_ue_golomb(&s->gb); | |
| 4328 sps->crop_bottom= get_ue_golomb(&s->gb); | |
| 4329 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
|
4330 av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completly supported, this could look slightly wrong ...\n"); |
| 1371 | 4331 } |
| 4332 }else{ | |
| 4333 sps->crop_left = | |
| 4334 sps->crop_right = | |
| 4335 sps->crop_top = | |
| 4336 sps->crop_bottom= 0; | |
| 4337 } | |
| 4338 | |
| 1168 | 4339 sps->vui_parameters_present_flag= get_bits1(&s->gb); |
| 4340 if( sps->vui_parameters_present_flag ) | |
| 4341 decode_vui_parameters(h, sps); | |
| 4342 | |
| 4343 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
|
4344 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 | 4345 sps_id, sps->profile_idc, sps->level_idc, |
| 4346 sps->poc_type, | |
| 4347 sps->ref_frame_count, | |
| 4348 sps->mb_width, sps->mb_height, | |
| 4349 sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"), | |
| 4350 sps->direct_8x8_inference_flag ? "8B8" : "", | |
| 1371 | 4351 sps->crop_left, sps->crop_right, |
| 4352 sps->crop_top, sps->crop_bottom, | |
| 1168 | 4353 sps->vui_parameters_present_flag ? "VUI" : "" |
| 4354 ); | |
| 4355 } | |
| 4356 return 0; | |
| 4357 } | |
| 4358 | |
| 4359 static inline int decode_picture_parameter_set(H264Context *h){ | |
| 4360 MpegEncContext * const s = &h->s; | |
| 4361 int pps_id= get_ue_golomb(&s->gb); | |
| 4362 PPS *pps= &h->pps_buffer[pps_id]; | |
| 4363 | |
| 4364 pps->sps_id= get_ue_golomb(&s->gb); | |
| 4365 pps->cabac= get_bits1(&s->gb); | |
| 4366 pps->pic_order_present= get_bits1(&s->gb); | |
| 4367 pps->slice_group_count= get_ue_golomb(&s->gb) + 1; | |
| 4368 if(pps->slice_group_count > 1 ){ | |
| 4369 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
|
4370 av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); |
| 1168 | 4371 switch(pps->mb_slice_group_map_type){ |
| 4372 case 0: | |
| 4373 #if 0 | |
| 4374 | for( i = 0; i <= num_slice_groups_minus1; i++ ) | | | | |
| 4375 | run_length[ i ] |1 |ue(v) | | |
| 4376 #endif | |
| 4377 break; | |
| 4378 case 2: | |
| 4379 #if 0 | |
| 4380 | for( i = 0; i < num_slice_groups_minus1; i++ ) | | | | |
| 4381 |{ | | | | |
| 4382 | top_left_mb[ i ] |1 |ue(v) | | |
| 4383 | bottom_right_mb[ i ] |1 |ue(v) | | |
| 4384 | } | | | | |
| 4385 #endif | |
| 4386 break; | |
| 4387 case 3: | |
| 4388 case 4: | |
| 4389 case 5: | |
| 4390 #if 0 | |
| 4391 | slice_group_change_direction_flag |1 |u(1) | | |
| 4392 | slice_group_change_rate_minus1 |1 |ue(v) | | |
| 4393 #endif | |
| 4394 break; | |
| 4395 case 6: | |
| 4396 #if 0 | |
| 4397 | slice_group_id_cnt_minus1 |1 |ue(v) | | |
| 4398 | for( i = 0; i <= slice_group_id_cnt_minus1; i++ | | | | |
| 4399 |) | | | | |
| 4400 | slice_group_id[ i ] |1 |u(v) | | |
| 4401 #endif | |
| 1214 | 4402 break; |
| 1168 | 4403 } |
| 4404 } | |
| 4405 pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; | |
| 4406 pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; | |
| 4407 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
|
4408 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); |
| 1168 | 4409 return -1; |
| 4410 } | |
| 4411 | |
| 4412 pps->weighted_pred= get_bits1(&s->gb); | |
| 4413 pps->weighted_bipred_idc= get_bits(&s->gb, 2); | |
| 4414 pps->init_qp= get_se_golomb(&s->gb) + 26; | |
| 4415 pps->init_qs= get_se_golomb(&s->gb) + 26; | |
| 4416 pps->chroma_qp_index_offset= get_se_golomb(&s->gb); | |
| 4417 pps->deblocking_filter_parameters_present= get_bits1(&s->gb); | |
| 4418 pps->constrained_intra_pred= get_bits1(&s->gb); | |
| 4419 pps->redundant_pic_cnt_present = get_bits1(&s->gb); | |
| 4420 | |
| 4421 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
|
4422 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 | 4423 pps_id, pps->sps_id, |
| 4424 pps->cabac ? "CABAC" : "CAVLC", | |
| 4425 pps->slice_group_count, | |
| 4426 pps->ref_count[0], pps->ref_count[1], | |
| 4427 pps->weighted_pred ? "weighted" : "", | |
| 4428 pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset, | |
| 4429 pps->deblocking_filter_parameters_present ? "LPAR" : "", | |
| 4430 pps->constrained_intra_pred ? "CONSTR" : "", | |
| 1371 | 4431 pps->redundant_pic_cnt_present ? "REDU" : "" |
| 1168 | 4432 ); |
| 4433 } | |
| 4434 | |
| 4435 return 0; | |
| 4436 } | |
| 4437 | |
| 4438 /** | |
| 4439 * finds the end of the current frame in the bitstream. | |
| 4440 * @return the position of the first byte of the next frame, or -1 | |
| 4441 */ | |
| 4442 static int find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ | |
| 4443 ParseContext *pc= &s->parse_context; | |
| 1187 | 4444 int i; |
| 1168 | 4445 uint32_t state; |
| 4446 //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); | |
| 4447 // mb_addr= pc->mb_addr - 1; | |
| 4448 state= pc->state; | |
| 4449 //FIXME this will fail with slices | |
| 4450 for(i=0; i<buf_size; i++){ | |
| 4451 state= (state<<8) | buf[i]; | |
| 4452 if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){ | |
| 4453 if(pc->frame_start_found){ | |
| 4454 pc->state=-1; | |
| 4455 pc->frame_start_found= 0; | |
| 4456 return i-3; | |
| 4457 } | |
| 4458 pc->frame_start_found= 1; | |
| 4459 } | |
| 4460 } | |
| 4461 | |
| 4462 pc->state= state; | |
| 1219 | 4463 return END_NOT_FOUND; |
| 1168 | 4464 } |
| 4465 | |
| 4466 static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ | |
| 4467 MpegEncContext * const s = &h->s; | |
| 4468 AVCodecContext * const avctx= s->avctx; | |
| 4469 int buf_index=0; | |
| 1322 | 4470 #if 0 |
| 1168 | 4471 int i; |
| 4472 for(i=0; i<32; i++){ | |
| 4473 printf("%X ", buf[i]); | |
| 4474 } | |
| 4475 #endif | |
| 4476 for(;;){ | |
| 4477 int consumed; | |
| 4478 int dst_length; | |
| 4479 int bit_length; | |
| 4480 uint8_t *ptr; | |
| 4481 | |
| 4482 // start code prefix search | |
| 4483 for(; buf_index + 3 < buf_size; buf_index++){ | |
| 4484 // this should allways succeed in the first iteration | |
| 4485 if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1) | |
| 4486 break; | |
| 4487 } | |
| 4488 | |
| 4489 if(buf_index+3 >= buf_size) break; | |
| 4490 | |
| 4491 buf_index+=3; | |
| 4492 | |
| 4493 ptr= decode_nal(h, buf + buf_index, &dst_length, &consumed, buf_size - buf_index); | |
| 4494 if(ptr[dst_length - 1] == 0) dst_length--; | |
| 4495 bit_length= 8*dst_length - decode_rbsp_trailing(ptr + dst_length - 1); | |
| 4496 | |
| 4497 if(s->avctx->debug&FF_DEBUG_STARTCODE){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4498 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d length %d\n", h->nal_unit_type, buf_index, dst_length); |
| 1168 | 4499 } |
| 4500 | |
| 4501 buf_index += consumed; | |
| 4502 | |
| 4503 if(h->nal_ref_idc < s->hurry_up) | |
| 4504 continue; | |
| 4505 | |
| 4506 switch(h->nal_unit_type){ | |
| 4507 case NAL_IDR_SLICE: | |
| 4508 idr(h); //FIXME ensure we dont loose some frames if there is reordering | |
| 4509 case NAL_SLICE: | |
| 4510 init_get_bits(&s->gb, ptr, bit_length); | |
| 4511 h->intra_gb_ptr= | |
| 4512 h->inter_gb_ptr= &s->gb; | |
| 4513 s->data_partitioning = 0; | |
| 4514 | |
| 4515 if(decode_slice_header(h) < 0) return -1; | |
| 4516 if(h->redundant_pic_count==0) | |
| 4517 decode_slice(h); | |
| 4518 break; | |
| 4519 case NAL_DPA: | |
| 4520 init_get_bits(&s->gb, ptr, bit_length); | |
| 4521 h->intra_gb_ptr= | |
| 4522 h->inter_gb_ptr= NULL; | |
| 4523 s->data_partitioning = 1; | |
| 4524 | |
| 4525 if(decode_slice_header(h) < 0) return -1; | |
| 4526 break; | |
| 4527 case NAL_DPB: | |
| 4528 init_get_bits(&h->intra_gb, ptr, bit_length); | |
| 4529 h->intra_gb_ptr= &h->intra_gb; | |
| 4530 break; | |
| 4531 case NAL_DPC: | |
| 4532 init_get_bits(&h->inter_gb, ptr, bit_length); | |
| 4533 h->inter_gb_ptr= &h->inter_gb; | |
| 1174 | 4534 |
| 4535 if(h->redundant_pic_count==0 && h->intra_gb_ptr && s->data_partitioning) | |
| 1168 | 4536 decode_slice(h); |
| 4537 break; | |
| 4538 case NAL_SEI: | |
| 4539 break; | |
| 4540 case NAL_SPS: | |
| 4541 init_get_bits(&s->gb, ptr, bit_length); | |
| 4542 decode_seq_parameter_set(h); | |
| 4543 | |
| 4544 if(s->flags& CODEC_FLAG_LOW_DELAY) | |
| 4545 s->low_delay=1; | |
| 4546 | |
| 4547 avctx->has_b_frames= !s->low_delay; | |
| 4548 break; | |
| 4549 case NAL_PPS: | |
| 4550 init_get_bits(&s->gb, ptr, bit_length); | |
| 4551 | |
| 4552 decode_picture_parameter_set(h); | |
| 4553 | |
| 4554 break; | |
| 4555 case NAL_PICTURE_DELIMITER: | |
| 4556 break; | |
| 4557 case NAL_FILTER_DATA: | |
| 4558 break; | |
| 4559 } | |
| 4560 | |
| 4561 //FIXME move after where irt is set | |
| 4562 s->current_picture.pict_type= s->pict_type; | |
| 4563 s->current_picture.key_frame= s->pict_type == I_TYPE; | |
| 4564 } | |
| 4565 | |
| 1174 | 4566 if(!s->current_picture_ptr) return buf_index; //no frame |
| 4567 | |
| 1168 | 4568 h->prev_frame_num_offset= h->frame_num_offset; |
| 4569 h->prev_frame_num= h->frame_num; | |
| 4570 if(s->current_picture_ptr->reference){ | |
| 4571 h->prev_poc_msb= h->poc_msb; | |
| 4572 h->prev_poc_lsb= h->poc_lsb; | |
| 4573 } | |
| 4574 if(s->current_picture_ptr->reference) | |
| 4575 execute_ref_pic_marking(h, h->mmco, h->mmco_index); | |
| 4576 else | |
| 1169 | 4577 assert(h->mmco_index==0); |
| 1168 | 4578 |
| 4579 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
|
4580 |
| 1168 | 4581 MPV_frame_end(s); |
| 4582 | |
| 4583 return buf_index; | |
| 4584 } | |
| 4585 | |
| 4586 /** | |
| 4587 * retunrs the number of bytes consumed for building the current frame | |
| 4588 */ | |
| 4589 static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){ | |
| 4590 if(s->flags&CODEC_FLAG_TRUNCATED){ | |
| 4591 pos -= s->parse_context.last_index; | |
| 4592 if(pos<0) pos=0; // FIXME remove (uneeded?) | |
| 4593 | |
| 4594 return pos; | |
| 4595 }else{ | |
| 4596 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) | |
| 4597 if(pos+10>buf_size) pos=buf_size; // oops ;) | |
| 4598 | |
| 4599 return pos; | |
| 4600 } | |
| 4601 } | |
| 4602 | |
| 4603 static int decode_frame(AVCodecContext *avctx, | |
| 4604 void *data, int *data_size, | |
| 4605 uint8_t *buf, int buf_size) | |
| 4606 { | |
| 4607 H264Context *h = avctx->priv_data; | |
| 4608 MpegEncContext *s = &h->s; | |
| 4609 AVFrame *pict = data; | |
| 4610 int buf_index; | |
| 4611 | |
| 4612 s->flags= avctx->flags; | |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1706
diff
changeset
|
4613 s->flags2= avctx->flags2; |
| 1168 | 4614 |
| 4615 *data_size = 0; | |
| 4616 | |
| 4617 /* no supplementary picture */ | |
| 4618 if (buf_size == 0) { | |
| 4619 return 0; | |
| 4620 } | |
| 4621 | |
| 4622 if(s->flags&CODEC_FLAG_TRUNCATED){ | |
| 4623 int next= find_frame_end(s, buf, buf_size); | |
| 4624 | |
| 4625 if( ff_combine_frame(s, next, &buf, &buf_size) < 0 ) | |
| 4626 return buf_size; | |
| 4627 //printf("next:%d buf_size:%d last_index:%d\n", next, buf_size, s->parse_context.last_index); | |
| 4628 } | |
| 4629 | |
| 4630 if(s->avctx->extradata_size && s->picture_number==0){ | |
| 4631 if(0 < decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) ) | |
| 4632 return -1; | |
| 4633 } | |
| 4634 | |
| 4635 buf_index=decode_nal_units(h, buf, buf_size); | |
| 4636 if(buf_index < 0) | |
| 4637 return -1; | |
| 4638 | |
| 4639 //FIXME do something with unavailable reference frames | |
| 4640 | |
| 4641 // if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_index, buf_size); | |
| 4642 #if 0 | |
| 4643 if(s->pict_type==B_TYPE || s->low_delay){ | |
| 4644 *pict= *(AVFrame*)&s->current_picture; | |
| 4645 } else { | |
| 4646 *pict= *(AVFrame*)&s->last_picture; | |
| 4647 } | |
| 4648 #endif | |
| 1174 | 4649 if(!s->current_picture_ptr){ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4650 av_log(h->s.avctx, AV_LOG_DEBUG, "error, NO frame\n"); |
| 1174 | 4651 return -1; |
| 4652 } | |
| 4653 | |
| 1168 | 4654 *pict= *(AVFrame*)&s->current_picture; //FIXME |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1698
diff
changeset
|
4655 ff_print_debug_info(s, pict); |
| 1168 | 4656 assert(pict->data[0]); |
| 4657 //printf("out %d\n", (int)pict->data[0]); | |
| 4658 #if 0 //? | |
| 4659 | |
| 4660 /* Return the Picture timestamp as the frame number */ | |
| 4661 /* we substract 1 because it is added on utils.c */ | |
| 4662 avctx->frame_number = s->picture_number - 1; | |
| 4663 #endif | |
| 4664 #if 0 | |
| 4665 /* dont output the last pic after seeking */ | |
| 4666 if(s->last_picture_ptr || s->low_delay) | |
| 4667 //Note this isnt a issue as a IDR pic should flush teh buffers | |
| 4668 #endif | |
| 4669 *data_size = sizeof(AVFrame); | |
| 4670 return get_consumed_bytes(s, buf_index, buf_size); | |
| 4671 } | |
| 4672 #if 0 | |
| 4673 static inline void fill_mb_avail(H264Context *h){ | |
| 4674 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
|
4675 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
| 1168 | 4676 |
| 4677 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
|
4678 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
|
4679 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
|
4680 h->mb_avail[2]= s->mb_x+1 < s->mb_width && h->slice_table[mb_xy - s->mb_stride + 1] == h->slice_num; |
| 1168 | 4681 }else{ |
| 4682 h->mb_avail[0]= | |
| 4683 h->mb_avail[1]= | |
| 4684 h->mb_avail[2]= 0; | |
| 4685 } | |
| 4686 h->mb_avail[3]= s->mb_x && h->slice_table[mb_xy - 1] == h->slice_num; | |
| 4687 h->mb_avail[4]= 1; //FIXME move out | |
| 4688 h->mb_avail[5]= 0; //FIXME move out | |
| 4689 } | |
| 4690 #endif | |
| 4691 | |
| 4692 #if 0 //selftest | |
| 4693 #define COUNT 8000 | |
| 4694 #define SIZE (COUNT*40) | |
| 4695 int main(){ | |
| 4696 int i; | |
| 4697 uint8_t temp[SIZE]; | |
| 4698 PutBitContext pb; | |
| 4699 GetBitContext gb; | |
| 4700 // int int_temp[10000]; | |
| 4701 DSPContext dsp; | |
| 4702 AVCodecContext avctx; | |
| 4703 | |
| 4704 dsputil_init(&dsp, &avctx); | |
| 4705 | |
|
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1453
diff
changeset
|
4706 init_put_bits(&pb, temp, SIZE); |
| 1168 | 4707 printf("testing unsigned exp golomb\n"); |
| 4708 for(i=0; i<COUNT; i++){ | |
| 4709 START_TIMER | |
| 4710 set_ue_golomb(&pb, i); | |
| 4711 STOP_TIMER("set_ue_golomb"); | |
| 4712 } | |
| 4713 flush_put_bits(&pb); | |
| 4714 | |
| 4715 init_get_bits(&gb, temp, 8*SIZE); | |
| 4716 for(i=0; i<COUNT; i++){ | |
| 4717 int j, s; | |
| 4718 | |
| 4719 s= show_bits(&gb, 24); | |
| 4720 | |
| 4721 START_TIMER | |
| 4722 j= get_ue_golomb(&gb); | |
| 4723 if(j != i){ | |
| 4724 printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); | |
| 4725 // return -1; | |
| 4726 } | |
| 4727 STOP_TIMER("get_ue_golomb"); | |
| 4728 } | |
| 4729 | |
| 4730 | |
| 1524 | 4731 init_put_bits(&pb, temp, SIZE); |
| 1168 | 4732 printf("testing signed exp golomb\n"); |
| 4733 for(i=0; i<COUNT; i++){ | |
| 4734 START_TIMER | |
| 4735 set_se_golomb(&pb, i - COUNT/2); | |
| 4736 STOP_TIMER("set_se_golomb"); | |
| 4737 } | |
| 4738 flush_put_bits(&pb); | |
| 4739 | |
| 4740 init_get_bits(&gb, temp, 8*SIZE); | |
| 4741 for(i=0; i<COUNT; i++){ | |
| 4742 int j, s; | |
| 4743 | |
| 4744 s= show_bits(&gb, 24); | |
| 4745 | |
| 4746 START_TIMER | |
| 4747 j= get_se_golomb(&gb); | |
| 4748 if(j != i - COUNT/2){ | |
| 4749 printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); | |
| 4750 // return -1; | |
| 4751 } | |
| 4752 STOP_TIMER("get_se_golomb"); | |
| 4753 } | |
| 4754 | |
| 4755 printf("testing 4x4 (I)DCT\n"); | |
| 4756 | |
| 4757 DCTELEM block[16]; | |
| 4758 uint8_t src[16], ref[16]; | |
| 4759 uint64_t error= 0, max_error=0; | |
| 4760 | |
| 4761 for(i=0; i<COUNT; i++){ | |
| 4762 int j; | |
| 4763 // printf("%d %d %d\n", r1, r2, (r2-r1)*16); | |
| 4764 for(j=0; j<16; j++){ | |
| 4765 ref[j]= random()%255; | |
| 4766 src[j]= random()%255; | |
| 4767 } | |
| 4768 | |
| 4769 h264_diff_dct_c(block, src, ref, 4); | |
| 4770 | |
| 4771 //normalize | |
| 4772 for(j=0; j<16; j++){ | |
| 4773 // printf("%d ", block[j]); | |
| 4774 block[j]= block[j]*4; | |
| 4775 if(j&1) block[j]= (block[j]*4 + 2)/5; | |
| 4776 if(j&4) block[j]= (block[j]*4 + 2)/5; | |
| 4777 } | |
| 4778 // printf("\n"); | |
| 4779 | |
| 4780 h264_add_idct_c(ref, block, 4); | |
| 4781 /* for(j=0; j<16; j++){ | |
| 4782 printf("%d ", ref[j]); | |
| 4783 } | |
| 4784 printf("\n");*/ | |
| 4785 | |
| 4786 for(j=0; j<16; j++){ | |
| 4787 int diff= ABS(src[j] - ref[j]); | |
| 4788 | |
| 4789 error+= diff*diff; | |
| 4790 max_error= FFMAX(max_error, diff); | |
| 4791 } | |
| 4792 } | |
| 4793 printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error ); | |
| 4794 #if 0 | |
| 4795 printf("testing quantizer\n"); | |
| 4796 for(qp=0; qp<52; qp++){ | |
| 4797 for(i=0; i<16; i++) | |
| 4798 src1_block[i]= src2_block[i]= random()%255; | |
| 4799 | |
| 4800 } | |
| 4801 #endif | |
| 4802 printf("Testing NAL layer\n"); | |
| 4803 | |
| 4804 uint8_t bitstream[COUNT]; | |
| 4805 uint8_t nal[COUNT*2]; | |
| 4806 H264Context h; | |
| 4807 memset(&h, 0, sizeof(H264Context)); | |
| 4808 | |
| 4809 for(i=0; i<COUNT; i++){ | |
| 4810 int zeros= i; | |
| 4811 int nal_length; | |
| 4812 int consumed; | |
| 4813 int out_length; | |
| 4814 uint8_t *out; | |
| 4815 int j; | |
| 4816 | |
| 4817 for(j=0; j<COUNT; j++){ | |
| 4818 bitstream[j]= (random() % 255) + 1; | |
| 4819 } | |
| 4820 | |
| 4821 for(j=0; j<zeros; j++){ | |
| 4822 int pos= random() % COUNT; | |
| 4823 while(bitstream[pos] == 0){ | |
| 4824 pos++; | |
| 4825 pos %= COUNT; | |
| 4826 } | |
| 4827 bitstream[pos]=0; | |
| 4828 } | |
| 4829 | |
| 4830 START_TIMER | |
| 4831 | |
| 4832 nal_length= encode_nal(&h, nal, bitstream, COUNT, COUNT*2); | |
| 4833 if(nal_length<0){ | |
| 4834 printf("encoding failed\n"); | |
| 4835 return -1; | |
| 4836 } | |
| 4837 | |
| 4838 out= decode_nal(&h, nal, &out_length, &consumed, nal_length); | |
| 4839 | |
| 4840 STOP_TIMER("NAL") | |
| 4841 | |
| 4842 if(out_length != COUNT){ | |
| 4843 printf("incorrect length %d %d\n", out_length, COUNT); | |
| 4844 return -1; | |
| 4845 } | |
| 4846 | |
| 4847 if(consumed != nal_length){ | |
| 4848 printf("incorrect consumed length %d %d\n", nal_length, consumed); | |
| 4849 return -1; | |
| 4850 } | |
| 4851 | |
| 4852 if(memcmp(bitstream, out, COUNT)){ | |
| 4853 printf("missmatch\n"); | |
| 4854 return -1; | |
| 4855 } | |
| 4856 } | |
| 4857 | |
| 4858 printf("Testing RBSP\n"); | |
| 4859 | |
| 4860 | |
| 4861 return 0; | |
| 4862 } | |
| 4863 #endif | |
| 4864 | |
| 4865 | |
| 4866 static int decode_end(AVCodecContext *avctx) | |
| 4867 { | |
| 4868 H264Context *h = avctx->priv_data; | |
| 4869 MpegEncContext *s = &h->s; | |
| 4870 | |
| 4871 free_tables(h); //FIXME cleanup init stuff perhaps | |
| 4872 MPV_common_end(s); | |
| 4873 | |
| 4874 // memset(h, 0, sizeof(H264Context)); | |
| 4875 | |
| 4876 return 0; | |
| 4877 } | |
| 4878 | |
| 4879 | |
| 4880 AVCodec h264_decoder = { | |
| 4881 "h264", | |
| 4882 CODEC_TYPE_VIDEO, | |
| 4883 CODEC_ID_H264, | |
| 4884 sizeof(H264Context), | |
| 4885 decode_init, | |
| 4886 NULL, | |
| 4887 decode_end, | |
| 4888 decode_frame, | |
| 1214 | 4889 /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, |
| 1168 | 4890 }; |
| 4891 | |
| 1234 | 4892 #include "svq3.c" |
