Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master: (25 commits)
rv40dsp x86: MMX/MMX2/3DNow/SSE2/SSSE3 implementations of MC
ape: Use unsigned integer maths
arm: dsputil: fix overreads in put/avg_pixels functions
h264: K&R formatting cosmetics for header files (part II/II)
h264: K&R formatting cosmetics for header files (part I/II)
rtmp: Implement check bandwidth notification.
rtmp: Support 'rtmp_swfurl', an option which specifies the URL of the SWF player.
rtmp: Support 'rtmp_flashver', an option which overrides the version of the Flash plugin.
rtmp: Support 'rtmp_tcurl', an option which overrides the URL of the target stream.
cmdutils: Add fallback case to switch in check_stream_specifier().
sctp: be consistent with socket option level
configure: Add _XOPEN_SOURCE=600 to Solaris preprocessor flags.
vcr1enc: drop pointless empty encode_init() wrapper function
vcr1: drop pointless write-only AVCodecContext member from VCR1Context
vcr1: group encoder code together to save #ifdefs
vcr1: cosmetics: K&R prettyprinting, typos, parentheses, dead code, comments
mov: make one comment slightly more specific
lavr: replace the SSE version of ff_conv_fltp_to_flt_6ch() with SSE4 and AVX
lavfi: move audio-related functions to a separate file.
lavfi: remove some audio-related function from public API.
...

Conflicts:
cmdutils.c
libavcodec/h264.h
libavcodec/h264_mvpred.h
libavcodec/vcr1.c
libavfilter/avfilter.c
libavfilter/avfilter.h
libavfilter/defaults.c
libavfilter/internal.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2012/05/11 05:41:29
Showing 44 changed files
... ...
@@ -38,6 +38,7 @@
38 38
 #if CONFIG_POSTPROC
39 39
 #include "libpostproc/postprocess.h"
40 40
 #endif
41
+#include "libavutil/avassert.h"
41 42
 #include "libavutil/avstring.h"
42 43
 #include "libavutil/mathematics.h"
43 44
 #include "libavutil/parseutils.h"
... ...
@@ -1075,7 +1076,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
1075 1075
         case 's': type = AVMEDIA_TYPE_SUBTITLE;   break;
1076 1076
         case 'd': type = AVMEDIA_TYPE_DATA;       break;
1077 1077
         case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
1078
-        default: abort(); // never reached, silence warning
1078
+        default:  av_assert0(0);
1079 1079
         }
1080 1080
         if (type != st->codec->codec_type)
1081 1081
             return 0;
... ...
@@ -2662,7 +2662,7 @@ case $target_os in
2662 2662
         SHFLAGS='-shared -Wl,-h,$$(@F)'
2663 2663
         enabled x86 && SHFLAGS="-mimpure-text $SHFLAGS"
2664 2664
         network_extralibs="-lsocket -lnsl"
2665
-        add_cppflags -D__EXTENSIONS__
2665
+        add_cppflags -D__EXTENSIONS__ -D_XOPEN_SOURCE=600
2666 2666
         # When using suncc to build, the Solaris linker will mark
2667 2667
         # an executable with each instruction set encountered by
2668 2668
         # the Solaris assembler.  As our libraries contain their own
... ...
@@ -393,7 +393,7 @@ static inline int range_get_symbol(APEContext *ctx,
393 393
 }
394 394
 /** @} */ // group rangecoder
395 395
 
396
-static inline void update_rice(APERice *rice, int x)
396
+static inline void update_rice(APERice *rice, unsigned int x)
397 397
 {
398 398
     int lim = rice->k ? (1 << (rice->k + 4)) : 0;
399 399
     rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5);
... ...
@@ -406,7 +406,7 @@ static inline void update_rice(APERice *rice, int x)
406 406
 
407 407
 static inline int ape_decode_value(APEContext *ctx, APERice *rice)
408 408
 {
409
-    int x, overflow;
409
+    unsigned int x, overflow;
410 410
 
411 411
     if (ctx->fileversion < 3990) {
412 412
         int tmpk;
... ...
@@ -95,6 +95,7 @@ endfunc
95 95
 .endm
96 96
 
97 97
 .macro  pixels16_y2     rnd=1, avg=0
98
+        sub             r3,  r3,  #2
98 99
         vld1.64         {q0},     [r1], r2
99 100
         vld1.64         {q1},     [r1], r2
100 101
 1:      subs            r3,  r3,  #2
... ...
@@ -114,10 +115,25 @@ endfunc
114 114
         vst1.64         {q2},     [r0,:128], r2
115 115
         vst1.64         {q3},     [r0,:128], r2
116 116
         bne             1b
117
+
118
+        avg             q2,  q0,  q1
119
+        vld1.64         {q0},     [r1], r2
120
+        avg             q3,  q0,  q1
121
+  .if \avg
122
+        vld1.8          {q8},     [r0,:128], r2
123
+        vld1.8          {q9},     [r0,:128]
124
+        vrhadd.u8       q2,  q2,  q8
125
+        vrhadd.u8       q3,  q3,  q9
126
+        sub             r0,  r0,  r2
127
+  .endif
128
+        vst1.64         {q2},     [r0,:128], r2
129
+        vst1.64         {q3},     [r0,:128], r2
130
+
117 131
         bx              lr
118 132
 .endm
119 133
 
120 134
 .macro  pixels16_xy2    rnd=1, avg=0
135
+        sub             r3,  r3,  #2
121 136
         vld1.64         {d0-d2},  [r1], r2
122 137
         vld1.64         {d4-d6},  [r1], r2
123 138
   .ifeq \rnd
... ...
@@ -173,6 +189,42 @@ endfunc
173 173
         vaddl.u8        q11, d3,  d5
174 174
         vst1.64         {q15},    [r0,:128], r2
175 175
         bgt             1b
176
+
177
+        vld1.64         {d0-d2},  [r1], r2
178
+        vadd.u16        q12, q8,  q9
179
+  .ifeq \rnd
180
+        vadd.u16        q12, q12, q13
181
+  .endif
182
+        vext.8          q15, q0,  q1,  #1
183
+        vadd.u16        q1 , q10, q11
184
+        shrn            d28, q12, #2
185
+  .ifeq \rnd
186
+        vadd.u16        q1,  q1,  q13
187
+  .endif
188
+        shrn            d29, q1,  #2
189
+  .if \avg
190
+        vld1.8          {q8},     [r0,:128]
191
+        vrhadd.u8       q14, q14, q8
192
+  .endif
193
+        vaddl.u8        q8,  d0,  d30
194
+        vaddl.u8        q10, d1,  d31
195
+        vst1.64         {q14},    [r0,:128], r2
196
+        vadd.u16        q12, q8,  q9
197
+  .ifeq \rnd
198
+        vadd.u16        q12, q12, q13
199
+  .endif
200
+        vadd.u16        q0,  q10, q11
201
+        shrn            d30, q12, #2
202
+  .ifeq \rnd
203
+        vadd.u16        q0,  q0,  q13
204
+  .endif
205
+        shrn            d31, q0,  #2
206
+  .if \avg
207
+        vld1.8          {q9},     [r0,:128]
208
+        vrhadd.u8       q15, q15, q9
209
+  .endif
210
+        vst1.64         {q15},    [r0,:128], r2
211
+
176 212
         bx              lr
177 213
 .endm
178 214
 
... ...
@@ -228,6 +280,7 @@ endfunc
228 228
 .endm
229 229
 
230 230
 .macro  pixels8_y2      rnd=1, avg=0
231
+        sub             r3,  r3,  #2
231 232
         vld1.64         {d0},     [r1], r2
232 233
         vld1.64         {d1},     [r1], r2
233 234
 1:      subs            r3,  r3,  #2
... ...
@@ -246,10 +299,24 @@ endfunc
246 246
         vst1.64         {d4},     [r0,:64], r2
247 247
         vst1.64         {d5},     [r0,:64], r2
248 248
         bne             1b
249
+
250
+        avg             d4,  d0,  d1
251
+        vld1.64         {d0},     [r1], r2
252
+        avg             d5,  d0,  d1
253
+  .if \avg
254
+        vld1.8          {d2},     [r0,:64], r2
255
+        vld1.8          {d3},     [r0,:64]
256
+        vrhadd.u8       q2,  q2,  q1
257
+        sub             r0,  r0,  r2
258
+  .endif
259
+        vst1.64         {d4},     [r0,:64], r2
260
+        vst1.64         {d5},     [r0,:64], r2
261
+
249 262
         bx              lr
250 263
 .endm
251 264
 
252 265
 .macro  pixels8_xy2     rnd=1, avg=0
266
+        sub             r3,  r3,  #2
253 267
         vld1.64         {q0},     [r1], r2
254 268
         vld1.64         {q1},     [r1], r2
255 269
   .ifeq \rnd
... ...
@@ -291,6 +358,31 @@ endfunc
291 291
         vaddl.u8        q9,  d2,  d6
292 292
         vst1.64         {d7},     [r0,:64], r2
293 293
         bgt             1b
294
+
295
+        vld1.64         {q0},     [r1], r2
296
+        vadd.u16        q10, q8,  q9
297
+        vext.8          d4,  d0,  d1,  #1
298
+  .ifeq \rnd
299
+        vadd.u16        q10, q10, q11
300
+  .endif
301
+        vaddl.u8        q8,  d0,  d4
302
+        shrn            d5,  q10, #2
303
+        vadd.u16        q10, q8,  q9
304
+  .if \avg
305
+        vld1.8          {d7},     [r0,:64]
306
+        vrhadd.u8       d5,  d5,  d7
307
+  .endif
308
+  .ifeq \rnd
309
+        vadd.u16        q10, q10, q11
310
+  .endif
311
+        vst1.64         {d5},     [r0,:64], r2
312
+        shrn            d7,  q10, #2
313
+  .if \avg
314
+        vld1.8          {d5},     [r0,:64]
315
+        vrhadd.u8       d7,  d7,  d5
316
+  .endif
317
+        vst1.64         {d7},     [r0,:64], r2
318
+
294 319
         bx              lr
295 320
 .endm
296 321
 
... ...
@@ -37,14 +37,14 @@
37 37
 #include "rectangle.h"
38 38
 
39 39
 #define interlaced_dct interlaced_dct_is_a_bad_name
40
-#define mb_intra mb_intra_is_not_initialized_see_mb_type
40
+#define mb_intra       mb_intra_is_not_initialized_see_mb_type
41 41
 
42
-#define MAX_SPS_COUNT 32
43
-#define MAX_PPS_COUNT 256
42
+#define MAX_SPS_COUNT          32
43
+#define MAX_PPS_COUNT         256
44 44
 
45
-#define MAX_MMCO_COUNT 66
45
+#define MAX_MMCO_COUNT         66
46 46
 
47
-#define MAX_DELAYED_PIC_COUNT 16
47
+#define MAX_DELAYED_PIC_COUNT  16
48 48
 
49 49
 #define MAX_MBPAIR_SIZE (256*1024) // a tighter bound could be calculated if someone cares about a few bytes
50 50
 
... ...
@@ -61,25 +61,25 @@
61 61
 #define MAX_SLICES 16
62 62
 
63 63
 #ifdef ALLOW_INTERLACE
64
-#define MB_MBAFF h->mb_mbaff
65
-#define MB_FIELD h->mb_field_decoding_flag
64
+#define MB_MBAFF    h->mb_mbaff
65
+#define MB_FIELD    h->mb_field_decoding_flag
66 66
 #define FRAME_MBAFF h->mb_aff_frame
67 67
 #define FIELD_PICTURE (s->picture_structure != PICT_FRAME)
68 68
 #define LEFT_MBS 2
69
-#define LTOP 0
70
-#define LBOT 1
71
-#define LEFT(i) (i)
69
+#define LTOP     0
70
+#define LBOT     1
71
+#define LEFT(i)  (i)
72 72
 #else
73
-#define MB_MBAFF 0
74
-#define MB_FIELD 0
75
-#define FRAME_MBAFF 0
73
+#define MB_MBAFF      0
74
+#define MB_FIELD      0
75
+#define FRAME_MBAFF   0
76 76
 #define FIELD_PICTURE 0
77 77
 #undef  IS_INTERLACED
78 78
 #define IS_INTERLACED(mb_type) 0
79 79
 #define LEFT_MBS 1
80
-#define LTOP 0
81
-#define LBOT 0
82
-#define LEFT(i) 0
80
+#define LTOP     0
81
+#define LBOT     0
82
+#define LEFT(i)  0
83 83
 #endif
84 84
 #define FIELD_OR_MBAFF_PICTURE (FRAME_MBAFF || FIELD_PICTURE)
85 85
 
... ...
@@ -91,9 +91,9 @@
91 91
 #define CHROMA422 (h->sps.chroma_format_idc == 2)
92 92
 #define CHROMA444 (h->sps.chroma_format_idc == 3)
93 93
 
94
-#define EXTENDED_SAR          255
94
+#define EXTENDED_SAR       255
95 95
 
96
-#define MB_TYPE_REF0       MB_TYPE_ACPRED //dirty but it fits in 16 bit
96
+#define MB_TYPE_REF0       MB_TYPE_ACPRED // dirty but it fits in 16 bit
97 97
 #define MB_TYPE_8x8DCT     0x01000000
98 98
 #define IS_REF0(a)         ((a) & MB_TYPE_REF0)
99 99
 #define IS_8x8DCT(a)       ((a) & MB_TYPE_8x8DCT)
... ...
@@ -108,7 +108,7 @@
108 108
 
109 109
 /* NAL unit types */
110 110
 enum {
111
-    NAL_SLICE=1,
111
+    NAL_SLICE = 1,
112 112
     NAL_DPA,
113 113
     NAL_DPB,
114 114
     NAL_DPC,
... ...
@@ -121,17 +121,17 @@ enum {
121 121
     NAL_END_STREAM,
122 122
     NAL_FILLER_DATA,
123 123
     NAL_SPS_EXT,
124
-    NAL_AUXILIARY_SLICE=19
124
+    NAL_AUXILIARY_SLICE = 19
125 125
 };
126 126
 
127 127
 /**
128 128
  * SEI message types
129 129
  */
130 130
 typedef enum {
131
-    SEI_BUFFERING_PERIOD             =  0, ///< buffering period (H.264, D.1.1)
132
-    SEI_TYPE_PIC_TIMING              =  1, ///< picture timing
133
-    SEI_TYPE_USER_DATA_UNREGISTERED  =  5, ///< unregistered user data
134
-    SEI_TYPE_RECOVERY_POINT          =  6  ///< recovery point (frame # to decoder sync)
131
+    SEI_BUFFERING_PERIOD            = 0,   ///< buffering period (H.264, D.1.1)
132
+    SEI_TYPE_PIC_TIMING             = 1,   ///< picture timing
133
+    SEI_TYPE_USER_DATA_UNREGISTERED = 5,   ///< unregistered user data
134
+    SEI_TYPE_RECOVERY_POINT         = 6    ///< recovery point (frame # to decoder sync)
135 135
 } SEI_Type;
136 136
 
137 137
 /**
... ...
@@ -152,8 +152,7 @@ typedef enum {
152 152
 /**
153 153
  * Sequence parameter set
154 154
  */
155
-typedef struct SPS{
156
-
155
+typedef struct SPS {
157 156
     int profile_idc;
158 157
     int level_idc;
159 158
     int chroma_format_idc;
... ...
@@ -170,9 +169,9 @@ typedef struct SPS{
170 170
     int mb_width;                      ///< pic_width_in_mbs_minus1 + 1
171 171
     int mb_height;                     ///< pic_height_in_map_units_minus1 + 1
172 172
     int frame_mbs_only_flag;
173
-    int mb_aff;                        ///<mb_adaptive_frame_field_flag
173
+    int mb_aff;                        ///< mb_adaptive_frame_field_flag
174 174
     int direct_8x8_inference_flag;
175
-    int crop;                   ///< frame_cropping_flag
175
+    int crop;                          ///< frame_cropping_flag
176 176
     unsigned int crop_left;            ///< frame_cropping_rect_left_offset
177 177
     unsigned int crop_right;           ///< frame_cropping_rect_right_offset
178 178
     unsigned int crop_top;             ///< frame_cropping_rect_top_offset
... ...
@@ -189,7 +188,7 @@ typedef struct SPS{
189 189
     uint32_t num_units_in_tick;
190 190
     uint32_t time_scale;
191 191
     int fixed_frame_rate_flag;
192
-    short offset_for_ref_frame[256]; //FIXME dyn aloc?
192
+    short offset_for_ref_frame[256]; // FIXME dyn aloc?
193 193
     int bitstream_restriction_flag;
194 194
     int num_reorder_frames;
195 195
     int scaling_matrix_present;
... ...
@@ -199,20 +198,20 @@ typedef struct SPS{
199 199
     int vcl_hrd_parameters_present_flag;
200 200
     int pic_struct_present_flag;
201 201
     int time_offset_length;
202
-    int cpb_cnt;                       ///< See H.264 E.1.2
203
-    int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 +1
204
-    int cpb_removal_delay_length;      ///< cpb_removal_delay_length_minus1 + 1
205
-    int dpb_output_delay_length;       ///< dpb_output_delay_length_minus1 + 1
206
-    int bit_depth_luma;                ///< bit_depth_luma_minus8 + 8
207
-    int bit_depth_chroma;              ///< bit_depth_chroma_minus8 + 8
208
-    int residual_color_transform_flag; ///< residual_colour_transform_flag
209
-    int constraint_set_flags;          ///< constraint_set[0-3]_flag
210
-}SPS;
202
+    int cpb_cnt;                          ///< See H.264 E.1.2
203
+    int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 + 1
204
+    int cpb_removal_delay_length;         ///< cpb_removal_delay_length_minus1 + 1
205
+    int dpb_output_delay_length;          ///< dpb_output_delay_length_minus1 + 1
206
+    int bit_depth_luma;                   ///< bit_depth_luma_minus8 + 8
207
+    int bit_depth_chroma;                 ///< bit_depth_chroma_minus8 + 8
208
+    int residual_color_transform_flag;    ///< residual_colour_transform_flag
209
+    int constraint_set_flags;             ///< constraint_set[0-3]_flag
210
+} SPS;
211 211
 
212 212
 /**
213 213
  * Picture parameter set
214 214
  */
215
-typedef struct PPS{
215
+typedef struct PPS {
216 216
     unsigned int sps_id;
217 217
     int cabac;                  ///< entropy_coding_mode_flag
218 218
     int pic_order_present;      ///< pic_order_present_flag
... ...
@@ -225,20 +224,20 @@ typedef struct PPS{
225 225
     int init_qs;                ///< pic_init_qs_minus26 + 26
226 226
     int chroma_qp_index_offset[2];
227 227
     int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
228
-    int constrained_intra_pred; ///< constrained_intra_pred_flag
229
-    int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
230
-    int transform_8x8_mode;     ///< transform_8x8_mode_flag
228
+    int constrained_intra_pred;     ///< constrained_intra_pred_flag
229
+    int redundant_pic_cnt_present;  ///< redundant_pic_cnt_present_flag
230
+    int transform_8x8_mode;         ///< transform_8x8_mode_flag
231 231
     uint8_t scaling_matrix4[6][16];
232 232
     uint8_t scaling_matrix8[6][64];
233 233
     uint8_t chroma_qp_table[2][QP_MAX_NUM+1];  ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
234 234
     int chroma_qp_diff;
235
-}PPS;
235
+} PPS;
236 236
 
237 237
 /**
238 238
  * Memory management control operation opcode.
239 239
  */
240
-typedef enum MMCOOpcode{
241
-    MMCO_END=0,
240
+typedef enum MMCOOpcode {
241
+    MMCO_END = 0,
242 242
     MMCO_SHORT2UNUSED,
243 243
     MMCO_LONG2UNUSED,
244 244
     MMCO_SHORT2LONG,
... ...
@@ -250,7 +249,7 @@ typedef enum MMCOOpcode{
250 250
 /**
251 251
  * Memory management control operation.
252 252
  */
253
-typedef struct MMCO{
253
+typedef struct MMCO {
254 254
     MMCOOpcode opcode;
255 255
     int short_pic_num;  ///< pic_num without wrapping (pic_num & max_pic_num)
256 256
     int long_arg;       ///< index, pic_num, or num long refs depending on opcode
... ...
@@ -259,18 +258,18 @@ typedef struct MMCO{
259 259
 /**
260 260
  * H264Context
261 261
  */
262
-typedef struct H264Context{
262
+typedef struct H264Context {
263 263
     MpegEncContext s;
264 264
     H264DSPContext h264dsp;
265 265
     int pixel_shift;    ///< 0 for 8-bit H264, 1 for high-bit-depth H264
266
-    int chroma_qp[2]; //QPc
266
+    int chroma_qp[2];   // QPc
267 267
 
268 268
     int qp_thresh;      ///< QP threshold to skip loopfilter
269 269
 
270 270
     int prev_mb_skipped;
271 271
     int next_mb_skipped;
272 272
 
273
-    //prediction stuff
273
+    // prediction stuff
274 274
     int chroma_pred_mode;
275 275
     int intra16x16_pred_mode;
276 276
 
... ...
@@ -284,32 +283,32 @@ typedef struct H264Context{
284 284
     int topright_type;
285 285
     int left_type[LEFT_MBS];
286 286
 
287
-    const uint8_t * left_block;
287
+    const uint8_t *left_block;
288 288
     int topleft_partition;
289 289
 
290
-    int8_t intra4x4_pred_mode_cache[5*8];
291
-    int8_t (*intra4x4_pred_mode);
290
+    int8_t intra4x4_pred_mode_cache[5 * 8];
291
+    int8_t(*intra4x4_pred_mode);
292 292
     H264PredContext hpc;
293 293
     unsigned int topleft_samples_available;
294 294
     unsigned int top_samples_available;
295 295
     unsigned int topright_samples_available;
296 296
     unsigned int left_samples_available;
297
-    uint8_t (*top_borders[2])[(16*3)*2];
297
+    uint8_t (*top_borders[2])[(16 * 3) * 2];
298 298
 
299 299
     /**
300 300
      * non zero coeff count cache.
301 301
      * is 64 if not available.
302 302
      */
303
-    DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15*8];
303
+    DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15 * 8];
304 304
 
305 305
     uint8_t (*non_zero_count)[48];
306 306
 
307 307
     /**
308 308
      * Motion vector cache.
309 309
      */
310
-    DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5*8][2];
311
-    DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5*8];
312
-#define LIST_NOT_USED -1 //FIXME rename?
310
+    DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5 * 8][2];
311
+    DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5 * 8];
312
+#define LIST_NOT_USED -1 // FIXME rename?
313 313
 #define PART_NOT_AVAILABLE -2
314 314
 
315 315
     /**
... ...
@@ -321,13 +320,13 @@ typedef struct H264Context{
321 321
      * block_offset[ 0..23] for frame macroblocks
322 322
      * block_offset[24..47] for field macroblocks
323 323
      */
324
-    int block_offset[2*(16*3)];
324
+    int block_offset[2 * (16 * 3)];
325 325
 
326
-    uint32_t *mb2b_xy; //FIXME are these 4 a good idea?
326
+    uint32_t *mb2b_xy;  // FIXME are these 4 a good idea?
327 327
     uint32_t *mb2br_xy;
328
-    int b_stride; //FIXME use s->b4_stride
328
+    int b_stride;       // FIXME use s->b4_stride
329 329
 
330
-    int mb_linesize;   ///< may be equal to s->linesize or s->linesize*2, for mbaff
330
+    int mb_linesize;    ///< may be equal to s->linesize or s->linesize * 2, for mbaff
331 331
     int mb_uvlinesize;
332 332
 
333 333
     int emu_edge_width;
... ...
@@ -338,32 +337,32 @@ typedef struct H264Context{
338 338
     /**
339 339
      * current pps
340 340
      */
341
-    PPS pps; //FIXME move to Picture perhaps? (->no) do we need that?
341
+    PPS pps; // FIXME move to Picture perhaps? (->no) do we need that?
342 342
 
343
-    uint32_t dequant4_buffer[6][QP_MAX_NUM+1][16]; //FIXME should these be moved down?
344
-    uint32_t dequant8_buffer[6][QP_MAX_NUM+1][64];
345
-    uint32_t (*dequant4_coeff[6])[16];
346
-    uint32_t (*dequant8_coeff[6])[64];
343
+    uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16]; // FIXME should these be moved down?
344
+    uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
345
+    uint32_t(*dequant4_coeff[6])[16];
346
+    uint32_t(*dequant8_coeff[6])[64];
347 347
 
348 348
     int slice_num;
349
-    uint16_t *slice_table;     ///< slice_table_base + 2*mb_stride + 1
349
+    uint16_t *slice_table;      ///< slice_table_base + 2*mb_stride + 1
350 350
     int slice_type;
351
-    int slice_type_nos;        ///< S free slice type (SI/SP are remapped to I/P)
351
+    int slice_type_nos;         ///< S free slice type (SI/SP are remapped to I/P)
352 352
     int slice_type_fixed;
353 353
 
354
-    //interlacing specific flags
354
+    // interlacing specific flags
355 355
     int mb_aff_frame;
356 356
     int mb_field_decoding_flag;
357
-    int mb_mbaff;              ///< mb_aff_frame && mb_field_decoding_flag
357
+    int mb_mbaff;               ///< mb_aff_frame && mb_field_decoding_flag
358 358
 
359 359
     DECLARE_ALIGNED(8, uint16_t, sub_mb_type)[4];
360 360
 
361
-    //Weighted pred stuff
361
+    // Weighted pred stuff
362 362
     int use_weight;
363 363
     int use_weight_chroma;
364 364
     int luma_log2_weight_denom;
365 365
     int chroma_log2_weight_denom;
366
-    //The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss
366
+    // The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss
367 367
     int luma_weight[48][2][2];
368 368
     int chroma_weight[48][2][2][2];
369 369
     int implicit_weight[48][48][2];
... ...
@@ -373,48 +372,48 @@ typedef struct H264Context{
373 373
     int col_fieldoff;
374 374
     int dist_scale_factor[16];
375 375
     int dist_scale_factor_field[2][32];
376
-    int map_col_to_list0[2][16+32];
377
-    int map_col_to_list0_field[2][2][16+32];
376
+    int map_col_to_list0[2][16 + 32];
377
+    int map_col_to_list0_field[2][2][16 + 32];
378 378
 
379 379
     /**
380 380
      * num_ref_idx_l0/1_active_minus1 + 1
381 381
      */
382
-    uint8_t *list_counts;            ///< Array of list_count per MB specifying the slice type
383
-    unsigned int ref_count[2];   ///< counts frames or fields, depending on current mb mode
382
+    unsigned int ref_count[2];          ///< counts frames or fields, depending on current mb mode
384 383
     unsigned int list_count;
385
-    Picture ref_list[2][48];         /**< 0..15: frame refs, 16..47: mbaff field refs.
386
-                                          Reordered version of default_ref_list
387
-                                          according to picture reordering in slice header */
388
-    int ref2frm[MAX_SLICES][2][64];  ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1
384
+    uint8_t *list_counts;               ///< Array of list_count per MB specifying the slice type
385
+    Picture ref_list[2][48];            /**< 0..15: frame refs, 16..47: mbaff field refs.
386
+                                         *   Reordered version of default_ref_list
387
+                                         *   according to picture reordering in slice header */
388
+    int ref2frm[MAX_SLICES][2][64];     ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1
389 389
 
390
-    //data partitioning
390
+    // data partitioning
391 391
     GetBitContext intra_gb;
392 392
     GetBitContext inter_gb;
393 393
     GetBitContext *intra_gb_ptr;
394 394
     GetBitContext *inter_gb_ptr;
395 395
 
396
-    DECLARE_ALIGNED(16, DCTELEM, mb)[16*48*2]; ///< as a dct coeffecient is int32_t in high depth, we need to reserve twice the space.
397
-    DECLARE_ALIGNED(16, DCTELEM, mb_luma_dc)[3][16*2];
398
-    DCTELEM mb_padding[256*2];        ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb
396
+    DECLARE_ALIGNED(16, DCTELEM, mb)[16 * 48 * 2]; ///< as a dct coeffecient is int32_t in high depth, we need to reserve twice the space.
397
+    DECLARE_ALIGNED(16, DCTELEM, mb_luma_dc)[3][16 * 2];
398
+    DCTELEM mb_padding[256 * 2];        ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb
399 399
 
400 400
     /**
401 401
      * Cabac
402 402
      */
403 403
     CABACContext cabac;
404
-    uint8_t      cabac_state[1024];
404
+    uint8_t cabac_state[1024];
405 405
 
406
-    /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */
407
-    uint16_t     *cbp_table;
406
+    /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0, 1, 2), 0x0? luma_cbp */
407
+    uint16_t *cbp_table;
408 408
     int cbp;
409 409
     int top_cbp;
410 410
     int left_cbp;
411 411
     /* chroma_pred_mode for i4x4 or i16x16, else 0 */
412
-    uint8_t     *chroma_pred_mode_table;
413
-    int         last_qscale_diff;
414
-    uint8_t     (*mvd_table[2])[2];
415
-    DECLARE_ALIGNED(16, uint8_t, mvd_cache)[2][5*8][2];
416
-    uint8_t     *direct_table;
417
-    uint8_t     direct_cache[5*8];
412
+    uint8_t *chroma_pred_mode_table;
413
+    int last_qscale_diff;
414
+    uint8_t (*mvd_table[2])[2];
415
+    DECLARE_ALIGNED(16, uint8_t, mvd_cache)[2][5 * 8][2];
416
+    uint8_t *direct_table;
417
+    uint8_t direct_cache[5 * 8];
418 418
 
419 419
     uint8_t zigzag_scan[16];
420 420
     uint8_t zigzag_scan8x8[64];
... ...
@@ -435,13 +434,13 @@ typedef struct H264Context{
435 435
 
436 436
     int is_complex;
437 437
 
438
-    //deblock
439
-    int deblocking_filter;         ///< disable_deblocking_filter_idc with 1<->0
438
+    // deblock
439
+    int deblocking_filter;          ///< disable_deblocking_filter_idc with 1 <-> 0
440 440
     int slice_alpha_c0_offset;
441 441
     int slice_beta_offset;
442 442
 
443
-//=============================================================
444
-    //Things below are not used in the MB or more inner code
443
+    // =============================================================
444
+    // Things below are not used in the MB or more inner code
445 445
 
446 446
     int nal_ref_idc;
447 447
     int nal_unit_type;
... ...
@@ -451,37 +450,36 @@ typedef struct H264Context{
451 451
     /**
452 452
      * Used to parse AVC variant of h264
453 453
      */
454
-    int is_avc; ///< this flag is != 0 if codec is avc1
455
-    int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4)
456
-    int got_first; ///< this flag is != 0 if we've parsed a frame
454
+    int is_avc;           ///< this flag is != 0 if codec is avc1
455
+    int nal_length_size;  ///< Number of bytes used for nal length (1, 2 or 4)
456
+    int got_first;        ///< this flag is != 0 if we've parsed a frame
457 457
 
458 458
     SPS *sps_buffers[MAX_SPS_COUNT];
459 459
     PPS *pps_buffers[MAX_PPS_COUNT];
460 460
 
461
-    int dequant_coeff_pps;     ///< reinit tables when pps changes
461
+    int dequant_coeff_pps;      ///< reinit tables when pps changes
462 462
 
463 463
     uint16_t *slice_table_base;
464 464
 
465
-
466
-    //POC stuff
465
+    // POC stuff
467 466
     int poc_lsb;
468 467
     int poc_msb;
469 468
     int delta_poc_bottom;
470 469
     int delta_poc[2];
471 470
     int frame_num;
472
-    int prev_poc_msb;             ///< poc_msb of the last reference pic for POC type 0
473
-    int prev_poc_lsb;             ///< poc_lsb of the last reference pic for POC type 0
474
-    int frame_num_offset;         ///< for POC type 2
475
-    int prev_frame_num_offset;    ///< for POC type 2
476
-    int prev_frame_num;           ///< frame_num of the last pic for POC type 1/2
471
+    int prev_poc_msb;           ///< poc_msb of the last reference pic for POC type 0
472
+    int prev_poc_lsb;           ///< poc_lsb of the last reference pic for POC type 0
473
+    int frame_num_offset;       ///< for POC type 2
474
+    int prev_frame_num_offset;  ///< for POC type 2
475
+    int prev_frame_num;         ///< frame_num of the last pic for POC type 1/2
477 476
 
478 477
     /**
479
-     * frame_num for frames or 2*frame_num+1 for field pics.
478
+     * frame_num for frames or 2 * frame_num + 1 for field pics.
480 479
      */
481 480
     int curr_pic_num;
482 481
 
483 482
     /**
484
-     * max_frame_num or 2*max_frame_num for field pics.
483
+     * max_frame_num or 2 * max_frame_num for field pics.
485 484
      */
486 485
     int max_pic_num;
487 486
 
... ...
@@ -490,7 +488,7 @@ typedef struct H264Context{
490 490
     Picture *short_ref[32];
491 491
     Picture *long_ref[32];
492 492
     Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture
493
-    Picture *delayed_pic[MAX_DELAYED_PIC_COUNT+2]; //FIXME size?
493
+    Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size?
494 494
     int last_pocs[MAX_DELAYED_PIC_COUNT];
495 495
     Picture *next_output_pic;
496 496
     int outputed_poc;
... ...
@@ -503,10 +501,10 @@ typedef struct H264Context{
503 503
     int mmco_index;
504 504
     int mmco_reset;
505 505
 
506
-    int long_ref_count;  ///< number of actual long term references
507
-    int short_ref_count; ///< number of actual short term references
506
+    int long_ref_count;     ///< number of actual long term references
507
+    int short_ref_count;    ///< number of actual short term references
508 508
 
509
-    int          cabac_init_idc;
509
+    int cabac_init_idc;
510 510
 
511 511
     /**
512 512
      * @name Members for slice based multithreading
... ...
@@ -582,12 +580,12 @@ typedef struct H264Context{
582 582
      */
583 583
     int recovery_frame;
584 584
 
585
-    int luma_weight_flag[2];   ///< 7.4.3.2 luma_weight_lX_flag
586
-    int chroma_weight_flag[2]; ///< 7.4.3.2 chroma_weight_lX_flag
585
+    int luma_weight_flag[2];    ///< 7.4.3.2 luma_weight_lX_flag
586
+    int chroma_weight_flag[2];  ///< 7.4.3.2 chroma_weight_lX_flag
587 587
 
588 588
     // Timestamp stuff
589
-    int sei_buffering_period_present;  ///< Buffering period SEI flag
590
-    int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs
589
+    int sei_buffering_period_present;   ///< Buffering period SEI flag
590
+    int initial_cpb_removal_delay[32];  ///< Initial timestamps for CPBs
591 591
 
592 592
     int cur_chroma_format_idc;
593 593
 
... ...
@@ -598,10 +596,9 @@ typedef struct H264Context{
598 598
     uint8_t parse_history[4];
599 599
     int parse_history_count;
600 600
     int parse_last_mb;
601
-}H264Context;
602
-
601
+} H264Context;
603 602
 
604
-extern const uint8_t ff_h264_chroma_qp[5][QP_MAX_NUM+1]; ///< One chroma qp table for each possible bit depth (8-12).
603
+extern const uint8_t ff_h264_chroma_qp[5][QP_MAX_NUM + 1]; ///< One chroma qp table for each possible bit depth (8-12).
605 604
 extern const uint16_t ff_h264_mb_sizes[4];
606 605
 
607 606
 /**
... ...
@@ -628,13 +625,16 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length);
628 628
  * Decode a network abstraction layer unit.
629 629
  * @param consumed is the number of bytes used as input
630 630
  * @param length is the length of the array
631
- * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp tailing?
631
+ * @param dst_length is the number of decoded bytes FIXME here
632
+ *                   or a decode rbsp tailing?
632 633
  * @return decoded bytes, might be src+1 if no escapes
633 634
  */
634
-const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length);
635
+const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src,
636
+                                  int *dst_length, int *consumed, int length);
635 637
 
636 638
 /**
637
- * Free any data that may have been allocated in the H264 context like SPS, PPS etc.
639
+ * Free any data that may have been allocated in the H264 context
640
+ * like SPS, PPS etc.
638 641
  */
639 642
 av_cold void ff_h264_free_context(H264Context *h);
640 643
 
... ...
@@ -667,12 +667,16 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb);
667 667
 
668 668
 void ff_generate_sliding_window_mmcos(H264Context *h);
669 669
 
670
-
671 670
 /**
672
- * Check if the top & left blocks are available if needed & change the dc mode so it only uses the available blocks.
671
+ * Check if the top & left blocks are available if needed & change the
672
+ * dc mode so it only uses the available blocks.
673 673
  */
674 674
 int ff_h264_check_intra4x4_pred_mode(H264Context *h);
675 675
 
676
+/**
677
+ * Check if the top & left blocks are available if needed & change the
678
+ * dc mode so it only uses the available blocks.
679
+ */
676 680
 int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma);
677 681
 
678 682
 void ff_h264_hl_decode_mb(H264Context *h);
... ...
@@ -683,24 +687,28 @@ av_cold void ff_h264_decode_init_vlc(void);
683 683
 
684 684
 /**
685 685
  * Decode a macroblock
686
- * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed
686
+ * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR on error
687 687
  */
688 688
 int ff_h264_decode_mb_cavlc(H264Context *h);
689 689
 
690 690
 /**
691 691
  * Decode a CABAC coded macroblock
692
- * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed
692
+ * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR on error
693 693
  */
694 694
 int ff_h264_decode_mb_cabac(H264Context *h);
695 695
 
696 696
 void ff_h264_init_cabac_states(H264Context *h);
697 697
 
698
-void ff_h264_direct_dist_scale_factor(H264Context * const h);
699
-void ff_h264_direct_ref_list_init(H264Context * const h);
700
-void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type);
698
+void ff_h264_direct_dist_scale_factor(H264Context *const h);
699
+void ff_h264_direct_ref_list_init(H264Context *const h);
700
+void ff_h264_pred_direct_motion(H264Context *const h, int *mb_type);
701 701
 
702
-void ff_h264_filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize);
703
-void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize);
702
+void ff_h264_filter_mb_fast(H264Context *h, int mb_x, int mb_y,
703
+                            uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
704
+                            unsigned int linesize, unsigned int uvlinesize);
705
+void ff_h264_filter_mb(H264Context *h, int mb_x, int mb_y,
706
+                       uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
707
+                       unsigned int linesize, unsigned int uvlinesize);
704 708
 
705 709
 /**
706 710
  * Reset SEI values at the beginning of the frame.
... ...
@@ -709,16 +717,15 @@ void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint
709 709
  */
710 710
 void ff_h264_reset_sei(H264Context *h);
711 711
 
712
-
713 712
 /*
714
-o-o o-o
715
- / / /
716
-o-o o-o
717
- ,---'
718
-o-o o-o
719
- / / /
720
-o-o o-o
721
-*/
713
+ * o-o o-o
714
+ *  / / /
715
+ * o-o o-o
716
+ *  ,---'
717
+ * o-o o-o
718
+ *  / / /
719
+ * o-o o-o
720
+ */
722 721
 
723 722
 /* Scan8 organization:
724 723
  *    0 1 2 3 4 5 6 7
... ...
@@ -743,156 +750,173 @@ o-o o-o
743 743
 #define LUMA_DC_BLOCK_INDEX   48
744 744
 #define CHROMA_DC_BLOCK_INDEX 49
745 745
 
746
-//This table must be here because scan8[constant] must be known at compiletime
747
-static const uint8_t scan8[16*3 + 3]={
748
- 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8,
749
- 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8,
750
- 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8,
751
- 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8,
752
- 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8,
753
- 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8,
754
- 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8,
755
- 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8,
756
- 4+11*8, 5+11*8, 4+12*8, 5+12*8,
757
- 6+11*8, 7+11*8, 6+12*8, 7+12*8,
758
- 4+13*8, 5+13*8, 4+14*8, 5+14*8,
759
- 6+13*8, 7+13*8, 6+14*8, 7+14*8,
760
- 0+ 0*8, 0+ 5*8, 0+10*8
746
+// This table must be here because scan8[constant] must be known at compiletime
747
+static const uint8_t scan8[16 * 3 + 3] = {
748
+    4 +  1 * 8, 5 +  1 * 8, 4 +  2 * 8, 5 +  2 * 8,
749
+    6 +  1 * 8, 7 +  1 * 8, 6 +  2 * 8, 7 +  2 * 8,
750
+    4 +  3 * 8, 5 +  3 * 8, 4 +  4 * 8, 5 +  4 * 8,
751
+    6 +  3 * 8, 7 +  3 * 8, 6 +  4 * 8, 7 +  4 * 8,
752
+    4 +  6 * 8, 5 +  6 * 8, 4 +  7 * 8, 5 +  7 * 8,
753
+    6 +  6 * 8, 7 +  6 * 8, 6 +  7 * 8, 7 +  7 * 8,
754
+    4 +  8 * 8, 5 +  8 * 8, 4 +  9 * 8, 5 +  9 * 8,
755
+    6 +  8 * 8, 7 +  8 * 8, 6 +  9 * 8, 7 +  9 * 8,
756
+    4 + 11 * 8, 5 + 11 * 8, 4 + 12 * 8, 5 + 12 * 8,
757
+    6 + 11 * 8, 7 + 11 * 8, 6 + 12 * 8, 7 + 12 * 8,
758
+    4 + 13 * 8, 5 + 13 * 8, 4 + 14 * 8, 5 + 14 * 8,
759
+    6 + 13 * 8, 7 + 13 * 8, 6 + 14 * 8, 7 + 14 * 8,
760
+    0 +  0 * 8, 0 +  5 * 8, 0 + 10 * 8
761 761
 };
762 762
 
763
-static av_always_inline uint32_t pack16to32(int a, int b){
763
+static av_always_inline uint32_t pack16to32(int a, int b)
764
+{
764 765
 #if HAVE_BIGENDIAN
765
-   return (b&0xFFFF) + (a<<16);
766
+    return (b & 0xFFFF) + (a << 16);
766 767
 #else
767
-   return (a&0xFFFF) + (b<<16);
768
+    return (a & 0xFFFF) + (b << 16);
768 769
 #endif
769 770
 }
770 771
 
771
-static av_always_inline uint16_t pack8to16(int a, int b){
772
+static av_always_inline uint16_t pack8to16(int a, int b)
773
+{
772 774
 #if HAVE_BIGENDIAN
773
-   return (b&0xFF) + (a<<8);
775
+    return (b & 0xFF) + (a << 8);
774 776
 #else
775
-   return (a&0xFF) + (b<<8);
777
+    return (a & 0xFF) + (b << 8);
776 778
 #endif
777 779
 }
778 780
 
779 781
 /**
780 782
  * Get the chroma qp.
781 783
  */
782
-static av_always_inline int get_chroma_qp(H264Context *h, int t, int qscale){
784
+static av_always_inline int get_chroma_qp(H264Context *h, int t, int qscale)
785
+{
783 786
     return h->pps.chroma_qp_table[t][qscale];
784 787
 }
785 788
 
786 789
 /**
787 790
  * Get the predicted intra4x4 prediction mode.
788 791
  */
789
-static av_always_inline int pred_intra_mode(H264Context *h, int n){
790
-    const int index8= scan8[n];
791
-    const int left= h->intra4x4_pred_mode_cache[index8 - 1];
792
-    const int top = h->intra4x4_pred_mode_cache[index8 - 8];
793
-    const int min= FFMIN(left, top);
792
+static av_always_inline int pred_intra_mode(H264Context *h, int n)
793
+{
794
+    const int index8 = scan8[n];
795
+    const int left   = h->intra4x4_pred_mode_cache[index8 - 1];
796
+    const int top    = h->intra4x4_pred_mode_cache[index8 - 8];
797
+    const int min    = FFMIN(left, top);
794 798
 
795
-    tprintf(h->s.avctx, "mode:%d %d min:%d\n", left ,top, min);
799
+    tprintf(h->s.avctx, "mode:%d %d min:%d\n", left, top, min);
796 800
 
797
-    if(min<0) return DC_PRED;
798
-    else      return min;
801
+    if (min < 0)
802
+        return DC_PRED;
803
+    else
804
+        return min;
799 805
 }
800 806
 
801
-static av_always_inline void write_back_intra_pred_mode(H264Context *h){
802
-    int8_t *i4x4= h->intra4x4_pred_mode + h->mb2br_xy[h->mb_xy];
803
-    int8_t *i4x4_cache= h->intra4x4_pred_mode_cache;
807
+static av_always_inline void write_back_intra_pred_mode(H264Context *h)
808
+{
809
+    int8_t *i4x4       = h->intra4x4_pred_mode + h->mb2br_xy[h->mb_xy];
810
+    int8_t *i4x4_cache = h->intra4x4_pred_mode_cache;
804 811
 
805
-    AV_COPY32(i4x4, i4x4_cache + 4 + 8*4);
806
-    i4x4[4]= i4x4_cache[7+8*3];
807
-    i4x4[5]= i4x4_cache[7+8*2];
808
-    i4x4[6]= i4x4_cache[7+8*1];
812
+    AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
813
+    i4x4[4] = i4x4_cache[7 + 8 * 3];
814
+    i4x4[5] = i4x4_cache[7 + 8 * 2];
815
+    i4x4[6] = i4x4_cache[7 + 8 * 1];
809 816
 }
810 817
 
811
-static av_always_inline void write_back_non_zero_count(H264Context *h){
812
-    const int mb_xy= h->mb_xy;
813
-    uint8_t *nnz = h->non_zero_count[mb_xy];
818
+static av_always_inline void write_back_non_zero_count(H264Context *h)
819
+{
820
+    const int mb_xy    = h->mb_xy;
821
+    uint8_t *nnz       = h->non_zero_count[mb_xy];
814 822
     uint8_t *nnz_cache = h->non_zero_count_cache;
815 823
 
816
-    AV_COPY32(&nnz[ 0], &nnz_cache[4+8* 1]);
817
-    AV_COPY32(&nnz[ 4], &nnz_cache[4+8* 2]);
818
-    AV_COPY32(&nnz[ 8], &nnz_cache[4+8* 3]);
819
-    AV_COPY32(&nnz[12], &nnz_cache[4+8* 4]);
820
-    AV_COPY32(&nnz[16], &nnz_cache[4+8* 6]);
821
-    AV_COPY32(&nnz[20], &nnz_cache[4+8* 7]);
822
-    AV_COPY32(&nnz[32], &nnz_cache[4+8*11]);
823
-    AV_COPY32(&nnz[36], &nnz_cache[4+8*12]);
824
-
825
-    if(!h->s.chroma_y_shift){
826
-        AV_COPY32(&nnz[24], &nnz_cache[4+8* 8]);
827
-        AV_COPY32(&nnz[28], &nnz_cache[4+8* 9]);
828
-        AV_COPY32(&nnz[40], &nnz_cache[4+8*13]);
829
-        AV_COPY32(&nnz[44], &nnz_cache[4+8*14]);
824
+    AV_COPY32(&nnz[ 0], &nnz_cache[4 + 8 * 1]);
825
+    AV_COPY32(&nnz[ 4], &nnz_cache[4 + 8 * 2]);
826
+    AV_COPY32(&nnz[ 8], &nnz_cache[4 + 8 * 3]);
827
+    AV_COPY32(&nnz[12], &nnz_cache[4 + 8 * 4]);
828
+    AV_COPY32(&nnz[16], &nnz_cache[4 + 8 * 6]);
829
+    AV_COPY32(&nnz[20], &nnz_cache[4 + 8 * 7]);
830
+    AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]);
831
+    AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]);
832
+
833
+    if (!h->s.chroma_y_shift) {
834
+        AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]);
835
+        AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]);
836
+        AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]);
837
+        AV_COPY32(&nnz[44], &nnz_cache[4 + 8 * 14]);
830 838
     }
831 839
 }
832 840
 
833
-static av_always_inline void write_back_motion_list(H264Context *h, MpegEncContext * const s, int b_stride,
834
-                                                    int b_xy, int b8_xy, int mb_type, int list )
841
+static av_always_inline void write_back_motion_list(H264Context *h,
842
+                                                    MpegEncContext *const s,
843
+                                                    int b_stride,
844
+                                                    int b_xy, int b8_xy,
845
+                                                    int mb_type, int list)
835 846
 {
836
-    int16_t (*mv_dst)[2] = &s->current_picture.f.motion_val[list][b_xy];
837
-    int16_t (*mv_src)[2] = &h->mv_cache[list][scan8[0]];
838
-    AV_COPY128(mv_dst + 0*b_stride, mv_src + 8*0);
839
-    AV_COPY128(mv_dst + 1*b_stride, mv_src + 8*1);
840
-    AV_COPY128(mv_dst + 2*b_stride, mv_src + 8*2);
841
-    AV_COPY128(mv_dst + 3*b_stride, mv_src + 8*3);
842
-    if( CABAC ) {
843
-        uint8_t (*mvd_dst)[2] = &h->mvd_table[list][FMO ? 8*h->mb_xy : h->mb2br_xy[h->mb_xy]];
844
-        uint8_t (*mvd_src)[2] = &h->mvd_cache[list][scan8[0]];
845
-        if(IS_SKIP(mb_type))
847
+    int16_t(*mv_dst)[2] = &s->current_picture.f.motion_val[list][b_xy];
848
+    int16_t(*mv_src)[2] = &h->mv_cache[list][scan8[0]];
849
+    AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0);
850
+    AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1);
851
+    AV_COPY128(mv_dst + 2 * b_stride, mv_src + 8 * 2);
852
+    AV_COPY128(mv_dst + 3 * b_stride, mv_src + 8 * 3);
853
+    if (CABAC) {
854
+        uint8_t (*mvd_dst)[2] = &h->mvd_table[list][FMO ? 8 * h->mb_xy
855
+                                                        : h->mb2br_xy[h->mb_xy]];
856
+        uint8_t(*mvd_src)[2]  = &h->mvd_cache[list][scan8[0]];
857
+        if (IS_SKIP(mb_type)) {
846 858
             AV_ZERO128(mvd_dst);
847
-        else{
848
-            AV_COPY64(mvd_dst, mvd_src + 8*3);
849
-            AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8*0);
850
-            AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8*1);
851
-            AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8*2);
859
+        } else {
860
+            AV_COPY64(mvd_dst, mvd_src + 8 * 3);
861
+            AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8 * 0);
862
+            AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8 * 1);
863
+            AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8 * 2);
852 864
         }
853 865
     }
854 866
 
855 867
     {
856 868
         int8_t *ref_index = &s->current_picture.f.ref_index[list][b8_xy];
857 869
         int8_t *ref_cache = h->ref_cache[list];
858
-        ref_index[0+0*2]= ref_cache[scan8[0]];
859
-        ref_index[1+0*2]= ref_cache[scan8[4]];
860
-        ref_index[0+1*2]= ref_cache[scan8[8]];
861
-        ref_index[1+1*2]= ref_cache[scan8[12]];
870
+        ref_index[0 + 0 * 2] = ref_cache[scan8[0]];
871
+        ref_index[1 + 0 * 2] = ref_cache[scan8[4]];
872
+        ref_index[0 + 1 * 2] = ref_cache[scan8[8]];
873
+        ref_index[1 + 1 * 2] = ref_cache[scan8[12]];
862 874
     }
863 875
 }
864 876
 
865
-static av_always_inline void write_back_motion(H264Context *h, int mb_type){
866
-    MpegEncContext * const s = &h->s;
867
-    const int b_stride = h->b_stride;
868
-    const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; //try mb2b(8)_xy
869
-    const int b8_xy= 4*h->mb_xy;
877
+static av_always_inline void write_back_motion(H264Context *h, int mb_type)
878
+{
879
+    MpegEncContext *const s = &h->s;
880
+    const int b_stride      = h->b_stride;
881
+    const int b_xy  = 4 * s->mb_x + 4 * s->mb_y * h->b_stride; // try mb2b(8)_xy
882
+    const int b8_xy = 4 * h->mb_xy;
870 883
 
871
-    if(USES_LIST(mb_type, 0)){
884
+    if (USES_LIST(mb_type, 0)) {
872 885
         write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 0);
873
-    }else{
886
+    } else {
874 887
         fill_rectangle(&s->current_picture.f.ref_index[0][b8_xy],
875 888
                        2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
876 889
     }
877
-    if(USES_LIST(mb_type, 1)){
890
+    if (USES_LIST(mb_type, 1))
878 891
         write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 1);
879
-    }
880 892
 
881
-    if(h->slice_type_nos == AV_PICTURE_TYPE_B && CABAC){
882
-        if(IS_8X8(mb_type)){
883
-            uint8_t *direct_table = &h->direct_table[4*h->mb_xy];
884
-            direct_table[1] = h->sub_mb_type[1]>>1;
885
-            direct_table[2] = h->sub_mb_type[2]>>1;
886
-            direct_table[3] = h->sub_mb_type[3]>>1;
893
+    if (h->slice_type_nos == AV_PICTURE_TYPE_B && CABAC) {
894
+        if (IS_8X8(mb_type)) {
895
+            uint8_t *direct_table = &h->direct_table[4 * h->mb_xy];
896
+            direct_table[1] = h->sub_mb_type[1] >> 1;
897
+            direct_table[2] = h->sub_mb_type[2] >> 1;
898
+            direct_table[3] = h->sub_mb_type[3] >> 1;
887 899
         }
888 900
     }
889 901
 }
890 902
 
891
-static av_always_inline int get_dct8x8_allowed(H264Context *h){
892
-    if(h->sps.direct_8x8_inference_flag)
893
-        return !(AV_RN64A(h->sub_mb_type) & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8                )*0x0001000100010001ULL));
903
+static av_always_inline int get_dct8x8_allowed(H264Context *h)
904
+{
905
+    if (h->sps.direct_8x8_inference_flag)
906
+        return !(AV_RN64A(h->sub_mb_type) &
907
+                 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8) *
908
+                  0x0001000100010001ULL));
894 909
     else
895
-        return !(AV_RN64A(h->sub_mb_type) & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8|MB_TYPE_DIRECT2)*0x0001000100010001ULL));
910
+        return !(AV_RN64A(h->sub_mb_type) &
911
+                 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8 | MB_TYPE_DIRECT2) *
912
+                  0x0001000100010001ULL));
896 913
 }
897 914
 
898 915
 #endif /* AVCODEC_H264_H */
... ...
@@ -35,53 +35,53 @@
35 35
 //#undef NDEBUG
36 36
 #include <assert.h>
37 37
 
38
-static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){
39
-    const int topright_ref= h->ref_cache[list][ i - 8 + part_width ];
40
-    MpegEncContext *s = &h->s;
38
+static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C,
39
+                                              int i, int list, int part_width)
40
+{
41
+    const int topright_ref = h->ref_cache[list][i - 8 + part_width];
42
+    MpegEncContext *s      = &h->s;
41 43
 
42 44
     /* there is no consistent mapping of mvs to neighboring locations that will
43 45
      * make mbaff happy, so we can't move all this logic to fill_caches */
44
-    if(FRAME_MBAFF){
45
-
46
-#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)\
47
-                const int xy = XY, y4 = Y4;\
48
-                const int mb_type = mb_types[xy+(y4>>2)*s->mb_stride];\
49
-                if(!USES_LIST(mb_type,list))\
50
-                    return LIST_NOT_USED;\
51
-                mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4*h->b_stride];\
52
-                h->mv_cache[list][scan8[0]-2][0] = mv[0];\
53
-                h->mv_cache[list][scan8[0]-2][1] = mv[1] MV_OP;\
54
-                return s->current_picture_ptr->f.ref_index[list][4*xy + 1 + (y4 & ~1)] REF_OP;
55
-
56
-        if(topright_ref == PART_NOT_AVAILABLE
57
-           && i >= scan8[0]+8 && (i&7)==4
58
-           && h->ref_cache[list][scan8[0]-1] != PART_NOT_AVAILABLE){
46
+    if (FRAME_MBAFF) {
47
+#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)                              \
48
+        const int xy = XY, y4 = Y4;                                     \
49
+        const int mb_type = mb_types[xy + (y4 >> 2) * s->mb_stride];    \
50
+        if (!USES_LIST(mb_type, list))                                  \
51
+            return LIST_NOT_USED;                                       \
52
+        mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
53
+        h->mv_cache[list][scan8[0] - 2][0] = mv[0];                     \
54
+        h->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP;               \
55
+        return s->current_picture_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
56
+
57
+        if (topright_ref == PART_NOT_AVAILABLE
58
+            && i >= scan8[0] + 8 && (i & 7) == 4
59
+            && h->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) {
59 60
             const uint32_t *mb_types = s->current_picture_ptr->f.mb_type;
60 61
             const int16_t *mv;
61
-            AV_ZERO32(h->mv_cache[list][scan8[0]-2]);
62
-            *C = h->mv_cache[list][scan8[0]-2];
62
+            AV_ZERO32(h->mv_cache[list][scan8[0] - 2]);
63
+            *C = h->mv_cache[list][scan8[0] - 2];
63 64
 
64
-            if(!MB_FIELD
65
-               && IS_INTERLACED(h->left_type[0])){
66
-                SET_DIAG_MV(*2, >>1, h->left_mb_xy[0]+s->mb_stride, (s->mb_y&1)*2+(i>>5));
65
+            if (!MB_FIELD && IS_INTERLACED(h->left_type[0])) {
66
+                SET_DIAG_MV(* 2, >> 1, h->left_mb_xy[0] + s->mb_stride,
67
+                            (s->mb_y & 1) * 2 + (i >> 5));
67 68
             }
68
-            if(MB_FIELD
69
-               && !IS_INTERLACED(h->left_type[0])){
69
+            if (MB_FIELD && !IS_INTERLACED(h->left_type[0])) {
70 70
                 // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
71
-                SET_DIAG_MV(/2, <<1, h->left_mb_xy[i>=36], ((i>>2))&3);
71
+                SET_DIAG_MV(/ 2, << 1, h->left_mb_xy[i >= 36], ((i >> 2)) & 3);
72 72
             }
73 73
         }
74 74
 #undef SET_DIAG_MV
75 75
     }
76 76
 
77
-    if(topright_ref != PART_NOT_AVAILABLE){
78
-        *C= h->mv_cache[list][ i - 8 + part_width ];
77
+    if (topright_ref != PART_NOT_AVAILABLE) {
78
+        *C = h->mv_cache[list][i - 8 + part_width];
79 79
         return topright_ref;
80
-    }else{
80
+    } else {
81 81
         tprintf(s->avctx, "topright MV not available\n");
82 82
 
83
-        *C= h->mv_cache[list][ i - 8 - 1 ];
84
-        return h->ref_cache[list][ i - 8 - 1 ];
83
+        *C = h->mv_cache[list][i - 8 - 1];
84
+        return h->ref_cache[list][i - 8 - 1];
85 85
     }
86 86
 }
87 87
 
... ...
@@ -92,53 +92,61 @@ static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C,
92 92
  * @param mx the x component of the predicted motion vector
93 93
  * @param my the y component of the predicted motion vector
94 94
  */
95
-static av_always_inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){
96
-    const int index8= scan8[n];
97
-    const int top_ref=      h->ref_cache[list][ index8 - 8 ];
98
-    const int left_ref=     h->ref_cache[list][ index8 - 1 ];
99
-    const int16_t * const A= h->mv_cache[list][ index8 - 1 ];
100
-    const int16_t * const B= h->mv_cache[list][ index8 - 8 ];
101
-    const int16_t * C;
95
+static av_always_inline void pred_motion(H264Context *const h, int n,
96
+                                         int part_width, int list, int ref,
97
+                                         int *const mx, int *const my)
98
+{
99
+    const int index8       = scan8[n];
100
+    const int top_ref      = h->ref_cache[list][index8 - 8];
101
+    const int left_ref     = h->ref_cache[list][index8 - 1];
102
+    const int16_t *const A = h->mv_cache[list][index8 - 1];
103
+    const int16_t *const B = h->mv_cache[list][index8 - 8];
104
+    const int16_t *C;
102 105
     int diagonal_ref, match_count;
103 106
 
104
-    assert(part_width==1 || part_width==2 || part_width==4);
107
+    assert(part_width == 1 || part_width == 2 || part_width == 4);
105 108
 
106 109
 /* mv_cache
107
-  B . . A T T T T
108
-  U . . L . . , .
109
-  U . . L . . . .
110
-  U . . L . . , .
111
-  . . . L . . . .
112
-*/
113
-
114
-    diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width);
115
-    match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref);
110
+ * B . . A T T T T
111
+ * U . . L . . , .
112
+ * U . . L . . . .
113
+ * U . . L . . , .
114
+ * . . . L . . . .
115
+ */
116
+
117
+    diagonal_ref = fetch_diagonal_mv(h, &C, index8, list, part_width);
118
+    match_count  = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
116 119
     tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count);
117
-    if(match_count > 1){ //most common
118
-        *mx= mid_pred(A[0], B[0], C[0]);
119
-        *my= mid_pred(A[1], B[1], C[1]);
120
-    }else if(match_count==1){
121
-        if(left_ref==ref){
122
-            *mx= A[0];
123
-            *my= A[1];
124
-        }else if(top_ref==ref){
125
-            *mx= B[0];
126
-            *my= B[1];
127
-        }else{
128
-            *mx= C[0];
129
-            *my= C[1];
120
+    if (match_count > 1) { //most common
121
+        *mx = mid_pred(A[0], B[0], C[0]);
122
+        *my = mid_pred(A[1], B[1], C[1]);
123
+    } else if (match_count == 1) {
124
+        if (left_ref == ref) {
125
+            *mx = A[0];
126
+            *my = A[1];
127
+        } else if (top_ref == ref) {
128
+            *mx = B[0];
129
+            *my = B[1];
130
+        } else {
131
+            *mx = C[0];
132
+            *my = C[1];
130 133
         }
131
-    }else{
132
-        if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){
133
-            *mx= A[0];
134
-            *my= A[1];
135
-        }else{
136
-            *mx= mid_pred(A[0], B[0], C[0]);
137
-            *my= mid_pred(A[1], B[1], C[1]);
134
+    } else {
135
+        if (top_ref      == PART_NOT_AVAILABLE &&
136
+            diagonal_ref == PART_NOT_AVAILABLE &&
137
+            left_ref     != PART_NOT_AVAILABLE) {
138
+            *mx = A[0];
139
+            *my = A[1];
140
+        } else {
141
+            *mx = mid_pred(A[0], B[0], C[0]);
142
+            *my = mid_pred(A[1], B[1], C[1]);
138 143
         }
139 144
     }
140 145
 
141
-    tprintf(h->s.avctx, "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);
146
+    tprintf(h->s.avctx,
147
+            "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
148
+            top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
149
+            A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list);
142 150
 }
143 151
 
144 152
 /**
... ...
@@ -147,27 +155,32 @@ static av_always_inline void pred_motion(H264Context * const h, int n, int part_
147 147
  * @param mx the x component of the predicted motion vector
148 148
  * @param my the y component of the predicted motion vector
149 149
  */
150
-static av_always_inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
151
-    if(n==0){
152
-        const int top_ref=      h->ref_cache[list][ scan8[0] - 8 ];
153
-        const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];
154
-
155
-        tprintf(h->s.avctx, "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);
156
-
157
-        if(top_ref == ref){
158
-            *mx= B[0];
159
-            *my= B[1];
150
+static av_always_inline void pred_16x8_motion(H264Context *const h,
151
+                                              int n, int list, int ref,
152
+                                              int *const mx, int *const my)
153
+{
154
+    if (n == 0) {
155
+        const int top_ref      = h->ref_cache[list][scan8[0] - 8];
156
+        const int16_t *const B = h->mv_cache[list][scan8[0] - 8];
157
+
158
+        tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
159
+                top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list);
160
+
161
+        if (top_ref == ref) {
162
+            *mx = B[0];
163
+            *my = B[1];
160 164
             return;
161 165
         }
162
-    }else{
163
-        const int left_ref=     h->ref_cache[list][ scan8[8] - 1 ];
164
-        const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ];
166
+    } else {
167
+        const int left_ref     = h->ref_cache[list][scan8[8] - 1];
168
+        const int16_t *const A = h->mv_cache[list][scan8[8] - 1];
165 169
 
166
-        tprintf(h->s.avctx, "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);
170
+        tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
171
+                left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list);
167 172
 
168
-        if(left_ref == ref){
169
-            *mx= A[0];
170
-            *my= A[1];
173
+        if (left_ref == ref) {
174
+            *mx = A[0];
175
+            *my = A[1];
171 176
             return;
172 177
         }
173 178
     }
... ...
@@ -182,29 +195,34 @@ static av_always_inline void pred_16x8_motion(H264Context * const h, int n, int
182 182
  * @param mx the x component of the predicted motion vector
183 183
  * @param my the y component of the predicted motion vector
184 184
  */
185
-static av_always_inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
186
-    if(n==0){
187
-        const int left_ref=      h->ref_cache[list][ scan8[0] - 1 ];
188
-        const int16_t * const A=  h->mv_cache[list][ scan8[0] - 1 ];
189
-
190
-        tprintf(h->s.avctx, "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);
191
-
192
-        if(left_ref == ref){
193
-            *mx= A[0];
194
-            *my= A[1];
185
+static av_always_inline void pred_8x16_motion(H264Context *const h,
186
+                                              int n, int list, int ref,
187
+                                              int *const mx, int *const my)
188
+{
189
+    if (n == 0) {
190
+        const int left_ref     = h->ref_cache[list][scan8[0] - 1];
191
+        const int16_t *const A = h->mv_cache[list][scan8[0] - 1];
192
+
193
+        tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
194
+                left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list);
195
+
196
+        if (left_ref == ref) {
197
+            *mx = A[0];
198
+            *my = A[1];
195 199
             return;
196 200
         }
197
-    }else{
198
-        const int16_t * C;
201
+    } else {
202
+        const int16_t *C;
199 203
         int diagonal_ref;
200 204
 
201
-        diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2);
205
+        diagonal_ref = fetch_diagonal_mv(h, &C, scan8[4], list, 2);
202 206
 
203
-        tprintf(h->s.avctx, "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);
207
+        tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
208
+                diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list);
204 209
 
205
-        if(diagonal_ref == ref){
206
-            *mx= C[0];
207
-            *my= C[1];
210
+        if (diagonal_ref == ref) {
211
+            *mx = C[0];
212
+            *my = C[1];
208 213
             return;
209 214
         }
210 215
     }
... ...
@@ -213,168 +231,174 @@ static av_always_inline void pred_8x16_motion(H264Context * const h, int n, int
213 213
     pred_motion(h, n, 2, list, ref, mx, my);
214 214
 }
215 215
 
216
-#define FIX_MV_MBAFF(type, refn, mvn, idx)\
217
-    if(FRAME_MBAFF){\
218
-        if(MB_FIELD){\
219
-            if(!IS_INTERLACED(type)){\
220
-                refn <<= 1;\
221
-                AV_COPY32(mvbuf[idx], mvn);\
222
-                mvbuf[idx][1] /= 2;\
223
-                mvn = mvbuf[idx];\
224
-            }\
225
-        }else{\
226
-            if(IS_INTERLACED(type)){\
227
-                refn >>= 1;\
228
-                AV_COPY32(mvbuf[idx], mvn);\
229
-                mvbuf[idx][1] <<= 1;\
230
-                mvn = mvbuf[idx];\
231
-            }\
232
-        }\
216
+#define FIX_MV_MBAFF(type, refn, mvn, idx)      \
217
+    if (FRAME_MBAFF) {                          \
218
+        if (MB_FIELD) {                         \
219
+            if (!IS_INTERLACED(type)) {         \
220
+                refn <<= 1;                     \
221
+                AV_COPY32(mvbuf[idx], mvn);     \
222
+                mvbuf[idx][1] /= 2;             \
223
+                mvn = mvbuf[idx];               \
224
+            }                                   \
225
+        } else {                                \
226
+            if (IS_INTERLACED(type)) {          \
227
+                refn >>= 1;                     \
228
+                AV_COPY32(mvbuf[idx], mvn);     \
229
+                mvbuf[idx][1] <<= 1;            \
230
+                mvn = mvbuf[idx];               \
231
+            }                                   \
232
+        }                                       \
233 233
     }
234 234
 
235
-static av_always_inline void pred_pskip_motion(H264Context * const h){
236
-    DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = {0};
235
+static av_always_inline void pred_pskip_motion(H264Context *const h)
236
+{
237
+    DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 };
237 238
     DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2];
238
-    MpegEncContext * const s = &h->s;
239
-    int8_t *ref      = s->current_picture.f.ref_index[0];
240
-    int16_t (*mv)[2] = s->current_picture.f.motion_val[0];
239
+    MpegEncContext *const s = &h->s;
240
+    int8_t *ref     = s->current_picture.f.ref_index[0];
241
+    int16_t(*mv)[2] = s->current_picture.f.motion_val[0];
241 242
     int top_ref, left_ref, diagonal_ref, match_count, mx, my;
242 243
     const int16_t *A, *B, *C;
243 244
     int b_stride = h->b_stride;
244 245
 
245 246
     fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
246 247
 
247
-    /* To avoid doing an entire fill_decode_caches, we inline the relevant parts here.
248
-     * FIXME: this is a partial duplicate of the logic in fill_decode_caches, but it's
249
-     * faster this way.  Is there a way to avoid this duplication?
248
+    /* To avoid doing an entire fill_decode_caches, we inline the relevant
249
+     * parts here.
250
+     * FIXME: this is a partial duplicate of the logic in fill_decode_caches,
251
+     * but it's faster this way.  Is there a way to avoid this duplication?
250 252
      */
251
-    if(USES_LIST(h->left_type[LTOP], 0)){
252
-        left_ref = ref[4*h->left_mb_xy[LTOP] + 1 + (h->left_block[0]&~1)];
253
-        A = mv[h->mb2b_xy[h->left_mb_xy[LTOP]] + 3 + b_stride*h->left_block[0]];
253
+    if (USES_LIST(h->left_type[LTOP], 0)) {
254
+        left_ref = ref[4 * h->left_mb_xy[LTOP] + 1 + (h->left_block[0] & ~1)];
255
+        A = mv[h->mb2b_xy[h->left_mb_xy[LTOP]] + 3 + b_stride * h->left_block[0]];
254 256
         FIX_MV_MBAFF(h->left_type[LTOP], left_ref, A, 0);
255
-        if(!(left_ref | AV_RN32A(A))){
257
+        if (!(left_ref | AV_RN32A(A)))
256 258
             goto zeromv;
257
-        }
258
-    }else if(h->left_type[LTOP]){
259
+    } else if (h->left_type[LTOP]) {
259 260
         left_ref = LIST_NOT_USED;
260
-        A = zeromv;
261
-    }else{
261
+        A        = zeromv;
262
+    } else {
262 263
         goto zeromv;
263 264
     }
264 265
 
265
-    if(USES_LIST(h->top_type, 0)){
266
-        top_ref = ref[4*h->top_mb_xy + 2];
267
-        B = mv[h->mb2b_xy[h->top_mb_xy] + 3*b_stride];
266
+    if (USES_LIST(h->top_type, 0)) {
267
+        top_ref = ref[4 * h->top_mb_xy + 2];
268
+        B       = mv[h->mb2b_xy[h->top_mb_xy] + 3 * b_stride];
268 269
         FIX_MV_MBAFF(h->top_type, top_ref, B, 1);
269
-        if(!(top_ref | AV_RN32A(B))){
270
+        if (!(top_ref | AV_RN32A(B)))
270 271
             goto zeromv;
271
-        }
272
-    }else if(h->top_type){
272
+    } else if (h->top_type) {
273 273
         top_ref = LIST_NOT_USED;
274
-        B = zeromv;
275
-    }else{
274
+        B       = zeromv;
275
+    } else {
276 276
         goto zeromv;
277 277
     }
278 278
 
279
-    tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y);
279
+    tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n",
280
+            top_ref, left_ref, h->s.mb_x, h->s.mb_y);
280 281
 
281
-    if(USES_LIST(h->topright_type, 0)){
282
-        diagonal_ref = ref[4*h->topright_mb_xy + 2];
283
-        C = mv[h->mb2b_xy[h->topright_mb_xy] + 3*b_stride];
282
+    if (USES_LIST(h->topright_type, 0)) {
283
+        diagonal_ref = ref[4 * h->topright_mb_xy + 2];
284
+        C = mv[h->mb2b_xy[h->topright_mb_xy] + 3 * b_stride];
284 285
         FIX_MV_MBAFF(h->topright_type, diagonal_ref, C, 2);
285
-    }else if(h->topright_type){
286
+    } else if (h->topright_type) {
286 287
         diagonal_ref = LIST_NOT_USED;
287 288
         C = zeromv;
288
-    }else{
289
-        if(USES_LIST(h->topleft_type, 0)){
290
-            diagonal_ref = ref[4*h->topleft_mb_xy + 1 + (h->topleft_partition & 2)];
291
-            C = mv[h->mb2b_xy[h->topleft_mb_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride)];
289
+    } else {
290
+        if (USES_LIST(h->topleft_type, 0)) {
291
+            diagonal_ref = ref[4 * h->topleft_mb_xy + 1 +
292
+                               (h->topleft_partition & 2)];
293
+            C = mv[h->mb2b_xy[h->topleft_mb_xy] + 3 + b_stride +
294
+                   (h->topleft_partition & 2 * b_stride)];
292 295
             FIX_MV_MBAFF(h->topleft_type, diagonal_ref, C, 2);
293
-        }else if(h->topleft_type){
296
+        } else if (h->topleft_type) {
294 297
             diagonal_ref = LIST_NOT_USED;
295
-            C = zeromv;
296
-        }else{
298
+            C            = zeromv;
299
+        } else {
297 300
             diagonal_ref = PART_NOT_AVAILABLE;
298
-            C = zeromv;
301
+            C            = zeromv;
299 302
         }
300 303
     }
301 304
 
302
-    match_count= !diagonal_ref + !top_ref + !left_ref;
305
+    match_count = !diagonal_ref + !top_ref + !left_ref;
303 306
     tprintf(h->s.avctx, "pred_pskip_motion match_count=%d\n", match_count);
304
-    if(match_count > 1){
307
+    if (match_count > 1) {
305 308
         mx = mid_pred(A[0], B[0], C[0]);
306 309
         my = mid_pred(A[1], B[1], C[1]);
307
-    }else if(match_count==1){
308
-        if(!left_ref){
310
+    } else if (match_count == 1) {
311
+        if (!left_ref) {
309 312
             mx = A[0];
310 313
             my = A[1];
311
-        }else if(!top_ref){
314
+        } else if (!top_ref) {
312 315
             mx = B[0];
313 316
             my = B[1];
314
-        }else{
317
+        } else {
315 318
             mx = C[0];
316 319
             my = C[1];
317 320
         }
318
-    }else{
321
+    } else {
319 322
         mx = mid_pred(A[0], B[0], C[0]);
320 323
         my = mid_pred(A[1], B[1], C[1]);
321 324
     }
322 325
 
323
-    fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4);
326
+    fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx, my), 4);
324 327
     return;
328
+
325 329
 zeromv:
326
-    fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
330
+    fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
327 331
     return;
328 332
 }
329 333
 
330
-static void fill_decode_neighbors(H264Context *h, int mb_type){
331
-    MpegEncContext * const s = &h->s;
332
-    const int mb_xy= h->mb_xy;
334
+static void fill_decode_neighbors(H264Context *h, int mb_type)
335
+{
336
+    MpegEncContext *const s = &h->s;
337
+    const int mb_xy = h->mb_xy;
333 338
     int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
334
-    static const uint8_t left_block_options[4][32]={
335
-        {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4},
336
-        {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4},
337
-        {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4},
338
-        {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}
339
+    static const uint8_t left_block_options[4][32] = {
340
+        { 0, 1, 2, 3, 7, 10, 8, 11, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 5 * 4, 1 + 9 * 4 },
341
+        { 2, 2, 3, 3, 8, 11, 8, 11, 3 + 2 * 4, 3 + 2 * 4, 3 + 3 * 4, 3 + 3 * 4, 1 + 5 * 4, 1 + 9 * 4, 1 + 5 * 4, 1 + 9 * 4 },
342
+        { 0, 0, 1, 1, 7, 10, 7, 10, 3 + 0 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 1 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 },
343
+        { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 }
339 344
     };
340 345
 
341
-    h->topleft_partition= -1;
346
+    h->topleft_partition = -1;
342 347
 
343
-    top_xy     = mb_xy  - (s->mb_stride << MB_FIELD);
348
+    top_xy = mb_xy - (s->mb_stride << MB_FIELD);
344 349
 
345 350
     /* Wow, what a mess, why didn't they simplify the interlacing & intra
346 351
      * stuff, I can't imagine that these complex rules are worth it. */
347 352
 
348
-    topleft_xy = top_xy - 1;
349
-    topright_xy= top_xy + 1;
350
-    left_xy[LBOT] = left_xy[LTOP] = mb_xy-1;
353
+    topleft_xy    = top_xy - 1;
354
+    topright_xy   = top_xy + 1;
355
+    left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;
351 356
     h->left_block = left_block_options[0];
352
-    if(FRAME_MBAFF){
357
+    if (FRAME_MBAFF) {
353 358
         const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]);
354 359
         const int curr_mb_field_flag = IS_INTERLACED(mb_type);
355
-        if(s->mb_y&1){
360
+        if (s->mb_y & 1) {
356 361
             if (left_mb_field_flag != curr_mb_field_flag) {
357 362
                 left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1;
358 363
                 if (curr_mb_field_flag) {
359 364
                     left_xy[LBOT] += s->mb_stride;
360
-                    h->left_block = left_block_options[3];
365
+                    h->left_block  = left_block_options[3];
361 366
                 } else {
362 367
                     topleft_xy += s->mb_stride;
363
-                    // take top left mv from the middle of the mb, as opposed to all other modes which use the bottom right partition
368
+                    /* take top left mv from the middle of the mb, as opposed
369
+                     * to all other modes which use the bottom right partition */
364 370
                     h->topleft_partition = 0;
365
-                    h->left_block = left_block_options[1];
371
+                    h->left_block        = left_block_options[1];
366 372
                 }
367 373
             }
368
-        }else{
369
-            if(curr_mb_field_flag){
374
+        } else {
375
+            if (curr_mb_field_flag) {
370 376
                 topleft_xy  += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1);
371 377
                 topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1);
372
-                top_xy      += s->mb_stride & (((s->current_picture.f.mb_type[top_xy    ] >> 7) & 1) - 1);
378
+                top_xy      += s->mb_stride & (((s->current_picture.f.mb_type[top_xy]     >> 7) & 1) - 1);
373 379
             }
374 380
             if (left_mb_field_flag != curr_mb_field_flag) {
375 381
                 if (curr_mb_field_flag) {
376 382
                     left_xy[LBOT] += s->mb_stride;
377
-                    h->left_block = left_block_options[3];
383
+                    h->left_block  = left_block_options[3];
378 384
                 } else {
379 385
                     h->left_block = left_block_options[2];
380 386
                 }
... ...
@@ -382,9 +406,9 @@ static void fill_decode_neighbors(H264Context *h, int mb_type){
382 382
         }
383 383
     }
384 384
 
385
-    h->topleft_mb_xy = topleft_xy;
386
-    h->top_mb_xy     = top_xy;
387
-    h->topright_mb_xy= topright_xy;
385
+    h->topleft_mb_xy    = topleft_xy;
386
+    h->top_mb_xy        = top_xy;
387
+    h->topright_mb_xy   = topright_xy;
388 388
     h->left_mb_xy[LTOP] = left_xy[LTOP];
389 389
     h->left_mb_xy[LBOT] = left_xy[LBOT];
390 390
     //FIXME do we need all in the context?
... ...
@@ -395,351 +419,372 @@ static void fill_decode_neighbors(H264Context *h, int mb_type){
395 395
     h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]];
396 396
     h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]];
397 397
 
398
-    if(FMO){
399
-    if(h->slice_table[topleft_xy    ] != h->slice_num) h->topleft_type = 0;
400
-    if(h->slice_table[top_xy        ] != h->slice_num) h->top_type     = 0;
401
-    if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;
402
-    }else{
403
-        if(h->slice_table[topleft_xy ] != h->slice_num){
398
+    if (FMO) {
399
+        if (h->slice_table[topleft_xy] != h->slice_num)
400
+            h->topleft_type = 0;
401
+        if (h->slice_table[top_xy] != h->slice_num)
402
+            h->top_type = 0;
403
+        if (h->slice_table[left_xy[LTOP]] != h->slice_num)
404
+            h->left_type[LTOP] = h->left_type[LBOT] = 0;
405
+    } else {
406
+        if (h->slice_table[topleft_xy] != h->slice_num) {
404 407
             h->topleft_type = 0;
405
-            if(h->slice_table[top_xy        ] != h->slice_num) h->top_type     = 0;
406
-            if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;
408
+            if (h->slice_table[top_xy] != h->slice_num)
409
+                h->top_type = 0;
410
+            if (h->slice_table[left_xy[LTOP]] != h->slice_num)
411
+                h->left_type[LTOP] = h->left_type[LBOT] = 0;
407 412
         }
408 413
     }
409
-    if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;
414
+    if (h->slice_table[topright_xy] != h->slice_num)
415
+        h->topright_type = 0;
410 416
 }
411 417
 
412
-static void fill_decode_caches(H264Context *h, int mb_type){
413
-    MpegEncContext * const s = &h->s;
418
+static void fill_decode_caches(H264Context *h, int mb_type)
419
+{
420
+    MpegEncContext *const s = &h->s;
414 421
     int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
415 422
     int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
416
-    const uint8_t * left_block= h->left_block;
423
+    const uint8_t *left_block = h->left_block;
417 424
     int i;
418 425
     uint8_t *nnz;
419 426
     uint8_t *nnz_cache;
420 427
 
421
-    topleft_xy     = h->topleft_mb_xy;
422
-    top_xy         = h->top_mb_xy;
423
-    topright_xy    = h->topright_mb_xy;
424
-    left_xy[LTOP]  = h->left_mb_xy[LTOP];
425
-    left_xy[LBOT]  = h->left_mb_xy[LBOT];
426
-    topleft_type   = h->topleft_type;
427
-    top_type       = h->top_type;
428
-    topright_type  = h->topright_type;
429
-    left_type[LTOP]= h->left_type[LTOP];
430
-    left_type[LBOT]= h->left_type[LBOT];
431
-
432
-    if(!IS_SKIP(mb_type)){
433
-        if(IS_INTRA(mb_type)){
434
-            int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
435
-            h->topleft_samples_available=
436
-            h->top_samples_available=
437
-            h->left_samples_available= 0xFFFF;
438
-            h->topright_samples_available= 0xEEEA;
439
-
440
-            if(!(top_type & type_mask)){
441
-                h->topleft_samples_available= 0xB3FF;
442
-                h->top_samples_available= 0x33FF;
443
-                h->topright_samples_available= 0x26EA;
428
+    topleft_xy      = h->topleft_mb_xy;
429
+    top_xy          = h->top_mb_xy;
430
+    topright_xy     = h->topright_mb_xy;
431
+    left_xy[LTOP]   = h->left_mb_xy[LTOP];
432
+    left_xy[LBOT]   = h->left_mb_xy[LBOT];
433
+    topleft_type    = h->topleft_type;
434
+    top_type        = h->top_type;
435
+    topright_type   = h->topright_type;
436
+    left_type[LTOP] = h->left_type[LTOP];
437
+    left_type[LBOT] = h->left_type[LBOT];
438
+
439
+    if (!IS_SKIP(mb_type)) {
440
+        if (IS_INTRA(mb_type)) {
441
+            int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
442
+            h->topleft_samples_available      =
443
+                h->top_samples_available      =
444
+                    h->left_samples_available = 0xFFFF;
445
+            h->topright_samples_available     = 0xEEEA;
446
+
447
+            if (!(top_type & type_mask)) {
448
+                h->topleft_samples_available  = 0xB3FF;
449
+                h->top_samples_available      = 0x33FF;
450
+                h->topright_samples_available = 0x26EA;
444 451
             }
445
-            if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){
446
-                if(IS_INTERLACED(mb_type)){
447
-                    if(!(left_type[LTOP] & type_mask)){
448
-                        h->topleft_samples_available&= 0xDFFF;
449
-                        h->left_samples_available&= 0x5FFF;
452
+            if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {
453
+                if (IS_INTERLACED(mb_type)) {
454
+                    if (!(left_type[LTOP] & type_mask)) {
455
+                        h->topleft_samples_available &= 0xDFFF;
456
+                        h->left_samples_available    &= 0x5FFF;
450 457
                     }
451
-                    if(!(left_type[LBOT] & type_mask)){
452
-                        h->topleft_samples_available&= 0xFF5F;
453
-                        h->left_samples_available&= 0xFF5F;
458
+                    if (!(left_type[LBOT] & type_mask)) {
459
+                        h->topleft_samples_available &= 0xFF5F;
460
+                        h->left_samples_available    &= 0xFF5F;
454 461
                     }
455
-                }else{
462
+                } else {
456 463
                     int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride];
457 464
 
458 465
                     assert(left_xy[LTOP] == left_xy[LBOT]);
459
-                    if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){
460
-                        h->topleft_samples_available&= 0xDF5F;
461
-                        h->left_samples_available&= 0x5F5F;
466
+                    if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
467
+                        h->topleft_samples_available &= 0xDF5F;
468
+                        h->left_samples_available    &= 0x5F5F;
462 469
                     }
463 470
                 }
464
-            }else{
465
-                if(!(left_type[LTOP] & type_mask)){
466
-                    h->topleft_samples_available&= 0xDF5F;
467
-                    h->left_samples_available&= 0x5F5F;
471
+            } else {
472
+                if (!(left_type[LTOP] & type_mask)) {
473
+                    h->topleft_samples_available &= 0xDF5F;
474
+                    h->left_samples_available    &= 0x5F5F;
468 475
                 }
469 476
             }
470 477
 
471
-            if(!(topleft_type & type_mask))
472
-                h->topleft_samples_available&= 0x7FFF;
478
+            if (!(topleft_type & type_mask))
479
+                h->topleft_samples_available &= 0x7FFF;
473 480
 
474
-            if(!(topright_type & type_mask))
475
-                h->topright_samples_available&= 0xFBFF;
481
+            if (!(topright_type & type_mask))
482
+                h->topright_samples_available &= 0xFBFF;
476 483
 
477
-            if(IS_INTRA4x4(mb_type)){
478
-                if(IS_INTRA4x4(top_type)){
479
-                    AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
480
-                }else{
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]= 2 - 3*!(top_type & type_mask);
484
+            if (IS_INTRA4x4(mb_type)) {
485
+                if (IS_INTRA4x4(top_type)) {
486
+                    AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
487
+                } else {
488
+                    h->intra4x4_pred_mode_cache[4 + 8 * 0] =
489
+                    h->intra4x4_pred_mode_cache[5 + 8 * 0] =
490
+                    h->intra4x4_pred_mode_cache[6 + 8 * 0] =
491
+                    h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);
485 492
                 }
486
-                for(i=0; i<2; i++){
487
-                    if(IS_INTRA4x4(left_type[LEFT(i)])){
488
-                        int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
489
-                        h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];
490
-                        h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];
491
-                    }else{
492
-                        h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
493
-                        h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);
493
+                for (i = 0; i < 2; i++) {
494
+                    if (IS_INTRA4x4(left_type[LEFT(i)])) {
495
+                        int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
496
+                        h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];
497
+                        h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];
498
+                    } else {
499
+                        h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =
500
+                        h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);
494 501
                     }
495 502
                 }
496 503
             }
497 504
         }
498 505
 
499
-
500
-/*
501
-0 . T T. T T T T
502
-1 L . .L . . . .
503
-2 L . .L . . . .
504
-3 . T TL . . . .
505
-4 L . .L . . . .
506
-5 L . .. . . . .
507
-*/
508
-//FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec)
509
-    nnz_cache = h->non_zero_count_cache;
510
-    if(top_type){
511
-        nnz = h->non_zero_count[top_xy];
512
-        AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);
513
-        if(!s->chroma_y_shift){
514
-            AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);
515
-            AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);
516
-        }else{
517
-            AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);
518
-            AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);
506
+        /*
507
+         * 0 . T T. T T T T
508
+         * 1 L . .L . . . .
509
+         * 2 L . .L . . . .
510
+         * 3 . T TL . . . .
511
+         * 4 L . .L . . . .
512
+         * 5 L . .. . . . .
513
+         */
514
+        /* FIXME: constraint_intra_pred & partitioning & nnz
515
+         * (let us hope this is just a typo in the spec) */
516
+        nnz_cache = h->non_zero_count_cache;
517
+        if (top_type) {
518
+            nnz = h->non_zero_count[top_xy];
519
+            AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
520
+            if (!s->chroma_y_shift) {
521
+                AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 *  7]);
522
+                AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
523
+            } else {
524
+                AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 * 5]);
525
+                AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
526
+            }
527
+        } else {
528
+            uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
529
+            AV_WN32A(&nnz_cache[4 + 8 *  0], top_empty);
530
+            AV_WN32A(&nnz_cache[4 + 8 *  5], top_empty);
531
+            AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
519 532
         }
520
-    }else{
521
-        uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
522
-        AV_WN32A(&nnz_cache[4+8* 0], top_empty);
523
-        AV_WN32A(&nnz_cache[4+8* 5], top_empty);
524
-        AV_WN32A(&nnz_cache[4+8*10], top_empty);
525
-    }
526 533
 
527
-    for (i=0; i<2; i++) {
528
-        if(left_type[LEFT(i)]){
529
-            nnz = h->non_zero_count[left_xy[LEFT(i)]];
530
-            nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];
531
-            nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];
532
-            if(CHROMA444){
533
-                nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];
534
-                nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];
535
-                nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];
536
-                nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];
537
-            }else if(CHROMA422) {
538
-                nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]-2+4*4];
539
-                nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]-2+4*4];
540
-                nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]-2+8*4];
541
-                nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]-2+8*4];
542
-            }else{
543
-                nnz_cache[3+8* 6 +   8*i]= nnz[left_block[8+4+2*i]];
544
-                nnz_cache[3+8*11 +   8*i]= nnz[left_block[8+5+2*i]];
534
+        for (i = 0; i < 2; i++) {
535
+            if (left_type[LEFT(i)]) {
536
+                nnz = h->non_zero_count[left_xy[LEFT(i)]];
537
+                nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
538
+                nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
539
+                if (CHROMA444) {
540
+                    nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
541
+                    nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
542
+                    nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
543
+                    nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
544
+                } else if (CHROMA422) {
545
+                    nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
546
+                    nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
547
+                    nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
548
+                    nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
549
+                } else {
550
+                    nnz_cache[3 + 8 *  6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
551
+                    nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
552
+                }
553
+            } else {
554
+                nnz_cache[3 + 8 *  1 + 2 * 8 * i] =
555
+                nnz_cache[3 + 8 *  2 + 2 * 8 * i] =
556
+                nnz_cache[3 + 8 *  6 + 2 * 8 * i] =
557
+                nnz_cache[3 + 8 *  7 + 2 * 8 * i] =
558
+                nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
559
+                nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC && !IS_INTRA(mb_type) ? 0 : 64;
545 560
             }
546
-        }else{
547
-            nnz_cache[3+8* 1 + 2*8*i]=
548
-            nnz_cache[3+8* 2 + 2*8*i]=
549
-            nnz_cache[3+8* 6 + 2*8*i]=
550
-            nnz_cache[3+8* 7 + 2*8*i]=
551
-            nnz_cache[3+8*11 + 2*8*i]=
552
-            nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;
553 561
         }
554
-    }
555 562
 
556
-    if( CABAC ) {
557
-        // top_cbp
558
-        if(top_type) {
559
-            h->top_cbp = h->cbp_table[top_xy];
560
-        } else {
561
-            h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
562
-        }
563
-        // left_cbp
564
-        if (left_type[LTOP]) {
565
-            h->left_cbp =   (h->cbp_table[left_xy[LTOP]] & 0x7F0)
566
-                        |  ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)
567
-                        | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);
568
-        } else {
569
-            h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
563
+        if (CABAC) {
564
+            // top_cbp
565
+            if (top_type)
566
+                h->top_cbp = h->cbp_table[top_xy];
567
+            else
568
+                h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
569
+            // left_cbp
570
+            if (left_type[LTOP]) {
571
+                h->left_cbp =   (h->cbp_table[left_xy[LTOP]] & 0x7F0) |
572
+                               ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
573
+                              (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
574
+            } else {
575
+                h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
576
+            }
570 577
         }
571 578
     }
572
-    }
573 579
 
574
-    if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
580
+    if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) {
575 581
         int list;
576 582
         int b_stride = h->b_stride;
577
-        for(list=0; list<h->list_count; list++){
583
+        for (list = 0; list < h->list_count; list++) {
578 584
             int8_t *ref_cache = &h->ref_cache[list][scan8[0]];
579 585
             int8_t *ref       = s->current_picture.f.ref_index[list];
580
-            int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
581
-            int16_t (*mv)[2]       = s->current_picture.f.motion_val[list];
582
-            if(!USES_LIST(mb_type, list)){
586
+            int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
587
+            int16_t(*mv)[2]       = s->current_picture.f.motion_val[list];
588
+            if (!USES_LIST(mb_type, list))
583 589
                 continue;
584
-            }
585 590
             assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
586 591
 
587
-            if(USES_LIST(top_type, list)){
588
-                const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;
589
-                AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);
590
-                ref_cache[0 - 1*8]=
591
-                ref_cache[1 - 1*8]= ref[4*top_xy + 2];
592
-                ref_cache[2 - 1*8]=
593
-                ref_cache[3 - 1*8]= ref[4*top_xy + 3];
594
-            }else{
595
-                AV_ZERO128(mv_cache[0 - 1*8]);
596
-                AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101u);
592
+            if (USES_LIST(top_type, list)) {
593
+                const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
594
+                AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);
595
+                ref_cache[0 - 1 * 8] =
596
+                ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
597
+                ref_cache[2 - 1 * 8] =
598
+                ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
599
+            } else {
600
+                AV_ZERO128(mv_cache[0 - 1 * 8]);
601
+                AV_WN32A(&ref_cache[0 - 1 * 8],
602
+                         ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);
597 603
             }
598 604
 
599
-            if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){
600
-            for(i=0; i<2; i++){
601
-                int cache_idx = -1 + i*2*8;
602
-                if(USES_LIST(left_type[LEFT(i)], list)){
603
-                    const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;
604
-                    const int b8_xy= 4*left_xy[LEFT(i)] + 1;
605
-                    AV_COPY32(mv_cache[cache_idx  ], mv[b_xy + b_stride*left_block[0+i*2]]);
606
-                    AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);
607
-                    ref_cache[cache_idx  ]= ref[b8_xy + (left_block[0+i*2]&~1)];
608
-                    ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];
609
-                }else{
610
-                    AV_ZERO32(mv_cache[cache_idx  ]);
611
-                    AV_ZERO32(mv_cache[cache_idx+8]);
612
-                    ref_cache[cache_idx  ]=
613
-                    ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;
605
+            if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {
606
+                for (i = 0; i < 2; i++) {
607
+                    int cache_idx = -1 + i * 2 * 8;
608
+                    if (USES_LIST(left_type[LEFT(i)], list)) {
609
+                        const int b_xy  = h->mb2b_xy[left_xy[LEFT(i)]] + 3;
610
+                        const int b8_xy = 4 * left_xy[LEFT(i)] + 1;
611
+                        AV_COPY32(mv_cache[cache_idx],
612
+                                  mv[b_xy + b_stride * left_block[0 + i * 2]]);
613
+                        AV_COPY32(mv_cache[cache_idx + 8],
614
+                                  mv[b_xy + b_stride * left_block[1 + i * 2]]);
615
+                        ref_cache[cache_idx]     = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
616
+                        ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
617
+                    } else {
618
+                        AV_ZERO32(mv_cache[cache_idx]);
619
+                        AV_ZERO32(mv_cache[cache_idx + 8]);
620
+                        ref_cache[cache_idx]     =
621
+                        ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED
622
+                                                                        : PART_NOT_AVAILABLE;
623
+                    }
614 624
                 }
615
-            }
616
-            }else{
617
-                if(USES_LIST(left_type[LTOP], list)){
618
-                    const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;
619
-                    const int b8_xy= 4*left_xy[LTOP] + 1;
620
-                    AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);
621
-                    ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];
622
-                }else{
625
+            } else {
626
+                if (USES_LIST(left_type[LTOP], list)) {
627
+                    const int b_xy  = h->mb2b_xy[left_xy[LTOP]] + 3;
628
+                    const int b8_xy = 4 * left_xy[LTOP] + 1;
629
+                    AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);
630
+                    ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
631
+                } else {
623 632
                     AV_ZERO32(mv_cache[-1]);
624
-                    ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
633
+                    ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED
634
+                                                    : PART_NOT_AVAILABLE;
625 635
                 }
626 636
             }
627 637
 
628
-            if(USES_LIST(topright_type, list)){
629
-                const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;
630
-                AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);
631
-                ref_cache[4 - 1*8]= ref[4*topright_xy + 2];
632
-            }else{
633
-                AV_ZERO32(mv_cache[4 - 1*8]);
634
-                ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
638
+            if (USES_LIST(topright_type, list)) {
639
+                const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;
640
+                AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);
641
+                ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
642
+            } else {
643
+                AV_ZERO32(mv_cache[4 - 1 * 8]);
644
+                ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED
645
+                                                     : PART_NOT_AVAILABLE;
635 646
             }
636 647
             if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1*8] < 0){
637
-                if(USES_LIST(topleft_type, list)){
638
-                    const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);
639
-                    const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);
640
-                    AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);
641
-                    ref_cache[-1 - 1*8]= ref[b8_xy];
642
-                }else{
643
-                    AV_ZERO32(mv_cache[-1 - 1*8]);
644
-                    ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
648
+                if (USES_LIST(topleft_type, list)) {
649
+                    const int b_xy  = h->mb2b_xy[topleft_xy] + 3 + b_stride +
650
+                                      (h->topleft_partition & 2 * b_stride);
651
+                    const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2);
652
+                    AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);
653
+                    ref_cache[-1 - 1 * 8] = ref[b8_xy];
654
+                } else {
655
+                    AV_ZERO32(mv_cache[-1 - 1 * 8]);
656
+                    ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED
657
+                                                         : PART_NOT_AVAILABLE;
645 658
                 }
646 659
             }
647 660
 
648
-            if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
661
+            if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
649 662
                 continue;
650 663
 
651
-            if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){
652
-                uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];
653
-                uint8_t (*mvd)[2] = h->mvd_table[list];
654
-                ref_cache[2+8*0] =
655
-                ref_cache[2+8*2] = PART_NOT_AVAILABLE;
656
-                AV_ZERO32(mv_cache[2+8*0]);
657
-                AV_ZERO32(mv_cache[2+8*2]);
658
-
659
-                if( CABAC ) {
660
-                    if(USES_LIST(top_type, list)){
661
-                        const int b_xy= h->mb2br_xy[top_xy];
662
-                        AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);
663
-                    }else{
664
-                        AV_ZERO64(mvd_cache[0 - 1*8]);
664
+            if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {
665
+                uint8_t(*mvd_cache)[2]   = &h->mvd_cache[list][scan8[0]];
666
+                uint8_t(*mvd)[2]         = h->mvd_table[list];
667
+                ref_cache[2 + 8 * 0] =
668
+                ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;
669
+                AV_ZERO32(mv_cache[2 + 8 * 0]);
670
+                AV_ZERO32(mv_cache[2 + 8 * 2]);
671
+
672
+                if (CABAC) {
673
+                    if (USES_LIST(top_type, list)) {
674
+                        const int b_xy = h->mb2br_xy[top_xy];
675
+                        AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
676
+                    } else {
677
+                        AV_ZERO64(mvd_cache[0 - 1 * 8]);
665 678
                     }
666
-                    if(USES_LIST(left_type[LTOP], list)){
667
-                        const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;
668
-                        AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);
669
-                        AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);
670
-                    }else{
671
-                        AV_ZERO16(mvd_cache[-1 + 0*8]);
672
-                        AV_ZERO16(mvd_cache[-1 + 1*8]);
679
+                    if (USES_LIST(left_type[LTOP], list)) {
680
+                        const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;
681
+                        AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
682
+                        AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
683
+                    } else {
684
+                        AV_ZERO16(mvd_cache[-1 + 0 * 8]);
685
+                        AV_ZERO16(mvd_cache[-1 + 1 * 8]);
673 686
                     }
674
-                    if(USES_LIST(left_type[LBOT], list)){
675
-                        const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;
676
-                        AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);
677
-                        AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);
678
-                    }else{
679
-                        AV_ZERO16(mvd_cache[-1 + 2*8]);
680
-                        AV_ZERO16(mvd_cache[-1 + 3*8]);
687
+                    if (USES_LIST(left_type[LBOT], list)) {
688
+                        const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;
689
+                        AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
690
+                        AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
691
+                    } else {
692
+                        AV_ZERO16(mvd_cache[-1 + 2 * 8]);
693
+                        AV_ZERO16(mvd_cache[-1 + 3 * 8]);
681 694
                     }
682
-                    AV_ZERO16(mvd_cache[2+8*0]);
683
-                    AV_ZERO16(mvd_cache[2+8*2]);
684
-                    if(h->slice_type_nos == AV_PICTURE_TYPE_B){
695
+                    AV_ZERO16(mvd_cache[2 + 8 * 0]);
696
+                    AV_ZERO16(mvd_cache[2 + 8 * 2]);
697
+                    if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
685 698
                         uint8_t *direct_cache = &h->direct_cache[scan8[0]];
686 699
                         uint8_t *direct_table = h->direct_table;
687
-                        fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);
688
-
689
-                        if(IS_DIRECT(top_type)){
690
-                            AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));
691
-                        }else if(IS_8X8(top_type)){
692
-                            int b8_xy = 4*top_xy;
693
-                            direct_cache[0 - 1*8]= direct_table[b8_xy + 2];
694
-                            direct_cache[2 - 1*8]= direct_table[b8_xy + 3];
695
-                        }else{
696
-                            AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));
700
+                        fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);
701
+
702
+                        if (IS_DIRECT(top_type)) {
703
+                            AV_WN32A(&direct_cache[-1 * 8],
704
+                                     0x01010101u * (MB_TYPE_DIRECT2 >> 1));
705
+                        } else if (IS_8X8(top_type)) {
706
+                            int b8_xy = 4 * top_xy;
707
+                            direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
708
+                            direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
709
+                        } else {
710
+                            AV_WN32A(&direct_cache[-1 * 8],
711
+                                     0x01010101 * (MB_TYPE_16x16 >> 1));
697 712
                         }
698 713
 
699
-                        if(IS_DIRECT(left_type[LTOP]))
700
-                            direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;
701
-                        else if(IS_8X8(left_type[LTOP]))
702
-                            direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];
714
+                        if (IS_DIRECT(left_type[LTOP]))
715
+                            direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;
716
+                        else if (IS_8X8(left_type[LTOP]))
717
+                            direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];
703 718
                         else
704
-                            direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;
719
+                            direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;
705 720
 
706
-                        if(IS_DIRECT(left_type[LBOT]))
707
-                            direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;
708
-                        else if(IS_8X8(left_type[LBOT]))
709
-                            direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];
721
+                        if (IS_DIRECT(left_type[LBOT]))
722
+                            direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;
723
+                        else if (IS_8X8(left_type[LBOT]))
724
+                            direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
710 725
                         else
711
-                            direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;
726
+                            direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;
712 727
                     }
713 728
                 }
714 729
             }
715
-            if(FRAME_MBAFF){
716
-#define MAP_MVS\
717
-                    MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\
718
-                    MAP_F2F(scan8[0] + 0 - 1*8, top_type)\
719
-                    MAP_F2F(scan8[0] + 1 - 1*8, top_type)\
720
-                    MAP_F2F(scan8[0] + 2 - 1*8, top_type)\
721
-                    MAP_F2F(scan8[0] + 3 - 1*8, top_type)\
722
-                    MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\
723
-                    MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\
724
-                    MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\
725
-                    MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\
726
-                    MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])
727
-                if(MB_FIELD){
728
-#define MAP_F2F(idx, mb_type)\
729
-                    if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
730
-                        h->ref_cache[list][idx] <<= 1;\
731
-                        h->mv_cache[list][idx][1] /= 2;\
732
-                        h->mvd_cache[list][idx][1] >>=1;\
733
-                    }
730
+
731
+#define MAP_MVS                                                         \
732
+    MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type)                         \
733
+    MAP_F2F(scan8[0] + 0 - 1 * 8, top_type)                             \
734
+    MAP_F2F(scan8[0] + 1 - 1 * 8, top_type)                             \
735
+    MAP_F2F(scan8[0] + 2 - 1 * 8, top_type)                             \
736
+    MAP_F2F(scan8[0] + 3 - 1 * 8, top_type)                             \
737
+    MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type)                        \
738
+    MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP])                      \
739
+    MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP])                      \
740
+    MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT])                      \
741
+    MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
742
+
743
+            if (FRAME_MBAFF) {
744
+                if (MB_FIELD) {
745
+
746
+#define MAP_F2F(idx, mb_type)                                           \
747
+    if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) {      \
748
+        h->ref_cache[list][idx]    <<= 1;                               \
749
+        h->mv_cache[list][idx][1]   /= 2;                               \
750
+        h->mvd_cache[list][idx][1] >>= 1;                               \
751
+    }
752
+
734 753
                     MAP_MVS
754
+                } else {
755
+
735 756
 #undef MAP_F2F
736
-                }else{
737
-#define MAP_F2F(idx, mb_type)\
738
-                    if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
739
-                        h->ref_cache[list][idx] >>= 1;\
740
-                        h->mv_cache[list][idx][1] <<= 1;\
741
-                        h->mvd_cache[list][idx][1] <<= 1;\
742
-                    }
757
+#define MAP_F2F(idx, mb_type)                                           \
758
+    if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) {       \
759
+        h->ref_cache[list][idx]    >>= 1;                               \
760
+        h->mv_cache[list][idx][1]  <<= 1;                               \
761
+        h->mvd_cache[list][idx][1] <<= 1;                               \
762
+    }
763
+
743 764
                     MAP_MVS
744 765
 #undef MAP_F2F
745 766
                 }
... ...
@@ -747,36 +792,34 @@ static void fill_decode_caches(H264Context *h, int mb_type){
747 747
         }
748 748
     }
749 749
 
750
-        h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
750
+    h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
751 751
 }
752 752
 
753 753
 /**
754 754
  * decodes a P_SKIP or B_SKIP macroblock
755 755
  */
756
-static void av_unused decode_mb_skip(H264Context *h){
757
-    MpegEncContext * const s = &h->s;
758
-    const int mb_xy= h->mb_xy;
759
-    int mb_type=0;
756
+static void av_unused decode_mb_skip(H264Context *h)
757
+{
758
+    MpegEncContext *const s = &h->s;
759
+    const int mb_xy = h->mb_xy;
760
+    int mb_type     = 0;
760 761
 
761 762
     memset(h->non_zero_count[mb_xy], 0, 48);
762 763
 
763
-    if(MB_FIELD)
764
-        mb_type|= MB_TYPE_INTERLACED;
764
+    if (MB_FIELD)
765
+        mb_type |= MB_TYPE_INTERLACED;
765 766
 
766
-    if( h->slice_type_nos == AV_PICTURE_TYPE_B )
767
-    {
767
+    if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
768 768
         // just for fill_caches. pred_direct_motion will set the real mb_type
769
-        mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;
770
-        if(h->direct_spatial_mv_pred){
769
+        mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP;
770
+        if (h->direct_spatial_mv_pred) {
771 771
             fill_decode_neighbors(h, mb_type);
772
-        fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ...
772
+            fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ...
773 773
         }
774 774
         ff_h264_pred_direct_motion(h, &mb_type);
775
-        mb_type|= MB_TYPE_SKIP;
776
-    }
777
-    else
778
-    {
779
-        mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP;
775
+        mb_type |= MB_TYPE_SKIP;
776
+    } else {
777
+        mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP;
780 778
 
781 779
         fill_decode_neighbors(h, mb_type);
782 780
         pred_pskip_motion(h);
... ...
@@ -785,8 +828,8 @@ static void av_unused decode_mb_skip(H264Context *h){
785 785
     write_back_motion(h, mb_type);
786 786
     s->current_picture.f.mb_type[mb_xy]      = mb_type;
787 787
     s->current_picture.f.qscale_table[mb_xy] = s->qscale;
788
-    h->slice_table[ mb_xy ]= h->slice_num;
789
-    h->prev_mb_skipped= 1;
788
+    h->slice_table[mb_xy]                    = h->slice_num;
789
+    h->prev_mb_skipped                       = 1;
790 790
 }
791 791
 
792 792
 #endif /* AVCODEC_H264_MVPRED_H */
... ...
@@ -30,240 +30,243 @@
30 30
 #define AVCODEC_H264DATA_H
31 31
 
32 32
 #include <stdint.h>
33
+
33 34
 #include "libavutil/rational.h"
34 35
 #include "mpegvideo.h"
35 36
 #include "h264.h"
36 37
 
38
+static const uint8_t golomb_to_pict_type[5] = {
39
+    AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, AV_PICTURE_TYPE_I,
40
+    AV_PICTURE_TYPE_SP, AV_PICTURE_TYPE_SI
41
+};
37 42
 
38
-static const uint8_t golomb_to_pict_type[5]=
39
-{AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_SP, AV_PICTURE_TYPE_SI};
40
-
41
-static const uint8_t golomb_to_intra4x4_cbp[48]={
42
- 47, 31, 15,  0, 23, 27, 29, 30,  7, 11, 13, 14, 39, 43, 45, 46,
43
- 16,  3,  5, 10, 12, 19, 21, 26, 28, 35, 37, 42, 44,  1,  2,  4,
44
-  8, 17, 18, 20, 24,  6,  9, 22, 25, 32, 33, 34, 36, 40, 38, 41
43
+static const uint8_t golomb_to_intra4x4_cbp[48] = {
44
+    47, 31, 15, 0,  23, 27, 29, 30, 7,  11, 13, 14, 39, 43, 45, 46,
45
+    16, 3,  5,  10, 12, 19, 21, 26, 28, 35, 37, 42, 44, 1,  2,  4,
46
+    8,  17, 18, 20, 24, 6,  9,  22, 25, 32, 33, 34, 36, 40, 38, 41
45 47
 };
46 48
 
47
-static const uint8_t golomb_to_inter_cbp[48]={
48
-  0, 16,  1,  2,  4,  8, 32,  3,  5, 10, 12, 15, 47,  7, 11, 13,
49
- 14,  6,  9, 31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46,
50
- 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41
49
+static const uint8_t golomb_to_inter_cbp[48] = {
50
+    0,  16, 1,  2,  4,  8,  32, 3,  5,  10, 12, 15, 47, 7,  11, 13,
51
+    14, 6,  9,  31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46,
52
+    17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41
51 53
 };
52 54
 
53
-static const uint8_t zigzag_scan[16]={
54
- 0+0*4, 1+0*4, 0+1*4, 0+2*4,
55
- 1+1*4, 2+0*4, 3+0*4, 2+1*4,
56
- 1+2*4, 0+3*4, 1+3*4, 2+2*4,
57
- 3+1*4, 3+2*4, 2+3*4, 3+3*4,
55
+static const uint8_t zigzag_scan[16] = {
56
+    0 + 0 * 4, 1 + 0 * 4, 0 + 1 * 4, 0 + 2 * 4,
57
+    1 + 1 * 4, 2 + 0 * 4, 3 + 0 * 4, 2 + 1 * 4,
58
+    1 + 2 * 4, 0 + 3 * 4, 1 + 3 * 4, 2 + 2 * 4,
59
+    3 + 1 * 4, 3 + 2 * 4, 2 + 3 * 4, 3 + 3 * 4,
58 60
 };
59 61
 
60
-static const uint8_t field_scan[16]={
61
- 0+0*4, 0+1*4, 1+0*4, 0+2*4,
62
- 0+3*4, 1+1*4, 1+2*4, 1+3*4,
63
- 2+0*4, 2+1*4, 2+2*4, 2+3*4,
64
- 3+0*4, 3+1*4, 3+2*4, 3+3*4,
62
+static const uint8_t field_scan[16] = {
63
+    0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
64
+    0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
65
+    2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
66
+    3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
65 67
 };
66 68
 
67
-static const uint8_t luma_dc_zigzag_scan[16]={
68
- 0*16 + 0*64, 1*16 + 0*64, 2*16 + 0*64, 0*16 + 2*64,
69
- 3*16 + 0*64, 0*16 + 1*64, 1*16 + 1*64, 2*16 + 1*64,
70
- 1*16 + 2*64, 2*16 + 2*64, 3*16 + 2*64, 0*16 + 3*64,
71
- 3*16 + 1*64, 1*16 + 3*64, 2*16 + 3*64, 3*16 + 3*64,
69
+static const uint8_t luma_dc_zigzag_scan[16] = {
70
+    0 * 16 + 0 * 64, 1 * 16 + 0 * 64, 2 * 16 + 0 * 64, 0 * 16 + 2 * 64,
71
+    3 * 16 + 0 * 64, 0 * 16 + 1 * 64, 1 * 16 + 1 * 64, 2 * 16 + 1 * 64,
72
+    1 * 16 + 2 * 64, 2 * 16 + 2 * 64, 3 * 16 + 2 * 64, 0 * 16 + 3 * 64,
73
+    3 * 16 + 1 * 64, 1 * 16 + 3 * 64, 2 * 16 + 3 * 64, 3 * 16 + 3 * 64,
72 74
 };
73 75
 
74
-static const uint8_t luma_dc_field_scan[16]={
75
- 0*16 + 0*64, 2*16 + 0*64, 1*16 + 0*64, 0*16 + 2*64,
76
- 2*16 + 2*64, 3*16 + 0*64, 1*16 + 2*64, 3*16 + 2*64,
77
- 0*16 + 1*64, 2*16 + 1*64, 0*16 + 3*64, 2*16 + 3*64,
78
- 1*16 + 1*64, 3*16 + 1*64, 1*16 + 3*64, 3*16 + 3*64,
76
+static const uint8_t luma_dc_field_scan[16] = {
77
+    0 * 16 + 0 * 64, 2 * 16 + 0 * 64, 1 * 16 + 0 * 64, 0 * 16 + 2 * 64,
78
+    2 * 16 + 2 * 64, 3 * 16 + 0 * 64, 1 * 16 + 2 * 64, 3 * 16 + 2 * 64,
79
+    0 * 16 + 1 * 64, 2 * 16 + 1 * 64, 0 * 16 + 3 * 64, 2 * 16 + 3 * 64,
80
+    1 * 16 + 1 * 64, 3 * 16 + 1 * 64, 1 * 16 + 3 * 64, 3 * 16 + 3 * 64,
79 81
 };
80 82
 
81
-static const uint8_t chroma_dc_scan[4]={
82
- (0+0*2)*16, (1+0*2)*16,
83
- (0+1*2)*16, (1+1*2)*16,
83
+static const uint8_t chroma_dc_scan[4] = {
84
+    (0 + 0 * 2) * 16, (1 + 0 * 2) * 16,
85
+    (0 + 1 * 2) * 16, (1 + 1 * 2) * 16,
84 86
 };
85 87
 
86
-static const uint8_t chroma422_dc_scan[8]={
87
- (0+0*2)*16, (0+1*2)*16,
88
- (1+0*2)*16, (0+2*2)*16,
89
- (0+3*2)*16, (1+1*2)*16,
90
- (1+2*2)*16, (1+3*2)*16,
88
+static const uint8_t chroma422_dc_scan[8] = {
89
+    (0 + 0 * 2) * 16, (0 + 1 * 2) * 16,
90
+    (1 + 0 * 2) * 16, (0 + 2 * 2) * 16,
91
+    (0 + 3 * 2) * 16, (1 + 1 * 2) * 16,
92
+    (1 + 2 * 2) * 16, (1 + 3 * 2) * 16,
91 93
 };
92 94
 
93 95
 // zigzag_scan8x8_cavlc[i] = zigzag_scan8x8[(i/4) + 16*(i%4)]
94
-static const uint8_t zigzag_scan8x8_cavlc[64]={
95
- 0+0*8, 1+1*8, 1+2*8, 2+2*8,
96
- 4+1*8, 0+5*8, 3+3*8, 7+0*8,
97
- 3+4*8, 1+7*8, 5+3*8, 6+3*8,
98
- 2+7*8, 6+4*8, 5+6*8, 7+5*8,
99
- 1+0*8, 2+0*8, 0+3*8, 3+1*8,
100
- 3+2*8, 0+6*8, 4+2*8, 6+1*8,
101
- 2+5*8, 2+6*8, 6+2*8, 5+4*8,
102
- 3+7*8, 7+3*8, 4+7*8, 7+6*8,
103
- 0+1*8, 3+0*8, 0+4*8, 4+0*8,
104
- 2+3*8, 1+5*8, 5+1*8, 5+2*8,
105
- 1+6*8, 3+5*8, 7+1*8, 4+5*8,
106
- 4+6*8, 7+4*8, 5+7*8, 6+7*8,
107
- 0+2*8, 2+1*8, 1+3*8, 5+0*8,
108
- 1+4*8, 2+4*8, 6+0*8, 4+3*8,
109
- 0+7*8, 4+4*8, 7+2*8, 3+6*8,
110
- 5+5*8, 6+5*8, 6+6*8, 7+7*8,
96
+static const uint8_t zigzag_scan8x8_cavlc[64] = {
97
+    0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
98
+    4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
99
+    3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
100
+    2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
101
+    1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
102
+    3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
103
+    2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
104
+    3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
105
+    0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
106
+    2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
107
+    1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
108
+    4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
109
+    0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
110
+    1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
111
+    0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
112
+    5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
111 113
 };
112 114
 
113
-static const uint8_t field_scan8x8[64]={
114
- 0+0*8, 0+1*8, 0+2*8, 1+0*8,
115
- 1+1*8, 0+3*8, 0+4*8, 1+2*8,
116
- 2+0*8, 1+3*8, 0+5*8, 0+6*8,
117
- 0+7*8, 1+4*8, 2+1*8, 3+0*8,
118
- 2+2*8, 1+5*8, 1+6*8, 1+7*8,
119
- 2+3*8, 3+1*8, 4+0*8, 3+2*8,
120
- 2+4*8, 2+5*8, 2+6*8, 2+7*8,
121
- 3+3*8, 4+1*8, 5+0*8, 4+2*8,
122
- 3+4*8, 3+5*8, 3+6*8, 3+7*8,
123
- 4+3*8, 5+1*8, 6+0*8, 5+2*8,
124
- 4+4*8, 4+5*8, 4+6*8, 4+7*8,
125
- 5+3*8, 6+1*8, 6+2*8, 5+4*8,
126
- 5+5*8, 5+6*8, 5+7*8, 6+3*8,
127
- 7+0*8, 7+1*8, 6+4*8, 6+5*8,
128
- 6+6*8, 6+7*8, 7+2*8, 7+3*8,
129
- 7+4*8, 7+5*8, 7+6*8, 7+7*8,
115
+static const uint8_t field_scan8x8[64] = {
116
+    0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
117
+    1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
118
+    2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
119
+    0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
120
+    2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
121
+    2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
122
+    2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
123
+    3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
124
+    3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
125
+    4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
126
+    4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
127
+    5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
128
+    5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
129
+    7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
130
+    6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
131
+    7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
130 132
 };
131 133
 
132
-static const uint8_t field_scan8x8_cavlc[64]={
133
- 0+0*8, 1+1*8, 2+0*8, 0+7*8,
134
- 2+2*8, 2+3*8, 2+4*8, 3+3*8,
135
- 3+4*8, 4+3*8, 4+4*8, 5+3*8,
136
- 5+5*8, 7+0*8, 6+6*8, 7+4*8,
137
- 0+1*8, 0+3*8, 1+3*8, 1+4*8,
138
- 1+5*8, 3+1*8, 2+5*8, 4+1*8,
139
- 3+5*8, 5+1*8, 4+5*8, 6+1*8,
140
- 5+6*8, 7+1*8, 6+7*8, 7+5*8,
141
- 0+2*8, 0+4*8, 0+5*8, 2+1*8,
142
- 1+6*8, 4+0*8, 2+6*8, 5+0*8,
143
- 3+6*8, 6+0*8, 4+6*8, 6+2*8,
144
- 5+7*8, 6+4*8, 7+2*8, 7+6*8,
145
- 1+0*8, 1+2*8, 0+6*8, 3+0*8,
146
- 1+7*8, 3+2*8, 2+7*8, 4+2*8,
147
- 3+7*8, 5+2*8, 4+7*8, 5+4*8,
148
- 6+3*8, 6+5*8, 7+3*8, 7+7*8,
134
+static const uint8_t field_scan8x8_cavlc[64] = {
135
+    0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
136
+    2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
137
+    3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
138
+    5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
139
+    0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
140
+    1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
141
+    3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
142
+    5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
143
+    0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
144
+    1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
145
+    3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
146
+    5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
147
+    1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
148
+    1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
149
+    3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
150
+    6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
149 151
 };
150 152
 
151
-typedef struct IMbInfo{
153
+typedef struct IMbInfo {
152 154
     uint16_t type;
153 155
     uint8_t pred_mode;
154 156
     uint8_t cbp;
155 157
 } IMbInfo;
156 158
 
157
-static const IMbInfo i_mb_type_info[26]={
158
-{MB_TYPE_INTRA4x4  , -1, -1},
159
-{MB_TYPE_INTRA16x16,  2,  0},
160
-{MB_TYPE_INTRA16x16,  1,  0},
161
-{MB_TYPE_INTRA16x16,  0,  0},
162
-{MB_TYPE_INTRA16x16,  3,  0},
163
-{MB_TYPE_INTRA16x16,  2,  16},
164
-{MB_TYPE_INTRA16x16,  1,  16},
165
-{MB_TYPE_INTRA16x16,  0,  16},
166
-{MB_TYPE_INTRA16x16,  3,  16},
167
-{MB_TYPE_INTRA16x16,  2,  32},
168
-{MB_TYPE_INTRA16x16,  1,  32},
169
-{MB_TYPE_INTRA16x16,  0,  32},
170
-{MB_TYPE_INTRA16x16,  3,  32},
171
-{MB_TYPE_INTRA16x16,  2,  15+0},
172
-{MB_TYPE_INTRA16x16,  1,  15+0},
173
-{MB_TYPE_INTRA16x16,  0,  15+0},
174
-{MB_TYPE_INTRA16x16,  3,  15+0},
175
-{MB_TYPE_INTRA16x16,  2,  15+16},
176
-{MB_TYPE_INTRA16x16,  1,  15+16},
177
-{MB_TYPE_INTRA16x16,  0,  15+16},
178
-{MB_TYPE_INTRA16x16,  3,  15+16},
179
-{MB_TYPE_INTRA16x16,  2,  15+32},
180
-{MB_TYPE_INTRA16x16,  1,  15+32},
181
-{MB_TYPE_INTRA16x16,  0,  15+32},
182
-{MB_TYPE_INTRA16x16,  3,  15+32},
183
-{MB_TYPE_INTRA_PCM , -1, -1},
159
+static const IMbInfo i_mb_type_info[26] = {
160
+    { MB_TYPE_INTRA4x4,  -1,  -1 },
161
+    { MB_TYPE_INTRA16x16, 2,   0 },
162
+    { MB_TYPE_INTRA16x16, 1,   0 },
163
+    { MB_TYPE_INTRA16x16, 0,   0 },
164
+    { MB_TYPE_INTRA16x16, 3,   0 },
165
+    { MB_TYPE_INTRA16x16, 2,  16 },
166
+    { MB_TYPE_INTRA16x16, 1,  16 },
167
+    { MB_TYPE_INTRA16x16, 0,  16 },
168
+    { MB_TYPE_INTRA16x16, 3,  16 },
169
+    { MB_TYPE_INTRA16x16, 2,  32 },
170
+    { MB_TYPE_INTRA16x16, 1,  32 },
171
+    { MB_TYPE_INTRA16x16, 0,  32 },
172
+    { MB_TYPE_INTRA16x16, 3,  32 },
173
+    { MB_TYPE_INTRA16x16, 2,  15 +  0 },
174
+    { MB_TYPE_INTRA16x16, 1,  15 +  0 },
175
+    { MB_TYPE_INTRA16x16, 0,  15 +  0 },
176
+    { MB_TYPE_INTRA16x16, 3,  15 +  0 },
177
+    { MB_TYPE_INTRA16x16, 2,  15 + 16 },
178
+    { MB_TYPE_INTRA16x16, 1,  15 + 16 },
179
+    { MB_TYPE_INTRA16x16, 0,  15 + 16 },
180
+    { MB_TYPE_INTRA16x16, 3,  15 + 16 },
181
+    { MB_TYPE_INTRA16x16, 2,  15 + 32 },
182
+    { MB_TYPE_INTRA16x16, 1,  15 + 32 },
183
+    { MB_TYPE_INTRA16x16, 0,  15 + 32 },
184
+    { MB_TYPE_INTRA16x16, 3,  15 + 32 },
185
+    { MB_TYPE_INTRA_PCM,  -1, -1 },
184 186
 };
185 187
 
186
-typedef struct PMbInfo{
188
+typedef struct PMbInfo {
187 189
     uint16_t type;
188 190
     uint8_t partition_count;
189 191
 } PMbInfo;
190 192
 
191
-static const PMbInfo p_mb_type_info[5]={
192
-{MB_TYPE_16x16|MB_TYPE_P0L0             , 1},
193
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},
194
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},
195
-{MB_TYPE_8x8  |MB_TYPE_P0L0|MB_TYPE_P1L0, 4},
196
-{MB_TYPE_8x8  |MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_REF0, 4},
193
+static const PMbInfo p_mb_type_info[5] = {
194
+    { MB_TYPE_16x16 | MB_TYPE_P0L0,                               1 },
195
+    { MB_TYPE_16x8  | MB_TYPE_P0L0 | MB_TYPE_P1L0,                2 },
196
+    { MB_TYPE_8x16  | MB_TYPE_P0L0 | MB_TYPE_P1L0,                2 },
197
+    { MB_TYPE_8x8   | MB_TYPE_P0L0 | MB_TYPE_P1L0,                4 },
198
+    { MB_TYPE_8x8   | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_REF0, 4 },
197 199
 };
198 200
 
199
-static const PMbInfo p_sub_mb_type_info[4]={
200
-{MB_TYPE_16x16|MB_TYPE_P0L0             , 1},
201
-{MB_TYPE_16x8 |MB_TYPE_P0L0             , 2},
202
-{MB_TYPE_8x16 |MB_TYPE_P0L0             , 2},
203
-{MB_TYPE_8x8  |MB_TYPE_P0L0             , 4},
201
+static const PMbInfo p_sub_mb_type_info[4] = {
202
+    { MB_TYPE_16x16 | MB_TYPE_P0L0, 1 },
203
+    { MB_TYPE_16x8  | MB_TYPE_P0L0, 2 },
204
+    { MB_TYPE_8x16  | MB_TYPE_P0L0, 2 },
205
+    { MB_TYPE_8x8   | MB_TYPE_P0L0, 4 },
204 206
 };
205 207
 
206
-static const PMbInfo b_mb_type_info[23]={
207
-{MB_TYPE_DIRECT2|MB_TYPE_L0L1                                      , 1, },
208
-{MB_TYPE_16x16|MB_TYPE_P0L0                                       , 1, },
209
-{MB_TYPE_16x16             |MB_TYPE_P0L1                          , 1, },
210
-{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1                          , 1, },
211
-{MB_TYPE_16x8 |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 2, },
212
-{MB_TYPE_8x16 |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 2, },
213
-{MB_TYPE_16x8              |MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },
214
-{MB_TYPE_8x16              |MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },
215
-{MB_TYPE_16x8 |MB_TYPE_P0L0                          |MB_TYPE_P1L1, 2, },
216
-{MB_TYPE_8x16 |MB_TYPE_P0L0                          |MB_TYPE_P1L1, 2, },
217
-{MB_TYPE_16x8              |MB_TYPE_P0L1|MB_TYPE_P1L0             , 2, },
218
-{MB_TYPE_8x16              |MB_TYPE_P0L1|MB_TYPE_P1L0             , 2, },
219
-{MB_TYPE_16x8 |MB_TYPE_P0L0             |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
220
-{MB_TYPE_8x16 |MB_TYPE_P0L0             |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
221
-{MB_TYPE_16x8              |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
222
-{MB_TYPE_8x16              |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
223
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0             , 2, },
224
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0             , 2, },
225
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },
226
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },
227
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
228
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
229
-{MB_TYPE_8x8  |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 4, },
208
+static const PMbInfo b_mb_type_info[23] = {
209
+    { MB_TYPE_DIRECT2 | MB_TYPE_L0L1,                                              1, },
210
+    { MB_TYPE_16x16   | MB_TYPE_P0L0,                                              1, },
211
+    { MB_TYPE_16x16   | MB_TYPE_P0L1,                                              1, },
212
+    { MB_TYPE_16x16   | MB_TYPE_P0L0 | MB_TYPE_P0L1,                               1, },
213
+    { MB_TYPE_16x8    | MB_TYPE_P0L0 | MB_TYPE_P1L0,                               2, },
214
+    { MB_TYPE_8x16    | MB_TYPE_P0L0 | MB_TYPE_P1L0,                               2, },
215
+    { MB_TYPE_16x8    | MB_TYPE_P0L1 | MB_TYPE_P1L1,                               2, },
216
+    { MB_TYPE_8x16    | MB_TYPE_P0L1 | MB_TYPE_P1L1,                               2, },
217
+    { MB_TYPE_16x8    | MB_TYPE_P0L0 | MB_TYPE_P1L1,                               2, },
218
+    { MB_TYPE_8x16    | MB_TYPE_P0L0 | MB_TYPE_P1L1,                               2, },
219
+    { MB_TYPE_16x8    | MB_TYPE_P0L1 | MB_TYPE_P1L0,                               2, },
220
+    { MB_TYPE_8x16    | MB_TYPE_P0L1 | MB_TYPE_P1L0,                               2, },
221
+    { MB_TYPE_16x8    | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_P1L1,                2, },
222
+    { MB_TYPE_8x16    | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_P1L1,                2, },
223
+    { MB_TYPE_16x8    | MB_TYPE_P0L1 | MB_TYPE_P1L0 | MB_TYPE_P1L1,                2, },
224
+    { MB_TYPE_8x16    | MB_TYPE_P0L1 | MB_TYPE_P1L0 | MB_TYPE_P1L1,                2, },
225
+    { MB_TYPE_16x8    | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L0,                2, },
226
+    { MB_TYPE_8x16    | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L0,                2, },
227
+    { MB_TYPE_16x8    | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L1,                2, },
228
+    { MB_TYPE_8x16    | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L1,                2, },
229
+    { MB_TYPE_16x8    | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L0 | MB_TYPE_P1L1, 2, },
230
+    { MB_TYPE_8x16    | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L0 | MB_TYPE_P1L1, 2, },
231
+    { MB_TYPE_8x8     | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L0 | MB_TYPE_P1L1, 4, },
230 232
 };
231 233
 
232
-static const PMbInfo b_sub_mb_type_info[13]={
233
-{MB_TYPE_DIRECT2                                                   , 1, },
234
-{MB_TYPE_16x16|MB_TYPE_P0L0                                       , 1, },
235
-{MB_TYPE_16x16             |MB_TYPE_P0L1                          , 1, },
236
-{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1                          , 1, },
237
-{MB_TYPE_16x8 |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 2, },
238
-{MB_TYPE_8x16 |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 2, },
239
-{MB_TYPE_16x8              |MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },
240
-{MB_TYPE_8x16              |MB_TYPE_P0L1             |MB_TYPE_P1L1, 2, },
241
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
242
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
243
-{MB_TYPE_8x8  |MB_TYPE_P0L0             |MB_TYPE_P1L0             , 4, },
244
-{MB_TYPE_8x8               |MB_TYPE_P0L1             |MB_TYPE_P1L1, 4, },
245
-{MB_TYPE_8x8  |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 4, },
234
+static const PMbInfo b_sub_mb_type_info[13] = {
235
+    { MB_TYPE_DIRECT2,                                                           1, },
236
+    { MB_TYPE_16x16 | MB_TYPE_P0L0,                                              1, },
237
+    { MB_TYPE_16x16 | MB_TYPE_P0L1,                                              1, },
238
+    { MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1,                               1, },
239
+    { MB_TYPE_16x8  | MB_TYPE_P0L0 | MB_TYPE_P1L0,                               2, },
240
+    { MB_TYPE_8x16  | MB_TYPE_P0L0 | MB_TYPE_P1L0,                               2, },
241
+    { MB_TYPE_16x8  | MB_TYPE_P0L1 | MB_TYPE_P1L1,                               2, },
242
+    { MB_TYPE_8x16  | MB_TYPE_P0L1 | MB_TYPE_P1L1,                               2, },
243
+    { MB_TYPE_16x8  | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L0 | MB_TYPE_P1L1, 2, },
244
+    { MB_TYPE_8x16  | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L0 | MB_TYPE_P1L1, 2, },
245
+    { MB_TYPE_8x8   | MB_TYPE_P0L0 | MB_TYPE_P1L0,                               4, },
246
+    { MB_TYPE_8x8   | MB_TYPE_P0L1 | MB_TYPE_P1L1,                               4, },
247
+    { MB_TYPE_8x8   | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_P1L0 | MB_TYPE_P1L1, 4, },
246 248
 };
247 249
 
248
-static const uint8_t dequant4_coeff_init[6][3]={
249
-  {10,13,16},
250
-  {11,14,18},
251
-  {13,16,20},
252
-  {14,18,23},
253
-  {16,20,25},
254
-  {18,23,29},
250
+static const uint8_t dequant4_coeff_init[6][3] = {
251
+    { 10, 13, 16 },
252
+    { 11, 14, 18 },
253
+    { 13, 16, 20 },
254
+    { 14, 18, 23 },
255
+    { 16, 20, 25 },
256
+    { 18, 23, 29 },
255 257
 };
256 258
 
257 259
 static const uint8_t dequant8_coeff_init_scan[16] = {
258
-  0,3,4,3, 3,1,5,1, 4,5,2,5, 3,1,5,1
260
+    0, 3, 4, 3, 3, 1, 5, 1, 4, 5, 2, 5, 3, 1, 5, 1
259 261
 };
260
-static const uint8_t dequant8_coeff_init[6][6]={
261
-  {20,18,32,19,25,24},
262
-  {22,19,35,21,28,26},
263
-  {26,23,42,24,33,31},
264
-  {28,25,45,26,35,33},
265
-  {32,28,51,30,40,38},
266
-  {36,32,58,34,46,43},
262
+
263
+static const uint8_t dequant8_coeff_init[6][6] = {
264
+    { 20, 18, 32, 19, 25, 24 },
265
+    { 22, 19, 35, 21, 28, 26 },
266
+    { 26, 23, 42, 24, 33, 31 },
267
+    { 28, 25, 45, 26, 35, 33 },
268
+    { 32, 28, 51, 30, 40, 38 },
269
+    { 36, 32, 58, 34, 46, 43 },
267 270
 };
268 271
 
269 272
 #endif /* AVCODEC_H264DATA_H */
... ...
@@ -28,56 +28,90 @@
28 28
 #define AVCODEC_H264DSP_H
29 29
 
30 30
 #include <stdint.h>
31
+
31 32
 #include "dsputil.h"
32 33
 
33 34
 typedef void (*h264_weight_func)(uint8_t *block, int stride, int height,
34 35
                                  int log2_denom, int weight, int offset);
35
-typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int height,
36
-                                   int log2_denom, int weightd, int weights, int offset);
36
+typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src,
37
+                                   int stride, int height, int log2_denom,
38
+                                   int weightd, int weights, int offset);
37 39
 
38 40
 /**
39 41
  * Context for storing H.264 DSP functions
40 42
  */
41
-typedef struct H264DSPContext{
43
+typedef struct H264DSPContext {
42 44
     /* weighted MC */
43 45
     h264_weight_func weight_h264_pixels_tab[4];
44 46
     h264_biweight_func biweight_h264_pixels_tab[4];
45 47
 
46 48
     /* loop filter */
47
-    void (*h264_v_loop_filter_luma)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0);
48
-    void (*h264_h_loop_filter_luma)(uint8_t *pix/*align 4 */, int stride, int alpha, int beta, int8_t *tc0);
49
-    void (*h264_h_loop_filter_luma_mbaff)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0);
49
+    void (*h264_v_loop_filter_luma)(uint8_t *pix /*align 16*/, int stride,
50
+                                    int alpha, int beta, int8_t *tc0);
51
+    void (*h264_h_loop_filter_luma)(uint8_t *pix /*align 4 */, int stride,
52
+                                    int alpha, int beta, int8_t *tc0);
53
+    void (*h264_h_loop_filter_luma_mbaff)(uint8_t *pix /*align 16*/, int stride,
54
+                                          int alpha, int beta, int8_t *tc0);
50 55
     /* v/h_loop_filter_luma_intra: align 16 */
51
-    void (*h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta);
52
-    void (*h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta);
53
-    void (*h264_h_loop_filter_luma_mbaff_intra)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta);
54
-    void (*h264_v_loop_filter_chroma)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta, int8_t *tc0);
55
-    void (*h264_h_loop_filter_chroma)(uint8_t *pix/*align 4*/, int stride, int alpha, int beta, int8_t *tc0);
56
-    void (*h264_h_loop_filter_chroma_mbaff)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta, int8_t *tc0);
57
-    void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta);
58
-    void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta);
59
-    void (*h264_h_loop_filter_chroma_mbaff_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta);
56
+    void (*h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride,
57
+                                          int alpha, int beta);
58
+    void (*h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride,
59
+                                          int alpha, int beta);
60
+    void (*h264_h_loop_filter_luma_mbaff_intra)(uint8_t *pix /*align 16*/,
61
+                                                int stride, int alpha, int beta);
62
+    void (*h264_v_loop_filter_chroma)(uint8_t *pix /*align 8*/, int stride,
63
+                                      int alpha, int beta, int8_t *tc0);
64
+    void (*h264_h_loop_filter_chroma)(uint8_t *pix /*align 4*/, int stride,
65
+                                      int alpha, int beta, int8_t *tc0);
66
+    void (*h264_h_loop_filter_chroma_mbaff)(uint8_t *pix /*align 8*/,
67
+                                            int stride, int alpha, int beta,
68
+                                            int8_t *tc0);
69
+    void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix /*align 8*/,
70
+                                            int stride, int alpha, int beta);
71
+    void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix /*align 8*/,
72
+                                            int stride, int alpha, int beta);
73
+    void (*h264_h_loop_filter_chroma_mbaff_intra)(uint8_t *pix /*align 8*/,
74
+                                                  int stride, int alpha, int beta);
60 75
     // h264_loop_filter_strength: simd only. the C version is inlined in h264.c
61
-    void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2],
62
-                                      int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field);
76
+    void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40],
77
+                                      int8_t ref[2][40], int16_t mv[2][40][2],
78
+                                      int bidir, int edges, int step,
79
+                                      int mask_mv0, int mask_mv1, int field);
63 80
 
64 81
     /* IDCT */
65
-    void (*h264_idct_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride);
66
-    void (*h264_idct8_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride);
67
-    void (*h264_idct_dc_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride);
68
-    void (*h264_idct8_dc_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride);
82
+    void (*h264_idct_add)(uint8_t *dst /*align 4*/,
83
+                          DCTELEM *block /*align 16*/, int stride);
84
+    void (*h264_idct8_add)(uint8_t *dst /*align 8*/,
85
+                           DCTELEM *block /*align 16*/, int stride);
86
+    void (*h264_idct_dc_add)(uint8_t *dst /*align 4*/,
87
+                             DCTELEM *block /*align 16*/, int stride);
88
+    void (*h264_idct8_dc_add)(uint8_t *dst /*align 8*/,
89
+                              DCTELEM *block /*align 16*/, int stride);
69 90
 
70
-    void (*h264_idct_add16)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[15*8]);
71
-    void (*h264_idct8_add4)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[15*8]);
72
-    void (*h264_idct_add8)(uint8_t **dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[15*8]);
73
-    void (*h264_idct_add16intra)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[15*8]);
74
-    void (*h264_luma_dc_dequant_idct)(DCTELEM *output, DCTELEM *input/*align 16*/, int qmul);
91
+    void (*h264_idct_add16)(uint8_t *dst /*align 16*/, const int *blockoffset,
92
+                            DCTELEM *block /*align 16*/, int stride,
93
+                            const uint8_t nnzc[15 * 8]);
94
+    void (*h264_idct8_add4)(uint8_t *dst /*align 16*/, const int *blockoffset,
95
+                            DCTELEM *block /*align 16*/, int stride,
96
+                            const uint8_t nnzc[15 * 8]);
97
+    void (*h264_idct_add8)(uint8_t **dst /*align 16*/, const int *blockoffset,
98
+                           DCTELEM *block /*align 16*/, int stride,
99
+                           const uint8_t nnzc[15 * 8]);
100
+    void (*h264_idct_add16intra)(uint8_t *dst /*align 16*/, const int *blockoffset,
101
+                                 DCTELEM *block /*align 16*/,
102
+                                 int stride, const uint8_t nnzc[15 * 8]);
103
+    void (*h264_luma_dc_dequant_idct)(DCTELEM *output,
104
+                                      DCTELEM *input /*align 16*/, int qmul);
75 105
     void (*h264_chroma_dc_dequant_idct)(DCTELEM *block, int qmul);
76
-}H264DSPContext;
106
+} H264DSPContext;
77 107
 
78
-void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc);
79
-void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth, const int chroma_format_idc);
80
-void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth, const int chroma_format_idc);
81
-void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth, const int chroma_format_idc);
108
+void ff_h264dsp_init(H264DSPContext *c, const int bit_depth,
109
+                     const int chroma_format_idc);
110
+void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth,
111
+                         const int chroma_format_idc);
112
+void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth,
113
+                         const int chroma_format_idc);
114
+void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
115
+                         const int chroma_format_idc);
82 116
 
83 117
 #endif /* AVCODEC_H264DSP_H */
... ...
@@ -35,18 +35,18 @@
35 35
  * Prediction types
36 36
  */
37 37
 //@{
38
-#define VERT_PRED             0
39
-#define HOR_PRED              1
40
-#define DC_PRED               2
41
-#define DIAG_DOWN_LEFT_PRED   3
42
-#define DIAG_DOWN_RIGHT_PRED  4
43
-#define VERT_RIGHT_PRED       5
44
-#define HOR_DOWN_PRED         6
45
-#define VERT_LEFT_PRED        7
46
-#define HOR_UP_PRED           8
38
+#define VERT_PRED              0
39
+#define HOR_PRED               1
40
+#define DC_PRED                2
41
+#define DIAG_DOWN_LEFT_PRED    3
42
+#define DIAG_DOWN_RIGHT_PRED   4
43
+#define VERT_RIGHT_PRED        5
44
+#define HOR_DOWN_PRED          6
45
+#define VERT_LEFT_PRED         7
46
+#define HOR_UP_PRED            8
47 47
 
48 48
 // DC edge (not for VP8)
49
-#define LEFT_DC_PRED          9
49
+#define LEFT_DC_PRED           9
50 50
 #define TOP_DC_PRED           10
51 51
 #define DC_128_PRED           11
52 52
 
... ...
@@ -56,7 +56,7 @@
56 56
 #define VERT_LEFT_PRED_RV40_NODOWN        14
57 57
 
58 58
 // VP8 specific
59
-#define TM_VP8_PRED           9     ///< "True Motion", used instead of plane
59
+#define TM_VP8_PRED            9    ///< "True Motion", used instead of plane
60 60
 #define VERT_VP8_PRED         10    ///< for VP8, #VERT_PRED is the average of
61 61
                                     ///< (left col+cur col x2+right col) / 4;
62 62
                                     ///< this is the "unaveraged" one
... ...
@@ -65,44 +65,53 @@
65 65
 #define DC_127_PRED           12
66 66
 #define DC_129_PRED           13
67 67
 
68
-#define DC_PRED8x8            0
69
-#define HOR_PRED8x8           1
70
-#define VERT_PRED8x8          2
71
-#define PLANE_PRED8x8         3
68
+#define DC_PRED8x8             0
69
+#define HOR_PRED8x8            1
70
+#define VERT_PRED8x8           2
71
+#define PLANE_PRED8x8          3
72 72
 
73 73
 // DC edge
74
-#define LEFT_DC_PRED8x8       4
75
-#define TOP_DC_PRED8x8        5
76
-#define DC_128_PRED8x8        6
74
+#define LEFT_DC_PRED8x8        4
75
+#define TOP_DC_PRED8x8         5
76
+#define DC_128_PRED8x8         6
77 77
 
78 78
 // H264/SVQ3 (8x8) specific
79
-#define ALZHEIMER_DC_L0T_PRED8x8 7
80
-#define ALZHEIMER_DC_0LT_PRED8x8 8
81
-#define ALZHEIMER_DC_L00_PRED8x8 9
79
+#define ALZHEIMER_DC_L0T_PRED8x8  7
80
+#define ALZHEIMER_DC_0LT_PRED8x8  8
81
+#define ALZHEIMER_DC_L00_PRED8x8  9
82 82
 #define ALZHEIMER_DC_0L0_PRED8x8 10
83 83
 
84 84
 // VP8 specific
85
-#define DC_127_PRED8x8        7
86
-#define DC_129_PRED8x8        8
85
+#define DC_127_PRED8x8         7
86
+#define DC_129_PRED8x8         8
87 87
 //@}
88 88
 
89 89
 /**
90 90
  * Context for storing H.264 prediction functions
91 91
  */
92
-typedef struct H264PredContext{
93
-    void (*pred4x4  [9+3+3])(uint8_t *src, const uint8_t *topright, int stride);//FIXME move to dsp?
94
-    void (*pred8x8l [9+3])(uint8_t *src, int topleft, int topright, int stride);
95
-    void (*pred8x8  [4+3+4])(uint8_t *src, int stride);
96
-    void (*pred16x16[4+3+2])(uint8_t *src, int stride);
92
+typedef struct H264PredContext {
93
+    void(*pred4x4[9 + 3 + 3])(uint8_t *src, const uint8_t *topright, int stride); //FIXME move to dsp?
94
+    void(*pred8x8l[9 + 3])(uint8_t *src, int topleft, int topright, int stride);
95
+    void(*pred8x8[4 + 3 + 4])(uint8_t *src, int stride);
96
+    void(*pred16x16[4 + 3 + 2])(uint8_t *src, int stride);
97 97
 
98
-    void (*pred4x4_add  [2])(uint8_t *pix/*align  4*/, const DCTELEM *block/*align 16*/, int stride);
99
-    void (*pred8x8l_add [2])(uint8_t *pix/*align  8*/, const DCTELEM *block/*align 16*/, int stride);
100
-    void (*pred8x8_add  [3])(uint8_t *pix/*align  8*/, const int *block_offset, const DCTELEM *block/*align 16*/, int stride);
101
-    void (*pred16x16_add[3])(uint8_t *pix/*align 16*/, const int *block_offset, const DCTELEM *block/*align 16*/, int stride);
102
-}H264PredContext;
98
+    void(*pred4x4_add[2])(uint8_t *pix /*align  4*/,
99
+                          const DCTELEM *block /*align 16*/, int stride);
100
+    void(*pred8x8l_add[2])(uint8_t *pix /*align  8*/,
101
+                           const DCTELEM *block /*align 16*/, int stride);
102
+    void(*pred8x8_add[3])(uint8_t *pix /*align  8*/,
103
+                          const int *block_offset,
104
+                          const DCTELEM *block /*align 16*/, int stride);
105
+    void(*pred16x16_add[3])(uint8_t *pix /*align 16*/,
106
+                            const int *block_offset,
107
+                            const DCTELEM *block /*align 16*/, int stride);
108
+} H264PredContext;
103 109
 
104
-void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc);
105
-void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc);
106
-void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc);
110
+void ff_h264_pred_init(H264PredContext *h, int codec_id,
111
+                       const int bit_depth, const int chroma_format_idc);
112
+void ff_h264_pred_init_arm(H264PredContext *h, int codec_id,
113
+                           const int bit_depth, const int chroma_format_idc);
114
+void ff_h264_pred_init_x86(H264PredContext *h, int codec_id,
115
+                           const int bit_depth, const int chroma_format_idc);
107 116
 
108 117
 #endif /* AVCODEC_H264PRED_H */
... ...
@@ -21,39 +21,57 @@
21 21
 
22 22
 /**
23 23
  * @file
24
- * ati vcr1 codec.
24
+ * ATI VCR1 codec
25 25
  */
26 26
 
27 27
 #include "avcodec.h"
28 28
 #include "dsputil.h"
29 29
 
30
-//#undef NDEBUG
31
-//#include <assert.h>
32
-
33
-/* Disable the encoder. */
34
-#undef CONFIG_VCR1_ENCODER
35
-#define CONFIG_VCR1_ENCODER 0
36
-
37
-typedef struct VCR1Context{
38
-    AVCodecContext *avctx;
30
+typedef struct VCR1Context {
39 31
     AVFrame picture;
40 32
     int delta[16];
41 33
     int offset[4];
42 34
 } VCR1Context;
43 35
 
44
-static int decode_frame(AVCodecContext *avctx,
45
-                        void *data, int *data_size,
46
-                        AVPacket *avpkt)
36
+static av_cold void common_init(AVCodecContext *avctx)
37
+{
38
+    VCR1Context *const a = avctx->priv_data;
39
+
40
+    avctx->coded_frame = &a->picture;
41
+    avcodec_get_frame_defaults(&a->picture);
42
+}
43
+
44
+static av_cold int decode_init(AVCodecContext *avctx)
45
+{
46
+    common_init(avctx);
47
+
48
+    avctx->pix_fmt = PIX_FMT_YUV410P;
49
+
50
+    return 0;
51
+}
52
+
53
+static av_cold int decode_end(AVCodecContext *avctx)
54
+{
55
+    VCR1Context *s = avctx->priv_data;
56
+
57
+    if (s->picture.data[0])
58
+        avctx->release_buffer(avctx, &s->picture);
59
+
60
+    return 0;
61
+}
62
+
63
+static int decode_frame(AVCodecContext *avctx, void *data,
64
+                        int *data_size, AVPacket *avpkt)
47 65
 {
48
-    const uint8_t *buf = avpkt->data;
49
-    int buf_size = avpkt->size;
50
-    VCR1Context * const a = avctx->priv_data;
51
-    AVFrame *picture = data;
52
-    AVFrame * const p = &a->picture;
53
-    const uint8_t *bytestream= buf;
66
+    const uint8_t *buf        = avpkt->data;
67
+    int buf_size              = avpkt->size;
68
+    VCR1Context *const a      = avctx->priv_data;
69
+    AVFrame *picture          = data;
70
+    AVFrame *const p          = &a->picture;
71
+    const uint8_t *bytestream = buf;
54 72
     int i, x, y;
55 73
 
56
-    if(p->data[0])
74
+    if (p->data[0])
57 75
         avctx->release_buffer(avctx, p);
58 76
 
59 77
     if(buf_size < 16 + avctx->height + avctx->width*avctx->height*5/8){
... ...
@@ -61,57 +79,57 @@ static int decode_frame(AVCodecContext *avctx,
61 61
         return AVERROR(EINVAL);
62 62
     }
63 63
 
64
-    p->reference= 0;
65
-    if(avctx->get_buffer(avctx, p) < 0){
64
+    p->reference = 0;
65
+    if (avctx->get_buffer(avctx, p) < 0) {
66 66
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
67 67
         return -1;
68 68
     }
69
-    p->pict_type= AV_PICTURE_TYPE_I;
70
-    p->key_frame= 1;
69
+    p->pict_type = AV_PICTURE_TYPE_I;
70
+    p->key_frame = 1;
71 71
 
72
-    for(i=0; i<16; i++){
73
-        a->delta[i]= *(bytestream++);
72
+    for (i = 0; i < 16; i++) {
73
+        a->delta[i] = *bytestream++;
74 74
         bytestream++;
75 75
     }
76 76
 
77
-    for(y=0; y<avctx->height; y++){
77
+    for (y = 0; y < avctx->height; y++) {
78 78
         int offset;
79
-        uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
79
+        uint8_t *luma = &a->picture.data[0][y * a->picture.linesize[0]];
80 80
 
81
-        if((y&3) == 0){
82
-            uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
83
-            uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
81
+        if ((y & 3) == 0) {
82
+            uint8_t *cb = &a->picture.data[1][(y >> 2) * a->picture.linesize[1]];
83
+            uint8_t *cr = &a->picture.data[2][(y >> 2) * a->picture.linesize[2]];
84 84
 
85
-            for(i=0; i<4; i++)
86
-                a->offset[i]= *(bytestream++);
85
+            for (i = 0; i < 4; i++)
86
+                a->offset[i] = *bytestream++;
87 87
 
88
-            offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
89
-            for(x=0; x<avctx->width; x+=4){
90
-                luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
91
-                luma[1]=( offset += a->delta[ bytestream[2]>>4  ]);
92
-                luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
93
-                luma[3]=( offset += a->delta[ bytestream[0]>>4  ]);
94
-                luma += 4;
88
+            offset = a->offset[0] - a->delta[bytestream[2] & 0xF];
89
+            for (x = 0; x < avctx->width; x += 4) {
90
+                luma[0]     = offset += a->delta[bytestream[2] & 0xF];
91
+                luma[1]     = offset += a->delta[bytestream[2] >>  4];
92
+                luma[2]     = offset += a->delta[bytestream[0] & 0xF];
93
+                luma[3]     = offset += a->delta[bytestream[0] >>  4];
94
+                luma       += 4;
95 95
 
96
-                *(cb++) = bytestream[3];
97
-                *(cr++) = bytestream[1];
96
+                *cb++       = bytestream[3];
97
+                *cr++       = bytestream[1];
98 98
 
99
-                bytestream+= 4;
99
+                bytestream += 4;
100 100
             }
101
-        }else{
102
-            offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
103
-
104
-            for(x=0; x<avctx->width; x+=8){
105
-                luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
106
-                luma[1]=( offset += a->delta[ bytestream[2]>>4  ]);
107
-                luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
108
-                luma[3]=( offset += a->delta[ bytestream[3]>>4  ]);
109
-                luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
110
-                luma[5]=( offset += a->delta[ bytestream[0]>>4  ]);
111
-                luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
112
-                luma[7]=( offset += a->delta[ bytestream[1]>>4  ]);
113
-                luma += 8;
114
-                bytestream+= 4;
101
+        } else {
102
+            offset = a->offset[y & 3] - a->delta[bytestream[2] & 0xF];
103
+
104
+            for (x = 0; x < avctx->width; x += 8) {
105
+                luma[0]     = offset += a->delta[bytestream[2] & 0xF];
106
+                luma[1]     = offset += a->delta[bytestream[2] >>  4];
107
+                luma[2]     = offset += a->delta[bytestream[3] & 0xF];
108
+                luma[3]     = offset += a->delta[bytestream[3] >>  4];
109
+                luma[4]     = offset += a->delta[bytestream[0] & 0xF];
110
+                luma[5]     = offset += a->delta[bytestream[0] >>  4];
111
+                luma[6]     = offset += a->delta[bytestream[1] & 0xF];
112
+                luma[7]     = offset += a->delta[bytestream[1] >>  4];
113
+                luma       += 8;
114
+                bytestream += 4;
115 115
             }
116 116
         }
117 117
     }
... ...
@@ -122,62 +140,6 @@ static int decode_frame(AVCodecContext *avctx,
122 122
     return buf_size;
123 123
 }
124 124
 
125
-#if CONFIG_VCR1_ENCODER
126
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
127
-    VCR1Context * const a = avctx->priv_data;
128
-    AVFrame *pict = data;
129
-    AVFrame * const p = &a->picture;
130
-    int size;
131
-
132
-    *p = *pict;
133
-    p->pict_type= AV_PICTURE_TYPE_I;
134
-    p->key_frame= 1;
135
-
136
-    avpriv_align_put_bits(&a->pb);
137
-    while(get_bit_count(&a->pb)&31)
138
-        put_bits(&a->pb, 8, 0);
139
-
140
-    size= get_bit_count(&a->pb)/32;
141
-
142
-    return size*4;
143
-}
144
-#endif
145
-
146
-static av_cold void common_init(AVCodecContext *avctx){
147
-    VCR1Context * const a = avctx->priv_data;
148
-
149
-    avctx->coded_frame = &a->picture;
150
-    avcodec_get_frame_defaults(&a->picture);
151
-    a->avctx= avctx;
152
-}
153
-
154
-static av_cold int decode_init(AVCodecContext *avctx){
155
-
156
-    common_init(avctx);
157
-
158
-    avctx->pix_fmt= PIX_FMT_YUV410P;
159
-
160
-    return 0;
161
-}
162
-
163
-static av_cold int decode_end(AVCodecContext *avctx){
164
-    VCR1Context *s = avctx->priv_data;
165
-
166
-    if (s->picture.data[0])
167
-        avctx->release_buffer(avctx, &s->picture);
168
-
169
-    return 0;
170
-}
171
-
172
-#if CONFIG_VCR1_ENCODER
173
-static av_cold int encode_init(AVCodecContext *avctx){
174
-
175
-    common_init(avctx);
176
-
177
-    return 0;
178
-}
179
-#endif
180
-
181 125
 AVCodec ff_vcr1_decoder = {
182 126
     .name           = "vcr1",
183 127
     .type           = AVMEDIA_TYPE_VIDEO,
... ...
@@ -190,14 +152,39 @@ AVCodec ff_vcr1_decoder = {
190 190
     .long_name      = NULL_IF_CONFIG_SMALL("ATI VCR1"),
191 191
 };
192 192
 
193
+/* Disable the encoder. */
194
+#undef CONFIG_VCR1_ENCODER
195
+#define CONFIG_VCR1_ENCODER 0
196
+
193 197
 #if CONFIG_VCR1_ENCODER
198
+static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
199
+                        int buf_size, void *data)
200
+{
201
+    VCR1Context *const a = avctx->priv_data;
202
+    AVFrame *pict        = data;
203
+    AVFrame *const p     = &a->picture;
204
+    int size;
205
+
206
+    *p           = *pict;
207
+    p->pict_type = AV_PICTURE_TYPE_I;
208
+    p->key_frame = 1;
209
+
210
+    avpriv_align_put_bits(&a->pb);
211
+    while (get_bit_count(&a->pb) & 31)
212
+        put_bits(&a->pb, 8, 0);
213
+
214
+    size = get_bit_count(&a->pb) / 32;
215
+
216
+    return size * 4;
217
+}
218
+
194 219
 AVCodec ff_vcr1_encoder = {
195 220
     .name           = "vcr1",
196 221
     .type           = AVMEDIA_TYPE_VIDEO,
197 222
     .id             = CODEC_ID_VCR1,
198 223
     .priv_data_size = sizeof(VCR1Context),
199
-    .init           = encode_init,
224
+    .init           = common_init,
200 225
     .encode         = encode_frame,
201 226
     .long_name      = NULL_IF_CONFIG_SMALL("ATI VCR1"),
202 227
 };
203
-#endif
228
+#endif /* CONFIG_VCR1_ENCODER */
... ...
@@ -1792,6 +1792,22 @@ QPEL_2TAP(avg_, 16, 3dnow)
1792 1792
 QPEL_2TAP(put_,  8, 3dnow)
1793 1793
 QPEL_2TAP(avg_,  8, 3dnow)
1794 1794
 
1795
+void ff_put_rv40_qpel8_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
1796
+{
1797
+  put_pixels8_xy2_mmx(dst, src, stride, 8);
1798
+}
1799
+void ff_put_rv40_qpel16_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
1800
+{
1801
+  put_pixels16_xy2_mmx(dst, src, stride, 16);
1802
+}
1803
+void ff_avg_rv40_qpel8_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
1804
+{
1805
+  avg_pixels8_xy2_mmx(dst, src, stride, 8);
1806
+}
1807
+void ff_avg_rv40_qpel16_mc33_mmx(uint8_t *dst, uint8_t *src, int stride)
1808
+{
1809
+  avg_pixels16_xy2_mmx(dst, src, stride, 16);
1810
+}
1795 1811
 
1796 1812
 #if HAVE_YASM
1797 1813
 typedef void emu_edge_core_func(uint8_t *buf, const uint8_t *src,
... ...
@@ -199,6 +199,11 @@ void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
199 199
 void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd);
200 200
 void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd);
201 201
 
202
+void ff_put_rv40_qpel8_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
203
+void ff_put_rv40_qpel16_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
204
+void ff_avg_rv40_qpel8_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
205
+void ff_avg_rv40_qpel16_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
206
+
202 207
 void ff_mmx_idct(DCTELEM *block);
203 208
 void ff_mmxext_idct(DCTELEM *block);
204 209
 
... ...
@@ -1,5 +1,7 @@
1 1
 ;******************************************************************************
2 2
 ;* MMX/SSE2-optimized functions for the RV40 decoder
3
+;* Copyright (c) 2010 Ronald S. Bultje <rsbultje@gmail.com>
4
+;* Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.com>
3 5
 ;* Copyright (C) 2012 Christophe Gisquet <christophe.gisquet@gmail.com>
4 6
 ;*
5 7
 ;* This file is part of Libav.
... ...
@@ -25,11 +27,319 @@
25 25
 SECTION_RODATA
26 26
 
27 27
 align 16
28
-shift_round:   times 8 dw 1 << (16 - 6)
29
-cextern pw_16
28
+pw_1024:   times 8 dw 1 << (16 - 6) ; pw_1024
29
+
30
+sixtap_filter_hb_m:  times 8 db   1, -5
31
+                     times 8 db  52, 20
32
+                     ; multiplied by 2 to have the same shift
33
+                     times 8 db   2, -10
34
+                     times 8 db  40,  40
35
+                     ; back to normal
36
+                     times 8 db   1, -5
37
+                     times 8 db  20, 52
38
+
39
+sixtap_filter_v_m:   times 8 dw   1
40
+                     times 8 dw  -5
41
+                     times 8 dw  52
42
+                     times 8 dw  20
43
+                     ; multiplied by 2 to have the same shift
44
+                     times 8 dw   2
45
+                     times 8 dw -10
46
+                     times 8 dw  40
47
+                     times 8 dw  40
48
+                     ; back to normal
49
+                     times 8 dw   1
50
+                     times 8 dw  -5
51
+                     times 8 dw  20
52
+                     times 8 dw  52
53
+
54
+%ifdef PIC
55
+%define sixtap_filter_hw   picregq
56
+%define sixtap_filter_hb   picregq
57
+%define sixtap_filter_v    picregq
58
+%define npicregs 1
59
+%else
60
+%define sixtap_filter_hw   sixtap_filter_hw_m
61
+%define sixtap_filter_hb   sixtap_filter_hb_m
62
+%define sixtap_filter_v    sixtap_filter_v_m
63
+%define npicregs 0
64
+%endif
65
+
66
+filter_h6_shuf1: db 0, 1, 1, 2, 2, 3, 3, 4, 4, 5,  5, 6,  6,  7,  7,  8
67
+filter_h6_shuf2: db 2, 3, 3, 4, 4, 5, 5, 6, 6, 7,  7, 8,  8,  9,  9, 10
68
+filter_h6_shuf3: db 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11
69
+
70
+cextern  pw_32
71
+cextern  pw_16
72
+cextern  pw_512
30 73
 
31 74
 SECTION .text
32 75
 
76
+;-----------------------------------------------------------------------------
77
+; subpel MC functions:
78
+;
79
+; void [put|rv40]_rv40_qpel_[h|v]_<opt>(uint8_t *dst, int deststride,
80
+;                                       uint8_t *src, int srcstride,
81
+;                                       int len, int m);
82
+;----------------------------------------------------------------------
83
+%macro LOAD  2
84
+%if WIN64
85
+   movsxd   %1q, %1d
86
+%endif
87
+%ifdef PIC
88
+   add      %1q, picregq
89
+%else
90
+   add      %1q, %2
91
+%endif
92
+%endmacro
93
+
94
+%macro STORE 3
95
+%ifidn %3, avg
96
+    movh      %2, [dstq]
97
+%endif
98
+    packuswb  %1, %1
99
+%ifidn %3, avg
100
+%if cpuflag(3dnow)
101
+    pavgusb   %1, %2
102
+%else
103
+    pavgb     %1, %2
104
+%endif
105
+%endif
106
+    movh  [dstq], %1
107
+%endmacro
108
+
109
+%macro FILTER_V 1
110
+cglobal %1_rv40_qpel_v, 6,6+npicregs,12, dst, dststride, src, srcstride, height, my, picreg
111
+%ifdef PIC
112
+    lea  picregq, [sixtap_filter_v_m]
113
+%endif
114
+    pxor      m7, m7
115
+    LOAD      my, sixtap_filter_v
116
+
117
+    ; read 5 lines
118
+    sub     srcq, srcstrideq
119
+    sub     srcq, srcstrideq
120
+    movh      m0, [srcq]
121
+    movh      m1, [srcq+srcstrideq]
122
+    movh      m2, [srcq+srcstrideq*2]
123
+    lea     srcq, [srcq+srcstrideq*2]
124
+    add     srcq, srcstrideq
125
+    movh      m3, [srcq]
126
+    movh      m4, [srcq+srcstrideq]
127
+    punpcklbw m0, m7
128
+    punpcklbw m1, m7
129
+    punpcklbw m2, m7
130
+    punpcklbw m3, m7
131
+    punpcklbw m4, m7
132
+
133
+%ifdef m8
134
+    mova      m8, [myq+ 0]
135
+    mova      m9, [myq+16]
136
+    mova     m10, [myq+32]
137
+    mova     m11, [myq+48]
138
+%define COEFF05  m8
139
+%define COEFF14  m9
140
+%define COEFF2   m10
141
+%define COEFF3   m11
142
+%else
143
+%define COEFF05  [myq+ 0]
144
+%define COEFF14  [myq+16]
145
+%define COEFF2   [myq+32]
146
+%define COEFF3   [myq+48]
147
+%endif
148
+.nextrow:
149
+    mova      m6, m1
150
+    movh      m5, [srcq+2*srcstrideq]      ; read new row
151
+    paddw     m6, m4
152
+    punpcklbw m5, m7
153
+    pmullw    m6, COEFF14
154
+    paddw     m0, m5
155
+    pmullw    m0, COEFF05
156
+    paddw     m6, m0
157
+    mova      m0, m1
158
+    paddw     m6, [pw_32]
159
+    mova      m1, m2
160
+    pmullw    m2, COEFF2
161
+    paddw     m6, m2
162
+    mova      m2, m3
163
+    pmullw    m3, COEFF3
164
+    paddw     m6, m3
165
+
166
+    ; round/clip/store
167
+    mova      m3, m4
168
+    psraw     m6, 6
169
+    mova      m4, m5
170
+    STORE     m6, m5, %1
171
+
172
+    ; go to next line
173
+    add     dstq, dststrideq
174
+    add     srcq, srcstrideq
175
+    dec  heightd                           ; next row
176
+    jg .nextrow
177
+    REP_RET
178
+%endmacro
179
+
180
+%macro FILTER_H  1
181
+cglobal %1_rv40_qpel_h, 6, 6+npicregs, 12, dst, dststride, src, srcstride, height, mx, picreg
182
+%ifdef PIC
183
+    lea  picregq, [sixtap_filter_v_m]
184
+%endif
185
+    pxor      m7, m7
186
+    LOAD      mx, sixtap_filter_v
187
+    mova      m6, [pw_32]
188
+%ifdef m8
189
+    mova      m8, [mxq+ 0]
190
+    mova      m9, [mxq+16]
191
+    mova     m10, [mxq+32]
192
+    mova     m11, [mxq+48]
193
+%define COEFF05  m8
194
+%define COEFF14  m9
195
+%define COEFF2   m10
196
+%define COEFF3   m11
197
+%else
198
+%define COEFF05  [mxq+ 0]
199
+%define COEFF14  [mxq+16]
200
+%define COEFF2   [mxq+32]
201
+%define COEFF3   [mxq+48]
202
+%endif
203
+.nextrow:
204
+    movq      m0, [srcq-2]
205
+    movq      m5, [srcq+3]
206
+    movq      m1, [srcq-1]
207
+    movq      m4, [srcq+2]
208
+    punpcklbw m0, m7
209
+    punpcklbw m5, m7
210
+    punpcklbw m1, m7
211
+    punpcklbw m4, m7
212
+    movq      m2, [srcq-0]
213
+    movq      m3, [srcq+1]
214
+    paddw     m0, m5
215
+    paddw     m1, m4
216
+    punpcklbw m2, m7
217
+    punpcklbw m3, m7
218
+    pmullw    m0, COEFF05
219
+    pmullw    m1, COEFF14
220
+    pmullw    m2, COEFF2
221
+    pmullw    m3, COEFF3
222
+    paddw     m0, m6
223
+    paddw     m1, m2
224
+    paddw     m0, m3
225
+    paddw     m0, m1
226
+    psraw     m0, 6
227
+    STORE     m0, m1, %1
228
+
229
+    ; go to next line
230
+    add     dstq, dststrideq
231
+    add     srcq, srcstrideq
232
+    dec  heightd            ; next row
233
+    jg .nextrow
234
+    REP_RET
235
+%endmacro
236
+
237
+%if ARCH_X86_32
238
+INIT_MMX  mmx
239
+FILTER_V  put
240
+FILTER_H  put
241
+
242
+INIT_MMX  mmx2
243
+FILTER_V  avg
244
+FILTER_H  avg
245
+
246
+INIT_MMX  3dnow
247
+FILTER_V  avg
248
+FILTER_H  avg
249
+%endif
250
+
251
+INIT_XMM  sse2
252
+FILTER_H  put
253
+FILTER_H  avg
254
+FILTER_V  put
255
+FILTER_V  avg
256
+
257
+%macro FILTER_SSSE3 1
258
+cglobal %1_rv40_qpel_v, 6,6+npicregs,8, dst, dststride, src, srcstride, height, my, picreg
259
+%ifdef PIC
260
+    lea  picregq, [sixtap_filter_hb_m]
261
+%endif
262
+
263
+    ; read 5 lines
264
+    sub     srcq, srcstrideq
265
+    LOAD      my, sixtap_filter_hb
266
+    sub     srcq, srcstrideq
267
+    movh      m0, [srcq]
268
+    movh      m1, [srcq+srcstrideq]
269
+    movh      m2, [srcq+srcstrideq*2]
270
+    lea     srcq, [srcq+srcstrideq*2]
271
+    add     srcq, srcstrideq
272
+    mova      m5, [myq]
273
+    movh      m3, [srcq]
274
+    movh      m4, [srcq+srcstrideq]
275
+    lea     srcq, [srcq+2*srcstrideq]
276
+
277
+.nextrow:
278
+    mova      m6, m2
279
+    punpcklbw m0, m1
280
+    punpcklbw m6, m3
281
+    pmaddubsw m0, m5
282
+    pmaddubsw m6, [myq+16]
283
+    movh      m7, [srcq]      ; read new row
284
+    paddw     m6, m0
285
+    mova      m0, m1
286
+    mova      m1, m2
287
+    mova      m2, m3
288
+    mova      m3, m4
289
+    mova      m4, m7
290
+    punpcklbw m7, m3
291
+    pmaddubsw m7, m5
292
+    paddw     m6, m7
293
+    pmulhrsw  m6, [pw_512]
294
+    STORE     m6, m7, %1
295
+
296
+    ; go to next line
297
+    add     dstq, dststrideq
298
+    add     srcq, srcstrideq
299
+    dec       heightd                          ; next row
300
+    jg       .nextrow
301
+    REP_RET
302
+
303
+cglobal %1_rv40_qpel_h, 6,6+npicregs,8, dst, dststride, src, srcstride, height, mx, picreg
304
+%ifdef PIC
305
+    lea  picregq, [sixtap_filter_hb_m]
306
+%endif
307
+    mova      m3, [filter_h6_shuf2]
308
+    mova      m4, [filter_h6_shuf3]
309
+    LOAD      mx, sixtap_filter_hb
310
+    mova      m5, [mxq] ; set up 6tap filter in bytes
311
+    mova      m6, [mxq+16]
312
+    mova      m7, [filter_h6_shuf1]
313
+
314
+.nextrow:
315
+    movu      m0, [srcq-2]
316
+    mova      m1, m0
317
+    mova      m2, m0
318
+    pshufb    m0, m7
319
+    pshufb    m1, m3
320
+    pshufb    m2, m4
321
+    pmaddubsw m0, m5
322
+    pmaddubsw m1, m6
323
+    pmaddubsw m2, m5
324
+    paddw     m0, m1
325
+    paddw     m0, m2
326
+    pmulhrsw  m0, [pw_512]
327
+    STORE     m0, m1, %1
328
+
329
+    ; go to next line
330
+    add     dstq, dststrideq
331
+    add     srcq, srcstrideq
332
+    dec  heightd            ; next row
333
+    jg .nextrow
334
+    REP_RET
335
+%endmacro
336
+
337
+INIT_XMM ssse3
338
+FILTER_SSSE3  put
339
+FILTER_SSSE3  avg
340
+
33 341
 ; %1=5bits weights?, %2=dst %3=src1 %4=src3 %5=stride if sse2
34 342
 %macro RV40_WCORE  4-5
35 343
     movh       m4, [%3 + r6 + 0]
... ...
@@ -143,7 +453,7 @@ SECTION .text
143 143
 %macro RV40_WEIGHT  3
144 144
 cglobal rv40_weight_func_%1_%2, 6, 7, 8
145 145
 %if cpuflag(ssse3)
146
-    mova       m1, [shift_round]
146
+    mova       m1, [pw_1024]
147 147
 %else
148 148
     mova       m1, [pw_16]
149 149
 %endif
... ...
@@ -22,8 +22,11 @@
22 22
 /**
23 23
  * @file
24 24
  * RV40 decoder motion compensation functions x86-optimised
25
+ * 2,0 and 0,2 have h264 equivalents.
26
+ * 3,3 is bugged in the rv40 format and maps to _xy2 version
25 27
  */
26 28
 
29
+#include "libavcodec/x86/dsputil_mmx.h"
27 30
 #include "libavcodec/rv34dsp.h"
28 31
 
29 32
 void ff_put_rv40_chroma_mc8_mmx  (uint8_t *dst, uint8_t *src,
... ...
@@ -53,6 +56,132 @@ DECLARE_WEIGHT(mmx)
53 53
 DECLARE_WEIGHT(sse2)
54 54
 DECLARE_WEIGHT(ssse3)
55 55
 
56
+/** @{ */
57
+/**
58
+ * Define one qpel function.
59
+ * LOOPSIZE must be already set to the number of pixels processed per
60
+ * iteration in the inner loop of the called functions.
61
+ * COFF(x) must be already defined so as to provide the offset into any
62
+ * array of coeffs used by the called function for the qpel position x.
63
+ */
64
+#define QPEL_FUNC_DECL(OP, SIZE, PH, PV, OPT)                           \
65
+static void OP ## rv40_qpel ##SIZE ##_mc ##PH ##PV ##OPT(uint8_t *dst,  \
66
+                                                         uint8_t *src,  \
67
+                                                         int stride)    \
68
+{                                                                       \
69
+    int i;                                                              \
70
+    if (PH && PV) {                                                     \
71
+        DECLARE_ALIGNED(16, uint8_t, tmp)[SIZE * (SIZE + 5)];           \
72
+        uint8_t *tmpptr = tmp + SIZE * 2;                               \
73
+        src -= stride * 2;                                              \
74
+                                                                        \
75
+        for (i = 0; i < SIZE; i += LOOPSIZE)                            \
76
+            ff_put_rv40_qpel_h ##OPT(tmp + i, SIZE, src + i, stride,    \
77
+                                     SIZE + 5, HCOFF(PH));              \
78
+        for (i = 0; i < SIZE; i += LOOPSIZE)                            \
79
+            ff_ ##OP ##rv40_qpel_v ##OPT(dst + i, stride, tmpptr + i,   \
80
+                                         SIZE, SIZE, VCOFF(PV));        \
81
+    } else if (PV) {                                                    \
82
+        for (i = 0; i < SIZE; i += LOOPSIZE)                            \
83
+            ff_ ##OP ##rv40_qpel_v ## OPT(dst + i, stride, src + i,     \
84
+                                          stride, SIZE, VCOFF(PV));     \
85
+    } else {                                                            \
86
+        for (i = 0; i < SIZE; i += LOOPSIZE)                            \
87
+            ff_ ##OP ##rv40_qpel_h ## OPT(dst + i, stride, src + i,     \
88
+                                          stride, SIZE, HCOFF(PH));     \
89
+    }                                                                   \
90
+};
91
+
92
+/** Declare functions for sizes 8 and 16 and given operations
93
+ *  and qpel position. */
94
+#define QPEL_FUNCS_DECL(OP, PH, PV, OPT) \
95
+    QPEL_FUNC_DECL(OP,  8, PH, PV, OPT)  \
96
+    QPEL_FUNC_DECL(OP, 16, PH, PV, OPT)
97
+
98
+/** Declare all functions for all sizes and qpel positions */
99
+#define QPEL_MC_DECL(OP, OPT)                                           \
100
+void ff_ ##OP ##rv40_qpel_h ##OPT(uint8_t *dst, ptrdiff_t dstStride,    \
101
+                                  const uint8_t *src,                   \
102
+                                  ptrdiff_t srcStride,                  \
103
+                                  int len, int m);                      \
104
+void ff_ ##OP ##rv40_qpel_v ##OPT(uint8_t *dst, ptrdiff_t dstStride,    \
105
+                                  const uint8_t *src,                   \
106
+                                  ptrdiff_t srcStride,                  \
107
+                                  int len, int m);                      \
108
+QPEL_FUNCS_DECL(OP, 0, 1, OPT)                                          \
109
+QPEL_FUNCS_DECL(OP, 0, 3, OPT)                                          \
110
+QPEL_FUNCS_DECL(OP, 1, 0, OPT)                                          \
111
+QPEL_FUNCS_DECL(OP, 1, 1, OPT)                                          \
112
+QPEL_FUNCS_DECL(OP, 1, 2, OPT)                                          \
113
+QPEL_FUNCS_DECL(OP, 1, 3, OPT)                                          \
114
+QPEL_FUNCS_DECL(OP, 2, 1, OPT)                                          \
115
+QPEL_FUNCS_DECL(OP, 2, 2, OPT)                                          \
116
+QPEL_FUNCS_DECL(OP, 2, 3, OPT)                                          \
117
+QPEL_FUNCS_DECL(OP, 3, 0, OPT)                                          \
118
+QPEL_FUNCS_DECL(OP, 3, 1, OPT)                                          \
119
+QPEL_FUNCS_DECL(OP, 3, 2, OPT)
120
+/** @} */
121
+
122
+#define LOOPSIZE  8
123
+#define HCOFF(x)  (32 * (x - 1))
124
+#define VCOFF(x)  (32 * (x - 1))
125
+QPEL_MC_DECL(put_, _ssse3)
126
+QPEL_MC_DECL(avg_, _ssse3)
127
+
128
+#undef LOOPSIZE
129
+#undef HCOFF
130
+#undef VCOFF
131
+#define LOOPSIZE  8
132
+#define HCOFF(x)  (64 * (x - 1))
133
+#define VCOFF(x)  (64 * (x - 1))
134
+QPEL_MC_DECL(put_, _sse2)
135
+QPEL_MC_DECL(avg_, _sse2)
136
+
137
+#if ARCH_X86_32
138
+#undef LOOPSIZE
139
+#undef HCOFF
140
+#undef VCOFF
141
+#define LOOPSIZE  4
142
+#define HCOFF(x)  (64 * (x - 1))
143
+#define VCOFF(x)  (64 * (x - 1))
144
+
145
+QPEL_MC_DECL(put_, _mmx)
146
+
147
+#define ff_put_rv40_qpel_h_mmx2  ff_put_rv40_qpel_h_mmx
148
+#define ff_put_rv40_qpel_v_mmx2  ff_put_rv40_qpel_v_mmx
149
+QPEL_MC_DECL(avg_, _mmx2)
150
+
151
+#define ff_put_rv40_qpel_h_3dnow  ff_put_rv40_qpel_h_mmx
152
+#define ff_put_rv40_qpel_v_3dnow  ff_put_rv40_qpel_v_mmx
153
+QPEL_MC_DECL(avg_, _3dnow)
154
+#endif
155
+
156
+/** @{ */
157
+/** Set one function */
158
+#define QPEL_FUNC_SET(OP, SIZE, PH, PV, OPT)                            \
159
+    c-> OP ## pixels_tab[2 - SIZE / 8][4 * PV + PH] = OP ## rv40_qpel ##SIZE ## _mc ##PH ##PV ##OPT;
160
+
161
+/** Set functions put and avg for sizes 8 and 16 and a given qpel position */
162
+#define QPEL_FUNCS_SET(OP, PH, PV, OPT)         \
163
+    QPEL_FUNC_SET(OP,  8, PH, PV, OPT)          \
164
+    QPEL_FUNC_SET(OP, 16, PH, PV, OPT)
165
+
166
+/** Set all functions for all sizes and qpel positions */
167
+#define QPEL_MC_SET(OP, OPT)   \
168
+QPEL_FUNCS_SET (OP, 0, 1, OPT) \
169
+QPEL_FUNCS_SET (OP, 0, 3, OPT) \
170
+QPEL_FUNCS_SET (OP, 1, 0, OPT) \
171
+QPEL_FUNCS_SET (OP, 1, 1, OPT) \
172
+QPEL_FUNCS_SET (OP, 1, 2, OPT) \
173
+QPEL_FUNCS_SET (OP, 1, 3, OPT) \
174
+QPEL_FUNCS_SET (OP, 2, 1, OPT) \
175
+QPEL_FUNCS_SET (OP, 2, 2, OPT) \
176
+QPEL_FUNCS_SET (OP, 2, 3, OPT) \
177
+QPEL_FUNCS_SET (OP, 3, 0, OPT) \
178
+QPEL_FUNCS_SET (OP, 3, 1, OPT) \
179
+QPEL_FUNCS_SET (OP, 3, 2, OPT)
180
+/** @} */
181
+
56 182
 void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
57 183
 {
58 184
 #if HAVE_YASM
... ...
@@ -65,25 +194,42 @@ void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
65 65
         c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_mmx;
66 66
         c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_mmx;
67 67
         c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_mmx;
68
+        c->put_pixels_tab[0][15] = ff_put_rv40_qpel16_mc33_mmx;
69
+        c->put_pixels_tab[1][15] = ff_put_rv40_qpel8_mc33_mmx;
70
+        c->avg_pixels_tab[0][15] = ff_avg_rv40_qpel16_mc33_mmx;
71
+        c->avg_pixels_tab[1][15] = ff_avg_rv40_qpel8_mc33_mmx;
72
+#if ARCH_X86_32
73
+        QPEL_MC_SET(put_, _mmx)
74
+#endif
68 75
     }
69 76
     if (mm_flags & AV_CPU_FLAG_MMX2) {
70 77
         c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_mmx2;
71 78
         c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_mmx2;
79
+#if ARCH_X86_32
80
+        QPEL_MC_SET(avg_, _mmx2)
81
+#endif
72 82
     } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
73 83
         c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_3dnow;
74 84
         c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_3dnow;
85
+#if ARCH_X86_32
86
+        QPEL_MC_SET(avg_, _3dnow)
87
+#endif
75 88
     }
76 89
     if (mm_flags & AV_CPU_FLAG_SSE2) {
77 90
         c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_sse2;
78 91
         c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_sse2;
79 92
         c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_sse2;
80 93
         c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_sse2;
94
+        QPEL_MC_SET(put_, _sse2)
95
+        QPEL_MC_SET(avg_, _sse2)
81 96
     }
82 97
     if (mm_flags & AV_CPU_FLAG_SSSE3) {
83 98
         c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_ssse3;
84 99
         c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_ssse3;
85 100
         c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_ssse3;
86 101
         c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_ssse3;
102
+        QPEL_MC_SET(put_, _ssse3)
103
+        QPEL_MC_SET(avg_, _ssse3)
87 104
     }
88 105
 #endif
89 106
 }
... ...
@@ -21,6 +21,7 @@ HEADERS = asrc_abuffer.h                                                \
21 21
           vsrc_buffer.h                                                 \
22 22
 
23 23
 OBJS = allfilters.o                                                     \
24
+       audio.o                                                          \
24 25
        avfilter.o                                                       \
25 26
        avfiltergraph.o                                                  \
26 27
        buffersink.o                                                     \
... ...
@@ -144,7 +144,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref
144 144
     AConvertContext *aconvert = inlink->dst->priv;
145 145
     const int n = insamplesref->audio->nb_samples;
146 146
     AVFilterLink *const outlink = inlink->dst->outputs[0];
147
-    AVFilterBufferRef *outsamplesref = avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, n);
147
+    AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);
148 148
 
149 149
     swr_convert(aconvert->swr, outsamplesref->data, n,
150 150
                         (void *)insamplesref->data, n);
... ...
@@ -153,7 +153,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref
153 153
     outsamplesref->audio->channel_layout = outlink->channel_layout;
154 154
     outsamplesref->audio->planar         = outlink->planar;
155 155
 
156
-    avfilter_filter_samples(outlink, outsamplesref);
156
+    ff_filter_samples(outlink, outsamplesref);
157 157
     avfilter_unref_buffer(insamplesref);
158 158
 }
159 159
 
... ...
@@ -89,7 +89,7 @@ static int query_formats(AVFilterContext *ctx)
89 89
 
90 90
 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
91 91
 {
92
-    avfilter_filter_samples(inlink->dst->outputs[0], insamplesref);
92
+    ff_filter_samples(inlink->dst->outputs[0], insamplesref);
93 93
 }
94 94
 
95 95
 AVFilter avfilter_af_aformat = {
... ...
@@ -208,7 +208,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
208 208
 
209 209
     nb_samples = FFMIN(am->queue[0].nb_samples,
210 210
                        am->queue[1].nb_samples);
211
-    outbuf = avfilter_get_audio_buffer(ctx->outputs[0], AV_PERM_WRITE,
211
+    outbuf = ff_get_audio_buffer(ctx->outputs[0], AV_PERM_WRITE,
212 212
                                        nb_samples);
213 213
     outs = outbuf->data[0];
214 214
     for (i = 0; i < 2; i++) {
... ...
@@ -264,7 +264,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
264 264
                     am->queue[i].nb_buf * sizeof(**inbuf));
265 265
         }
266 266
     }
267
-    avfilter_filter_samples(ctx->outputs[0], outbuf);
267
+    ff_filter_samples(ctx->outputs[0], outbuf);
268 268
 }
269 269
 
270 270
 AVFilter avfilter_af_amerge = {
... ...
@@ -21,6 +21,7 @@
21 21
  * null audio filter
22 22
  */
23 23
 
24
+#include "audio.h"
24 25
 #include "avfilter.h"
25 26
 
26 27
 AVFilter avfilter_af_anull = {
... ...
@@ -31,8 +32,8 @@ AVFilter avfilter_af_anull = {
31 31
 
32 32
     .inputs    = (const AVFilterPad[]) {{ .name       = "default",
33 33
                                     .type             = AVMEDIA_TYPE_AUDIO,
34
-                                    .get_audio_buffer = avfilter_null_get_audio_buffer,
35
-                                    .filter_samples   = avfilter_null_filter_samples },
34
+                                    .get_audio_buffer = ff_null_get_audio_buffer,
35
+                                    .filter_samples   = ff_null_filter_samples },
36 36
                                   { .name = NULL}},
37 37
 
38 38
     .outputs   = (const AVFilterPad[]) {{ .name       = "default",
... ...
@@ -92,7 +92,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref
92 92
     const int n_in  = insamplesref->audio->nb_samples;
93 93
     int n_out       = n_in * aresample->ratio;
94 94
     AVFilterLink *const outlink = inlink->dst->outputs[0];
95
-    AVFilterBufferRef *outsamplesref = avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, n_out);
95
+    AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n_out);
96 96
 
97 97
     n_out = swr_convert(aresample->swr, outsamplesref->data, n_out,
98 98
                                  (void *)insamplesref->data, n_in);
... ...
@@ -103,7 +103,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref
103 103
     outsamplesref->pts = insamplesref->pts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE :
104 104
         av_rescale(outlink->sample_rate, insamplesref->pts, inlink ->sample_rate);
105 105
 
106
-    avfilter_filter_samples(outlink, outsamplesref);
106
+    ff_filter_samples(outlink, outsamplesref);
107 107
     avfilter_unref_buffer(insamplesref);
108 108
 }
109 109
 
... ...
@@ -83,7 +83,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
83 83
     av_log(ctx, AV_LOG_INFO, "]\n");
84 84
 
85 85
     showinfo->frame++;
86
-    avfilter_filter_samples(inlink->dst->outputs[0], samplesref);
86
+    ff_filter_samples(inlink->dst->outputs[0], samplesref);
87 87
 }
88 88
 
89 89
 AVFilter avfilter_af_ashowinfo = {
... ...
@@ -95,7 +95,7 @@ AVFilter avfilter_af_ashowinfo = {
95 95
 
96 96
     .inputs    = (const AVFilterPad[]) {{ .name       = "default",
97 97
                                     .type             = AVMEDIA_TYPE_AUDIO,
98
-                                    .get_audio_buffer = avfilter_null_get_audio_buffer,
98
+                                    .get_audio_buffer = ff_null_get_audio_buffer,
99 99
                                     .filter_samples   = filter_samples,
100 100
                                     .min_perms        = AV_PERM_READ, },
101 101
                                   { .name = NULL}},
... ...
@@ -27,9 +27,9 @@
27 27
 
28 28
 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
29 29
 {
30
-    avfilter_filter_samples(inlink->dst->outputs[0],
30
+    ff_filter_samples(inlink->dst->outputs[0],
31 31
                             avfilter_ref_buffer(insamples, ~AV_PERM_WRITE));
32
-    avfilter_filter_samples(inlink->dst->outputs[1],
32
+    ff_filter_samples(inlink->dst->outputs[1],
33 33
                             avfilter_ref_buffer(insamples, ~AV_PERM_WRITE));
34 34
     avfilter_unref_buffer(insamples);
35 35
 }
... ...
@@ -41,7 +41,7 @@ AVFilter avfilter_af_asplit = {
41 41
     .inputs = (const AVFilterPad[]) {
42 42
         { .name             = "default",
43 43
           .type             = AVMEDIA_TYPE_AUDIO,
44
-          .get_audio_buffer = avfilter_null_get_audio_buffer,
44
+          .get_audio_buffer = ff_null_get_audio_buffer,
45 45
           .filter_samples   = filter_samples, },
46 46
         { .name = NULL}
47 47
     },
... ...
@@ -119,7 +119,7 @@ static void send_out(AVFilterContext *ctx, int out_id)
119 119
             av_q2d(ctx->outputs[out_id]->time_base) * buf->pts;
120 120
     as->var_values[VAR_T1 + out_id] += buf->audio->nb_samples /
121 121
                                    (double)ctx->inputs[out_id]->sample_rate;
122
-    avfilter_filter_samples(ctx->outputs[out_id], buf);
122
+    ff_filter_samples(ctx->outputs[out_id], buf);
123 123
     queue->nb--;
124 124
     queue->tail = (queue->tail + 1) % QUEUE_SIZE;
125 125
     if (as->req[out_id])
... ...
@@ -122,7 +122,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
122 122
     AVFilterLink *outlink = inlink->dst->outputs[0];
123 123
     int16_t *taps, *endin, *in, *out;
124 124
     AVFilterBufferRef *outsamples =
125
-        avfilter_get_audio_buffer(inlink, AV_PERM_WRITE,
125
+        ff_get_audio_buffer(inlink, AV_PERM_WRITE,
126 126
                                   insamples->audio->nb_samples);
127 127
     avfilter_copy_buffer_ref_props(outsamples, insamples);
128 128
 
... ...
@@ -141,7 +141,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
141 141
     // save part of input for next round
142 142
     memcpy(taps, endin, NUMTAPS * sizeof(*taps));
143 143
 
144
-    avfilter_filter_samples(outlink, outsamples);
144
+    ff_filter_samples(outlink, outsamples);
145 145
     avfilter_unref_buffer(insamples);
146 146
 }
147 147
 
... ...
@@ -340,7 +340,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
340 340
 {
341 341
     int n = insamples->audio->nb_samples;
342 342
     AVFilterLink *const outlink = inlink->dst->outputs[0];
343
-    AVFilterBufferRef *outsamples = avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, n);
343
+    AVFilterBufferRef *outsamples = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);
344 344
     PanContext *pan = inlink->dst->priv;
345 345
 
346 346
     swr_convert(pan->swr, outsamples->data, n, (void *)insamples->data, n);
... ...
@@ -348,7 +348,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
348 348
     outsamples->audio->channel_layout = outlink->channel_layout;
349 349
     outsamples->audio->planar         = outlink->planar;
350 350
 
351
-    avfilter_filter_samples(outlink, outsamples);
351
+    ff_filter_samples(outlink, outsamples);
352 352
     avfilter_unref_buffer(insamples);
353 353
 }
354 354
 
... ...
@@ -123,7 +123,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
123 123
         }
124 124
     }
125 125
 
126
-    avfilter_filter_samples(inlink->dst->outputs[0], insamples);
126
+    ff_filter_samples(inlink->dst->outputs[0], insamples);
127 127
 }
128 128
 
129 129
 static int query_formats(AVFilterContext *ctx)
... ...
@@ -163,7 +163,7 @@ AVFilter avfilter_af_silencedetect = {
163 163
     .inputs = (const AVFilterPad[]) {
164 164
         { .name             = "default",
165 165
           .type             = AVMEDIA_TYPE_AUDIO,
166
-          .get_audio_buffer = avfilter_null_get_audio_buffer,
166
+          .get_audio_buffer = ff_null_get_audio_buffer,
167 167
           .filter_samples   = filter_samples, },
168 168
         { .name = NULL }
169 169
     },
... ...
@@ -167,7 +167,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
167 167
         }
168 168
         }
169 169
     }
170
-    avfilter_filter_samples(outlink, insamples);
170
+    ff_filter_samples(outlink, insamples);
171 171
 }
172 172
 
173 173
 AVFilter avfilter_af_volume = {
... ...
@@ -205,7 +205,7 @@ static int request_frame(AVFilterLink *outlink)
205 205
     if (eval->duration >= 0 && t > eval->duration)
206 206
         return AVERROR_EOF;
207 207
 
208
-    samplesref = avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, eval->nb_samples);
208
+    samplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, eval->nb_samples);
209 209
 
210 210
     /* evaluate expression for each single sample and for each channel */
211 211
     for (i = 0; i < eval->nb_samples; i++, eval->n++) {
... ...
@@ -223,7 +223,7 @@ static int request_frame(AVFilterLink *outlink)
223 223
     samplesref->audio->sample_rate = eval->sample_rate;
224 224
     eval->pts += eval->nb_samples;
225 225
 
226
-    avfilter_filter_samples(outlink, samplesref);
226
+    ff_filter_samples(outlink, samplesref);
227 227
 
228 228
     return 0;
229 229
 }
... ...
@@ -108,13 +108,13 @@ static int request_frame(AVFilterLink *outlink)
108 108
     AVFilterBufferRef *samplesref;
109 109
 
110 110
     samplesref =
111
-        avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
111
+        ff_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
112 112
     samplesref->pts = null->pts;
113 113
     samplesref->pos = -1;
114 114
     samplesref->audio->channel_layout = null->channel_layout;
115 115
     samplesref->audio->sample_rate = outlink->sample_rate;
116 116
 
117
-    avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
117
+    ff_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
118 118
     avfilter_unref_buffer(samplesref);
119 119
 
120 120
     null->pts += null->nb_samples;
121 121
new file mode 100644
... ...
@@ -0,0 +1,291 @@
0
+/*
1
+ * Copyright (c) Stefano Sabatini | stefasab at gmail.com
2
+ * Copyright (c) S.N. Hemanth Meenakshisundaram | smeenaks at ucsd.edu
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "libavutil/avassert.h"
22
+#include "libavutil/audioconvert.h"
23
+
24
+#include "audio.h"
25
+#include "avfilter.h"
26
+#include "internal.h"
27
+
28
+AVFilterBufferRef *ff_null_get_audio_buffer(AVFilterLink *link, int perms,
29
+                                            int nb_samples)
30
+{
31
+    return ff_get_audio_buffer(link->dst->outputs[0], perms, nb_samples);
32
+}
33
+
34
+AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms,
35
+                                                     int nb_samples)
36
+{
37
+    AVFilterBufferRef *samplesref = NULL;
38
+    int linesize[8] = {0};
39
+    uint8_t *data[8] = {0};
40
+    int ch, nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
41
+
42
+    /* right now we don't support more than 8 channels */
43
+    av_assert0(nb_channels <= 8);
44
+
45
+    /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
46
+    if (av_samples_alloc(data, linesize,
47
+                         nb_channels, nb_samples,
48
+                         av_get_alt_sample_fmt(link->format, link->planar),
49
+                         16) < 0)
50
+        return NULL;
51
+
52
+    for (ch = 1; link->planar && ch < nb_channels; ch++)
53
+        linesize[ch] = linesize[0];
54
+    samplesref =
55
+        avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms,
56
+                                                  nb_samples, link->format,
57
+                                                  link->channel_layout, link->planar);
58
+    if (!samplesref) {
59
+        av_free(data[0]);
60
+        return NULL;
61
+    }
62
+
63
+    return samplesref;
64
+}
65
+
66
+static AVFilterBufferRef *ff_default_get_audio_buffer_alt(AVFilterLink *link, int perms,
67
+                                               int nb_samples)
68
+{
69
+    AVFilterBufferRef *samplesref = NULL;
70
+    uint8_t **data;
71
+    int planar      = av_sample_fmt_is_planar(link->format);
72
+    int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
73
+    int planes      = planar ? nb_channels : 1;
74
+    int linesize;
75
+
76
+    if (!(data = av_mallocz(sizeof(*data) * planes)))
77
+        goto fail;
78
+
79
+    if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0)
80
+        goto fail;
81
+
82
+    samplesref = avfilter_get_audio_buffer_ref_from_arrays_alt(data, linesize, perms,
83
+                                                           nb_samples, link->format,
84
+                                                           link->channel_layout);
85
+    if (!samplesref)
86
+        goto fail;
87
+
88
+    av_freep(&data);
89
+
90
+fail:
91
+    if (data)
92
+        av_freep(&data[0]);
93
+    av_freep(&data);
94
+    return samplesref;
95
+}
96
+
97
+AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms,
98
+                                       int nb_samples)
99
+{
100
+    AVFilterBufferRef *ret = NULL;
101
+
102
+    if (link->dstpad->get_audio_buffer)
103
+        ret = link->dstpad->get_audio_buffer(link, perms, nb_samples);
104
+
105
+    if (!ret)
106
+        ret = ff_default_get_audio_buffer(link, perms, nb_samples);
107
+
108
+    if (ret)
109
+        ret->type = AVMEDIA_TYPE_AUDIO;
110
+
111
+    return ret;
112
+}
113
+
114
+AVFilterBufferRef *
115
+avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
116
+                                          int nb_samples, enum AVSampleFormat sample_fmt,
117
+                                          uint64_t channel_layout, int planar)
118
+{
119
+    AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
120
+    AVFilterBufferRef *samplesref = av_mallocz(sizeof(AVFilterBufferRef));
121
+
122
+    if (!samples || !samplesref)
123
+        goto fail;
124
+
125
+    samplesref->buf = samples;
126
+    samplesref->buf->free = ff_avfilter_default_free_buffer;
127
+    if (!(samplesref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps))))
128
+        goto fail;
129
+
130
+    samplesref->audio->nb_samples     = nb_samples;
131
+    samplesref->audio->channel_layout = channel_layout;
132
+    samplesref->audio->planar         = planar;
133
+
134
+    /* make sure the buffer gets read permission or it's useless for output */
135
+    samplesref->perms = perms | AV_PERM_READ;
136
+
137
+    samples->refcount = 1;
138
+    samplesref->type = AVMEDIA_TYPE_AUDIO;
139
+    samplesref->format = sample_fmt;
140
+
141
+    memcpy(samples->data,        data,     sizeof(samples->data));
142
+    memcpy(samples->linesize,    linesize, sizeof(samples->linesize));
143
+    memcpy(samplesref->data,     data,     sizeof(samplesref->data));
144
+    memcpy(samplesref->linesize, linesize, sizeof(samplesref->linesize));
145
+
146
+    return samplesref;
147
+
148
+fail:
149
+    if (samplesref && samplesref->audio)
150
+        av_freep(&samplesref->audio);
151
+    av_freep(&samplesref);
152
+    av_freep(&samples);
153
+    return NULL;
154
+}
155
+
156
+AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays_alt(uint8_t **data,
157
+                                                             int linesize,int perms,
158
+                                                             int nb_samples,
159
+                                                             enum AVSampleFormat sample_fmt,
160
+                                                             uint64_t channel_layout)
161
+{
162
+    int planes;
163
+    AVFilterBuffer    *samples    = av_mallocz(sizeof(*samples));
164
+    AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref));
165
+
166
+    if (!samples || !samplesref)
167
+        goto fail;
168
+
169
+    samplesref->buf         = samples;
170
+    samplesref->buf->free   = ff_avfilter_default_free_buffer;
171
+    if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio))))
172
+        goto fail;
173
+
174
+    samplesref->audio->nb_samples     = nb_samples;
175
+    samplesref->audio->channel_layout = channel_layout;
176
+    samplesref->audio->planar         = av_sample_fmt_is_planar(sample_fmt);
177
+
178
+    planes = samplesref->audio->planar ? av_get_channel_layout_nb_channels(channel_layout) : 1;
179
+
180
+    /* make sure the buffer gets read permission or it's useless for output */
181
+    samplesref->perms = perms | AV_PERM_READ;
182
+
183
+    samples->refcount  = 1;
184
+    samplesref->type   = AVMEDIA_TYPE_AUDIO;
185
+    samplesref->format = sample_fmt;
186
+
187
+    memcpy(samples->data, data,
188
+           FFMIN(FF_ARRAY_ELEMS(samples->data), planes)*sizeof(samples->data[0]));
189
+    memcpy(samplesref->data, samples->data, sizeof(samples->data));
190
+
191
+    samples->linesize[0] = samplesref->linesize[0] = linesize;
192
+
193
+    if (planes > FF_ARRAY_ELEMS(samples->data)) {
194
+        samples->   extended_data = av_mallocz(sizeof(*samples->extended_data) *
195
+                                               planes);
196
+        samplesref->extended_data = av_mallocz(sizeof(*samplesref->extended_data) *
197
+                                               planes);
198
+
199
+        if (!samples->extended_data || !samplesref->extended_data)
200
+            goto fail;
201
+
202
+        memcpy(samples->   extended_data, data, sizeof(*data)*planes);
203
+        memcpy(samplesref->extended_data, data, sizeof(*data)*planes);
204
+    } else {
205
+        samples->extended_data    = samples->data;
206
+        samplesref->extended_data = samplesref->data;
207
+    }
208
+
209
+    return samplesref;
210
+
211
+fail:
212
+    if (samples && samples->extended_data != samples->data)
213
+        av_freep(&samples->extended_data);
214
+    if (samplesref) {
215
+        av_freep(&samplesref->audio);
216
+        if (samplesref->extended_data != samplesref->data)
217
+            av_freep(&samplesref->extended_data);
218
+    }
219
+    av_freep(&samplesref);
220
+    av_freep(&samples);
221
+    return NULL;
222
+}
223
+
224
+void ff_null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
225
+{
226
+    ff_filter_samples(link->dst->outputs[0], samplesref);
227
+}
228
+
229
+/* FIXME: samplesref is same as link->cur_buf. Need to consider removing the redundant parameter. */
230
+void ff_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
231
+{
232
+    AVFilterLink *outlink = NULL;
233
+
234
+    if (inlink->dst->output_count)
235
+        outlink = inlink->dst->outputs[0];
236
+
237
+    if (outlink) {
238
+        outlink->out_buf = ff_default_get_audio_buffer(inlink, AV_PERM_WRITE,
239
+                                                       samplesref->audio->nb_samples);
240
+        outlink->out_buf->pts                = samplesref->pts;
241
+        outlink->out_buf->audio->sample_rate = samplesref->audio->sample_rate;
242
+        ff_filter_samples(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
243
+        avfilter_unref_buffer(outlink->out_buf);
244
+        outlink->out_buf = NULL;
245
+    }
246
+    avfilter_unref_buffer(samplesref);
247
+    inlink->cur_buf = NULL;
248
+}
249
+
250
+void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
251
+{
252
+    void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
253
+    AVFilterPad *dst = link->dstpad;
254
+    int64_t pts;
255
+
256
+    FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);
257
+
258
+    if (!(filter_samples = dst->filter_samples))
259
+        filter_samples = ff_default_filter_samples;
260
+
261
+    /* prepare to copy the samples if the buffer has insufficient permissions */
262
+    if ((dst->min_perms & samplesref->perms) != dst->min_perms ||
263
+        dst->rej_perms & samplesref->perms) {
264
+        int  i, planar = av_sample_fmt_is_planar(samplesref->format);
265
+        int planes = !planar ? 1:
266
+                     av_get_channel_layout_nb_channels(samplesref->audio->channel_layout);
267
+
268
+        av_log(link->dst, AV_LOG_DEBUG,
269
+               "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n",
270
+               samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);
271
+
272
+        link->cur_buf = ff_default_get_audio_buffer(link, dst->min_perms,
273
+                                                    samplesref->audio->nb_samples);
274
+        link->cur_buf->pts                = samplesref->pts;
275
+        link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
276
+
277
+        /* Copy actual data into new samples buffer */
278
+        for (i = 0; samplesref->data[i] && i < 8; i++)
279
+            memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]);
280
+        for (i = 0; i < planes; i++)
281
+            memcpy(link->cur_buf->extended_data[i], samplesref->extended_data[i], samplesref->linesize[0]);
282
+
283
+        avfilter_unref_buffer(samplesref);
284
+    } else
285
+        link->cur_buf = samplesref;
286
+
287
+    pts = link->cur_buf->pts;
288
+    filter_samples(link, link->cur_buf);
289
+    ff_update_link_current_pts(link, pts);
290
+}
0 291
new file mode 100644
... ...
@@ -0,0 +1,65 @@
0
+/*
1
+ * Copyright (c) Stefano Sabatini | stefasab at gmail.com
2
+ * Copyright (c) S.N. Hemanth Meenakshisundaram | smeenaks at ucsd.edu
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#ifndef AVFILTER_AUDIO_H
22
+#define AVFILTER_AUDIO_H
23
+
24
+#include "avfilter.h"
25
+
26
+
27
+/** default handler for get_audio_buffer() for audio inputs */
28
+AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms,
29
+                                                     int nb_samples);
30
+
31
+/** get_audio_buffer() handler for filters which simply pass audio along */
32
+AVFilterBufferRef *ff_null_get_audio_buffer(AVFilterLink *link, int perms,
33
+                                                  int nb_samples);
34
+
35
+/**
36
+ * Request an audio samples buffer with a specific set of permissions.
37
+ *
38
+ * @param link           the output link to the filter from which the buffer will
39
+ *                       be requested
40
+ * @param perms          the required access permissions
41
+ * @param nb_samples     the number of samples per channel
42
+ * @return               A reference to the samples. This must be unreferenced with
43
+ *                       avfilter_unref_buffer when you are finished with it.
44
+ */
45
+AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms,
46
+                                             int nb_samples);
47
+
48
+/** default handler for filter_samples() for audio inputs */
49
+void ff_default_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
50
+
51
+/** filter_samples() handler for filters which simply pass audio along */
52
+void ff_null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
53
+
54
+/**
55
+ * Send a buffer of audio samples to the next filter.
56
+ *
57
+ * @param link       the output link over which the audio samples are being sent
58
+ * @param samplesref a reference to the buffer of audio samples being sent. The
59
+ *                   receiving filter will free this reference when it no longer
60
+ *                   needs it or pass it on to the next filter.
61
+ */
62
+void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
63
+
64
+#endif /* AVFILTER_AUDIO_H */
... ...
@@ -27,6 +27,7 @@
27 27
 #include "libavutil/imgutils.h"
28 28
 #include "libavutil/avassert.h"
29 29
 #include "libavutil/avstring.h"
30
+
30 31
 #include "avfilter.h"
31 32
 #include "internal.h"
32 33
 
... ...
@@ -410,7 +411,7 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end)
410 410
     av_dlog(ctx, "]%s", end ? "\n" : "");
411 411
 }
412 412
 
413
-static void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
413
+void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
414 414
 {
415 415
     if (link->type == AVMEDIA_TYPE_VIDEO) {
416 416
         av_dlog(ctx,
... ...
@@ -434,8 +435,6 @@ static void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
434 434
     }
435 435
 }
436 436
 
437
-#define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
438
-
439 437
 AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
440 438
 {
441 439
     AVFilterBufferRef *ret = NULL;
... ...
@@ -501,133 +500,6 @@ fail:
501 501
     return NULL;
502 502
 }
503 503
 
504
-AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link,
505
-                                             int perms, int nb_samples)
506
-{
507
-    AVFilterBufferRef *ret = NULL;
508
-
509
-    if (link->dstpad->get_audio_buffer)
510
-        ret = link->dstpad->get_audio_buffer(link, perms, nb_samples);
511
-
512
-    if (!ret)
513
-        ret = avfilter_default_get_audio_buffer(link, perms, nb_samples);
514
-
515
-    if (ret)
516
-        ret->type = AVMEDIA_TYPE_AUDIO;
517
-
518
-    return ret;
519
-}
520
-
521
-AVFilterBufferRef *
522
-avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
523
-                                          int nb_samples, enum AVSampleFormat sample_fmt,
524
-                                          uint64_t channel_layout, int planar)
525
-{
526
-    AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
527
-    AVFilterBufferRef *samplesref = av_mallocz(sizeof(AVFilterBufferRef));
528
-
529
-    if (!samples || !samplesref)
530
-        goto fail;
531
-
532
-    samplesref->buf = samples;
533
-    samplesref->buf->free = ff_avfilter_default_free_buffer;
534
-    if (!(samplesref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps))))
535
-        goto fail;
536
-
537
-    samplesref->audio->nb_samples     = nb_samples;
538
-    samplesref->audio->channel_layout = channel_layout;
539
-    samplesref->audio->planar         = planar;
540
-
541
-    /* make sure the buffer gets read permission or it's useless for output */
542
-    samplesref->perms = perms | AV_PERM_READ;
543
-
544
-    samples->refcount = 1;
545
-    samplesref->type = AVMEDIA_TYPE_AUDIO;
546
-    samplesref->format = sample_fmt;
547
-
548
-    memcpy(samples->data,        data,     sizeof(samples->data));
549
-    memcpy(samples->linesize,    linesize, sizeof(samples->linesize));
550
-    memcpy(samplesref->data,     data,     sizeof(samplesref->data));
551
-    memcpy(samplesref->linesize, linesize, sizeof(samplesref->linesize));
552
-
553
-    return samplesref;
554
-
555
-fail:
556
-    if (samplesref && samplesref->audio)
557
-        av_freep(&samplesref->audio);
558
-    av_freep(&samplesref);
559
-    av_freep(&samples);
560
-    return NULL;
561
-}
562
-
563
-AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays_alt(uint8_t **data,
564
-                                                             int linesize, int perms,
565
-                                                             int nb_samples,
566
-                                                             enum AVSampleFormat sample_fmt,
567
-                                                             uint64_t channel_layout)
568
-{
569
-    int planes;
570
-    AVFilterBuffer    *samples    = av_mallocz(sizeof(*samples));
571
-    AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref));
572
-
573
-    if (!samples || !samplesref)
574
-        goto fail;
575
-
576
-    samplesref->buf         = samples;
577
-    samplesref->buf->free   = ff_avfilter_default_free_buffer;
578
-    if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio))))
579
-        goto fail;
580
-
581
-    samplesref->audio->nb_samples     = nb_samples;
582
-    samplesref->audio->channel_layout = channel_layout;
583
-    samplesref->audio->planar         = av_sample_fmt_is_planar(sample_fmt);
584
-
585
-    planes = samplesref->audio->planar ? av_get_channel_layout_nb_channels(channel_layout) : 1;
586
-
587
-    /* make sure the buffer gets read permission or it's useless for output */
588
-    samplesref->perms = perms | AV_PERM_READ;
589
-
590
-    samples->refcount  = 1;
591
-    samplesref->type   = AVMEDIA_TYPE_AUDIO;
592
-    samplesref->format = sample_fmt;
593
-
594
-    memcpy(samples->data, data,
595
-           FFMIN(FF_ARRAY_ELEMS(samples->data), planes)*sizeof(samples->data[0]));
596
-    memcpy(samplesref->data, samples->data, sizeof(samples->data));
597
-
598
-    samples->linesize[0] = samplesref->linesize[0] = linesize;
599
-
600
-    if (planes > FF_ARRAY_ELEMS(samples->data)) {
601
-        samples->   extended_data = av_mallocz(sizeof(*samples->extended_data) *
602
-                                               planes);
603
-        samplesref->extended_data = av_mallocz(sizeof(*samplesref->extended_data) *
604
-                                               planes);
605
-
606
-        if (!samples->extended_data || !samplesref->extended_data)
607
-            goto fail;
608
-
609
-        memcpy(samples->   extended_data, data, sizeof(*data)*planes);
610
-        memcpy(samplesref->extended_data, data, sizeof(*data)*planes);
611
-    } else {
612
-        samples->extended_data    = samples->data;
613
-        samplesref->extended_data = samplesref->data;
614
-    }
615
-
616
-    return samplesref;
617
-
618
-fail:
619
-    if (samples && samples->extended_data != samples->data)
620
-        av_freep(&samples->extended_data);
621
-    if (samplesref) {
622
-        av_freep(&samplesref->audio);
623
-        if (samplesref->extended_data != samplesref->data)
624
-            av_freep(&samplesref->extended_data);
625
-    }
626
-    av_freep(&samplesref);
627
-    av_freep(&samples);
628
-    return NULL;
629
-}
630
-
631 504
 int avfilter_request_frame(AVFilterLink *link)
632 505
 {
633 506
     FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1);
... ...
@@ -657,7 +529,7 @@ int avfilter_poll_frame(AVFilterLink *link)
657 657
     return min;
658 658
 }
659 659
 
660
-static void update_link_current_pts(AVFilterLink *link, int64_t pts)
660
+void ff_update_link_current_pts(AVFilterLink *link, int64_t pts)
661 661
 {
662 662
     if (pts == AV_NOPTS_VALUE)
663 663
         return;
... ...
@@ -706,7 +578,7 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
706 706
     }
707 707
 
708 708
     start_frame(link, link->cur_buf);
709
-    update_link_current_pts(link, link->cur_buf->pts);
709
+    ff_update_link_current_pts(link, link->cur_buf->pts);
710 710
 }
711 711
 
712 712
 void avfilter_end_frame(AVFilterLink *link)
... ...
@@ -778,44 +650,6 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha
778 778
     return AVERROR(ENOSYS);
779 779
 }
780 780
 
781
-void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
782
-{
783
-    void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
784
-    AVFilterPad *dst = link->dstpad;
785
-    int i;
786
-    int64_t pts;
787
-
788
-    FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);
789
-
790
-    if (!(filter_samples = dst->filter_samples))
791
-        filter_samples = avfilter_default_filter_samples;
792
-
793
-    /* prepare to copy the samples if the buffer has insufficient permissions */
794
-    if ((dst->min_perms & samplesref->perms) != dst->min_perms ||
795
-        dst->rej_perms & samplesref->perms) {
796
-
797
-        av_log(link->dst, AV_LOG_DEBUG,
798
-               "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n",
799
-               samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);
800
-
801
-        link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,
802
-                                                          samplesref->audio->nb_samples);
803
-        link->cur_buf->pts                = samplesref->pts;
804
-        link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
805
-
806
-        /* Copy actual data into new samples buffer */
807
-        for (i = 0; samplesref->data[i] && i < 8; i++)
808
-            memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]);
809
-
810
-        avfilter_unref_buffer(samplesref);
811
-    } else
812
-        link->cur_buf = samplesref;
813
-
814
-    pts = link->cur_buf->pts;
815
-    filter_samples(link, link->cur_buf);
816
-    update_link_current_pts(link, pts);
817
-}
818
-
819 781
 #define MAX_REGISTERED_AVFILTERS_NB 128
820 782
 
821 783
 static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
... ...
@@ -430,7 +430,8 @@ struct AVFilterPad {
430 430
      *
431 431
      * Input audio pads only.
432 432
      */
433
-    AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, int nb_samples);
433
+    AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
434
+                                           int nb_samples);
434 435
 
435 436
     /**
436 437
      * Callback called after the slices of a frame are completely sent. If
... ...
@@ -508,16 +509,10 @@ void avfilter_default_draw_slice(AVFilterLink *link, int y, int h, int slice_dir
508 508
 /** default handler for end_frame() for video inputs */
509 509
 void avfilter_default_end_frame(AVFilterLink *link);
510 510
 
511
-/** default handler for filter_samples() for audio inputs */
512
-void avfilter_default_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
513
-
514 511
 /** default handler for get_video_buffer() for video inputs */
515 512
 AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
516 513
                                                      int perms, int w, int h);
517 514
 
518
-/** default handler for get_audio_buffer() for audio inputs */
519
-AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link,
520
-                                                     int perms, int nb_samples);
521 515
 
522 516
 /**
523 517
  * Helpers for query_formats() which set all links to the same list of
... ...
@@ -541,17 +536,10 @@ void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
541 541
 /** end_frame() handler for filters which simply pass video along */
542 542
 void avfilter_null_end_frame(AVFilterLink *link);
543 543
 
544
-/** filter_samples() handler for filters which simply pass audio along */
545
-void avfilter_null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
546
-
547 544
 /** get_video_buffer() handler for filters which simply pass video along */
548 545
 AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
549 546
                                                   int perms, int w, int h);
550 547
 
551
-/** get_audio_buffer() handler for filters which simply pass audio along */
552
-AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link,
553
-                                                  int perms, int nb_samples);
554
-
555 548
 /**
556 549
  * Filter definition. This defines the pads a filter contains, and all the
557 550
  * callback functions used to interact with the filter.
... ...
@@ -665,7 +653,7 @@ struct AVFilterLink {
665 665
     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
666 666
     /* These parameters apply only to audio */
667 667
     uint64_t channel_layout;    ///< channel layout of current buffer (see libavutil/audioconvert.h)
668
-#if LIBAVFILTER_VERSION_MAJOR < 3
668
+#if FF_API_SAMPLERATE64
669 669
     int64_t sample_rate;        ///< samples per second
670 670
 #else
671 671
     int sample_rate;            ///< samples per second
... ...
@@ -791,19 +779,6 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int lin
791 791
                                           int w, int h, enum PixelFormat format);
792 792
 
793 793
 /**
794
- * Request an audio samples buffer with a specific set of permissions.
795
- *
796
- * @param link           the output link to the filter from which the buffer will
797
- *                       be requested
798
- * @param perms          the required access permissions
799
- * @param nb_samples     the number of samples per channel
800
- * @return               A reference to the samples. This must be unreferenced with
801
- *                       avfilter_unref_buffer when you are finished with it.
802
- */
803
-AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
804
-                                             int nb_samples);
805
-
806
-/**
807 794
  * Create an audio buffer reference wrapped around an already
808 795
  * allocated samples buffer.
809 796
  *
... ...
@@ -904,17 +879,7 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
904 904
  */
905 905
 int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
906 906
 
907
-/**
908
- * Send a buffer of audio samples to the next filter.
909
- *
910
- * @param link       the output link over which the audio samples are being sent
911
- * @param samplesref a reference to the buffer of audio samples being sent. The
912
- *                   receiving filter will free this reference when it no longer
913
- *                   needs it or pass it on to the next filter.
914
- */
915
-void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
916
-
917
-/** Initialize the filter system. Register all built-in filters. */
907
+/** Initialize the filter system. Register all builtin filters. */
918 908
 void avfilter_register_all(void);
919 909
 
920 910
 /** Uninitialize the filter system. Unregister all filters. */
... ...
@@ -1024,4 +989,6 @@ static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
1024 1024
                         &f->output_pads, &f->outputs, p);
1025 1025
 }
1026 1026
 
1027
+#include "audio.h"
1028
+
1027 1029
 #endif /* AVFILTER_AVFILTER_H */
... ...
@@ -23,6 +23,7 @@
23 23
 #include "libavutil/audioconvert.h"
24 24
 #include "libavutil/imgutils.h"
25 25
 #include "libavutil/samplefmt.h"
26
+
26 27
 #include "avfilter.h"
27 28
 #include "internal.h"
28 29
 
... ...
@@ -87,38 +88,6 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
87 87
     return picref;
88 88
 }
89 89
 
90
-AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,
91
-                                                     int nb_samples)
92
-{
93
-    AVFilterBufferRef *samplesref = NULL;
94
-    int linesize[8] = {0};
95
-    uint8_t *data[8] = {0};
96
-    int ch, nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
97
-
98
-    /* right now we don't support more than 8 channels */
99
-    av_assert0(nb_channels <= 8);
100
-
101
-    /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
102
-    if (av_samples_alloc(data, linesize,
103
-                         nb_channels, nb_samples,
104
-                         av_get_alt_sample_fmt(link->format, link->planar),
105
-                         16) < 0)
106
-        return NULL;
107
-
108
-    for (ch = 1; link->planar && ch < nb_channels; ch++)
109
-        linesize[ch] = linesize[0];
110
-    samplesref =
111
-        avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms,
112
-                                                  nb_samples, link->format,
113
-                                                  link->channel_layout, link->planar);
114
-    if (!samplesref) {
115
-        av_free(data[0]);
116
-        return NULL;
117
-    }
118
-
119
-    return samplesref;
120
-}
121
-
122 90
 void avfilter_default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
123 91
 {
124 92
     AVFilterLink *outlink = NULL;
... ...
@@ -163,27 +132,6 @@ void avfilter_default_end_frame(AVFilterLink *inlink)
163 163
     }
164 164
 }
165 165
 
166
-/* FIXME: samplesref is same as link->cur_buf. Need to consider removing the redundant parameter. */
167
-void avfilter_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
168
-{
169
-    AVFilterLink *outlink = NULL;
170
-
171
-    if (inlink->dst->output_count)
172
-        outlink = inlink->dst->outputs[0];
173
-
174
-    if (outlink) {
175
-        outlink->out_buf = avfilter_default_get_audio_buffer(inlink, AV_PERM_WRITE,
176
-                                                             samplesref->audio->nb_samples);
177
-        outlink->out_buf->pts                = samplesref->pts;
178
-        outlink->out_buf->audio->sample_rate = samplesref->audio->sample_rate;
179
-        avfilter_filter_samples(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
180
-        avfilter_unref_buffer(outlink->out_buf);
181
-        outlink->out_buf = NULL;
182
-    }
183
-    avfilter_unref_buffer(samplesref);
184
-    inlink->cur_buf = NULL;
185
-}
186
-
187 166
 static void set_common_formats(AVFilterContext *ctx, AVFilterFormats *fmts,
188 167
                                enum AVMediaType type, int offin, int offout)
189 168
 {
... ...
@@ -258,18 +206,7 @@ void avfilter_null_end_frame(AVFilterLink *link)
258 258
     avfilter_end_frame(link->dst->outputs[0]);
259 259
 }
260 260
 
261
-void avfilter_null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
262
-{
263
-    avfilter_filter_samples(link->dst->outputs[0], samplesref);
264
-}
265
-
266 261
 AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
267 262
 {
268 263
     return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
269 264
 }
270
-
271
-AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, int perms,
272
-                                                  int nb_samples)
273
-{
274
-    return avfilter_get_audio_buffer(link->dst->outputs[0], perms, nb_samples);
275
-}
... ...
@@ -149,4 +149,10 @@ static inline void ff_null_start_frame_keep_ref(AVFilterLink *inlink,
149 149
     avfilter_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0));
150 150
 }
151 151
 
152
+void ff_update_link_current_pts(AVFilterLink *link, int64_t pts);
153
+
154
+#define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
155
+
156
+void ff_dlog_link(void *ctx, AVFilterLink *link, int end);
157
+
152 158
 #endif /* AVFILTER_INTERNAL_H */
... ...
@@ -297,7 +297,7 @@ static AVFilterBufferRef *copy_buffer_ref(AVFilterContext *ctx,
297 297
         break;
298 298
 
299 299
     case AVMEDIA_TYPE_AUDIO:
300
-        buf = avfilter_get_audio_buffer(outlink, AV_PERM_WRITE,
300
+        buf = ff_get_audio_buffer(outlink, AV_PERM_WRITE,
301 301
                                         ref->audio->nb_samples);
302 302
         channels = av_get_channel_layout_nb_channels(ref->audio->channel_layout);
303 303
         data_size = av_samples_get_buffer_size(NULL, channels,
... ...
@@ -562,7 +562,7 @@ static int request_frame(AVFilterLink *link)
562 562
         avfilter_unref_buffer(buf);
563 563
         break;
564 564
     case AVMEDIA_TYPE_AUDIO:
565
-        avfilter_filter_samples(link, avfilter_ref_buffer(buf, ~0));
565
+        ff_filter_samples(link, avfilter_ref_buffer(buf, ~0));
566 566
         avfilter_unref_buffer(buf);
567 567
         break;
568 568
     default:
... ...
@@ -437,7 +437,7 @@ static int amovie_get_samples(AVFilterLink *outlink)
437 437
         if (data_size < 0)
438 438
             return data_size;
439 439
         movie->samplesref =
440
-            avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);
440
+            ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);
441 441
         memcpy(movie->samplesref->data[0], movie->frame->data[0], data_size);
442 442
         movie->samplesref->pts = movie->pkt.pts;
443 443
         movie->samplesref->pos = movie->pkt.pos;
... ...
@@ -463,7 +463,7 @@ static int amovie_request_frame(AVFilterLink *outlink)
463 463
             return ret;
464 464
     } while (!movie->samplesref);
465 465
 
466
-    avfilter_filter_samples(outlink, avfilter_ref_buffer(movie->samplesref, ~0));
466
+    ff_filter_samples(outlink, avfilter_ref_buffer(movie->samplesref, ~0));
467 467
     avfilter_unref_buffer(movie->samplesref);
468 468
     movie->samplesref = NULL;
469 469
 
... ...
@@ -47,5 +47,8 @@
47 47
 #ifndef FF_API_GRAPH_AVCLASS
48 48
 #define FF_API_GRAPH_AVCLASS            (LIBAVFILTER_VERSION_MAJOR > 2)
49 49
 #endif
50
+#ifndef FF_API_SAMPLERATE64
51
+#define FF_API_SAMPLERATE64             (LIBAVFILTER_VERSION_MAJOR < 3)
52
+#endif
50 53
 
51 54
 #endif // AVFILTER_VERSION_H
... ...
@@ -1051,7 +1051,7 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
1051 1051
         return AVERROR_INVALIDDATA;
1052 1052
 
1053 1053
     if (atom.size >= 10) {
1054
-        // Broken files created by legacy versions of Libav and FFmpeg will
1054
+        // Broken files created by legacy versions of libavformat will
1055 1055
         // wrap a whole fiel atom inside of a glbl atom.
1056 1056
         unsigned size = avio_rb32(pb);
1057 1057
         unsigned type = avio_rl32(pb);
... ...
@@ -44,6 +44,8 @@
44 44
 
45 45
 #define APP_MAX_LENGTH 128
46 46
 #define PLAYPATH_MAX_LENGTH 256
47
+#define TCURL_MAX_LENGTH 512
48
+#define FLASHVER_MAX_LENGTH 64
47 49
 
48 50
 /** RTMP protocol handler state */
49 51
 typedef enum {
... ...
@@ -82,6 +84,9 @@ typedef struct RTMPContext {
82 82
     int           flv_header_bytes;           ///< number of initialized bytes in flv_header
83 83
     int           nb_invokes;                 ///< keeps track of invoke messages
84 84
     int           create_stream_invoke;       ///< invoke id for the create stream command
85
+    char*         tcurl;                      ///< url of the target stream
86
+    char*         flashver;                   ///< version of the flash plugin
87
+    char*         swfurl;                     ///< url of the swf player
85 88
 } RTMPContext;
86 89
 
87 90
 #define PLAYER_KEY_OPEN_PART_LEN 30   ///< length of partial key used for first client digest signing
... ...
@@ -110,35 +115,34 @@ static const uint8_t rtmp_server_key[] = {
110 110
 /**
111 111
  * Generate 'connect' call and send it to the server.
112 112
  */
113
-static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto,
114
-                        const char *host, int port)
113
+static void gen_connect(URLContext *s, RTMPContext *rt)
115 114
 {
116 115
     RTMPPacket pkt;
117
-    uint8_t ver[64], *p;
118
-    char tcurl[512];
116
+    uint8_t *p;
119 117
 
120 118
     ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 4096);
121 119
     p = pkt.data;
122 120
 
123
-    ff_url_join(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app);
124 121
     ff_amf_write_string(&p, "connect");
125 122
     ff_amf_write_number(&p, ++rt->nb_invokes);
126 123
     ff_amf_write_object_start(&p);
127 124
     ff_amf_write_field_name(&p, "app");
128 125
     ff_amf_write_string(&p, rt->app);
129 126
 
130
-    if (rt->is_input) {
131
-        snprintf(ver, sizeof(ver), "%s %d,%d,%d,%d", RTMP_CLIENT_PLATFORM, RTMP_CLIENT_VER1,
132
-                 RTMP_CLIENT_VER2, RTMP_CLIENT_VER3, RTMP_CLIENT_VER4);
133
-    } else {
134
-        snprintf(ver, sizeof(ver), "FMLE/3.0 (compatible; %s)", LIBAVFORMAT_IDENT);
127
+    if (!rt->is_input) {
135 128
         ff_amf_write_field_name(&p, "type");
136 129
         ff_amf_write_string(&p, "nonprivate");
137 130
     }
138 131
     ff_amf_write_field_name(&p, "flashVer");
139
-    ff_amf_write_string(&p, ver);
132
+    ff_amf_write_string(&p, rt->flashver);
133
+
134
+    if (rt->swfurl) {
135
+        ff_amf_write_field_name(&p, "swfUrl");
136
+        ff_amf_write_string(&p, rt->swfurl);
137
+    }
138
+
140 139
     ff_amf_write_field_name(&p, "tcUrl");
141
-    ff_amf_write_string(&p, tcurl);
140
+    ff_amf_write_string(&p, rt->tcurl);
142 141
     if (rt->is_input) {
143 142
         ff_amf_write_field_name(&p, "fpad");
144 143
         ff_amf_write_bool(&p, 0);
... ...
@@ -369,6 +373,25 @@ static void gen_server_bw(URLContext *s, RTMPContext *rt)
369 369
 }
370 370
 
371 371
 /**
372
+ * Generate check bandwidth message and send it to the server.
373
+ */
374
+static void gen_check_bw(URLContext *s, RTMPContext *rt)
375
+{
376
+    RTMPPacket pkt;
377
+    uint8_t *p;
378
+
379
+    ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 21);
380
+
381
+    p = pkt.data;
382
+    ff_amf_write_string(&p, "_checkbw");
383
+    ff_amf_write_number(&p, ++rt->nb_invokes);
384
+    ff_amf_write_null(&p);
385
+
386
+    ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
387
+    ff_rtmp_packet_destroy(&pkt);
388
+}
389
+
390
+/**
372 391
  * Generate report on bytes read so far and send it to the server.
373 392
  */
374 393
 static void gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts)
... ...
@@ -687,6 +710,8 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
687 687
             if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED;
688 688
             if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED;
689 689
             if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING;
690
+        } else if (!memcmp(pkt->data, "\002\000\010onBWDone", 11)) {
691
+            gen_check_bw(s, rt);
690 692
         }
691 693
         break;
692 694
     }
... ...
@@ -910,13 +935,31 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
910 910
         strncat(rt->playpath, fname, PLAYPATH_MAX_LENGTH - 5);
911 911
     }
912 912
 
913
+    if (!rt->tcurl) {
914
+        rt->tcurl = av_malloc(TCURL_MAX_LENGTH);
915
+        ff_url_join(rt->tcurl, TCURL_MAX_LENGTH, proto, NULL, hostname,
916
+                    port, "/%s", rt->app);
917
+    }
918
+
919
+    if (!rt->flashver) {
920
+        rt->flashver = av_malloc(FLASHVER_MAX_LENGTH);
921
+        if (rt->is_input) {
922
+            snprintf(rt->flashver, FLASHVER_MAX_LENGTH, "%s %d,%d,%d,%d",
923
+                    RTMP_CLIENT_PLATFORM, RTMP_CLIENT_VER1, RTMP_CLIENT_VER2,
924
+                    RTMP_CLIENT_VER3, RTMP_CLIENT_VER4);
925
+        } else {
926
+            snprintf(rt->flashver, FLASHVER_MAX_LENGTH,
927
+                    "FMLE/3.0 (compatible; %s)", LIBAVFORMAT_IDENT);
928
+        }
929
+    }
930
+
913 931
     rt->client_report_size = 1048576;
914 932
     rt->bytes_read = 0;
915 933
     rt->last_bytes_read = 0;
916 934
 
917 935
     av_log(s, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n",
918 936
            proto, path, rt->app, rt->playpath);
919
-    gen_connect(s, rt, proto, hostname, port);
937
+    gen_connect(s, rt);
920 938
 
921 939
     do {
922 940
         ret = get_packet(s, 1);
... ...
@@ -1052,11 +1095,14 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
1052 1052
 
1053 1053
 static const AVOption rtmp_options[] = {
1054 1054
     {"rtmp_app", "Name of application to connect to on the RTMP server", OFFSET(app), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
1055
+    {"rtmp_flashver", "Version of the Flash plugin used to run the SWF player.", OFFSET(flashver), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
1055 1056
     {"rtmp_live", "Specify that the media is a live stream.", OFFSET(live), AV_OPT_TYPE_INT, {-2}, INT_MIN, INT_MAX, DEC, "rtmp_live"},
1056 1057
     {"any", "both", 0, AV_OPT_TYPE_CONST, {-2}, 0, 0, DEC, "rtmp_live"},
1057 1058
     {"live", "live stream", 0, AV_OPT_TYPE_CONST, {-1}, 0, 0, DEC, "rtmp_live"},
1058 1059
     {"recorded", "recorded stream", 0, AV_OPT_TYPE_CONST, {0}, 0, 0, DEC, "rtmp_live"},
1059 1060
     {"rtmp_playpath", "Stream identifier to play or to publish", OFFSET(playpath), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
1061
+    {"rtmp_swfurl", "URL of the SWF player. By default no value will be sent", OFFSET(swfurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
1062
+    {"rtmp_tcurl", "URL of the target stream. Defaults to rtmp://host[:port]/app.", OFFSET(tcurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
1060 1063
     { NULL },
1061 1064
 };
1062 1065
 
... ...
@@ -227,7 +227,7 @@ static int sctp_open(URLContext *h, const char *uri, int flags)
227 227
     if (s->max_streams) {
228 228
         initparams.sinit_max_instreams = s->max_streams;
229 229
         initparams.sinit_num_ostreams  = s->max_streams;
230
-        if (setsockopt(fd, SOL_SCTP, SCTP_INITMSG, &initparams,
230
+        if (setsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &initparams,
231 231
                        sizeof(initparams)) < 0)
232 232
             av_log(h, AV_LOG_ERROR,
233 233
                    "SCTP ERROR: Unable to initialize socket max streams %d\n",
... ...
@@ -54,26 +54,24 @@ cglobal conv_fltp_to_flt_6ch, 2,8,7, dst, src, src1, src2, src3, src4, src5, len
54 54
     mova      m3, [srcq+src3q]
55 55
     mova      m4, [srcq+src4q]
56 56
     mova      m5, [srcq+src5q]
57
-%if cpuflag(sse)
57
+%if cpuflag(sse4)
58 58
     SBUTTERFLYPS 0, 1, 6
59 59
     SBUTTERFLYPS 2, 3, 6
60 60
     SBUTTERFLYPS 4, 5, 6
61 61
 
62
-    movaps    m6, m4
63
-    shufps    m4, m0, q3210
62
+    blendps   m6, m4, m0, 1100b
64 63
     movlhps   m0, m2
65
-    movhlps   m6, m2
66
-    movaps [dstq   ], m0
67
-    movaps [dstq+16], m4
68
-    movaps [dstq+32], m6
69
-
70
-    movaps    m6, m5
71
-    shufps    m5, m1, q3210
64
+    movhlps   m4, m2
65
+    blendps   m2, m5, m1, 1100b
72 66
     movlhps   m1, m3
73
-    movhlps   m6, m3
67
+    movhlps   m5, m3
68
+
69
+    movaps [dstq   ], m0
70
+    movaps [dstq+16], m6
71
+    movaps [dstq+32], m4
74 72
     movaps [dstq+48], m1
75
-    movaps [dstq+64], m5
76
-    movaps [dstq+80], m6
73
+    movaps [dstq+64], m2
74
+    movaps [dstq+80], m5
77 75
 %else ; mmx
78 76
     SBUTTERFLY dq, 0, 1, 6
79 77
     SBUTTERFLY dq, 2, 3, 6
... ...
@@ -100,5 +98,9 @@ cglobal conv_fltp_to_flt_6ch, 2,8,7, dst, src, src1, src2, src3, src4, src5, len
100 100
 
101 101
 INIT_MMX mmx
102 102
 CONV_FLTP_TO_FLT_6CH
103
-INIT_XMM sse
103
+INIT_XMM sse4
104
+CONV_FLTP_TO_FLT_6CH
105
+%if HAVE_AVX
106
+INIT_XMM avx
104 107
 CONV_FLTP_TO_FLT_6CH
108
+%endif
... ...
@@ -22,8 +22,9 @@
22 22
 #include "libavutil/cpu.h"
23 23
 #include "libavresample/audio_convert.h"
24 24
 
25
-extern void ff_conv_fltp_to_flt_6ch_mmx(float *dst, float *const *src, int len);
26
-extern void ff_conv_fltp_to_flt_6ch_sse(float *dst, float *const *src, int len);
25
+extern void ff_conv_fltp_to_flt_6ch_mmx (float *dst, float *const *src, int len);
26
+extern void ff_conv_fltp_to_flt_6ch_sse4(float *dst, float *const *src, int len);
27
+extern void ff_conv_fltp_to_flt_6ch_avx (float *dst, float *const *src, int len);
27 28
 
28 29
 av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
29 30
 {
... ...
@@ -34,9 +35,13 @@ av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
34 34
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
35 35
                                   6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx);
36 36
     }
37
-    if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
37
+    if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
38 38
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
39
-                                  6, 16, 4, "SSE", ff_conv_fltp_to_flt_6ch_sse);
39
+                                  6, 16, 4, "SSE4", ff_conv_fltp_to_flt_6ch_sse4);
40
+    }
41
+    if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
42
+        ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
43
+                                  6, 16, 4, "AVX", ff_conv_fltp_to_flt_6ch_avx);
40 44
     }
41 45
 #endif
42 46
 }
... ...
@@ -42,10 +42,9 @@
42 42
 %endmacro
43 43
 
44 44
 %macro SBUTTERFLYPS 3
45
-    movaps   m%3, m%1
46
-    unpcklps m%1, m%2
47
-    unpckhps m%3, m%2
48
-    SWAP %2, %3
45
+    unpcklps m%3, m%1, m%2
46
+    unpckhps m%1, m%1, m%2
47
+    SWAP %1, %3, %2
49 48
 %endmacro
50 49
 
51 50
 %macro TRANSPOSE4x4B 5