Mercurial > libavcodec.hg
annotate h264.c @ 2447:0237bb5ca0f0 libavcodec
simplify
reference list 1 swaping fix? seems its not used by any samples i found though
author | michael |
---|---|
date | Sun, 23 Jan 2005 03:49:36 +0000 |
parents | 358813ec4ca2 |
children | 6f719184e2b9 |
rev | line source |
---|---|
1168 | 1 /* |
2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder | |
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 * | |
19 */ | |
20 | |
21 /** | |
22 * @file h264.c | |
23 * H.264 / AVC / MPEG4 part10 codec. | |
24 * @author Michael Niedermayer <michaelni@gmx.at> | |
25 */ | |
26 | |
27 #include "common.h" | |
28 #include "dsputil.h" | |
29 #include "avcodec.h" | |
30 #include "mpegvideo.h" | |
31 #include "h264data.h" | |
32 #include "golomb.h" | |
33 | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
34 #include "cabac.h" |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
35 |
1168 | 36 #undef NDEBUG |
37 #include <assert.h> | |
38 | |
39 #define interlaced_dct interlaced_dct_is_a_bad_name | |
40 #define mb_intra mb_intra_isnt_initalized_see_mb_type | |
41 | |
42 #define LUMA_DC_BLOCK_INDEX 25 | |
43 #define CHROMA_DC_BLOCK_INDEX 26 | |
44 | |
45 #define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8 | |
46 #define COEFF_TOKEN_VLC_BITS 8 | |
47 #define TOTAL_ZEROS_VLC_BITS 9 | |
48 #define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3 | |
49 #define RUN_VLC_BITS 3 | |
50 #define RUN7_VLC_BITS 6 | |
51 | |
52 #define MAX_SPS_COUNT 32 | |
53 #define MAX_PPS_COUNT 256 | |
54 | |
55 #define MAX_MMCO_COUNT 66 | |
56 | |
57 /** | |
58 * Sequence parameter set | |
59 */ | |
60 typedef struct SPS{ | |
61 | |
62 int profile_idc; | |
63 int level_idc; | |
64 int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4 | |
65 int poc_type; ///< pic_order_cnt_type | |
66 int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4 | |
67 int delta_pic_order_always_zero_flag; | |
68 int offset_for_non_ref_pic; | |
69 int offset_for_top_to_bottom_field; | |
70 int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle | |
71 int ref_frame_count; ///< num_ref_frames | |
1371 | 72 int gaps_in_frame_num_allowed_flag; |
1168 | 73 int mb_width; ///< frame_width_in_mbs_minus1 + 1 |
74 int mb_height; ///< frame_height_in_mbs_minus1 + 1 | |
75 int frame_mbs_only_flag; | |
76 int mb_aff; ///<mb_adaptive_frame_field_flag | |
77 int direct_8x8_inference_flag; | |
1371 | 78 int crop; ///< frame_cropping_flag |
79 int crop_left; ///< frame_cropping_rect_left_offset | |
80 int crop_right; ///< frame_cropping_rect_right_offset | |
81 int crop_top; ///< frame_cropping_rect_top_offset | |
82 int crop_bottom; ///< frame_cropping_rect_bottom_offset | |
1168 | 83 int vui_parameters_present_flag; |
1548 | 84 AVRational sar; |
2174
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
85 int timing_info_present_flag; |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
86 uint32_t num_units_in_tick; |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
87 uint32_t time_scale; |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
88 int fixed_frame_rate_flag; |
1168 | 89 short offset_for_ref_frame[256]; //FIXME dyn aloc? |
90 }SPS; | |
91 | |
92 /** | |
93 * Picture parameter set | |
94 */ | |
95 typedef struct PPS{ | |
96 int sps_id; | |
97 int cabac; ///< entropy_coding_mode_flag | |
98 int pic_order_present; ///< pic_order_present_flag | |
99 int slice_group_count; ///< num_slice_groups_minus1 + 1 | |
100 int mb_slice_group_map_type; | |
101 int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1 | |
102 int weighted_pred; ///< weighted_pred_flag | |
103 int weighted_bipred_idc; | |
104 int init_qp; ///< pic_init_qp_minus26 + 26 | |
105 int init_qs; ///< pic_init_qs_minus26 + 26 | |
106 int chroma_qp_index_offset; | |
107 int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag | |
108 int constrained_intra_pred; ///< constrained_intra_pred_flag | |
109 int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag | |
110 }PPS; | |
111 | |
112 /** | |
113 * Memory management control operation opcode. | |
114 */ | |
115 typedef enum MMCOOpcode{ | |
116 MMCO_END=0, | |
117 MMCO_SHORT2UNUSED, | |
118 MMCO_LONG2UNUSED, | |
119 MMCO_SHORT2LONG, | |
120 MMCO_SET_MAX_LONG, | |
121 MMCO_RESET, | |
122 MMCO_LONG, | |
123 } MMCOOpcode; | |
124 | |
125 /** | |
126 * Memory management control operation. | |
127 */ | |
128 typedef struct MMCO{ | |
129 MMCOOpcode opcode; | |
130 int short_frame_num; | |
131 int long_index; | |
132 } MMCO; | |
133 | |
134 /** | |
135 * H264Context | |
136 */ | |
137 typedef struct H264Context{ | |
138 MpegEncContext s; | |
139 int nal_ref_idc; | |
140 int nal_unit_type; | |
141 #define NAL_SLICE 1 | |
142 #define NAL_DPA 2 | |
143 #define NAL_DPB 3 | |
144 #define NAL_DPC 4 | |
145 #define NAL_IDR_SLICE 5 | |
146 #define NAL_SEI 6 | |
147 #define NAL_SPS 7 | |
148 #define NAL_PPS 8 | |
149 #define NAL_PICTURE_DELIMITER 9 | |
150 #define NAL_FILTER_DATA 10 | |
151 uint8_t *rbsp_buffer; | |
152 int rbsp_buffer_size; | |
153 | |
2227 | 154 /** |
155 * Used to parse AVC variant of h264 | |
156 */ | |
157 int is_avc; ///< this flag is != 0 if codec is avc1 | |
158 int got_avcC; ///< flag used to parse avcC data only once | |
159 int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) | |
160 | |
1168 | 161 int chroma_qp; //QPc |
162 | |
163 int prev_mb_skiped; //FIXME remove (IMHO not used) | |
164 | |
165 //prediction stuff | |
166 int chroma_pred_mode; | |
167 int intra16x16_pred_mode; | |
168 | |
169 int8_t intra4x4_pred_mode_cache[5*8]; | |
170 int8_t (*intra4x4_pred_mode)[8]; | |
171 void (*pred4x4 [9+3])(uint8_t *src, uint8_t *topright, int stride);//FIXME move to dsp? | |
172 void (*pred8x8 [4+3])(uint8_t *src, int stride); | |
173 void (*pred16x16[4+3])(uint8_t *src, int stride); | |
174 unsigned int topleft_samples_available; | |
175 unsigned int top_samples_available; | |
176 unsigned int topright_samples_available; | |
177 unsigned int left_samples_available; | |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
178 uint8_t (*top_border)[16+2*8]; |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
179 uint8_t left_border[17+2*9]; |
1168 | 180 |
181 /** | |
182 * non zero coeff count cache. | |
183 * is 64 if not available. | |
184 */ | |
185 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
|
186 uint8_t (*non_zero_count)[16]; |
1168 | 187 |
188 /** | |
189 * Motion vector cache. | |
190 */ | |
191 int16_t mv_cache[2][5*8][2]; | |
192 int8_t ref_cache[2][5*8]; | |
193 #define LIST_NOT_USED -1 //FIXME rename? | |
194 #define PART_NOT_AVAILABLE -2 | |
195 | |
196 /** | |
197 * is 1 if the specific list MV&references are set to 0,0,-2. | |
198 */ | |
199 int mv_cache_clean[2]; | |
200 | |
201 int block_offset[16+8]; | |
202 int chroma_subblock_offset[16]; //FIXME remove | |
203 | |
204 uint16_t *mb2b_xy; //FIXME are these 4 a good idea? | |
205 uint16_t *mb2b8_xy; | |
2395 | 206 int b_stride; //FIXME use s->b4_stride |
1168 | 207 int b8_stride; |
208 | |
1234 | 209 int halfpel_flag; |
210 int thirdpel_flag; | |
211 | |
1319 | 212 int unknown_svq3_flag; |
213 int next_slice_index; | |
214 | |
1168 | 215 SPS sps_buffer[MAX_SPS_COUNT]; |
216 SPS sps; ///< current sps | |
217 | |
218 PPS pps_buffer[MAX_PPS_COUNT]; | |
219 /** | |
220 * current pps | |
221 */ | |
222 PPS pps; //FIXME move tp Picture perhaps? (->no) do we need that? | |
223 | |
224 int slice_num; | |
225 uint8_t *slice_table_base; | |
226 uint8_t *slice_table; ///< slice_table_base + mb_stride + 1 | |
227 int slice_type; | |
228 int slice_type_fixed; | |
229 | |
230 //interlacing specific flags | |
231 int mb_field_decoding_flag; | |
232 | |
233 int sub_mb_type[4]; | |
234 | |
235 //POC stuff | |
236 int poc_lsb; | |
237 int poc_msb; | |
238 int delta_poc_bottom; | |
239 int delta_poc[2]; | |
240 int frame_num; | |
241 int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0 | |
242 int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0 | |
243 int frame_num_offset; ///< for POC type 2 | |
244 int prev_frame_num_offset; ///< for POC type 2 | |
245 int prev_frame_num; ///< frame_num of the last pic for POC type 1/2 | |
246 | |
247 /** | |
248 * frame_num for frames or 2*frame_num for field pics. | |
249 */ | |
250 int curr_pic_num; | |
251 | |
252 /** | |
253 * max_frame_num or 2*max_frame_num for field pics. | |
254 */ | |
255 int max_pic_num; | |
256 | |
257 //Weighted pred stuff | |
2415 | 258 int use_weight; |
259 int use_weight_chroma; | |
1168 | 260 int luma_log2_weight_denom; |
261 int chroma_log2_weight_denom; | |
262 int luma_weight[2][16]; | |
263 int luma_offset[2][16]; | |
264 int chroma_weight[2][16][2]; | |
265 int chroma_offset[2][16][2]; | |
2415 | 266 int implicit_weight[16][16]; |
1168 | 267 |
268 //deblock | |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
269 int deblocking_filter; ///< disable_deblocking_filter_idc with 1<->0 |
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
270 int slice_alpha_c0_offset; |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
271 int slice_beta_offset; |
1168 | 272 |
273 int redundant_pic_count; | |
274 | |
275 int direct_spatial_mv_pred; | |
2396 | 276 int dist_scale_factor[16]; |
1168 | 277 |
278 /** | |
279 * num_ref_idx_l0/1_active_minus1 + 1 | |
280 */ | |
281 int ref_count[2];// FIXME split for AFF | |
282 Picture *short_ref[16]; | |
283 Picture *long_ref[16]; | |
284 Picture default_ref_list[2][32]; | |
285 Picture ref_list[2][32]; //FIXME size? | |
286 Picture field_ref_list[2][32]; //FIXME size? | |
2409 | 287 Picture *delayed_pic[16]; //FIXME size? |
1168 | 288 |
289 /** | |
290 * memory management control operations buffer. | |
291 */ | |
292 MMCO mmco[MAX_MMCO_COUNT]; | |
293 int mmco_index; | |
294 | |
295 int long_ref_count; ///< number of actual long term references | |
296 int short_ref_count; ///< number of actual short term references | |
297 | |
298 //data partitioning | |
299 GetBitContext intra_gb; | |
300 GetBitContext inter_gb; | |
301 GetBitContext *intra_gb_ptr; | |
302 GetBitContext *inter_gb_ptr; | |
303 | |
304 DCTELEM mb[16*24] __align8; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
305 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
306 /** |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
307 * Cabac |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
308 */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
309 CABACContext cabac; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
310 uint8_t cabac_state[399]; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
311 int cabac_init_idc; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
312 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
313 /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
314 uint16_t *cbp_table; |
2314 | 315 int top_cbp; |
316 int left_cbp; | |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
317 /* chroma_pred_mode for i4x4 or i16x16, else 0 */ |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
318 uint8_t *chroma_pred_mode_table; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
319 int last_qscale_diff; |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
320 int16_t (*mvd_table[2])[2]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
321 int16_t mvd_cache[2][5*8][2]; |
2396 | 322 uint8_t *direct_table; |
323 uint8_t direct_cache[5*8]; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
324 |
1168 | 325 }H264Context; |
326 | |
327 static VLC coeff_token_vlc[4]; | |
328 static VLC chroma_dc_coeff_token_vlc; | |
329 | |
330 static VLC total_zeros_vlc[15]; | |
331 static VLC chroma_dc_total_zeros_vlc[3]; | |
332 | |
333 static VLC run_vlc[6]; | |
334 static VLC run7_vlc; | |
335 | |
1234 | 336 static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp); |
337 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
|
338 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 | 339 |
1269 | 340 static inline uint32_t pack16to32(int a, int b){ |
341 #ifdef WORDS_BIGENDIAN | |
342 return (b&0xFFFF) + (a<<16); | |
343 #else | |
344 return (a&0xFFFF) + (b<<16); | |
345 #endif | |
346 } | |
347 | |
1168 | 348 /** |
349 * fill a rectangle. | |
2392 | 350 * @param h height of the rectangle, should be a constant |
351 * @param w width of the rectangle, should be a constant | |
1168 | 352 * @param size the size of val (1 or 4), should be a constant |
353 */ | |
1187 | 354 static inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){ //FIXME ensure this IS inlined |
355 uint8_t *p= (uint8_t*)vp; | |
1168 | 356 assert(size==1 || size==4); |
357 | |
358 w *= size; | |
359 stride *= size; | |
360 | |
361 //FIXME check what gcc generates for 64 bit on x86 and possible write a 32 bit ver of it | |
362 if(w==2 && h==2){ | |
363 *(uint16_t*)(p + 0)= | |
364 *(uint16_t*)(p + stride)= size==4 ? val : val*0x0101; | |
365 }else if(w==2 && h==4){ | |
366 *(uint16_t*)(p + 0*stride)= | |
367 *(uint16_t*)(p + 1*stride)= | |
368 *(uint16_t*)(p + 2*stride)= | |
369 *(uint16_t*)(p + 3*stride)= size==4 ? val : val*0x0101; | |
1252 | 370 }else if(w==4 && h==1){ |
371 *(uint32_t*)(p + 0*stride)= size==4 ? val : val*0x01010101; | |
1168 | 372 }else if(w==4 && h==2){ |
373 *(uint32_t*)(p + 0*stride)= | |
374 *(uint32_t*)(p + 1*stride)= size==4 ? val : val*0x01010101; | |
375 }else if(w==4 && h==4){ | |
376 *(uint32_t*)(p + 0*stride)= | |
377 *(uint32_t*)(p + 1*stride)= | |
378 *(uint32_t*)(p + 2*stride)= | |
379 *(uint32_t*)(p + 3*stride)= size==4 ? val : val*0x01010101; | |
380 }else if(w==8 && h==1){ | |
381 *(uint32_t*)(p + 0)= | |
382 *(uint32_t*)(p + 4)= size==4 ? val : val*0x01010101; | |
383 }else if(w==8 && h==2){ | |
384 *(uint32_t*)(p + 0 + 0*stride)= | |
385 *(uint32_t*)(p + 4 + 0*stride)= | |
386 *(uint32_t*)(p + 0 + 1*stride)= | |
387 *(uint32_t*)(p + 4 + 1*stride)= size==4 ? val : val*0x01010101; | |
388 }else if(w==8 && h==4){ | |
389 *(uint64_t*)(p + 0*stride)= | |
390 *(uint64_t*)(p + 1*stride)= | |
391 *(uint64_t*)(p + 2*stride)= | |
392 *(uint64_t*)(p + 3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
393 }else if(w==16 && h==2){ | |
394 *(uint64_t*)(p + 0+0*stride)= | |
395 *(uint64_t*)(p + 8+0*stride)= | |
396 *(uint64_t*)(p + 0+1*stride)= | |
397 *(uint64_t*)(p + 8+1*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
398 }else if(w==16 && h==4){ | |
399 *(uint64_t*)(p + 0+0*stride)= | |
400 *(uint64_t*)(p + 8+0*stride)= | |
401 *(uint64_t*)(p + 0+1*stride)= | |
402 *(uint64_t*)(p + 8+1*stride)= | |
403 *(uint64_t*)(p + 0+2*stride)= | |
404 *(uint64_t*)(p + 8+2*stride)= | |
405 *(uint64_t*)(p + 0+3*stride)= | |
406 *(uint64_t*)(p + 8+3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | |
407 }else | |
408 assert(0); | |
409 } | |
410 | |
411 static inline void fill_caches(H264Context *h, int mb_type){ | |
412 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
|
413 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
1168 | 414 int topleft_xy, top_xy, topright_xy, left_xy[2]; |
415 int topleft_type, top_type, topright_type, left_type[2]; | |
416 int left_block[4]; | |
417 int i; | |
418 | |
419 //wow what a mess, why didnt they simplify the interlacing&intra stuff, i cant imagine that these complex rules are worth it | |
420 | |
421 if(h->sps.mb_aff){ | |
422 //FIXME | |
1453 | 423 topleft_xy = 0; /* avoid warning */ |
424 top_xy = 0; /* avoid warning */ | |
425 topright_xy = 0; /* avoid warning */ | |
1168 | 426 }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
|
427 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
|
428 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
|
429 topright_xy= mb_xy+1 - s->mb_stride; |
1168 | 430 left_xy[0] = mb_xy-1; |
431 left_xy[1] = mb_xy-1; | |
432 left_block[0]= 0; | |
433 left_block[1]= 1; | |
434 left_block[2]= 2; | |
435 left_block[3]= 3; | |
436 } | |
437 | |
438 topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0; | |
439 top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0; | |
440 topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0; | |
441 left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0; | |
442 left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0; | |
443 | |
444 if(IS_INTRA(mb_type)){ | |
445 h->topleft_samples_available= | |
446 h->top_samples_available= | |
447 h->left_samples_available= 0xFFFF; | |
448 h->topright_samples_available= 0xEEEA; | |
449 | |
450 if(!IS_INTRA(top_type) && (top_type==0 || h->pps.constrained_intra_pred)){ | |
451 h->topleft_samples_available= 0xB3FF; | |
452 h->top_samples_available= 0x33FF; | |
453 h->topright_samples_available= 0x26EA; | |
454 } | |
455 for(i=0; i<2; i++){ | |
456 if(!IS_INTRA(left_type[i]) && (left_type[i]==0 || h->pps.constrained_intra_pred)){ | |
457 h->topleft_samples_available&= 0xDF5F; | |
458 h->left_samples_available&= 0x5F5F; | |
459 } | |
460 } | |
461 | |
462 if(!IS_INTRA(topleft_type) && (topleft_type==0 || h->pps.constrained_intra_pred)) | |
463 h->topleft_samples_available&= 0x7FFF; | |
464 | |
465 if(!IS_INTRA(topright_type) && (topright_type==0 || h->pps.constrained_intra_pred)) | |
466 h->topright_samples_available&= 0xFBFF; | |
467 | |
468 if(IS_INTRA4x4(mb_type)){ | |
469 if(IS_INTRA4x4(top_type)){ | |
470 h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4]; | |
471 h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5]; | |
472 h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6]; | |
473 h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3]; | |
474 }else{ | |
475 int pred; | |
476 if(IS_INTRA16x16(top_type) || (IS_INTER(top_type) && !h->pps.constrained_intra_pred)) | |
477 pred= 2; | |
478 else{ | |
479 pred= -1; | |
480 } | |
481 h->intra4x4_pred_mode_cache[4+8*0]= | |
482 h->intra4x4_pred_mode_cache[5+8*0]= | |
483 h->intra4x4_pred_mode_cache[6+8*0]= | |
484 h->intra4x4_pred_mode_cache[7+8*0]= pred; | |
485 } | |
486 for(i=0; i<2; i++){ | |
487 if(IS_INTRA4x4(left_type[i])){ | |
488 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]]; | |
489 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]]; | |
490 }else{ | |
491 int pred; | |
492 if(IS_INTRA16x16(left_type[i]) || (IS_INTER(left_type[i]) && !h->pps.constrained_intra_pred)) | |
493 pred= 2; | |
494 else{ | |
495 pred= -1; | |
496 } | |
497 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= | |
498 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred; | |
499 } | |
500 } | |
501 } | |
502 } | |
503 | |
504 | |
505 /* | |
506 0 . T T. T T T T | |
507 1 L . .L . . . . | |
508 2 L . .L . . . . | |
509 3 . T TL . . . . | |
510 4 L . .L . . . . | |
511 5 L . .. . . . . | |
512 */ | |
513 //FIXME constraint_intra_pred & partitioning & nnz (lets hope this is just a typo in the spec) | |
514 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
|
515 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
|
516 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
|
517 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
|
518 h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3]; |
1168 | 519 |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
520 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
|
521 h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8]; |
1168 | 522 |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
523 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
|
524 h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11]; |
2314 | 525 |
526 h->top_cbp= h->cbp_table[top_xy]; | |
1168 | 527 }else{ |
528 h->non_zero_count_cache[4+8*0]= | |
529 h->non_zero_count_cache[5+8*0]= | |
530 h->non_zero_count_cache[6+8*0]= | |
531 h->non_zero_count_cache[7+8*0]= | |
532 | |
533 h->non_zero_count_cache[1+8*0]= | |
534 h->non_zero_count_cache[2+8*0]= | |
535 | |
536 h->non_zero_count_cache[1+8*3]= | |
2314 | 537 h->non_zero_count_cache[2+8*3]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
538 | |
539 if(IS_INTRA(mb_type)) h->top_cbp= 0x1C0; | |
540 else h->top_cbp= 0; | |
1168 | 541 } |
542 | |
543 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
|
544 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
|
545 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
|
546 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
|
547 h->non_zero_count_cache[0+8*4]= h->non_zero_count[left_xy[0]][12]; |
2314 | 548 h->left_cbp= h->cbp_table[left_xy[0]]; //FIXME interlacing |
1168 | 549 }else{ |
550 h->non_zero_count_cache[3+8*1]= | |
551 h->non_zero_count_cache[3+8*2]= | |
552 h->non_zero_count_cache[0+8*1]= | |
2314 | 553 h->non_zero_count_cache[0+8*4]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
554 | |
555 if(IS_INTRA(mb_type)) h->left_cbp= 0x1C0;//FIXME interlacing | |
556 else h->left_cbp= 0; | |
1168 | 557 } |
558 | |
559 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
|
560 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
|
561 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
|
562 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
|
563 h->non_zero_count_cache[0+8*5]= h->non_zero_count[left_xy[1]][11]; |
1168 | 564 }else{ |
565 h->non_zero_count_cache[3+8*3]= | |
566 h->non_zero_count_cache[3+8*4]= | |
567 h->non_zero_count_cache[0+8*2]= | |
2314 | 568 h->non_zero_count_cache[0+8*5]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
1168 | 569 } |
570 | |
571 #if 1 | |
2396 | 572 //FIXME direct mb can skip much of this |
573 if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ | |
1168 | 574 int list; |
575 for(list=0; list<2; list++){ | |
2396 | 576 if((!IS_8X8(mb_type)) && !USES_LIST(mb_type, list) && !IS_DIRECT(mb_type)){ |
1168 | 577 /*if(!h->mv_cache_clean[list]){ |
578 memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? | |
579 memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); | |
580 h->mv_cache_clean[list]= 1; | |
581 }*/ | |
2396 | 582 continue; |
1168 | 583 } |
584 h->mv_cache_clean[list]= 0; | |
585 | |
586 if(IS_INTER(topleft_type)){ | |
587 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride; | |
588 const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + h->b8_stride; | |
589 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; | |
590 h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; | |
591 }else{ | |
592 *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= 0; | |
593 h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
594 } | |
595 | |
596 if(IS_INTER(top_type)){ | |
597 const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; | |
598 const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride; | |
599 *(uint32_t*)h->mv_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 0]; | |
600 *(uint32_t*)h->mv_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 1]; | |
601 *(uint32_t*)h->mv_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 2]; | |
602 *(uint32_t*)h->mv_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 3]; | |
603 h->ref_cache[list][scan8[0] + 0 - 1*8]= | |
604 h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0]; | |
605 h->ref_cache[list][scan8[0] + 2 - 1*8]= | |
606 h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1]; | |
607 }else{ | |
608 *(uint32_t*)h->mv_cache [list][scan8[0] + 0 - 1*8]= | |
609 *(uint32_t*)h->mv_cache [list][scan8[0] + 1 - 1*8]= | |
610 *(uint32_t*)h->mv_cache [list][scan8[0] + 2 - 1*8]= | |
611 *(uint32_t*)h->mv_cache [list][scan8[0] + 3 - 1*8]= 0; | |
612 *(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101; | |
613 } | |
614 | |
615 if(IS_INTER(topright_type)){ | |
616 const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; | |
617 const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride; | |
618 *(uint32_t*)h->mv_cache[list][scan8[0] + 4 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; | |
619 h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy]; | |
620 }else{ | |
621 *(uint32_t*)h->mv_cache [list][scan8[0] + 4 - 1*8]= 0; | |
622 h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
623 } | |
624 | |
625 //FIXME unify cleanup or sth | |
626 if(IS_INTER(left_type[0])){ | |
627 const int b_xy= h->mb2b_xy[left_xy[0]] + 3; | |
628 const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1; | |
629 *(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]]; | |
630 *(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]]; | |
631 h->ref_cache[list][scan8[0] - 1 + 0*8]= | |
632 h->ref_cache[list][scan8[0] - 1 + 1*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0]>>1)]; | |
633 }else{ | |
634 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0*8]= | |
635 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 1*8]= 0; | |
636 h->ref_cache[list][scan8[0] - 1 + 0*8]= | |
637 h->ref_cache[list][scan8[0] - 1 + 1*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
638 } | |
639 | |
640 if(IS_INTER(left_type[1])){ | |
641 const int b_xy= h->mb2b_xy[left_xy[1]] + 3; | |
642 const int b8_xy= h->mb2b8_xy[left_xy[1]] + 1; | |
643 *(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]]; | |
644 *(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]]; | |
645 h->ref_cache[list][scan8[0] - 1 + 2*8]= | |
646 h->ref_cache[list][scan8[0] - 1 + 3*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[2]>>1)]; | |
647 }else{ | |
648 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 2*8]= | |
649 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 3*8]= 0; | |
650 h->ref_cache[list][scan8[0] - 1 + 2*8]= | |
651 h->ref_cache[list][scan8[0] - 1 + 3*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; | |
652 } | |
653 | |
654 h->ref_cache[list][scan8[5 ]+1] = | |
655 h->ref_cache[list][scan8[7 ]+1] = | |
656 h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewher else) | |
657 h->ref_cache[list][scan8[4 ]] = | |
658 h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; | |
659 *(uint32_t*)h->mv_cache [list][scan8[5 ]+1]= | |
660 *(uint32_t*)h->mv_cache [list][scan8[7 ]+1]= | |
661 *(uint32_t*)h->mv_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) | |
662 *(uint32_t*)h->mv_cache [list][scan8[4 ]]= | |
663 *(uint32_t*)h->mv_cache [list][scan8[12]]= 0; | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
664 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
665 if( h->pps.cabac ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
666 /* XXX beurk, Load mvd */ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
667 if(IS_INTER(topleft_type)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
668 const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
669 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
670 }else{ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
671 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 - 1*8]= 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
672 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
673 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
674 if(IS_INTER(top_type)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
675 const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
676 *(uint32_t*)h->mvd_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 0]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
677 *(uint32_t*)h->mvd_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 1]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
678 *(uint32_t*)h->mvd_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 2]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
679 *(uint32_t*)h->mvd_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 3]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
680 }else{ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
681 *(uint32_t*)h->mvd_cache [list][scan8[0] + 0 - 1*8]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
682 *(uint32_t*)h->mvd_cache [list][scan8[0] + 1 - 1*8]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
683 *(uint32_t*)h->mvd_cache [list][scan8[0] + 2 - 1*8]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
684 *(uint32_t*)h->mvd_cache [list][scan8[0] + 3 - 1*8]= 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
685 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
686 if(IS_INTER(left_type[0])){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
687 const int b_xy= h->mb2b_xy[left_xy[0]] + 3; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
688 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 0*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[0]]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
689 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[1]]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
690 }else{ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
691 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 0*8]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
692 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 1*8]= 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
693 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
694 if(IS_INTER(left_type[1])){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
695 const int b_xy= h->mb2b_xy[left_xy[1]] + 3; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
696 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 2*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[2]]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
697 *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 3*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[3]]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
698 }else{ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
699 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 2*8]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
700 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 3*8]= 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
701 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
702 *(uint32_t*)h->mvd_cache [list][scan8[5 ]+1]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
703 *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
704 *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
705 *(uint32_t*)h->mvd_cache [list][scan8[4 ]]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
706 *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0; |
2396 | 707 |
708 if(h->slice_type == B_TYPE){ | |
709 fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1); | |
710 | |
711 if(IS_DIRECT(top_type)){ | |
712 *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0x01010101; | |
713 }else if(IS_8X8(top_type)){ | |
714 int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride; | |
715 h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy]; | |
716 h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1]; | |
717 }else{ | |
718 *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0; | |
719 } | |
720 | |
721 //FIXME interlacing | |
722 if(IS_DIRECT(left_type[0])){ | |
723 h->direct_cache[scan8[0] - 1 + 0*8]= | |
724 h->direct_cache[scan8[0] - 1 + 2*8]= 1; | |
725 }else if(IS_8X8(left_type[0])){ | |
726 int b8_xy = h->mb2b8_xy[left_xy[0]] + 1; | |
727 h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[b8_xy]; | |
728 h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[b8_xy + h->b8_stride]; | |
729 }else{ | |
730 h->direct_cache[scan8[0] - 1 + 0*8]= | |
731 h->direct_cache[scan8[0] - 1 + 2*8]= 0; | |
732 } | |
733 } | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
734 } |
1168 | 735 } |
736 } | |
737 #endif | |
738 } | |
739 | |
740 static inline void write_back_intra_pred_mode(H264Context *h){ | |
741 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
|
742 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
1168 | 743 |
744 h->intra4x4_pred_mode[mb_xy][0]= h->intra4x4_pred_mode_cache[7+8*1]; | |
745 h->intra4x4_pred_mode[mb_xy][1]= h->intra4x4_pred_mode_cache[7+8*2]; | |
746 h->intra4x4_pred_mode[mb_xy][2]= h->intra4x4_pred_mode_cache[7+8*3]; | |
747 h->intra4x4_pred_mode[mb_xy][3]= h->intra4x4_pred_mode_cache[7+8*4]; | |
748 h->intra4x4_pred_mode[mb_xy][4]= h->intra4x4_pred_mode_cache[4+8*4]; | |
749 h->intra4x4_pred_mode[mb_xy][5]= h->intra4x4_pred_mode_cache[5+8*4]; | |
750 h->intra4x4_pred_mode[mb_xy][6]= h->intra4x4_pred_mode_cache[6+8*4]; | |
751 } | |
752 | |
753 /** | |
754 * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. | |
755 */ | |
756 static inline int check_intra4x4_pred_mode(H264Context *h){ | |
757 MpegEncContext * const s = &h->s; | |
758 static const int8_t top [12]= {-1, 0,LEFT_DC_PRED,-1,-1,-1,-1,-1, 0}; | |
759 static const int8_t left[12]= { 0,-1, TOP_DC_PRED, 0,-1,-1,-1, 0,-1,DC_128_PRED}; | |
760 int i; | |
761 | |
762 if(!(h->top_samples_available&0x8000)){ | |
763 for(i=0; i<4; i++){ | |
764 int status= top[ h->intra4x4_pred_mode_cache[scan8[0] + i] ]; | |
765 if(status<0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
766 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 | 767 return -1; |
768 } else if(status){ | |
769 h->intra4x4_pred_mode_cache[scan8[0] + i]= status; | |
770 } | |
771 } | |
772 } | |
773 | |
774 if(!(h->left_samples_available&0x8000)){ | |
775 for(i=0; i<4; i++){ | |
776 int status= left[ h->intra4x4_pred_mode_cache[scan8[0] + 8*i] ]; | |
777 if(status<0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
778 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 | 779 return -1; |
780 } else if(status){ | |
781 h->intra4x4_pred_mode_cache[scan8[0] + 8*i]= status; | |
782 } | |
783 } | |
784 } | |
785 | |
786 return 0; | |
787 } //FIXME cleanup like next | |
788 | |
789 /** | |
790 * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. | |
791 */ | |
792 static inline int check_intra_pred_mode(H264Context *h, int mode){ | |
793 MpegEncContext * const s = &h->s; | |
794 static const int8_t top [7]= {LEFT_DC_PRED8x8, 1,-1,-1}; | |
795 static const int8_t left[7]= { TOP_DC_PRED8x8,-1, 2,-1,DC_128_PRED8x8}; | |
796 | |
2392 | 797 if(mode < 0 || mode > 6) { |
798 av_log(h->s.avctx, AV_LOG_ERROR, "out of range intra chroma pred mode at %d %d\n", s->mb_x, s->mb_y); | |
2163 | 799 return -1; |
2392 | 800 } |
2163 | 801 |
1168 | 802 if(!(h->top_samples_available&0x8000)){ |
803 mode= top[ mode ]; | |
804 if(mode<0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
805 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 | 806 return -1; |
807 } | |
808 } | |
809 | |
810 if(!(h->left_samples_available&0x8000)){ | |
811 mode= left[ mode ]; | |
812 if(mode<0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
813 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 | 814 return -1; |
815 } | |
816 } | |
817 | |
818 return mode; | |
819 } | |
820 | |
821 /** | |
822 * gets the predicted intra4x4 prediction mode. | |
823 */ | |
824 static inline int pred_intra_mode(H264Context *h, int n){ | |
825 const int index8= scan8[n]; | |
826 const int left= h->intra4x4_pred_mode_cache[index8 - 1]; | |
827 const int top = h->intra4x4_pred_mode_cache[index8 - 8]; | |
828 const int min= FFMIN(left, top); | |
829 | |
1170 | 830 tprintf("mode:%d %d min:%d\n", left ,top, min); |
1168 | 831 |
832 if(min<0) return DC_PRED; | |
833 else return min; | |
834 } | |
835 | |
836 static inline void write_back_non_zero_count(H264Context *h){ | |
837 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
|
838 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
|
839 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
840 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
|
841 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
|
842 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
|
843 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
|
844 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
|
845 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
|
846 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
|
847 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
848 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
|
849 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
|
850 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
|
851 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
852 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
|
853 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
|
854 h->non_zero_count[mb_xy][12]=h->non_zero_count_cache[2+8*4]; |
1168 | 855 } |
856 | |
857 /** | |
858 * gets the predicted number of non zero coefficients. | |
859 * @param n block index | |
860 */ | |
861 static inline int pred_non_zero_count(H264Context *h, int n){ | |
862 const int index8= scan8[n]; | |
863 const int left= h->non_zero_count_cache[index8 - 1]; | |
864 const int top = h->non_zero_count_cache[index8 - 8]; | |
865 int i= left + top; | |
866 | |
867 if(i<64) i= (i+1)>>1; | |
868 | |
1170 | 869 tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); |
1168 | 870 |
871 return i&31; | |
872 } | |
873 | |
1169 | 874 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ |
875 const int topright_ref= h->ref_cache[list][ i - 8 + part_width ]; | |
876 | |
877 if(topright_ref != PART_NOT_AVAILABLE){ | |
878 *C= h->mv_cache[list][ i - 8 + part_width ]; | |
879 return topright_ref; | |
880 }else{ | |
1170 | 881 tprintf("topright MV not available\n"); |
882 | |
1169 | 883 *C= h->mv_cache[list][ i - 8 - 1 ]; |
884 return h->ref_cache[list][ i - 8 - 1 ]; | |
885 } | |
886 } | |
887 | |
1168 | 888 /** |
889 * gets the predicted MV. | |
890 * @param n the block index | |
891 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) | |
892 * @param mx the x component of the predicted motion vector | |
893 * @param my the y component of the predicted motion vector | |
894 */ | |
895 static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){ | |
896 const int index8= scan8[n]; | |
897 const int top_ref= h->ref_cache[list][ index8 - 8 ]; | |
898 const int left_ref= h->ref_cache[list][ index8 - 1 ]; | |
899 const int16_t * const A= h->mv_cache[list][ index8 - 1 ]; | |
900 const int16_t * const B= h->mv_cache[list][ index8 - 8 ]; | |
1169 | 901 const int16_t * C; |
902 int diagonal_ref, match_count; | |
903 | |
1168 | 904 assert(part_width==1 || part_width==2 || part_width==4); |
1169 | 905 |
1168 | 906 /* mv_cache |
907 B . . A T T T T | |
908 U . . L . . , . | |
909 U . . L . . . . | |
910 U . . L . . , . | |
911 . . . L . . . . | |
912 */ | |
1169 | 913 |
914 diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); | |
915 match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
916 tprintf("pred_motion match_count=%d\n", match_count); |
1169 | 917 if(match_count > 1){ //most common |
918 *mx= mid_pred(A[0], B[0], C[0]); | |
919 *my= mid_pred(A[1], B[1], C[1]); | |
920 }else if(match_count==1){ | |
921 if(left_ref==ref){ | |
922 *mx= A[0]; | |
923 *my= A[1]; | |
924 }else if(top_ref==ref){ | |
925 *mx= B[0]; | |
926 *my= B[1]; | |
927 }else{ | |
928 *mx= C[0]; | |
929 *my= C[1]; | |
930 } | |
931 }else{ | |
932 if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ | |
933 *mx= A[0]; | |
934 *my= A[1]; | |
1168 | 935 }else{ |
936 *mx= mid_pred(A[0], B[0], C[0]); | |
937 *my= mid_pred(A[1], B[1], C[1]); | |
938 } | |
1169 | 939 } |
1168 | 940 |
1187 | 941 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 | 942 } |
943 | |
944 /** | |
945 * gets the directionally predicted 16x8 MV. | |
946 * @param n the block index | |
947 * @param mx the x component of the predicted motion vector | |
948 * @param my the y component of the predicted motion vector | |
949 */ | |
950 static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ | |
951 if(n==0){ | |
952 const int top_ref= h->ref_cache[list][ scan8[0] - 8 ]; | |
953 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; | |
954 | |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
955 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); |
1168 | 956 |
957 if(top_ref == ref){ | |
958 *mx= B[0]; | |
959 *my= B[1]; | |
960 return; | |
961 } | |
962 }else{ | |
963 const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; | |
964 const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; | |
965 | |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
966 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); |
1168 | 967 |
968 if(left_ref == ref){ | |
969 *mx= A[0]; | |
970 *my= A[1]; | |
971 return; | |
972 } | |
973 } | |
974 | |
975 //RARE | |
976 pred_motion(h, n, 4, list, ref, mx, my); | |
977 } | |
978 | |
979 /** | |
980 * gets the directionally predicted 8x16 MV. | |
981 * @param n the block index | |
982 * @param mx the x component of the predicted motion vector | |
983 * @param my the y component of the predicted motion vector | |
984 */ | |
985 static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ | |
986 if(n==0){ | |
987 const int left_ref= h->ref_cache[list][ scan8[0] - 1 ]; | |
988 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; | |
989 | |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
990 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); |
1168 | 991 |
992 if(left_ref == ref){ | |
993 *mx= A[0]; | |
994 *my= A[1]; | |
995 return; | |
996 } | |
997 }else{ | |
1169 | 998 const int16_t * C; |
999 int diagonal_ref; | |
1000 | |
1001 diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); | |
1168 | 1002 |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
1003 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); |
1168 | 1004 |
1169 | 1005 if(diagonal_ref == ref){ |
1168 | 1006 *mx= C[0]; |
1007 *my= C[1]; | |
1008 return; | |
1009 } | |
1010 } | |
1011 | |
1012 //RARE | |
1013 pred_motion(h, n, 2, list, ref, mx, my); | |
1014 } | |
1015 | |
1016 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){ | |
1017 const int top_ref = h->ref_cache[0][ scan8[0] - 8 ]; | |
1018 const int left_ref= h->ref_cache[0][ scan8[0] - 1 ]; | |
1019 | |
2392 | 1020 tprintf("pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y); |
1168 | 1021 |
1022 if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE | |
1023 || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0) | |
1024 || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){ | |
1025 | |
1026 *mx = *my = 0; | |
1027 return; | |
1028 } | |
1029 | |
1030 pred_motion(h, 0, 4, 0, 0, mx, my); | |
1031 | |
1032 return; | |
1033 } | |
1034 | |
2396 | 1035 static inline void direct_dist_scale_factor(H264Context * const h){ |
1036 const int poc = h->s.current_picture_ptr->poc; | |
1037 const int poc1 = h->ref_list[1][0].poc; | |
1038 int i; | |
1039 for(i=0; i<h->ref_count[0]; i++){ | |
1040 int poc0 = h->ref_list[0][i].poc; | |
1041 int td = clip(poc1 - poc0, -128, 127); | |
1042 if(td == 0 /* FIXME || pic0 is a long-term ref */){ | |
1043 h->dist_scale_factor[i] = 256; | |
1044 }else{ | |
1045 int tb = clip(poc - poc0, -128, 127); | |
1046 int tx = (16384 + (ABS(td) >> 1)) / td; | |
1047 h->dist_scale_factor[i] = clip((tb*tx + 32) >> 6, -1024, 1023); | |
1048 } | |
1049 } | |
1050 } | |
1051 | |
1052 static inline void pred_direct_motion(H264Context * const h, int *mb_type){ | |
1053 MpegEncContext * const s = &h->s; | |
1054 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; | |
1055 const int b8_xy = 2*s->mb_x + 2*s->mb_y*h->b8_stride; | |
1056 const int b4_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; | |
1057 const int mb_type_col = h->ref_list[1][0].mb_type[mb_xy]; | |
1058 const int16_t (*l1mv0)[2] = (const int16_t (*)[2]) &h->ref_list[1][0].motion_val[0][b4_xy]; | |
1059 const int8_t *l1ref0 = &h->ref_list[1][0].ref_index[0][b8_xy]; | |
1060 const int is_b8x8 = IS_8X8(*mb_type); | |
1061 int sub_mb_type; | |
1062 int i8, i4; | |
1063 | |
1064 if(IS_8X8(mb_type_col) && !h->sps.direct_8x8_inference_flag){ | |
1065 /* FIXME save sub mb types from previous frames (or derive from MVs) | |
1066 * so we know exactly what block size to use */ | |
1067 sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */ | |
1068 *mb_type = MB_TYPE_8x8; | |
1069 }else if(!is_b8x8 && (IS_16X16(mb_type_col) || IS_INTRA(mb_type_col))){ | |
1070 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
1071 *mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */ | |
1072 }else{ | |
1073 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ | |
1074 *mb_type = MB_TYPE_8x8; | |
1075 } | |
1076 if(!is_b8x8) | |
1077 *mb_type |= MB_TYPE_DIRECT2; | |
1078 | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
1079 tprintf("mb_type = %08x, sub_mb_type = %08x, is_b8x8 = %d, mb_type_col = %08x\n", *mb_type, sub_mb_type, is_b8x8, mb_type_col); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
1080 |
2396 | 1081 if(h->direct_spatial_mv_pred){ |
1082 int ref[2]; | |
1083 int mv[2][2]; | |
1084 int list; | |
1085 | |
1086 /* ref = min(neighbors) */ | |
1087 for(list=0; list<2; list++){ | |
1088 int refa = h->ref_cache[list][scan8[0] - 1]; | |
1089 int refb = h->ref_cache[list][scan8[0] - 8]; | |
1090 int refc = h->ref_cache[list][scan8[0] - 8 + 4]; | |
1091 if(refc == -2) | |
1092 refc = h->ref_cache[list][scan8[0] - 8 - 1]; | |
1093 ref[list] = refa; | |
1094 if(ref[list] < 0 || (refb < ref[list] && refb >= 0)) | |
1095 ref[list] = refb; | |
1096 if(ref[list] < 0 || (refc < ref[list] && refc >= 0)) | |
1097 ref[list] = refc; | |
1098 if(ref[list] < 0) | |
1099 ref[list] = -1; | |
1100 } | |
1101 | |
1102 if(ref[0] < 0 && ref[1] < 0){ | |
1103 ref[0] = ref[1] = 0; | |
1104 mv[0][0] = mv[0][1] = | |
1105 mv[1][0] = mv[1][1] = 0; | |
1106 }else{ | |
1107 for(list=0; list<2; list++){ | |
1108 if(ref[list] >= 0) | |
1109 pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]); | |
1110 else | |
1111 mv[list][0] = mv[list][1] = 0; | |
1112 } | |
1113 } | |
1114 | |
1115 if(ref[1] < 0){ | |
1116 *mb_type &= ~MB_TYPE_P0L1; | |
1117 sub_mb_type &= ~MB_TYPE_P0L1; | |
1118 }else if(ref[0] < 0){ | |
1119 *mb_type &= ~MB_TYPE_P0L0; | |
1120 sub_mb_type &= ~MB_TYPE_P0L0; | |
1121 } | |
1122 | |
1123 if(IS_16X16(*mb_type)){ | |
1124 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref[0], 1); | |
1125 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, ref[1], 1); | |
1126 if(!IS_INTRA(mb_type_col) && l1ref0[0] == 0 && | |
1127 ABS(l1mv0[0][0]) <= 1 && ABS(l1mv0[0][1]) <= 1){ | |
1128 if(ref[0] > 0) | |
1129 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
1130 else | |
1131 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
1132 if(ref[1] > 0) | |
1133 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
1134 else | |
1135 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
1136 }else{ | |
1137 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
1138 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
1139 } | |
1140 }else{ | |
1141 for(i8=0; i8<4; i8++){ | |
1142 const int x8 = i8&1; | |
1143 const int y8 = i8>>1; | |
1144 | |
1145 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) | |
1146 continue; | |
1147 h->sub_mb_type[i8] = sub_mb_type; | |
1148 | |
1149 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4); | |
1150 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4); | |
1151 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref[0], 1); | |
1152 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, ref[1], 1); | |
1153 | |
1154 /* col_zero_flag */ | |
1155 if(!IS_INTRA(mb_type_col) && l1ref0[x8 + y8*h->b8_stride] == 0){ | |
1156 for(i4=0; i4<4; i4++){ | |
1157 const int16_t *mv_col = l1mv0[x8*2 + (i4&1) + (y8*2 + (i4>>1))*h->b_stride]; | |
1158 if(ABS(mv_col[0]) <= 1 && ABS(mv_col[1]) <= 1){ | |
1159 if(ref[0] == 0) | |
1160 *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0; | |
1161 if(ref[1] == 0) | |
1162 *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0; | |
1163 } | |
1164 } | |
1165 } | |
1166 } | |
1167 } | |
1168 }else{ /* direct temporal mv pred */ | |
1169 /* FIXME assumes that L1ref0 used the same ref lists as current frame */ | |
1170 if(IS_16X16(*mb_type)){ | |
1171 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); | |
1172 if(IS_INTRA(mb_type_col)){ | |
1173 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
1174 fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
1175 fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
1176 }else{ | |
1177 const int ref0 = l1ref0[0]; | |
1178 const int dist_scale_factor = h->dist_scale_factor[ref0]; | |
1179 const int16_t *mv_col = l1mv0[0]; | |
1180 int mv_l0[2]; | |
1181 mv_l0[0] = (dist_scale_factor * mv_col[0] + 128) >> 8; | |
1182 mv_l0[1] = (dist_scale_factor * mv_col[1] + 128) >> 8; | |
1183 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref0, 1); | |
1184 fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mv_l0[0],mv_l0[1]), 4); | |
1185 fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]), 4); | |
1186 } | |
1187 }else{ | |
1188 for(i8=0; i8<4; i8++){ | |
1189 const int x8 = i8&1; | |
1190 const int y8 = i8>>1; | |
1191 int ref0, dist_scale_factor; | |
1192 | |
1193 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) | |
1194 continue; | |
1195 h->sub_mb_type[i8] = sub_mb_type; | |
1196 if(IS_INTRA(mb_type_col)){ | |
1197 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1); | |
1198 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); | |
1199 fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); | |
1200 fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); | |
1201 continue; | |
1202 } | |
1203 | |
1204 ref0 = l1ref0[x8 + y8*h->b8_stride]; | |
1205 dist_scale_factor = h->dist_scale_factor[ref0]; | |
1206 | |
1207 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1); | |
1208 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); | |
1209 for(i4=0; i4<4; i4++){ | |
1210 const int16_t *mv_col = l1mv0[x8*2 + (i4&1) + (y8*2 + (i4>>1))*h->b_stride]; | |
1211 int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]]; | |
1212 mv_l0[0] = (dist_scale_factor * mv_col[0] + 128) >> 8; | |
1213 mv_l0[1] = (dist_scale_factor * mv_col[1] + 128) >> 8; | |
1214 *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = | |
1215 pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]); | |
1216 } | |
1217 } | |
1218 } | |
1219 } | |
1220 } | |
1221 | |
1168 | 1222 static inline void write_back_motion(H264Context *h, int mb_type){ |
1223 MpegEncContext * const s = &h->s; | |
1224 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; | |
1225 const int b8_xy= 2*s->mb_x + 2*s->mb_y*h->b8_stride; | |
1226 int list; | |
1227 | |
1228 for(list=0; list<2; list++){ | |
1229 int y; | |
1230 if((!IS_8X8(mb_type)) && !USES_LIST(mb_type, list)){ | |
1231 if(1){ //FIXME skip or never read if mb_type doesnt use it | |
1232 for(y=0; y<4; y++){ | |
1233 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= | |
1234 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= 0; | |
1235 } | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1236 if( h->pps.cabac ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1237 /* FIXME needed ? */ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1238 for(y=0; y<4; y++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1239 *(uint64_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1240 *(uint64_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]= 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1241 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1242 } |
1168 | 1243 for(y=0; y<2; y++){ |
2365
b76a4977447a
Fixed typo which caused incorrect motion prediction in B-frames. patch by (Loren Merritt <lorenm ta u tod washington tod edu>)
michael
parents:
2336
diff
changeset
|
1244 *(uint16_t*)&s->current_picture.ref_index[list][b8_xy + y*h->b8_stride]= (LIST_NOT_USED&0xFF)*0x0101; |
1168 | 1245 } |
1246 } | |
2396 | 1247 continue; |
1168 | 1248 } |
1249 | |
1250 for(y=0; y<4; y++){ | |
1251 *(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]; | |
1252 *(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]; | |
1253 } | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1254 if( h->pps.cabac ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1255 for(y=0; y<4; y++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1256 *(uint64_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mvd_cache[list][scan8[0]+0 + 8*y]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1257 *(uint64_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mvd_cache[list][scan8[0]+2 + 8*y]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1258 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
1259 } |
1168 | 1260 for(y=0; y<2; y++){ |
1261 s->current_picture.ref_index[list][b8_xy + 0 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+0 + 16*y]; | |
1262 s->current_picture.ref_index[list][b8_xy + 1 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+2 + 16*y]; | |
1263 } | |
1264 } | |
2396 | 1265 |
1266 if(h->slice_type == B_TYPE && h->pps.cabac){ | |
1267 if(IS_8X8(mb_type)){ | |
1268 h->direct_table[b8_xy+1+0*h->b8_stride] = IS_DIRECT(h->sub_mb_type[1]) ? 1 : 0; | |
1269 h->direct_table[b8_xy+0+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[2]) ? 1 : 0; | |
1270 h->direct_table[b8_xy+1+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[3]) ? 1 : 0; | |
1271 } | |
1272 } | |
1168 | 1273 } |
1274 | |
1275 /** | |
1276 * Decodes a network abstraction layer unit. | |
1277 * @param consumed is the number of bytes used as input | |
1278 * @param length is the length of the array | |
1279 * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp ttailing? | |
1280 * @returns decoded bytes, might be src+1 if no escapes | |
1281 */ | |
1282 static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){ | |
1283 int i, si, di; | |
1284 uint8_t *dst; | |
1285 | |
1286 // src[0]&0x80; //forbidden bit | |
1287 h->nal_ref_idc= src[0]>>5; | |
1288 h->nal_unit_type= src[0]&0x1F; | |
1289 | |
1290 src++; length--; | |
1291 #if 0 | |
1292 for(i=0; i<length; i++) | |
1293 printf("%2X ", src[i]); | |
1294 #endif | |
1295 for(i=0; i+1<length; i+=2){ | |
1296 if(src[i]) continue; | |
1297 if(i>0 && src[i-1]==0) i--; | |
1298 if(i+2<length && src[i+1]==0 && src[i+2]<=3){ | |
1299 if(src[i+2]!=3){ | |
1300 /* startcode, so we must be past the end */ | |
1301 length=i; | |
1302 } | |
1303 break; | |
1304 } | |
1305 } | |
1306 | |
1307 if(i>=length-1){ //no escaped 0 | |
1308 *dst_length= length; | |
1309 *consumed= length+1; //+1 for the header | |
1310 return src; | |
1311 } | |
1312 | |
1313 h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length); | |
1314 dst= h->rbsp_buffer; | |
1315 | |
1316 //printf("deoding esc\n"); | |
1317 si=di=0; | |
1318 while(si<length){ | |
1319 //remove escapes (very rare 1:2^22) | |
1320 if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){ | |
1321 if(src[si+2]==3){ //escape | |
1322 dst[di++]= 0; | |
1323 dst[di++]= 0; | |
1324 si+=3; | |
1957
54411768fa38
h264 nal decoding fix by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1956
diff
changeset
|
1325 continue; |
1168 | 1326 }else //next start code |
1327 break; | |
1328 } | |
1329 | |
1330 dst[di++]= src[si++]; | |
1331 } | |
1332 | |
1333 *dst_length= di; | |
1334 *consumed= si + 1;//+1 for the header | |
1335 //FIXME store exact number of bits in the getbitcontext (its needed for decoding) | |
1336 return dst; | |
1337 } | |
1338 | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1339 #if 0 |
1168 | 1340 /** |
1341 * @param src the data which should be escaped | |
1342 * @param dst the target buffer, dst+1 == src is allowed as a special case | |
1343 * @param length the length of the src data | |
1344 * @param dst_length the length of the dst array | |
1345 * @returns length of escaped data in bytes or -1 if an error occured | |
1346 */ | |
1347 static int encode_nal(H264Context *h, uint8_t *dst, uint8_t *src, int length, int dst_length){ | |
1348 int i, escape_count, si, di; | |
1349 uint8_t *temp; | |
1350 | |
1351 assert(length>=0); | |
1352 assert(dst_length>0); | |
1353 | |
1354 dst[0]= (h->nal_ref_idc<<5) + h->nal_unit_type; | |
1355 | |
1356 if(length==0) return 1; | |
1357 | |
1358 escape_count= 0; | |
1359 for(i=0; i<length; i+=2){ | |
1360 if(src[i]) continue; | |
1361 if(i>0 && src[i-1]==0) | |
1362 i--; | |
1363 if(i+2<length && src[i+1]==0 && src[i+2]<=3){ | |
1364 escape_count++; | |
1365 i+=2; | |
1366 } | |
1367 } | |
1368 | |
1369 if(escape_count==0){ | |
1370 if(dst+1 != src) | |
1371 memcpy(dst+1, src, length); | |
1372 return length + 1; | |
1373 } | |
1374 | |
1375 if(length + escape_count + 1> dst_length) | |
1376 return -1; | |
1377 | |
1378 //this should be damn rare (hopefully) | |
1379 | |
1380 h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length + escape_count); | |
1381 temp= h->rbsp_buffer; | |
1382 //printf("encoding esc\n"); | |
1383 | |
1384 si= 0; | |
1385 di= 0; | |
1386 while(si < length){ | |
1387 if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){ | |
1388 temp[di++]= 0; si++; | |
1389 temp[di++]= 0; si++; | |
1390 temp[di++]= 3; | |
1391 temp[di++]= src[si++]; | |
1392 } | |
1393 else | |
1394 temp[di++]= src[si++]; | |
1395 } | |
1396 memcpy(dst+1, temp, length+escape_count); | |
1397 | |
1398 assert(di == length+escape_count); | |
1399 | |
1400 return di + 1; | |
1401 } | |
1402 | |
1403 /** | |
1404 * write 1,10,100,1000,... for alignment, yes its exactly inverse to mpeg4 | |
1405 */ | |
1406 static void encode_rbsp_trailing(PutBitContext *pb){ | |
1407 int length; | |
1408 put_bits(pb, 1, 1); | |
1786 | 1409 length= (-put_bits_count(pb))&7; |
1168 | 1410 if(length) put_bits(pb, length, 0); |
1411 } | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1412 #endif |
1168 | 1413 |
1414 /** | |
1415 * identifies the exact end of the bitstream | |
1416 * @return the length of the trailing, or 0 if damaged | |
1417 */ | |
1418 static int decode_rbsp_trailing(uint8_t *src){ | |
1419 int v= *src; | |
1420 int r; | |
1421 | |
1170 | 1422 tprintf("rbsp trailing %X\n", v); |
1168 | 1423 |
1424 for(r=1; r<9; r++){ | |
1425 if(v&1) return r; | |
1426 v>>=1; | |
1427 } | |
1428 return 0; | |
1429 } | |
1430 | |
1431 /** | |
1432 * idct tranforms the 16 dc values and dequantize them. | |
1433 * @param qp quantization parameter | |
1434 */ | |
1435 static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp){ | |
1436 const int qmul= dequant_coeff[qp][0]; | |
1437 #define stride 16 | |
1438 int i; | |
1439 int temp[16]; //FIXME check if this is a good idea | |
1440 static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride}; | |
1441 static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride}; | |
1442 | |
1443 //memset(block, 64, 2*256); | |
1444 //return; | |
1445 for(i=0; i<4; i++){ | |
1446 const int offset= y_offset[i]; | |
1447 const int z0= block[offset+stride*0] + block[offset+stride*4]; | |
1448 const int z1= block[offset+stride*0] - block[offset+stride*4]; | |
1449 const int z2= block[offset+stride*1] - block[offset+stride*5]; | |
1450 const int z3= block[offset+stride*1] + block[offset+stride*5]; | |
1451 | |
1452 temp[4*i+0]= z0+z3; | |
1453 temp[4*i+1]= z1+z2; | |
1454 temp[4*i+2]= z1-z2; | |
1455 temp[4*i+3]= z0-z3; | |
1456 } | |
1457 | |
1458 for(i=0; i<4; i++){ | |
1459 const int offset= x_offset[i]; | |
1460 const int z0= temp[4*0+i] + temp[4*2+i]; | |
1461 const int z1= temp[4*0+i] - temp[4*2+i]; | |
1462 const int z2= temp[4*1+i] - temp[4*3+i]; | |
1463 const int z3= temp[4*1+i] + temp[4*3+i]; | |
1464 | |
1465 block[stride*0 +offset]= ((z0 + z3)*qmul + 2)>>2; //FIXME think about merging this into decode_resdual | |
1466 block[stride*2 +offset]= ((z1 + z2)*qmul + 2)>>2; | |
1467 block[stride*8 +offset]= ((z1 - z2)*qmul + 2)>>2; | |
1468 block[stride*10+offset]= ((z0 - z3)*qmul + 2)>>2; | |
1469 } | |
1470 } | |
1471 | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1472 #if 0 |
1168 | 1473 /** |
1474 * dct tranforms the 16 dc values. | |
1475 * @param qp quantization parameter ??? FIXME | |
1476 */ | |
1477 static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){ | |
1478 // const int qmul= dequant_coeff[qp][0]; | |
1479 int i; | |
1480 int temp[16]; //FIXME check if this is a good idea | |
1481 static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride}; | |
1482 static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride}; | |
1483 | |
1484 for(i=0; i<4; i++){ | |
1485 const int offset= y_offset[i]; | |
1486 const int z0= block[offset+stride*0] + block[offset+stride*4]; | |
1487 const int z1= block[offset+stride*0] - block[offset+stride*4]; | |
1488 const int z2= block[offset+stride*1] - block[offset+stride*5]; | |
1489 const int z3= block[offset+stride*1] + block[offset+stride*5]; | |
1490 | |
1491 temp[4*i+0]= z0+z3; | |
1492 temp[4*i+1]= z1+z2; | |
1493 temp[4*i+2]= z1-z2; | |
1494 temp[4*i+3]= z0-z3; | |
1495 } | |
1496 | |
1497 for(i=0; i<4; i++){ | |
1498 const int offset= x_offset[i]; | |
1499 const int z0= temp[4*0+i] + temp[4*2+i]; | |
1500 const int z1= temp[4*0+i] - temp[4*2+i]; | |
1501 const int z2= temp[4*1+i] - temp[4*3+i]; | |
1502 const int z3= temp[4*1+i] + temp[4*3+i]; | |
1503 | |
1504 block[stride*0 +offset]= (z0 + z3)>>1; | |
1505 block[stride*2 +offset]= (z1 + z2)>>1; | |
1506 block[stride*8 +offset]= (z1 - z2)>>1; | |
1507 block[stride*10+offset]= (z0 - z3)>>1; | |
1508 } | |
1509 } | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1510 #endif |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1511 |
1168 | 1512 #undef xStride |
1513 #undef stride | |
1514 | |
1515 static void chroma_dc_dequant_idct_c(DCTELEM *block, int qp){ | |
1516 const int qmul= dequant_coeff[qp][0]; | |
1517 const int stride= 16*2; | |
1518 const int xStride= 16; | |
1519 int a,b,c,d,e; | |
1520 | |
1521 a= block[stride*0 + xStride*0]; | |
1522 b= block[stride*0 + xStride*1]; | |
1523 c= block[stride*1 + xStride*0]; | |
1524 d= block[stride*1 + xStride*1]; | |
1525 | |
1526 e= a-b; | |
1527 a= a+b; | |
1528 b= c-d; | |
1529 c= c+d; | |
1530 | |
1531 block[stride*0 + xStride*0]= ((a+c)*qmul + 0)>>1; | |
1532 block[stride*0 + xStride*1]= ((e+b)*qmul + 0)>>1; | |
1533 block[stride*1 + xStride*0]= ((a-c)*qmul + 0)>>1; | |
1534 block[stride*1 + xStride*1]= ((e-b)*qmul + 0)>>1; | |
1535 } | |
1536 | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1537 #if 0 |
1168 | 1538 static void chroma_dc_dct_c(DCTELEM *block){ |
1539 const int stride= 16*2; | |
1540 const int xStride= 16; | |
1541 int a,b,c,d,e; | |
1542 | |
1543 a= block[stride*0 + xStride*0]; | |
1544 b= block[stride*0 + xStride*1]; | |
1545 c= block[stride*1 + xStride*0]; | |
1546 d= block[stride*1 + xStride*1]; | |
1547 | |
1548 e= a-b; | |
1549 a= a+b; | |
1550 b= c-d; | |
1551 c= c+d; | |
1552 | |
1553 block[stride*0 + xStride*0]= (a+c); | |
1554 block[stride*0 + xStride*1]= (e+b); | |
1555 block[stride*1 + xStride*0]= (a-c); | |
1556 block[stride*1 + xStride*1]= (e-b); | |
1557 } | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1558 #endif |
1168 | 1559 |
1560 /** | |
1561 * gets the chroma qp. | |
1562 */ | |
1563 static inline int get_chroma_qp(H264Context *h, int qscale){ | |
1564 | |
1565 return chroma_qp[clip(qscale + h->pps.chroma_qp_index_offset, 0, 51)]; | |
1566 } | |
1567 | |
1568 | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1569 #if 0 |
1168 | 1570 static void h264_diff_dct_c(DCTELEM *block, uint8_t *src1, uint8_t *src2, int stride){ |
1571 int i; | |
1572 //FIXME try int temp instead of block | |
1573 | |
1574 for(i=0; i<4; i++){ | |
1575 const int d0= src1[0 + i*stride] - src2[0 + i*stride]; | |
1576 const int d1= src1[1 + i*stride] - src2[1 + i*stride]; | |
1577 const int d2= src1[2 + i*stride] - src2[2 + i*stride]; | |
1578 const int d3= src1[3 + i*stride] - src2[3 + i*stride]; | |
1579 const int z0= d0 + d3; | |
1580 const int z3= d0 - d3; | |
1581 const int z1= d1 + d2; | |
1582 const int z2= d1 - d2; | |
1583 | |
1584 block[0 + 4*i]= z0 + z1; | |
1585 block[1 + 4*i]= 2*z3 + z2; | |
1586 block[2 + 4*i]= z0 - z1; | |
1587 block[3 + 4*i]= z3 - 2*z2; | |
1588 } | |
1589 | |
1590 for(i=0; i<4; i++){ | |
1591 const int z0= block[0*4 + i] + block[3*4 + i]; | |
1592 const int z3= block[0*4 + i] - block[3*4 + i]; | |
1593 const int z1= block[1*4 + i] + block[2*4 + i]; | |
1594 const int z2= block[1*4 + i] - block[2*4 + i]; | |
1595 | |
1596 block[0*4 + i]= z0 + z1; | |
1597 block[1*4 + i]= 2*z3 + z2; | |
1598 block[2*4 + i]= z0 - z1; | |
1599 block[3*4 + i]= z3 - 2*z2; | |
1600 } | |
1601 } | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
1602 #endif |
1168 | 1603 |
1604 //FIXME need to check that this doesnt overflow signed 32 bit for low qp, iam not sure, its very close | |
1605 //FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away) | |
1606 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int seperate_dc){ | |
1607 int i; | |
1608 const int * const quant_table= quant_coeff[qscale]; | |
1609 const int bias= intra ? (1<<QUANT_SHIFT)/3 : (1<<QUANT_SHIFT)/6; | |
1610 const unsigned int threshold1= (1<<QUANT_SHIFT) - bias - 1; | |
1611 const unsigned int threshold2= (threshold1<<1); | |
1612 int last_non_zero; | |
1613 | |
1614 if(seperate_dc){ | |
1615 if(qscale<=18){ | |
1616 //avoid overflows | |
1617 const int dc_bias= intra ? (1<<(QUANT_SHIFT-2))/3 : (1<<(QUANT_SHIFT-2))/6; | |
1618 const unsigned int dc_threshold1= (1<<(QUANT_SHIFT-2)) - dc_bias - 1; | |
1619 const unsigned int dc_threshold2= (dc_threshold1<<1); | |
1620 | |
1621 int level= block[0]*quant_coeff[qscale+18][0]; | |
1622 if(((unsigned)(level+dc_threshold1))>dc_threshold2){ | |
1623 if(level>0){ | |
1624 level= (dc_bias + level)>>(QUANT_SHIFT-2); | |
1625 block[0]= level; | |
1626 }else{ | |
1627 level= (dc_bias - level)>>(QUANT_SHIFT-2); | |
1628 block[0]= -level; | |
1629 } | |
1630 // last_non_zero = i; | |
1631 }else{ | |
1632 block[0]=0; | |
1633 } | |
1634 }else{ | |
1635 const int dc_bias= intra ? (1<<(QUANT_SHIFT+1))/3 : (1<<(QUANT_SHIFT+1))/6; | |
1636 const unsigned int dc_threshold1= (1<<(QUANT_SHIFT+1)) - dc_bias - 1; | |
1637 const unsigned int dc_threshold2= (dc_threshold1<<1); | |
1638 | |
1639 int level= block[0]*quant_table[0]; | |
1640 if(((unsigned)(level+dc_threshold1))>dc_threshold2){ | |
1641 if(level>0){ | |
1642 level= (dc_bias + level)>>(QUANT_SHIFT+1); | |
1643 block[0]= level; | |
1644 }else{ | |
1645 level= (dc_bias - level)>>(QUANT_SHIFT+1); | |
1646 block[0]= -level; | |
1647 } | |
1648 // last_non_zero = i; | |
1649 }else{ | |
1650 block[0]=0; | |
1651 } | |
1652 } | |
1653 last_non_zero= 0; | |
1654 i=1; | |
1655 }else{ | |
1656 last_non_zero= -1; | |
1657 i=0; | |
1658 } | |
1659 | |
1660 for(; i<16; i++){ | |
1661 const int j= scantable[i]; | |
1662 int level= block[j]*quant_table[j]; | |
1663 | |
1664 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
1665 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
1666 if(((unsigned)(level+threshold1))>threshold2){ | |
1667 if(level>0){ | |
1668 level= (bias + level)>>QUANT_SHIFT; | |
1669 block[j]= level; | |
1670 }else{ | |
1671 level= (bias - level)>>QUANT_SHIFT; | |
1672 block[j]= -level; | |
1673 } | |
1674 last_non_zero = i; | |
1675 }else{ | |
1676 block[j]=0; | |
1677 } | |
1678 } | |
1679 | |
1680 return last_non_zero; | |
1681 } | |
1682 | |
1683 static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){ | |
1684 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
1685 ((uint32_t*)(src+0*stride))[0]= a; | |
1686 ((uint32_t*)(src+1*stride))[0]= a; | |
1687 ((uint32_t*)(src+2*stride))[0]= a; | |
1688 ((uint32_t*)(src+3*stride))[0]= a; | |
1689 } | |
1690 | |
1691 static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){ | |
1692 ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101; | |
1693 ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101; | |
1694 ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101; | |
1695 ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101; | |
1696 } | |
1697 | |
1698 static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
1699 const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] | |
1700 + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3; | |
1701 | |
1702 ((uint32_t*)(src+0*stride))[0]= | |
1703 ((uint32_t*)(src+1*stride))[0]= | |
1704 ((uint32_t*)(src+2*stride))[0]= | |
1705 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
1706 } | |
1707 | |
1708 static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
1709 const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2; | |
1710 | |
1711 ((uint32_t*)(src+0*stride))[0]= | |
1712 ((uint32_t*)(src+1*stride))[0]= | |
1713 ((uint32_t*)(src+2*stride))[0]= | |
1714 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
1715 } | |
1716 | |
1717 static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
1718 const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2; | |
1719 | |
1720 ((uint32_t*)(src+0*stride))[0]= | |
1721 ((uint32_t*)(src+1*stride))[0]= | |
1722 ((uint32_t*)(src+2*stride))[0]= | |
1723 ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; | |
1724 } | |
1725 | |
1726 static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){ | |
1727 ((uint32_t*)(src+0*stride))[0]= | |
1728 ((uint32_t*)(src+1*stride))[0]= | |
1729 ((uint32_t*)(src+2*stride))[0]= | |
1730 ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U; | |
1731 } | |
1732 | |
1733 | |
1734 #define LOAD_TOP_RIGHT_EDGE\ | |
1735 const int t4= topright[0];\ | |
1736 const int t5= topright[1];\ | |
1737 const int t6= topright[2];\ | |
1738 const int t7= topright[3];\ | |
1739 | |
1740 #define LOAD_LEFT_EDGE\ | |
1741 const int l0= src[-1+0*stride];\ | |
1742 const int l1= src[-1+1*stride];\ | |
1743 const int l2= src[-1+2*stride];\ | |
1744 const int l3= src[-1+3*stride];\ | |
1745 | |
1746 #define LOAD_TOP_EDGE\ | |
1747 const int t0= src[ 0-1*stride];\ | |
1748 const int t1= src[ 1-1*stride];\ | |
1749 const int t2= src[ 2-1*stride];\ | |
1750 const int t3= src[ 3-1*stride];\ | |
1751 | |
1752 static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){ | |
1753 const int lt= src[-1-1*stride]; | |
1754 LOAD_TOP_EDGE | |
1755 LOAD_LEFT_EDGE | |
1756 | |
1757 src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2; | |
1758 src[0+2*stride]= | |
1759 src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2; | |
1760 src[0+1*stride]= | |
1761 src[1+2*stride]= | |
1762 src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2; | |
1763 src[0+0*stride]= | |
1764 src[1+1*stride]= | |
1765 src[2+2*stride]= | |
1766 src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
1767 src[1+0*stride]= | |
1768 src[2+1*stride]= | |
1769 src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
1770 src[2+0*stride]= | |
1771 src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
1772 src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
1282 | 1773 } |
1168 | 1774 |
1775 static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){ | |
1776 LOAD_TOP_EDGE | |
1777 LOAD_TOP_RIGHT_EDGE | |
1778 // LOAD_LEFT_EDGE | |
1779 | |
1780 src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2; | |
1781 src[1+0*stride]= | |
1782 src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2; | |
1783 src[2+0*stride]= | |
1784 src[1+1*stride]= | |
1785 src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2; | |
1786 src[3+0*stride]= | |
1787 src[2+1*stride]= | |
1788 src[1+2*stride]= | |
1789 src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2; | |
1790 src[3+1*stride]= | |
1791 src[2+2*stride]= | |
1792 src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2; | |
1793 src[3+2*stride]= | |
1794 src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2; | |
1795 src[3+3*stride]=(t6 + 3*t7 + 2)>>2; | |
1282 | 1796 } |
1168 | 1797 |
1798 static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){ | |
1799 const int lt= src[-1-1*stride]; | |
1800 LOAD_TOP_EDGE | |
1801 LOAD_LEFT_EDGE | |
1802 const __attribute__((unused)) int unu= l3; | |
1803 | |
1804 src[0+0*stride]= | |
1805 src[1+2*stride]=(lt + t0 + 1)>>1; | |
1806 src[1+0*stride]= | |
1807 src[2+2*stride]=(t0 + t1 + 1)>>1; | |
1808 src[2+0*stride]= | |
1809 src[3+2*stride]=(t1 + t2 + 1)>>1; | |
1810 src[3+0*stride]=(t2 + t3 + 1)>>1; | |
1811 src[0+1*stride]= | |
1812 src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
1813 src[1+1*stride]= | |
1814 src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
1815 src[2+1*stride]= | |
1816 src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
1817 src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
1818 src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; | |
1819 src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
1282 | 1820 } |
1168 | 1821 |
1822 static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){ | |
1823 LOAD_TOP_EDGE | |
1824 LOAD_TOP_RIGHT_EDGE | |
1825 const __attribute__((unused)) int unu= t7; | |
1826 | |
1827 src[0+0*stride]=(t0 + t1 + 1)>>1; | |
1828 src[1+0*stride]= | |
1829 src[0+2*stride]=(t1 + t2 + 1)>>1; | |
1830 src[2+0*stride]= | |
1831 src[1+2*stride]=(t2 + t3 + 1)>>1; | |
1832 src[3+0*stride]= | |
1833 src[2+2*stride]=(t3 + t4+ 1)>>1; | |
1834 src[3+2*stride]=(t4 + t5+ 1)>>1; | |
1835 src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
1836 src[1+1*stride]= | |
1837 src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; | |
1838 src[2+1*stride]= | |
1839 src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; | |
1840 src[3+1*stride]= | |
1841 src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; | |
1842 src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2; | |
1282 | 1843 } |
1168 | 1844 |
1845 static void pred4x4_horizontal_up_c(uint8_t *src, uint8_t *topright, int stride){ | |
1846 LOAD_LEFT_EDGE | |
1847 | |
1848 src[0+0*stride]=(l0 + l1 + 1)>>1; | |
1849 src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
1850 src[2+0*stride]= | |
1851 src[0+1*stride]=(l1 + l2 + 1)>>1; | |
1852 src[3+0*stride]= | |
1853 src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2; | |
1854 src[2+1*stride]= | |
1855 src[0+2*stride]=(l2 + l3 + 1)>>1; | |
1856 src[3+1*stride]= | |
1857 src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2; | |
1858 src[3+2*stride]= | |
1859 src[1+3*stride]= | |
1860 src[0+3*stride]= | |
1861 src[2+2*stride]= | |
1862 src[2+3*stride]= | |
1863 src[3+3*stride]=l3; | |
1282 | 1864 } |
1168 | 1865 |
1866 static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){ | |
1867 const int lt= src[-1-1*stride]; | |
1868 LOAD_TOP_EDGE | |
1869 LOAD_LEFT_EDGE | |
1870 const __attribute__((unused)) int unu= t3; | |
1871 | |
1872 src[0+0*stride]= | |
1873 src[2+1*stride]=(lt + l0 + 1)>>1; | |
1874 src[1+0*stride]= | |
1875 src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2; | |
1876 src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2; | |
1877 src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2; | |
1878 src[0+1*stride]= | |
1879 src[2+2*stride]=(l0 + l1 + 1)>>1; | |
1880 src[1+1*stride]= | |
1881 src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2; | |
1882 src[0+2*stride]= | |
1883 src[2+3*stride]=(l1 + l2+ 1)>>1; | |
1884 src[1+2*stride]= | |
1885 src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; | |
1886 src[0+3*stride]=(l2 + l3 + 1)>>1; | |
1887 src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2; | |
1282 | 1888 } |
1168 | 1889 |
1890 static void pred16x16_vertical_c(uint8_t *src, int stride){ | |
1891 int i; | |
1892 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
1893 const uint32_t b= ((uint32_t*)(src-stride))[1]; | |
1894 const uint32_t c= ((uint32_t*)(src-stride))[2]; | |
1895 const uint32_t d= ((uint32_t*)(src-stride))[3]; | |
1896 | |
1897 for(i=0; i<16; i++){ | |
1898 ((uint32_t*)(src+i*stride))[0]= a; | |
1899 ((uint32_t*)(src+i*stride))[1]= b; | |
1900 ((uint32_t*)(src+i*stride))[2]= c; | |
1901 ((uint32_t*)(src+i*stride))[3]= d; | |
1902 } | |
1903 } | |
1904 | |
1905 static void pred16x16_horizontal_c(uint8_t *src, int stride){ | |
1906 int i; | |
1907 | |
1908 for(i=0; i<16; i++){ | |
1909 ((uint32_t*)(src+i*stride))[0]= | |
1910 ((uint32_t*)(src+i*stride))[1]= | |
1911 ((uint32_t*)(src+i*stride))[2]= | |
1912 ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101; | |
1913 } | |
1914 } | |
1915 | |
1916 static void pred16x16_dc_c(uint8_t *src, int stride){ | |
1917 int i, dc=0; | |
1918 | |
1919 for(i=0;i<16; i++){ | |
1920 dc+= src[-1+i*stride]; | |
1921 } | |
1922 | |
1923 for(i=0;i<16; i++){ | |
1924 dc+= src[i-stride]; | |
1925 } | |
1926 | |
1927 dc= 0x01010101*((dc + 16)>>5); | |
1928 | |
1929 for(i=0; i<16; i++){ | |
1930 ((uint32_t*)(src+i*stride))[0]= | |
1931 ((uint32_t*)(src+i*stride))[1]= | |
1932 ((uint32_t*)(src+i*stride))[2]= | |
1933 ((uint32_t*)(src+i*stride))[3]= dc; | |
1934 } | |
1935 } | |
1936 | |
1937 static void pred16x16_left_dc_c(uint8_t *src, int stride){ | |
1938 int i, dc=0; | |
1939 | |
1940 for(i=0;i<16; i++){ | |
1941 dc+= src[-1+i*stride]; | |
1942 } | |
1943 | |
1944 dc= 0x01010101*((dc + 8)>>4); | |
1945 | |
1946 for(i=0; i<16; i++){ | |
1947 ((uint32_t*)(src+i*stride))[0]= | |
1948 ((uint32_t*)(src+i*stride))[1]= | |
1949 ((uint32_t*)(src+i*stride))[2]= | |
1950 ((uint32_t*)(src+i*stride))[3]= dc; | |
1951 } | |
1952 } | |
1953 | |
1954 static void pred16x16_top_dc_c(uint8_t *src, int stride){ | |
1955 int i, dc=0; | |
1956 | |
1957 for(i=0;i<16; i++){ | |
1958 dc+= src[i-stride]; | |
1959 } | |
1960 dc= 0x01010101*((dc + 8)>>4); | |
1961 | |
1962 for(i=0; i<16; i++){ | |
1963 ((uint32_t*)(src+i*stride))[0]= | |
1964 ((uint32_t*)(src+i*stride))[1]= | |
1965 ((uint32_t*)(src+i*stride))[2]= | |
1966 ((uint32_t*)(src+i*stride))[3]= dc; | |
1967 } | |
1968 } | |
1969 | |
1970 static void pred16x16_128_dc_c(uint8_t *src, int stride){ | |
1971 int i; | |
1972 | |
1973 for(i=0; i<16; i++){ | |
1974 ((uint32_t*)(src+i*stride))[0]= | |
1975 ((uint32_t*)(src+i*stride))[1]= | |
1976 ((uint32_t*)(src+i*stride))[2]= | |
1977 ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U; | |
1978 } | |
1979 } | |
1980 | |
1234 | 1981 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
|
1982 int i, j, k; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1983 int a; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1984 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
|
1985 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
|
1986 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
|
1987 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
|
1988 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
|
1989 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
|
1990 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
|
1991 src1 += stride; src2 -= stride; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
1992 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
|
1993 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
|
1994 } |
1234 | 1995 if(svq3){ |
1996 H = ( 5*(H/4) ) / 16; | |
1997 V = ( 5*(V/4) ) / 16; | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
1998 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
1999 /* required for 100% accuracy */ |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1322
diff
changeset
|
2000 i = H; H = V; V = i; |
1234 | 2001 }else{ |
2002 H = ( 5*H+32 ) >> 6; | |
2003 V = ( 5*V+32 ) >> 6; | |
2004 } | |
1184
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2005 |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2006 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
|
2007 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
|
2008 int b = a; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2009 a += V; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2010 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
|
2011 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
|
2012 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
|
2013 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
|
2014 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
|
2015 b += 4*H; |
1168 | 2016 } |
1184
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2017 src += stride; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2018 } |
1168 | 2019 } |
2020 | |
1234 | 2021 static void pred16x16_plane_c(uint8_t *src, int stride){ |
2022 pred16x16_plane_compat_c(src, stride, 0); | |
2023 } | |
2024 | |
1168 | 2025 static void pred8x8_vertical_c(uint8_t *src, int stride){ |
2026 int i; | |
2027 const uint32_t a= ((uint32_t*)(src-stride))[0]; | |
2028 const uint32_t b= ((uint32_t*)(src-stride))[1]; | |
2029 | |
2030 for(i=0; i<8; i++){ | |
2031 ((uint32_t*)(src+i*stride))[0]= a; | |
2032 ((uint32_t*)(src+i*stride))[1]= b; | |
2033 } | |
2034 } | |
2035 | |
2036 static void pred8x8_horizontal_c(uint8_t *src, int stride){ | |
2037 int i; | |
2038 | |
2039 for(i=0; i<8; i++){ | |
2040 ((uint32_t*)(src+i*stride))[0]= | |
2041 ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101; | |
2042 } | |
2043 } | |
2044 | |
2045 static void pred8x8_128_dc_c(uint8_t *src, int stride){ | |
2046 int i; | |
2047 | |
2048 for(i=0; i<4; i++){ | |
2049 ((uint32_t*)(src+i*stride))[0]= | |
2050 ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; | |
2051 } | |
2052 for(i=4; i<8; i++){ | |
2053 ((uint32_t*)(src+i*stride))[0]= | |
2054 ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; | |
2055 } | |
2056 } | |
2057 | |
2058 static void pred8x8_left_dc_c(uint8_t *src, int stride){ | |
2059 int i; | |
2060 int dc0, dc2; | |
2061 | |
2062 dc0=dc2=0; | |
2063 for(i=0;i<4; i++){ | |
2064 dc0+= src[-1+i*stride]; | |
2065 dc2+= src[-1+(i+4)*stride]; | |
2066 } | |
2067 dc0= 0x01010101*((dc0 + 2)>>2); | |
2068 dc2= 0x01010101*((dc2 + 2)>>2); | |
2069 | |
2070 for(i=0; i<4; i++){ | |
2071 ((uint32_t*)(src+i*stride))[0]= | |
2072 ((uint32_t*)(src+i*stride))[1]= dc0; | |
2073 } | |
2074 for(i=4; i<8; i++){ | |
2075 ((uint32_t*)(src+i*stride))[0]= | |
2076 ((uint32_t*)(src+i*stride))[1]= dc2; | |
2077 } | |
2078 } | |
2079 | |
2080 static void pred8x8_top_dc_c(uint8_t *src, int stride){ | |
2081 int i; | |
2082 int dc0, dc1; | |
2083 | |
2084 dc0=dc1=0; | |
2085 for(i=0;i<4; i++){ | |
2086 dc0+= src[i-stride]; | |
2087 dc1+= src[4+i-stride]; | |
2088 } | |
2089 dc0= 0x01010101*((dc0 + 2)>>2); | |
2090 dc1= 0x01010101*((dc1 + 2)>>2); | |
2091 | |
2092 for(i=0; i<4; i++){ | |
2093 ((uint32_t*)(src+i*stride))[0]= dc0; | |
2094 ((uint32_t*)(src+i*stride))[1]= dc1; | |
2095 } | |
2096 for(i=4; i<8; i++){ | |
2097 ((uint32_t*)(src+i*stride))[0]= dc0; | |
2098 ((uint32_t*)(src+i*stride))[1]= dc1; | |
2099 } | |
2100 } | |
2101 | |
2102 | |
2103 static void pred8x8_dc_c(uint8_t *src, int stride){ | |
2104 int i; | |
2105 int dc0, dc1, dc2, dc3; | |
2106 | |
2107 dc0=dc1=dc2=0; | |
2108 for(i=0;i<4; i++){ | |
2109 dc0+= src[-1+i*stride] + src[i-stride]; | |
2110 dc1+= src[4+i-stride]; | |
2111 dc2+= src[-1+(i+4)*stride]; | |
2112 } | |
2113 dc3= 0x01010101*((dc1 + dc2 + 4)>>3); | |
2114 dc0= 0x01010101*((dc0 + 4)>>3); | |
2115 dc1= 0x01010101*((dc1 + 2)>>2); | |
2116 dc2= 0x01010101*((dc2 + 2)>>2); | |
2117 | |
2118 for(i=0; i<4; i++){ | |
2119 ((uint32_t*)(src+i*stride))[0]= dc0; | |
2120 ((uint32_t*)(src+i*stride))[1]= dc1; | |
2121 } | |
2122 for(i=4; i<8; i++){ | |
2123 ((uint32_t*)(src+i*stride))[0]= dc2; | |
2124 ((uint32_t*)(src+i*stride))[1]= dc3; | |
2125 } | |
2126 } | |
2127 | |
2128 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
|
2129 int j, k; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2130 int a; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2131 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
|
2132 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
|
2133 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
|
2134 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
|
2135 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
|
2136 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
|
2137 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
|
2138 src1 += stride; src2 -= stride; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2139 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
|
2140 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
|
2141 } |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2142 H = ( 17*H+16 ) >> 5; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2143 V = ( 17*V+16 ) >> 5; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2144 |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2145 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
|
2146 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
|
2147 int b = a; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2148 a += V; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2149 src[0] = cm[ (b ) >> 5 ]; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2150 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
|
2151 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
|
2152 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
|
2153 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
|
2154 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
|
2155 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
|
2156 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
|
2157 src += stride; |
05a2ac8978ad
faster 8x8 & 16x16 plane prediction by skal (massimin at planet-d dot net)
michaelni
parents:
1177
diff
changeset
|
2158 } |
1168 | 2159 } |
2160 | |
2161 static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list, | |
2162 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
2163 int src_x_offset, int src_y_offset, | |
2164 qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op){ | |
2165 MpegEncContext * const s = &h->s; | |
2166 const int mx= h->mv_cache[list][ scan8[n] ][0] + src_x_offset*8; | |
2167 const int my= h->mv_cache[list][ scan8[n] ][1] + src_y_offset*8; | |
2168 const int luma_xy= (mx&3) + ((my&3)<<2); | |
2169 uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*s->linesize; | |
2170 uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*s->uvlinesize; | |
2171 uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*s->uvlinesize; | |
2172 int extra_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; //FIXME increase edge?, IMHO not worth it | |
2173 int extra_height= extra_width; | |
2174 int emu=0; | |
2175 const int full_mx= mx>>2; | |
2176 const int full_my= my>>2; | |
2177 | |
2178 assert(pic->data[0]); | |
2179 | |
2180 if(mx&7) extra_width -= 3; | |
2181 if(my&7) extra_height -= 3; | |
2182 | |
2183 if( full_mx < 0-extra_width | |
2184 || full_my < 0-extra_height | |
2185 || full_mx + 16/*FIXME*/ > s->width + extra_width | |
2186 || full_my + 16/*FIXME*/ > s->height + extra_height){ | |
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
2187 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 | 2188 src_y= s->edge_emu_buffer + 2 + 2*s->linesize; |
2189 emu=1; | |
2190 } | |
2191 | |
2192 qpix_op[luma_xy](dest_y, src_y, s->linesize); //FIXME try variable height perhaps? | |
2193 if(!square){ | |
2194 qpix_op[luma_xy](dest_y + delta, src_y + delta, s->linesize); | |
2195 } | |
2196 | |
2197 if(s->flags&CODEC_FLAG_GRAY) return; | |
2198 | |
2199 if(emu){ | |
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
2200 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 | 2201 src_cb= s->edge_emu_buffer; |
2202 } | |
2203 chroma_op(dest_cb, src_cb, s->uvlinesize, chroma_height, mx&7, my&7); | |
2204 | |
2205 if(emu){ | |
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1282
diff
changeset
|
2206 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 | 2207 src_cr= s->edge_emu_buffer; |
2208 } | |
2209 chroma_op(dest_cr, src_cr, s->uvlinesize, chroma_height, mx&7, my&7); | |
2210 } | |
2211 | |
2415 | 2212 static inline void mc_part_std(H264Context *h, int n, int square, int chroma_height, int delta, |
1168 | 2213 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
2214 int x_offset, int y_offset, | |
2215 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, | |
2216 qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, | |
2217 int list0, int list1){ | |
2218 MpegEncContext * const s = &h->s; | |
2219 qpel_mc_func *qpix_op= qpix_put; | |
2220 h264_chroma_mc_func chroma_op= chroma_put; | |
2221 | |
2222 dest_y += 2*x_offset + 2*y_offset*s-> linesize; | |
2223 dest_cb += x_offset + y_offset*s->uvlinesize; | |
2224 dest_cr += x_offset + y_offset*s->uvlinesize; | |
2225 x_offset += 8*s->mb_x; | |
2226 y_offset += 8*s->mb_y; | |
2227 | |
2228 if(list0){ | |
1169 | 2229 Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ]; |
1168 | 2230 mc_dir_part(h, ref, n, square, chroma_height, delta, 0, |
2231 dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
2232 qpix_op, chroma_op); | |
2233 | |
2234 qpix_op= qpix_avg; | |
2235 chroma_op= chroma_avg; | |
2236 } | |
2237 | |
2238 if(list1){ | |
1169 | 2239 Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ]; |
1168 | 2240 mc_dir_part(h, ref, n, square, chroma_height, delta, 1, |
2241 dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
2242 qpix_op, chroma_op); | |
2243 } | |
2244 } | |
2245 | |
2415 | 2246 static inline void mc_part_weighted(H264Context *h, int n, int square, int chroma_height, int delta, |
2247 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
2248 int x_offset, int y_offset, | |
2249 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, | |
2250 h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op, | |
2251 h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg, | |
2252 int list0, int list1){ | |
2253 MpegEncContext * const s = &h->s; | |
2254 | |
2255 dest_y += 2*x_offset + 2*y_offset*s-> linesize; | |
2256 dest_cb += x_offset + y_offset*s->uvlinesize; | |
2257 dest_cr += x_offset + y_offset*s->uvlinesize; | |
2258 x_offset += 8*s->mb_x; | |
2259 y_offset += 8*s->mb_y; | |
2260 | |
2261 if(list0 && list1){ | |
2262 /* don't optimize for luma-only case, since B-frames usually | |
2263 * use implicit weights => chroma too. */ | |
2264 uint8_t *tmp_cb = s->obmc_scratchpad; | |
2265 uint8_t *tmp_cr = tmp_cb + 8*s->uvlinesize; | |
2266 uint8_t *tmp_y = tmp_cr + 8*s->uvlinesize; | |
2267 int refn0 = h->ref_cache[0][ scan8[n] ]; | |
2268 int refn1 = h->ref_cache[1][ scan8[n] ]; | |
2269 | |
2270 mc_dir_part(h, &h->ref_list[0][refn0], n, square, chroma_height, delta, 0, | |
2271 dest_y, dest_cb, dest_cr, | |
2272 x_offset, y_offset, qpix_put, chroma_put); | |
2273 mc_dir_part(h, &h->ref_list[1][refn1], n, square, chroma_height, delta, 1, | |
2274 tmp_y, tmp_cb, tmp_cr, | |
2275 x_offset, y_offset, qpix_put, chroma_put); | |
2276 | |
2277 if(h->use_weight == 2){ | |
2278 int weight0 = h->implicit_weight[refn0][refn1]; | |
2279 int weight1 = 64 - weight0; | |
2280 luma_weight_avg( dest_y, tmp_y, s-> linesize, 5, weight0, weight1, 0, 0); | |
2281 chroma_weight_avg(dest_cb, tmp_cb, s->uvlinesize, 5, weight0, weight1, 0, 0); | |
2282 chroma_weight_avg(dest_cr, tmp_cr, s->uvlinesize, 5, weight0, weight1, 0, 0); | |
2283 }else{ | |
2284 luma_weight_avg(dest_y, tmp_y, s->linesize, h->luma_log2_weight_denom, | |
2285 h->luma_weight[0][refn0], h->luma_weight[1][refn1], | |
2286 h->luma_offset[0][refn0], h->luma_offset[1][refn1]); | |
2287 chroma_weight_avg(dest_cb, tmp_cb, s->uvlinesize, h->chroma_log2_weight_denom, | |
2288 h->chroma_weight[0][refn0][0], h->chroma_weight[1][refn1][0], | |
2289 h->chroma_offset[0][refn0][0], h->chroma_offset[1][refn1][0]); | |
2290 chroma_weight_avg(dest_cr, tmp_cr, s->uvlinesize, h->chroma_log2_weight_denom, | |
2291 h->chroma_weight[0][refn0][1], h->chroma_weight[1][refn1][1], | |
2292 h->chroma_offset[0][refn0][1], h->chroma_offset[1][refn1][1]); | |
2293 } | |
2294 }else{ | |
2295 int list = list1 ? 1 : 0; | |
2296 int refn = h->ref_cache[list][ scan8[n] ]; | |
2297 Picture *ref= &h->ref_list[list][refn]; | |
2298 mc_dir_part(h, ref, n, square, chroma_height, delta, list, | |
2299 dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
2300 qpix_put, chroma_put); | |
2301 | |
2302 luma_weight_op(dest_y, s->linesize, h->luma_log2_weight_denom, | |
2303 h->luma_weight[list][refn], h->luma_offset[list][refn]); | |
2304 if(h->use_weight_chroma){ | |
2305 chroma_weight_op(dest_cb, s->uvlinesize, h->chroma_log2_weight_denom, | |
2306 h->chroma_weight[list][refn][0], h->chroma_offset[list][refn][0]); | |
2307 chroma_weight_op(dest_cr, s->uvlinesize, h->chroma_log2_weight_denom, | |
2308 h->chroma_weight[list][refn][1], h->chroma_offset[list][refn][1]); | |
2309 } | |
2310 } | |
2311 } | |
2312 | |
2313 static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta, | |
2314 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
2315 int x_offset, int y_offset, | |
2316 qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, | |
2317 qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, | |
2318 h264_weight_func *weight_op, h264_biweight_func *weight_avg, | |
2319 int list0, int list1){ | |
2320 if((h->use_weight==2 && list0 && list1 | |
2321 && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ] != 32)) | |
2322 || h->use_weight==1) | |
2323 mc_part_weighted(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr, | |
2324 x_offset, y_offset, qpix_put, chroma_put, | |
2325 weight_op[0], weight_op[3], weight_avg[0], weight_avg[3], list0, list1); | |
2326 else | |
2327 mc_part_std(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr, | |
2328 x_offset, y_offset, qpix_put, chroma_put, qpix_avg, chroma_avg, list0, list1); | |
2329 } | |
2330 | |
1168 | 2331 static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
2332 qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put), | |
2415 | 2333 qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg), |
2334 h264_weight_func *weight_op, h264_biweight_func *weight_avg){ | |
1168 | 2335 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
|
2336 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
1168 | 2337 const int mb_type= s->current_picture.mb_type[mb_xy]; |
2338 | |
2339 assert(IS_INTER(mb_type)); | |
2340 | |
2341 if(IS_16X16(mb_type)){ | |
2342 mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0, | |
2343 qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0], | |
2415 | 2344 &weight_op[0], &weight_avg[0], |
1168 | 2345 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); |
2346 }else if(IS_16X8(mb_type)){ | |
2347 mc_part(h, 0, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 0, | |
2348 qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0], | |
2415 | 2349 &weight_op[1], &weight_avg[1], |
1168 | 2350 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); |
2351 mc_part(h, 8, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 4, | |
2352 qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0], | |
2415 | 2353 &weight_op[1], &weight_avg[1], |
1168 | 2354 IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1)); |
2355 }else if(IS_8X16(mb_type)){ | |
2356 mc_part(h, 0, 0, 8, 8*s->linesize, dest_y, dest_cb, dest_cr, 0, 0, | |
2357 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
2415 | 2358 &weight_op[2], &weight_avg[2], |
1168 | 2359 IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); |
2360 mc_part(h, 4, 0, 8, 8*s->linesize, dest_y, dest_cb, dest_cr, 4, 0, | |
2361 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
2415 | 2362 &weight_op[2], &weight_avg[2], |
1168 | 2363 IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1)); |
2364 }else{ | |
2365 int i; | |
2366 | |
2367 assert(IS_8X8(mb_type)); | |
2368 | |
2369 for(i=0; i<4; i++){ | |
2370 const int sub_mb_type= h->sub_mb_type[i]; | |
2371 const int n= 4*i; | |
2372 int x_offset= (i&1)<<2; | |
2373 int y_offset= (i&2)<<1; | |
2374 | |
2375 if(IS_SUB_8X8(sub_mb_type)){ | |
2376 mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
2377 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], | |
2415 | 2378 &weight_op[3], &weight_avg[3], |
1168 | 2379 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
2380 }else if(IS_SUB_8X4(sub_mb_type)){ | |
2381 mc_part(h, n , 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
2382 qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1], | |
2415 | 2383 &weight_op[4], &weight_avg[4], |
1168 | 2384 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
2385 mc_part(h, n+2, 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset+2, | |
2386 qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1], | |
2415 | 2387 &weight_op[4], &weight_avg[4], |
1168 | 2388 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
2389 }else if(IS_SUB_4X8(sub_mb_type)){ | |
2390 mc_part(h, n , 0, 4, 4*s->linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset, | |
2391 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
2415 | 2392 &weight_op[5], &weight_avg[5], |
1168 | 2393 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
2394 mc_part(h, n+1, 0, 4, 4*s->linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset, | |
2395 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
2415 | 2396 &weight_op[5], &weight_avg[5], |
1168 | 2397 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
2398 }else{ | |
2399 int j; | |
2400 assert(IS_SUB_4X4(sub_mb_type)); | |
2401 for(j=0; j<4; j++){ | |
2402 int sub_x_offset= x_offset + 2*(j&1); | |
2403 int sub_y_offset= y_offset + (j&2); | |
2404 mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset, | |
2405 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], | |
2415 | 2406 &weight_op[6], &weight_avg[6], |
1168 | 2407 IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); |
2408 } | |
2409 } | |
2410 } | |
2411 } | |
2412 } | |
2413 | |
2414 static void decode_init_vlc(H264Context *h){ | |
2415 static int done = 0; | |
2416 | |
2417 if (!done) { | |
2418 int i; | |
2419 done = 1; | |
2420 | |
2421 init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5, | |
2422 &chroma_dc_coeff_token_len [0], 1, 1, | |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2423 &chroma_dc_coeff_token_bits[0], 1, 1, 1); |
1168 | 2424 |
2425 for(i=0; i<4; i++){ | |
2426 init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17, | |
2427 &coeff_token_len [i][0], 1, 1, | |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2428 &coeff_token_bits[i][0], 1, 1, 1); |
1168 | 2429 } |
2430 | |
2431 for(i=0; i<3; i++){ | |
2432 init_vlc(&chroma_dc_total_zeros_vlc[i], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4, | |
2433 &chroma_dc_total_zeros_len [i][0], 1, 1, | |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2434 &chroma_dc_total_zeros_bits[i][0], 1, 1, 1); |
1168 | 2435 } |
2436 for(i=0; i<15; i++){ | |
2437 init_vlc(&total_zeros_vlc[i], TOTAL_ZEROS_VLC_BITS, 16, | |
2438 &total_zeros_len [i][0], 1, 1, | |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2439 &total_zeros_bits[i][0], 1, 1, 1); |
1168 | 2440 } |
2441 | |
2442 for(i=0; i<6; i++){ | |
2443 init_vlc(&run_vlc[i], RUN_VLC_BITS, 7, | |
2444 &run_len [i][0], 1, 1, | |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2445 &run_bits[i][0], 1, 1, 1); |
1168 | 2446 } |
2447 init_vlc(&run7_vlc, RUN7_VLC_BITS, 16, | |
2448 &run_len [6][0], 1, 1, | |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2365
diff
changeset
|
2449 &run_bits[6][0], 1, 1, 1); |
1168 | 2450 } |
2451 } | |
2452 | |
2453 /** | |
2454 * Sets the intra prediction function pointers. | |
2455 */ | |
2456 static void init_pred_ptrs(H264Context *h){ | |
2457 // MpegEncContext * const s = &h->s; | |
2458 | |
2459 h->pred4x4[VERT_PRED ]= pred4x4_vertical_c; | |
2460 h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c; | |
2461 h->pred4x4[DC_PRED ]= pred4x4_dc_c; | |
2462 h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c; | |
2463 h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c; | |
2464 h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c; | |
2465 h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c; | |
2466 h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c; | |
2467 h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c; | |
2468 h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c; | |
2469 h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c; | |
2470 h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c; | |
2471 | |
2472 h->pred8x8[DC_PRED8x8 ]= pred8x8_dc_c; | |
2473 h->pred8x8[VERT_PRED8x8 ]= pred8x8_vertical_c; | |
2474 h->pred8x8[HOR_PRED8x8 ]= pred8x8_horizontal_c; | |
2475 h->pred8x8[PLANE_PRED8x8 ]= pred8x8_plane_c; | |
2476 h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c; | |
2477 h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c; | |
2478 h->pred8x8[DC_128_PRED8x8 ]= pred8x8_128_dc_c; | |
2479 | |
2480 h->pred16x16[DC_PRED8x8 ]= pred16x16_dc_c; | |
2481 h->pred16x16[VERT_PRED8x8 ]= pred16x16_vertical_c; | |
2482 h->pred16x16[HOR_PRED8x8 ]= pred16x16_horizontal_c; | |
2483 h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_c; | |
2484 h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c; | |
2485 h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c; | |
2486 h->pred16x16[DC_128_PRED8x8 ]= pred16x16_128_dc_c; | |
2487 } | |
2488 | |
2489 static void free_tables(H264Context *h){ | |
2490 av_freep(&h->intra4x4_pred_mode); | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2491 av_freep(&h->chroma_pred_mode_table); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2492 av_freep(&h->cbp_table); |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
2493 av_freep(&h->mvd_table[0]); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
2494 av_freep(&h->mvd_table[1]); |
2396 | 2495 av_freep(&h->direct_table); |
1168 | 2496 av_freep(&h->non_zero_count); |
2497 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
|
2498 av_freep(&h->top_border); |
1168 | 2499 h->slice_table= NULL; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2500 |
1168 | 2501 av_freep(&h->mb2b_xy); |
2502 av_freep(&h->mb2b8_xy); | |
2415 | 2503 |
2504 av_freep(&h->s.obmc_scratchpad); | |
1168 | 2505 } |
2506 | |
2507 /** | |
2508 * allocates tables. | |
2509 * needs widzh/height | |
2510 */ | |
2511 static int alloc_tables(H264Context *h){ | |
2512 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
|
2513 const int big_mb_num= s->mb_stride * (s->mb_height+1); |
1168 | 2514 int x,y; |
2515 | |
2516 CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t)) | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2517 |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2518 CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t)) |
1168 | 2519 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
|
2520 CHECKED_ALLOCZ(h->top_border , s->mb_width * (16+8+8) * sizeof(uint8_t)) |
2336 | 2521 CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t)) |
1168 | 2522 |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2523 if( h->pps.cabac ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2524 CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
2525 CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
2526 CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); |
2396 | 2527 CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t)); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2528 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
2529 |
1168 | 2530 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
|
2531 h->slice_table= h->slice_table_base + s->mb_stride + 1; |
1168 | 2532 |
2533 CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint16_t)); | |
2534 CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint16_t)); | |
2535 for(y=0; y<s->mb_height; y++){ | |
2536 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
|
2537 const int mb_xy= x + y*s->mb_stride; |
1168 | 2538 const int b_xy = 4*x + 4*y*h->b_stride; |
2539 const int b8_xy= 2*x + 2*y*h->b8_stride; | |
2540 | |
2541 h->mb2b_xy [mb_xy]= b_xy; | |
2542 h->mb2b8_xy[mb_xy]= b8_xy; | |
2543 } | |
2544 } | |
2415 | 2545 |
2417 | 2546 s->obmc_scratchpad = NULL; |
2547 | |
1168 | 2548 return 0; |
2549 fail: | |
2550 free_tables(h); | |
2551 return -1; | |
2552 } | |
2553 | |
2554 static void common_init(H264Context *h){ | |
2555 MpegEncContext * const s = &h->s; | |
2556 | |
2557 s->width = s->avctx->width; | |
2558 s->height = s->avctx->height; | |
2559 s->codec_id= s->avctx->codec->id; | |
2560 | |
2561 init_pred_ptrs(h); | |
2562 | |
1698 | 2563 s->unrestricted_mv=1; |
1168 | 2564 s->decode=1; //FIXME |
2565 } | |
2566 | |
2567 static int decode_init(AVCodecContext *avctx){ | |
2568 H264Context *h= avctx->priv_data; | |
2569 MpegEncContext * const s = &h->s; | |
2570 | |
1892 | 2571 MPV_decode_defaults(s); |
2572 | |
1168 | 2573 s->avctx = avctx; |
2574 common_init(h); | |
2575 | |
2576 s->out_format = FMT_H264; | |
2577 s->workaround_bugs= avctx->workaround_bugs; | |
2578 | |
2579 // set defaults | |
2580 // s->decode_mb= ff_h263_decode_mb; | |
2581 s->low_delay= 1; | |
2582 avctx->pix_fmt= PIX_FMT_YUV420P; | |
2583 | |
2584 decode_init_vlc(h); | |
2585 | |
2384 | 2586 if(avctx->codec_tag != 0x31637661 && avctx->codec_tag != 0x31435641) // avc1 |
2227 | 2587 h->is_avc = 0; |
2588 else { | |
2589 if((avctx->extradata_size == 0) || (avctx->extradata == NULL)) { | |
2590 av_log(avctx, AV_LOG_ERROR, "AVC codec requires avcC data\n"); | |
2591 return -1; | |
2592 } | |
2593 h->is_avc = 1; | |
2594 h->got_avcC = 0; | |
2595 } | |
2596 | |
1168 | 2597 return 0; |
2598 } | |
2599 | |
2600 static void frame_start(H264Context *h){ | |
2601 MpegEncContext * const s = &h->s; | |
2602 int i; | |
2603 | |
2604 MPV_frame_start(s, s->avctx); | |
2605 ff_er_frame_start(s); | |
2606 | |
2607 assert(s->linesize && s->uvlinesize); | |
2608 | |
2609 for(i=0; i<16; i++){ | |
2610 h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3); | |
2611 h->chroma_subblock_offset[i]= 2*((scan8[i] - scan8[0])&7) + 2*s->uvlinesize*((scan8[i] - scan8[0])>>3); | |
2612 } | |
2613 for(i=0; i<4; i++){ | |
2614 h->block_offset[16+i]= | |
2615 h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3); | |
2616 } | |
2617 | |
2416
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2618 /* can't be in alloc_tables because linesize isn't known there. |
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2619 * FIXME: redo bipred weight to not require extra buffer? */ |
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2620 if(!s->obmc_scratchpad) |
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2621 s->obmc_scratchpad = av_malloc(16*s->linesize + 2*8*s->uvlinesize); |
06b7d678b582
10l: scratchpad could be allocated before its size was known.
lorenm
parents:
2415
diff
changeset
|
2622 |
1168 | 2623 // s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1; |
2624 } | |
2625 | |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2626 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
|
2627 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
|
2628 int i; |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2629 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2630 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
|
2631 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
|
2632 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
|
2633 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2634 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
|
2635 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
|
2636 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
|
2637 } |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2638 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2639 *(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
|
2640 *(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
|
2641 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2642 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
|
2643 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
|
2644 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
|
2645 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
|
2646 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
|
2647 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
|
2648 } |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2649 *(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
|
2650 *(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
|
2651 } |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2652 } |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2653 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2654 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
|
2655 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
|
2656 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
|
2657 uint64_t temp64; |
2200
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2658 int deblock_left = (s->mb_x > 0); |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2659 int deblock_top = (s->mb_y > 0); |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2660 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2661 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
|
2662 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
|
2663 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
|
2664 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2665 #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
|
2666 t= a;\ |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2667 if(xchg)\ |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2668 a= b;\ |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2669 b= t; |
2200
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2670 |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2671 if(deblock_left){ |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2672 for(i = !deblock_top; i<17; i++){ |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2673 XCHG(h->left_border[i ], src_y [i* linesize], temp8, xchg); |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2674 } |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2675 } |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2676 |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2677 if(deblock_top){ |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2678 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg); |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2679 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1); |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2680 } |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2681 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2682 if(!(s->flags&CODEC_FLAG_GRAY)){ |
2200
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2683 if(deblock_left){ |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2684 for(i = !deblock_top; i<9; i++){ |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2685 XCHG(h->left_border[i+17 ], src_cb[i*uvlinesize], temp8, xchg); |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2686 XCHG(h->left_border[i+17+9], src_cr[i*uvlinesize], temp8, xchg); |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2687 } |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2688 } |
2200
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2689 if(deblock_top){ |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2690 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1); |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2691 XCHG(*(uint64_t*)(h->top_border[s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1); |
733c60a6e30c
h264 deblocking crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2175
diff
changeset
|
2692 } |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2693 } |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2694 } |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2695 |
1168 | 2696 static void hl_decode_mb(H264Context *h){ |
2697 MpegEncContext * const s = &h->s; | |
2698 const int mb_x= s->mb_x; | |
2699 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
|
2700 const int mb_xy= mb_x + mb_y*s->mb_stride; |
1168 | 2701 const int mb_type= s->current_picture.mb_type[mb_xy]; |
2702 uint8_t *dest_y, *dest_cb, *dest_cr; | |
2703 int linesize, uvlinesize /*dct_offset*/; | |
2704 int i; | |
2705 | |
2706 if(!s->decode) | |
2707 return; | |
2708 | |
2709 if(s->mb_skiped){ | |
2710 } | |
2711 | |
2712 dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16; | |
2713 dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
2714 dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
2715 | |
2716 if (h->mb_field_decoding_flag) { | |
2717 linesize = s->linesize * 2; | |
2718 uvlinesize = s->uvlinesize * 2; | |
2719 if(mb_y&1){ //FIXME move out of this func? | |
2720 dest_y -= s->linesize*15; | |
2721 dest_cb-= s->linesize*7; | |
2722 dest_cr-= s->linesize*7; | |
2723 } | |
2724 } else { | |
2725 linesize = s->linesize; | |
2726 uvlinesize = s->uvlinesize; | |
2727 // dct_offset = s->linesize * 16; | |
2728 } | |
2729 | |
2730 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
|
2731 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
|
2732 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
|
2733 |
1168 | 2734 if(!(s->flags&CODEC_FLAG_GRAY)){ |
2735 h->pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize); | |
2736 h->pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize); | |
2737 } | |
2738 | |
2739 if(IS_INTRA4x4(mb_type)){ | |
2740 if(!s->encoding){ | |
2741 for(i=0; i<16; i++){ | |
2742 uint8_t * const ptr= dest_y + h->block_offset[i]; | |
2383 | 2743 uint8_t *topright; |
1168 | 2744 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; |
2745 int tr; | |
2746 | |
2383 | 2747 if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){ |
2748 const int topright_avail= (h->topright_samples_available<<i)&0x8000; | |
2749 assert(mb_y || linesize <= h->block_offset[i]); | |
2750 if(!topright_avail){ | |
2751 tr= ptr[3 - linesize]*0x01010101; | |
2752 topright= (uint8_t*) &tr; | |
2753 }else if(i==5 && h->deblocking_filter){ | |
2754 tr= *(uint32_t*)h->top_border[mb_x+1]; | |
2755 topright= (uint8_t*) &tr; | |
2756 }else | |
2757 topright= ptr + 4 - linesize; | |
2758 }else | |
2759 topright= NULL; | |
1168 | 2760 |
2761 h->pred4x4[ dir ](ptr, topright, linesize); | |
1234 | 2762 if(h->non_zero_count_cache[ scan8[i] ]){ |
2763 if(s->codec_id == CODEC_ID_H264) | |
2272
cd43603c46f9
move h264 idct to its own file and call via function pointer in DspContext
michael
parents:
2255
diff
changeset
|
2764 s->dsp.h264_idct_add(ptr, h->mb + i*16, linesize); |
1234 | 2765 else |
2766 svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0); | |
2767 } | |
1168 | 2768 } |
2769 } | |
2770 }else{ | |
2771 h->pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize); | |
1234 | 2772 if(s->codec_id == CODEC_ID_H264) |
2773 h264_luma_dc_dequant_idct_c(h->mb, s->qscale); | |
2774 else | |
2775 svq3_luma_dc_dequant_idct_c(h->mb, s->qscale); | |
1168 | 2776 } |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2777 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
|
2778 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0); |
1234 | 2779 }else if(s->codec_id == CODEC_ID_H264){ |
1168 | 2780 hl_motion(h, dest_y, dest_cb, dest_cr, |
2781 s->dsp.put_h264_qpel_pixels_tab, s->dsp.put_h264_chroma_pixels_tab, | |
2415 | 2782 s->dsp.avg_h264_qpel_pixels_tab, s->dsp.avg_h264_chroma_pixels_tab, |
2783 s->dsp.weight_h264_pixels_tab, s->dsp.biweight_h264_pixels_tab); | |
1168 | 2784 } |
2785 | |
2786 | |
2787 if(!IS_INTRA4x4(mb_type)){ | |
1250 | 2788 if(s->codec_id == CODEC_ID_H264){ |
2789 for(i=0; i<16; i++){ | |
2790 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below | |
2791 uint8_t * const ptr= dest_y + h->block_offset[i]; | |
2272
cd43603c46f9
move h264 idct to its own file and call via function pointer in DspContext
michael
parents:
2255
diff
changeset
|
2792 s->dsp.h264_idct_add(ptr, h->mb + i*16, linesize); |
1250 | 2793 } |
2794 } | |
2795 }else{ | |
2796 for(i=0; i<16; i++){ | |
2797 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below | |
2798 uint8_t * const ptr= dest_y + h->block_offset[i]; | |
1234 | 2799 svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0); |
1250 | 2800 } |
1168 | 2801 } |
2802 } | |
2803 } | |
2804 | |
2805 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
2806 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp); | |
2807 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp); | |
1250 | 2808 if(s->codec_id == CODEC_ID_H264){ |
2809 for(i=16; i<16+4; i++){ | |
2810 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ | |
2811 uint8_t * const ptr= dest_cb + h->block_offset[i]; | |
2272
cd43603c46f9
move h264 idct to its own file and call via function pointer in DspContext
michael
parents:
2255
diff
changeset
|
2812 s->dsp.h264_idct_add(ptr, h->mb + i*16, uvlinesize); |
1250 | 2813 } |
2814 } | |
2815 for(i=20; i<20+4; i++){ | |
2816 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ | |
2817 uint8_t * const ptr= dest_cr + h->block_offset[i]; | |
2272
cd43603c46f9
move h264 idct to its own file and call via function pointer in DspContext
michael
parents:
2255
diff
changeset
|
2818 s->dsp.h264_idct_add(ptr, h->mb + i*16, uvlinesize); |
1250 | 2819 } |
1168 | 2820 } |
1250 | 2821 }else{ |
2822 for(i=16; i<16+4; i++){ | |
2823 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ | |
2824 uint8_t * const ptr= dest_cb + h->block_offset[i]; | |
1234 | 2825 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); |
1250 | 2826 } |
2827 } | |
2828 for(i=20; i<20+4; i++){ | |
2829 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ | |
2830 uint8_t * const ptr= dest_cr + h->block_offset[i]; | |
2831 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); | |
2832 } | |
1168 | 2833 } |
2834 } | |
2835 } | |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
2836 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
|
2837 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
|
2838 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
|
2839 } |
1168 | 2840 } |
2841 | |
2842 /** | |
2843 * fills the default_ref_list. | |
2844 */ | |
2845 static int fill_default_ref_list(H264Context *h){ | |
2846 MpegEncContext * const s = &h->s; | |
2847 int i; | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2848 int smallest_poc_greater_than_current = -1; |
1168 | 2849 Picture sorted_short_ref[16]; |
2850 | |
2851 if(h->slice_type==B_TYPE){ | |
2852 int out_i; | |
2853 int limit= -1; | |
2854 | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2855 /* sort frame according to poc in B slice */ |
1168 | 2856 for(out_i=0; out_i<h->short_ref_count; out_i++){ |
2857 int best_i=-1; | |
2255
507690ff49a2
assertion when playing AVC/H.264 streams fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2254
diff
changeset
|
2858 int best_poc=INT_MAX; |
1168 | 2859 |
2860 for(i=0; i<h->short_ref_count; i++){ | |
2861 const int poc= h->short_ref[i]->poc; | |
2862 if(poc > limit && poc < best_poc){ | |
2863 best_poc= poc; | |
2864 best_i= i; | |
2865 } | |
2866 } | |
2867 | |
2868 assert(best_i != -1); | |
2869 | |
2870 limit= best_poc; | |
2871 sorted_short_ref[out_i]= *h->short_ref[best_i]; | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2872 tprintf("sorted poc: %d->%d poc:%d fn:%d\n", best_i, out_i, sorted_short_ref[out_i].poc, sorted_short_ref[out_i].frame_num); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2873 if (-1 == smallest_poc_greater_than_current) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2874 if (h->short_ref[best_i]->poc >= s->current_picture_ptr->poc) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2875 smallest_poc_greater_than_current = out_i; |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2876 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2877 } |
1168 | 2878 } |
2879 } | |
2880 | |
2881 if(s->picture_structure == PICT_FRAME){ | |
2882 if(h->slice_type==B_TYPE){ | |
2883 int list; | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2884 tprintf("current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2885 |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2886 // find the largest poc |
1168 | 2887 for(list=0; list<2; list++){ |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2888 int index = 0; |
2447 | 2889 int j= -99; |
2890 int step= list ? -1 : 1; | |
2891 | |
2892 for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++, j+=step) { | |
2893 while(j<0 || j>= h->short_ref_count){ | |
2894 step = -step; | |
2895 j= smallest_poc_greater_than_current + (step>>1); | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2896 } |
2447 | 2897 if(sorted_short_ref[j].reference != 3) continue; |
2898 h->default_ref_list[list][index ]= sorted_short_ref[j]; | |
2899 h->default_ref_list[list][index++].pic_id= sorted_short_ref[j].frame_num; | |
1168 | 2900 } |
2901 | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2902 for(i = 0; i < 16 && index < h->ref_count[ list ]; i++){ |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2903 if(h->long_ref[i] == NULL) continue; |
1168 | 2904 if(h->long_ref[i]->reference != 3) continue; |
2905 | |
2906 h->default_ref_list[ list ][index ]= *h->long_ref[i]; | |
2907 h->default_ref_list[ list ][index++].pic_id= i;; | |
2908 } | |
2909 | |
2447 | 2910 if(list && (smallest_poc_greater_than_current<=0 || smallest_poc_greater_than_current>=h->short_ref_count) && (1 < index)){ |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2911 // swap the two first elements of L1 when |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2912 // L0 and L1 are identical |
1168 | 2913 Picture temp= h->default_ref_list[1][0]; |
2914 h->default_ref_list[1][0] = h->default_ref_list[1][1]; | |
2915 h->default_ref_list[1][0] = temp; | |
2916 } | |
2917 | |
2918 if(index < h->ref_count[ list ]) | |
2919 memset(&h->default_ref_list[list][index], 0, sizeof(Picture)*(h->ref_count[ list ] - index)); | |
2920 } | |
2921 }else{ | |
2922 int index=0; | |
2923 for(i=0; i<h->short_ref_count && index < h->ref_count[0]; i++){ | |
2924 if(h->short_ref[i]->reference != 3) continue; //FIXME refernce field shit | |
2925 h->default_ref_list[0][index ]= *h->short_ref[i]; | |
2926 h->default_ref_list[0][index++].pic_id= h->short_ref[i]->frame_num; | |
2927 } | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2928 for(i = 0; i < 16 && index < h->ref_count[0]; i++){ |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2929 if(h->long_ref[i] == NULL) continue; |
1168 | 2930 if(h->long_ref[i]->reference != 3) continue; |
2931 h->default_ref_list[0][index ]= *h->long_ref[i]; | |
2932 h->default_ref_list[0][index++].pic_id= i;; | |
2933 } | |
2934 if(index < h->ref_count[0]) | |
2935 memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index)); | |
2936 } | |
2937 }else{ //FIELD | |
2938 if(h->slice_type==B_TYPE){ | |
2939 }else{ | |
2940 //FIXME second field balh | |
2941 } | |
2942 } | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2943 #ifdef TRACE |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2944 for (i=0; i<h->ref_count[0]; i++) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2945 tprintf("List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2946 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2947 if(h->slice_type==B_TYPE){ |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2948 for (i=0; i<h->ref_count[1]; i++) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2949 tprintf("List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[0][i].data[0]); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2950 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2951 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2952 #endif |
1168 | 2953 return 0; |
2954 } | |
2955 | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2956 static void print_short_term(H264Context *h); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2957 static void print_long_term(H264Context *h); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2958 |
1168 | 2959 static int decode_ref_pic_list_reordering(H264Context *h){ |
2960 MpegEncContext * const s = &h->s; | |
2961 int list; | |
2962 | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2963 print_short_term(h); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
2964 print_long_term(h); |
1168 | 2965 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move beofre func |
2966 | |
2967 for(list=0; list<2; list++){ | |
2968 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); | |
2969 | |
2970 if(get_bits1(&s->gb)){ | |
2971 int pred= h->curr_pic_num; | |
2972 int index; | |
2973 | |
2974 for(index=0; ; index++){ | |
2975 int reordering_of_pic_nums_idc= get_ue_golomb(&s->gb); | |
2976 int pic_id; | |
2977 int i; | |
2978 | |
2284
6d26e105f68f
h.264 ref list reordering bugfix patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2272
diff
changeset
|
2979 if(reordering_of_pic_nums_idc==3) |
6d26e105f68f
h.264 ref list reordering bugfix patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2272
diff
changeset
|
2980 break; |
1168 | 2981 |
2982 if(index >= h->ref_count[list]){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
2983 av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); |
1168 | 2984 return -1; |
2985 } | |
2986 | |
2987 if(reordering_of_pic_nums_idc<3){ | |
2988 if(reordering_of_pic_nums_idc<2){ | |
2989 const int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; | |
2990 | |
2991 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
|
2992 av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); |
1168 | 2993 return -1; |
2994 } | |
2995 | |
2996 if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num; | |
2997 else pred+= abs_diff_pic_num; | |
2998 pred &= h->max_pic_num - 1; | |
2999 | |
3000 for(i= h->ref_count[list]-1; i>=index; i--){ | |
3001 if(h->ref_list[list][i].pic_id == pred && h->ref_list[list][i].long_ref==0) | |
3002 break; | |
3003 } | |
3004 }else{ | |
3005 pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx | |
3006 | |
3007 for(i= h->ref_count[list]-1; i>=index; i--){ | |
3008 if(h->ref_list[list][i].pic_id == pic_id && h->ref_list[list][i].long_ref==1) | |
3009 break; | |
3010 } | |
3011 } | |
3012 | |
3013 if(i < index){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3014 av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); |
1168 | 3015 memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME |
3016 }else if(i > index){ | |
3017 Picture tmp= h->ref_list[list][i]; | |
3018 for(; i>index; i--){ | |
3019 h->ref_list[list][i]= h->ref_list[list][i-1]; | |
3020 } | |
3021 h->ref_list[list][index]= tmp; | |
3022 } | |
2284
6d26e105f68f
h.264 ref list reordering bugfix patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2272
diff
changeset
|
3023 }else{ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3024 av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); |
1168 | 3025 return -1; |
3026 } | |
3027 } | |
3028 } | |
3029 | |
3030 if(h->slice_type!=B_TYPE) break; | |
3031 } | |
2396 | 3032 |
3033 if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred) | |
3034 direct_dist_scale_factor(h); | |
1168 | 3035 return 0; |
3036 } | |
3037 | |
3038 static int pred_weight_table(H264Context *h){ | |
3039 MpegEncContext * const s = &h->s; | |
3040 int list, i; | |
2415 | 3041 int luma_def, chroma_def; |
1168 | 3042 |
2415 | 3043 h->use_weight= 0; |
3044 h->use_weight_chroma= 0; | |
1168 | 3045 h->luma_log2_weight_denom= get_ue_golomb(&s->gb); |
3046 h->chroma_log2_weight_denom= get_ue_golomb(&s->gb); | |
2415 | 3047 luma_def = 1<<h->luma_log2_weight_denom; |
3048 chroma_def = 1<<h->chroma_log2_weight_denom; | |
1168 | 3049 |
3050 for(list=0; list<2; list++){ | |
3051 for(i=0; i<h->ref_count[list]; i++){ | |
3052 int luma_weight_flag, chroma_weight_flag; | |
3053 | |
3054 luma_weight_flag= get_bits1(&s->gb); | |
3055 if(luma_weight_flag){ | |
3056 h->luma_weight[list][i]= get_se_golomb(&s->gb); | |
3057 h->luma_offset[list][i]= get_se_golomb(&s->gb); | |
2415 | 3058 if( h->luma_weight[list][i] != luma_def |
3059 || h->luma_offset[list][i] != 0) | |
3060 h->use_weight= 1; | |
3061 }else{ | |
3062 h->luma_weight[list][i]= luma_def; | |
3063 h->luma_offset[list][i]= 0; | |
1168 | 3064 } |
3065 | |
3066 chroma_weight_flag= get_bits1(&s->gb); | |
3067 if(chroma_weight_flag){ | |
3068 int j; | |
3069 for(j=0; j<2; j++){ | |
3070 h->chroma_weight[list][i][j]= get_se_golomb(&s->gb); | |
3071 h->chroma_offset[list][i][j]= get_se_golomb(&s->gb); | |
2415 | 3072 if( h->chroma_weight[list][i][j] != chroma_def |
3073 || h->chroma_offset[list][i][j] != 0) | |
3074 h->use_weight_chroma= 1; | |
3075 } | |
3076 }else{ | |
3077 int j; | |
3078 for(j=0; j<2; j++){ | |
3079 h->chroma_weight[list][i][j]= chroma_def; | |
3080 h->chroma_offset[list][i][j]= 0; | |
1168 | 3081 } |
3082 } | |
3083 } | |
3084 if(h->slice_type != B_TYPE) break; | |
3085 } | |
2415 | 3086 h->use_weight= h->use_weight || h->use_weight_chroma; |
1168 | 3087 return 0; |
3088 } | |
3089 | |
2415 | 3090 static void implicit_weight_table(H264Context *h){ |
3091 MpegEncContext * const s = &h->s; | |
3092 int ref0, ref1; | |
3093 int cur_poc = s->current_picture_ptr->poc; | |
3094 | |
3095 if( h->ref_count[0] == 1 && h->ref_count[1] == 1 | |
3096 && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){ | |
3097 h->use_weight= 0; | |
3098 h->use_weight_chroma= 0; | |
3099 return; | |
3100 } | |
3101 | |
3102 h->use_weight= 2; | |
3103 h->use_weight_chroma= 2; | |
3104 h->luma_log2_weight_denom= 5; | |
3105 h->chroma_log2_weight_denom= 5; | |
3106 | |
3107 /* FIXME: MBAFF */ | |
3108 for(ref0=0; ref0 < h->ref_count[0]; ref0++){ | |
3109 int poc0 = h->ref_list[0][ref0].poc; | |
3110 for(ref1=0; ref1 < h->ref_count[1]; ref1++){ | |
3111 int poc1 = h->ref_list[0][ref1].poc; | |
3112 int td = clip(poc1 - poc0, -128, 127); | |
3113 if(td){ | |
3114 int tb = clip(cur_poc - poc0, -128, 127); | |
3115 int tx = (16384 + (ABS(td) >> 1)) / td; | |
3116 int dist_scale_factor = clip((tb*tx + 32) >> 6, -1024, 1023) >> 2; | |
3117 if(dist_scale_factor < -64 || dist_scale_factor > 128) | |
3118 h->implicit_weight[ref0][ref1] = 32; | |
3119 else | |
3120 h->implicit_weight[ref0][ref1] = 64 - dist_scale_factor; | |
3121 }else | |
3122 h->implicit_weight[ref0][ref1] = 32; | |
3123 } | |
3124 } | |
3125 } | |
3126 | |
1168 | 3127 /** |
2392 | 3128 * instantaneous decoder refresh. |
1168 | 3129 */ |
3130 static void idr(H264Context *h){ | |
2409 | 3131 int i,j; |
3132 | |
3133 #define CHECK_DELAY(pic) \ | |
3134 for(j = 0; h->delayed_pic[j]; j++) \ | |
3135 if(pic == h->delayed_pic[j]){ \ | |
3136 pic->reference=1; \ | |
3137 break; \ | |
3138 } | |
1168 | 3139 |
3140 for(i=0; i<h->long_ref_count; i++){ | |
3141 h->long_ref[i]->reference=0; | |
2409 | 3142 CHECK_DELAY(h->long_ref[i]); |
1168 | 3143 h->long_ref[i]= NULL; |
3144 } | |
3145 h->long_ref_count=0; | |
3146 | |
3147 for(i=0; i<h->short_ref_count; i++){ | |
3148 h->short_ref[i]->reference=0; | |
2409 | 3149 CHECK_DELAY(h->short_ref[i]); |
1168 | 3150 h->short_ref[i]= NULL; |
3151 } | |
3152 h->short_ref_count=0; | |
3153 } | |
2409 | 3154 #undef CHECK_DELAY |
1168 | 3155 |
3156 /** | |
3157 * | |
3158 * @return the removed picture or NULL if an error occures | |
3159 */ | |
3160 static Picture * remove_short(H264Context *h, int frame_num){ | |
1169 | 3161 MpegEncContext * const s = &h->s; |
1168 | 3162 int i; |
3163 | |
1169 | 3164 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
|
3165 av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); |
1169 | 3166 |
1168 | 3167 for(i=0; i<h->short_ref_count; i++){ |
3168 Picture *pic= h->short_ref[i]; | |
1169 | 3169 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
|
3170 av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); |
1168 | 3171 if(pic->frame_num == frame_num){ |
3172 h->short_ref[i]= NULL; | |
3173 memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*)); | |
3174 h->short_ref_count--; | |
3175 return pic; | |
3176 } | |
3177 } | |
3178 return NULL; | |
3179 } | |
3180 | |
3181 /** | |
3182 * | |
3183 * @return the removed picture or NULL if an error occures | |
3184 */ | |
3185 static Picture * remove_long(H264Context *h, int i){ | |
3186 Picture *pic; | |
3187 | |
3188 pic= h->long_ref[i]; | |
3189 h->long_ref[i]= NULL; | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3190 if(pic) h->long_ref_count--; |
1168 | 3191 |
3192 return pic; | |
3193 } | |
3194 | |
3195 /** | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3196 * print short term list |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3197 */ |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3198 static void print_short_term(H264Context *h) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3199 uint32_t i; |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3200 if(h->s.avctx->debug&FF_DEBUG_MMCO) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3201 av_log(h->s.avctx, AV_LOG_DEBUG, "short term list:\n"); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3202 for(i=0; i<h->short_ref_count; i++){ |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3203 Picture *pic= h->short_ref[i]; |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3204 av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3205 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3206 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3207 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3208 |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3209 /** |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3210 * print long term list |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3211 */ |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3212 static void print_long_term(H264Context *h) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3213 uint32_t i; |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3214 if(h->s.avctx->debug&FF_DEBUG_MMCO) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3215 av_log(h->s.avctx, AV_LOG_DEBUG, "long term list:\n"); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3216 for(i = 0; i < 16; i++){ |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3217 Picture *pic= h->long_ref[i]; |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3218 if (pic) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3219 av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3220 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3221 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3222 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3223 } |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3224 |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3225 /** |
1168 | 3226 * Executes the reference picture marking (memory management control operations). |
3227 */ | |
3228 static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |
3229 MpegEncContext * const s = &h->s; | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3230 int i, j; |
1168 | 3231 int current_is_long=0; |
3232 Picture *pic; | |
3233 | |
3234 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
|
3235 av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); |
1168 | 3236 |
3237 for(i=0; i<mmco_count; i++){ | |
3238 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
|
3239 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 | 3240 |
3241 switch(mmco[i].opcode){ | |
3242 case MMCO_SHORT2UNUSED: | |
3243 pic= remove_short(h, mmco[i].short_frame_num); | |
3244 if(pic==NULL) return -1; | |
3245 pic->reference= 0; | |
3246 break; | |
3247 case MMCO_SHORT2LONG: | |
3248 pic= remove_long(h, mmco[i].long_index); | |
3249 if(pic) pic->reference=0; | |
3250 | |
3251 h->long_ref[ mmco[i].long_index ]= remove_short(h, mmco[i].short_frame_num); | |
3252 h->long_ref[ mmco[i].long_index ]->long_ref=1; | |
3253 break; | |
3254 case MMCO_LONG2UNUSED: | |
3255 pic= remove_long(h, mmco[i].long_index); | |
3256 if(pic==NULL) return -1; | |
3257 pic->reference= 0; | |
3258 break; | |
3259 case MMCO_LONG: | |
3260 pic= remove_long(h, mmco[i].long_index); | |
3261 if(pic) pic->reference=0; | |
3262 | |
3263 h->long_ref[ mmco[i].long_index ]= s->current_picture_ptr; | |
3264 h->long_ref[ mmco[i].long_index ]->long_ref=1; | |
3265 h->long_ref_count++; | |
3266 | |
3267 current_is_long=1; | |
3268 break; | |
3269 case MMCO_SET_MAX_LONG: | |
3270 assert(mmco[i].long_index <= 16); | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3271 // just remove the long term which index is greater than new max |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3272 for(j = mmco[i].long_index; j<16; j++){ |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3273 pic = remove_long(h, j); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3274 if (pic) pic->reference=0; |
1168 | 3275 } |
3276 break; | |
3277 case MMCO_RESET: | |
3278 while(h->short_ref_count){ | |
3279 pic= remove_short(h, h->short_ref[0]->frame_num); | |
3280 pic->reference=0; | |
3281 } | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3282 for(j = 0; j < 16; j++) { |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3283 pic= remove_long(h, j); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3284 if(pic) pic->reference=0; |
1168 | 3285 } |
3286 break; | |
3287 default: assert(0); | |
3288 } | |
3289 } | |
3290 | |
3291 if(!current_is_long){ | |
3292 pic= remove_short(h, s->current_picture_ptr->frame_num); | |
3293 if(pic){ | |
3294 pic->reference=0; | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3295 av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); |
1168 | 3296 } |
3297 | |
3298 if(h->short_ref_count) | |
1169 | 3299 memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); |
3300 | |
3301 h->short_ref[0]= s->current_picture_ptr; | |
1168 | 3302 h->short_ref[0]->long_ref=0; |
3303 h->short_ref_count++; | |
3304 } | |
3305 | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3306 print_short_term(h); |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
3307 print_long_term(h); |
1168 | 3308 return 0; |
3309 } | |
3310 | |
3311 static int decode_ref_pic_marking(H264Context *h){ | |
3312 MpegEncContext * const s = &h->s; | |
3313 int i; | |
3314 | |
3315 if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields | |
3316 s->broken_link= get_bits1(&s->gb) -1; | |
3317 h->mmco[0].long_index= get_bits1(&s->gb) - 1; // current_long_term_idx | |
3318 if(h->mmco[0].long_index == -1) | |
3319 h->mmco_index= 0; | |
3320 else{ | |
3321 h->mmco[0].opcode= MMCO_LONG; | |
3322 h->mmco_index= 1; | |
3323 } | |
3324 }else{ | |
3325 if(get_bits1(&s->gb)){ // adaptive_ref_pic_marking_mode_flag | |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
3326 for(i= 0; i<MAX_MMCO_COUNT; i++) { |
1168 | 3327 MMCOOpcode opcode= get_ue_golomb(&s->gb);; |
3328 | |
3329 h->mmco[i].opcode= opcode; | |
3330 if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){ | |
3331 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 | |
3332 /* if(h->mmco[i].short_frame_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_frame_num ] == NULL){ | |
3333 fprintf(stderr, "illegal short ref in memory management control operation %d\n", mmco); | |
3334 return -1; | |
3335 }*/ | |
3336 } | |
3337 if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){ | |
3338 h->mmco[i].long_index= get_ue_golomb(&s->gb); | |
3339 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
|
3340 av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); |
1168 | 3341 return -1; |
3342 } | |
3343 } | |
3344 | |
3345 if(opcode > MMCO_LONG){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3346 av_log(h->s.avctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", opcode); |
1168 | 3347 return -1; |
3348 } | |
2255
507690ff49a2
assertion when playing AVC/H.264 streams fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2254
diff
changeset
|
3349 if(opcode == MMCO_END) |
507690ff49a2
assertion when playing AVC/H.264 streams fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2254
diff
changeset
|
3350 break; |
1168 | 3351 } |
3352 h->mmco_index= i; | |
3353 }else{ | |
3354 assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); | |
3355 | |
3356 if(h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count){ //FIXME fields | |
3357 h->mmco[0].opcode= MMCO_SHORT2UNUSED; | |
3358 h->mmco[0].short_frame_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num; | |
3359 h->mmco_index= 1; | |
3360 }else | |
3361 h->mmco_index= 0; | |
3362 } | |
3363 } | |
3364 | |
3365 return 0; | |
3366 } | |
3367 | |
3368 static int init_poc(H264Context *h){ | |
3369 MpegEncContext * const s = &h->s; | |
3370 const int max_frame_num= 1<<h->sps.log2_max_frame_num; | |
3371 int field_poc[2]; | |
3372 | |
3373 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
3374 h->frame_num_offset= 0; | |
3375 }else{ | |
3376 if(h->frame_num < h->prev_frame_num) | |
3377 h->frame_num_offset= h->prev_frame_num_offset + max_frame_num; | |
3378 else | |
3379 h->frame_num_offset= h->prev_frame_num_offset; | |
3380 } | |
3381 | |
3382 if(h->sps.poc_type==0){ | |
3383 const int max_poc_lsb= 1<<h->sps.log2_max_poc_lsb; | |
3384 | |
3385 if (h->poc_lsb < h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb/2) | |
3386 h->poc_msb = h->prev_poc_msb + max_poc_lsb; | |
3387 else if(h->poc_lsb > h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb/2) | |
3388 h->poc_msb = h->prev_poc_msb - max_poc_lsb; | |
3389 else | |
3390 h->poc_msb = h->prev_poc_msb; | |
3391 //printf("poc: %d %d\n", h->poc_msb, h->poc_lsb); | |
3392 field_poc[0] = | |
3393 field_poc[1] = h->poc_msb + h->poc_lsb; | |
3394 if(s->picture_structure == PICT_FRAME) | |
3395 field_poc[1] += h->delta_poc_bottom; | |
3396 }else if(h->sps.poc_type==1){ | |
3397 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc; | |
3398 int i; | |
3399 | |
3400 if(h->sps.poc_cycle_length != 0) | |
3401 abs_frame_num = h->frame_num_offset + h->frame_num; | |
3402 else | |
3403 abs_frame_num = 0; | |
3404 | |
3405 if(h->nal_ref_idc==0 && abs_frame_num > 0) | |
3406 abs_frame_num--; | |
3407 | |
3408 expected_delta_per_poc_cycle = 0; | |
3409 for(i=0; i < h->sps.poc_cycle_length; i++) | |
3410 expected_delta_per_poc_cycle += h->sps.offset_for_ref_frame[ i ]; //FIXME integrate during sps parse | |
3411 | |
3412 if(abs_frame_num > 0){ | |
3413 int poc_cycle_cnt = (abs_frame_num - 1) / h->sps.poc_cycle_length; | |
3414 int frame_num_in_poc_cycle = (abs_frame_num - 1) % h->sps.poc_cycle_length; | |
3415 | |
3416 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle; | |
3417 for(i = 0; i <= frame_num_in_poc_cycle; i++) | |
3418 expectedpoc = expectedpoc + h->sps.offset_for_ref_frame[ i ]; | |
3419 } else | |
3420 expectedpoc = 0; | |
3421 | |
3422 if(h->nal_ref_idc == 0) | |
3423 expectedpoc = expectedpoc + h->sps.offset_for_non_ref_pic; | |
3424 | |
3425 field_poc[0] = expectedpoc + h->delta_poc[0]; | |
3426 field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field; | |
3427 | |
3428 if(s->picture_structure == PICT_FRAME) | |
3429 field_poc[1] += h->delta_poc[1]; | |
3430 }else{ | |
3431 int poc; | |
3432 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
3433 poc= 0; | |
3434 }else{ | |
3435 if(h->nal_ref_idc) poc= 2*(h->frame_num_offset + h->frame_num); | |
3436 else poc= 2*(h->frame_num_offset + h->frame_num) - 1; | |
3437 } | |
3438 field_poc[0]= poc; | |
3439 field_poc[1]= poc; | |
3440 } | |
3441 | |
3442 if(s->picture_structure != PICT_BOTTOM_FIELD) | |
3443 s->current_picture_ptr->field_poc[0]= field_poc[0]; | |
3444 if(s->picture_structure != PICT_TOP_FIELD) | |
3445 s->current_picture_ptr->field_poc[1]= field_poc[1]; | |
3446 if(s->picture_structure == PICT_FRAME) // FIXME field pix? | |
3447 s->current_picture_ptr->poc= FFMIN(field_poc[0], field_poc[1]); | |
3448 | |
3449 return 0; | |
3450 } | |
3451 | |
3452 /** | |
3453 * decodes a slice header. | |
3454 * this will allso call MPV_common_init() and frame_start() as needed | |
3455 */ | |
3456 static int decode_slice_header(H264Context *h){ | |
3457 MpegEncContext * const s = &h->s; | |
3458 int first_mb_in_slice, pps_id; | |
3459 int num_ref_idx_active_override_flag; | |
3460 static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; | |
3461 | |
3462 s->current_picture.reference= h->nal_ref_idc != 0; | |
3463 | |
3464 first_mb_in_slice= get_ue_golomb(&s->gb); | |
3465 | |
3466 h->slice_type= get_ue_golomb(&s->gb); | |
3467 if(h->slice_type > 9){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3468 av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); |
2392 | 3469 return -1; |
1168 | 3470 } |
3471 if(h->slice_type > 4){ | |
3472 h->slice_type -= 5; | |
3473 h->slice_type_fixed=1; | |
3474 }else | |
3475 h->slice_type_fixed=0; | |
3476 | |
3477 h->slice_type= slice_type_map[ h->slice_type ]; | |
3478 | |
3479 s->pict_type= h->slice_type; // to make a few old func happy, its wrong though | |
3480 | |
3481 pps_id= get_ue_golomb(&s->gb); | |
3482 if(pps_id>255){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3483 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); |
1168 | 3484 return -1; |
3485 } | |
3486 h->pps= h->pps_buffer[pps_id]; | |
1174 | 3487 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
|
3488 av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\n"); |
1174 | 3489 return -1; |
3490 } | |
3491 | |
1168 | 3492 h->sps= h->sps_buffer[ h->pps.sps_id ]; |
1174 | 3493 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
|
3494 av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n"); |
1174 | 3495 return -1; |
3496 } | |
1168 | 3497 |
3498 s->mb_width= h->sps.mb_width; | |
3499 s->mb_height= h->sps.mb_height; | |
3500 | |
2395 | 3501 h->b_stride= s->mb_width*4 + 1; |
3502 h->b8_stride= s->mb_width*2 + 1; | |
1168 | 3503 |
2392 | 3504 s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width; |
3505 s->resync_mb_y = s->mb_y = first_mb_in_slice / s->mb_width; //FIXME AFFW | |
1168 | 3506 |
1371 | 3507 s->width = 16*s->mb_width - 2*(h->sps.crop_left + h->sps.crop_right ); |
1168 | 3508 if(h->sps.frame_mbs_only_flag) |
1371 | 3509 s->height= 16*s->mb_height - 2*(h->sps.crop_top + h->sps.crop_bottom); |
1168 | 3510 else |
1371 | 3511 s->height= 16*s->mb_height - 4*(h->sps.crop_top + h->sps.crop_bottom); //FIXME recheck |
1168 | 3512 |
3513 if (s->context_initialized | |
1548 | 3514 && ( s->width != s->avctx->width || s->height != s->avctx->height)) { |
1168 | 3515 free_tables(h); |
3516 MPV_common_end(s); | |
3517 } | |
3518 if (!s->context_initialized) { | |
3519 if (MPV_common_init(s) < 0) | |
3520 return -1; | |
3521 | |
3522 alloc_tables(h); | |
3523 | |
3524 s->avctx->width = s->width; | |
3525 s->avctx->height = s->height; | |
1548 | 3526 s->avctx->sample_aspect_ratio= h->sps.sar; |
2440 | 3527 if(!s->avctx->sample_aspect_ratio.den) |
3528 s->avctx->sample_aspect_ratio.den = 1; | |
2174
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3529 |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3530 if(h->sps.timing_info_present_flag && h->sps.fixed_frame_rate_flag){ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3531 s->avctx->frame_rate = h->sps.time_scale; |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3532 s->avctx->frame_rate_base = h->sps.num_units_in_tick; |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
3533 } |
1168 | 3534 } |
3535 | |
2392 | 3536 if(h->slice_num == 0){ |
1168 | 3537 frame_start(h); |
3538 } | |
3539 | |
1169 | 3540 s->current_picture_ptr->frame_num= //FIXME frame_num cleanup |
1168 | 3541 h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); |
3542 | |
3543 if(h->sps.frame_mbs_only_flag){ | |
3544 s->picture_structure= PICT_FRAME; | |
3545 }else{ | |
3546 if(get_bits1(&s->gb)) //field_pic_flag | |
3547 s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag | |
3548 else | |
3549 s->picture_structure= PICT_FRAME; | |
3550 } | |
3551 | |
3552 if(s->picture_structure==PICT_FRAME){ | |
3553 h->curr_pic_num= h->frame_num; | |
3554 h->max_pic_num= 1<< h->sps.log2_max_frame_num; | |
3555 }else{ | |
3556 h->curr_pic_num= 2*h->frame_num; | |
3557 h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1); | |
3558 } | |
3559 | |
3560 if(h->nal_unit_type == NAL_IDR_SLICE){ | |
1453 | 3561 get_ue_golomb(&s->gb); /* idr_pic_id */ |
1168 | 3562 } |
3563 | |
3564 if(h->sps.poc_type==0){ | |
3565 h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb); | |
3566 | |
3567 if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){ | |
3568 h->delta_poc_bottom= get_se_golomb(&s->gb); | |
3569 } | |
3570 } | |
3571 | |
3572 if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){ | |
3573 h->delta_poc[0]= get_se_golomb(&s->gb); | |
3574 | |
3575 if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME) | |
3576 h->delta_poc[1]= get_se_golomb(&s->gb); | |
3577 } | |
3578 | |
3579 init_poc(h); | |
3580 | |
3581 if(h->pps.redundant_pic_cnt_present){ | |
3582 h->redundant_pic_count= get_ue_golomb(&s->gb); | |
3583 } | |
3584 | |
3585 //set defaults, might be overriden a few line later | |
3586 h->ref_count[0]= h->pps.ref_count[0]; | |
3587 h->ref_count[1]= h->pps.ref_count[1]; | |
3588 | |
3589 if(h->slice_type == P_TYPE || h->slice_type == SP_TYPE || h->slice_type == B_TYPE){ | |
3590 if(h->slice_type == B_TYPE){ | |
3591 h->direct_spatial_mv_pred= get_bits1(&s->gb); | |
3592 } | |
3593 num_ref_idx_active_override_flag= get_bits1(&s->gb); | |
3594 | |
3595 if(num_ref_idx_active_override_flag){ | |
3596 h->ref_count[0]= get_ue_golomb(&s->gb) + 1; | |
3597 if(h->slice_type==B_TYPE) | |
3598 h->ref_count[1]= get_ue_golomb(&s->gb) + 1; | |
3599 | |
3600 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
|
3601 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); |
1168 | 3602 return -1; |
3603 } | |
3604 } | |
3605 } | |
3606 | |
2392 | 3607 if(h->slice_num == 0){ |
1168 | 3608 fill_default_ref_list(h); |
3609 } | |
3610 | |
3611 decode_ref_pic_list_reordering(h); | |
3612 | |
3613 if( (h->pps.weighted_pred && (h->slice_type == P_TYPE || h->slice_type == SP_TYPE )) | |
3614 || (h->pps.weighted_bipred_idc==1 && h->slice_type==B_TYPE ) ) | |
3615 pred_weight_table(h); | |
2415 | 3616 else if(h->pps.weighted_bipred_idc==2 && h->slice_type==B_TYPE) |
3617 implicit_weight_table(h); | |
3618 else | |
3619 h->use_weight = 0; | |
1168 | 3620 |
3621 if(s->current_picture.reference) | |
3622 decode_ref_pic_marking(h); | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3623 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3624 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE && h->pps.cabac ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3625 h->cabac_init_idc = get_ue_golomb(&s->gb); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3626 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3627 h->last_qscale_diff = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3628 s->qscale = h->pps.init_qp + get_se_golomb(&s->gb); |
1898 | 3629 if(s->qscale<0 || s->qscale>51){ |
3630 av_log(s->avctx, AV_LOG_ERROR, "QP %d out of range\n", s->qscale); | |
3631 return -1; | |
3632 } | |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
3633 h->chroma_qp = get_chroma_qp(h, s->qscale); |
1168 | 3634 //FIXME qscale / qp ... stuff |
3635 if(h->slice_type == SP_TYPE){ | |
1453 | 3636 get_bits1(&s->gb); /* sp_for_switch_flag */ |
1168 | 3637 } |
3638 if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){ | |
1453 | 3639 get_se_golomb(&s->gb); /* slice_qs_delta */ |
1168 | 3640 } |
3641 | |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3642 h->deblocking_filter = 1; |
1898 | 3643 h->slice_alpha_c0_offset = 0; |
3644 h->slice_beta_offset = 0; | |
1168 | 3645 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
|
3646 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
|
3647 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
|
3648 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
|
3649 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3650 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
|
3651 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
|
3652 h->slice_beta_offset = get_se_golomb(&s->gb) << 1; |
1168 | 3653 } |
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
|
3654 } |
1168 | 3655 |
3656 #if 0 //FMO | |
3657 if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5) | |
3658 slice_group_change_cycle= get_bits(&s->gb, ?); | |
3659 #endif | |
3660 | |
2392 | 3661 h->slice_num++; |
3662 | |
1168 | 3663 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ |
2415 | 3664 av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d mb:%d %c pps:%d frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d weight:%d%s\n", |
2392 | 3665 h->slice_num, first_mb_in_slice, |
1264 | 3666 av_get_pict_type_char(h->slice_type), |
1168 | 3667 pps_id, h->frame_num, |
3668 s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1], | |
3669 h->ref_count[0], h->ref_count[1], | |
3670 s->qscale, | |
2415 | 3671 h->deblocking_filter, |
3672 h->use_weight, | |
3673 h->use_weight==1 && h->use_weight_chroma ? "c" : "" | |
1168 | 3674 ); |
3675 } | |
3676 | |
3677 return 0; | |
3678 } | |
3679 | |
3680 /** | |
3681 * | |
3682 */ | |
3683 static inline int get_level_prefix(GetBitContext *gb){ | |
3684 unsigned int buf; | |
3685 int log; | |
3686 | |
3687 OPEN_READER(re, gb); | |
3688 UPDATE_CACHE(re, gb); | |
3689 buf=GET_CACHE(re, gb); | |
3690 | |
3691 log= 32 - av_log2(buf); | |
3692 #ifdef TRACE | |
3693 print_bin(buf>>(32-log), log); | |
2272
cd43603c46f9
move h264 idct to its own file and call via function pointer in DspContext
michael
parents:
2255
diff
changeset
|
3694 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d lpr @%5d in %s get_level_prefix\n", buf>>(32-log), log, log-1, get_bits_count(gb), __FILE__); |
1168 | 3695 #endif |
3696 | |
3697 LAST_SKIP_BITS(re, gb, log); | |
3698 CLOSE_READER(re, gb); | |
3699 | |
3700 return log-1; | |
3701 } | |
3702 | |
3703 /** | |
3704 * decodes a residual block. | |
3705 * @param n block index | |
3706 * @param scantable scantable | |
3707 * @param max_coeff number of coefficients in the block | |
3708 * @return <0 if an error occured | |
3709 */ | |
3710 static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, int qp, int max_coeff){ | |
3711 MpegEncContext * const s = &h->s; | |
3712 const uint16_t *qmul= dequant_coeff[qp]; | |
3713 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}; | |
3714 int level[16], run[16]; | |
3715 int suffix_length, zeros_left, coeff_num, coeff_token, total_coeff, i, trailing_ones; | |
3716 | |
3717 //FIXME put trailing_onex into the context | |
3718 | |
3719 if(n == CHROMA_DC_BLOCK_INDEX){ | |
3720 coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1); | |
3721 total_coeff= coeff_token>>2; | |
3722 }else{ | |
3723 if(n == LUMA_DC_BLOCK_INDEX){ | |
3724 total_coeff= pred_non_zero_count(h, 0); | |
3725 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); | |
3726 total_coeff= coeff_token>>2; | |
3727 }else{ | |
3728 total_coeff= pred_non_zero_count(h, n); | |
3729 coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); | |
3730 total_coeff= coeff_token>>2; | |
3731 h->non_zero_count_cache[ scan8[n] ]= total_coeff; | |
3732 } | |
3733 } | |
3734 | |
3735 //FIXME set last_non_zero? | |
3736 | |
3737 if(total_coeff==0) | |
3738 return 0; | |
3739 | |
3740 trailing_ones= coeff_token&3; | |
1170 | 3741 tprintf("trailing:%d, total:%d\n", trailing_ones, total_coeff); |
1168 | 3742 assert(total_coeff<=16); |
3743 | |
3744 for(i=0; i<trailing_ones; i++){ | |
3745 level[i]= 1 - 2*get_bits1(gb); | |
3746 } | |
3747 | |
3748 suffix_length= total_coeff > 10 && trailing_ones < 3; | |
3749 | |
3750 for(; i<total_coeff; i++){ | |
3751 const int prefix= get_level_prefix(gb); | |
3752 int level_code, mask; | |
3753 | |
3754 if(prefix<14){ //FIXME try to build a large unified VLC table for all this | |
3755 if(suffix_length) | |
3756 level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part | |
3757 else | |
3758 level_code= (prefix<<suffix_length); //part | |
3759 }else if(prefix==14){ | |
3760 if(suffix_length) | |
3761 level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part | |
3762 else | |
3763 level_code= prefix + get_bits(gb, 4); //part | |
3764 }else if(prefix==15){ | |
3765 level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part | |
3766 if(suffix_length==0) level_code+=15; //FIXME doesnt make (much)sense | |
3767 }else{ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3768 av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y); |
1168 | 3769 return -1; |
3770 } | |
3771 | |
3772 if(i==trailing_ones && i<3) level_code+= 2; //FIXME split first iteration | |
3773 | |
3774 mask= -(level_code&1); | |
3775 level[i]= (((2+level_code)>>1) ^ mask) - mask; | |
3776 | |
3777 if(suffix_length==0) suffix_length=1; //FIXME split first iteration | |
3778 | |
3779 #if 1 | |
3780 if(ABS(level[i]) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++; | |
3781 #else | |
3782 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
|
3783 /* ? == prefix > 2 or sth */ |
1168 | 3784 #endif |
1170 | 3785 tprintf("level: %d suffix_length:%d\n", level[i], suffix_length); |
1168 | 3786 } |
3787 | |
3788 if(total_coeff == max_coeff) | |
3789 zeros_left=0; | |
3790 else{ | |
3791 if(n == CHROMA_DC_BLOCK_INDEX) | |
3792 zeros_left= get_vlc2(gb, chroma_dc_total_zeros_vlc[ total_coeff-1 ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1); | |
3793 else | |
3794 zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff-1 ].table, TOTAL_ZEROS_VLC_BITS, 1); | |
3795 } | |
3796 | |
3797 for(i=0; i<total_coeff-1; i++){ | |
3798 if(zeros_left <=0) | |
3799 break; | |
3800 else if(zeros_left < 7){ | |
3801 run[i]= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1); | |
3802 }else{ | |
3803 run[i]= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); | |
3804 } | |
3805 zeros_left -= run[i]; | |
3806 } | |
3807 | |
3808 if(zeros_left<0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3809 av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); |
1168 | 3810 return -1; |
3811 } | |
3812 | |
3813 for(; i<total_coeff-1; i++){ | |
3814 run[i]= 0; | |
3815 } | |
3816 | |
3817 run[i]= zeros_left; | |
3818 | |
3819 coeff_num=-1; | |
3820 if(n > 24){ | |
3821 for(i=total_coeff-1; i>=0; i--){ //FIXME merge into rundecode? | |
3822 int j; | |
3823 | |
3824 coeff_num += run[i] + 1; //FIXME add 1 earlier ? | |
3825 j= scantable[ coeff_num ]; | |
3826 | |
3827 block[j]= level[i]; | |
3828 } | |
3829 }else{ | |
3830 for(i=total_coeff-1; i>=0; i--){ //FIXME merge into rundecode? | |
3831 int j; | |
3832 | |
3833 coeff_num += run[i] + 1; //FIXME add 1 earlier ? | |
3834 j= scantable[ coeff_num ]; | |
3835 | |
3836 block[j]= level[i] * qmul[j]; | |
3837 // printf("%d %d ", block[j], qmul[j]); | |
3838 } | |
3839 } | |
3840 return 0; | |
3841 } | |
3842 | |
3843 /** | |
2396 | 3844 * decodes a P_SKIP or B_SKIP macroblock |
3845 */ | |
3846 static void decode_mb_skip(H264Context *h){ | |
3847 MpegEncContext * const s = &h->s; | |
3848 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; | |
3849 int mb_type; | |
3850 | |
3851 memset(h->non_zero_count[mb_xy], 0, 16); | |
3852 memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui | |
3853 | |
3854 if( h->slice_type == B_TYPE ) | |
3855 { | |
3856 // just for fill_caches. pred_direct_motion will set the real mb_type | |
3857 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; | |
3858 //FIXME mbaff | |
3859 | |
3860 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | |
3861 pred_direct_motion(h, &mb_type); | |
3862 if(h->pps.cabac){ | |
3863 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
3864 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
3865 } | |
3866 } | |
3867 else | |
3868 { | |
3869 int mx, my; | |
3870 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP; | |
3871 | |
3872 if(h->sps.mb_aff && s->mb_skip_run==0 && (s->mb_y&1)==0){ | |
3873 h->mb_field_decoding_flag= get_bits1(&s->gb); | |
3874 } | |
3875 if(h->mb_field_decoding_flag) | |
3876 mb_type|= MB_TYPE_INTERLACED; | |
3877 | |
3878 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | |
3879 pred_pskip_motion(h, &mx, &my); | |
3880 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | |
3881 fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); | |
3882 if(h->pps.cabac) | |
3883 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
3884 } | |
3885 | |
3886 write_back_motion(h, mb_type); | |
3887 s->current_picture.mb_type[mb_xy]= mb_type|MB_TYPE_SKIP; | |
3888 s->current_picture.qscale_table[mb_xy]= s->qscale; | |
3889 h->slice_table[ mb_xy ]= h->slice_num; | |
3890 h->prev_mb_skiped= 1; | |
3891 } | |
3892 | |
3893 /** | |
1168 | 3894 * decodes a macroblock |
3895 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed | |
3896 */ | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
3897 static int decode_mb_cavlc(H264Context *h){ |
1168 | 3898 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
|
3899 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
1169 | 3900 int mb_type, partition_count, cbp; |
1168 | 3901 |
1252 | 3902 s->dsp.clear_blocks(h->mb); //FIXME avoid if allready clear (move after skip handlong? |
1168 | 3903 |
1170 | 3904 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); |
1453 | 3905 cbp = 0; /* avoid warning. FIXME: find a solution without slowing |
3906 down the code */ | |
1168 | 3907 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ |
3908 if(s->mb_skip_run==-1) | |
3909 s->mb_skip_run= get_ue_golomb(&s->gb); | |
3910 | |
3911 if (s->mb_skip_run--) { | |
2396 | 3912 decode_mb_skip(h); |
1168 | 3913 return 0; |
3914 } | |
3915 } | |
3916 if(h->sps.mb_aff /* && !field pic FIXME needed? */){ | |
3917 if((s->mb_y&1)==0) | |
3918 h->mb_field_decoding_flag = get_bits1(&s->gb); | |
3919 }else | |
3920 h->mb_field_decoding_flag=0; //FIXME som ed note ?! | |
3921 | |
3922 h->prev_mb_skiped= 0; | |
3923 | |
3924 mb_type= get_ue_golomb(&s->gb); | |
3925 if(h->slice_type == B_TYPE){ | |
3926 if(mb_type < 23){ | |
3927 partition_count= b_mb_type_info[mb_type].partition_count; | |
3928 mb_type= b_mb_type_info[mb_type].type; | |
3929 }else{ | |
3930 mb_type -= 23; | |
3931 goto decode_intra_mb; | |
3932 } | |
3933 }else if(h->slice_type == P_TYPE /*|| h->slice_type == SP_TYPE */){ | |
3934 if(mb_type < 5){ | |
3935 partition_count= p_mb_type_info[mb_type].partition_count; | |
3936 mb_type= p_mb_type_info[mb_type].type; | |
3937 }else{ | |
3938 mb_type -= 5; | |
3939 goto decode_intra_mb; | |
3940 } | |
3941 }else{ | |
3942 assert(h->slice_type == I_TYPE); | |
3943 decode_intra_mb: | |
3944 if(mb_type > 25){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
3945 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 | 3946 return -1; |
3947 } | |
3948 partition_count=0; | |
3949 cbp= i_mb_type_info[mb_type].cbp; | |
3950 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; | |
3951 mb_type= i_mb_type_info[mb_type].type; | |
3952 } | |
3953 | |
3954 if(h->mb_field_decoding_flag) | |
3955 mb_type |= MB_TYPE_INTERLACED; | |
3956 | |
3957 s->current_picture.mb_type[mb_xy]= mb_type; | |
3958 h->slice_table[ mb_xy ]= h->slice_num; | |
3959 | |
3960 if(IS_INTRA_PCM(mb_type)){ | |
3961 const uint8_t *ptr; | |
1187 | 3962 int x, y; |
1168 | 3963 |
3964 // we assume these blocks are very rare so we dont optimize it | |
3965 align_get_bits(&s->gb); | |
3966 | |
3967 ptr= s->gb.buffer + get_bits_count(&s->gb); | |
3968 | |
3969 for(y=0; y<16; y++){ | |
3970 const int index= 4*(y&3) + 64*(y>>2); | |
3971 for(x=0; x<16; x++){ | |
3972 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); | |
3973 } | |
3974 } | |
3975 for(y=0; y<8; y++){ | |
3976 const int index= 256 + 4*(y&3) + 32*(y>>2); | |
3977 for(x=0; x<8; x++){ | |
3978 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); | |
3979 } | |
3980 } | |
3981 for(y=0; y<8; y++){ | |
3982 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); | |
3983 for(x=0; x<8; x++){ | |
3984 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); | |
3985 } | |
3986 } | |
3987 | |
3988 skip_bits(&s->gb, 384); //FIXME check /fix the bitstream readers | |
3989 | |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
3990 //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
|
3991 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
|
3992 s->current_picture.qscale_table[mb_xy]= s->qscale; |
1168 | 3993 |
3994 return 0; | |
3995 } | |
3996 | |
3997 fill_caches(h, mb_type); | |
3998 | |
3999 //mb_pred | |
4000 if(IS_INTRA(mb_type)){ | |
4001 // init_top_left_availability(h); | |
4002 if(IS_INTRA4x4(mb_type)){ | |
4003 int i; | |
4004 | |
4005 // fill_intra4x4_pred_table(h); | |
4006 for(i=0; i<16; i++){ | |
4007 const int mode_coded= !get_bits1(&s->gb); | |
4008 const int predicted_mode= pred_intra_mode(h, i); | |
4009 int mode; | |
4010 | |
4011 if(mode_coded){ | |
4012 const int rem_mode= get_bits(&s->gb, 3); | |
4013 if(rem_mode<predicted_mode) | |
4014 mode= rem_mode; | |
4015 else | |
4016 mode= rem_mode + 1; | |
4017 }else{ | |
4018 mode= predicted_mode; | |
4019 } | |
4020 | |
4021 h->intra4x4_pred_mode_cache[ scan8[i] ] = mode; | |
4022 } | |
4023 write_back_intra_pred_mode(h); | |
4024 if( check_intra4x4_pred_mode(h) < 0) | |
4025 return -1; | |
4026 }else{ | |
4027 h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode); | |
4028 if(h->intra16x16_pred_mode < 0) | |
4029 return -1; | |
4030 } | |
4031 h->chroma_pred_mode= get_ue_golomb(&s->gb); | |
4032 | |
4033 h->chroma_pred_mode= check_intra_pred_mode(h, h->chroma_pred_mode); | |
4034 if(h->chroma_pred_mode < 0) | |
4035 return -1; | |
4036 }else if(partition_count==4){ | |
4037 int i, j, sub_partition_count[4], list, ref[2][4]; | |
4038 | |
4039 if(h->slice_type == B_TYPE){ | |
4040 for(i=0; i<4; i++){ | |
4041 h->sub_mb_type[i]= get_ue_golomb(&s->gb); | |
4042 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
|
4043 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 | 4044 return -1; |
4045 } | |
4046 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | |
4047 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; | |
4048 } | |
2396 | 4049 if( IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1]) |
4050 || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) | |
4051 pred_direct_motion(h, &mb_type); | |
1168 | 4052 }else{ |
4053 assert(h->slice_type == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ? | |
4054 for(i=0; i<4; i++){ | |
4055 h->sub_mb_type[i]= get_ue_golomb(&s->gb); | |
4056 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
|
4057 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 | 4058 return -1; |
4059 } | |
4060 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | |
4061 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; | |
4062 } | |
4063 } | |
4064 | |
4065 for(list=0; list<2; list++){ | |
4066 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | |
4067 if(ref_count == 0) continue; | |
4068 for(i=0; i<4; i++){ | |
2396 | 4069 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
4070 if(IS_DIR(h->sub_mb_type[i], 0, list)){ | |
1168 | 4071 ref[list][i] = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip? |
4072 }else{ | |
4073 //FIXME | |
4074 ref[list][i] = -1; | |
4075 } | |
4076 } | |
4077 } | |
4078 | |
4079 for(list=0; list<2; list++){ | |
4080 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | |
4081 if(ref_count == 0) continue; | |
4082 | |
4083 for(i=0; i<4; i++){ | |
2396 | 4084 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
1168 | 4085 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]= |
4086 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; | |
4087 | |
2396 | 4088 if(IS_DIR(h->sub_mb_type[i], 0, list)){ |
1168 | 4089 const int sub_mb_type= h->sub_mb_type[i]; |
4090 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; | |
4091 for(j=0; j<sub_partition_count[i]; j++){ | |
4092 int mx, my; | |
4093 const int index= 4*i + block_width*j; | |
4094 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; | |
4095 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |
4096 mx += get_se_golomb(&s->gb); | |
4097 my += get_se_golomb(&s->gb); | |
1170 | 4098 tprintf("final mv:%d %d\n", mx, my); |
4099 | |
1168 | 4100 if(IS_SUB_8X8(sub_mb_type)){ |
4101 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= | |
4102 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; | |
4103 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= | |
4104 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; | |
4105 }else if(IS_SUB_8X4(sub_mb_type)){ | |
4106 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mx; | |
4107 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= my; | |
4108 }else if(IS_SUB_4X8(sub_mb_type)){ | |
4109 mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mx; | |
4110 mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= my; | |
4111 }else{ | |
4112 assert(IS_SUB_4X4(sub_mb_type)); | |
4113 mv_cache[ 0 ][0]= mx; | |
4114 mv_cache[ 0 ][1]= my; | |
4115 } | |
4116 } | |
4117 }else{ | |
4118 uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0]; | |
4119 p[0] = p[1]= | |
4120 p[8] = p[9]= 0; | |
4121 } | |
4122 } | |
4123 } | |
2396 | 4124 }else if(IS_DIRECT(mb_type)){ |
4125 pred_direct_motion(h, &mb_type); | |
4126 s->current_picture.mb_type[mb_xy]= mb_type; | |
4127 }else{ | |
1168 | 4128 int list, mx, my, i; |
4129 //FIXME we should set ref_idx_l? to 0 if we use that later ... | |
4130 if(IS_16X16(mb_type)){ | |
4131 for(list=0; list<2; list++){ | |
2392 | 4132 if(h->ref_count[list]>0){ |
1168 | 4133 if(IS_DIR(mb_type, 0, list)){ |
4134 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
4135 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1); | |
4136 } | |
4137 } | |
4138 } | |
4139 for(list=0; list<2; list++){ | |
4140 if(IS_DIR(mb_type, 0, list)){ | |
4141 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |
4142 mx += get_se_golomb(&s->gb); | |
4143 my += get_se_golomb(&s->gb); | |
1170 | 4144 tprintf("final mv:%d %d\n", mx, my); |
4145 | |
1269 | 4146 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); |
1168 | 4147 } |
4148 } | |
4149 } | |
4150 else if(IS_16X8(mb_type)){ | |
4151 for(list=0; list<2; list++){ | |
4152 if(h->ref_count[list]>0){ | |
4153 for(i=0; i<2; i++){ | |
4154 if(IS_DIR(mb_type, i, list)){ | |
4155 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
4156 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); | |
2396 | 4157 }else // needed only for mixed refs (e.g. B_L0_L1_16x8) |
4158 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); | |
1168 | 4159 } |
4160 } | |
4161 } | |
4162 for(list=0; list<2; list++){ | |
4163 for(i=0; i<2; i++){ | |
4164 if(IS_DIR(mb_type, i, list)){ | |
4165 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |
4166 mx += get_se_golomb(&s->gb); | |
4167 my += get_se_golomb(&s->gb); | |
1170 | 4168 tprintf("final mv:%d %d\n", mx, my); |
4169 | |
1269 | 4170 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); |
2396 | 4171 }else |
4172 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); | |
1168 | 4173 } |
4174 } | |
4175 }else{ | |
4176 assert(IS_8X16(mb_type)); | |
4177 for(list=0; list<2; list++){ | |
4178 if(h->ref_count[list]>0){ | |
4179 for(i=0; i<2; i++){ | |
4180 if(IS_DIR(mb_type, i, list)){ //FIXME optimize | |
4181 const int val= get_te0_golomb(&s->gb, h->ref_count[list]); | |
4182 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); | |
2396 | 4183 }else // needed only for mixed refs |
4184 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); | |
1168 | 4185 } |
4186 } | |
4187 } | |
4188 for(list=0; list<2; list++){ | |
4189 for(i=0; i<2; i++){ | |
4190 if(IS_DIR(mb_type, i, list)){ | |
4191 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |
4192 mx += get_se_golomb(&s->gb); | |
4193 my += get_se_golomb(&s->gb); | |
1170 | 4194 tprintf("final mv:%d %d\n", mx, my); |
4195 | |
1269 | 4196 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); |
2396 | 4197 }else |
4198 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); | |
1168 | 4199 } |
4200 } | |
4201 } | |
4202 } | |
4203 | |
4204 if(IS_INTER(mb_type)) | |
4205 write_back_motion(h, mb_type); | |
4206 | |
4207 if(!IS_INTRA16x16(mb_type)){ | |
4208 cbp= get_ue_golomb(&s->gb); | |
4209 if(cbp > 47){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4210 av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%d) at %d %d\n", cbp, s->mb_x, s->mb_y); |
1168 | 4211 return -1; |
4212 } | |
4213 | |
4214 if(IS_INTRA4x4(mb_type)) | |
4215 cbp= golomb_to_intra4x4_cbp[cbp]; | |
4216 else | |
4217 cbp= golomb_to_inter_cbp[cbp]; | |
4218 } | |
4219 | |
4220 if(cbp || IS_INTRA16x16(mb_type)){ | |
4221 int i8x8, i4x4, chroma_idx; | |
4222 int chroma_qp, dquant; | |
4223 GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; | |
4224 const uint8_t *scan, *dc_scan; | |
4225 | |
4226 // fill_non_zero_count_cache(h); | |
4227 | |
4228 if(IS_INTERLACED(mb_type)){ | |
4229 scan= field_scan; | |
4230 dc_scan= luma_dc_field_scan; | |
4231 }else{ | |
4232 scan= zigzag_scan; | |
4233 dc_scan= luma_dc_zigzag_scan; | |
4234 } | |
4235 | |
4236 dquant= get_se_golomb(&s->gb); | |
4237 | |
4238 if( dquant > 25 || dquant < -26 ){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
4239 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 | 4240 return -1; |
4241 } | |
4242 | |
4243 s->qscale += dquant; | |
4244 if(((unsigned)s->qscale) > 51){ | |
4245 if(s->qscale<0) s->qscale+= 52; | |
4246 else s->qscale-= 52; | |
4247 } | |
4248 | |
4249 h->chroma_qp= chroma_qp= get_chroma_qp(h, s->qscale); | |
4250 if(IS_INTRA16x16(mb_type)){ | |
4251 if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, s->qscale, 16) < 0){ | |
4252 return -1; //FIXME continue if partotioned and other retirn -1 too | |
4253 } | |
4254 | |
4255 assert((cbp&15) == 0 || (cbp&15) == 15); | |
4256 | |
4257 if(cbp&15){ | |
4258 for(i8x8=0; i8x8<4; i8x8++){ | |
4259 for(i4x4=0; i4x4<4; i4x4++){ | |
4260 const int index= i4x4 + 4*i8x8; | |
4261 if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, s->qscale, 15) < 0 ){ | |
4262 return -1; | |
4263 } | |
4264 } | |
4265 } | |
4266 }else{ | |
1636 | 4267 fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); |
1168 | 4268 } |
4269 }else{ | |
4270 for(i8x8=0; i8x8<4; i8x8++){ | |
4271 if(cbp & (1<<i8x8)){ | |
4272 for(i4x4=0; i4x4<4; i4x4++){ | |
4273 const int index= i4x4 + 4*i8x8; | |
4274 | |
4275 if( decode_residual(h, gb, h->mb + 16*index, index, scan, s->qscale, 16) <0 ){ | |
4276 return -1; | |
4277 } | |
4278 } | |
4279 }else{ | |
4280 uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; | |
4281 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; | |
4282 } | |
4283 } | |
4284 } | |
4285 | |
4286 if(cbp&0x30){ | |
4287 for(chroma_idx=0; chroma_idx<2; chroma_idx++) | |
4288 if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, chroma_qp, 4) < 0){ | |
4289 return -1; | |
4290 } | |
4291 } | |
4292 | |
4293 if(cbp&0x20){ | |
4294 for(chroma_idx=0; chroma_idx<2; chroma_idx++){ | |
4295 for(i4x4=0; i4x4<4; i4x4++){ | |
4296 const int index= 16 + 4*chroma_idx + i4x4; | |
4297 if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, chroma_qp, 15) < 0){ | |
4298 return -1; | |
4299 } | |
4300 } | |
4301 } | |
4302 }else{ | |
4303 uint8_t * const nnz= &h->non_zero_count_cache[0]; | |
4304 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = | |
4305 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; | |
4306 } | |
4307 }else{ | |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
4308 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
|
4309 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
|
4310 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
|
4311 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; |
1168 | 4312 } |
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
|
4313 s->current_picture.qscale_table[mb_xy]= s->qscale; |
1168 | 4314 write_back_non_zero_count(h); |
4315 | |
4316 return 0; | |
4317 } | |
4318 | |
2312 | 4319 static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) { |
4320 uint8_t *state= &h->cabac_state[ctx_base]; | |
4321 int mb_type; | |
4322 | |
4323 if(intra_slice){ | |
4324 MpegEncContext * const s = &h->s; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4325 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
2312 | 4326 int ctx=0; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4327 if( s->mb_x > 0 && !IS_INTRA4x4( s->current_picture.mb_type[mb_xy-1] ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4328 ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4329 if( s->mb_y > 0 && !IS_INTRA4x4( s->current_picture.mb_type[mb_xy-s->mb_stride] ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4330 ctx++; |
2312 | 4331 if( get_cabac( &h->cabac, &state[ctx] ) == 0 ) |
4332 return 0; /* I4x4 */ | |
4333 state += 2; | |
4334 }else{ | |
4335 if( get_cabac( &h->cabac, &state[0] ) == 0 ) | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4336 return 0; /* I4x4 */ |
2312 | 4337 } |
4338 | |
4339 if( get_cabac_terminate( &h->cabac ) ) | |
4340 return 25; /* PCM */ | |
4341 | |
4342 mb_type = 1; /* I16x16 */ | |
4343 if( get_cabac( &h->cabac, &state[1] ) ) | |
4344 mb_type += 12; /* cbp_luma != 0 */ | |
4345 | |
4346 if( get_cabac( &h->cabac, &state[2] ) ) { | |
4347 if( get_cabac( &h->cabac, &state[2+intra_slice] ) ) | |
4348 mb_type += 4 * 2; /* cbp_chroma == 2 */ | |
4349 else | |
4350 mb_type += 4 * 1; /* cbp_chroma == 1 */ | |
4351 } | |
4352 if( get_cabac( &h->cabac, &state[3+intra_slice] ) ) | |
4353 mb_type += 2; | |
4354 if( get_cabac( &h->cabac, &state[3+2*intra_slice] ) ) | |
4355 mb_type += 1; | |
4356 return mb_type; | |
4357 } | |
4358 | |
4359 static int decode_cabac_mb_type( H264Context *h ) { | |
4360 MpegEncContext * const s = &h->s; | |
4361 | |
4362 if( h->slice_type == I_TYPE ) { | |
4363 return decode_cabac_intra_mb_type(h, 3, 1); | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4364 } else if( h->slice_type == P_TYPE ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4365 if( get_cabac( &h->cabac, &h->cabac_state[14] ) == 0 ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4366 /* P-type */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4367 if( get_cabac( &h->cabac, &h->cabac_state[15] ) == 0 ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4368 if( get_cabac( &h->cabac, &h->cabac_state[16] ) == 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4369 return 0; /* P_L0_D16x16; */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4370 else |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4371 return 3; /* P_8x8; */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4372 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4373 if( get_cabac( &h->cabac, &h->cabac_state[17] ) == 0 ) |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4374 return 2; /* P_L0_D8x16; */ |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4375 else |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4376 return 1; /* P_L0_D16x8; */ |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4377 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4378 } else { |
2312 | 4379 return decode_cabac_intra_mb_type(h, 17, 0) + 5; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4380 } |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4381 } else if( h->slice_type == B_TYPE ) { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4382 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4383 int ctx = 0; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4384 int bits; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4385 |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4386 if( s->mb_x > 0 && !IS_SKIP( s->current_picture.mb_type[mb_xy-1] ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4387 && !IS_DIRECT( s->current_picture.mb_type[mb_xy-1] ) ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4388 ctx++; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4389 if( s->mb_y > 0 && !IS_SKIP( s->current_picture.mb_type[mb_xy-s->mb_stride] ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4390 && !IS_DIRECT( s->current_picture.mb_type[mb_xy-s->mb_stride] ) ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4391 ctx++; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4392 |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4393 if( !get_cabac( &h->cabac, &h->cabac_state[27+ctx] ) ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4394 return 0; /* B_Direct_16x16 */ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4395 |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4396 if( !get_cabac( &h->cabac, &h->cabac_state[27+3] ) ) { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4397 return 1 + get_cabac( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4398 } |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4399 |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4400 bits = get_cabac( &h->cabac, &h->cabac_state[27+4] ) << 3; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4401 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 2; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4402 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 1; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4403 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ); |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4404 if( bits < 8 ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4405 return bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4406 else if( bits == 13 ) { |
2312 | 4407 return decode_cabac_intra_mb_type(h, 32, 0) + 23; |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4408 } else if( bits == 14 ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4409 return 11; /* B_L1_L0_8x16 */ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4410 else if( bits == 15 ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4411 return 22; /* B_8x8 */ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4412 |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4413 bits= ( bits<<1 ) | get_cabac( &h->cabac, &h->cabac_state[27+5] ); |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4414 return bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */ |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4415 } else { |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4416 /* TODO SI/SP frames? */ |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4417 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4418 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4419 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4420 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4421 static int decode_cabac_mb_skip( H264Context *h) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4422 MpegEncContext * const s = &h->s; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4423 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4424 const int mba_xy = mb_xy - 1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4425 const int mbb_xy = mb_xy - s->mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4426 int ctx = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4427 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4428 if( s->mb_x > 0 && !IS_SKIP( s->current_picture.mb_type[mba_xy] ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4429 ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4430 if( s->mb_y > 0 && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4431 ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4432 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4433 if( h->slice_type == P_TYPE || h->slice_type == SP_TYPE) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4434 return get_cabac( &h->cabac, &h->cabac_state[11+ctx] ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4435 else /* B-frame */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4436 return get_cabac( &h->cabac, &h->cabac_state[24+ctx] ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4437 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4438 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4439 static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4440 int mode = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4441 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4442 if( get_cabac( &h->cabac, &h->cabac_state[68] ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4443 return pred_mode; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4444 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4445 if( get_cabac( &h->cabac, &h->cabac_state[69] ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4446 mode += 1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4447 if( get_cabac( &h->cabac, &h->cabac_state[69] ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4448 mode += 2; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4449 if( get_cabac( &h->cabac, &h->cabac_state[69] ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4450 mode += 4; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4451 if( mode >= pred_mode ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4452 return mode + 1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4453 else |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4454 return mode; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4455 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4456 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4457 static int decode_cabac_mb_chroma_pre_mode( H264Context *h) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4458 MpegEncContext * const s = &h->s; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4459 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4460 const int mba_xy = mb_xy - 1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4461 const int mbb_xy = mb_xy - s->mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4462 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4463 int ctx = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4464 |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4465 /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */ |
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4466 if( s->mb_x > 0 && h->chroma_pred_mode_table[mba_xy] != 0 ) |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4467 ctx++; |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4468 |
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4469 if( s->mb_y > 0 && h->chroma_pred_mode_table[mbb_xy] != 0 ) |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4470 ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4471 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4472 if( get_cabac( &h->cabac, &h->cabac_state[64+ctx] ) == 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4473 return 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4474 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4475 if( get_cabac( &h->cabac, &h->cabac_state[64+3] ) == 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4476 return 1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4477 if( get_cabac( &h->cabac, &h->cabac_state[64+3] ) == 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4478 return 2; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4479 else |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4480 return 3; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4481 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4482 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4483 static const uint8_t block_idx_x[16] = { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4484 0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4485 }; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4486 static const uint8_t block_idx_y[16] = { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4487 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4488 }; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4489 static const uint8_t block_idx_xy[4][4] = { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4490 { 0, 2, 8, 10}, |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4491 { 1, 3, 9, 11}, |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4492 { 4, 6, 12, 14}, |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4493 { 5, 7, 13, 15} |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4494 }; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4495 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4496 static int decode_cabac_mb_cbp_luma( H264Context *h) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4497 MpegEncContext * const s = &h->s; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4498 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4499 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4500 int cbp = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4501 int i8x8; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4502 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4503 h->cbp_table[mb_xy] = 0; /* FIXME aaahahahah beurk */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4504 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4505 for( i8x8 = 0; i8x8 < 4; i8x8++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4506 int mba_xy = -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4507 int mbb_xy = -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4508 int x, y; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4509 int ctx = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4510 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4511 x = block_idx_x[4*i8x8]; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4512 y = block_idx_y[4*i8x8]; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4513 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4514 if( x > 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4515 mba_xy = mb_xy; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4516 else if( s->mb_x > 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4517 mba_xy = mb_xy - 1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4518 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4519 if( y > 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4520 mbb_xy = mb_xy; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4521 else if( s->mb_y > 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4522 mbb_xy = mb_xy - s->mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4523 |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4524 /* No need to test for skip as we put 0 for skip block */ |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4525 if( mba_xy >= 0 ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4526 int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4527 if( ((h->cbp_table[mba_xy] >> i8x8a)&0x01) == 0 ) |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4528 ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4529 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4530 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4531 if( mbb_xy >= 0 ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4532 int i8x8b = block_idx_xy[x][(y-1)&0x03]/4; |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4533 if( ((h->cbp_table[mbb_xy] >> i8x8b)&0x01) == 0 ) |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4534 ctx += 2; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4535 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4536 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4537 if( get_cabac( &h->cabac, &h->cabac_state[73 + ctx] ) ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4538 cbp |= 1 << i8x8; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4539 h->cbp_table[mb_xy] = cbp; /* FIXME aaahahahah beurk */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4540 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4541 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4542 return cbp; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4543 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4544 static int decode_cabac_mb_cbp_chroma( H264Context *h) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4545 int ctx; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4546 int cbp_a, cbp_b; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4547 |
2314 | 4548 cbp_a = (h->left_cbp>>4)&0x03; |
4549 cbp_b = (h-> top_cbp>>4)&0x03; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4550 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4551 ctx = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4552 if( cbp_a > 0 ) ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4553 if( cbp_b > 0 ) ctx += 2; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4554 if( get_cabac( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4555 return 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4556 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4557 ctx = 4; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4558 if( cbp_a == 2 ) ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4559 if( cbp_b == 2 ) ctx += 2; |
2314 | 4560 return 1 + get_cabac( &h->cabac, &h->cabac_state[77 + ctx] ); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4561 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4562 static int decode_cabac_mb_dqp( H264Context *h) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4563 MpegEncContext * const s = &h->s; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4564 int mbn_xy; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4565 int ctx = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4566 int val = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4567 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4568 if( s->mb_x > 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4569 mbn_xy = s->mb_x + s->mb_y*s->mb_stride - 1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4570 else |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4571 mbn_xy = s->mb_width - 1 + (s->mb_y-1)*s->mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4572 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4573 if( mbn_xy >= 0 && h->last_qscale_diff != 0 && ( IS_INTRA16x16(s->current_picture.mb_type[mbn_xy] ) || (h->cbp_table[mbn_xy]&0x3f) ) ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4574 ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4575 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4576 while( get_cabac( &h->cabac, &h->cabac_state[60 + ctx] ) ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4577 if( ctx < 2 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4578 ctx = 2; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4579 else |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4580 ctx = 3; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4581 val++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4582 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4583 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4584 if( val&0x01 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4585 return (val + 1)/2; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4586 else |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4587 return -(val + 1)/2; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4588 } |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4589 static int decode_cabac_p_mb_sub_type( H264Context *h ) { |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4590 if( get_cabac( &h->cabac, &h->cabac_state[21] ) ) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4591 return 0; /* 8x8 */ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4592 if( !get_cabac( &h->cabac, &h->cabac_state[22] ) ) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4593 return 1; /* 8x4 */ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4594 if( get_cabac( &h->cabac, &h->cabac_state[23] ) ) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4595 return 2; /* 4x8 */ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4596 return 3; /* 4x4 */ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4597 } |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4598 static int decode_cabac_b_mb_sub_type( H264Context *h ) { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4599 int type; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4600 if( !get_cabac( &h->cabac, &h->cabac_state[36] ) ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4601 return 0; /* B_Direct_8x8 */ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4602 if( !get_cabac( &h->cabac, &h->cabac_state[37] ) ) |
2311
cdbb2f30e08b
small typo patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
2310
diff
changeset
|
4603 return 1 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L0_8x8, B_L1_8x8 */ |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4604 type = 3; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4605 if( get_cabac( &h->cabac, &h->cabac_state[38] ) ) { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4606 if( get_cabac( &h->cabac, &h->cabac_state[39] ) ) |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4607 return 11 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L1_4x4, B_Bi_4x4 */ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4608 type += 4; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4609 } |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4610 type += 2*get_cabac( &h->cabac, &h->cabac_state[39] ); |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4611 type += get_cabac( &h->cabac, &h->cabac_state[39] ); |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4612 return type; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4613 } |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4614 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4615 static int decode_cabac_mb_ref( H264Context *h, int list, int n ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4616 int refa = h->ref_cache[list][scan8[n] - 1]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4617 int refb = h->ref_cache[list][scan8[n] - 8]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4618 int ref = 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4619 int ctx = 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4620 |
2396 | 4621 if( h->slice_type == B_TYPE) { |
4622 if( refa > 0 && !h->direct_cache[scan8[n] - 1] ) | |
4623 ctx++; | |
4624 if( refb > 0 && !h->direct_cache[scan8[n] - 8] ) | |
4625 ctx += 2; | |
4626 } else { | |
4627 if( refa > 0 ) | |
4628 ctx++; | |
4629 if( refb > 0 ) | |
4630 ctx += 2; | |
4631 } | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4632 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4633 while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4634 ref++; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4635 if( ctx < 4 ) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4636 ctx = 4; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4637 else |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4638 ctx = 5; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4639 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4640 return ref; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4641 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4642 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4643 static int decode_cabac_mb_mvd( H264Context *h, int list, int n, int l ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4644 int amvd = abs( h->mvd_cache[list][scan8[n] - 1][l] ) + |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4645 abs( h->mvd_cache[list][scan8[n] - 8][l] ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4646 int ctxbase = (l == 0) ? 40 : 47; |
2317 | 4647 int ctx, mvd; |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4648 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4649 if( amvd < 3 ) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4650 ctx = 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4651 else if( amvd > 32 ) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4652 ctx = 2; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4653 else |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4654 ctx = 1; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4655 |
2317 | 4656 if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+ctx])) |
4657 return 0; | |
4658 | |
4659 mvd= 1; | |
4660 ctx= 3; | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4661 while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase+ctx] ) ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4662 mvd++; |
2317 | 4663 if( ctx < 6 ) |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4664 ctx++; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4665 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4666 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4667 if( mvd >= 9 ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4668 int k = 3; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4669 while( get_cabac_bypass( &h->cabac ) ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4670 mvd += 1 << k; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4671 k++; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4672 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4673 while( k-- ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4674 if( get_cabac_bypass( &h->cabac ) ) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4675 mvd += 1 << k; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4676 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4677 } |
2317 | 4678 if( get_cabac_bypass( &h->cabac ) ) return -mvd; |
4679 else return mvd; | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4680 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4681 |
2316 | 4682 static int inline get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) { |
2314 | 4683 int nza, nzb; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4684 int ctx = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4685 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4686 if( cat == 0 ) { |
2314 | 4687 nza = h->left_cbp&0x100; |
4688 nzb = h-> top_cbp&0x100; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4689 } else if( cat == 1 || cat == 2 ) { |
2314 | 4690 nza = h->non_zero_count_cache[scan8[idx] - 1]; |
4691 nzb = h->non_zero_count_cache[scan8[idx] - 8]; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4692 } else if( cat == 3 ) { |
2314 | 4693 nza = (h->left_cbp>>(6+idx))&0x01; |
4694 nzb = (h-> top_cbp>>(6+idx))&0x01; | |
4695 } else { | |
4696 assert(cat == 4); | |
4697 nza = h->non_zero_count_cache[scan8[16+idx] - 1]; | |
4698 nzb = h->non_zero_count_cache[scan8[16+idx] - 8]; | |
4699 } | |
4700 | |
4701 if( nza > 0 ) | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4702 ctx++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4703 |
2314 | 4704 if( nzb > 0 ) |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4705 ctx += 2; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4706 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4707 return ctx + 4 * cat; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4708 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4709 |
2316 | 4710 static int inline decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int qp, int max_coeff) { |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4711 const int mb_xy = h->s.mb_x + h->s.mb_y*h->s.mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4712 const uint16_t *qmul= dequant_coeff[qp]; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4713 static const int significant_coeff_flag_offset[5] = { 0, 15, 29, 44, 47 }; |
2313 | 4714 static const int coeff_abs_level_m1_offset[5] = {227+ 0, 227+10, 227+20, 227+30, 227+39 }; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4715 |
2313 | 4716 int index[16]; |
4717 | |
4718 int i, last; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4719 int coeff_count = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4720 |
2316 | 4721 int abslevel1 = 1; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4722 int abslevelgt1 = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4723 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4724 /* cat: 0-> DC 16x16 n = 0 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4725 * 1-> AC 16x16 n = luma4x4idx |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4726 * 2-> Luma4x4 n = luma4x4idx |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4727 * 3-> DC Chroma n = iCbCr |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4728 * 4-> AC Chroma n = 4 * iCbCr + chroma4x4idx |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4729 */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4730 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4731 /* read coded block flag */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4732 if( get_cabac( &h->cabac, &h->cabac_state[85 + get_cabac_cbf_ctx( h, cat, n ) ] ) == 0 ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4733 if( cat == 1 || cat == 2 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4734 h->non_zero_count_cache[scan8[n]] = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4735 else if( cat == 4 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4736 h->non_zero_count_cache[scan8[16+n]] = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4737 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4738 return 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4739 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4740 |
2313 | 4741 for(last= 0; last < max_coeff - 1; last++) { |
4742 if( get_cabac( &h->cabac, &h->cabac_state[105+significant_coeff_flag_offset[cat]+last] )) { | |
4743 index[coeff_count++] = last; | |
4744 if( get_cabac( &h->cabac, &h->cabac_state[166+significant_coeff_flag_offset[cat]+last] ) ) { | |
4745 last= max_coeff; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4746 break; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4747 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4748 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4749 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4750 if( last == max_coeff -1 ) { |
2313 | 4751 index[coeff_count++] = last; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4752 } |
2316 | 4753 assert(coeff_count > 0); |
4754 | |
4755 if( cat == 0 ) | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4756 h->cbp_table[mb_xy] |= 0x100; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4757 else if( cat == 1 || cat == 2 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4758 h->non_zero_count_cache[scan8[n]] = coeff_count; |
2316 | 4759 else if( cat == 3 ) |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4760 h->cbp_table[mb_xy] |= 0x40 << n; |
2316 | 4761 else { |
4762 assert( cat == 4 ); | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4763 h->non_zero_count_cache[scan8[16+n]] = coeff_count; |
2316 | 4764 } |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4765 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4766 for( i = coeff_count - 1; i >= 0; i-- ) { |
2316 | 4767 int ctx = (abslevelgt1 != 0 ? 0 : FFMIN( 4, abslevel1 )) + coeff_abs_level_m1_offset[cat]; |
4768 int j= scantable[index[i]]; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4769 |
2313 | 4770 if( get_cabac( &h->cabac, &h->cabac_state[ctx] ) == 0 ) { |
2316 | 4771 if( cat == 0 || cat == 3 ) { |
4772 if( get_cabac_bypass( &h->cabac ) ) block[j] = -1; | |
4773 else block[j] = 1; | |
4774 }else{ | |
4775 if( get_cabac_bypass( &h->cabac ) ) block[j] = -qmul[j]; | |
4776 else block[j] = qmul[j]; | |
4777 } | |
2313 | 4778 |
4779 abslevel1++; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4780 } else { |
2313 | 4781 int coeff_abs = 2; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4782 ctx = 5 + FFMIN( 4, abslevelgt1 ) + coeff_abs_level_m1_offset[cat]; |
2313 | 4783 while( coeff_abs < 15 && get_cabac( &h->cabac, &h->cabac_state[ctx] ) ) { |
4784 coeff_abs++; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4785 } |
2313 | 4786 |
4787 if( coeff_abs >= 15 ) { | |
4788 int j = 0; | |
4789 while( get_cabac_bypass( &h->cabac ) ) { | |
4790 coeff_abs += 1 << j; | |
4791 j++; | |
4792 } | |
4793 | |
4794 while( j-- ) { | |
4795 if( get_cabac_bypass( &h->cabac ) ) | |
4796 coeff_abs += 1 << j ; | |
4797 } | |
4798 } | |
4799 | |
2316 | 4800 if( cat == 0 || cat == 3 ) { |
4801 if( get_cabac_bypass( &h->cabac ) ) block[j] = -coeff_abs; | |
4802 else block[j] = coeff_abs; | |
4803 }else{ | |
4804 if( get_cabac_bypass( &h->cabac ) ) block[j] = -coeff_abs * qmul[j]; | |
4805 else block[j] = coeff_abs * qmul[j]; | |
4806 } | |
2313 | 4807 |
4808 abslevelgt1++; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4809 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4810 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4811 return 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4812 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4813 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4814 /** |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4815 * decodes a macroblock |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4816 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4817 */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4818 static int decode_mb_cabac(H264Context *h) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4819 MpegEncContext * const s = &h->s; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4820 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4821 int mb_type, partition_count, cbp = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4822 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4823 s->dsp.clear_blocks(h->mb); //FIXME avoid if allready clear (move after skip handlong?) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4824 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4825 if( h->sps.mb_aff ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4826 av_log( h->s.avctx, AV_LOG_ERROR, "Fields not supported with CABAC\n" ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4827 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4828 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4829 |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
4830 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4831 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4832 /* read skip flags */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4833 if( decode_cabac_mb_skip( h ) ) { |
2396 | 4834 decode_mb_skip(h); |
4835 | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4836 h->cbp_table[mb_xy] = 0; |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4837 h->chroma_pred_mode_table[mb_xy] = 0; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4838 h->last_qscale_diff = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4839 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4840 return 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4841 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4842 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4843 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4844 h->prev_mb_skiped = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4845 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4846 if( ( mb_type = decode_cabac_mb_type( h ) ) < 0 ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4847 av_log( h->s.avctx, AV_LOG_ERROR, "decode_cabac_mb_type failed\n" ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4848 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4849 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4850 |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4851 if( h->slice_type == B_TYPE ) { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4852 if( mb_type < 23 ){ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4853 partition_count= b_mb_type_info[mb_type].partition_count; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4854 mb_type= b_mb_type_info[mb_type].type; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4855 }else{ |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4856 mb_type -= 23; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4857 goto decode_intra_mb; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4858 } |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4859 } else if( h->slice_type == P_TYPE ) { |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4860 if( mb_type < 5) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4861 partition_count= p_mb_type_info[mb_type].partition_count; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4862 mb_type= p_mb_type_info[mb_type].type; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4863 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4864 mb_type -= 5; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4865 goto decode_intra_mb; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4866 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4867 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4868 assert(h->slice_type == I_TYPE); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4869 decode_intra_mb: |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4870 partition_count = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4871 cbp= i_mb_type_info[mb_type].cbp; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4872 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4873 mb_type= i_mb_type_info[mb_type].type; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4874 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4875 #if 0 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4876 if(h->mb_field_decoding_flag) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4877 mb_type |= MB_TYPE_INTERLACED; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4878 #endif |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4879 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4880 s->current_picture.mb_type[mb_xy]= mb_type; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4881 h->slice_table[ mb_xy ]= h->slice_num; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4882 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4883 if(IS_INTRA_PCM(mb_type)) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4884 /* TODO */ |
2314 | 4885 assert(0); |
4886 h->cbp_table[mb_xy] = 0xf +4*2; //FIXME ?! | |
4887 h->cbp_table[mb_xy] |= 0x1C0; | |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
4888 h->chroma_pred_mode_table[mb_xy] = 0; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4889 s->current_picture.qscale_table[mb_xy]= s->qscale; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4890 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4891 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4892 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4893 fill_caches(h, mb_type); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4894 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4895 if( IS_INTRA( mb_type ) ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4896 if( IS_INTRA4x4( mb_type ) ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4897 int i; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4898 for( i = 0; i < 16; i++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4899 int pred = pred_intra_mode( h, i ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4900 h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4901 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4902 //av_log( s->avctx, AV_LOG_ERROR, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[ scan8[i] ] ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4903 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4904 write_back_intra_pred_mode(h); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4905 if( check_intra4x4_pred_mode(h) < 0 ) return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4906 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4907 h->intra16x16_pred_mode= check_intra_pred_mode( h, h->intra16x16_pred_mode ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4908 if( h->intra16x16_pred_mode < 0 ) return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4909 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4910 h->chroma_pred_mode_table[mb_xy] = |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4911 h->chroma_pred_mode = decode_cabac_mb_chroma_pre_mode( h ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4912 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4913 h->chroma_pred_mode= check_intra_pred_mode( h, h->chroma_pred_mode ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4914 if( h->chroma_pred_mode < 0 ) return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
4915 } else if( partition_count == 4 ) { |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4916 int i, j, sub_partition_count[4], list, ref[2][4]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4917 |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4918 if( h->slice_type == B_TYPE ) { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4919 for( i = 0; i < 4; i++ ) { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4920 h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h ); |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4921 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4922 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4923 } |
2396 | 4924 if( IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1]) |
4925 || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) { | |
4926 pred_direct_motion(h, &mb_type); | |
4927 if( h->ref_count[0] > 1 || h->ref_count[1] > 1 ) { | |
4928 for( i = 0; i < 4; i++ ) | |
4929 if( IS_DIRECT(h->sub_mb_type[i]) ) | |
4930 fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, 1, 1 ); | |
4931 } | |
4932 } | |
2310
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4933 } else { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4934 for( i = 0; i < 4; i++ ) { |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4935 h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h ); |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4936 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4937 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
c5cd8a064c34
H.264 CABAC + B-frames patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2284
diff
changeset
|
4938 } |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4939 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4940 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4941 for( list = 0; list < 2; list++ ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4942 if( h->ref_count[list] > 0 ) { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4943 for( i = 0; i < 4; i++ ) { |
2396 | 4944 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
4945 if(IS_DIR(h->sub_mb_type[i], 0, list)){ | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4946 if( h->ref_count[list] > 1 ) |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4947 ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4948 else |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4949 ref[list][i] = 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4950 } else { |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4951 ref[list][i] = -1; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4952 } |
2110 | 4953 h->ref_cache[list][ scan8[4*i]+1 ]= |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4954 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4955 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4956 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4957 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4958 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4959 for(list=0; list<2; list++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4960 for(i=0; i<4; i++){ |
2396 | 4961 if(IS_DIRECT(h->sub_mb_type[i])){ |
4962 fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4); | |
4963 continue; | |
4964 } | |
2110 | 4965 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]; |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4966 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4967 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4968 const int sub_mb_type= h->sub_mb_type[i]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4969 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4970 for(j=0; j<sub_partition_count[i]; j++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4971 int mpx, mpy; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4972 int mx, my; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4973 const int index= 4*i + block_width*j; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4974 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4975 int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4976 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mpx, &mpy); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4977 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4978 mx = mpx + decode_cabac_mb_mvd( h, list, index, 0 ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4979 my = mpy + decode_cabac_mb_mvd( h, list, index, 1 ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4980 tprintf("final mv:%d %d\n", mx, my); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4981 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4982 if(IS_SUB_8X8(sub_mb_type)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4983 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4984 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4985 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4986 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4987 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4988 mvd_cache[ 0 ][0]= mvd_cache[ 1 ][0]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4989 mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mx - mpx; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4990 mvd_cache[ 0 ][1]= mvd_cache[ 1 ][1]= |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4991 mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= my - mpy; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4992 }else if(IS_SUB_8X4(sub_mb_type)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4993 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mx; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4994 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= my; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4995 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4996 mvd_cache[ 0 ][0]= mvd_cache[ 1 ][0]= mx- mpx; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4997 mvd_cache[ 0 ][1]= mvd_cache[ 1 ][1]= my - mpy; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4998 }else if(IS_SUB_4X8(sub_mb_type)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
4999 mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mx; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5000 mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= my; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5001 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5002 mvd_cache[ 0 ][0]= mvd_cache[ 8 ][0]= mx - mpx; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5003 mvd_cache[ 0 ][1]= mvd_cache[ 8 ][1]= my - mpy; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5004 }else{ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5005 assert(IS_SUB_4X4(sub_mb_type)); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5006 mv_cache[ 0 ][0]= mx; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5007 mv_cache[ 0 ][1]= my; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5008 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5009 mvd_cache[ 0 ][0]= mx - mpx; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5010 mvd_cache[ 0 ][1]= my - mpy; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5011 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5012 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5013 }else{ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5014 uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5015 uint32_t *pd= (uint32_t *)&h->mvd_cache[list][ scan8[4*i] ][0]; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5016 p[0] = p[1] = p[8] = p[9] = 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5017 pd[0]= pd[1]= pd[8]= pd[9]= 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5018 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5019 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5020 } |
2396 | 5021 } else if( IS_DIRECT(mb_type) ) { |
5022 pred_direct_motion(h, &mb_type); | |
5023 s->current_picture.mb_type[mb_xy]= mb_type; | |
5024 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | |
5025 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); | |
5026 } else { | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5027 int list, mx, my, i, mpx, mpy; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5028 if(IS_16X16(mb_type)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5029 for(list=0; list<2; list++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5030 if(IS_DIR(mb_type, 0, list)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5031 if(h->ref_count[list] > 0 ){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5032 const int ref = h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 0 ) : 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5033 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5034 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5035 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5036 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5037 for(list=0; list<2; list++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5038 if(IS_DIR(mb_type, 0, list)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5039 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mpx, &mpy); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5040 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5041 mx = mpx + decode_cabac_mb_mvd( h, list, 0, 0 ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5042 my = mpy + decode_cabac_mb_mvd( h, list, 0, 1 ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5043 tprintf("final mv:%d %d\n", mx, my); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5044 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5045 fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx-mpx,my-mpy), 4); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5046 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5047 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5048 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5049 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5050 else if(IS_16X8(mb_type)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5051 for(list=0; list<2; list++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5052 if(h->ref_count[list]>0){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5053 for(i=0; i<2; i++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5054 if(IS_DIR(mb_type, i, list)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5055 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5056 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1); |
2396 | 5057 }else |
5058 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5059 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5060 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5061 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5062 for(list=0; list<2; list++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5063 for(i=0; i<2; i++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5064 if(IS_DIR(mb_type, i, list)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5065 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5066 mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5067 my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5068 tprintf("final mv:%d %d\n", mx, my); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5069 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5070 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx-mpx,my-mpy), 4); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5071 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); |
2396 | 5072 }else{ // needed only for mixed refs |
5073 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); | |
5074 fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5075 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5076 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5077 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5078 }else{ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5079 assert(IS_8X16(mb_type)); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5080 for(list=0; list<2; list++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5081 if(h->ref_count[list]>0){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5082 for(i=0; i<2; i++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5083 if(IS_DIR(mb_type, i, list)){ //FIXME optimize |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5084 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 0; |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5085 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1); |
2396 | 5086 }else |
5087 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5088 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5089 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5090 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5091 for(list=0; list<2; list++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5092 for(i=0; i<2; i++){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5093 if(IS_DIR(mb_type, i, list)){ |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5094 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5095 mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5096 my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 ); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5097 |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5098 tprintf("final mv:%d %d\n", mx, my); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5099 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx-mpx,my-mpy), 4); |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5100 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); |
2396 | 5101 }else{ // needed only for mixed refs |
5102 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); | |
5103 fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); | |
1935
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5104 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5105 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5106 } |
e935af90767b
progressive P frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1909
diff
changeset
|
5107 } |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5108 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5109 |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
5110 if( IS_INTER( mb_type ) ) { |
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
5111 h->chroma_pred_mode_table[mb_xy] = 0; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5112 write_back_motion( h, mb_type ); |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
5113 } |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5114 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5115 if( !IS_INTRA16x16( mb_type ) ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5116 cbp = decode_cabac_mb_cbp_luma( h ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5117 cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5118 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5119 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5120 h->cbp_table[mb_xy] = cbp; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5121 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5122 if( cbp || IS_INTRA16x16( mb_type ) ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5123 const uint8_t *scan, *dc_scan; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5124 int dqp; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5125 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5126 if(IS_INTERLACED(mb_type)){ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5127 scan= field_scan; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5128 dc_scan= luma_dc_field_scan; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5129 }else{ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5130 scan= zigzag_scan; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5131 dc_scan= luma_dc_zigzag_scan; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5132 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5133 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5134 h->last_qscale_diff = dqp = decode_cabac_mb_dqp( h ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5135 s->qscale += dqp; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5136 if(((unsigned)s->qscale) > 51){ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5137 if(s->qscale<0) s->qscale+= 52; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5138 else s->qscale-= 52; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5139 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5140 h->chroma_qp = get_chroma_qp(h, s->qscale); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5141 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5142 if( IS_INTRA16x16( mb_type ) ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5143 int i; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5144 //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5145 if( decode_cabac_residual( h, h->mb, 0, 0, dc_scan, s->qscale, 16) < 0) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5146 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5147 if( cbp&15 ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5148 for( i = 0; i < 16; i++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5149 //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5150 if( decode_cabac_residual(h, h->mb + 16*i, 1, i, scan + 1, s->qscale, 15) < 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5151 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5152 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5153 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5154 fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5155 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5156 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5157 int i8x8, i4x4; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5158 for( i8x8 = 0; i8x8 < 4; i8x8++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5159 if( cbp & (1<<i8x8) ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5160 for( i4x4 = 0; i4x4 < 4; i4x4++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5161 const int index = 4*i8x8 + i4x4; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5162 //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5163 if( decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, s->qscale, 16) < 0 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5164 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5165 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5166 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5167 uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5168 nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5169 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5170 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5171 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5172 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5173 if( cbp&0x30 ){ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5174 int c; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5175 for( c = 0; c < 2; c++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5176 //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5177 if( decode_cabac_residual(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, h->chroma_qp, 4) < 0) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5178 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5179 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5180 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5181 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5182 if( cbp&0x20 ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5183 int c, i; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5184 for( c = 0; c < 2; c++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5185 for( i = 0; i < 4; i++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5186 const int index = 16 + 4 * c + i; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5187 //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5188 if( decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, h->chroma_qp, 15) < 0) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5189 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5190 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5191 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5192 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5193 uint8_t * const nnz= &h->non_zero_count_cache[0]; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5194 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5195 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5196 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5197 } else { |
2315 | 5198 uint8_t * const nnz= &h->non_zero_count_cache[0]; |
5199 fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); | |
5200 nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = | |
5201 nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5202 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5203 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5204 s->current_picture.qscale_table[mb_xy]= s->qscale; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5205 write_back_non_zero_count(h); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5206 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5207 return 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5208 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5209 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5210 |
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
|
5211 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
|
5212 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
|
5213 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
|
5214 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
|
5215 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
|
5216 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5217 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
|
5218 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
|
5219 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
|
5220 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
|
5221 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5222 |
1898 | 5223 if( bS[i] < 4 ) { |
5224 const int tc0 = tc0_table[index_a][bS[i] - 1]; | |
5225 /* 4px edge length */ | |
5226 for( d = 0; d < 4; d++ ) { | |
5227 const int p0 = pix[-1]; | |
5228 const int p1 = pix[-2]; | |
5229 const int p2 = pix[-3]; | |
5230 const int q0 = pix[0]; | |
5231 const int q1 = pix[1]; | |
5232 const int q2 = pix[2]; | |
5233 | |
5234 if( ABS( p0 - q0 ) < alpha && | |
5235 ABS( p1 - p0 ) < beta && | |
5236 ABS( q1 - q0 ) < beta ) { | |
5237 int tc = tc0; | |
5238 int i_delta; | |
5239 | |
5240 if( ABS( p2 - p0 ) < beta ) { | |
5241 pix[-2] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); | |
5242 tc++; | |
5243 } | |
5244 if( ABS( q2 - q0 ) < beta ) { | |
5245 pix[1] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); | |
5246 tc++; | |
5247 } | |
5248 | |
5249 i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
5250 pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */ | |
5251 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
|
5252 } |
1898 | 5253 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
|
5254 } |
1898 | 5255 }else{ |
5256 /* 4px edge length */ | |
5257 for( d = 0; d < 4; d++ ) { | |
5258 const int p0 = pix[-1]; | |
5259 const int p1 = pix[-2]; | |
5260 const int p2 = pix[-3]; | |
5261 | |
5262 const int q0 = pix[0]; | |
5263 const int q1 = pix[1]; | |
5264 const int q2 = pix[2]; | |
5265 | |
5266 if( ABS( p0 - q0 ) < alpha && | |
5267 ABS( p1 - p0 ) < beta && | |
5268 ABS( q1 - q0 ) < beta ) { | |
5269 | |
5270 if(ABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ | |
5271 if( ABS( p2 - p0 ) < beta) | |
5272 { | |
5273 const int p3 = pix[-4]; | |
5274 /* p0', p1', p2' */ | |
5275 pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; | |
5276 pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; | |
5277 pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; | |
5278 } else { | |
5279 /* p0' */ | |
5280 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
5281 } | |
5282 if( ABS( q2 - q0 ) < beta) | |
5283 { | |
5284 const int q3 = pix[3]; | |
5285 /* q0', q1', q2' */ | |
5286 pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; | |
5287 pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; | |
5288 pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; | |
5289 } else { | |
5290 /* q0' */ | |
5291 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
5292 } | |
5293 }else{ | |
5294 /* p0', q0' */ | |
5295 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
5296 pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
5297 } | |
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
|
5298 } |
1898 | 5299 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
|
5300 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5301 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5302 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5303 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5304 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
|
5305 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
|
5306 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
|
5307 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
|
5308 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
|
5309 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5310 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
|
5311 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
|
5312 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
|
5313 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
|
5314 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5315 |
1898 | 5316 if( bS[i] < 4 ) { |
5317 const int tc = tc0_table[index_a][bS[i] - 1] + 1; | |
5318 /* 2px edge length (because we use same bS than the one for luma) */ | |
5319 for( d = 0; d < 2; d++ ){ | |
5320 const int p0 = pix[-1]; | |
5321 const int p1 = pix[-2]; | |
5322 const int q0 = pix[0]; | |
5323 const int q1 = pix[1]; | |
5324 | |
5325 if( ABS( p0 - q0 ) < alpha && | |
5326 ABS( p1 - p0 ) < beta && | |
5327 ABS( q1 - q0 ) < beta ) { | |
5328 const int i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
5329 | |
5330 pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */ | |
5331 pix[0] = clip_uint8( q0 - i_delta ); /* q0' */ | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
5332 //tprintf("filter_mb_edgecv i:%d d:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, qp, index_a, alpha, beta, tc, bS[i], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); |
1898 | 5333 } |
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
|
5334 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
|
5335 } |
1898 | 5336 }else{ |
5337 /* 2px edge length (because we use same bS than the one for luma) */ | |
5338 for( d = 0; d < 2; d++ ){ | |
5339 const int p0 = pix[-1]; | |
5340 const int p1 = pix[-2]; | |
5341 const int q0 = pix[0]; | |
5342 const int q1 = pix[1]; | |
5343 | |
5344 if( ABS( p0 - q0 ) < alpha && | |
5345 ABS( p1 - p0 ) < beta && | |
5346 ABS( q1 - q0 ) < beta ) { | |
5347 | |
5348 pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ | |
5349 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ | |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
5350 //tprintf("filter_mb_edgecv i:%d d:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, d, pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); |
1898 | 5351 } |
5352 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
|
5353 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5354 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5355 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5356 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5357 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5358 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
|
5359 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
|
5360 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
|
5361 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
|
5362 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
|
5363 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
|
5364 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5365 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
|
5366 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
|
5367 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
|
5368 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
|
5369 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5370 |
1898 | 5371 if( bS[i] < 4 ) { |
5372 const int tc0 = tc0_table[index_a][bS[i] - 1]; | |
5373 /* 4px edge length */ | |
5374 for( d = 0; d < 4; d++ ) { | |
5375 const int p0 = pix[-1*pix_next]; | |
5376 const int p1 = pix[-2*pix_next]; | |
5377 const int p2 = pix[-3*pix_next]; | |
5378 const int q0 = pix[0]; | |
5379 const int q1 = pix[1*pix_next]; | |
5380 const int q2 = pix[2*pix_next]; | |
5381 | |
5382 if( ABS( p0 - q0 ) < alpha && | |
5383 ABS( p1 - p0 ) < beta && | |
5384 ABS( q1 - q0 ) < beta ) { | |
5385 | |
5386 int tc = tc0; | |
5387 int i_delta; | |
5388 | |
5389 if( ABS( p2 - p0 ) < beta ) { | |
5390 pix[-2*pix_next] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); | |
5391 tc++; | |
5392 } | |
5393 if( ABS( q2 - q0 ) < beta ) { | |
5394 pix[pix_next] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); | |
5395 tc++; | |
5396 } | |
5397 | |
5398 i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
5399 pix[-pix_next] = clip_uint8( p0 + i_delta ); /* p0' */ | |
5400 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
|
5401 } |
1898 | 5402 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
|
5403 } |
1898 | 5404 }else{ |
5405 /* 4px edge length */ | |
5406 for( d = 0; d < 4; d++ ) { | |
5407 const int p0 = pix[-1*pix_next]; | |
5408 const int p1 = pix[-2*pix_next]; | |
5409 const int p2 = pix[-3*pix_next]; | |
5410 const int q0 = pix[0]; | |
5411 const int q1 = pix[1*pix_next]; | |
5412 const int q2 = pix[2*pix_next]; | |
5413 | |
5414 if( ABS( p0 - q0 ) < alpha && | |
5415 ABS( p1 - p0 ) < beta && | |
5416 ABS( q1 - q0 ) < beta ) { | |
5417 | |
5418 const int p3 = pix[-4*pix_next]; | |
5419 const int q3 = pix[ 3*pix_next]; | |
5420 | |
5421 if(ABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ | |
5422 if( ABS( p2 - p0 ) < beta) { | |
5423 /* p0', p1', p2' */ | |
5424 pix[-1*pix_next] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; | |
5425 pix[-2*pix_next] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; | |
5426 pix[-3*pix_next] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; | |
5427 } else { | |
5428 /* p0' */ | |
5429 pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
5430 } | |
5431 if( ABS( q2 - q0 ) < beta) { | |
5432 /* q0', q1', q2' */ | |
5433 pix[0*pix_next] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; | |
5434 pix[1*pix_next] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; | |
5435 pix[2*pix_next] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; | |
5436 } else { | |
5437 /* q0' */ | |
5438 pix[0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
5439 } | |
5440 }else{ | |
5441 /* p0', q0' */ | |
5442 pix[-1*pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | |
5443 pix[ 0*pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | |
5444 } | |
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
|
5445 } |
1898 | 5446 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
|
5447 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5448 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5449 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5450 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5451 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5452 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
|
5453 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
|
5454 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
|
5455 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
|
5456 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
|
5457 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
|
5458 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5459 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
|
5460 { |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5461 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
|
5462 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
|
5463 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
|
5464 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5465 |
1898 | 5466 if( bS[i] < 4 ) { |
5467 int tc = tc0_table[index_a][bS[i] - 1] + 1; | |
5468 /* 2px edge length (see deblocking_filter_edgecv) */ | |
5469 for( d = 0; d < 2; d++ ) { | |
5470 const int p0 = pix[-1*pix_next]; | |
5471 const int p1 = pix[-2*pix_next]; | |
5472 const int q0 = pix[0]; | |
5473 const int q1 = pix[1*pix_next]; | |
5474 | |
5475 if( ABS( p0 - q0 ) < alpha && | |
5476 ABS( p1 - p0 ) < beta && | |
5477 ABS( q1 - q0 ) < beta ) { | |
5478 | |
5479 int i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | |
5480 | |
5481 pix[-pix_next] = clip_uint8( p0 + i_delta ); /* p0' */ | |
5482 pix[0] = clip_uint8( q0 - i_delta ); /* q0' */ | |
5483 } | |
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
|
5484 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
|
5485 } |
1898 | 5486 }else{ |
5487 /* 2px edge length (see deblocking_filter_edgecv) */ | |
5488 for( d = 0; d < 2; d++ ) { | |
5489 const int p0 = pix[-1*pix_next]; | |
5490 const int p1 = pix[-2*pix_next]; | |
5491 const int q0 = pix[0]; | |
5492 const int q1 = pix[1*pix_next]; | |
5493 | |
5494 if( ABS( p0 - q0 ) < alpha && | |
5495 ABS( p1 - p0 ) < beta && | |
5496 ABS( q1 - q0 ) < beta ) { | |
5497 | |
5498 pix[-pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ | |
5499 pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ | |
5500 } | |
5501 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
|
5502 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5503 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5504 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5505 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5506 |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5507 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
|
5508 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
|
5509 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
|
5510 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
|
5511 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
|
5512 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5513 /* 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
|
5514 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
|
5515 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
|
5516 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5517 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
|
5518 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
|
5519 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5520 /* 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
|
5521 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
|
5522 { |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5523 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
|
5524 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
|
5525 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5526 /* 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
|
5527 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
|
5528 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
|
5529 } |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5530 if( 0 == start && 2 == h->deblocking_filter) { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5531 const int mbn_xy = dir == 0 ? mb_xy -1 : mb_xy - s->mb_stride; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5532 if (h->slice_table[mbn_xy] != h->slice_table[mb_xy]) { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5533 start = 1; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5534 } |
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5535 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5536 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5537 /* 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
|
5538 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
|
5539 /* 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
|
5540 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
|
5541 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
|
5542 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
|
5543 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5544 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
|
5545 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
|
5546 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
|
5547 } 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
|
5548 int i; |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5549 const int slice_boundary = (h->slice_table[mbn_xy] != h->slice_table[mb_xy]); |
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5550 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
|
5551 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
|
5552 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
|
5553 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
|
5554 int bn_idx= b_idx - (dir ? 8:1); |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5555 uint8_t left_non_zero_count; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5556 if (slice_boundary) { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5557 // must not use non_zero_count_cache, it is not valid |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5558 // across slice boundaries |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5559 if (0 == dir) { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5560 left_non_zero_count = h->non_zero_count[mbn_xy][6-i]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5561 } else { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5562 left_non_zero_count = h->non_zero_count[mbn_xy][i]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5563 } |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5564 } else { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5565 left_non_zero_count = h->non_zero_count_cache[bn_idx]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5566 } |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5567 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5568 if( h->non_zero_count_cache[b_idx] != 0 || |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5569 left_non_zero_count != 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
|
5570 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
|
5571 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5572 else if( h->slice_type == P_TYPE ) { |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5573 int16_t left_mv[2]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5574 int8_t left_ref; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5575 if (slice_boundary) { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5576 // must not use ref_cache and mv_cache, they are not |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5577 // valid across slice boundaries |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5578 if (dir == 0) { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5579 left_ref = s->current_picture.ref_index[0][h->mb2b8_xy[mbn_xy] + (i>>1) * h->b8_stride + 1]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5580 *(uint32_t*)left_mv = *(uint32_t*)s->current_picture.motion_val[0][h->mb2b_xy[mbn_xy]+i*h->b_stride+3]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5581 } else { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5582 left_ref = s->current_picture.ref_index[0][h->mb2b8_xy[mbn_xy] + (i>>1) + h->b8_stride]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5583 *(uint32_t*)left_mv = *(uint32_t*)s->current_picture.motion_val[0][h->mb2b_xy[mbn_xy]+3*h->b_stride+i]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5584 } |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5585 } else { |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5586 left_ref = h->ref_cache[0][bn_idx]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5587 *(uint32_t*)left_mv = *(uint32_t*)h->mv_cache[0][bn_idx]; |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5588 } |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5589 if( h->ref_cache[0][b_idx] != left_ref || |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5590 ABS( h->mv_cache[0][b_idx][0] - left_mv[0] ) >= 4 || |
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
5591 ABS( h->mv_cache[0][b_idx][1] - left_mv[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
|
5592 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
|
5593 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
|
5594 bS[i] = 0; |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
5595 } else { |
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
|
5596 /* 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
|
5597 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
|
5598 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5599 } |
1899
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5600 |
379a18a7131f
do loop filter immediatly after each macroblock is decoded instead of after a frame is decoded
michael
parents:
1898
diff
changeset
|
5601 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
|
5602 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
|
5603 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5604 |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5605 /* 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
|
5606 qp = ( s->qscale + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
5607 //tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]); |
1897
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5608 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
|
5609 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); |
1898 | 5610 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
|
5611 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
|
5612 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
|
5613 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
|
5614 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
|
5615 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5616 } 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
|
5617 filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp ); |
1898 | 5618 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
|
5619 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
|
5620 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
|
5621 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
|
5622 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
|
5623 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5624 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5625 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5626 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5627 } |
4e8ed93524f6
h264 loop filter for progressive I&P frames by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1892
diff
changeset
|
5628 |
1168 | 5629 static int decode_slice(H264Context *h){ |
5630 MpegEncContext * const s = &h->s; | |
5631 const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F; | |
5632 | |
5633 s->mb_skip_run= -1; | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5634 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5635 if( h->pps.cabac ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5636 int i; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5637 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5638 /* realign */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5639 align_get_bits( &s->gb ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5640 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5641 /* init cabac */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5642 ff_init_cabac_states( &h->cabac, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64 ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5643 ff_init_cabac_decoder( &h->cabac, |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5644 s->gb.buffer + get_bits_count(&s->gb)/8, |
2116 | 5645 ( s->gb.size_in_bits - get_bits_count(&s->gb) + 7)/8); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5646 /* calculate pre-state */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5647 for( i= 0; i < 399; i++ ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5648 int pre; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5649 if( h->slice_type == I_TYPE ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5650 pre = clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5651 else |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5652 pre = clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5653 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5654 if( pre <= 63 ) |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5655 h->cabac_state[i] = 2 * ( 63 - pre ) + 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5656 else |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5657 h->cabac_state[i] = 2 * ( pre - 64 ) + 1; |
1168 | 5658 } |
5659 | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5660 for(;;){ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5661 int ret = decode_mb_cabac(h); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5662 int eos = get_cabac_terminate( &h->cabac ); /* End of Slice flag */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5663 |
2163 | 5664 if(ret>=0) hl_decode_mb(h); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5665 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5666 /* XXX: useless as decode_mb_cabac it doesn't support that ... */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5667 if( ret >= 0 && h->sps.mb_aff ) { //FIXME optimal? or let mb_decode decode 16x32 ? |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5668 s->mb_y++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5669 |
2163 | 5670 if(ret>=0) ret = decode_mb_cabac(h); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5671 eos = get_cabac_terminate( &h->cabac ); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5672 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5673 hl_decode_mb(h); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5674 s->mb_y--; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5675 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5676 |
2116 | 5677 if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 1) { |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5678 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5679 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5680 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5681 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5682 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5683 if( ++s->mb_x >= s->mb_width ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5684 s->mb_x = 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5685 ff_draw_horiz_band(s, 16*s->mb_y, 16); |
2392 | 5686 ++s->mb_y; |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5687 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5688 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5689 if( eos || s->mb_y >= s->mb_height ) { |
2392 | 5690 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5691 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5692 return 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5693 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5694 #if 0 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5695 /* TODO test over-reading in cabac code */ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5696 else if( read too much in h->cabac ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5697 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5698 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5699 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5700 #endif |
1168 | 5701 } |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5702 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5703 } else { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5704 for(;;){ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5705 int ret = decode_mb_cavlc(h); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5706 |
2163 | 5707 if(ret>=0) hl_decode_mb(h); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5708 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5709 if(ret>=0 && h->sps.mb_aff){ //FIXME optimal? or let mb_decode decode 16x32 ? |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5710 s->mb_y++; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5711 ret = decode_mb_cavlc(h); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5712 |
2163 | 5713 if(ret>=0) hl_decode_mb(h); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5714 s->mb_y--; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5715 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5716 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5717 if(ret<0){ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5718 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5719 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5720 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5721 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5722 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5723 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5724 if(++s->mb_x >= s->mb_width){ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5725 s->mb_x=0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5726 ff_draw_horiz_band(s, 16*s->mb_y, 16); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5727 if(++s->mb_y >= s->mb_height){ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5728 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5729 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5730 if(get_bits_count(&s->gb) == s->gb.size_in_bits ) { |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5731 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5732 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5733 return 0; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5734 }else{ |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5735 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5736 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5737 return -1; |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5738 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5739 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5740 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5741 |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5742 if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){ |
2392 | 5743 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5744 if(get_bits_count(&s->gb) == s->gb.size_in_bits ){ |
1168 | 5745 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); |
5746 | |
5747 return 0; | |
5748 }else{ | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5749 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); |
1168 | 5750 |
5751 return -1; | |
5752 } | |
5753 } | |
5754 } | |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5755 } |
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
5756 |
1168 | 5757 #if 0 |
5758 for(;s->mb_y < s->mb_height; s->mb_y++){ | |
5759 for(;s->mb_x < s->mb_width; s->mb_x++){ | |
5760 int ret= decode_mb(h); | |
5761 | |
5762 hl_decode_mb(h); | |
5763 | |
5764 if(ret<0){ | |
5765 fprintf(stderr, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); | |
5766 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); | |
5767 | |
5768 return -1; | |
5769 } | |
5770 | |
5771 if(++s->mb_x >= s->mb_width){ | |
5772 s->mb_x=0; | |
5773 if(++s->mb_y >= s->mb_height){ | |
5774 if(get_bits_count(s->gb) == s->gb.size_in_bits){ | |
5775 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); | |
5776 | |
5777 return 0; | |
5778 }else{ | |
5779 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); | |
5780 | |
5781 return -1; | |
5782 } | |
5783 } | |
5784 } | |
5785 | |
5786 if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){ | |
5787 if(get_bits_count(s->gb) == s->gb.size_in_bits){ | |
5788 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); | |
5789 | |
5790 return 0; | |
5791 }else{ | |
5792 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); | |
5793 | |
5794 return -1; | |
5795 } | |
5796 } | |
5797 } | |
5798 s->mb_x=0; | |
5799 ff_draw_horiz_band(s, 16*s->mb_y, 16); | |
5800 } | |
5801 #endif | |
5802 return -1; //not reached | |
5803 } | |
5804 | |
5805 static inline int decode_vui_parameters(H264Context *h, SPS *sps){ | |
5806 MpegEncContext * const s = &h->s; | |
5807 int aspect_ratio_info_present_flag, aspect_ratio_idc; | |
5808 | |
5809 aspect_ratio_info_present_flag= get_bits1(&s->gb); | |
5810 | |
5811 if( aspect_ratio_info_present_flag ) { | |
5812 aspect_ratio_idc= get_bits(&s->gb, 8); | |
5813 if( aspect_ratio_idc == EXTENDED_SAR ) { | |
1548 | 5814 sps->sar.num= get_bits(&s->gb, 16); |
5815 sps->sar.den= get_bits(&s->gb, 16); | |
1168 | 5816 }else if(aspect_ratio_idc < 16){ |
1548 | 5817 sps->sar= pixel_aspect[aspect_ratio_idc]; |
1168 | 5818 }else{ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
5819 av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); |
1168 | 5820 return -1; |
5821 } | |
5822 }else{ | |
1548 | 5823 sps->sar.num= |
5824 sps->sar.den= 0; | |
1168 | 5825 } |
5826 // s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height); | |
2174
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5827 |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5828 if(get_bits1(&s->gb)){ /* overscan_info_present_flag */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5829 get_bits1(&s->gb); /* overscan_appropriate_flag */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5830 } |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5831 |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5832 if(get_bits1(&s->gb)){ /* video_signal_type_present_flag */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5833 get_bits(&s->gb, 3); /* video_format */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5834 get_bits1(&s->gb); /* video_full_range_flag */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5835 if(get_bits1(&s->gb)){ /* colour_description_present_flag */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5836 get_bits(&s->gb, 8); /* colour_primaries */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5837 get_bits(&s->gb, 8); /* transfer_characteristics */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5838 get_bits(&s->gb, 8); /* matrix_coefficients */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5839 } |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5840 } |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5841 |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5842 if(get_bits1(&s->gb)){ /* chroma_location_info_present_flag */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5843 get_ue_golomb(&s->gb); /* chroma_sample_location_type_top_field */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5844 get_ue_golomb(&s->gb); /* chroma_sample_location_type_bottom_field */ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5845 } |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5846 |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5847 sps->timing_info_present_flag = get_bits1(&s->gb); |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5848 if(sps->timing_info_present_flag){ |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5849 sps->num_units_in_tick = get_bits_long(&s->gb, 32); |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5850 sps->time_scale = get_bits_long(&s->gb, 32); |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5851 sps->fixed_frame_rate_flag = get_bits1(&s->gb); |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5852 } |
6d614374d907
Get H.264 frame rate from SPS/VUI patch by (Mns Rullgrd <mru at kth dot se>)
michael
parents:
2163
diff
changeset
|
5853 |
1168 | 5854 #if 0 |
5855 | nal_hrd_parameters_present_flag |0 |u(1) | | |
5856 | if( nal_hrd_parameters_present_flag = = 1) | | | | |
5857 | hrd_parameters( ) | | | | |
5858 | vcl_hrd_parameters_present_flag |0 |u(1) | | |
5859 | if( vcl_hrd_parameters_present_flag = = 1) | | | | |
5860 | hrd_parameters( ) | | | | |
5861 | if( ( nal_hrd_parameters_present_flag = = 1 | || | | | |
5862 | | | | | |
5863 |( vcl_hrd_parameters_present_flag = = 1 ) ) | | | | |
5864 | low_delay_hrd_flag |0 |u(1) | | |
5865 | bitstream_restriction_flag |0 |u(1) | | |
5866 | if( bitstream_restriction_flag ) { |0 |u(1) | | |
5867 | motion_vectors_over_pic_boundaries_flag |0 |u(1) | | |
5868 | max_bytes_per_pic_denom |0 |ue(v) | | |
5869 | max_bits_per_mb_denom |0 |ue(v) | | |
5870 | log2_max_mv_length_horizontal |0 |ue(v) | | |
5871 | log2_max_mv_length_vertical |0 |ue(v) | | |
5872 | num_reorder_frames |0 |ue(v) | | |
5873 | max_dec_frame_buffering |0 |ue(v) | | |
5874 | } | | | | |
5875 |} | | | | |
5876 #endif | |
5877 return 0; | |
5878 } | |
5879 | |
5880 static inline int decode_seq_parameter_set(H264Context *h){ | |
5881 MpegEncContext * const s = &h->s; | |
1371 | 5882 int profile_idc, level_idc; |
1168 | 5883 int sps_id, i; |
5884 SPS *sps; | |
5885 | |
5886 profile_idc= get_bits(&s->gb, 8); | |
1371 | 5887 get_bits1(&s->gb); //constraint_set0_flag |
5888 get_bits1(&s->gb); //constraint_set1_flag | |
5889 get_bits1(&s->gb); //constraint_set2_flag | |
2312 | 5890 get_bits1(&s->gb); //constraint_set3_flag |
5891 get_bits(&s->gb, 4); // reserved | |
1168 | 5892 level_idc= get_bits(&s->gb, 8); |
5893 sps_id= get_ue_golomb(&s->gb); | |
5894 | |
5895 sps= &h->sps_buffer[ sps_id ]; | |
5896 sps->profile_idc= profile_idc; | |
5897 sps->level_idc= level_idc; | |
2312 | 5898 |
1168 | 5899 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; |
5900 sps->poc_type= get_ue_golomb(&s->gb); | |
5901 | |
5902 if(sps->poc_type == 0){ //FIXME #define | |
5903 sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4; | |
5904 } else if(sps->poc_type == 1){//FIXME #define | |
5905 sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); | |
5906 sps->offset_for_non_ref_pic= get_se_golomb(&s->gb); | |
5907 sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb); | |
5908 sps->poc_cycle_length= get_ue_golomb(&s->gb); | |
5909 | |
5910 for(i=0; i<sps->poc_cycle_length; i++) | |
5911 sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); | |
5912 } | |
5913 if(sps->poc_type > 2){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
5914 av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); |
1168 | 5915 return -1; |
5916 } | |
5917 | |
5918 sps->ref_frame_count= get_ue_golomb(&s->gb); | |
2254
0dfe4e32b19c
H.264 max reference pictures fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2227
diff
changeset
|
5919 if(sps->ref_frame_count > MAX_PICTURE_COUNT-2){ |
0dfe4e32b19c
H.264 max reference pictures fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2227
diff
changeset
|
5920 av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); |
0dfe4e32b19c
H.264 max reference pictures fix by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2227
diff
changeset
|
5921 } |
1371 | 5922 sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); |
1168 | 5923 sps->mb_width= get_ue_golomb(&s->gb) + 1; |
5924 sps->mb_height= get_ue_golomb(&s->gb) + 1; | |
2422 | 5925 if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 || |
5926 avcodec_check_dimensions(NULL, 16*sps->mb_width, 16*sps->mb_height)) | |
5927 return -1; | |
5928 | |
1168 | 5929 sps->frame_mbs_only_flag= get_bits1(&s->gb); |
5930 if(!sps->frame_mbs_only_flag) | |
5931 sps->mb_aff= get_bits1(&s->gb); | |
5932 else | |
5933 sps->mb_aff= 0; | |
5934 | |
5935 sps->direct_8x8_inference_flag= get_bits1(&s->gb); | |
5936 | |
1371 | 5937 sps->crop= get_bits1(&s->gb); |
5938 if(sps->crop){ | |
5939 sps->crop_left = get_ue_golomb(&s->gb); | |
5940 sps->crop_right = get_ue_golomb(&s->gb); | |
5941 sps->crop_top = get_ue_golomb(&s->gb); | |
5942 sps->crop_bottom= get_ue_golomb(&s->gb); | |
5943 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
|
5944 av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completly supported, this could look slightly wrong ...\n"); |
1371 | 5945 } |
5946 }else{ | |
5947 sps->crop_left = | |
5948 sps->crop_right = | |
5949 sps->crop_top = | |
5950 sps->crop_bottom= 0; | |
5951 } | |
5952 | |
1168 | 5953 sps->vui_parameters_present_flag= get_bits1(&s->gb); |
5954 if( sps->vui_parameters_present_flag ) | |
5955 decode_vui_parameters(h, sps); | |
5956 | |
5957 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
|
5958 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 | 5959 sps_id, sps->profile_idc, sps->level_idc, |
5960 sps->poc_type, | |
5961 sps->ref_frame_count, | |
5962 sps->mb_width, sps->mb_height, | |
5963 sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"), | |
5964 sps->direct_8x8_inference_flag ? "8B8" : "", | |
1371 | 5965 sps->crop_left, sps->crop_right, |
5966 sps->crop_top, sps->crop_bottom, | |
1168 | 5967 sps->vui_parameters_present_flag ? "VUI" : "" |
5968 ); | |
5969 } | |
5970 return 0; | |
5971 } | |
5972 | |
5973 static inline int decode_picture_parameter_set(H264Context *h){ | |
5974 MpegEncContext * const s = &h->s; | |
5975 int pps_id= get_ue_golomb(&s->gb); | |
5976 PPS *pps= &h->pps_buffer[pps_id]; | |
5977 | |
5978 pps->sps_id= get_ue_golomb(&s->gb); | |
5979 pps->cabac= get_bits1(&s->gb); | |
5980 pps->pic_order_present= get_bits1(&s->gb); | |
5981 pps->slice_group_count= get_ue_golomb(&s->gb) + 1; | |
5982 if(pps->slice_group_count > 1 ){ | |
5983 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
|
5984 av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); |
1168 | 5985 switch(pps->mb_slice_group_map_type){ |
5986 case 0: | |
5987 #if 0 | |
5988 | for( i = 0; i <= num_slice_groups_minus1; i++ ) | | | | |
5989 | run_length[ i ] |1 |ue(v) | | |
5990 #endif | |
5991 break; | |
5992 case 2: | |
5993 #if 0 | |
5994 | for( i = 0; i < num_slice_groups_minus1; i++ ) | | | | |
5995 |{ | | | | |
5996 | top_left_mb[ i ] |1 |ue(v) | | |
5997 | bottom_right_mb[ i ] |1 |ue(v) | | |
5998 | } | | | | |
5999 #endif | |
6000 break; | |
6001 case 3: | |
6002 case 4: | |
6003 case 5: | |
6004 #if 0 | |
6005 | slice_group_change_direction_flag |1 |u(1) | | |
6006 | slice_group_change_rate_minus1 |1 |ue(v) | | |
6007 #endif | |
6008 break; | |
6009 case 6: | |
6010 #if 0 | |
6011 | slice_group_id_cnt_minus1 |1 |ue(v) | | |
6012 | for( i = 0; i <= slice_group_id_cnt_minus1; i++ | | | | |
6013 |) | | | | |
6014 | slice_group_id[ i ] |1 |u(v) | | |
6015 #endif | |
1214 | 6016 break; |
1168 | 6017 } |
6018 } | |
6019 pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; | |
6020 pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; | |
6021 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
|
6022 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); |
1168 | 6023 return -1; |
6024 } | |
6025 | |
6026 pps->weighted_pred= get_bits1(&s->gb); | |
6027 pps->weighted_bipred_idc= get_bits(&s->gb, 2); | |
6028 pps->init_qp= get_se_golomb(&s->gb) + 26; | |
6029 pps->init_qs= get_se_golomb(&s->gb) + 26; | |
6030 pps->chroma_qp_index_offset= get_se_golomb(&s->gb); | |
6031 pps->deblocking_filter_parameters_present= get_bits1(&s->gb); | |
6032 pps->constrained_intra_pred= get_bits1(&s->gb); | |
6033 pps->redundant_pic_cnt_present = get_bits1(&s->gb); | |
6034 | |
6035 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
|
6036 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 | 6037 pps_id, pps->sps_id, |
6038 pps->cabac ? "CABAC" : "CAVLC", | |
6039 pps->slice_group_count, | |
6040 pps->ref_count[0], pps->ref_count[1], | |
6041 pps->weighted_pred ? "weighted" : "", | |
6042 pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset, | |
6043 pps->deblocking_filter_parameters_present ? "LPAR" : "", | |
6044 pps->constrained_intra_pred ? "CONSTR" : "", | |
1371 | 6045 pps->redundant_pic_cnt_present ? "REDU" : "" |
1168 | 6046 ); |
6047 } | |
6048 | |
6049 return 0; | |
6050 } | |
6051 | |
6052 /** | |
6053 * finds the end of the current frame in the bitstream. | |
6054 * @return the position of the first byte of the next frame, or -1 | |
6055 */ | |
2392 | 6056 static int find_frame_end(H264Context *h, const uint8_t *buf, int buf_size){ |
1187 | 6057 int i; |
1168 | 6058 uint32_t state; |
2392 | 6059 ParseContext *pc = &(h->s.parse_context); |
1168 | 6060 //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); |
6061 // mb_addr= pc->mb_addr - 1; | |
6062 state= pc->state; | |
2392 | 6063 for(i=0; i<=buf_size; i++){ |
1168 | 6064 if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){ |
2392 | 6065 tprintf("find_frame_end new startcode = %08x, frame_start_found = %d, pos = %d\n", state, pc->frame_start_found, i); |
1168 | 6066 if(pc->frame_start_found){ |
2392 | 6067 // If there isn't one more byte in the buffer |
6068 // the test on first_mb_in_slice cannot be done yet | |
6069 // do it at next call. | |
6070 if (i >= buf_size) break; | |
6071 if (buf[i] & 0x80) { | |
6072 // first_mb_in_slice is 0, probably the first nal of a new | |
6073 // slice | |
6074 tprintf("find_frame_end frame_end_found, state = %08x, pos = %d\n", state, i); | |
6075 pc->state=-1; | |
6076 pc->frame_start_found= 0; | |
6077 return i-4; | |
6078 } | |
1168 | 6079 } |
2392 | 6080 pc->frame_start_found = 1; |
1168 | 6081 } |
2392 | 6082 if (i<buf_size) |
6083 state= (state<<8) | buf[i]; | |
1168 | 6084 } |
6085 | |
6086 pc->state= state; | |
1219 | 6087 return END_NOT_FOUND; |
1168 | 6088 } |
6089 | |
1988 | 6090 static int h264_parse(AVCodecParserContext *s, |
6091 AVCodecContext *avctx, | |
6092 uint8_t **poutbuf, int *poutbuf_size, | |
6093 const uint8_t *buf, int buf_size) | |
6094 { | |
2392 | 6095 H264Context *h = s->priv_data; |
6096 ParseContext *pc = &h->s.parse_context; | |
1988 | 6097 int next; |
6098 | |
2392 | 6099 next= find_frame_end(h, buf, buf_size); |
1988 | 6100 |
6101 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { | |
6102 *poutbuf = NULL; | |
6103 *poutbuf_size = 0; | |
6104 return buf_size; | |
6105 } | |
6106 | |
6107 *poutbuf = (uint8_t *)buf; | |
6108 *poutbuf_size = buf_size; | |
6109 return next; | |
6110 } | |
6111 | |
1168 | 6112 static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ |
6113 MpegEncContext * const s = &h->s; | |
6114 AVCodecContext * const avctx= s->avctx; | |
6115 int buf_index=0; | |
1322 | 6116 #if 0 |
1168 | 6117 int i; |
6118 for(i=0; i<32; i++){ | |
6119 printf("%X ", buf[i]); | |
6120 } | |
6121 #endif | |
2392 | 6122 h->slice_num = 0; |
1168 | 6123 for(;;){ |
6124 int consumed; | |
6125 int dst_length; | |
6126 int bit_length; | |
6127 uint8_t *ptr; | |
2227 | 6128 int i, nalsize = 0; |
1168 | 6129 |
2227 | 6130 if(h->is_avc) { |
6131 if(buf_index >= buf_size) break; | |
6132 nalsize = 0; | |
6133 for(i = 0; i < h->nal_length_size; i++) | |
6134 nalsize = (nalsize << 8) | buf[buf_index++]; | |
6135 } else { | |
1168 | 6136 // start code prefix search |
6137 for(; buf_index + 3 < buf_size; buf_index++){ | |
6138 // this should allways succeed in the first iteration | |
6139 if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1) | |
6140 break; | |
6141 } | |
6142 | |
6143 if(buf_index+3 >= buf_size) break; | |
6144 | |
6145 buf_index+=3; | |
2227 | 6146 } |
1168 | 6147 |
2401
46898a9fd6dc
Fix avc1 if there is nore than one nal per mov frame
rtognimp
parents:
2396
diff
changeset
|
6148 ptr= decode_nal(h, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index); |
1168 | 6149 if(ptr[dst_length - 1] == 0) dst_length--; |
6150 bit_length= 8*dst_length - decode_rbsp_trailing(ptr + dst_length - 1); | |
6151 | |
6152 if(s->avctx->debug&FF_DEBUG_STARTCODE){ | |
2402
f9d4e1eddbc5
- correct several errors on the deblocking accross slice boundaries.
michael
parents:
2401
diff
changeset
|
6153 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", h->nal_unit_type, buf_index, buf_size, dst_length); |
1168 | 6154 } |
6155 | |
2227 | 6156 if (h->is_avc && (nalsize != consumed)) |
6157 av_log(h->s.avctx, AV_LOG_ERROR, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize); | |
6158 | |
1168 | 6159 buf_index += consumed; |
6160 | |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
6161 if( s->hurry_up == 1 && h->nal_ref_idc == 0 ) |
1168 | 6162 continue; |
6163 | |
6164 switch(h->nal_unit_type){ | |
6165 case NAL_IDR_SLICE: | |
6166 idr(h); //FIXME ensure we dont loose some frames if there is reordering | |
6167 case NAL_SLICE: | |
6168 init_get_bits(&s->gb, ptr, bit_length); | |
6169 h->intra_gb_ptr= | |
6170 h->inter_gb_ptr= &s->gb; | |
6171 s->data_partitioning = 0; | |
6172 | |
6173 if(decode_slice_header(h) < 0) return -1; | |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
6174 if(h->redundant_pic_count==0 && s->hurry_up < 5 ) |
1168 | 6175 decode_slice(h); |
6176 break; | |
6177 case NAL_DPA: | |
6178 init_get_bits(&s->gb, ptr, bit_length); | |
6179 h->intra_gb_ptr= | |
6180 h->inter_gb_ptr= NULL; | |
6181 s->data_partitioning = 1; | |
6182 | |
6183 if(decode_slice_header(h) < 0) return -1; | |
6184 break; | |
6185 case NAL_DPB: | |
6186 init_get_bits(&h->intra_gb, ptr, bit_length); | |
6187 h->intra_gb_ptr= &h->intra_gb; | |
6188 break; | |
6189 case NAL_DPC: | |
6190 init_get_bits(&h->inter_gb, ptr, bit_length); | |
6191 h->inter_gb_ptr= &h->inter_gb; | |
1174 | 6192 |
1956
0eb2947f56f6
h264 hurry up fix and a tiny cabac clean patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1935
diff
changeset
|
6193 if(h->redundant_pic_count==0 && h->intra_gb_ptr && s->data_partitioning && s->hurry_up < 5 ) |
1168 | 6194 decode_slice(h); |
6195 break; | |
6196 case NAL_SEI: | |
6197 break; | |
6198 case NAL_SPS: | |
6199 init_get_bits(&s->gb, ptr, bit_length); | |
6200 decode_seq_parameter_set(h); | |
6201 | |
6202 if(s->flags& CODEC_FLAG_LOW_DELAY) | |
6203 s->low_delay=1; | |
6204 | |
6205 avctx->has_b_frames= !s->low_delay; | |
6206 break; | |
6207 case NAL_PPS: | |
6208 init_get_bits(&s->gb, ptr, bit_length); | |
6209 | |
6210 decode_picture_parameter_set(h); | |
6211 | |
6212 break; | |
6213 case NAL_PICTURE_DELIMITER: | |
6214 break; | |
6215 case NAL_FILTER_DATA: | |
6216 break; | |
2099 | 6217 default: |
6218 av_log(avctx, AV_LOG_ERROR, "Unknown NAL code: %d\n", h->nal_unit_type); | |
1168 | 6219 } |
6220 | |
6221 //FIXME move after where irt is set | |
6222 s->current_picture.pict_type= s->pict_type; | |
6223 s->current_picture.key_frame= s->pict_type == I_TYPE; | |
6224 } | |
6225 | |
1174 | 6226 if(!s->current_picture_ptr) return buf_index; //no frame |
6227 | |
1168 | 6228 h->prev_frame_num_offset= h->frame_num_offset; |
6229 h->prev_frame_num= h->frame_num; | |
6230 if(s->current_picture_ptr->reference){ | |
6231 h->prev_poc_msb= h->poc_msb; | |
6232 h->prev_poc_lsb= h->poc_lsb; | |
6233 } | |
6234 if(s->current_picture_ptr->reference) | |
6235 execute_ref_pic_marking(h, h->mmco, h->mmco_index); | |
6236 | |
6237 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
|
6238 |
1168 | 6239 MPV_frame_end(s); |
6240 | |
6241 return buf_index; | |
6242 } | |
6243 | |
6244 /** | |
6245 * retunrs the number of bytes consumed for building the current frame | |
6246 */ | |
6247 static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){ | |
6248 if(s->flags&CODEC_FLAG_TRUNCATED){ | |
6249 pos -= s->parse_context.last_index; | |
6250 if(pos<0) pos=0; // FIXME remove (uneeded?) | |
6251 | |
6252 return pos; | |
6253 }else{ | |
6254 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) | |
6255 if(pos+10>buf_size) pos=buf_size; // oops ;) | |
6256 | |
6257 return pos; | |
6258 } | |
6259 } | |
6260 | |
6261 static int decode_frame(AVCodecContext *avctx, | |
6262 void *data, int *data_size, | |
6263 uint8_t *buf, int buf_size) | |
6264 { | |
6265 H264Context *h = avctx->priv_data; | |
6266 MpegEncContext *s = &h->s; | |
6267 AVFrame *pict = data; | |
6268 int buf_index; | |
6269 | |
6270 s->flags= avctx->flags; | |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1706
diff
changeset
|
6271 s->flags2= avctx->flags2; |
1168 | 6272 |
6273 /* no supplementary picture */ | |
6274 if (buf_size == 0) { | |
6275 return 0; | |
6276 } | |
6277 | |
6278 if(s->flags&CODEC_FLAG_TRUNCATED){ | |
2392 | 6279 int next= find_frame_end(h, buf, buf_size); |
1168 | 6280 |
1988 | 6281 if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 ) |
1168 | 6282 return buf_size; |
6283 //printf("next:%d buf_size:%d last_index:%d\n", next, buf_size, s->parse_context.last_index); | |
6284 } | |
6285 | |
2227 | 6286 if(h->is_avc && !h->got_avcC) { |
6287 int i, cnt, nalsize; | |
6288 unsigned char *p = avctx->extradata; | |
6289 if(avctx->extradata_size < 7) { | |
6290 av_log(avctx, AV_LOG_ERROR, "avcC too short\n"); | |
6291 return -1; | |
6292 } | |
6293 if(*p != 1) { | |
6294 av_log(avctx, AV_LOG_ERROR, "Unknown avcC version %d\n", *p); | |
6295 return -1; | |
6296 } | |
6297 /* sps and pps in the avcC always have length coded with 2 bytes, | |
6298 so put a fake nal_length_size = 2 while parsing them */ | |
6299 h->nal_length_size = 2; | |
6300 // Decode sps from avcC | |
6301 cnt = *(p+5) & 0x1f; // Number of sps | |
6302 p += 6; | |
6303 for (i = 0; i < cnt; i++) { | |
6304 nalsize = BE_16(p) + 2; | |
6305 if(decode_nal_units(h, p, nalsize) != nalsize) { | |
6306 av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n", i); | |
6307 return -1; | |
6308 } | |
6309 p += nalsize; | |
6310 } | |
6311 // Decode pps from avcC | |
6312 cnt = *(p++); // Number of pps | |
6313 for (i = 0; i < cnt; i++) { | |
6314 nalsize = BE_16(p) + 2; | |
6315 if(decode_nal_units(h, p, nalsize) != nalsize) { | |
6316 av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n", i); | |
6317 return -1; | |
6318 } | |
6319 p += nalsize; | |
6320 } | |
6321 // Now store right nal length size, that will be use to parse all other nals | |
6322 h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1; | |
6323 // Do not reparse avcC | |
6324 h->got_avcC = 1; | |
6325 } | |
6326 | |
6327 if(!h->is_avc && s->avctx->extradata_size && s->picture_number==0){ | |
1168 | 6328 if(0 < decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) ) |
6329 return -1; | |
6330 } | |
6331 | |
6332 buf_index=decode_nal_units(h, buf, buf_size); | |
6333 if(buf_index < 0) | |
6334 return -1; | |
6335 | |
6336 //FIXME do something with unavailable reference frames | |
6337 | |
6338 // if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_index, buf_size); | |
1174 | 6339 if(!s->current_picture_ptr){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1548
diff
changeset
|
6340 av_log(h->s.avctx, AV_LOG_DEBUG, "error, NO frame\n"); |
1174 | 6341 return -1; |
6342 } | |
6343 | |
2409 | 6344 { |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
6345 //#define DECODE_ORDER |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
6346 Picture *out = s->current_picture_ptr; |
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
6347 #ifndef DECODE_ORDER |
2409 | 6348 /* Sort B-frames into display order |
6349 * FIXME doesn't allow for multiple delayed frames */ | |
6350 Picture *cur = s->current_picture_ptr; | |
6351 Picture *prev = h->delayed_pic[0]; | |
6352 | |
2410
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6353 if(s->low_delay |
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6354 && (cur->pict_type == B_TYPE |
2409 | 6355 || (!h->sps.gaps_in_frame_num_allowed_flag |
2410
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6356 && prev && cur->poc - prev->poc > 2))){ |
2409 | 6357 s->low_delay = 0; |
6358 s->avctx->has_b_frames = 1; | |
2410
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6359 if(prev && prev->poc > cur->poc) |
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6360 // too late to display this frame |
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6361 cur = prev; |
2409 | 6362 } |
6363 | |
6364 if(s->low_delay || !prev || cur->pict_type == B_TYPE) | |
6365 out = cur; | |
2410
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6366 else |
2409 | 6367 out = prev; |
2410
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6368 if(s->low_delay || !prev || out == prev){ |
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6369 if(prev && prev->reference == 1) |
2409 | 6370 prev->reference = 0; |
2410
9d780478f8a5
reduce stutter if we learn too late that the stream contains B-frames.
lorenm
parents:
2409
diff
changeset
|
6371 h->delayed_pic[0] = cur; |
2409 | 6372 } |
2441
358813ec4ca2
H.264 b ref pic list order and long term pictures patch by (Loic Le Loarer <loic.le-loarer polytechnique org>)
michael
parents:
2440
diff
changeset
|
6373 #endif |
2409 | 6374 |
6375 *pict= *(AVFrame*)out; | |
6376 } | |
6377 | |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1698
diff
changeset
|
6378 ff_print_debug_info(s, pict); |
1168 | 6379 assert(pict->data[0]); |
6380 //printf("out %d\n", (int)pict->data[0]); | |
6381 #if 0 //? | |
6382 | |
6383 /* Return the Picture timestamp as the frame number */ | |
6384 /* we substract 1 because it is added on utils.c */ | |
6385 avctx->frame_number = s->picture_number - 1; | |
6386 #endif | |
6387 #if 0 | |
6388 /* dont output the last pic after seeking */ | |
6389 if(s->last_picture_ptr || s->low_delay) | |
2392 | 6390 //Note this isnt a issue as a IDR pic should flush the buffers |
1168 | 6391 #endif |
6392 *data_size = sizeof(AVFrame); | |
6393 return get_consumed_bytes(s, buf_index, buf_size); | |
6394 } | |
6395 #if 0 | |
6396 static inline void fill_mb_avail(H264Context *h){ | |
6397 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
|
6398 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
1168 | 6399 |
6400 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
|
6401 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
|
6402 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
|
6403 h->mb_avail[2]= s->mb_x+1 < s->mb_width && h->slice_table[mb_xy - s->mb_stride + 1] == h->slice_num; |
1168 | 6404 }else{ |
6405 h->mb_avail[0]= | |
6406 h->mb_avail[1]= | |
6407 h->mb_avail[2]= 0; | |
6408 } | |
6409 h->mb_avail[3]= s->mb_x && h->slice_table[mb_xy - 1] == h->slice_num; | |
6410 h->mb_avail[4]= 1; //FIXME move out | |
6411 h->mb_avail[5]= 0; //FIXME move out | |
6412 } | |
6413 #endif | |
6414 | |
6415 #if 0 //selftest | |
6416 #define COUNT 8000 | |
6417 #define SIZE (COUNT*40) | |
6418 int main(){ | |
6419 int i; | |
6420 uint8_t temp[SIZE]; | |
6421 PutBitContext pb; | |
6422 GetBitContext gb; | |
6423 // int int_temp[10000]; | |
6424 DSPContext dsp; | |
6425 AVCodecContext avctx; | |
6426 | |
6427 dsputil_init(&dsp, &avctx); | |
6428 | |
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1453
diff
changeset
|
6429 init_put_bits(&pb, temp, SIZE); |
1168 | 6430 printf("testing unsigned exp golomb\n"); |
6431 for(i=0; i<COUNT; i++){ | |
6432 START_TIMER | |
6433 set_ue_golomb(&pb, i); | |
6434 STOP_TIMER("set_ue_golomb"); | |
6435 } | |
6436 flush_put_bits(&pb); | |
6437 | |
6438 init_get_bits(&gb, temp, 8*SIZE); | |
6439 for(i=0; i<COUNT; i++){ | |
6440 int j, s; | |
6441 | |
6442 s= show_bits(&gb, 24); | |
6443 | |
6444 START_TIMER | |
6445 j= get_ue_golomb(&gb); | |
6446 if(j != i){ | |
6447 printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); | |
6448 // return -1; | |
6449 } | |
6450 STOP_TIMER("get_ue_golomb"); | |
6451 } | |
6452 | |
6453 | |
1524 | 6454 init_put_bits(&pb, temp, SIZE); |
1168 | 6455 printf("testing signed exp golomb\n"); |
6456 for(i=0; i<COUNT; i++){ | |
6457 START_TIMER | |
6458 set_se_golomb(&pb, i - COUNT/2); | |
6459 STOP_TIMER("set_se_golomb"); | |
6460 } | |
6461 flush_put_bits(&pb); | |
6462 | |
6463 init_get_bits(&gb, temp, 8*SIZE); | |
6464 for(i=0; i<COUNT; i++){ | |
6465 int j, s; | |
6466 | |
6467 s= show_bits(&gb, 24); | |
6468 | |
6469 START_TIMER | |
6470 j= get_se_golomb(&gb); | |
6471 if(j != i - COUNT/2){ | |
6472 printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); | |
6473 // return -1; | |
6474 } | |
6475 STOP_TIMER("get_se_golomb"); | |
6476 } | |
6477 | |
6478 printf("testing 4x4 (I)DCT\n"); | |
6479 | |
6480 DCTELEM block[16]; | |
6481 uint8_t src[16], ref[16]; | |
6482 uint64_t error= 0, max_error=0; | |
6483 | |
6484 for(i=0; i<COUNT; i++){ | |
6485 int j; | |
6486 // printf("%d %d %d\n", r1, r2, (r2-r1)*16); | |
6487 for(j=0; j<16; j++){ | |
6488 ref[j]= random()%255; | |
6489 src[j]= random()%255; | |
6490 } | |
6491 | |
6492 h264_diff_dct_c(block, src, ref, 4); | |
6493 | |
6494 //normalize | |
6495 for(j=0; j<16; j++){ | |
6496 // printf("%d ", block[j]); | |
6497 block[j]= block[j]*4; | |
6498 if(j&1) block[j]= (block[j]*4 + 2)/5; | |
6499 if(j&4) block[j]= (block[j]*4 + 2)/5; | |
6500 } | |
6501 // printf("\n"); | |
6502 | |
2272
cd43603c46f9
move h264 idct to its own file and call via function pointer in DspContext
michael
parents:
2255
diff
changeset
|
6503 s->dsp.h264_idct_add(ref, block, 4); |
1168 | 6504 /* for(j=0; j<16; j++){ |
6505 printf("%d ", ref[j]); | |
6506 } | |
6507 printf("\n");*/ | |
6508 | |
6509 for(j=0; j<16; j++){ | |
6510 int diff= ABS(src[j] - ref[j]); | |
6511 | |
6512 error+= diff*diff; | |
6513 max_error= FFMAX(max_error, diff); | |
6514 } | |
6515 } | |
6516 printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error ); | |
6517 #if 0 | |
6518 printf("testing quantizer\n"); | |
6519 for(qp=0; qp<52; qp++){ | |
6520 for(i=0; i<16; i++) | |
6521 src1_block[i]= src2_block[i]= random()%255; | |
6522 | |
6523 } | |
6524 #endif | |
6525 printf("Testing NAL layer\n"); | |
6526 | |
6527 uint8_t bitstream[COUNT]; | |
6528 uint8_t nal[COUNT*2]; | |
6529 H264Context h; | |
6530 memset(&h, 0, sizeof(H264Context)); | |
6531 | |
6532 for(i=0; i<COUNT; i++){ | |
6533 int zeros= i; | |
6534 int nal_length; | |
6535 int consumed; | |
6536 int out_length; | |
6537 uint8_t *out; | |
6538 int j; | |
6539 | |
6540 for(j=0; j<COUNT; j++){ | |
6541 bitstream[j]= (random() % 255) + 1; | |
6542 } | |
6543 | |
6544 for(j=0; j<zeros; j++){ | |
6545 int pos= random() % COUNT; | |
6546 while(bitstream[pos] == 0){ | |
6547 pos++; | |
6548 pos %= COUNT; | |
6549 } | |
6550 bitstream[pos]=0; | |
6551 } | |
6552 | |
6553 START_TIMER | |
6554 | |
6555 nal_length= encode_nal(&h, nal, bitstream, COUNT, COUNT*2); | |
6556 if(nal_length<0){ | |
6557 printf("encoding failed\n"); | |
6558 return -1; | |
6559 } | |
6560 | |
6561 out= decode_nal(&h, nal, &out_length, &consumed, nal_length); | |
6562 | |
6563 STOP_TIMER("NAL") | |
6564 | |
6565 if(out_length != COUNT){ | |
6566 printf("incorrect length %d %d\n", out_length, COUNT); | |
6567 return -1; | |
6568 } | |
6569 | |
6570 if(consumed != nal_length){ | |
6571 printf("incorrect consumed length %d %d\n", nal_length, consumed); | |
6572 return -1; | |
6573 } | |
6574 | |
6575 if(memcmp(bitstream, out, COUNT)){ | |
6576 printf("missmatch\n"); | |
6577 return -1; | |
6578 } | |
6579 } | |
6580 | |
6581 printf("Testing RBSP\n"); | |
6582 | |
6583 | |
6584 return 0; | |
6585 } | |
6586 #endif | |
6587 | |
6588 | |
6589 static int decode_end(AVCodecContext *avctx) | |
6590 { | |
6591 H264Context *h = avctx->priv_data; | |
6592 MpegEncContext *s = &h->s; | |
6593 | |
6594 free_tables(h); //FIXME cleanup init stuff perhaps | |
6595 MPV_common_end(s); | |
6596 | |
6597 // memset(h, 0, sizeof(H264Context)); | |
6598 | |
6599 return 0; | |
6600 } | |
6601 | |
6602 | |
6603 AVCodec h264_decoder = { | |
6604 "h264", | |
6605 CODEC_TYPE_VIDEO, | |
6606 CODEC_ID_H264, | |
6607 sizeof(H264Context), | |
6608 decode_init, | |
6609 NULL, | |
6610 decode_end, | |
6611 decode_frame, | |
1214 | 6612 /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, |
1168 | 6613 }; |
6614 | |
1988 | 6615 AVCodecParser h264_parser = { |
6616 { CODEC_ID_H264 }, | |
2392 | 6617 sizeof(H264Context), |
1988 | 6618 NULL, |
6619 h264_parse, | |
6620 ff_parse_close, | |
6621 }; | |
6622 | |
1234 | 6623 #include "svq3.c" |