Browse code

Merge remote-tracking branch 'qatar/master' into master

* qatar/master: (27 commits)
ac3enc: fix LOCAL_ALIGNED usage in count_mantissa_bits()
ac3dsp: do not use the ff_* prefix when referencing ff_ac3_bap_bits.
ac3dsp: fix loop condition in ac3_update_bap_counts_c()
ARM: unbreak build
ac3enc: modify mantissa bit counting to keep bap counts for all values of bap instead of just 0 to 4.
ac3enc: split mantissa bit counting into a separate function.
ac3enc: store per-block/channel bap pointers by reference block in a 2D array rather than in the AC3Block struct.
get_bits: add av_unused tag to cache variable
sws: replace all long with int.
ARM: aacdec: fix constraints on inline asm
ARM: remove unnecessary volatile from inline asm
ARM: add "cc" clobbers to inline asm where needed
ARM: improve FASTDIV asm
ac3enc: use LOCAL_ALIGNED macro
APIchanges: fill in git hash for av_get_pix_fmt_name (0420bd7).
lavu: add av_get_pix_fmt_name() convenience function
cmdutils: remove OPT_FUNC2
swscale: fix crash in bilinear scaling.
vpxenc: add VP8E_SET_STATIC_THRESHOLD mapping
webm: support stereo videos in matroska/webm muxer
...

Conflicts:
Changelog
cmdutils.c
cmdutils.h
doc/APIchanges
doc/muxers.texi
ffmpeg.c
ffplay.c
libavcodec/ac3enc.c
libavcodec/ac3enc_float.c
libavcodec/avcodec.h
libavcodec/get_bits.h
libavcodec/libvpxenc.c
libavcodec/version.h
libavdevice/libdc1394.c
libavformat/matroskaenc.c
libavutil/avutil.h
libswscale/rgb2rgb.c
libswscale/swscale.c
libswscale/swscale_template.c
libswscale/x86/swscale_template.c

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

Michael Niedermayer authored on 2011/05/29 09:55:19
Showing 45 changed files
... ...
@@ -9,6 +9,7 @@ version <next>:
9 9
 - mpeg2 aspect ratio dection fixed
10 10
 - libxvid aspect pickiness fixed
11 11
 - Frame multithreaded decoding
12
+- E-AC-3 audio encoder
12 13
 - Lots of deprecated API cruft removed
13 14
 - fft and imdct optimizations for AVX (Sandy Bridge) processors
14 15
 - showinfo filter added
... ...
@@ -1268,6 +1268,7 @@ dca_decoder_select="mdct"
1268 1268
 dnxhd_encoder_select="aandct"
1269 1269
 dxa_decoder_select="zlib"
1270 1270
 eac3_decoder_select="ac3_decoder"
1271
+eac3_encoder_select="mdct ac3dsp"
1271 1272
 eamad_decoder_select="aandct"
1272 1273
 eatgq_decoder_select="aandct"
1273 1274
 eatqi_decoder_select="aandct"
... ...
@@ -30,6 +30,10 @@ API changes, most recent first:
30 30
 2011-05-XX - XXXXXX - lavfi 2.6.0 - avcodec.h
31 31
   Add avfilter_get_video_buffer_ref_from_frame() to libavfilter/avcodec.h.
32 32
 
33
+2011-05-28 - 0420bd7 - lavu 51.2.0 - pixdesc.h
34
+  Add av_get_pix_fmt_name() in libavutil/pixdesc.h, and deprecate
35
+  avcodec_get_pix_fmt_name() in libavcodec/avcodec.h in its favor.
36
+
33 37
 2011-05-25 - 30315a8 - lavf 53.1.0 - avformat.h
34 38
   Add fps_probe_size to AVFormatContext.
35 39
 
... ...
@@ -617,7 +617,7 @@ following image formats are supported:
617 617
     @tab Used in Origin's Wing Commander IV AVI files.
618 618
 @item DSP Group TrueSpeech   @tab     @tab  X
619 619
 @item DV audio               @tab     @tab  X
620
-@item Enhanced AC-3          @tab     @tab  X
620
+@item Enhanced AC-3          @tab  X  @tab  X
621 621
 @item FLAC (Free Lossless Audio Codec)  @tab  X  @tab  IX
622 622
 @item GSM                    @tab  E  @tab  X
623 623
     @tab encoding supported through external library libgsm
... ...
@@ -4395,10 +4395,10 @@ static const OptionDef options[] = {
4395 4395
     { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)&copy_initial_nonkeyframes}, "copy initial non-keyframes" },
4396 4396
 
4397 4397
     /* video options */
4398
-    { "b",  HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
4399
-    { "vb",  HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
4398
+    { "b", HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
4399
+    { "vb", HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
4400 4400
     { "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[AVMEDIA_TYPE_VIDEO]}, "set the number of video frames to record", "number" },
4401
-    { "r",  HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
4401
+    { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
4402 4402
     { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
4403 4403
     { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
4404 4404
     { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" },
... ...
@@ -127,6 +127,7 @@ OBJS-$(CONFIG_DVVIDEO_DECODER)         += dv.o dvdata.o
127 127
 OBJS-$(CONFIG_DVVIDEO_ENCODER)         += dv.o dvdata.o
128 128
 OBJS-$(CONFIG_DXA_DECODER)             += dxa.o
129 129
 OBJS-$(CONFIG_EAC3_DECODER)            += eac3dec.o eac3dec_data.o
130
+OBJS-$(CONFIG_EAC3_ENCODER)            += ac3enc_float.o ac3tab.o ac3.o kbdwin.o
130 131
 OBJS-$(CONFIG_EACMV_DECODER)           += eacmv.o
131 132
 OBJS-$(CONFIG_EAMAD_DECODER)           += eamad.o eaidct.o mpeg12.o \
132 133
                                           mpeg12data.o mpegvideo.o  \
... ...
@@ -128,24 +128,33 @@ static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd,
128 128
     } while (end > ff_ac3_band_start_tab[band++]);
129 129
 }
130 130
 
131
-static int ac3_compute_mantissa_size_c(int mant_cnt[5], uint8_t *bap,
132
-                                       int nb_coefs)
131
+static void ac3_update_bap_counts_c(uint16_t mant_cnt[16], uint8_t *bap,
132
+                                    int len)
133 133
 {
134
-    int bits, b, i;
134
+    while (len-- > 0)
135
+        mant_cnt[bap[len]]++;
136
+}
135 137
 
136
-    bits = 0;
137
-    for (i = 0; i < nb_coefs; i++) {
138
-        b = bap[i];
139
-        if (b <= 4) {
140
-            // bap=1 to bap=4 will be counted in compute_mantissa_size_final
141
-            mant_cnt[b]++;
142
-        } else if (b <= 13) {
143
-            // bap=5 to bap=13 use (bap-1) bits
144
-            bits += b - 1;
145
-        } else {
146
-            // bap=14 uses 14 bits and bap=15 uses 16 bits
147
-            bits += (b == 14) ? 14 : 16;
148
-        }
138
+DECLARE_ALIGNED(16, const uint16_t, ff_ac3_bap_bits)[16] = {
139
+    0,  0,  0,  3,  0,  4,  5,  6,  7,  8,  9, 10, 11, 12, 14, 16
140
+};
141
+
142
+static int ac3_compute_mantissa_size_c(uint16_t mant_cnt[6][16])
143
+{
144
+    int blk, bap;
145
+    int bits = 0;
146
+
147
+    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
148
+        // bap=1 : 3 mantissas in 5 bits
149
+        bits += (mant_cnt[blk][1] / 3) * 5;
150
+        // bap=2 : 3 mantissas in 7 bits
151
+        // bap=4 : 2 mantissas in 7 bits
152
+        bits += ((mant_cnt[blk][2] / 3) + (mant_cnt[blk][4] >> 1)) * 7;
153
+        // bap=3 : 1 mantissa in 3 bits
154
+        bits += mant_cnt[blk][3] * 3;
155
+        // bap=5 to 15 : get bits per mantissa from table
156
+        for (bap = 5; bap < 16; bap++)
157
+            bits += mant_cnt[blk][bap] * ff_ac3_bap_bits[bap];
149 158
     }
150 159
     return bits;
151 160
 }
... ...
@@ -181,6 +190,7 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
181 181
     c->ac3_rshift_int32 = ac3_rshift_int32_c;
182 182
     c->float_to_fixed24 = float_to_fixed24_c;
183 183
     c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c;
184
+    c->update_bap_counts = ac3_update_bap_counts_c;
184 185
     c->compute_mantissa_size = ac3_compute_mantissa_size_c;
185 186
     c->extract_exponents = ac3_extract_exponents_c;
186 187
 
... ...
@@ -24,6 +24,12 @@
24 24
 
25 25
 #include <stdint.h>
26 26
 
27
+/**
28
+ * Number of mantissa bits written for each bap value.
29
+ * bap values with fractional bits are set to 0 and are calculated separately.
30
+ */
31
+extern const uint16_t ff_ac3_bap_bits[16];
32
+
27 33
 typedef struct AC3DSPContext {
28 34
     /**
29 35
      * Set each encoded exponent in a block to the minimum of itself and the
... ...
@@ -102,9 +108,21 @@ typedef struct AC3DSPContext {
102 102
                                const uint8_t *bap_tab, uint8_t *bap);
103 103
 
104 104
     /**
105
+     * Update bap counts using the supplied array of bap.
106
+     *
107
+     * @param[out] mant_cnt   bap counts for 1 block
108
+     * @param[in]  bap        array of bap, pointing to start coef bin
109
+     * @param[in]  len        number of elements to process
110
+     */
111
+    void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len);
112
+
113
+    /**
105 114
      * Calculate the number of bits needed to encode a set of mantissas.
115
+     *
116
+     * @param[in] mant_cnt    bap counts for all blocks
117
+     * @return                mantissa bit count
106 118
      */
107
-    int (*compute_mantissa_size)(int mant_cnt[5], uint8_t *bap, int nb_coefs);
119
+    int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]);
108 120
 
109 121
     void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs);
110 122
 } AC3DSPContext;
... ...
@@ -75,7 +75,6 @@ typedef struct AC3MDCTContext {
75 75
  * Data for a single audio block.
76 76
  */
77 77
 typedef struct AC3Block {
78
-    uint8_t  **bap;                             ///< bit allocation pointers (bap)
79 78
     CoefType **mdct_coef;                       ///< MDCT coefficients
80 79
     int32_t  **fixed_coef;                      ///< fixed-point MDCT coefficients
81 80
     uint8_t  **exp;                             ///< original exponents
... ...
@@ -90,7 +89,6 @@ typedef struct AC3Block {
90 90
     uint8_t  new_rematrixing_strategy;          ///< send new rematrixing flags in this block
91 91
     int      num_rematrixing_bands;             ///< number of rematrixing bands
92 92
     uint8_t  rematrixing_flags[4];              ///< rematrixing flags
93
-    struct AC3Block *exp_ref_block[AC3_MAX_CHANNELS]; ///< reference blocks for EXP_REUSE
94 93
     int      new_cpl_strategy;                  ///< send new coupling strategy
95 94
     int      cpl_in_use;                        ///< coupling in use for this block     (cplinu)
96 95
     uint8_t  channel_in_cpl[AC3_MAX_CHANNELS];  ///< channel in coupling                (chincpl)
... ...
@@ -115,6 +113,7 @@ typedef struct AC3EncodeContext {
115 115
 
116 116
     AC3Block blocks[AC3_MAX_BLOCKS];        ///< per-block info
117 117
 
118
+    int eac3;                               ///< indicates if this is E-AC-3 vs. AC-3
118 119
     int bitstream_id;                       ///< bitstream id                           (bsid)
119 120
     int bitstream_mode;                     ///< bitstream mode                         (bsmod)
120 121
 
... ...
@@ -125,8 +124,8 @@ typedef struct AC3EncodeContext {
125 125
     int frame_size;                         ///< current frame size in bytes
126 126
     int frame_size_code;                    ///< frame size code                        (frmsizecod)
127 127
     uint16_t crc_inv[2];
128
-    int bits_written;                       ///< bit count    (used to avg. bitrate)
129
-    int samples_written;                    ///< sample count (used to avg. bitrate)
128
+    int64_t bits_written;                   ///< bit count    (used to avg. bitrate)
129
+    int64_t samples_written;                ///< sample count (used to avg. bitrate)
130 130
 
131 131
     int fbw_channels;                       ///< number of full-bandwidth channels      (nfchans)
132 132
     int channels;                           ///< total number of channels               (nchans)
... ...
@@ -186,6 +185,9 @@ typedef struct AC3EncodeContext {
186 186
     uint8_t *cpl_coord_mant_buffer;
187 187
 
188 188
     uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies
189
+    uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< reference blocks for EXP_REUSE
190
+    uint8_t *ref_bap     [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap)
191
+    int ref_bap_set;                                         ///< indicates if ref_bap pointers have been set
189 192
 
190 193
     DECLARE_ALIGNED(32, SampleType, windowed_samples)[AC3_WINDOW_SIZE];
191 194
 } AC3EncodeContext;
... ...
@@ -215,65 +217,25 @@ static const float extmixlev_options[EXTMIXLEV_NUM_OPTIONS] = {
215 215
 #define OFFSET(param) offsetof(AC3EncodeContext, options.param)
216 216
 #define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
217 217
 
218
-#if CONFIG_AC3ENC_FLOAT || !CONFIG_AC3_FLOAT_ENCODER //we need this exactly once compiled in
219
-const AVOption ff_ac3_options[] = {
220
-/* Metadata Options */
221
-{"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM},
222
-/* downmix levels */
223
-{"center_mixlev", "Center Mix Level", OFFSET(center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_4POINT5DB }, 0.0, 1.0, AC3ENC_PARAM},
224
-{"surround_mixlev", "Surround Mix Level", OFFSET(surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_6DB }, 0.0, 1.0, AC3ENC_PARAM},
225
-/* audio production information */
226
-{"mixing_level", "Mixing Level", OFFSET(mixing_level), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 111, AC3ENC_PARAM},
227
-{"room_type", "Room Type", OFFSET(room_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "room_type"},
228
-    {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
229
-    {"large",        "Large Room",              0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
230
-    {"small",        "Small Room",              0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
231
-/* other metadata options */
232
-{"copyright", "Copyright Bit", OFFSET(copyright), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM},
233
-{"dialnorm", "Dialogue Level (dB)", OFFSET(dialogue_level), FF_OPT_TYPE_INT, {.dbl = -31 }, -31, -1, AC3ENC_PARAM},
234
-{"dsur_mode", "Dolby Surround Mode", OFFSET(dolby_surround_mode), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 2, AC3ENC_PARAM, "dsur_mode"},
235
-    {"notindicated", "Not Indicated (default)",    0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
236
-    {"on",           "Dolby Surround Encoded",     0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
237
-    {"off",          "Not Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
238
-{"original", "Original Bit Stream", OFFSET(original), FF_OPT_TYPE_INT,   {.dbl = 1 }, 0, 1, AC3ENC_PARAM},
239
-/* extended bitstream information */
240
-{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dmix_mode"},
241
-    {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
242
-    {"ltrt", "Lt/Rt Downmix Preferred",         0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
243
-    {"loro", "Lo/Ro Downmix Preferred",         0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
244
-{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
245
-{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
246
-{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
247
-{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
248
-{"dsurex_mode", "Dolby Surround EX Mode", OFFSET(dolby_surround_ex_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dsurex_mode"},
249
-    {"notindicated", "Not Indicated (default)",       0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
250
-    {"on",           "Dolby Surround EX Encoded",     0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
251
-    {"off",          "Not Dolby Surround EX Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
252
-{"dheadphone_mode", "Dolby Headphone Mode", OFFSET(dolby_headphone_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dheadphone_mode"},
253
-    {"notindicated", "Not Indicated (default)",     0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
254
-    {"on",           "Dolby Headphone Encoded",     0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
255
-    {"off",          "Not Dolby Headphone Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
256
-{"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 1, AC3ENC_PARAM, "ad_conv_type"},
257
-    {"standard", "Standard (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
258
-    {"hdcd",     "HDCD",               0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
259
-/* Other Encoding Options */
260
-{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM},
261
-#if CONFIG_AC3ENC_FLOAT
262
-{"channel_coupling",   "Channel Coupling",   OFFSET(channel_coupling),   FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM, "channel_coupling"},
263
-    {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "channel_coupling"},
264
-{"cpl_start_band", "Coupling Start Band", OFFSET(cpl_start), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 15, AC3ENC_PARAM, "cpl_start_band"},
265
-    {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},
266
-#endif
267
-{NULL}
268
-};
269
-#endif
218
+#define AC3ENC_TYPE_AC3_FIXED   0
219
+#define AC3ENC_TYPE_AC3         1
220
+#define AC3ENC_TYPE_EAC3        2
270 221
 
271 222
 #if CONFIG_AC3ENC_FLOAT
223
+#define AC3ENC_TYPE AC3ENC_TYPE_AC3
224
+#include "ac3enc_opts_template.c"
272 225
 static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
273
-                                ff_ac3_options, LIBAVUTIL_VERSION_INT };
226
+                                ac3_options, LIBAVUTIL_VERSION_INT };
227
+#undef AC3ENC_TYPE
228
+#define AC3ENC_TYPE AC3ENC_TYPE_EAC3
229
+#include "ac3enc_opts_template.c"
230
+static AVClass eac3enc_class = { "E-AC-3 Encoder", av_default_item_name,
231
+                                 eac3_options, LIBAVUTIL_VERSION_INT };
274 232
 #else
233
+#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
234
+#include "ac3enc_opts_template.c"
275 235
 static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name,
276
-                                ff_ac3_options, LIBAVUTIL_VERSION_INT };
236
+                                ac3fixed_options, LIBAVUTIL_VERSION_INT };
277 237
 #endif
278 238
 
279 239
 
... ...
@@ -402,7 +364,7 @@ static const int8_t ac3_coupling_start_tab[6][3][19] = {
402 402
 
403 403
 /**
404 404
  * Adjust the frame size to make the average bit rate match the target bit rate.
405
- * This is only needed for 11025, 22050, and 44100 sample rates.
405
+ * This is only needed for 11025, 22050, and 44100 sample rates or any E-AC-3.
406 406
  */
407 407
 static void adjust_frame_size(AC3EncodeContext *s)
408 408
 {
... ...
@@ -555,12 +517,15 @@ static inline float calc_cpl_coord(float energy_ch, float energy_cpl)
555 555
 static void apply_channel_coupling(AC3EncodeContext *s)
556 556
 {
557 557
 #if CONFIG_AC3ENC_FLOAT
558
-    DECLARE_ALIGNED(16, float,   cpl_coords)      [AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}};
559
-    DECLARE_ALIGNED(16, int32_t, fixed_cpl_coords)[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}};
558
+    LOCAL_ALIGNED_16(float,   cpl_coords,       [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
559
+    LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
560 560
     int blk, ch, bnd, i, j;
561 561
     CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}};
562 562
     int num_cpl_coefs = s->num_cpl_subbands * 12;
563 563
 
564
+    memset(cpl_coords,       0, AC3_MAX_BLOCKS * sizeof(*cpl_coords));
565
+    memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*fixed_cpl_coords));
566
+
564 567
     /* calculate coupling channel from fbw channels */
565 568
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
566 569
         AC3Block *block = &s->blocks[blk];
... ...
@@ -749,6 +714,35 @@ static void apply_channel_coupling(AC3EncodeContext *s)
749 749
             }
750 750
         }
751 751
     }
752
+
753
+    if (s->eac3) {
754
+        /* set first cpl coords */
755
+        int first_cpl_coords[AC3_MAX_CHANNELS];
756
+        for (ch = 1; ch <= s->fbw_channels; ch++)
757
+            first_cpl_coords[ch] = 1;
758
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
759
+            AC3Block *block = &s->blocks[blk];
760
+            for (ch = 1; ch <= s->fbw_channels; ch++) {
761
+                if (block->channel_in_cpl[ch]) {
762
+                    if (first_cpl_coords[ch]) {
763
+                        block->new_cpl_coords = 2;
764
+                        first_cpl_coords[ch]  = 0;
765
+                    }
766
+                } else {
767
+                    first_cpl_coords[ch] = 1;
768
+                }
769
+            }
770
+        }
771
+
772
+        /* set first cpl leak */
773
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
774
+            AC3Block *block = &s->blocks[blk];
775
+            if (block->cpl_in_use) {
776
+                block->new_cpl_leak = 2;
777
+                break;
778
+            }
779
+        }
780
+    }
752 781
 #endif /* CONFIG_AC3ENC_FLOAT */
753 782
 }
754 783
 
... ...
@@ -1050,10 +1044,10 @@ static void encode_exponents(AC3EncodeContext *s)
1050 1050
             blk1 = blk + 1;
1051 1051
 
1052 1052
             /* count the number of EXP_REUSE blocks after the current block
1053
-               and set exponent reference block pointers */
1054
-            block->exp_ref_block[ch] = block;
1053
+               and set exponent reference block numbers */
1054
+            s->exp_ref_block[ch][blk] = blk;
1055 1055
             while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE) {
1056
-                s->blocks[blk1].exp_ref_block[ch] = block;
1056
+                s->exp_ref_block[ch][blk1] = blk;
1057 1057
                 blk1++;
1058 1058
             }
1059 1059
             num_reuse_blocks = blk1 - blk - 1;
... ...
@@ -1068,6 +1062,9 @@ static void encode_exponents(AC3EncodeContext *s)
1068 1068
             blk = blk1;
1069 1069
         }
1070 1070
     }
1071
+
1072
+    /* reference block numbers have been changed, so reset ref_bap_set */
1073
+    s->ref_bap_set = 0;
1071 1074
 }
1072 1075
 
1073 1076
 
... ...
@@ -1166,38 +1163,72 @@ static void count_frame_bits_fixed(AC3EncodeContext *s)
1166 1166
      *   no delta bit allocation
1167 1167
      *   no skipped data
1168 1168
      *   no auxilliary data
1169
+     *   no E-AC-3 metadata
1169 1170
      */
1170 1171
 
1171 1172
     /* header */
1172
-    frame_bits = 65;
1173
-    frame_bits += frame_bits_inc[s->channel_mode];
1173
+    frame_bits = 16; /* sync info */
1174
+    if (s->eac3) {
1175
+        /* bitstream info header */
1176
+        frame_bits += 35;
1177
+        frame_bits += 1 + 1 + 1;
1178
+        /* audio frame header */
1179
+        frame_bits += 2;
1180
+        frame_bits += 10;
1181
+        /* exponent strategy */
1182
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
1183
+            frame_bits += 2 * s->fbw_channels + s->lfe_on;
1184
+        /* converter exponent strategy */
1185
+        frame_bits += s->fbw_channels * 5;
1186
+        /* snr offsets */
1187
+        frame_bits += 10;
1188
+        /* block start info */
1189
+        frame_bits++;
1190
+    } else {
1191
+        frame_bits += 49;
1192
+        frame_bits += frame_bits_inc[s->channel_mode];
1193
+    }
1174 1194
 
1175 1195
     /* audio blocks */
1176 1196
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1177
-        /* block switch flags */
1178
-        frame_bits += s->fbw_channels;
1197
+        if (!s->eac3) {
1198
+            /* block switch flags */
1199
+            frame_bits += s->fbw_channels;
1179 1200
 
1180
-        /* dither flags */
1181
-        frame_bits += s->fbw_channels;
1201
+            /* dither flags */
1202
+            frame_bits += s->fbw_channels;
1203
+        }
1182 1204
 
1183 1205
         /* dynamic range */
1184 1206
         frame_bits++;
1185 1207
 
1186
-        /* exponent strategy */
1187
-        frame_bits += 2 * s->fbw_channels;
1188
-        if (s->lfe_on)
1208
+        /* spectral extension */
1209
+        if (s->eac3)
1189 1210
             frame_bits++;
1190 1211
 
1191
-        /* bit allocation params */
1192
-        frame_bits++;
1193
-        if (!blk)
1194
-            frame_bits += 2 + 2 + 2 + 2 + 3;
1212
+        if (!s->eac3) {
1213
+            /* exponent strategy */
1214
+            frame_bits += 2 * s->fbw_channels;
1215
+            if (s->lfe_on)
1216
+                frame_bits++;
1195 1217
 
1196
-        /* delta bit allocation */
1197
-        frame_bits++;
1218
+            /* bit allocation params */
1219
+            frame_bits++;
1220
+            if (!blk)
1221
+                frame_bits += 2 + 2 + 2 + 2 + 3;
1222
+        }
1198 1223
 
1199
-        /* skipped data */
1200
-        frame_bits++;
1224
+        /* converter snr offset */
1225
+        if (s->eac3)
1226
+            frame_bits++;
1227
+
1228
+        if (!s->eac3) {
1229
+            /* delta bit allocation */
1230
+            frame_bits++;
1231
+
1232
+            /* skipped data */
1233
+            frame_bits++;
1234
+        }
1201 1235
     }
1202 1236
 
1203 1237
     /* auxiliary data */
... ...
@@ -1222,7 +1253,7 @@ static void bit_alloc_init(AC3EncodeContext *s)
1222 1222
     s->slow_decay_code = 2;
1223 1223
     s->fast_decay_code = 1;
1224 1224
     s->slow_gain_code  = 1;
1225
-    s->db_per_bit_code = 3;
1225
+    s->db_per_bit_code = s->eac3 ? 2 : 3;
1226 1226
     s->floor_code      = 7;
1227 1227
     for (ch = 0; ch <= s->channels; ch++)
1228 1228
         s->fast_gain_code[ch] = 4;
... ...
@@ -1257,13 +1288,29 @@ static void count_frame_bits(AC3EncodeContext *s)
1257 1257
     int frame_bits = 0;
1258 1258
 
1259 1259
     /* header */
1260
-    if (opt->audio_production_info)
1261
-        frame_bits += 7;
1262
-    if (s->bitstream_id == 6) {
1263
-        if (opt->extended_bsi_1)
1264
-            frame_bits += 14;
1265
-        if (opt->extended_bsi_2)
1266
-            frame_bits += 14;
1260
+    if (s->eac3) {
1261
+        /* coupling */
1262
+        if (s->channel_mode > AC3_CHMODE_MONO) {
1263
+            frame_bits++;
1264
+            for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
1265
+                AC3Block *block = &s->blocks[blk];
1266
+                frame_bits++;
1267
+                if (block->new_cpl_strategy)
1268
+                    frame_bits++;
1269
+            }
1270
+        }
1271
+        /* coupling exponent strategy */
1272
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
1273
+            frame_bits += 2 * s->blocks[blk].cpl_in_use;
1274
+    } else {
1275
+        if (opt->audio_production_info)
1276
+            frame_bits += 7;
1277
+        if (s->bitstream_id == 6) {
1278
+            if (opt->extended_bsi_1)
1279
+                frame_bits += 14;
1280
+            if (opt->extended_bsi_2)
1281
+                frame_bits += 14;
1282
+        }
1267 1283
     }
1268 1284
 
1269 1285
     /* audio blocks */
... ...
@@ -1271,15 +1318,23 @@ static void count_frame_bits(AC3EncodeContext *s)
1271 1271
         AC3Block *block = &s->blocks[blk];
1272 1272
 
1273 1273
         /* coupling strategy */
1274
-        frame_bits++;
1275
-        if (block->new_cpl_strategy) {
1274
+        if (!s->eac3)
1276 1275
             frame_bits++;
1276
+        if (block->new_cpl_strategy) {
1277
+            if (!s->eac3)
1278
+                frame_bits++;
1277 1279
             if (block->cpl_in_use) {
1278
-                frame_bits += s->fbw_channels;
1280
+                if (s->eac3)
1281
+                    frame_bits++;
1282
+                if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO)
1283
+                    frame_bits += s->fbw_channels;
1279 1284
                 if (s->channel_mode == AC3_CHMODE_STEREO)
1280 1285
                     frame_bits++;
1281 1286
                 frame_bits += 4 + 4;
1282
-                frame_bits += s->num_cpl_subbands - 1;
1287
+                if (s->eac3)
1288
+                    frame_bits++;
1289
+                else
1290
+                    frame_bits += s->num_cpl_subbands - 1;
1283 1291
             }
1284 1292
         }
1285 1293
 
... ...
@@ -1287,7 +1342,8 @@ static void count_frame_bits(AC3EncodeContext *s)
1287 1287
         if (block->cpl_in_use) {
1288 1288
             for (ch = 1; ch <= s->fbw_channels; ch++) {
1289 1289
                 if (block->channel_in_cpl[ch]) {
1290
-                    frame_bits++;
1290
+                    if (!s->eac3 || block->new_cpl_coords != 2)
1291
+                        frame_bits++;
1291 1292
                     if (block->new_cpl_coords) {
1292 1293
                         frame_bits += 2;
1293 1294
                         frame_bits += (4 + 4) * s->num_cpl_bands;
... ...
@@ -1298,7 +1354,8 @@ static void count_frame_bits(AC3EncodeContext *s)
1298 1298
 
1299 1299
         /* stereo rematrixing */
1300 1300
         if (s->channel_mode == AC3_CHMODE_STEREO) {
1301
-            frame_bits++;
1301
+            if (!s->eac3 || blk > 0)
1302
+                frame_bits++;
1302 1303
             if (s->blocks[blk].new_rematrixing_strategy)
1303 1304
                 frame_bits += block->num_rematrixing_bands;
1304 1305
         }
... ...
@@ -1313,17 +1370,20 @@ static void count_frame_bits(AC3EncodeContext *s)
1313 1313
         }
1314 1314
 
1315 1315
         /* coupling exponent strategy */
1316
-        if (block->cpl_in_use)
1316
+        if (!s->eac3 && block->cpl_in_use)
1317 1317
             frame_bits += 2;
1318 1318
 
1319 1319
         /* snr offsets and fast gain codes */
1320
-        frame_bits++;
1321
-        if (block->new_snr_offsets)
1322
-            frame_bits += 6 + (s->channels + block->cpl_in_use) * (4 + 3);
1320
+        if (!s->eac3) {
1321
+            frame_bits++;
1322
+            if (block->new_snr_offsets)
1323
+                frame_bits += 6 + (s->channels + block->cpl_in_use) * (4 + 3);
1324
+        }
1323 1325
 
1324 1326
         /* coupling leak info */
1325 1327
         if (block->cpl_in_use) {
1326
-            frame_bits++;
1328
+            if (!s->eac3 || block->new_cpl_leak != 2)
1329
+                frame_bits++;
1327 1330
             if (block->new_cpl_leak)
1328 1331
                 frame_bits += 3 + 3;
1329 1332
         }
... ...
@@ -1334,22 +1394,6 @@ static void count_frame_bits(AC3EncodeContext *s)
1334 1334
 
1335 1335
 
1336 1336
 /**
1337
- * Finalize the mantissa bit count by adding in the grouped mantissas.
1338
- */
1339
-static int compute_mantissa_size_final(int mant_cnt[5])
1340
-{
1341
-    // bap=1 : 3 mantissas in 5 bits
1342
-    int bits = (mant_cnt[1] / 3) * 5;
1343
-    // bap=2 : 3 mantissas in 7 bits
1344
-    // bap=4 : 2 mantissas in 7 bits
1345
-    bits += ((mant_cnt[2] / 3) + (mant_cnt[4] >> 1)) * 7;
1346
-    // bap=3 : each mantissa is 3 bits
1347
-    bits += mant_cnt[3] * 3;
1348
-    return bits;
1349
-}
1350
-
1351
-
1352
-/**
1353 1337
  * Calculate masking curve based on the final exponents.
1354 1338
  * Also calculate the power spectral densities to use in future calculations.
1355 1339
  */
... ...
@@ -1386,18 +1430,79 @@ static void bit_alloc_masking(AC3EncodeContext *s)
1386 1386
 static void reset_block_bap(AC3EncodeContext *s)
1387 1387
 {
1388 1388
     int blk, ch;
1389
-    int channels = s->channels + 1;
1390
-    if (s->blocks[0].bap[0] == s->bap_buffer)
1389
+    uint8_t *ref_bap;
1390
+
1391
+    if (s->ref_bap[0][0] == s->bap_buffer && s->ref_bap_set)
1391 1392
         return;
1393
+
1394
+    ref_bap = s->bap_buffer;
1395
+    for (ch = 0; ch <= s->channels; ch++) {
1396
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
1397
+            s->ref_bap[ch][blk] = ref_bap + AC3_MAX_COEFS * s->exp_ref_block[ch][blk];
1398
+        ref_bap += AC3_MAX_COEFS * AC3_MAX_BLOCKS;
1399
+    }
1400
+    s->ref_bap_set = 1;
1401
+}
1402
+
1403
+
1404
+/**
1405
+ * Initialize mantissa counts.
1406
+ * These are set so that they are padded to the next whole group size when bits
1407
+ * are counted in compute_mantissa_size.
1408
+ */
1409
+static void count_mantissa_bits_init(uint16_t mant_cnt[AC3_MAX_BLOCKS][16])
1410
+{
1411
+    int blk;
1412
+
1392 1413
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1393
-        for (ch = 0; ch < channels; ch++) {
1394
-            s->blocks[blk].bap[ch] = &s->bap_buffer[AC3_MAX_COEFS * (blk * channels + ch)];
1395
-        }
1414
+        memset(mant_cnt[blk], 0, sizeof(mant_cnt[blk]));
1415
+        mant_cnt[blk][1] = mant_cnt[blk][2] = 2;
1416
+        mant_cnt[blk][4] = 1;
1417
+    }
1418
+}
1419
+
1420
+
1421
+/**
1422
+ * Update mantissa bit counts for all blocks in 1 channel in a given bandwidth
1423
+ * range.
1424
+ */
1425
+static void count_mantissa_bits_update_ch(AC3EncodeContext *s, int ch,
1426
+                                          uint16_t mant_cnt[AC3_MAX_BLOCKS][16],
1427
+                                          int start, int end)
1428
+{
1429
+    int blk;
1430
+
1431
+    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1432
+        AC3Block *block = &s->blocks[blk];
1433
+        if (ch == CPL_CH && !block->cpl_in_use)
1434
+            continue;
1435
+        s->ac3dsp.update_bap_counts(mant_cnt[blk],
1436
+                                    s->ref_bap[ch][blk] + start,
1437
+                                    FFMIN(end, block->end_freq[ch]) - start);
1396 1438
     }
1397 1439
 }
1398 1440
 
1399 1441
 
1400 1442
 /**
1443
+ * Count the number of mantissa bits in the frame based on the bap values.
1444
+ */
1445
+static int count_mantissa_bits(AC3EncodeContext *s)
1446
+{
1447
+    int ch, max_end_freq;
1448
+    LOCAL_ALIGNED_16(uint16_t, mant_cnt, [AC3_MAX_BLOCKS], [16]);
1449
+
1450
+    count_mantissa_bits_init(mant_cnt);
1451
+
1452
+    max_end_freq = s->bandwidth_code * 3 + 73;
1453
+    for (ch = !s->cpl_enabled; ch <= s->channels; ch++)
1454
+        count_mantissa_bits_update_ch(s, ch, mant_cnt, s->start_freq[ch],
1455
+                                      max_end_freq);
1456
+
1457
+    return s->ac3dsp.compute_mantissa_size(mant_cnt);
1458
+}
1459
+
1460
+
1461
+/**
1401 1462
  * Run the bit allocation with a given SNR offset.
1402 1463
  * This calculates the bit allocation pointers that will be used to determine
1403 1464
  * the quantization of each mantissa.
... ...
@@ -1407,51 +1512,27 @@ static void reset_block_bap(AC3EncodeContext *s)
1407 1407
 static int bit_alloc(AC3EncodeContext *s, int snr_offset)
1408 1408
 {
1409 1409
     int blk, ch;
1410
-    int mantissa_bits;
1411
-    int mant_cnt[5];
1412 1410
 
1413 1411
     snr_offset = (snr_offset - 240) << 2;
1414 1412
 
1415 1413
     reset_block_bap(s);
1416
-    mantissa_bits = 0;
1417 1414
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1418 1415
         AC3Block *block = &s->blocks[blk];
1419
-        AC3Block *ref_block;
1420
-        int av_uninit(ch0);
1421
-        int got_cpl = !block->cpl_in_use;
1422
-        // initialize grouped mantissa counts. these are set so that they are
1423
-        // padded to the next whole group size when bits are counted in
1424
-        // compute_mantissa_size_final
1425
-        mant_cnt[0] = mant_cnt[3] = 0;
1426
-        mant_cnt[1] = mant_cnt[2] = 2;
1427
-        mant_cnt[4] = 1;
1428
-        for (ch = 1; ch <= s->channels; ch++) {
1429
-            if (!got_cpl && ch > 1 && block->channel_in_cpl[ch-1]) {
1430
-                ch0     = ch - 1;
1431
-                ch      = CPL_CH;
1432
-                got_cpl = 1;
1433
-            }
1434 1416
 
1417
+        for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
1435 1418
             /* Currently the only bit allocation parameters which vary across
1436 1419
                blocks within a frame are the exponent values.  We can take
1437 1420
                advantage of that by reusing the bit allocation pointers
1438 1421
                whenever we reuse exponents. */
1439
-            ref_block = block->exp_ref_block[ch];
1440 1422
             if (s->exp_strategy[ch][blk] != EXP_REUSE) {
1441
-                s->ac3dsp.bit_alloc_calc_bap(ref_block->mask[ch], ref_block->psd[ch],
1423
+                s->ac3dsp.bit_alloc_calc_bap(block->mask[ch], block->psd[ch],
1442 1424
                                              s->start_freq[ch], block->end_freq[ch],
1443 1425
                                              snr_offset, s->bit_alloc.floor,
1444
-                                             ff_ac3_bap_tab, ref_block->bap[ch]);
1426
+                                             ff_ac3_bap_tab, s->ref_bap[ch][blk]);
1445 1427
             }
1446
-            mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt,
1447
-                                                             ref_block->bap[ch]+s->start_freq[ch],
1448
-                                                             block->end_freq[ch]-s->start_freq[ch]);
1449
-            if (ch == CPL_CH)
1450
-                ch = ch0;
1451 1428
         }
1452
-        mantissa_bits += compute_mantissa_size_final(mant_cnt);
1453 1429
     }
1454
-    return mantissa_bits;
1430
+    return count_mantissa_bits(s);
1455 1431
 }
1456 1432
 
1457 1433
 
... ...
@@ -1726,7 +1807,6 @@ static void quantize_mantissas(AC3EncodeContext *s)
1726 1726
 
1727 1727
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1728 1728
         AC3Block *block = &s->blocks[blk];
1729
-        AC3Block *ref_block;
1730 1729
         AC3Mant m = { 0 };
1731 1730
 
1732 1731
         got_cpl = !block->cpl_in_use;
... ...
@@ -1736,10 +1816,9 @@ static void quantize_mantissas(AC3EncodeContext *s)
1736 1736
                 ch      = CPL_CH;
1737 1737
                 got_cpl = 1;
1738 1738
             }
1739
-            ref_block = block->exp_ref_block[ch];
1740 1739
             quantize_mantissas_blk_ch(&m, block->fixed_coef[ch],
1741
-                                      ref_block->exp[ch],
1742
-                                      ref_block->bap[ch], block->qmant[ch],
1740
+                                      s->blocks[s->exp_ref_block[ch][blk]].exp[ch],
1741
+                                      s->ref_bap[ch][blk], block->qmant[ch],
1743 1742
                                       s->start_freq[ch], block->end_freq[ch]);
1744 1743
             if (ch == CPL_CH)
1745 1744
                 ch = ch0;
... ...
@@ -1751,7 +1830,7 @@ static void quantize_mantissas(AC3EncodeContext *s)
1751 1751
 /**
1752 1752
  * Write the AC-3 frame header to the output bitstream.
1753 1753
  */
1754
-static void output_frame_header(AC3EncodeContext *s)
1754
+static void ac3_output_frame_header(AC3EncodeContext *s)
1755 1755
 {
1756 1756
     AC3EncOptions *opt = &s->options;
1757 1757
 
... ...
@@ -1805,6 +1884,79 @@ static void output_frame_header(AC3EncodeContext *s)
1805 1805
 
1806 1806
 
1807 1807
 /**
1808
+ * Write the E-AC-3 frame header to the output bitstream.
1809
+ */
1810
+static void eac3_output_frame_header(AC3EncodeContext *s)
1811
+{
1812
+    int blk, ch;
1813
+    AC3EncOptions *opt = &s->options;
1814
+
1815
+    put_bits(&s->pb, 16, 0x0b77);                   /* sync word */
1816
+
1817
+    /* BSI header */
1818
+    put_bits(&s->pb,  2, 0);                        /* stream type = independent */
1819
+    put_bits(&s->pb,  3, 0);                        /* substream id = 0 */
1820
+    put_bits(&s->pb, 11, (s->frame_size / 2) - 1);  /* frame size */
1821
+    if (s->bit_alloc.sr_shift) {
1822
+        put_bits(&s->pb, 2, 0x3);                   /* fscod2 */
1823
+        put_bits(&s->pb, 2, s->bit_alloc.sr_code);  /* sample rate code */
1824
+    } else {
1825
+        put_bits(&s->pb, 2, s->bit_alloc.sr_code);  /* sample rate code */
1826
+        put_bits(&s->pb, 2, 0x3);                   /* number of blocks = 6 */
1827
+    }
1828
+    put_bits(&s->pb, 3, s->channel_mode);           /* audio coding mode */
1829
+    put_bits(&s->pb, 1, s->lfe_on);                 /* LFE channel indicator */
1830
+    put_bits(&s->pb, 5, s->bitstream_id);           /* bitstream id (EAC3=16) */
1831
+    put_bits(&s->pb, 5, -opt->dialogue_level);      /* dialogue normalization level */
1832
+    put_bits(&s->pb, 1, 0);                         /* no compression gain */
1833
+    put_bits(&s->pb, 1, 0);                         /* no mixing metadata */
1834
+    /* TODO: mixing metadata */
1835
+    put_bits(&s->pb, 1, 0);                         /* no info metadata */
1836
+    /* TODO: info metadata */
1837
+    put_bits(&s->pb, 1, 0);                         /* no additional bit stream info */
1838
+
1839
+    /* frame header */
1840
+    put_bits(&s->pb, 1, 1);                         /* exponent strategy syntax = each block */
1841
+    put_bits(&s->pb, 1, 0);                         /* aht enabled = no */
1842
+    put_bits(&s->pb, 2, 0);                         /* snr offset strategy = 1 */
1843
+    put_bits(&s->pb, 1, 0);                         /* transient pre-noise processing enabled = no */
1844
+    put_bits(&s->pb, 1, 0);                         /* block switch syntax enabled = no */
1845
+    put_bits(&s->pb, 1, 0);                         /* dither flag syntax enabled = no */
1846
+    put_bits(&s->pb, 1, 0);                         /* bit allocation model syntax enabled = no */
1847
+    put_bits(&s->pb, 1, 0);                         /* fast gain codes enabled = no */
1848
+    put_bits(&s->pb, 1, 0);                         /* dba syntax enabled = no */
1849
+    put_bits(&s->pb, 1, 0);                         /* skip field syntax enabled = no */
1850
+    put_bits(&s->pb, 1, 0);                         /* spx enabled = no */
1851
+    /* coupling strategy use flags */
1852
+    if (s->channel_mode > AC3_CHMODE_MONO) {
1853
+        put_bits(&s->pb, 1, s->blocks[0].cpl_in_use);
1854
+        for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
1855
+            AC3Block *block = &s->blocks[blk];
1856
+            put_bits(&s->pb, 1, block->new_cpl_strategy);
1857
+            if (block->new_cpl_strategy)
1858
+                put_bits(&s->pb, 1, block->cpl_in_use);
1859
+        }
1860
+    }
1861
+    /* exponent strategy */
1862
+    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
1863
+        for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++)
1864
+            put_bits(&s->pb, 2, s->exp_strategy[ch][blk]);
1865
+    if (s->lfe_on) {
1866
+        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
1867
+            put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]);
1868
+    }
1869
+    /* E-AC-3 to AC-3 converter exponent strategy (unfortunately not optional...) */
1870
+    for (ch = 1; ch <= s->fbw_channels; ch++)
1871
+        put_bits(&s->pb, 5, 0);
1872
+    /* snr offsets */
1873
+    put_bits(&s->pb, 6, s->coarse_snr_offset);
1874
+    put_bits(&s->pb, 4, s->fine_snr_offset[1]);
1875
+    /* block start info */
1876
+    put_bits(&s->pb, 1, 0);
1877
+}
1878
+
1879
+
1880
+/**
1808 1881
  * Write one audio block to the output bitstream.
1809 1882
  */
1810 1883
 static void output_audio_block(AC3EncodeContext *s, int blk)
... ...
@@ -1814,32 +1966,51 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
1814 1814
     AC3Block *block = &s->blocks[blk];
1815 1815
 
1816 1816
     /* block switching */
1817
-    for (ch = 0; ch < s->fbw_channels; ch++)
1818
-        put_bits(&s->pb, 1, 0);
1817
+    if (!s->eac3) {
1818
+        for (ch = 0; ch < s->fbw_channels; ch++)
1819
+            put_bits(&s->pb, 1, 0);
1820
+    }
1819 1821
 
1820 1822
     /* dither flags */
1821
-    for (ch = 0; ch < s->fbw_channels; ch++)
1822
-        put_bits(&s->pb, 1, 1);
1823
+    if (!s->eac3) {
1824
+        for (ch = 0; ch < s->fbw_channels; ch++)
1825
+            put_bits(&s->pb, 1, 1);
1826
+    }
1823 1827
 
1824 1828
     /* dynamic range codes */
1825 1829
     put_bits(&s->pb, 1, 0);
1826 1830
 
1831
+    /* spectral extension */
1832
+    if (s->eac3)
1833
+        put_bits(&s->pb, 1, 0);
1834
+
1827 1835
     /* channel coupling */
1828
-    put_bits(&s->pb, 1, block->new_cpl_strategy);
1836
+    if (!s->eac3)
1837
+        put_bits(&s->pb, 1, block->new_cpl_strategy);
1829 1838
     if (block->new_cpl_strategy) {
1830
-        put_bits(&s->pb, 1, block->cpl_in_use);
1839
+        if (!s->eac3)
1840
+            put_bits(&s->pb, 1, block->cpl_in_use);
1831 1841
         if (block->cpl_in_use) {
1832 1842
             int start_sub, end_sub;
1833
-            for (ch = 1; ch <= s->fbw_channels; ch++)
1834
-                put_bits(&s->pb, 1, block->channel_in_cpl[ch]);
1843
+            if (s->eac3)
1844
+                put_bits(&s->pb, 1, 0); /* enhanced coupling */
1845
+            if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO) {
1846
+                for (ch = 1; ch <= s->fbw_channels; ch++)
1847
+                    put_bits(&s->pb, 1, block->channel_in_cpl[ch]);
1848
+            }
1835 1849
             if (s->channel_mode == AC3_CHMODE_STEREO)
1836 1850
                 put_bits(&s->pb, 1, 0); /* phase flags in use */
1837 1851
             start_sub = (s->start_freq[CPL_CH] - 37) / 12;
1838 1852
             end_sub   = (s->cpl_end_freq       - 37) / 12;
1839 1853
             put_bits(&s->pb, 4, start_sub);
1840 1854
             put_bits(&s->pb, 4, end_sub - 3);
1841
-            for (bnd = start_sub+1; bnd < end_sub; bnd++)
1842
-                put_bits(&s->pb, 1, ff_eac3_default_cpl_band_struct[bnd]);
1855
+            /* coupling band structure */
1856
+            if (s->eac3) {
1857
+                put_bits(&s->pb, 1, 0); /* use default */
1858
+            } else {
1859
+                for (bnd = start_sub+1; bnd < end_sub; bnd++)
1860
+                    put_bits(&s->pb, 1, ff_eac3_default_cpl_band_struct[bnd]);
1861
+            }
1843 1862
         }
1844 1863
     }
1845 1864
 
... ...
@@ -1847,7 +2018,8 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
1847 1847
     if (block->cpl_in_use) {
1848 1848
         for (ch = 1; ch <= s->fbw_channels; ch++) {
1849 1849
             if (block->channel_in_cpl[ch]) {
1850
-                put_bits(&s->pb, 1, block->new_cpl_coords);
1850
+                if (!s->eac3 || block->new_cpl_coords != 2)
1851
+                    put_bits(&s->pb, 1, block->new_cpl_coords);
1851 1852
                 if (block->new_cpl_coords) {
1852 1853
                     put_bits(&s->pb, 2, block->cpl_master_exp[ch]);
1853 1854
                     for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
... ...
@@ -1861,7 +2033,8 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
1861 1861
 
1862 1862
     /* stereo rematrixing */
1863 1863
     if (s->channel_mode == AC3_CHMODE_STEREO) {
1864
-        put_bits(&s->pb, 1, block->new_rematrixing_strategy);
1864
+        if (!s->eac3 || blk > 0)
1865
+            put_bits(&s->pb, 1, block->new_rematrixing_strategy);
1865 1866
         if (block->new_rematrixing_strategy) {
1866 1867
             /* rematrixing flags */
1867 1868
             for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++)
... ...
@@ -1870,10 +2043,12 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
1870 1870
     }
1871 1871
 
1872 1872
     /* exponent strategy */
1873
-    for (ch = !block->cpl_in_use; ch <= s->fbw_channels; ch++)
1874
-        put_bits(&s->pb, 2, s->exp_strategy[ch][blk]);
1875
-    if (s->lfe_on)
1876
-        put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]);
1873
+    if (!s->eac3) {
1874
+        for (ch = !block->cpl_in_use; ch <= s->fbw_channels; ch++)
1875
+            put_bits(&s->pb, 2, s->exp_strategy[ch][blk]);
1876
+        if (s->lfe_on)
1877
+            put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]);
1878
+    }
1877 1879
 
1878 1880
     /* bandwidth */
1879 1881
     for (ch = 1; ch <= s->fbw_channels; ch++) {
... ...
@@ -1903,53 +2078,60 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
1903 1903
     }
1904 1904
 
1905 1905
     /* bit allocation info */
1906
-    baie = (blk == 0);
1907
-    put_bits(&s->pb, 1, baie);
1908
-    if (baie) {
1909
-        put_bits(&s->pb, 2, s->slow_decay_code);
1910
-        put_bits(&s->pb, 2, s->fast_decay_code);
1911
-        put_bits(&s->pb, 2, s->slow_gain_code);
1912
-        put_bits(&s->pb, 2, s->db_per_bit_code);
1913
-        put_bits(&s->pb, 3, s->floor_code);
1906
+    if (!s->eac3) {
1907
+        baie = (blk == 0);
1908
+        put_bits(&s->pb, 1, baie);
1909
+        if (baie) {
1910
+            put_bits(&s->pb, 2, s->slow_decay_code);
1911
+            put_bits(&s->pb, 2, s->fast_decay_code);
1912
+            put_bits(&s->pb, 2, s->slow_gain_code);
1913
+            put_bits(&s->pb, 2, s->db_per_bit_code);
1914
+            put_bits(&s->pb, 3, s->floor_code);
1915
+        }
1914 1916
     }
1915 1917
 
1916 1918
     /* snr offset */
1917
-    put_bits(&s->pb, 1, block->new_snr_offsets);
1918
-    if (block->new_snr_offsets) {
1919
-        put_bits(&s->pb, 6, s->coarse_snr_offset);
1920
-        for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
1921
-            put_bits(&s->pb, 4, s->fine_snr_offset[ch]);
1922
-            put_bits(&s->pb, 3, s->fast_gain_code[ch]);
1919
+    if (!s->eac3) {
1920
+        put_bits(&s->pb, 1, block->new_snr_offsets);
1921
+        if (block->new_snr_offsets) {
1922
+            put_bits(&s->pb, 6, s->coarse_snr_offset);
1923
+            for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
1924
+                put_bits(&s->pb, 4, s->fine_snr_offset[ch]);
1925
+                put_bits(&s->pb, 3, s->fast_gain_code[ch]);
1926
+            }
1923 1927
         }
1928
+    } else {
1929
+        put_bits(&s->pb, 1, 0); /* no converter snr offset */
1924 1930
     }
1925 1931
 
1926 1932
     /* coupling leak */
1927 1933
     if (block->cpl_in_use) {
1928
-        put_bits(&s->pb, 1, block->new_cpl_leak);
1934
+        if (!s->eac3 || block->new_cpl_leak != 2)
1935
+            put_bits(&s->pb, 1, block->new_cpl_leak);
1929 1936
         if (block->new_cpl_leak) {
1930 1937
             put_bits(&s->pb, 3, s->bit_alloc.cpl_fast_leak);
1931 1938
             put_bits(&s->pb, 3, s->bit_alloc.cpl_slow_leak);
1932 1939
         }
1933 1940
     }
1934 1941
 
1935
-    put_bits(&s->pb, 1, 0); /* no delta bit allocation */
1936
-    put_bits(&s->pb, 1, 0); /* no data to skip */
1942
+    if (!s->eac3) {
1943
+        put_bits(&s->pb, 1, 0); /* no delta bit allocation */
1944
+        put_bits(&s->pb, 1, 0); /* no data to skip */
1945
+    }
1937 1946
 
1938 1947
     /* mantissas */
1939 1948
     got_cpl = !block->cpl_in_use;
1940 1949
     for (ch = 1; ch <= s->channels; ch++) {
1941 1950
         int b, q;
1942
-        AC3Block *ref_block;
1943 1951
 
1944 1952
         if (!got_cpl && ch > 1 && block->channel_in_cpl[ch-1]) {
1945 1953
             ch0     = ch - 1;
1946 1954
             ch      = CPL_CH;
1947 1955
             got_cpl = 1;
1948 1956
         }
1949
-        ref_block = block->exp_ref_block[ch];
1950 1957
         for (i = s->start_freq[ch]; i < block->end_freq[ch]; i++) {
1951 1958
             q = block->qmant[ch][i];
1952
-            b = ref_block->bap[ch][i];
1959
+            b = s->ref_bap[ch][blk][i];
1953 1960
             switch (b) {
1954 1961
             case 0:                                         break;
1955 1962
             case 1: if (q != 128) put_bits(&s->pb,   5, q); break;
... ...
@@ -2022,6 +2204,10 @@ static void output_frame_end(AC3EncodeContext *s)
2022 2022
     if (pad_bytes > 0)
2023 2023
         memset(put_bits_ptr(&s->pb), 0, pad_bytes);
2024 2024
 
2025
+    if (s->eac3) {
2026
+        /* compute crc2 */
2027
+        crc2_partial = av_crc(crc_ctx, 0, frame + 2, s->frame_size - 5);
2028
+    } else {
2025 2029
     /* compute crc1 */
2026 2030
     /* this is not so easy because it is at the beginning of the data... */
2027 2031
     crc1    = av_bswap16(av_crc(crc_ctx, 0, frame + 4, frame_size_58 - 4));
... ...
@@ -2032,6 +2218,7 @@ static void output_frame_end(AC3EncodeContext *s)
2032 2032
     /* compute crc2 */
2033 2033
     crc2_partial = av_crc(crc_ctx, 0, frame + frame_size_58,
2034 2034
                           s->frame_size - frame_size_58 - 3);
2035
+    }
2035 2036
     crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1);
2036 2037
     /* ensure crc2 does not match sync word by flipping crcrsv bit if needed */
2037 2038
     if (crc2 == 0x770B) {
... ...
@@ -2052,7 +2239,10 @@ static void output_frame(AC3EncodeContext *s, unsigned char *frame)
2052 2052
 
2053 2053
     init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE);
2054 2054
 
2055
-    output_frame_header(s);
2055
+    if (s->eac3)
2056
+        eac3_output_frame_header(s);
2057
+    else
2058
+        ac3_output_frame_header(s);
2056 2059
 
2057 2060
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
2058 2061
         output_audio_block(s, blk);
... ...
@@ -2069,10 +2259,11 @@ static void dprint_options(AVCodecContext *avctx)
2069 2069
     char strbuf[32];
2070 2070
 
2071 2071
     switch (s->bitstream_id) {
2072
-    case  6:  av_strlcpy(strbuf, "AC-3 (alt syntax)", 32);      break;
2073
-    case  8:  av_strlcpy(strbuf, "AC-3 (standard)", 32);        break;
2074
-    case  9:  av_strlcpy(strbuf, "AC-3 (dnet half-rate)", 32);  break;
2075
-    case 10:  av_strlcpy(strbuf, "AC-3 (dnet quater-rate", 32); break;
2072
+    case  6:  av_strlcpy(strbuf, "AC-3 (alt syntax)",       32); break;
2073
+    case  8:  av_strlcpy(strbuf, "AC-3 (standard)",         32); break;
2074
+    case  9:  av_strlcpy(strbuf, "AC-3 (dnet half-rate)",   32); break;
2075
+    case 10:  av_strlcpy(strbuf, "AC-3 (dnet quater-rate)", 32); break;
2076
+    case 16:  av_strlcpy(strbuf, "E-AC-3 (enhanced)",       32); break;
2076 2077
     default: snprintf(strbuf, 32, "ERROR");
2077 2078
     }
2078 2079
     av_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id);
... ...
@@ -2333,13 +2524,13 @@ static int ac3_encode_frame(AVCodecContext *avctx, unsigned char *frame,
2333 2333
     const SampleType *samples = data;
2334 2334
     int ret;
2335 2335
 
2336
-    if (s->options.allow_per_frame_metadata) {
2336
+    if (!s->eac3 && s->options.allow_per_frame_metadata) {
2337 2337
         ret = validate_metadata(avctx);
2338 2338
         if (ret)
2339 2339
             return ret;
2340 2340
     }
2341 2341
 
2342
-    if (s->bit_alloc.sr_code == 1)
2342
+    if (s->bit_alloc.sr_code == 1 || s->eac3)
2343 2343
         adjust_frame_size(s);
2344 2344
 
2345 2345
     deinterleave_input_samples(s, samples);
... ...
@@ -2397,7 +2588,6 @@ static av_cold int ac3_encode_close(AVCodecContext *avctx)
2397 2397
     av_freep(&s->qmant_buffer);
2398 2398
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
2399 2399
         AC3Block *block = &s->blocks[blk];
2400
-        av_freep(&block->bap);
2401 2400
         av_freep(&block->mdct_coef);
2402 2401
         av_freep(&block->fixed_coef);
2403 2402
         av_freep(&block->exp);
... ...
@@ -2465,7 +2655,7 @@ static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
2465 2465
 
2466 2466
 static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
2467 2467
 {
2468
-    int i, ret;
2468
+    int i, ret, max_sr;
2469 2469
 
2470 2470
     /* validate channel layout */
2471 2471
     if (!avctx->channel_layout) {
... ...
@@ -2480,30 +2670,72 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
2480 2480
     }
2481 2481
 
2482 2482
     /* validate sample rate */
2483
-    for (i = 0; i < 9; i++) {
2484
-        if ((ff_ac3_sample_rate_tab[i / 3] >> (i % 3)) == avctx->sample_rate)
2483
+    /* note: max_sr could be changed from 2 to 5 for E-AC-3 once we find a
2484
+             decoder that supports half sample rate so we can validate that
2485
+             the generated files are correct. */
2486
+    max_sr = s->eac3 ? 2 : 8;
2487
+    for (i = 0; i <= max_sr; i++) {
2488
+        if ((ff_ac3_sample_rate_tab[i % 3] >> (i / 3)) == avctx->sample_rate)
2485 2489
             break;
2486 2490
     }
2487
-    if (i == 9) {
2491
+    if (i > max_sr) {
2488 2492
         av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n");
2489 2493
         return AVERROR(EINVAL);
2490 2494
     }
2491 2495
     s->sample_rate        = avctx->sample_rate;
2492
-    s->bit_alloc.sr_shift = i % 3;
2493
-    s->bit_alloc.sr_code  = i / 3;
2494
-    s->bitstream_id       = 8 + s->bit_alloc.sr_shift;
2496
+    s->bit_alloc.sr_shift = i / 3;
2497
+    s->bit_alloc.sr_code  = i % 3;
2498
+    s->bitstream_id       = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;
2495 2499
 
2496 2500
     /* validate bit rate */
2497
-    for (i = 0; i < 19; i++) {
2498
-        if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate)
2499
-            break;
2500
-    }
2501
-    if (i == 19) {
2502
-        av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n");
2503
-        return AVERROR(EINVAL);
2501
+    if (s->eac3) {
2502
+        int max_br, min_br, wpf, min_br_dist, min_br_code;
2503
+
2504
+        /* calculate min/max bitrate */
2505
+        max_br = 2048 * s->sample_rate / AC3_FRAME_SIZE * 16;
2506
+        min_br = ((s->sample_rate + (AC3_FRAME_SIZE-1)) / AC3_FRAME_SIZE) * 16;
2507
+        if (avctx->bit_rate < min_br || avctx->bit_rate > max_br) {
2508
+            av_log(avctx, AV_LOG_ERROR, "invalid bit rate. must be %d to %d "
2509
+                   "for this sample rate\n", min_br, max_br);
2510
+            return AVERROR(EINVAL);
2511
+        }
2512
+
2513
+        /* calculate words-per-frame for the selected bitrate */
2514
+        wpf = (avctx->bit_rate / 16) * AC3_FRAME_SIZE / s->sample_rate;
2515
+        av_assert1(wpf > 0 && wpf <= 2048);
2516
+
2517
+        /* find the closest AC-3 bitrate code to the selected bitrate.
2518
+           this is needed for lookup tables for bandwidth and coupling
2519
+           parameter selection */
2520
+        min_br_code = -1;
2521
+        min_br_dist = INT_MAX;
2522
+        for (i = 0; i < 19; i++) {
2523
+            int br_dist = abs(ff_ac3_bitrate_tab[i] * 1000 - avctx->bit_rate);
2524
+            if (br_dist < min_br_dist) {
2525
+                min_br_dist = br_dist;
2526
+                min_br_code = i;
2527
+            }
2528
+        }
2529
+
2530
+        /* make sure the minimum frame size is below the average frame size */
2531
+        s->frame_size_code = min_br_code << 1;
2532
+        while (wpf > 1 && wpf * s->sample_rate / AC3_FRAME_SIZE * 16 > avctx->bit_rate)
2533
+            wpf--;
2534
+        s->frame_size_min = 2 * wpf;
2535
+    } else {
2536
+        for (i = 0; i < 19; i++) {
2537
+            if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate)
2538
+                break;
2539
+        }
2540
+        if (i == 19) {
2541
+            av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n");
2542
+            return AVERROR(EINVAL);
2543
+        }
2544
+        s->frame_size_code = i << 1;
2545
+        s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
2504 2546
     }
2505
-    s->bit_rate        = avctx->bit_rate;
2506
-    s->frame_size_code = i << 1;
2547
+    s->bit_rate   = avctx->bit_rate;
2548
+    s->frame_size = s->frame_size_min;
2507 2549
 
2508 2550
     /* validate cutoff */
2509 2551
     if (avctx->cutoff < 0) {
... ...
@@ -2526,9 +2758,11 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
2526 2526
         return AVERROR(EINVAL);
2527 2527
     }
2528 2528
 
2529
-    ret = validate_metadata(avctx);
2530
-    if (ret)
2531
-        return ret;
2529
+    if (!s->eac3) {
2530
+        ret = validate_metadata(avctx);
2531
+        if (ret)
2532
+            return ret;
2533
+    }
2532 2534
 
2533 2535
     s->rematrixing_enabled = s->options.stereo_rematrixing &&
2534 2536
                              (s->channel_mode == AC3_CHMODE_STEREO);
... ...
@@ -2652,8 +2886,6 @@ static av_cold int allocate_buffers(AVCodecContext *avctx)
2652 2652
     }
2653 2653
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
2654 2654
         AC3Block *block = &s->blocks[blk];
2655
-        FF_ALLOC_OR_GOTO(avctx, block->bap, channels * sizeof(*block->bap),
2656
-                         alloc_fail);
2657 2655
         FF_ALLOCZ_OR_GOTO(avctx, block->mdct_coef, channels * sizeof(*block->mdct_coef),
2658 2656
                           alloc_fail);
2659 2657
         FF_ALLOCZ_OR_GOTO(avctx, block->exp, channels * sizeof(*block->exp),
... ...
@@ -2677,7 +2909,6 @@ static av_cold int allocate_buffers(AVCodecContext *avctx)
2677 2677
 
2678 2678
         for (ch = 0; ch < channels; ch++) {
2679 2679
             /* arrangement: block, channel, coeff */
2680
-            block->bap[ch]         = &s->bap_buffer        [AC3_MAX_COEFS * (blk * channels + ch)];
2681 2680
             block->grouped_exp[ch] = &s->grouped_exp_buffer[128           * (blk * channels + ch)];
2682 2681
             block->psd[ch]         = &s->psd_buffer        [AC3_MAX_COEFS * (blk * channels + ch)];
2683 2682
             block->band_psd[ch]    = &s->band_psd_buffer   [64            * (blk * channels + ch)];
... ...
@@ -2728,6 +2959,8 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx)
2728 2728
     AC3EncodeContext *s = avctx->priv_data;
2729 2729
     int ret, frame_size_58;
2730 2730
 
2731
+    s->eac3 = avctx->codec_id == CODEC_ID_EAC3;
2732
+
2731 2733
     avctx->frame_size = AC3_FRAME_SIZE;
2732 2734
 
2733 2735
     ff_ac3_common_init();
... ...
@@ -2740,10 +2973,8 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx)
2740 2740
     if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)
2741 2741
         s->bitstream_mode = 0x7;
2742 2742
 
2743
-    s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
2744 2743
     s->bits_written    = 0;
2745 2744
     s->samples_written = 0;
2746
-    s->frame_size      = s->frame_size_min;
2747 2745
 
2748 2746
     /* calculate crc_inv for both possible frame sizes */
2749 2747
     frame_size_58 = (( s->frame_size    >> 2) + ( s->frame_size    >> 4)) << 1;
... ...
@@ -11,8 +11,18 @@ typedef struct CombineContext{
11 11
     AVCodec *codec;
12 12
 }CombineContext;
13 13
 
14
+#define OFFSET(param) offsetof(CombineContext, options.param)
15
+#define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
16
+
17
+#define AC3ENC_TYPE_AC3_FIXED   0
18
+#define AC3ENC_TYPE_AC3         1
19
+#define AC3ENC_TYPE_EAC3        2
20
+
21
+#define AC3ENC_TYPE 12354
22
+#include "ac3enc_opts_template.c"
23
+
14 24
 static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
15
-                                ff_ac3_options, LIBAVUTIL_VERSION_INT };
25
+                                eac3_options, LIBAVUTIL_VERSION_INT };
16 26
 
17 27
 static av_cold AVCodec *get_codec(enum AVSampleFormat s){
18 28
 #if CONFIG_AC3_FIXED_ENCODER
... ...
@@ -100,6 +100,7 @@ static void scale_coefficients(AC3EncodeContext *s)
100 100
 }
101 101
 
102 102
 
103
+#if CONFIG_AC3_ENCODER
103 104
 AVCodec ff_ac3_float_encoder = {
104 105
     "ac3_float",
105 106
     AVMEDIA_TYPE_AUDIO,
... ...
@@ -114,3 +115,20 @@ AVCodec ff_ac3_float_encoder = {
114 114
     .priv_class = &ac3enc_class,
115 115
     .channel_layouts = ff_ac3_channel_layouts,
116 116
 };
117
+#endif
118
+
119
+#if CONFIG_EAC3_ENCODER
120
+AVCodec ff_eac3_encoder = {
121
+    .name            = "eac3",
122
+    .type            = AVMEDIA_TYPE_AUDIO,
123
+    .id              = CODEC_ID_EAC3,
124
+    .priv_data_size  = sizeof(AC3EncodeContext),
125
+    .init            = ac3_encode_init,
126
+    .encode          = ac3_encode_frame,
127
+    .close           = ac3_encode_close,
128
+    .sample_fmts     = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
129
+    .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
130
+    .priv_class      = &eac3enc_class,
131
+    .channel_layouts = ff_ac3_channel_layouts,
132
+};
133
+#endif
117 134
new file mode 100644
... ...
@@ -0,0 +1,81 @@
0
+/*
1
+ * AC-3 encoder options
2
+ * Copyright (c) 2010 Justin Ruggles <justin.ruggles@gmail.com>
3
+ *
4
+ * This file is part of Libav.
5
+ *
6
+ * Libav 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
+ * Libav 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 Libav; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED
22
+static const AVOption ac3fixed_options[] = {
23
+#elif AC3ENC_TYPE == AC3ENC_TYPE_AC3
24
+static const AVOption ac3_options[] = {
25
+#else /* AC3ENC_TYPE_EAC3 */
26
+static const AVOption eac3_options[] = {
27
+#endif
28
+#if AC3ENC_TYPE != AC3ENC_TYPE_EAC3
29
+/* Metadata Options */
30
+{"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM},
31
+/* downmix levels */
32
+{"center_mixlev", "Center Mix Level", OFFSET(center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_4POINT5DB }, 0.0, 1.0, AC3ENC_PARAM},
33
+{"surround_mixlev", "Surround Mix Level", OFFSET(surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_6DB }, 0.0, 1.0, AC3ENC_PARAM},
34
+/* audio production information */
35
+{"mixing_level", "Mixing Level", OFFSET(mixing_level), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 111, AC3ENC_PARAM},
36
+{"room_type", "Room Type", OFFSET(room_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "room_type"},
37
+    {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
38
+    {"large",        "Large Room",              0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
39
+    {"small",        "Small Room",              0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"},
40
+/* other metadata options */
41
+{"copyright", "Copyright Bit", OFFSET(copyright), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM},
42
+#endif
43
+{"dialnorm", "Dialogue Level (dB)", OFFSET(dialogue_level), FF_OPT_TYPE_INT, {.dbl = -31 }, -31, -1, AC3ENC_PARAM},
44
+#if AC3ENC_TYPE != AC3ENC_TYPE_EAC3
45
+{"dsur_mode", "Dolby Surround Mode", OFFSET(dolby_surround_mode), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, 2, AC3ENC_PARAM, "dsur_mode"},
46
+    {"notindicated", "Not Indicated (default)",    0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
47
+    {"on",           "Dolby Surround Encoded",     0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
48
+    {"off",          "Not Dolby Surround Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"},
49
+{"original", "Original Bit Stream", OFFSET(original), FF_OPT_TYPE_INT,   {.dbl = 1 }, 0, 1, AC3ENC_PARAM},
50
+/* extended bitstream information */
51
+{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dmix_mode"},
52
+    {"notindicated", "Not Indicated (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
53
+    {"ltrt", "Lt/Rt Downmix Preferred",         0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
54
+    {"loro", "Lo/Ro Downmix Preferred",         0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"},
55
+{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
56
+{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
57
+{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
58
+{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM},
59
+{"dsurex_mode", "Dolby Surround EX Mode", OFFSET(dolby_surround_ex_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dsurex_mode"},
60
+    {"notindicated", "Not Indicated (default)",       0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
61
+    {"on",           "Dolby Surround EX Encoded",     0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
62
+    {"off",          "Not Dolby Surround EX Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"},
63
+{"dheadphone_mode", "Dolby Headphone Mode", OFFSET(dolby_headphone_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, AC3ENC_PARAM, "dheadphone_mode"},
64
+    {"notindicated", "Not Indicated (default)",     0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
65
+    {"on",           "Dolby Headphone Encoded",     0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
66
+    {"off",          "Not Dolby Headphone Encoded", 0, FF_OPT_TYPE_CONST, {.dbl = 2 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"},
67
+{"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 1, AC3ENC_PARAM, "ad_conv_type"},
68
+    {"standard", "Standard (default)", 0, FF_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
69
+    {"hdcd",     "HDCD",               0, FF_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
70
+#endif
71
+/* Other Encoding Options */
72
+{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM},
73
+#if AC3ENC_TYPE != AC3ENC_TYPE_AC3_FIXED
74
+{"channel_coupling",   "Channel Coupling",   OFFSET(channel_coupling),   FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 1, AC3ENC_PARAM, "channel_coupling"},
75
+    {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "channel_coupling"},
76
+{"cpl_start_band", "Coupling Start Band", OFFSET(cpl_start), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 15, AC3ENC_PARAM, "cpl_start_band"},
77
+    {"auto", "Selected by the Encoder", 0, FF_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},
78
+#endif
79
+{NULL}
80
+};
... ...
@@ -253,7 +253,7 @@ void avcodec_register_all(void)
253 253
     REGISTER_DECODER (COOK, cook);
254 254
     REGISTER_ENCDEC  (DCA, dca);
255 255
     REGISTER_DECODER (DSICINAUDIO, dsicinaudio);
256
-    REGISTER_DECODER (EAC3, eac3);
256
+    REGISTER_ENCDEC  (EAC3, eac3);
257 257
     REGISTER_ENCDEC  (FLAC, flac);
258 258
     REGISTER_DECODER (GSM, gsm);
259 259
     REGISTER_DECODER (GSM_MS, gsm_ms);
... ...
@@ -1,5 +1,4 @@
1 1
 OBJS-$(CONFIG_AC3DSP)                  += arm/ac3dsp_init_arm.o         \
2
-                                          arm/ac3dsp_arm.o
3 2
 
4 3
 OBJS-$(CONFIG_DCA_DECODER)             += arm/dcadsp_init_arm.o         \
5 4
 
... ...
@@ -30,17 +30,17 @@ static inline float *VMUL2(float *dst, const float *v, unsigned idx,
30 30
                            const float *scale)
31 31
 {
32 32
     unsigned v0, v1;
33
-    __asm__ volatile ("ubfx     %0,  %4,  #0, #4      \n\t"
34
-                      "ubfx     %1,  %4,  #4, #4      \n\t"
35
-                      "ldr      %0,  [%3, %0, lsl #2] \n\t"
36
-                      "ldr      %1,  [%3, %1, lsl #2] \n\t"
37
-                      "vld1.32  {d1[]},   [%5,:32]    \n\t"
38
-                      "vmov     d0,  %0,  %1          \n\t"
39
-                      "vmul.f32 d0,  d0,  d1          \n\t"
40
-                      "vst1.32  {d0},     [%2,:64]!   \n\t"
41
-                      : "=&r"(v0), "=&r"(v1), "+r"(dst)
42
-                      : "r"(v), "r"(idx), "r"(scale)
43
-                      : "d0", "d1");
33
+    __asm__ ("ubfx     %0,  %6,  #0, #4      \n\t"
34
+             "ubfx     %1,  %6,  #4, #4      \n\t"
35
+             "ldr      %0,  [%5, %0, lsl #2] \n\t"
36
+             "ldr      %1,  [%5, %1, lsl #2] \n\t"
37
+             "vld1.32  {d1[]},   [%7,:32]    \n\t"
38
+             "vmov     d0,  %0,  %1          \n\t"
39
+             "vmul.f32 d0,  d0,  d1          \n\t"
40
+             "vst1.32  {d0},     [%2,:64]!   \n\t"
41
+             : "=&r"(v0), "=&r"(v1), "+r"(dst), "=m"(dst[0]), "=m"(dst[1])
42
+             : "r"(v), "r"(idx), "r"(scale)
43
+             : "d0", "d1");
44 44
     return dst;
45 45
 }
46 46
 
... ...
@@ -49,22 +49,23 @@ static inline float *VMUL4(float *dst, const float *v, unsigned idx,
49 49
                            const float *scale)
50 50
 {
51 51
     unsigned v0, v1, v2, v3;
52
-    __asm__ volatile ("ubfx     %0,  %6,  #0, #2      \n\t"
53
-                      "ubfx     %1,  %6,  #2, #2      \n\t"
54
-                      "ldr      %0,  [%5, %0, lsl #2] \n\t"
55
-                      "ubfx     %2,  %6,  #4, #2      \n\t"
56
-                      "ldr      %1,  [%5, %1, lsl #2] \n\t"
57
-                      "ubfx     %3,  %6,  #6, #2      \n\t"
58
-                      "ldr      %2,  [%5, %2, lsl #2] \n\t"
59
-                      "vmov     d0,  %0,  %1          \n\t"
60
-                      "ldr      %3,  [%5, %3, lsl #2] \n\t"
61
-                      "vld1.32  {d2[],d3[]},[%7,:32]  \n\t"
62
-                      "vmov     d1,  %2,  %3          \n\t"
63
-                      "vmul.f32 q0,  q0,  q1          \n\t"
64
-                      "vst1.32  {q0},     [%4,:128]!  \n\t"
65
-                      : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst)
66
-                      : "r"(v), "r"(idx), "r"(scale)
67
-                      : "d0", "d1", "d2", "d3");
52
+    __asm__ ("ubfx     %0,  %10, #0, #2      \n\t"
53
+             "ubfx     %1,  %10, #2, #2      \n\t"
54
+             "ldr      %0,  [%9, %0, lsl #2] \n\t"
55
+             "ubfx     %2,  %10, #4, #2      \n\t"
56
+             "ldr      %1,  [%9, %1, lsl #2] \n\t"
57
+             "ubfx     %3,  %10, #6, #2      \n\t"
58
+             "ldr      %2,  [%9, %2, lsl #2] \n\t"
59
+             "vmov     d0,  %0,  %1          \n\t"
60
+             "ldr      %3,  [%9, %3, lsl #2] \n\t"
61
+             "vld1.32  {d2[],d3[]},[%11,:32] \n\t"
62
+             "vmov     d1,  %2,  %3          \n\t"
63
+             "vmul.f32 q0,  q0,  q1          \n\t"
64
+             "vst1.32  {q0},     [%4,:128]!  \n\t"
65
+             : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst),
66
+               "=m"(dst[0]), "=m"(dst[1]), "=m"(dst[2]), "=m"(dst[3])
67
+             : "r"(v), "r"(idx), "r"(scale)
68
+             : "d0", "d1", "d2", "d3");
68 69
     return dst;
69 70
 }
70 71
 
... ...
@@ -73,22 +74,23 @@ static inline float *VMUL2S(float *dst, const float *v, unsigned idx,
73 73
                             unsigned sign, const float *scale)
74 74
 {
75 75
     unsigned v0, v1, v2, v3;
76
-    __asm__ volatile ("ubfx     %0,  %6,  #0, #4      \n\t"
77
-                      "ubfx     %1,  %6,  #4, #4      \n\t"
78
-                      "ldr      %0,  [%5, %0, lsl #2] \n\t"
79
-                      "lsl      %2,  %8,  #30         \n\t"
80
-                      "ldr      %1,  [%5, %1, lsl #2] \n\t"
81
-                      "lsl      %3,  %8,  #31         \n\t"
82
-                      "vmov     d0,  %0,  %1          \n\t"
83
-                      "bic      %2,  %2,  #1<<30      \n\t"
84
-                      "vld1.32  {d1[]},   [%7,:32]    \n\t"
85
-                      "vmov     d2,  %2,  %3          \n\t"
86
-                      "veor     d0,  d0,  d2          \n\t"
87
-                      "vmul.f32 d0,  d0,  d1          \n\t"
88
-                      "vst1.32  {d0},     [%4,:64]!   \n\t"
89
-                      : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst)
90
-                      : "r"(v), "r"(idx), "r"(scale), "r"(sign)
91
-                      : "d0", "d1", "d2");
76
+    __asm__ ("ubfx     %0,  %8,  #0, #4      \n\t"
77
+             "ubfx     %1,  %8,  #4, #4      \n\t"
78
+             "ldr      %0,  [%7, %0, lsl #2] \n\t"
79
+             "lsl      %2,  %10, #30         \n\t"
80
+             "ldr      %1,  [%7, %1, lsl #2] \n\t"
81
+             "lsl      %3,  %10, #31         \n\t"
82
+             "vmov     d0,  %0,  %1          \n\t"
83
+             "bic      %2,  %2,  #1<<30      \n\t"
84
+             "vld1.32  {d1[]},   [%9,:32]    \n\t"
85
+             "vmov     d2,  %2,  %3          \n\t"
86
+             "veor     d0,  d0,  d2          \n\t"
87
+             "vmul.f32 d0,  d0,  d1          \n\t"
88
+             "vst1.32  {d0},     [%4,:64]!   \n\t"
89
+             : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst),
90
+               "=m"(dst[0]), "=m"(dst[1])
91
+             : "r"(v), "r"(idx), "r"(scale), "r"(sign)
92
+             : "d0", "d1", "d2");
92 93
     return dst;
93 94
 }
94 95
 
... ...
@@ -97,38 +99,39 @@ static inline float *VMUL4S(float *dst, const float *v, unsigned idx,
97 97
                             unsigned sign, const float *scale)
98 98
 {
99 99
     unsigned v0, v1, v2, v3, nz;
100
-    __asm__ volatile ("vld1.32  {d2[],d3[]},[%9,:32]  \n\t"
101
-                      "ubfx     %0,  %8,  #0, #2      \n\t"
102
-                      "ubfx     %1,  %8,  #2, #2      \n\t"
103
-                      "ldr      %0,  [%7, %0, lsl #2] \n\t"
104
-                      "ubfx     %2,  %8,  #4, #2      \n\t"
105
-                      "ldr      %1,  [%7, %1, lsl #2] \n\t"
106
-                      "ubfx     %3,  %8,  #6, #2      \n\t"
107
-                      "ldr      %2,  [%7, %2, lsl #2] \n\t"
108
-                      "vmov     d0,  %0,  %1          \n\t"
109
-                      "ldr      %3,  [%7, %3, lsl #2] \n\t"
110
-                      "lsr      %6,  %8,  #12         \n\t"
111
-                      "rbit     %6,  %6               \n\t"
112
-                      "vmov     d1,  %2,  %3          \n\t"
113
-                      "lsls     %6,  %6,  #1          \n\t"
114
-                      "and      %0,  %5,  #1<<31      \n\t"
115
-                      "lslcs    %5,  %5,  #1          \n\t"
116
-                      "lsls     %6,  %6,  #1          \n\t"
117
-                      "and      %1,  %5,  #1<<31      \n\t"
118
-                      "lslcs    %5,  %5,  #1          \n\t"
119
-                      "lsls     %6,  %6,  #1          \n\t"
120
-                      "and      %2,  %5,  #1<<31      \n\t"
121
-                      "lslcs    %5,  %5,  #1          \n\t"
122
-                      "vmov     d4,  %0,  %1          \n\t"
123
-                      "and      %3,  %5,  #1<<31      \n\t"
124
-                      "vmov     d5,  %2,  %3          \n\t"
125
-                      "veor     q0,  q0,  q2          \n\t"
126
-                      "vmul.f32 q0,  q0,  q1          \n\t"
127
-                      "vst1.32  {q0},     [%4,:128]!  \n\t"
128
-                      : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst),
129
-                        "+r"(sign), "=r"(nz)
130
-                      : "r"(v), "r"(idx), "r"(scale)
131
-                      : "d0", "d1", "d2", "d3", "d4", "d5");
100
+    __asm__ ("vld1.32  {d2[],d3[]},[%13,:32] \n\t"
101
+             "ubfx     %0,  %12, #0, #2      \n\t"
102
+             "ubfx     %1,  %12, #2, #2      \n\t"
103
+             "ldr      %0,  [%11,%0, lsl #2] \n\t"
104
+             "ubfx     %2,  %12, #4, #2      \n\t"
105
+             "ldr      %1,  [%11,%1, lsl #2] \n\t"
106
+             "ubfx     %3,  %12, #6, #2      \n\t"
107
+             "ldr      %2,  [%11,%2, lsl #2] \n\t"
108
+             "vmov     d0,  %0,  %1          \n\t"
109
+             "ldr      %3,  [%11,%3, lsl #2] \n\t"
110
+             "lsr      %6,  %12, #12         \n\t"
111
+             "rbit     %6,  %6               \n\t"
112
+             "vmov     d1,  %2,  %3          \n\t"
113
+             "lsls     %6,  %6,  #1          \n\t"
114
+             "and      %0,  %5,  #1<<31      \n\t"
115
+             "lslcs    %5,  %5,  #1          \n\t"
116
+             "lsls     %6,  %6,  #1          \n\t"
117
+             "and      %1,  %5,  #1<<31      \n\t"
118
+             "lslcs    %5,  %5,  #1          \n\t"
119
+             "lsls     %6,  %6,  #1          \n\t"
120
+             "and      %2,  %5,  #1<<31      \n\t"
121
+             "lslcs    %5,  %5,  #1          \n\t"
122
+             "vmov     d4,  %0,  %1          \n\t"
123
+             "and      %3,  %5,  #1<<31      \n\t"
124
+             "vmov     d5,  %2,  %3          \n\t"
125
+             "veor     q0,  q0,  q2          \n\t"
126
+             "vmul.f32 q0,  q0,  q1          \n\t"
127
+             "vst1.32  {q0},     [%4,:128]!  \n\t"
128
+             : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst),
129
+               "+r"(sign), "=r"(nz),
130
+               "=m"(dst[0]), "=m"(dst[1]), "=m"(dst[2]), "=m"(dst[3])
131
+             : "r"(v), "r"(idx), "r"(scale)
132
+             : "cc", "d0", "d1", "d2", "d3", "d4", "d5");
132 133
     return dst;
133 134
 }
134 135
 
135 136
deleted file mode 100644
... ...
@@ -1,52 +0,0 @@
1
-/*
2
- * Copyright (c) 2011 Mans Rullgard <mans@mansr.com>
3
- *
4
- * This file is part of Libav.
5
- *
6
- * Libav 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
- * Libav 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 Libav; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#include "asm.S"
22
-
23
-function ff_ac3_compute_mantissa_size_arm, export=1
24
-        push            {r4-r8,lr}
25
-        ldm             r0,  {r4-r8}
26
-        mov             r3,  r0
27
-        mov             r0,  #0
28
-1:
29
-        ldrb            lr,  [r1], #1
30
-        subs            r2,  r2,  #1
31
-        blt             2f
32
-        cmp             lr,  #4
33
-        bgt             3f
34
-        subs            lr,  lr,  #1
35
-        addlt           r4,  r4,  #1
36
-        addeq           r5,  r5,  #1
37
-        ble             1b
38
-        subs            lr,  lr,  #2
39
-        addlt           r6,  r6,  #1
40
-        addeq           r7,  r7,  #1
41
-        addgt           r8,  r8,  #1
42
-        b               1b
43
-3:
44
-        cmp             lr,  #14
45
-        sublt           lr,  lr,  #1
46
-        addgt           r0,  r0,  #16
47
-        addle           r0,  r0,  lr
48
-        b               1b
49
-2:
50
-        stm             r3,  {r4-r8}
51
-        pop             {r4-r8,pc}
52
-endfunc
... ...
@@ -39,8 +39,6 @@ int ff_ac3_compute_mantissa_size_arm(int cnt[5], uint8_t *bap, int nb_coefs);
39 39
 
40 40
 av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact)
41 41
 {
42
-    c->compute_mantissa_size     = ff_ac3_compute_mantissa_size_arm;
43
-
44 42
     if (HAVE_ARMV6) {
45 43
         c->bit_alloc_calc_bap    = ff_ac3_bit_alloc_calc_bap_armv6;
46 44
     }
... ...
@@ -97,7 +97,7 @@ static inline av_const int MUL16(int ra, int rb)
97 97
 static inline av_const int mid_pred(int a, int b, int c)
98 98
 {
99 99
     int m;
100
-    __asm__ volatile (
100
+    __asm__ (
101 101
         "mov   %0, %2  \n\t"
102 102
         "cmp   %1, %2  \n\t"
103 103
         "movgt %0, %1  \n\t"
... ...
@@ -107,7 +107,8 @@ static inline av_const int mid_pred(int a, int b, int c)
107 107
         "cmp   %0, %1  \n\t"
108 108
         "movgt %0, %1  \n\t"
109 109
         : "=&r"(m), "+r"(a)
110
-        : "r"(b), "r"(c));
110
+        : "r"(b), "r"(c)
111
+        : "cc");
111 112
     return m;
112 113
 }
113 114
 
... ...
@@ -31,24 +31,25 @@ static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr)
31 31
     unsigned high      = c->high << shift;
32 32
     unsigned bit;
33 33
 
34
-    __asm__ volatile ("adds    %3,  %3,  %0           \n"
35
-                      "cmpcs   %7,  %4                \n"
36
-                      "ldrcsh  %2,  [%4], #2          \n"
37
-                      "rsb     %0,  %6,  #256         \n"
38
-                      "smlabb  %0,  %5,  %6,  %0      \n"
39
-                      "rev16cs %2,  %2                \n"
40
-                      "orrcs   %1,  %1,  %2,  lsl %3  \n"
41
-                      "subcs   %3,  %3,  #16          \n"
42
-                      "lsr     %0,  %0,  #8           \n"
43
-                      "cmp     %1,  %0,  lsl #16      \n"
44
-                      "subge   %1,  %1,  %0,  lsl #16 \n"
45
-                      "subge   %0,  %5,  %0           \n"
46
-                      "movge   %2,  #1                \n"
47
-                      "movlt   %2,  #0                \n"
48
-                      : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit),
49
-                        "+&r"(c->bits), "+&r"(c->buffer)
50
-                      : "r"(high), "r"(pr), "r"(c->end - 1),
51
-                        "0"(shift), "1"(code_word));
34
+    __asm__ ("adds    %3,  %3,  %0           \n"
35
+             "cmpcs   %7,  %4                \n"
36
+             "ldrcsh  %2,  [%4], #2          \n"
37
+             "rsb     %0,  %6,  #256         \n"
38
+             "smlabb  %0,  %5,  %6,  %0      \n"
39
+             "rev16cs %2,  %2                \n"
40
+             "orrcs   %1,  %1,  %2,  lsl %3  \n"
41
+             "subcs   %3,  %3,  #16          \n"
42
+             "lsr     %0,  %0,  #8           \n"
43
+             "cmp     %1,  %0,  lsl #16      \n"
44
+             "subge   %1,  %1,  %0,  lsl #16 \n"
45
+             "subge   %0,  %5,  %0           \n"
46
+             "movge   %2,  #1                \n"
47
+             "movlt   %2,  #0                \n"
48
+             : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit),
49
+               "+&r"(c->bits), "+&r"(c->buffer)
50
+             : "r"(high), "r"(pr), "r"(c->end - 1),
51
+               "0"(shift), "1"(code_word)
52
+             : "cc");
52 53
 
53 54
     return bit;
54 55
 }
... ...
@@ -62,19 +63,20 @@ static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr)
62 62
     unsigned low;
63 63
     unsigned tmp;
64 64
 
65
-    __asm__ volatile ("adds    %3,  %3,  %0           \n"
66
-                      "cmpcs   %7,  %4                \n"
67
-                      "ldrcsh  %2,  [%4], #2          \n"
68
-                      "rsb     %0,  %6,  #256         \n"
69
-                      "smlabb  %0,  %5,  %6,  %0      \n"
70
-                      "rev16cs %2,  %2                \n"
71
-                      "orrcs   %1,  %1,  %2,  lsl %3  \n"
72
-                      "subcs   %3,  %3,  #16          \n"
73
-                      "lsr     %0,  %0,  #8           \n"
74
-                      "lsl     %2,  %0,  #16          \n"
75
-                      : "=&r"(low), "+&r"(code_word), "=&r"(tmp),
76
-                        "+&r"(c->bits), "+&r"(c->buffer)
77
-                      : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift));
65
+    __asm__ ("adds    %3,  %3,  %0           \n"
66
+             "cmpcs   %7,  %4                \n"
67
+             "ldrcsh  %2,  [%4], #2          \n"
68
+             "rsb     %0,  %6,  #256         \n"
69
+             "smlabb  %0,  %5,  %6,  %0      \n"
70
+             "rev16cs %2,  %2                \n"
71
+             "orrcs   %1,  %1,  %2,  lsl %3  \n"
72
+             "subcs   %3,  %3,  #16          \n"
73
+             "lsr     %0,  %0,  #8           \n"
74
+             "lsl     %2,  %0,  #16          \n"
75
+             : "=&r"(low), "+&r"(code_word), "=&r"(tmp),
76
+               "+&r"(c->bits), "+&r"(c->buffer)
77
+             : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift)
78
+             : "cc");
78 79
 
79 80
     if (code_word >= tmp) {
80 81
         c->high      = high - low;
... ...
@@ -27,6 +27,11 @@ SECTION_RODATA
27 27
 ; 16777216.0f - used in ff_float_to_fixed24()
28 28
 pf_1_24: times 4 dd 0x4B800000
29 29
 
30
+; used in ff_ac3_compute_mantissa_size()
31
+cextern ac3_bap_bits
32
+pw_bap_mul1: dw 21846, 21846, 0, 32768, 21846, 21846, 0, 32768
33
+pw_bap_mul2: dw 5, 7, 0, 7, 5, 7, 0, 7
34
+
30 35
 SECTION .text
31 36
 
32 37
 ;-----------------------------------------------------------------------------
... ...
@@ -293,3 +298,51 @@ cglobal float_to_fixed24_sse2, 3,3,9, dst, src, len
293 293
 %endif
294 294
     ja .loop
295 295
     REP_RET
296
+
297
+;------------------------------------------------------------------------------
298
+; int ff_ac3_compute_mantissa_size(uint16_t mant_cnt[6][16])
299
+;------------------------------------------------------------------------------
300
+
301
+%macro PHADDD4 2 ; xmm src, xmm tmp
302
+    movhlps  %2, %1
303
+    paddd    %1, %2
304
+    pshufd   %2, %1, 0x1
305
+    paddd    %1, %2
306
+%endmacro
307
+
308
+INIT_XMM
309
+cglobal ac3_compute_mantissa_size_sse2, 1,2,4, mant_cnt, sum
310
+    movdqa      m0, [mant_cntq      ]
311
+    movdqa      m1, [mant_cntq+ 1*16]
312
+    paddw       m0, [mant_cntq+ 2*16]
313
+    paddw       m1, [mant_cntq+ 3*16]
314
+    paddw       m0, [mant_cntq+ 4*16]
315
+    paddw       m1, [mant_cntq+ 5*16]
316
+    paddw       m0, [mant_cntq+ 6*16]
317
+    paddw       m1, [mant_cntq+ 7*16]
318
+    paddw       m0, [mant_cntq+ 8*16]
319
+    paddw       m1, [mant_cntq+ 9*16]
320
+    paddw       m0, [mant_cntq+10*16]
321
+    paddw       m1, [mant_cntq+11*16]
322
+    pmaddwd     m0, [ac3_bap_bits   ]
323
+    pmaddwd     m1, [ac3_bap_bits+16]
324
+    paddd       m0, m1
325
+    PHADDD4     m0, m1
326
+    movd      sumd, m0
327
+    movdqa      m3, [pw_bap_mul1]
328
+    movhpd      m0, [mant_cntq     +2]
329
+    movlpd      m0, [mant_cntq+1*32+2]
330
+    movhpd      m1, [mant_cntq+2*32+2]
331
+    movlpd      m1, [mant_cntq+3*32+2]
332
+    movhpd      m2, [mant_cntq+4*32+2]
333
+    movlpd      m2, [mant_cntq+5*32+2]
334
+    pmulhuw     m0, m3
335
+    pmulhuw     m1, m3
336
+    pmulhuw     m2, m3
337
+    paddusw     m0, m1
338
+    paddusw     m0, m2
339
+    pmaddwd     m0, [pw_bap_mul2]
340
+    PHADDD4     m0, m1
341
+    movd       eax, m0
342
+    add        eax, sumd
343
+    RET
... ...
@@ -42,6 +42,8 @@ extern void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned i
42 42
 extern void ff_float_to_fixed24_sse  (int32_t *dst, const float *src, unsigned int len);
43 43
 extern void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len);
44 44
 
45
+extern int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]);
46
+
45 47
 av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
46 48
 {
47 49
     int mm_flags = av_get_cpu_flags();
... ...
@@ -69,6 +71,7 @@ av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
69 69
         c->ac3_exponent_min = ff_ac3_exponent_min_sse2;
70 70
         c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2;
71 71
         c->float_to_fixed24 = ff_float_to_fixed24_sse2;
72
+        c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2;
72 73
         if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
73 74
             c->ac3_lshift_int16 = ff_ac3_lshift_int16_sse2;
74 75
             c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2;
... ...
@@ -29,6 +29,7 @@
29 29
 #include <stdlib.h>
30 30
 #include <string.h>
31 31
 #include "libavutil/parseutils.h"
32
+#include "libavutil/pixdesc.h"
32 33
 
33 34
 #include <dc1394/dc1394.h>
34 35
 
... ...
@@ -42,6 +43,7 @@ typedef struct dc1394_data {
42 42
     int current_frame;
43 43
     int fps;
44 44
     char *video_size;       /**< String describing video size, set by a private option. */
45
+    char *pixel_format;     /**< Set by a private option. */
45 46
 
46 47
     AVPacket packet;
47 48
 } dc1394_data;
... ...
@@ -82,6 +84,7 @@ struct dc1394_frame_rate {
82 82
 #define DEC AV_OPT_FLAG_DECODING_PARAM
83 83
 static const AVOption options[] = {
84 84
     { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC },
85
+    { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "uyvy422"}, 0, 0, DEC },
85 86
     { NULL },
86 87
 };
87 88
 
... ...
@@ -134,6 +137,14 @@ static int dc1394_read_header(AVFormatContext *c, AVFormatParameters * ap)
134 134
         goto out_camera;
135 135
     }
136 136
 
137
+    if (dc1394->pixel_format) {
138
+        if ((ap->pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == PIX_FMT_NONE) {
139
+            av_log(c, AV_LOG_ERROR, "No such pixel format: %s.\n", dc1394->pixel_format);
140
+            ret = AVERROR(EINVAL);
141
+            goto out;
142
+        }
143
+    }
144
+
137 145
     if (dc1394->video_size) {
138 146
         if ((ret = av_parse_video_size(&ap->width, &ap->height, dc1394->video_size)) < 0) {
139 147
             av_log(c, AV_LOG_ERROR, "Couldn't parse video size.\n");
... ...
@@ -303,6 +314,8 @@ out_camera:
303 303
     dc1394_video_set_transmission(dc1394->camera, DC1394_OFF);
304 304
     dc1394_camera_free (dc1394->camera);
305 305
 out:
306
+    av_freep(&dc1394->video_size);
307
+    av_freep(&dc1394->pixel_format);
306 308
     dc1394_free(dc1394->d);
307 309
     return ret;
308 310
 }
... ...
@@ -50,6 +50,7 @@
50 50
 #include "libavutil/opt.h"
51 51
 #include "avdevice.h"
52 52
 #include "libavutil/parseutils.h"
53
+#include "libavutil/pixdesc.h"
53 54
 
54 55
 static const int desired_video_buffers = 256;
55 56
 
... ...
@@ -74,6 +75,7 @@ struct video_data {
74 74
     char *standard;
75 75
     int channel;
76 76
     char *video_size; /**< String describing video size, set by a private option. */
77
+    char *pixel_format; /**< Set by a private option. */
77 78
 };
78 79
 
79 80
 struct buff_data {
... ...
@@ -534,12 +536,12 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
534 534
 }
535 535
 
536 536
 static uint32_t device_try_init(AVFormatContext *s1,
537
-                                const AVFormatParameters *ap,
537
+                                enum PixelFormat pix_fmt,
538 538
                                 int *width,
539 539
                                 int *height,
540 540
                                 enum CodecID *codec_id)
541 541
 {
542
-    uint32_t desired_format = fmt_ff2v4l(ap->pix_fmt, s1->video_codec_id);
542
+    uint32_t desired_format = fmt_ff2v4l(pix_fmt, s1->video_codec_id);
543 543
 
544 544
     if (desired_format == 0 ||
545 545
         device_init(s1, width, height, desired_format) < 0) {
... ...
@@ -572,6 +574,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
572 572
     int res = 0;
573 573
     uint32_t desired_format, capabilities;
574 574
     enum CodecID codec_id;
575
+    enum PixelFormat pix_fmt = PIX_FMT_NONE;
575 576
 
576 577
     st = av_new_stream(s1, 0);
577 578
     if (!st) {
... ...
@@ -584,11 +587,18 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
584 584
         av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n");
585 585
         goto out;
586 586
     }
587
+    if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == PIX_FMT_NONE) {
588
+        av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format);
589
+        res = AVERROR(EINVAL);
590
+        goto out;
591
+    }
587 592
 #if FF_API_FORMAT_PARAMETERS
588 593
     if (ap->width > 0)
589 594
         s->width  = ap->width;
590 595
     if (ap->height > 0)
591 596
         s->height = ap->height;
597
+    if (ap->pix_fmt)
598
+        pix_fmt = ap->pix_fmt;
592 599
 #endif
593 600
 
594 601
     capabilities = 0;
... ...
@@ -614,7 +624,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
614 614
         av_log(s1, AV_LOG_VERBOSE, "Setting frame size to %dx%d\n", s->width, s->height);
615 615
     }
616 616
 
617
-    desired_format = device_try_init(s1, ap, &s->width, &s->height, &codec_id);
617
+    desired_format = device_try_init(s1, pix_fmt, &s->width, &s->height, &codec_id);
618 618
     if (desired_format == 0) {
619 619
         av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for "
620 620
                "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, ap->pix_fmt);
... ...
@@ -659,6 +669,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)
659 659
 
660 660
 out:
661 661
     av_freep(&s->video_size);
662
+    av_freep(&s->pixel_format);
662 663
     return res;
663 664
 }
664 665
 
... ...
@@ -709,6 +720,7 @@ static const AVOption options[] = {
709 709
     { "standard", "", OFFSET(standard), FF_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
710 710
     { "channel",  "", OFFSET(channel),  FF_OPT_TYPE_INT,    {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
711 711
     { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
712
+    { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
712 713
     { NULL },
713 714
 };
714 715
 
... ...
@@ -233,9 +233,7 @@ typedef struct AVFormatParameters {
233 233
     attribute_deprecated int channels;
234 234
     attribute_deprecated int width;
235 235
     attribute_deprecated int height;
236
-#endif
237
-    enum PixelFormat pix_fmt;
238
-#if FF_API_FORMAT_PARAMETERS
236
+    attribute_deprecated enum PixelFormat pix_fmt;
239 237
     attribute_deprecated int channel; /**< Used to select DV channel. */
240 238
     attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */
241 239
     attribute_deprecated unsigned int mpeg2ts_raw:1;  /**< deprecated, use mpegtsraw demuxer */
... ...
@@ -223,6 +223,24 @@ typedef enum {
223 223
   MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP = 3,
224 224
 } MatroskaTrackEncodingCompAlgo;
225 225
 
226
+typedef enum {
227
+  MATROSKA_VIDEO_STEREOMODE_TYPE_MONO               = 0,
228
+  MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT         = 1,
229
+  MATROSKA_VIDEO_STEREOMODE_TYPE_BOTTOM_TOP         = 2,
230
+  MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM         = 3,
231
+  MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_RL    = 4,
232
+  MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR    = 5,
233
+  MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_RL = 6,
234
+  MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR = 7,
235
+  MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_RL = 8,
236
+  MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR = 9,
237
+  MATROSKA_VIDEO_STEREOMODE_TYPE_ANAGLYPH_CYAN_RED  = 10,
238
+  MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT         = 11,
239
+  MATROSKA_VIDEO_STEREOMODE_TYPE_ANAGLYPH_GREEN_MAG = 12,
240
+  MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR = 13,
241
+  MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL = 14,
242
+} MatroskaVideoStereoModeType;
243
+
226 244
 /*
227 245
  * Matroska Codec IDs, strings
228 246
  */
... ...
@@ -25,6 +25,7 @@
25 25
 #include "rawdec.h"
26 26
 #include "libavutil/opt.h"
27 27
 #include "libavutil/parseutils.h"
28
+#include "libavutil/pixdesc.h"
28 29
 
29 30
 /* raw input */
30 31
 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
... ...
@@ -70,30 +71,37 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
70 70
         case AVMEDIA_TYPE_VIDEO: {
71 71
             FFRawVideoDemuxerContext *s1 = s->priv_data;
72 72
             int width = 0, height = 0, ret;
73
+            enum PixelFormat pix_fmt;
74
+
73 75
             if(ap->time_base.num)
74 76
                 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
75 77
             else
76 78
                 av_set_pts_info(st, 64, 1, 25);
77
-            if (s1->video_size) {
78
-                ret = av_parse_video_size(&width, &height, s1->video_size);
79
-                av_freep(&s1->video_size);
80
-                if (ret < 0) {
81
-                    av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
82
-                    return ret;
83
-                }
79
+            if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) {
80
+                av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
81
+                goto fail;
82
+            }
83
+            if ((pix_fmt = av_get_pix_fmt(s1->pixel_format)) == PIX_FMT_NONE) {
84
+                av_log(s, AV_LOG_ERROR, "No such pixel format: %s.\n", s1->pixel_format);
85
+                ret = AVERROR(EINVAL);
86
+                goto fail;
84 87
             }
85 88
 #if FF_API_FORMAT_PARAMETERS
86 89
             if (ap->width > 0)
87 90
                 width = ap->width;
88 91
             if (ap->height > 0)
89 92
                 height = ap->height;
93
+            if (ap->pix_fmt)
94
+                pix_fmt = ap->pix_fmt;
90 95
 #endif
91 96
             st->codec->width  = width;
92 97
             st->codec->height = height;
93
-            st->codec->pix_fmt = ap->pix_fmt;
94
-            if(st->codec->pix_fmt == PIX_FMT_NONE)
95
-                st->codec->pix_fmt= PIX_FMT_YUV420P;
98
+            st->codec->pix_fmt = pix_fmt;
96 99
             break;
100
+fail:
101
+            av_freep(&s1->video_size);
102
+            av_freep(&s1->pixel_format);
103
+            return ret;
97 104
             }
98 105
         default:
99 106
             return -1;
... ...
@@ -188,6 +196,7 @@ const AVClass ff_rawaudio_demuxer_class = {
188 188
 #define DEC AV_OPT_FLAG_DECODING_PARAM
189 189
 static const AVOption video_options[] = {
190 190
     { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
191
+    { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
191 192
     { NULL },
192 193
 };
193 194
 #undef OFFSET
... ...
@@ -34,6 +34,7 @@ typedef struct RawAudioDemuxerContext {
34 34
 typedef struct FFRawVideoDemuxerContext {
35 35
     const AVClass *class;     /**< Class for private options. */
36 36
     char *video_size;         /**< String describing video size, set by a private option. */
37
+    char *pixel_format;       /**< Set by a private option. */
37 38
 } FFRawVideoDemuxerContext;
38 39
 
39 40
 extern const AVClass ff_rawaudio_demuxer_class;
... ...
@@ -33,12 +33,12 @@
33 33
 #define FASTDIV FASTDIV
34 34
 static av_always_inline av_const int FASTDIV(int a, int b)
35 35
 {
36
-    int r, t;
37
-    __asm__ ("cmp     %3, #2               \n\t"
38
-             "ldr     %1, [%4, %3, lsl #2] \n\t"
39
-             "lsrle   %0, %2, #1           \n\t"
40
-             "smmulgt %0, %1, %2           \n\t"
41
-             : "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse));
36
+    int r;
37
+    __asm__ ("cmp     %2, #2               \n\t"
38
+             "ldr     %0, [%3, %2, lsl #2] \n\t"
39
+             "lsrle   %0, %1, #1           \n\t"
40
+             "smmulgt %0, %0, %1           \n\t"
41
+             : "=&r"(r) : "r"(a), "r"(b), "r"(ff_inverse) : "cc");
42 42
     return r;
43 43
 }
44 44
 
... ...
@@ -24,6 +24,7 @@
24 24
 
25 25
 #include "pixfmt.h"
26 26
 #include <inttypes.h>
27
+#include "pixfmt.h"
27 28
 
28 29
 typedef struct AVComponentDescriptor{
29 30
     uint16_t plane        :2;            ///< which of the 4 planes contains the component
... ...
@@ -466,8 +466,8 @@ DEFUN_END(yuv2rgb24_line)
466 466
 #define ARG_srcStride   40
467 467
 
468 468
 DEFUN(uyvytoyv12, mL3,  (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
469
-                         long width, long height,
470
-                         long lumStride, long chromStride, long srcStride)):
469
+                         int width, int height,
470
+                         int lumStride, int chromStride, int srcStride)):
471 471
         link 0;
472 472
         [--sp] = (r7:4,p5:4);
473 473
 
... ...
@@ -539,8 +539,8 @@ DEFUN(uyvytoyv12, mL3,  (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8
539 539
 DEFUN_END(uyvytoyv12)
540 540
 
541 541
 DEFUN(yuyvtoyv12, mL3,  (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
542
-                         long width, long height,
543
-                         long lumStride, long chromStride, long srcStride)):
542
+                         int width, int height,
543
+                         int lumStride, int chromStride, int srcStride)):
544 544
         link 0;
545 545
         [--sp] = (r7:4,p5:4);
546 546
 
... ...
@@ -38,12 +38,12 @@
38 38
 #endif
39 39
 
40 40
 int ff_bfin_uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
41
-                       long width, long height,
42
-                       long lumStride, long chromStride, long srcStride) L1CODE;
41
+                       int width, int height,
42
+                       int lumStride, int chromStride, int srcStride) L1CODE;
43 43
 
44 44
 int ff_bfin_yuyvtoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
45
-                       long width, long height,
46
-                       long lumStride, long chromStride, long srcStride) L1CODE;
45
+                       int width, int height,
46
+                       int lumStride, int chromStride, int srcStride) L1CODE;
47 47
 
48 48
 static int uyvytoyv12_unscaled(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
49 49
                                int srcSliceH, uint8_t* dst[], int dstStride[])
... ...
@@ -52,7 +52,7 @@ int main(int argc, char **argv)
52 52
             int src_bpp;
53 53
             int dst_bpp;
54 54
             const char *name;
55
-            void (*func)(const uint8_t *src, uint8_t *dst, long src_size);
55
+            void (*func)(const uint8_t *src, uint8_t *dst, int src_size);
56 56
         } func_info[] = {
57 57
             FUNC(2, 2, rgb15to16),
58 58
             FUNC(2, 3, rgb15to24),
... ...
@@ -29,13 +29,13 @@ altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW)
29 29
     register int i;
30 30
     vector unsigned int altivec_vectorShiftInt19 =
31 31
         vec_add(vec_splat_u32(10), vec_splat_u32(9));
32
-    if ((unsigned long)dest % 16) {
32
+    if ((unsigned int)dest % 16) {
33 33
         /* badly aligned store, we force store alignment */
34 34
         /* and will handle load misalignment on val w/ vec_perm */
35 35
         vector unsigned char perm1;
36 36
         vector signed int v1;
37 37
         for (i = 0 ; (i < dstW) &&
38
-            (((unsigned long)dest + i) % 16) ; i++) {
38
+            (((unsigned int)dest + i) % 16) ; i++) {
39 39
                 int t = val[i] >> 19;
40 40
                 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t);
41 41
         }
... ...
@@ -30,7 +30,7 @@ static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
30 30
                                     const int16_t **chrVSrc, int chrFilterSize,
31 31
                                     const int16_t **alpSrc,
32 32
                                     uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
33
-                                    uint8_t *aDest, long dstW, long chrDstW)
33
+                                    uint8_t *aDest, int dstW, int chrDstW)
34 34
 {
35 35
     yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize,
36 36
                           chrFilter, chrUSrc, chrVSrc, chrFilterSize,
... ...
@@ -45,7 +45,7 @@ static inline void RENAME(yuv2packedX)(SwsContext *c, const int16_t *lumFilter,
45 45
                                        const int16_t *chrFilter, const int16_t **chrUSrc,
46 46
                                        const int16_t **chrVSrc, int chrFilterSize,
47 47
                                        const int16_t **alpSrc, uint8_t *dest,
48
-                                       long dstW, long dstY)
48
+                                       int dstW, int dstY)
49 49
 {
50 50
     /* The following list of supported dstFormat values should
51 51
        match what's found in the body of ff_yuv2packedX_altivec() */
... ...
@@ -793,7 +793,7 @@ ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter,
793 793
 
794 794
     vector signed short   RND = vec_splat_s16(1<<3);
795 795
     vector unsigned short SCL = vec_splat_u16(4);
796
-    DECLARE_ALIGNED(16, unsigned long, scratch)[16];
796
+    DECLARE_ALIGNED(16, unsigned int, scratch)[16];
797 797
 
798 798
     vector signed short *YCoeffs, *CCoeffs;
799 799
 
... ...
@@ -29,70 +29,70 @@
29 29
 #include "swscale.h"
30 30
 #include "swscale_internal.h"
31 31
 
32
-void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
33
-void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
34
-void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
35
-void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
36
-void (*rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size);
37
-void (*rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size);
38
-void (*rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size);
39
-void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
40
-void (*rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size);
41
-void (*rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size);
42
-void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
43
-void (*rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size);
44
-void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
45
-void (*rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size);
46
-void (*rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size);
47
-void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size);
48
-void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
49
-void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
32
+void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size);
33
+void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
34
+void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
35
+void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
36
+void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size);
37
+void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size);
38
+void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size);
39
+void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
40
+void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size);
41
+void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size);
42
+void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
43
+void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size);
44
+void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
45
+void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size);
46
+void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size);
47
+void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size);
48
+void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
49
+void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
50 50
 
51 51
 void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
52
-                   long width, long height,
53
-                   long lumStride, long chromStride, long dstStride);
52
+                   int width, int height,
53
+                   int lumStride, int chromStride, int dstStride);
54 54
 void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
55
-                   long width, long height,
56
-                   long lumStride, long chromStride, long dstStride);
55
+                   int width, int height,
56
+                   int lumStride, int chromStride, int dstStride);
57 57
 void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
58
-                      long width, long height,
59
-                      long lumStride, long chromStride, long dstStride);
58
+                      int width, int height,
59
+                      int lumStride, int chromStride, int dstStride);
60 60
 void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
61
-                      long width, long height,
62
-                      long lumStride, long chromStride, long dstStride);
61
+                      int width, int height,
62
+                      int lumStride, int chromStride, int dstStride);
63 63
 void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
64
-                   long width, long height,
65
-                   long lumStride, long chromStride, long srcStride);
64
+                   int width, int height,
65
+                   int lumStride, int chromStride, int srcStride);
66 66
 void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
67
-                    long width, long height,
68
-                    long lumStride, long chromStride, long srcStride);
69
-void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height,
70
-                 long srcStride, long dstStride);
67
+                    int width, int height,
68
+                    int lumStride, int chromStride, int srcStride);
69
+void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height,
70
+                 int srcStride, int dstStride);
71 71
 void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst,
72
-                        long width, long height, long src1Stride,
73
-                        long src2Stride, long dstStride);
72
+                        int width, int height, int src1Stride,
73
+                        int src2Stride, int dstStride);
74 74
 void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
75 75
                     uint8_t *dst1, uint8_t *dst2,
76
-                    long width, long height,
77
-                    long srcStride1, long srcStride2,
78
-                    long dstStride1, long dstStride2);
76
+                    int width, int height,
77
+                    int srcStride1, int srcStride2,
78
+                    int dstStride1, int dstStride2);
79 79
 void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
80 80
                      uint8_t *dst,
81
-                     long width, long height,
82
-                     long srcStride1, long srcStride2,
83
-                     long srcStride3, long dstStride);
81
+                     int width, int height,
82
+                     int srcStride1, int srcStride2,
83
+                     int srcStride3, int dstStride);
84 84
 void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
85
-                     long width, long height,
86
-                     long lumStride, long chromStride, long srcStride);
85
+                     int width, int height,
86
+                     int lumStride, int chromStride, int srcStride);
87 87
 void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
88
-                     long width, long height,
89
-                     long lumStride, long chromStride, long srcStride);
88
+                     int width, int height,
89
+                     int lumStride, int chromStride, int srcStride);
90 90
 void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
91
-                     long width, long height,
92
-                     long lumStride, long chromStride, long srcStride);
91
+                     int width, int height,
92
+                     int lumStride, int chromStride, int srcStride);
93 93
 void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
94
-                     long width, long height,
95
-                     long lumStride, long chromStride, long srcStride);
94
+                     int width, int height,
95
+                     int lumStride, int chromStride, int srcStride);
96 96
 
97 97
 #define RGB2YUV_SHIFT 8
98 98
 #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
... ...
@@ -151,10 +151,10 @@ void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const ui
151 151
 }
152 152
 #endif
153 153
 
154
-void rgb32to24(const uint8_t *src, uint8_t *dst, long src_size)
154
+void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
155 155
 {
156
-    long i;
157
-    long num_pixels = src_size >> 2;
156
+    int i;
157
+    int num_pixels = src_size >> 2;
158 158
     for (i=0; i<num_pixels; i++) {
159 159
 #if HAVE_BIGENDIAN
160 160
         /* RGB32 (= A,B,G,R) -> BGR24 (= B,G,R) */
... ...
@@ -169,9 +169,9 @@ void rgb32to24(const uint8_t *src, uint8_t *dst, long src_size)
169 169
     }
170 170
 }
171 171
 
172
-void rgb24to32(const uint8_t *src, uint8_t *dst, long src_size)
172
+void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
173 173
 {
174
-    long i;
174
+    int i;
175 175
     for (i=0; 3*i<src_size; i++) {
176 176
 #if HAVE_BIGENDIAN
177 177
         /* RGB24 (= R,G,B) -> BGR32 (= A,R,G,B) */
... ...
@@ -188,7 +188,7 @@ void rgb24to32(const uint8_t *src, uint8_t *dst, long src_size)
188 188
     }
189 189
 }
190 190
 
191
-void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
191
+void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
192 192
 {
193 193
     const uint16_t *end;
194 194
     uint8_t *d = dst;
... ...
@@ -211,7 +211,7 @@ void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
211 211
     }
212 212
 }
213 213
 
214
-void rgb16to24(const uint8_t *src, uint8_t *dst, long src_size)
214
+void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
215 215
 {
216 216
     const uint16_t *end;
217 217
     uint8_t *d = dst;
... ...
@@ -226,10 +226,10 @@ void rgb16to24(const uint8_t *src, uint8_t *dst, long src_size)
226 226
     }
227 227
 }
228 228
 
229
-void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
229
+void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
230 230
 {
231
-    long i;
232
-    long num_pixels = src_size >> 1;
231
+    int i;
232
+    int num_pixels = src_size >> 1;
233 233
 
234 234
     for (i=0; i<num_pixels; i++) {
235 235
         unsigned rgb = ((const uint16_t*)src)[i];
... ...
@@ -237,10 +237,10 @@ void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
237 237
     }
238 238
 }
239 239
 
240
-void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
240
+void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
241 241
 {
242
-    long i;
243
-    long num_pixels = src_size >> 1;
242
+    int i;
243
+    int num_pixels = src_size >> 1;
244 244
 
245 245
     for (i=0; i<num_pixels; i++) {
246 246
         unsigned rgb = ((const uint16_t*)src)[i];
... ...
@@ -248,7 +248,7 @@ void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
248 248
     }
249 249
 }
250 250
 
251
-void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
251
+void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
252 252
 {
253 253
     const uint16_t *end;
254 254
     uint8_t *d = dst;
... ...
@@ -271,7 +271,7 @@ void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
271 271
     }
272 272
 }
273 273
 
274
-void rgb15to24(const uint8_t *src, uint8_t *dst, long src_size)
274
+void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
275 275
 {
276 276
     const uint16_t *end;
277 277
     uint8_t *d = dst;
... ...
@@ -286,10 +286,10 @@ void rgb15to24(const uint8_t *src, uint8_t *dst, long src_size)
286 286
     }
287 287
 }
288 288
 
289
-void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
289
+void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
290 290
 {
291
-    long i;
292
-    long num_pixels = src_size >> 1;
291
+    int i;
292
+    int num_pixels = src_size >> 1;
293 293
 
294 294
     for (i=0; i<num_pixels; i++) {
295 295
         unsigned rgb = ((const uint16_t*)src)[i];
... ...
@@ -297,10 +297,10 @@ void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
297 297
     }
298 298
 }
299 299
 
300
-void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
300
+void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
301 301
 {
302
-    long i;
303
-    long num_pixels = src_size >> 1;
302
+    int i;
303
+    int num_pixels = src_size >> 1;
304 304
 
305 305
     for (i=0; i<num_pixels; i++) {
306 306
         unsigned br;
... ...
@@ -310,10 +310,10 @@ void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
310 310
     }
311 311
 }
312 312
 
313
-void bgr8torgb8(const uint8_t *src, uint8_t *dst, long src_size)
313
+void bgr8torgb8(const uint8_t *src, uint8_t *dst, int src_size)
314 314
 {
315
-    long i;
316
-    long num_pixels = src_size;
315
+    int i;
316
+    int num_pixels = src_size;
317 317
     for (i=0; i<num_pixels; i++) {
318 318
         unsigned b,g,r;
319 319
         register uint8_t rgb;
... ...
@@ -326,9 +326,9 @@ void bgr8torgb8(const uint8_t *src, uint8_t *dst, long src_size)
326 326
 }
327 327
 
328 328
 #define DEFINE_SHUFFLE_BYTES(a, b, c, d)                                \
329
-void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, long src_size) \
329
+void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, int src_size) \
330 330
 {                                                                       \
331
-    long i;                                                             \
331
+    int i;                                                             \
332 332
                                                                         \
333 333
     for (i = 0; i < src_size; i+=4) {                                   \
334 334
         dst[i + 0] = src[i + a];                                        \
... ...
@@ -32,41 +32,41 @@
32 32
 #include "libavutil/avutil.h"
33 33
 
34 34
 /* A full collection of RGB to RGB(BGR) converters */
35
-extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
36
-extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
37
-extern void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
38
-extern void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
39
-extern void (*rgb32to16)   (const uint8_t *src, uint8_t *dst, long src_size);
40
-extern void (*rgb32to15)   (const uint8_t *src, uint8_t *dst, long src_size);
41
-extern void (*rgb15to16)   (const uint8_t *src, uint8_t *dst, long src_size);
42
-extern void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
43
-extern void (*rgb15to32)   (const uint8_t *src, uint8_t *dst, long src_size);
44
-extern void (*rgb16to15)   (const uint8_t *src, uint8_t *dst, long src_size);
45
-extern void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
46
-extern void (*rgb16to32)   (const uint8_t *src, uint8_t *dst, long src_size);
47
-extern void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
48
-extern void (*rgb24to16)   (const uint8_t *src, uint8_t *dst, long src_size);
49
-extern void (*rgb24to15)   (const uint8_t *src, uint8_t *dst, long src_size);
50
-extern void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size);
51
-extern void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
52
-extern void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
53
-
54
-void rgb24to32   (const uint8_t *src, uint8_t *dst, long src_size);
55
-void rgb32to24   (const uint8_t *src, uint8_t *dst, long src_size);
56
-void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size);
57
-void rgb16to24   (const uint8_t *src, uint8_t *dst, long src_size);
58
-void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size);
59
-void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size);
60
-void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size);
61
-void rgb15to24   (const uint8_t *src, uint8_t *dst, long src_size);
62
-void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size);
63
-void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size);
64
-void bgr8torgb8  (const uint8_t *src, uint8_t *dst, long src_size);
65
-
66
-void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, long src_size);
67
-void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, long src_size);
68
-void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size);
69
-void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size);
35
+extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size);
36
+extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
37
+extern void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
38
+extern void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
39
+extern void (*rgb32to16)   (const uint8_t *src, uint8_t *dst, int src_size);
40
+extern void (*rgb32to15)   (const uint8_t *src, uint8_t *dst, int src_size);
41
+extern void (*rgb15to16)   (const uint8_t *src, uint8_t *dst, int src_size);
42
+extern void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
43
+extern void (*rgb15to32)   (const uint8_t *src, uint8_t *dst, int src_size);
44
+extern void (*rgb16to15)   (const uint8_t *src, uint8_t *dst, int src_size);
45
+extern void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
46
+extern void (*rgb16to32)   (const uint8_t *src, uint8_t *dst, int src_size);
47
+extern void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
48
+extern void (*rgb24to16)   (const uint8_t *src, uint8_t *dst, int src_size);
49
+extern void (*rgb24to15)   (const uint8_t *src, uint8_t *dst, int src_size);
50
+extern void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size);
51
+extern void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
52
+extern void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
53
+
54
+void rgb24to32   (const uint8_t *src, uint8_t *dst, int src_size);
55
+void rgb32to24   (const uint8_t *src, uint8_t *dst, int src_size);
56
+void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size);
57
+void rgb16to24   (const uint8_t *src, uint8_t *dst, int src_size);
58
+void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size);
59
+void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size);
60
+void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size);
61
+void rgb15to24   (const uint8_t *src, uint8_t *dst, int src_size);
62
+void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size);
63
+void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size);
64
+void bgr8torgb8  (const uint8_t *src, uint8_t *dst, int src_size);
65
+
66
+void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, int src_size);
67
+void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, int src_size);
68
+void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, int src_size);
69
+void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, int src_size);
70 70
 
71 71
 #if LIBSWSCALE_VERSION_MAJOR < 1
72 72
 /* deprecated, use the public versions in swscale.h */
... ...
@@ -80,46 +80,46 @@ attribute_deprecated void palette8tobgr16(const uint8_t *src, uint8_t *dst, long
80 80
 
81 81
 
82 82
 void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
83
-                   uint8_t *vdst, long width, long height, long lumStride,
84
-                   long chromStride, long srcStride);
83
+                   uint8_t *vdst, int width, int height, int lumStride,
84
+                   int chromStride, int srcStride);
85 85
 
86 86
 /**
87 87
  * Height should be a multiple of 2 and width should be a multiple of 16.
88 88
  * (If this is a problem for anyone then tell me, and I will fix it.)
89 89
  */
90 90
 extern void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
91
-                          long width, long height,
92
-                          long lumStride, long chromStride, long dstStride);
91
+                          int width, int height,
92
+                          int lumStride, int chromStride, int dstStride);
93 93
 
94 94
 /**
95 95
  * Width should be a multiple of 16.
96 96
  */
97 97
 extern void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
98
-                             long width, long height,
99
-                             long lumStride, long chromStride, long dstStride);
98
+                             int width, int height,
99
+                             int lumStride, int chromStride, int dstStride);
100 100
 
101 101
 /**
102 102
  * Height should be a multiple of 2 and width should be a multiple of 16.
103 103
  * (If this is a problem for anyone then tell me, and I will fix it.)
104 104
  */
105 105
 extern void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
106
-                          long width, long height,
107
-                          long lumStride, long chromStride, long srcStride);
106
+                          int width, int height,
107
+                          int lumStride, int chromStride, int srcStride);
108 108
 
109 109
 /**
110 110
  * Height should be a multiple of 2 and width should be a multiple of 16.
111 111
  * (If this is a problem for anyone then tell me, and I will fix it.)
112 112
  */
113 113
 extern void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
114
-                          long width, long height,
115
-                          long lumStride, long chromStride, long dstStride);
114
+                          int width, int height,
115
+                          int lumStride, int chromStride, int dstStride);
116 116
 
117 117
 /**
118 118
  * Width should be a multiple of 16.
119 119
  */
120 120
 extern void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
121
-                             long width, long height,
122
-                             long lumStride, long chromStride, long dstStride);
121
+                             int width, int height,
122
+                             int lumStride, int chromStride, int dstStride);
123 123
 
124 124
 /**
125 125
  * Height should be a multiple of 2 and width should be a multiple of 2.
... ...
@@ -128,40 +128,40 @@ extern void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uin
128 128
  * FIXME: Write high quality version.
129 129
  */
130 130
 extern void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
131
-                           long width, long height,
132
-                           long lumStride, long chromStride, long srcStride);
133
-extern void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height,
134
-                        long srcStride, long dstStride);
131
+                           int width, int height,
132
+                           int lumStride, int chromStride, int srcStride);
133
+extern void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height,
134
+                        int srcStride, int dstStride);
135 135
 
136 136
 extern void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst,
137
-                               long width, long height, long src1Stride,
138
-                               long src2Stride, long dstStride);
137
+                               int width, int height, int src1Stride,
138
+                               int src2Stride, int dstStride);
139 139
 
140 140
 extern void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
141 141
                            uint8_t *dst1, uint8_t *dst2,
142
-                           long width, long height,
143
-                           long srcStride1, long srcStride2,
144
-                           long dstStride1, long dstStride2);
142
+                           int width, int height,
143
+                           int srcStride1, int srcStride2,
144
+                           int dstStride1, int dstStride2);
145 145
 
146 146
 extern void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
147 147
                             uint8_t *dst,
148
-                            long width, long height,
149
-                            long srcStride1, long srcStride2,
150
-                            long srcStride3, long dstStride);
148
+                            int width, int height,
149
+                            int srcStride1, int srcStride2,
150
+                            int srcStride3, int dstStride);
151 151
 
152 152
 
153 153
 extern void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
154
-                            long width, long height,
155
-                            long lumStride, long chromStride, long srcStride);
154
+                            int width, int height,
155
+                            int lumStride, int chromStride, int srcStride);
156 156
 extern void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
157
-                            long width, long height,
158
-                            long lumStride, long chromStride, long srcStride);
157
+                            int width, int height,
158
+                            int lumStride, int chromStride, int srcStride);
159 159
 extern void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
160
-                            long width, long height,
161
-                            long lumStride, long chromStride, long srcStride);
160
+                            int width, int height,
161
+                            int lumStride, int chromStride, int srcStride);
162 162
 extern void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
163
-                            long width, long height,
164
-                            long lumStride, long chromStride, long srcStride);
163
+                            int width, int height,
164
+                            int lumStride, int chromStride, int srcStride);
165 165
 
166 166
 void sws_rgb2rgb_init(void);
167 167
 
... ...
@@ -26,7 +26,7 @@
26 26
 
27 27
 #include <stddef.h>
28 28
 
29
-static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, long src_size)
29
+static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, int src_size)
30 30
 {
31 31
     uint8_t *dest = dst;
32 32
     const uint8_t *s = src;
... ...
@@ -50,7 +50,7 @@ static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, long src_siz
50 50
     }
51 51
 }
52 52
 
53
-static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, long src_size)
53
+static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
54 54
 {
55 55
     uint8_t *dest = dst;
56 56
     const uint8_t *s = src;
... ...
@@ -81,7 +81,7 @@ static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, long src_siz
81 81
  MMX2, 3DNOW optimization by Nick Kurshev
82 82
  32-bit C version, and and&add trick by Michael Niedermayer
83 83
 */
84
-static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, long src_size)
84
+static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, int src_size)
85 85
 {
86 86
     register const uint8_t* s=src;
87 87
     register uint8_t* d=dst;
... ...
@@ -101,7 +101,7 @@ static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, long src_size)
101 101
     }
102 102
 }
103 103
 
104
-static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, long src_size)
104
+static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, int src_size)
105 105
 {
106 106
     register const uint8_t* s=src;
107 107
     register uint8_t* d=dst;
... ...
@@ -122,7 +122,7 @@ static inline void rgb16to15_c(const uint8_t *src, uint8_t *dst, long src_size)
122 122
     }
123 123
 }
124 124
 
125
-static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, long src_size)
125
+static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, int src_size)
126 126
 {
127 127
     const uint8_t *s = src;
128 128
     const uint8_t *end;
... ...
@@ -135,7 +135,7 @@ static inline void rgb32to16_c(const uint8_t *src, uint8_t *dst, long src_size)
135 135
     }
136 136
 }
137 137
 
138
-static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, long src_size)
138
+static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size)
139 139
 {
140 140
     const uint8_t *s = src;
141 141
     const uint8_t *end;
... ...
@@ -147,7 +147,7 @@ static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, long src_siz
147 147
     }
148 148
 }
149 149
 
150
-static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, long src_size)
150
+static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size)
151 151
 {
152 152
     const uint8_t *s = src;
153 153
     const uint8_t *end;
... ...
@@ -159,7 +159,7 @@ static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, long src_size)
159 159
     }
160 160
 }
161 161
 
162
-static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, long src_size)
162
+static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size)
163 163
 {
164 164
     const uint8_t *s = src;
165 165
     const uint8_t *end;
... ...
@@ -171,7 +171,7 @@ static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, long src_siz
171 171
     }
172 172
 }
173 173
 
174
-static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, long src_size)
174
+static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size)
175 175
 {
176 176
     const uint8_t *s = src;
177 177
     const uint8_t *end;
... ...
@@ -185,7 +185,7 @@ static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, long src_siz
185 185
     }
186 186
 }
187 187
 
188
-static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, long src_size)
188
+static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size)
189 189
 {
190 190
     const uint8_t *s = src;
191 191
     const uint8_t *end;
... ...
@@ -199,7 +199,7 @@ static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, long src_size)
199 199
     }
200 200
 }
201 201
 
202
-static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, long src_size)
202
+static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size)
203 203
 {
204 204
     const uint8_t *s = src;
205 205
     const uint8_t *end;
... ...
@@ -213,7 +213,7 @@ static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, long src_siz
213 213
     }
214 214
 }
215 215
 
216
-static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, long src_size)
216
+static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size)
217 217
 {
218 218
     const uint8_t *s = src;
219 219
     const uint8_t *end;
... ...
@@ -248,7 +248,7 @@ static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, long src_size)
248 248
        |
249 249
    original bits
250 250
 */
251
-static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, long src_size)
251
+static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
252 252
 {
253 253
     const uint16_t *end;
254 254
     uint8_t *d = dst;
... ...
@@ -263,7 +263,7 @@ static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, long src_siz
263 263
     }
264 264
 }
265 265
 
266
-static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, long src_size)
266
+static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
267 267
 {
268 268
     const uint16_t *end;
269 269
     uint8_t *d = (uint8_t *)dst;
... ...
@@ -278,7 +278,7 @@ static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, long src_siz
278 278
     }
279 279
 }
280 280
 
281
-static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, long src_size)
281
+static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size)
282 282
 {
283 283
     const uint16_t *end;
284 284
     uint8_t *d = dst;
... ...
@@ -301,7 +301,7 @@ static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, long src_size)
301 301
     }
302 302
 }
303 303
 
304
-static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, long src_size)
304
+static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size)
305 305
 {
306 306
     const uint16_t *end;
307 307
     uint8_t *d = dst;
... ...
@@ -324,7 +324,7 @@ static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, long src_size)
324 324
     }
325 325
 }
326 326
 
327
-static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, long src_size)
327
+static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, int src_size)
328 328
 {
329 329
     int idx = 15 - src_size;
330 330
     const uint8_t *s = src-idx;
... ...
@@ -336,7 +336,7 @@ static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, long s
336 336
     }
337 337
 }
338 338
 
339
-static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, long src_size)
339
+static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
340 340
 {
341 341
     unsigned i;
342 342
     for (i=0; i<src_size; i+=3) {
... ...
@@ -350,11 +350,11 @@ static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, long src_siz
350 350
 
351 351
 static inline void yuvPlanartoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
352 352
                                      const uint8_t *vsrc, uint8_t *dst,
353
-                                     long width, long height,
354
-                                     long lumStride, long chromStride,
355
-                                     long dstStride, long vertLumPerChroma)
353
+                                     int width, int height,
354
+                                     int lumStride, int chromStride,
355
+                                     int dstStride, int vertLumPerChroma)
356 356
 {
357
-    long y;
357
+    int y;
358 358
     const int chromWidth = width >> 1;
359 359
     for (y=0; y<height; y++) {
360 360
 #if HAVE_FAST_64BIT
... ...
@@ -404,9 +404,9 @@ static inline void yuvPlanartoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
404 404
  */
405 405
 static inline void yv12toyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
406 406
                                 const uint8_t *vsrc, uint8_t *dst,
407
-                                long width, long height,
408
-                                long lumStride, long chromStride,
409
-                                long dstStride)
407
+                                int width, int height,
408
+                                int lumStride, int chromStride,
409
+                                int dstStride)
410 410
 {
411 411
     //FIXME interpolate chroma
412 412
     yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
... ...
@@ -415,11 +415,11 @@ static inline void yv12toyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
415 415
 
416 416
 static inline void yuvPlanartouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
417 417
                                      const uint8_t *vsrc, uint8_t *dst,
418
-                                     long width, long height,
419
-                                     long lumStride, long chromStride,
420
-                                     long dstStride, long vertLumPerChroma)
418
+                                     int width, int height,
419
+                                     int lumStride, int chromStride,
420
+                                     int dstStride, int vertLumPerChroma)
421 421
 {
422
-    long y;
422
+    int y;
423 423
     const int chromWidth = width >> 1;
424 424
     for (y=0; y<height; y++) {
425 425
 #if HAVE_FAST_64BIT
... ...
@@ -469,9 +469,9 @@ static inline void yuvPlanartouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
469 469
  */
470 470
 static inline void yv12touyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
471 471
                                 const uint8_t *vsrc, uint8_t *dst,
472
-                                long width, long height,
473
-                                long lumStride, long chromStride,
474
-                                long dstStride)
472
+                                int width, int height,
473
+                                int lumStride, int chromStride,
474
+                                int dstStride)
475 475
 {
476 476
     //FIXME interpolate chroma
477 477
     yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
... ...
@@ -483,9 +483,9 @@ static inline void yv12touyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
483 483
  */
484 484
 static inline void yuv422ptouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
485 485
                                    const uint8_t *vsrc, uint8_t *dst,
486
-                                   long width, long height,
487
-                                   long lumStride, long chromStride,
488
-                                   long dstStride)
486
+                                   int width, int height,
487
+                                   int lumStride, int chromStride,
488
+                                   int dstStride)
489 489
 {
490 490
     yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
491 491
                       chromStride, dstStride, 1);
... ...
@@ -496,9 +496,9 @@ static inline void yuv422ptouyvy_c(const uint8_t *ysrc, const uint8_t *usrc,
496 496
  */
497 497
 static inline void yuv422ptoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
498 498
                                    const uint8_t *vsrc, uint8_t *dst,
499
-                                   long width, long height,
500
-                                   long lumStride, long chromStride,
501
-                                   long dstStride)
499
+                                   int width, int height,
500
+                                   int lumStride, int chromStride,
501
+                                   int dstStride)
502 502
 {
503 503
     yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride,
504 504
                       chromStride, dstStride, 1);
... ...
@@ -510,14 +510,14 @@ static inline void yuv422ptoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc,
510 510
  */
511 511
 static inline void yuy2toyv12_c(const uint8_t *src, uint8_t *ydst,
512 512
                                 uint8_t *udst, uint8_t *vdst,
513
-                                long width, long height,
514
-                                long lumStride, long chromStride,
515
-                                long srcStride)
513
+                                int width, int height,
514
+                                int lumStride, int chromStride,
515
+                                int srcStride)
516 516
 {
517
-    long y;
517
+    int y;
518 518
     const int chromWidth = width >> 1;
519 519
     for (y=0; y<height; y+=2) {
520
-        long i;
520
+        int i;
521 521
         for (i=0; i<chromWidth; i++) {
522 522
             ydst[2*i+0]     = src[4*i+0];
523 523
             udst[i]     = src[4*i+1];
... ...
@@ -538,10 +538,10 @@ static inline void yuy2toyv12_c(const uint8_t *src, uint8_t *ydst,
538 538
     }
539 539
 }
540 540
 
541
-static inline void planar2x_c(const uint8_t *src, uint8_t *dst, long srcWidth,
542
-                              long srcHeight, long srcStride, long dstStride)
541
+static inline void planar2x_c(const uint8_t *src, uint8_t *dst, int srcWidth,
542
+                              int srcHeight, int srcStride, int dstStride)
543 543
 {
544
-    long x,y;
544
+    int x,y;
545 545
 
546 546
     dst[0]= src[0];
547 547
 
... ...
@@ -598,14 +598,14 @@ static inline void planar2x_c(const uint8_t *src, uint8_t *dst, long srcWidth,
598 598
  */
599 599
 static inline void uyvytoyv12_c(const uint8_t *src, uint8_t *ydst,
600 600
                                 uint8_t *udst, uint8_t *vdst,
601
-                                long width, long height,
602
-                                long lumStride, long chromStride,
603
-                                long srcStride)
601
+                                int width, int height,
602
+                                int lumStride, int chromStride,
603
+                                int srcStride)
604 604
 {
605
-    long y;
605
+    int y;
606 606
     const int chromWidth = width >> 1;
607 607
     for (y=0; y<height; y+=2) {
608
-        long i;
608
+        int i;
609 609
         for (i=0; i<chromWidth; i++) {
610 610
             udst[i]     = src[4*i+0];
611 611
             ydst[2*i+0] = src[4*i+1];
... ...
@@ -634,14 +634,14 @@ static inline void uyvytoyv12_c(const uint8_t *src, uint8_t *ydst,
634 634
  * FIXME: Write HQ version.
635 635
  */
636 636
 void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
637
-                   uint8_t *vdst, long width, long height, long lumStride,
638
-                   long chromStride, long srcStride)
637
+                   uint8_t *vdst, int width, int height, int lumStride,
638
+                   int chromStride, int srcStride)
639 639
 {
640
-    long y;
640
+    int y;
641 641
     const int chromWidth = width >> 1;
642 642
     y=0;
643 643
     for (; y<height; y+=2) {
644
-        long i;
644
+        int i;
645 645
         for (i=0; i<chromWidth; i++) {
646 646
             unsigned int b = src[6*i+0];
647 647
             unsigned int g = src[6*i+1];
... ...
@@ -692,14 +692,14 @@ void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
692 692
 }
693 693
 
694 694
 static void interleaveBytes_c(const uint8_t *src1, const uint8_t *src2,
695
-                              uint8_t *dest, long width,
696
-                              long height, long src1Stride,
697
-                              long src2Stride, long dstStride)
695
+                              uint8_t *dest, int width,
696
+                              int height, int src1Stride,
697
+                              int src2Stride, int dstStride)
698 698
 {
699
-    long h;
699
+    int h;
700 700
 
701 701
     for (h=0; h < height; h++) {
702
-        long w;
702
+        int w;
703 703
         for (w=0; w < width; w++) {
704 704
             dest[2*w+0] = src1[w];
705 705
             dest[2*w+1] = src2[w];
... ...
@@ -712,12 +712,12 @@ static void interleaveBytes_c(const uint8_t *src1, const uint8_t *src2,
712 712
 
713 713
 static inline void vu9_to_vu12_c(const uint8_t *src1, const uint8_t *src2,
714 714
                                  uint8_t *dst1, uint8_t *dst2,
715
-                                 long width, long height,
716
-                                 long srcStride1, long srcStride2,
717
-                                 long dstStride1, long dstStride2)
715
+                                 int width, int height,
716
+                                 int srcStride1, int srcStride2,
717
+                                 int dstStride1, int dstStride2)
718 718
 {
719 719
     int y;
720
-    long x,w,h;
720
+    int x,w,h;
721 721
     w=width/2; h=height/2;
722 722
     for (y=0;y<h;y++) {
723 723
         const uint8_t* s1=src1+srcStride1*(y>>1);
... ...
@@ -735,12 +735,12 @@ static inline void vu9_to_vu12_c(const uint8_t *src1, const uint8_t *src2,
735 735
 
736 736
 static inline void yvu9_to_yuy2_c(const uint8_t *src1, const uint8_t *src2,
737 737
                                   const uint8_t *src3, uint8_t *dst,
738
-                                  long width, long height,
739
-                                  long srcStride1, long srcStride2,
740
-                                  long srcStride3, long dstStride)
738
+                                  int width, int height,
739
+                                  int srcStride1, int srcStride2,
740
+                                  int srcStride3, int dstStride)
741 741
 {
742 742
     int x;
743
-    long y,w,h;
743
+    int y,w,h;
744 744
     w=width/2; h=height;
745 745
     for (y=0;y<h;y++) {
746 746
         const uint8_t* yp=src1+srcStride1*y;
... ...
@@ -749,7 +749,7 @@ static inline void yvu9_to_yuy2_c(const uint8_t *src1, const uint8_t *src2,
749 749
         uint8_t* d=dst+dstStride*y;
750 750
         x=0;
751 751
         for (; x<w; x++) {
752
-            const long x2 = x<<2;
752
+            const int x2 = x<<2;
753 753
             d[8*x+0] = yp[x2];
754 754
             d[8*x+1] = up[x];
755 755
             d[8*x+2] = yp[x2+1];
... ...
@@ -836,11 +836,11 @@ static void extract_odd2avg_c(const uint8_t *src0, const uint8_t *src1,
836 836
 }
837 837
 
838 838
 static void yuyvtoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
839
-                           const uint8_t *src, long width, long height,
840
-                           long lumStride, long chromStride, long srcStride)
839
+                           const uint8_t *src, int width, int height,
840
+                           int lumStride, int chromStride, int srcStride)
841 841
 {
842
-    long y;
843
-    const long chromWidth= -((-width)>>1);
842
+    int y;
843
+    const int chromWidth= -((-width)>>1);
844 844
 
845 845
     for (y=0; y<height; y++) {
846 846
         extract_even_c(src, ydst, width);
... ...
@@ -856,11 +856,11 @@ static void yuyvtoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
856 856
 }
857 857
 
858 858
 static void yuyvtoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
859
-                           const uint8_t *src, long width, long height,
860
-                           long lumStride, long chromStride, long srcStride)
859
+                           const uint8_t *src, int width, int height,
860
+                           int lumStride, int chromStride, int srcStride)
861 861
 {
862
-    long y;
863
-    const long chromWidth= -((-width)>>1);
862
+    int y;
863
+    const int chromWidth= -((-width)>>1);
864 864
 
865 865
     for (y=0; y<height; y++) {
866 866
         extract_even_c(src, ydst, width);
... ...
@@ -874,11 +874,11 @@ static void yuyvtoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
874 874
 }
875 875
 
876 876
 static void uyvytoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
877
-                           const uint8_t *src, long width, long height,
878
-                           long lumStride, long chromStride, long srcStride)
877
+                           const uint8_t *src, int width, int height,
878
+                           int lumStride, int chromStride, int srcStride)
879 879
 {
880
-    long y;
881
-    const long chromWidth= -((-width)>>1);
880
+    int y;
881
+    const int chromWidth= -((-width)>>1);
882 882
 
883 883
     for (y=0; y<height; y++) {
884 884
         extract_even_c(src + 1, ydst, width);
... ...
@@ -894,11 +894,11 @@ static void uyvytoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
894 894
 }
895 895
 
896 896
 static void uyvytoyuv422_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
897
-                           const uint8_t *src, long width, long height,
898
-                           long lumStride, long chromStride, long srcStride)
897
+                           const uint8_t *src, int width, int height,
898
+                           int lumStride, int chromStride, int srcStride)
899 899
 {
900
-    long y;
901
-    const long chromWidth= -((-width)>>1);
900
+    int y;
901
+    const int chromWidth= -((-width)>>1);
902 902
 
903 903
     for (y=0; y<height; y++) {
904 904
         extract_even_c(src + 1, ydst, width);
... ...
@@ -1075,7 +1075,7 @@ static void fillPlane(uint8_t* plane, int stride, int width, int height, int y,
1075 1075
 }
1076 1076
 
1077 1077
 #define RGB48(name, R, B, READ)\
1078
-static inline void name ## ToY(int16_t *dst, const uint16_t *src, long width, uint32_t *unused)\
1078
+static inline void name ## ToY(int16_t *dst, const uint16_t *src, int width, uint32_t *unused)\
1079 1079
 {\
1080 1080
     int i;\
1081 1081
     for (i = 0; i < width; i++) {\
... ...
@@ -1089,7 +1089,7 @@ static inline void name ## ToY(int16_t *dst, const uint16_t *src, long width, ui
1089 1089
 \
1090 1090
 static inline void name ## ToUV(int16_t *dstU, int16_t *dstV,\
1091 1091
                              const uint16_t *src1, const uint16_t *src2,\
1092
-                             long width, uint32_t *unused)\
1092
+                             int width, uint32_t *unused)\
1093 1093
 {\
1094 1094
     int i;\
1095 1095
     assert(src1==src2);\
... ...
@@ -1105,7 +1105,7 @@ static inline void name ## ToUV(int16_t *dstU, int16_t *dstV,\
1105 1105
 \
1106 1106
 static inline void name ## ToUV_half(int16_t *dstU, int16_t *dstV,\
1107 1107
                                   const uint16_t *src1, const uint16_t *src2,\
1108
-                                  long width, uint32_t *unused)\
1108
+                                  int width, uint32_t *unused)\
1109 1109
 {\
1110 1110
     int i;\
1111 1111
     assert(src1==src2);\
... ...
@@ -1125,7 +1125,7 @@ RGB48(bgr48LE, 2, 0, AV_RL16)
1125 1125
 RGB48(bgr48BE, 2, 0, AV_RB16)
1126 1126
 
1127 1127
 #define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\
1128
-static inline void name(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)\
1128
+static inline void name(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)\
1129 1129
 {\
1130 1130
     int i;\
1131 1131
     for (i=0; i<width; i++) {\
... ...
@@ -1146,7 +1146,7 @@ BGR2Y(uint16_t, bgr15ToY, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RY<<10, GY<<5, BY
1146 1146
 BGR2Y(uint16_t, rgb16ToY, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RY    , GY<<5, BY<<11, RGB2YUV_SHIFT+8)
1147 1147
 BGR2Y(uint16_t, rgb15ToY, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RY    , GY<<5, BY<<10, RGB2YUV_SHIFT+7)
1148 1148
 
1149
-static inline void abgrToA(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
1149
+static inline void abgrToA(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
1150 1150
 {
1151 1151
     int i;
1152 1152
     for (i=0; i<width; i++) {
... ...
@@ -1155,7 +1155,7 @@ static inline void abgrToA(int16_t *dst, const uint8_t *src, long width, uint32_
1155 1155
 }
1156 1156
 
1157 1157
 #define BGR2UV(type, name, shr, shg, shb, shp, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S) \
1158
-static inline void name(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\
1158
+static inline void name(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\
1159 1159
 {\
1160 1160
     int i;\
1161 1161
     for (i=0; i<width; i++) {\
... ...
@@ -1167,7 +1167,7 @@ static inline void name(int16_t *dstU, int16_t *dstV, const uint8_t *src, const
1167 1167
         dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (256<<((S)-1)) + (1<<(S-7)))>>((S)-6);\
1168 1168
     }\
1169 1169
 }\
1170
-static inline void name ## _half(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\
1170
+static inline void name ## _half(int16_t *dstU, int16_t *dstV, const uint8_t *src, const uint8_t *dummy, int width, uint32_t *unused)\
1171 1171
 {\
1172 1172
     int i;\
1173 1173
     for (i=0; i<width; i++) {\
... ...
@@ -1194,7 +1194,7 @@ BGR2UV(uint16_t, bgr15ToUV, 0, 0, 0, 0,   0x001F, 0x03E0,   0x7C00, RU<<10, GU<<
1194 1194
 BGR2UV(uint16_t, rgb16ToUV, 0, 0, 0, 0,   0xF800, 0x07E0,   0x001F, RU    , GU<<5, BU<<11, RV    , GV<<5, BV<<11, RGB2YUV_SHIFT+8)
1195 1195
 BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0,   0x7C00, 0x03E0,   0x001F, RU    , GU<<5, BU<<10, RV    , GV<<5, BV<<10, RGB2YUV_SHIFT+7)
1196 1196
 
1197
-static inline void palToA(int16_t *dst, const uint8_t *src, long width, uint32_t *pal)
1197
+static inline void palToA(int16_t *dst, const uint8_t *src, int width, uint32_t *pal)
1198 1198
 {
1199 1199
     int i;
1200 1200
     for (i=0; i<width; i++) {
... ...
@@ -1216,7 +1216,7 @@ static inline void palToY(int16_t *dst, const uint8_t *src, long width, uint32_t
1216 1216
 
1217 1217
 static inline void palToUV(uint16_t *dstU, int16_t *dstV,
1218 1218
                            const uint8_t *src1, const uint8_t *src2,
1219
-                           long width, uint32_t *pal)
1219
+                           int width, uint32_t *pal)
1220 1220
 {
1221 1221
     int i;
1222 1222
     assert(src1 == src2);
... ...
@@ -1228,7 +1228,7 @@ static inline void palToUV(uint16_t *dstU, int16_t *dstV,
1228 1228
     }
1229 1229
 }
1230 1230
 
1231
-static inline void monowhite2Y(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
1231
+static inline void monowhite2Y(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
1232 1232
 {
1233 1233
     int i, j;
1234 1234
     for (i=0; i<width/8; i++) {
... ...
@@ -1238,7 +1238,7 @@ static inline void monowhite2Y(int16_t *dst, const uint8_t *src, long width, uin
1238 1238
     }
1239 1239
 }
1240 1240
 
1241
-static inline void monoblack2Y(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
1241
+static inline void monoblack2Y(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
1242 1242
 {
1243 1243
     int i, j;
1244 1244
     for (i=0; i<width/8; i++) {
... ...
@@ -1431,24 +1431,24 @@ static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t* src[], int srcStrid
1431 1431
     return srcSliceH;
1432 1432
 }
1433 1433
 
1434
-static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
1434
+static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
1435 1435
 {
1436
-    long i;
1436
+    int i;
1437 1437
     for (i=0; i<num_pixels; i++)
1438 1438
         ((uint32_t *) dst)[i] = ((const uint32_t *)palette)[src[i<<1]] | (src[(i<<1)+1] << 24);
1439 1439
 }
1440 1440
 
1441
-static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
1441
+static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
1442 1442
 {
1443
-    long i;
1443
+    int i;
1444 1444
 
1445 1445
     for (i=0; i<num_pixels; i++)
1446 1446
         ((uint32_t *) dst)[i] = ((const uint32_t *)palette)[src[i<<1]] | src[(i<<1)+1];
1447 1447
 }
1448 1448
 
1449
-static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
1449
+static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
1450 1450
 {
1451
-    long i;
1451
+    int i;
1452 1452
 
1453 1453
     for (i=0; i<num_pixels; i++) {
1454 1454
         //FIXME slow?
... ...
@@ -1464,7 +1464,7 @@ static int palToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[],
1464 1464
 {
1465 1465
     const enum PixelFormat srcFormat= c->srcFormat;
1466 1466
     const enum PixelFormat dstFormat= c->dstFormat;
1467
-    void (*conv)(const uint8_t *src, uint8_t *dst, long num_pixels,
1467
+    void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels,
1468 1468
                  const uint8_t *palette)=NULL;
1469 1469
     int i;
1470 1470
     uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY;
... ...
@@ -1521,7 +1521,7 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[],
1521 1521
     const int dstBpp= (c->dstFormatBpp + 7) >> 3;
1522 1522
     const int srcId= c->srcFormatBpp >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */
1523 1523
     const int dstId= c->dstFormatBpp >> 2;
1524
-    void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL;
1524
+    void (*conv)(const uint8_t *src, uint8_t *dst, int src_size)=NULL;
1525 1525
 
1526 1526
 #define CONV_IS(src, dst) (srcFormat == PIX_FMT_##src && dstFormat == PIX_FMT_##dst)
1527 1527
 
... ...
@@ -2085,18 +2085,18 @@ int sws_scale_ordered(SwsContext *c, const uint8_t* const src[], int srcStride[]
2085 2085
 #endif
2086 2086
 
2087 2087
 /* Convert the palette to the same packed 32-bit format as the palette */
2088
-void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
2088
+void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
2089 2089
 {
2090
-    long i;
2090
+    int i;
2091 2091
 
2092 2092
     for (i=0; i<num_pixels; i++)
2093 2093
         ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
2094 2094
 }
2095 2095
 
2096 2096
 /* Palette format: ABCD -> dst format: ABC */
2097
-void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
2097
+void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
2098 2098
 {
2099
-    long i;
2099
+    int i;
2100 2100
 
2101 2101
     for (i=0; i<num_pixels; i++) {
2102 2102
         //FIXME slow?
... ...
@@ -351,7 +351,7 @@ struct SwsContext *sws_getCachedContext(struct SwsContext *context,
351 351
  * @param num_pixels number of pixels to convert
352 352
  * @param palette    array with [256] entries, which must match color arrangement (RGB or BGR) of src
353 353
  */
354
-void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
354
+void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
355 355
 
356 356
 /**
357 357
  * Converts an 8bit paletted frame into a frame with a color depth of 24 bits.
... ...
@@ -363,7 +363,7 @@ void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pi
363 363
  * @param num_pixels number of pixels to convert
364 364
  * @param palette    array with [256] entries, which must match color arrangement (RGB or BGR) of src
365 365
  */
366
-void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
366
+void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
367 367
 
368 368
 
369 369
 #endif /* SWSCALE_SWSCALE_H */
... ...
@@ -194,6 +194,7 @@ typedef struct SwsContext {
194 194
 #define Y_TEMP                "11*8+4*4*256*2+40"
195 195
 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
196 196
 #define UV_OFF                "11*8+4*4*256*3+48"
197
+#define UV_OFFx2              "11*8+4*4*256*3+56"
197 198
 
198 199
     DECLARE_ALIGNED(8, uint64_t, redDither);
199 200
     DECLARE_ALIGNED(8, uint64_t, greenDither);
... ...
@@ -217,6 +218,7 @@ typedef struct SwsContext {
217 217
     DECLARE_ALIGNED(8, uint64_t, y_temp);
218 218
     int32_t  alpMmxFilter[4*MAX_FILTER_SIZE];
219 219
     DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes
220
+    DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes
220 221
 
221 222
 #if HAVE_ALTIVEC
222 223
     vector signed short   CY;
... ...
@@ -259,7 +261,7 @@ typedef struct SwsContext {
259 259
                         const int16_t *chrVSrc, const int16_t *alpSrc,
260 260
                         uint8_t *dest,
261 261
                         uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
262
-                        long dstW, long chrDstW);
262
+                        int dstW, int chrDstW);
263 263
     void (*yuv2yuvX   )(struct SwsContext *c,
264 264
                         const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
265 265
                         const int16_t *chrFilter, const int16_t **chrUSrc,
... ...
@@ -267,7 +269,7 @@ typedef struct SwsContext {
267 267
                         const int16_t **alpSrc,
268 268
                         uint8_t *dest,
269 269
                         uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
270
-                        long dstW, long chrDstW);
270
+                        int dstW, int chrDstW);
271 271
     void (*yuv2packed1)(struct SwsContext *c,
272 272
                         const uint16_t *buf0,
273 273
                         const uint16_t *ubuf0, const uint16_t *ubuf1,
... ...
@@ -287,26 +289,26 @@ typedef struct SwsContext {
287 287
                         const int16_t *chrFilter, const int16_t **chrUSrc,
288 288
                         const int16_t **chrVSrc, int chrFilterSize,
289 289
                         const int16_t **alpSrc, uint8_t *dest,
290
-                        long dstW, long dstY);
290
+                        int dstW, int dstY);
291 291
 
292 292
     void (*lumToYV12)(uint8_t *dst, const uint8_t *src,
293
-                      long width, uint32_t *pal); ///< Unscaled conversion of luma plane to YV12 for horizontal scaler.
293
+                      int width, uint32_t *pal); ///< Unscaled conversion of luma plane to YV12 for horizontal scaler.
294 294
     void (*alpToYV12)(uint8_t *dst, const uint8_t *src,
295
-                      long width, uint32_t *pal); ///< Unscaled conversion of alpha plane to YV12 for horizontal scaler.
295
+                      int width, uint32_t *pal); ///< Unscaled conversion of alpha plane to YV12 for horizontal scaler.
296 296
     void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
297 297
                       const uint8_t *src1, const uint8_t *src2,
298
-                      long width, uint32_t *pal); ///< Unscaled conversion of chroma planes to YV12 for horizontal scaler.
298
+                      int width, uint32_t *pal); ///< Unscaled conversion of chroma planes to YV12 for horizontal scaler.
299 299
     void (*hyscale_fast)(struct SwsContext *c,
300
-                         int16_t *dst, long dstWidth,
300
+                         int16_t *dst, int dstWidth,
301 301
                          const uint8_t *src, int srcW, int xInc);
302 302
     void (*hcscale_fast)(struct SwsContext *c,
303
-                         int16_t *dst1, int16_t *dst2, long dstWidth,
303
+                         int16_t *dst1, int16_t *dst2, int dstWidth,
304 304
                          const uint8_t *src1, const uint8_t *src2,
305 305
                          int srcW, int xInc);
306 306
 
307 307
     void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW,
308 308
                    int xInc, const int16_t *filter, const int16_t *filterPos,
309
-                   long filterSize);
309
+                   int filterSize);
310 310
 
311 311
     void (*hScale16)(int16_t *dst, int dstW, const uint16_t *src, int srcW,
312 312
                    int xInc, const int16_t *filter, const int16_t *filterPos,
... ...
@@ -24,7 +24,7 @@ static inline void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
24 24
                               const int16_t **chrVSrc,
25 25
                               int chrFilterSize, const int16_t **alpSrc,
26 26
                               uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
27
-                              uint8_t *aDest, long dstW, long chrDstW)
27
+                              uint8_t *aDest, int dstW, int chrDstW)
28 28
 {
29 29
     yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize,
30 30
                 chrFilter, chrUSrc, chrVSrc, chrFilterSize,
... ...
@@ -47,7 +47,7 @@ static inline void yuv2yuv1_c(SwsContext *c, const int16_t *lumSrc,
47 47
                               const int16_t *chrUSrc, const int16_t *chrVSrc,
48 48
                               const int16_t *alpSrc,
49 49
                               uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
50
-                              uint8_t *aDest, long dstW, long chrDstW)
50
+                              uint8_t *aDest, int dstW, int chrDstW)
51 51
 {
52 52
     int i;
53 53
     for (i=0; i<dstW; i++) {
... ...
@@ -79,7 +79,7 @@ static inline void yuv2packedX_c(SwsContext *c, const int16_t *lumFilter,
79 79
                                  const int16_t *chrFilter, const int16_t **chrUSrc,
80 80
                                  const int16_t **chrVSrc,
81 81
                                  int chrFilterSize, const int16_t **alpSrc,
82
-                                 uint8_t *dest, long dstW, long dstY)
82
+                                 uint8_t *dest, int dstW, int dstY)
83 83
 {
84 84
         yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize,
85 85
                        chrFilter, chrUSrc, chrVSrc, chrFilterSize,
... ...
@@ -128,7 +128,7 @@ static inline void yuv2packed1_c(SwsContext *c, const uint16_t *buf0,
128 128
 
129 129
 //FIXME yuy2* can read up to 7 samples too much
130 130
 
131
-static inline void yuy2ToY_c(uint8_t *dst, const uint8_t *src, long width,
131
+static inline void yuy2ToY_c(uint8_t *dst, const uint8_t *src, int width,
132 132
                              uint32_t *unused)
133 133
 {
134 134
     int i;
... ...
@@ -137,7 +137,7 @@ static inline void yuy2ToY_c(uint8_t *dst, const uint8_t *src, long width,
137 137
 }
138 138
 
139 139
 static inline void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
140
-                              const uint8_t *src2, long width, uint32_t *unused)
140
+                              const uint8_t *src2, int width, uint32_t *unused)
141 141
 {
142 142
     int i;
143 143
     for (i=0; i<width; i++) {
... ...
@@ -148,7 +148,7 @@ static inline void yuy2ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
148 148
 }
149 149
 
150 150
 static inline void LEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
151
-                            const uint8_t *src2, long width, uint32_t *unused)
151
+                            const uint8_t *src2, int width, uint32_t *unused)
152 152
 {
153 153
     int i;
154 154
     // FIXME I don't think this code is right for YUV444/422, since then h is not subsampled so
... ...
@@ -161,7 +161,7 @@ static inline void LEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
161 161
 
162 162
 /* This is almost identical to the previous, end exists only because
163 163
  * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
164
-static inline void uyvyToY_c(uint8_t *dst, const uint8_t *src, long width,
164
+static inline void uyvyToY_c(uint8_t *dst, const uint8_t *src, int width,
165 165
                              uint32_t *unused)
166 166
 {
167 167
     int i;
... ...
@@ -170,7 +170,7 @@ static inline void uyvyToY_c(uint8_t *dst, const uint8_t *src, long width,
170 170
 }
171 171
 
172 172
 static inline void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
173
-                              const uint8_t *src2, long width, uint32_t *unused)
173
+                              const uint8_t *src2, int width, uint32_t *unused)
174 174
 {
175 175
     int i;
176 176
     for (i=0; i<width; i++) {
... ...
@@ -181,7 +181,7 @@ static inline void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
181 181
 }
182 182
 
183 183
 static inline void BEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
184
-                            const uint8_t *src2, long width, uint32_t *unused)
184
+                            const uint8_t *src2, int width, uint32_t *unused)
185 185
 {
186 186
     int i;
187 187
     for (i=0; i<width; i++) {
... ...
@@ -191,7 +191,7 @@ static inline void BEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
191 191
 }
192 192
 
193 193
 static inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
194
-                              const uint8_t *src, long width)
194
+                              const uint8_t *src, int width)
195 195
 {
196 196
     int i;
197 197
     for (i = 0; i < width; i++) {
... ...
@@ -205,7 +205,7 @@ static inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
205 205
 #define YUV_NBPS(depth, endianness, rfunc) \
206 206
 static inline void endianness ## depth ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
207 207
                                           const uint16_t *srcU, const uint16_t *srcV, \
208
-                                          long width, uint32_t *unused) \
208
+                                          int width, uint32_t *unused) \
209 209
 { \
210 210
     int i; \
211 211
     for (i = 0; i < width; i++) { \
... ...
@@ -214,7 +214,7 @@ static inline void endianness ## depth ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
214 214
     } \
215 215
 } \
216 216
 \
217
-static inline void endianness ## depth ## ToY_c(uint8_t *dstY, const uint16_t *srcY, long width, uint32_t *unused) \
217
+static inline void endianness ## depth ## ToY_c(uint8_t *dstY, const uint16_t *srcY, int width, uint32_t *unused) \
218 218
 { \
219 219
     int i; \
220 220
     for (i = 0; i < width; i++) \
... ...
@@ -229,20 +229,20 @@ YUV_NBPS(10, BE, AV_RB16)
229 229
 
230 230
 static inline void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV,
231 231
                               const uint8_t *src1, const uint8_t *src2,
232
-                              long width, uint32_t *unused)
232
+                              int width, uint32_t *unused)
233 233
 {
234 234
     nvXXtoUV_c(dstU, dstV, src1, width);
235 235
 }
236 236
 
237 237
 static inline void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
238 238
                               const uint8_t *src1, const uint8_t *src2,
239
-                              long width, uint32_t *unused)
239
+                              int width, uint32_t *unused)
240 240
 {
241 241
     nvXXtoUV_c(dstV, dstU, src1, width);
242 242
 }
243 243
 
244 244
 static inline void bgr24ToY_c(int16_t *dst, const uint8_t *src,
245
-                              long width, uint32_t *unused)
245
+                              int width, uint32_t *unused)
246 246
 {
247 247
     int i;
248 248
     for (i=0; i<width; i++) {
... ...
@@ -255,7 +255,7 @@ static inline void bgr24ToY_c(int16_t *dst, const uint8_t *src,
255 255
 }
256 256
 
257 257
 static inline void bgr24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
258
-                               const uint8_t *src2, long width, uint32_t *unused)
258
+                               const uint8_t *src2, int width, uint32_t *unused)
259 259
 {
260 260
     int i;
261 261
     for (i=0; i<width; i++) {
... ...
@@ -270,7 +270,7 @@ static inline void bgr24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1
270 270
 }
271 271
 
272 272
 static inline void bgr24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
273
-                                    const uint8_t *src2, long width, uint32_t *unused)
273
+                                    const uint8_t *src2, int width, uint32_t *unused)
274 274
 {
275 275
     int i;
276 276
     for (i=0; i<width; i++) {
... ...
@@ -284,7 +284,7 @@ static inline void bgr24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t
284 284
     assert(src1 == src2);
285 285
 }
286 286
 
287
-static inline void rgb24ToY_c(int16_t *dst, const uint8_t *src, long width,
287
+static inline void rgb24ToY_c(int16_t *dst, const uint8_t *src, int width,
288 288
                               uint32_t *unused)
289 289
 {
290 290
     int i;
... ...
@@ -298,7 +298,7 @@ static inline void rgb24ToY_c(int16_t *dst, const uint8_t *src, long width,
298 298
 }
299 299
 
300 300
 static inline void rgb24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
301
-                               const uint8_t *src2, long width, uint32_t *unused)
301
+                               const uint8_t *src2, int width, uint32_t *unused)
302 302
 {
303 303
     int i;
304 304
     assert(src1==src2);
... ...
@@ -313,7 +313,7 @@ static inline void rgb24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1
313 313
 }
314 314
 
315 315
 static inline void rgb24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *src1,
316
-                                    const uint8_t *src2, long width, uint32_t *unused)
316
+                                    const uint8_t *src2, int width, uint32_t *unused)
317 317
 {
318 318
     int i;
319 319
     assert(src1==src2);
... ...
@@ -332,7 +332,7 @@ static inline void rgb24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t
332 332
 static inline void hScale_c(int16_t *dst, int dstW, const uint8_t *src,
333 333
                             int srcW, int xInc,
334 334
                             const int16_t *filter, const int16_t *filterPos,
335
-                            long filterSize)
335
+                            int filterSize)
336 336
 {
337 337
     int i;
338 338
     for (i=0; i<dstW; i++) {
... ...
@@ -408,7 +408,7 @@ static void lumRangeFromJpeg_c(int16_t *dst, int width)
408 408
         dst[i] = (dst[i]*14071 + 33561947)>>14;
409 409
 }
410 410
 
411
-static inline void hyscale_fast_c(SwsContext *c, int16_t *dst, long dstWidth,
411
+static inline void hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
412 412
                                   const uint8_t *src, int srcW, int xInc)
413 413
 {
414 414
     int i;
... ...
@@ -422,14 +422,14 @@ static inline void hyscale_fast_c(SwsContext *c, int16_t *dst, long dstWidth,
422 422
 }
423 423
 
424 424
       // *** horizontal scale Y line to temp buffer
425
-static inline void hyscale_c(SwsContext *c, uint16_t *dst, long dstWidth,
425
+static inline void hyscale_c(SwsContext *c, uint16_t *dst, int dstWidth,
426 426
                              const uint8_t *src, int srcW, int xInc,
427 427
                              const int16_t *hLumFilter,
428 428
                              const int16_t *hLumFilterPos, int hLumFilterSize,
429 429
                              uint8_t *formatConvBuffer,
430 430
                              uint32_t *pal, int isAlpha)
431 431
 {
432
-    void (*toYV12)(uint8_t *, const uint8_t *, long, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
432
+    void (*toYV12)(uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
433 433
     void (*convertRange)(int16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
434 434
 
435 435
     src += isAlpha ? c->alpSrcOffset : c->lumSrcOffset;
... ...
@@ -453,7 +453,7 @@ static inline void hyscale_c(SwsContext *c, uint16_t *dst, long dstWidth,
453 453
 }
454 454
 
455 455
 static inline void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
456
-                                  long dstWidth, const uint8_t *src1,
456
+                                  int dstWidth, const uint8_t *src1,
457 457
                                   const uint8_t *src2, int srcW, int xInc)
458 458
 {
459 459
     int i;
... ...
@@ -467,7 +467,7 @@ static inline void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
467 467
     }
468 468
 }
469 469
 
470
-inline static void hcscale_c(SwsContext *c, uint16_t *dst1, uint16_t *dst2, long dstWidth,
470
+inline static void hcscale_c(SwsContext *c, uint16_t *dst1, uint16_t *dst2, int dstWidth,
471 471
                              const uint8_t *src1, const uint8_t *src2,
472 472
                              int srcW, int xInc, const int16_t *hChrFilter,
473 473
                              const int16_t *hChrFilterPos, int hChrFilterSize,
... ...
@@ -1009,6 +1009,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
1009 1009
         c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize];
1010 1010
     }
1011 1011
     c->uv_off = dst_stride_px;
1012
+    c->uv_offx2 = dst_stride;
1012 1013
     for (i=0; i<c->vChrBufSize; i++) {
1013 1014
         FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+1, fail);
1014 1015
         c->chrUPixBuf[i] = c->chrUPixBuf[i+c->vChrBufSize];
... ...
@@ -61,7 +61,7 @@
61 61
 
62 62
 #if !COMPILE_TEMPLATE_AMD3DNOW
63 63
 
64
-static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size)
64
+static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size)
65 65
 {
66 66
     uint8_t *dest = dst;
67 67
     const uint8_t *s = src;
... ...
@@ -143,7 +143,7 @@ static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long s
143 143
             MOVNTQ"     %%mm4, 16%0"
144 144
 
145 145
 
146
-static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
146
+static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
147 147
 {
148 148
     uint8_t *dest = dst;
149 149
     const uint8_t *s = src;
... ...
@@ -186,7 +186,7 @@ static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long s
186 186
  MMX2, 3DNOW optimization by Nick Kurshev
187 187
  32-bit C version, and and&add trick by Michael Niedermayer
188 188
 */
189
-static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size)
189
+static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size)
190 190
 {
191 191
     register const uint8_t* s=src;
192 192
     register uint8_t* d=dst;
... ...
@@ -230,7 +230,7 @@ static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_
230 230
     }
231 231
 }
232 232
 
233
-static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size)
233
+static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size)
234 234
 {
235 235
     register const uint8_t* s=src;
236 236
     register uint8_t* d=dst;
... ...
@@ -279,7 +279,7 @@ static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, long src_
279 279
     }
280 280
 }
281 281
 
282
-static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size)
282
+static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size)
283 283
 {
284 284
     const uint8_t *s = src;
285 285
     const uint8_t *end;
... ...
@@ -371,7 +371,7 @@ static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, long src_
371 371
     }
372 372
 }
373 373
 
374
-static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size)
374
+static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
375 375
 {
376 376
     const uint8_t *s = src;
377 377
     const uint8_t *end;
... ...
@@ -426,7 +426,7 @@ static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long s
426 426
     }
427 427
 }
428 428
 
429
-static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size)
429
+static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size)
430 430
 {
431 431
     const uint8_t *s = src;
432 432
     const uint8_t *end;
... ...
@@ -518,7 +518,7 @@ static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_
518 518
     }
519 519
 }
520 520
 
521
-static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size)
521
+static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
522 522
 {
523 523
     const uint8_t *s = src;
524 524
     const uint8_t *end;
... ...
@@ -573,7 +573,7 @@ static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long s
573 573
     }
574 574
 }
575 575
 
576
-static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size)
576
+static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
577 577
 {
578 578
     const uint8_t *s = src;
579 579
     const uint8_t *end;
... ...
@@ -630,7 +630,7 @@ static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long s
630 630
     }
631 631
 }
632 632
 
633
-static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size)
633
+static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size)
634 634
 {
635 635
     const uint8_t *s = src;
636 636
     const uint8_t *end;
... ...
@@ -687,7 +687,7 @@ static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_
687 687
     }
688 688
 }
689 689
 
690
-static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size)
690
+static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
691 691
 {
692 692
     const uint8_t *s = src;
693 693
     const uint8_t *end;
... ...
@@ -744,7 +744,7 @@ static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long s
744 744
     }
745 745
 }
746 746
 
747
-static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size)
747
+static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size)
748 748
 {
749 749
     const uint8_t *s = src;
750 750
     const uint8_t *end;
... ...
@@ -822,7 +822,7 @@ static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_
822 822
        |
823 823
    original bits
824 824
 */
825
-static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
825
+static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
826 826
 {
827 827
     const uint16_t *end;
828 828
     const uint16_t *mm_end;
... ...
@@ -925,7 +925,7 @@ static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long s
925 925
     }
926 926
 }
927 927
 
928
-static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
928
+static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
929 929
 {
930 930
     const uint16_t *end;
931 931
     const uint16_t *mm_end;
... ...
@@ -1046,7 +1046,7 @@ static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long s
1046 1046
     MOVNTQ"     %%mm0,  %0      \n\t"                               \
1047 1047
     MOVNTQ"     %%mm3, 8%0      \n\t"                               \
1048 1048
 
1049
-static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size)
1049
+static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size)
1050 1050
 {
1051 1051
     const uint16_t *end;
1052 1052
     const uint16_t *mm_end;
... ...
@@ -1088,7 +1088,7 @@ static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_
1088 1088
     }
1089 1089
 }
1090 1090
 
1091
-static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size)
1091
+static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size)
1092 1092
 {
1093 1093
     const uint16_t *end;
1094 1094
     const uint16_t *mm_end;
... ...
@@ -1130,7 +1130,7 @@ static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_
1130 1130
     }
1131 1131
 }
1132 1132
 
1133
-static inline void RENAME(shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size)
1133
+static inline void RENAME(shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size)
1134 1134
 {
1135 1135
     x86_reg idx = 15 - src_size;
1136 1136
     const uint8_t *s = src-idx;
... ...
@@ -1192,7 +1192,7 @@ static inline void RENAME(shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst,
1192 1192
     }
1193 1193
 }
1194 1194
 
1195
-static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size)
1195
+static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
1196 1196
 {
1197 1197
     unsigned i;
1198 1198
     x86_reg mmx_size= 23 - src_size;
... ...
@@ -1260,10 +1260,10 @@ static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long s
1260 1260
 }
1261 1261
 
1262 1262
 static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
1263
-                                           long width, long height,
1264
-                                           long lumStride, long chromStride, long dstStride, long vertLumPerChroma)
1263
+                                           int width, int height,
1264
+                                           int lumStride, int chromStride, int dstStride, int vertLumPerChroma)
1265 1265
 {
1266
-    long y;
1266
+    int y;
1267 1267
     const x86_reg chromWidth= width>>1;
1268 1268
     for (y=0; y<height; y++) {
1269 1269
         //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway)
... ...
@@ -1317,18 +1317,18 @@ static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *u
1317 1317
  * (If this is a problem for anyone then tell me, and I will fix it.)
1318 1318
  */
1319 1319
 static inline void RENAME(yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
1320
-                                      long width, long height,
1321
-                                      long lumStride, long chromStride, long dstStride)
1320
+                                      int width, int height,
1321
+                                      int lumStride, int chromStride, int dstStride)
1322 1322
 {
1323 1323
     //FIXME interpolate chroma
1324 1324
     RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
1325 1325
 }
1326 1326
 
1327 1327
 static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
1328
-                                           long width, long height,
1329
-                                           long lumStride, long chromStride, long dstStride, long vertLumPerChroma)
1328
+                                           int width, int height,
1329
+                                           int lumStride, int chromStride, int dstStride, int vertLumPerChroma)
1330 1330
 {
1331
-    long y;
1331
+    int y;
1332 1332
     const x86_reg chromWidth= width>>1;
1333 1333
     for (y=0; y<height; y++) {
1334 1334
         //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway)
... ...
@@ -1382,8 +1382,8 @@ static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *u
1382 1382
  * (If this is a problem for anyone then tell me, and I will fix it.)
1383 1383
  */
1384 1384
 static inline void RENAME(yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
1385
-                                      long width, long height,
1386
-                                      long lumStride, long chromStride, long dstStride)
1385
+                                      int width, int height,
1386
+                                      int lumStride, int chromStride, int dstStride)
1387 1387
 {
1388 1388
     //FIXME interpolate chroma
1389 1389
     RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
... ...
@@ -1393,8 +1393,8 @@ static inline void RENAME(yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc,
1393 1393
  * Width should be a multiple of 16.
1394 1394
  */
1395 1395
 static inline void RENAME(yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
1396
-                                         long width, long height,
1397
-                                         long lumStride, long chromStride, long dstStride)
1396
+                                         int width, int height,
1397
+                                         int lumStride, int chromStride, int dstStride)
1398 1398
 {
1399 1399
     RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1);
1400 1400
 }
... ...
@@ -1403,8 +1403,8 @@ static inline void RENAME(yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usr
1403 1403
  * Width should be a multiple of 16.
1404 1404
  */
1405 1405
 static inline void RENAME(yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
1406
-                                         long width, long height,
1407
-                                         long lumStride, long chromStride, long dstStride)
1406
+                                         int width, int height,
1407
+                                         int lumStride, int chromStride, int dstStride)
1408 1408
 {
1409 1409
     RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1);
1410 1410
 }
... ...
@@ -1414,10 +1414,10 @@ static inline void RENAME(yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usr
1414 1414
  * (If this is a problem for anyone then tell me, and I will fix it.)
1415 1415
  */
1416 1416
 static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
1417
-                                      long width, long height,
1418
-                                      long lumStride, long chromStride, long srcStride)
1417
+                                      int width, int height,
1418
+                                      int lumStride, int chromStride, int srcStride)
1419 1419
 {
1420
-    long y;
1420
+    int y;
1421 1421
     const x86_reg chromWidth= width>>1;
1422 1422
     for (y=0; y<height; y+=2) {
1423 1423
         __asm__ volatile(
... ...
@@ -1513,9 +1513,9 @@ static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t
1513 1513
 #endif /* !COMPILE_TEMPLATE_AMD3DNOW */
1514 1514
 
1515 1515
 #if COMPILE_TEMPLATE_MMX2 || COMPILE_TEMPLATE_AMD3DNOW
1516
-static inline void RENAME(planar2x)(const uint8_t *src, uint8_t *dst, long srcWidth, long srcHeight, long srcStride, long dstStride)
1516
+static inline void RENAME(planar2x)(const uint8_t *src, uint8_t *dst, int srcWidth, int srcHeight, int srcStride, int dstStride)
1517 1517
 {
1518
-    long x,y;
1518
+    int x,y;
1519 1519
 
1520 1520
     dst[0]= src[0];
1521 1521
 
... ...
@@ -1612,10 +1612,10 @@ static inline void RENAME(planar2x)(const uint8_t *src, uint8_t *dst, long srcWi
1612 1612
  * FIXME: Write HQ version.
1613 1613
  */
1614 1614
 static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
1615
-                                      long width, long height,
1616
-                                      long lumStride, long chromStride, long srcStride)
1615
+                                      int width, int height,
1616
+                                      int lumStride, int chromStride, int srcStride)
1617 1617
 {
1618
-    long y;
1618
+    int y;
1619 1619
     const x86_reg chromWidth= width>>1;
1620 1620
     for (y=0; y<height; y+=2) {
1621 1621
         __asm__ volatile(
... ...
@@ -1718,13 +1718,13 @@ static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t
1718 1718
  * FIXME: Write HQ version.
1719 1719
  */
1720 1720
 static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
1721
-                                       long width, long height,
1722
-                                       long lumStride, long chromStride, long srcStride)
1721
+                                       int width, int height,
1722
+                                       int lumStride, int chromStride, int srcStride)
1723 1723
 {
1724
-    long y;
1724
+    int y;
1725 1725
     const x86_reg chromWidth= width>>1;
1726 1726
     for (y=0; y<height-2; y+=2) {
1727
-        long i;
1727
+        int i;
1728 1728
         for (i=0; i<2; i++) {
1729 1729
             __asm__ volatile(
1730 1730
                 "mov                        %2, %%"REG_a"   \n\t"
... ...
@@ -1963,13 +1963,13 @@ static inline void RENAME(rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_
1963 1963
 
1964 1964
 #if !COMPILE_TEMPLATE_AMD3DNOW
1965 1965
 static void RENAME(interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dest,
1966
-                                    long width, long height, long src1Stride,
1967
-                                    long src2Stride, long dstStride)
1966
+                                    int width, int height, int src1Stride,
1967
+                                    int src2Stride, int dstStride)
1968 1968
 {
1969
-    long h;
1969
+    int h;
1970 1970
 
1971 1971
     for (h=0; h < height; h++) {
1972
-        long w;
1972
+        int w;
1973 1973
 
1974 1974
 #if COMPILE_TEMPLATE_SSE2
1975 1975
         __asm__(
... ...
@@ -2037,12 +2037,12 @@ static void RENAME(interleaveBytes)(const uint8_t *src1, const uint8_t *src2, ui
2037 2037
 #if !COMPILE_TEMPLATE_AMD3DNOW
2038 2038
 static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
2039 2039
                                        uint8_t *dst1, uint8_t *dst2,
2040
-                                       long width, long height,
2041
-                                       long srcStride1, long srcStride2,
2042
-                                       long dstStride1, long dstStride2)
2040
+                                       int width, int height,
2041
+                                       int srcStride1, int srcStride2,
2042
+                                       int dstStride1, int dstStride2)
2043 2043
 {
2044 2044
     x86_reg y;
2045
-    long x,w,h;
2045
+    int x,w,h;
2046 2046
     w=width/2; h=height/2;
2047 2047
     __asm__ volatile(
2048 2048
         PREFETCH" %0    \n\t"
... ...
@@ -2131,12 +2131,12 @@ static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
2131 2131
 
2132 2132
 static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
2133 2133
                                         uint8_t *dst,
2134
-                                        long width, long height,
2135
-                                        long srcStride1, long srcStride2,
2136
-                                        long srcStride3, long dstStride)
2134
+                                        int width, int height,
2135
+                                        int srcStride1, int srcStride2,
2136
+                                        int srcStride3, int dstStride)
2137 2137
 {
2138 2138
     x86_reg x;
2139
-    long y,w,h;
2139
+    int y,w,h;
2140 2140
     w=width/2; h=height;
2141 2141
     for (y=0;y<h;y++) {
2142 2142
         const uint8_t* yp=src1+srcStride1*y;
... ...
@@ -2197,7 +2197,7 @@ static inline void RENAME(yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2
2197 2197
                 :"memory");
2198 2198
         }
2199 2199
         for (; x<w; x++) {
2200
-            const long x2 = x<<2;
2200
+            const int x2 = x<<2;
2201 2201
             d[8*x+0] = yp[x2];
2202 2202
             d[8*x+1] = up[x];
2203 2203
             d[8*x+2] = yp[x2+1];
... ...
@@ -2459,11 +2459,11 @@ static void RENAME(extract_odd2avg)(const uint8_t *src0, const uint8_t *src1, ui
2459 2459
 }
2460 2460
 
2461 2461
 static void RENAME(yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
2462
-                                 long width, long height,
2463
-                                 long lumStride, long chromStride, long srcStride)
2462
+                                 int width, int height,
2463
+                                 int lumStride, int chromStride, int srcStride)
2464 2464
 {
2465
-    long y;
2466
-    const long chromWidth= -((-width)>>1);
2465
+    int y;
2466
+    const int chromWidth= -((-width)>>1);
2467 2467
 
2468 2468
     for (y=0; y<height; y++) {
2469 2469
         RENAME(extract_even)(src, ydst, width);
... ...
@@ -2485,11 +2485,11 @@ static void RENAME(yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, co
2485 2485
 
2486 2486
 #if !COMPILE_TEMPLATE_AMD3DNOW
2487 2487
 static void RENAME(yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
2488
-                                 long width, long height,
2489
-                                 long lumStride, long chromStride, long srcStride)
2488
+                                 int width, int height,
2489
+                                 int lumStride, int chromStride, int srcStride)
2490 2490
 {
2491
-    long y;
2492
-    const long chromWidth= -((-width)>>1);
2491
+    int y;
2492
+    const int chromWidth= -((-width)>>1);
2493 2493
 
2494 2494
     for (y=0; y<height; y++) {
2495 2495
         RENAME(extract_even)(src, ydst, width);
... ...
@@ -2509,11 +2509,11 @@ static void RENAME(yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, co
2509 2509
 #endif /* !COMPILE_TEMPLATE_AMD3DNOW */
2510 2510
 
2511 2511
 static void RENAME(uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
2512
-                                 long width, long height,
2513
-                                 long lumStride, long chromStride, long srcStride)
2512
+                                 int width, int height,
2513
+                                 int lumStride, int chromStride, int srcStride)
2514 2514
 {
2515
-    long y;
2516
-    const long chromWidth= -((-width)>>1);
2515
+    int y;
2516
+    const int chromWidth= -((-width)>>1);
2517 2517
 
2518 2518
     for (y=0; y<height; y++) {
2519 2519
         RENAME(extract_even)(src+1, ydst, width);
... ...
@@ -2535,11 +2535,11 @@ static void RENAME(uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, co
2535 2535
 
2536 2536
 #if !COMPILE_TEMPLATE_AMD3DNOW
2537 2537
 static void RENAME(uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
2538
-                                 long width, long height,
2539
-                                 long lumStride, long chromStride, long srcStride)
2538
+                                 int width, int height,
2539
+                                 int lumStride, int chromStride, int srcStride)
2540 2540
 {
2541
-    long y;
2542
-    const long chromWidth= -((-width)>>1);
2541
+    int y;
2542
+    const int chromWidth= -((-width)>>1);
2543 2543
 
2544 2544
     for (y=0; y<height; y++) {
2545 2545
         RENAME(extract_even)(src+1, ydst, width);
... ...
@@ -78,7 +78,7 @@ static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
78 78
                                     const int16_t **chrVSrc,
79 79
                                     int chrFilterSize, const int16_t **alpSrc,
80 80
                                     uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
81
-                                    uint8_t *aDest, long dstW, long chrDstW)
81
+                                    uint8_t *aDest, int dstW, int chrDstW)
82 82
 {
83 83
     if (uDest) {
84 84
         x86_reg uv_off = c->uv_off;
... ...
@@ -159,7 +159,7 @@ static inline void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter,
159 159
                                        const int16_t **chrVSrc,
160 160
                                        int chrFilterSize, const int16_t **alpSrc,
161 161
                                        uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
162
-                                       uint8_t *aDest, long dstW, long chrDstW)
162
+                                       uint8_t *aDest, int dstW, int chrDstW)
163 163
 {
164 164
     if (uDest) {
165 165
         x86_reg uv_off = c->uv_off;
... ...
@@ -190,9 +190,9 @@ static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc,
190 190
                                     const int16_t *chrUSrc, const int16_t *chrVSrc,
191 191
                                     const int16_t *alpSrc,
192 192
                                     uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
193
-                                    uint8_t *aDest, long dstW, long chrDstW)
193
+                                    uint8_t *aDest, int dstW, int chrDstW)
194 194
 {
195
-    long p= 4;
195
+    int p= 4;
196 196
     const int16_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
197 197
     uint8_t *dst[4]= { aDest, dest, uDest, vDest };
198 198
     x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW };
... ...
@@ -231,9 +231,9 @@ static inline void RENAME(yuv2yuv1_ar)(SwsContext *c, const int16_t *lumSrc,
231 231
                                        const int16_t *chrUSrc, const int16_t *chrVSrc,
232 232
                                        const int16_t *alpSrc,
233 233
                                        uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
234
-                                       uint8_t *aDest, long dstW, long chrDstW)
234
+                                       uint8_t *aDest, int dstW, int chrDstW)
235 235
 {
236
-    long p= 4;
236
+    int p= 4;
237 237
     const int16_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
238 238
     uint8_t *dst[4]= { aDest, dest, uDest, vDest };
239 239
     x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW };
... ...
@@ -471,7 +471,7 @@ static inline void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilte
471 471
                                           const int16_t *chrFilter, const int16_t **chrUSrc,
472 472
                                           const int16_t **chrVSrc,
473 473
                                           int chrFilterSize, const int16_t **alpSrc,
474
-                                          uint8_t *dest, long dstW, long dstY)
474
+                                          uint8_t *dest, int dstW, int dstY)
475 475
 {
476 476
     x86_reg dummy=0;
477 477
     x86_reg dstW_reg = dstW;
... ...
@@ -504,7 +504,7 @@ static inline void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter,
504 504
                                        const int16_t *chrFilter, const int16_t **chrUSrc,
505 505
                                        const int16_t **chrVSrc,
506 506
                                        int chrFilterSize, const int16_t **alpSrc,
507
-                                       uint8_t *dest, long dstW, long dstY)
507
+                                       uint8_t *dest, int dstW, int dstY)
508 508
 {
509 509
     x86_reg dummy=0;
510 510
     x86_reg dstW_reg = dstW;
... ...
@@ -561,7 +561,7 @@ static inline void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilt
561 561
                                            const int16_t *chrFilter, const int16_t **chrUSrc,
562 562
                                            const int16_t **chrVSrc,
563 563
                                            int chrFilterSize, const int16_t **alpSrc,
564
-                                           uint8_t *dest, long dstW, long dstY)
564
+                                           uint8_t *dest, int dstW, int dstY)
565 565
 {
566 566
     x86_reg dummy=0;
567 567
     x86_reg dstW_reg = dstW;
... ...
@@ -585,7 +585,7 @@ static inline void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter,
585 585
                                         const int16_t *chrFilter, const int16_t **chrUSrc,
586 586
                                         const int16_t **chrVSrc,
587 587
                                         int chrFilterSize, const int16_t **alpSrc,
588
-                                        uint8_t *dest, long dstW, long dstY)
588
+                                        uint8_t *dest, int dstW, int dstY)
589 589
 {
590 590
     x86_reg dummy=0;
591 591
     x86_reg dstW_reg = dstW;
... ...
@@ -638,7 +638,7 @@ static inline void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilt
638 638
                                            const int16_t *chrFilter, const int16_t **chrUSrc,
639 639
                                            const int16_t **chrVSrc,
640 640
                                            int chrFilterSize, const int16_t **alpSrc,
641
-                                           uint8_t *dest, long dstW, long dstY)
641
+                                           uint8_t *dest, int dstW, int dstY)
642 642
 {
643 643
     x86_reg dummy=0;
644 644
     x86_reg dstW_reg = dstW;
... ...
@@ -662,7 +662,7 @@ static inline void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter,
662 662
                                         const int16_t *chrFilter, const int16_t **chrUSrc,
663 663
                                         const int16_t **chrVSrc,
664 664
                                         int chrFilterSize, const int16_t **alpSrc,
665
-                                        uint8_t *dest, long dstW, long dstY)
665
+                                        uint8_t *dest, int dstW, int dstY)
666 666
 {
667 667
     x86_reg dummy=0;
668 668
     x86_reg dstW_reg = dstW;
... ...
@@ -795,7 +795,7 @@ static inline void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilte
795 795
                                           const int16_t *chrFilter, const int16_t **chrUSrc,
796 796
                                           const int16_t **chrVSrc,
797 797
                                           int chrFilterSize, const int16_t **alpSrc,
798
-                                          uint8_t *dest, long dstW, long dstY)
798
+                                          uint8_t *dest, int dstW, int dstY)
799 799
 {
800 800
     x86_reg dummy=0;
801 801
     x86_reg dstW_reg = dstW;
... ...
@@ -819,7 +819,7 @@ static inline void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter,
819 819
                                        const int16_t *chrFilter, const int16_t **chrUSrc,
820 820
                                        const int16_t **chrVSrc,
821 821
                                        int chrFilterSize, const int16_t **alpSrc,
822
-                                       uint8_t *dest, long dstW, long dstY)
822
+                                       uint8_t *dest, int dstW, int dstY)
823 823
 {
824 824
     x86_reg dummy=0;
825 825
     x86_reg dstW_reg = dstW;
... ...
@@ -860,7 +860,7 @@ static inline void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFil
860 860
                                             const int16_t *chrFilter, const int16_t **chrUSrc,
861 861
                                             const int16_t **chrVSrc,
862 862
                                             int chrFilterSize, const int16_t **alpSrc,
863
-                                            uint8_t *dest, long dstW, long dstY)
863
+                                            uint8_t *dest, int dstW, int dstY)
864 864
 {
865 865
     x86_reg dummy=0;
866 866
     x86_reg dstW_reg = dstW;
... ...
@@ -881,7 +881,7 @@ static inline void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter
881 881
                                          const int16_t *chrFilter, const int16_t **chrUSrc,
882 882
                                          const int16_t **chrVSrc,
883 883
                                          int chrFilterSize, const int16_t **alpSrc,
884
-                                         uint8_t *dest, long dstW, long dstY)
884
+                                         uint8_t *dest, int dstW, int dstY)
885 885
 {
886 886
     x86_reg dummy=0;
887 887
     x86_reg dstW_reg = dstW;
... ...
@@ -897,16 +897,16 @@ static inline void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter
897 897
     YSCALEYUV2PACKEDX_END
898 898
 }
899 899
 
900
-#define REAL_YSCALEYUV2RGB_UV(index, c, uv_off) \
900
+#define REAL_YSCALEYUV2RGB_UV(index, c) \
901 901
     "xor            "#index", "#index"  \n\t"\
902 902
     ".p2align              4            \n\t"\
903 903
     "1:                                 \n\t"\
904 904
     "movq     (%2, "#index"), %%mm2     \n\t" /* uvbuf0[eax]*/\
905 905
     "movq     (%3, "#index"), %%mm3     \n\t" /* uvbuf1[eax]*/\
906
-    "add           "#uv_off", "#index"  \n\t" \
906
+    "add           "UV_OFFx2"("#c"), "#index"  \n\t" \
907 907
     "movq     (%2, "#index"), %%mm5     \n\t" /* uvbuf0[eax+2048]*/\
908 908
     "movq     (%3, "#index"), %%mm4     \n\t" /* uvbuf1[eax+2048]*/\
909
-    "sub           "#uv_off", "#index"  \n\t" \
909
+    "sub           "UV_OFFx2"("#c"), "#index"  \n\t" \
910 910
     "psubw             %%mm3, %%mm2     \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
911 911
     "psubw             %%mm4, %%mm5     \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
912 912
     "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0    \n\t"\
... ...
@@ -969,8 +969,8 @@ static inline void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter
969 969
 
970 970
 #define YSCALEYUV2RGB_YA(index, c, b1, b2) REAL_YSCALEYUV2RGB_YA(index, c, b1, b2)
971 971
 
972
-#define YSCALEYUV2RGB(index, c, uv_off) \
973
-    REAL_YSCALEYUV2RGB_UV(index, c, uv_off) \
972
+#define YSCALEYUV2RGB(index, c) \
973
+    REAL_YSCALEYUV2RGB_UV(index, c) \
974 974
     REAL_YSCALEYUV2RGB_YA(index, c, %0, %1) \
975 975
     REAL_YSCALEYUV2RGB_COEFF(c)
976 976
 
... ...
@@ -984,12 +984,10 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0,
984 984
                                        const uint16_t *abuf1, uint8_t *dest,
985 985
                                        int dstW, int yalpha, int uvalpha, int y)
986 986
 {
987
-    x86_reg uv_off = c->uv_off << 1;
988
-
989 987
     if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
990 988
 #if ARCH_X86_64
991 989
         __asm__ volatile(
992
-            YSCALEYUV2RGB(%%r8, %5, %8)
990
+            YSCALEYUV2RGB(%%r8, %5)
993 991
             YSCALEYUV2RGB_YA(%%r8, %5, %6, %7)
994 992
             "psraw                  $3, %%mm1       \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
995 993
             "psraw                  $3, %%mm7       \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
... ...
@@ -997,7 +995,7 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0,
997 997
             WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
998 998
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "r" (dest),
999 999
                "a" (&c->redDither),
1000
-               "r" (abuf0), "r" (abuf1), "m"(uv_off)
1000
+               "r" (abuf0), "r" (abuf1)
1001 1001
             : "%r8"
1002 1002
         );
1003 1003
 #else
... ...
@@ -1007,7 +1005,7 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0,
1007 1007
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1008 1008
             "mov        %4, %%"REG_b"               \n\t"
1009 1009
             "push %%"REG_BP"                        \n\t"
1010
-            YSCALEYUV2RGB(%%REGBP, %5, %6)
1010
+            YSCALEYUV2RGB(%%REGBP, %5)
1011 1011
             "push                   %0              \n\t"
1012 1012
             "push                   %1              \n\t"
1013 1013
             "mov          "U_TEMP"(%5), %0          \n\t"
... ...
@@ -1022,7 +1020,7 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0,
1022 1022
             "pop %%"REG_BP"                         \n\t"
1023 1023
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1024 1024
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1025
-               "a" (&c->redDither), "m"(uv_off)
1025
+               "a" (&c->redDither)
1026 1026
         );
1027 1027
 #endif
1028 1028
     } else {
... ...
@@ -1030,13 +1028,13 @@ static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0,
1030 1030
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1031 1031
             "mov        %4, %%"REG_b"               \n\t"
1032 1032
             "push %%"REG_BP"                        \n\t"
1033
-            YSCALEYUV2RGB(%%REGBP, %5, %6)
1033
+            YSCALEYUV2RGB(%%REGBP, %5)
1034 1034
             "pcmpeqd %%mm7, %%mm7                   \n\t"
1035 1035
             WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1036 1036
             "pop %%"REG_BP"                         \n\t"
1037 1037
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1038 1038
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1039
-               "a" (&c->redDither), "m"(uv_off)
1039
+               "a" (&c->redDither)
1040 1040
         );
1041 1041
     }
1042 1042
 }
... ...
@@ -1048,20 +1046,18 @@ static inline void RENAME(yuv2bgr24_2)(SwsContext *c, const uint16_t *buf0,
1048 1048
                                        const uint16_t *abuf1, uint8_t *dest,
1049 1049
                                        int dstW, int yalpha, int uvalpha, int y)
1050 1050
 {
1051
-    x86_reg uv_off = c->uv_off << 1;
1052
-
1053 1051
     //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1054 1052
     __asm__ volatile(
1055 1053
         "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1056 1054
         "mov        %4, %%"REG_b"               \n\t"
1057 1055
         "push %%"REG_BP"                        \n\t"
1058
-        YSCALEYUV2RGB(%%REGBP, %5, %6)
1056
+        YSCALEYUV2RGB(%%REGBP, %5)
1059 1057
         "pxor    %%mm7, %%mm7                   \n\t"
1060 1058
         WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
1061 1059
         "pop %%"REG_BP"                         \n\t"
1062 1060
         "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1063 1061
         :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1064
-           "a" (&c->redDither), "m"(uv_off)
1062
+           "a" (&c->redDither)
1065 1063
     );
1066 1064
 }
1067 1065
 
... ...
@@ -1072,14 +1068,12 @@ static inline void RENAME(yuv2rgb555_2)(SwsContext *c, const uint16_t *buf0,
1072 1072
                                         const uint16_t *abuf1, uint8_t *dest,
1073 1073
                                         int dstW, int yalpha, int uvalpha, int y)
1074 1074
 {
1075
-    x86_reg uv_off = c->uv_off << 1;
1076
-
1077 1075
     //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1078 1076
     __asm__ volatile(
1079 1077
         "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1080 1078
         "mov        %4, %%"REG_b"               \n\t"
1081 1079
         "push %%"REG_BP"                        \n\t"
1082
-        YSCALEYUV2RGB(%%REGBP, %5, %6)
1080
+        YSCALEYUV2RGB(%%REGBP, %5)
1083 1081
         "pxor    %%mm7, %%mm7                   \n\t"
1084 1082
         /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1085 1083
 #ifdef DITHER1XBPP
... ...
@@ -1091,7 +1085,7 @@ static inline void RENAME(yuv2rgb555_2)(SwsContext *c, const uint16_t *buf0,
1091 1091
         "pop %%"REG_BP"                         \n\t"
1092 1092
         "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1093 1093
         :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1094
-           "a" (&c->redDither), "m"(uv_off)
1094
+           "a" (&c->redDither)
1095 1095
     );
1096 1096
 }
1097 1097
 
... ...
@@ -1102,14 +1096,12 @@ static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0,
1102 1102
                                         const uint16_t *abuf1, uint8_t *dest,
1103 1103
                                         int dstW, int yalpha, int uvalpha, int y)
1104 1104
 {
1105
-    x86_reg uv_off = c->uv_off << 1;
1106
-
1107 1105
     //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1108 1106
     __asm__ volatile(
1109 1107
         "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1110 1108
         "mov        %4, %%"REG_b"               \n\t"
1111 1109
         "push %%"REG_BP"                        \n\t"
1112
-        YSCALEYUV2RGB(%%REGBP, %5, %6)
1110
+        YSCALEYUV2RGB(%%REGBP, %5)
1113 1111
         "pxor    %%mm7, %%mm7                   \n\t"
1114 1112
         /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1115 1113
 #ifdef DITHER1XBPP
... ...
@@ -1121,11 +1113,11 @@ static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0,
1121 1121
         "pop %%"REG_BP"                         \n\t"
1122 1122
         "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1123 1123
         :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1124
-           "a" (&c->redDither), "m"(uv_off)
1124
+           "a" (&c->redDither)
1125 1125
     );
1126 1126
 }
1127 1127
 
1128
-#define REAL_YSCALEYUV2PACKED(index, c, uv_off) \
1128
+#define REAL_YSCALEYUV2PACKED(index, c) \
1129 1129
     "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0              \n\t"\
1130 1130
     "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1              \n\t"\
1131 1131
     "psraw                $3, %%mm0                           \n\t"\
... ...
@@ -1137,10 +1129,10 @@ static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0,
1137 1137
     "1:                                 \n\t"\
1138 1138
     "movq     (%2, "#index"), %%mm2     \n\t" /* uvbuf0[eax]*/\
1139 1139
     "movq     (%3, "#index"), %%mm3     \n\t" /* uvbuf1[eax]*/\
1140
-    "add           "#uv_off", "#index"  \n\t" \
1140
+    "add           "UV_OFFx2"("#c"), "#index"  \n\t" \
1141 1141
     "movq     (%2, "#index"), %%mm5     \n\t" /* uvbuf0[eax+2048]*/\
1142 1142
     "movq     (%3, "#index"), %%mm4     \n\t" /* uvbuf1[eax+2048]*/\
1143
-    "sub           "#uv_off", "#index"  \n\t" \
1143
+    "sub           "UV_OFFx2"("#c"), "#index"  \n\t" \
1144 1144
     "psubw             %%mm3, %%mm2     \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
1145 1145
     "psubw             %%mm4, %%mm5     \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
1146 1146
     "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0    \n\t"\
... ...
@@ -1163,7 +1155,7 @@ static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0,
1163 1163
     "paddw             %%mm0, %%mm1     \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
1164 1164
     "paddw             %%mm6, %%mm7     \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
1165 1165
 
1166
-#define YSCALEYUV2PACKED(index, c, uv_off)  REAL_YSCALEYUV2PACKED(index, c, uv_off)
1166
+#define YSCALEYUV2PACKED(index, c)  REAL_YSCALEYUV2PACKED(index, c)
1167 1167
 
1168 1168
 static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0,
1169 1169
                                          const uint16_t *buf1, const uint16_t *ubuf0,
... ...
@@ -1172,30 +1164,28 @@ static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0,
1172 1172
                                          const uint16_t *abuf1, uint8_t *dest,
1173 1173
                                          int dstW, int yalpha, int uvalpha, int y)
1174 1174
 {
1175
-    x86_reg uv_off = c->uv_off << 1;
1176
-
1177 1175
     //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1178 1176
     __asm__ volatile(
1179 1177
         "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1180 1178
         "mov %4, %%"REG_b"                        \n\t"
1181 1179
         "push %%"REG_BP"                        \n\t"
1182
-        YSCALEYUV2PACKED(%%REGBP, %5, %6)
1180
+        YSCALEYUV2PACKED(%%REGBP, %5)
1183 1181
         WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
1184 1182
         "pop %%"REG_BP"                         \n\t"
1185 1183
         "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1186 1184
         :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1187
-           "a" (&c->redDither), "m"(uv_off)
1185
+           "a" (&c->redDither)
1188 1186
     );
1189 1187
 }
1190 1188
 
1191
-#define REAL_YSCALEYUV2RGB1(index, c, uv_off) \
1189
+#define REAL_YSCALEYUV2RGB1(index, c) \
1192 1190
     "xor            "#index", "#index"  \n\t"\
1193 1191
     ".p2align              4            \n\t"\
1194 1192
     "1:                                 \n\t"\
1195 1193
     "movq     (%2, "#index"), %%mm3     \n\t" /* uvbuf0[eax]*/\
1196
-    "add           "#uv_off", "#index"  \n\t" \
1194
+    "add           "UV_OFFx2"("#c"), "#index"  \n\t" \
1197 1195
     "movq     (%2, "#index"), %%mm4     \n\t" /* uvbuf0[eax+2048]*/\
1198
-    "sub           "#uv_off", "#index"  \n\t" \
1196
+    "sub           "UV_OFFx2"("#c"), "#index"  \n\t" \
1199 1197
     "psraw                $4, %%mm3     \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
1200 1198
     "psraw                $4, %%mm4     \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
1201 1199
     "psubw  "U_OFFSET"("#c"), %%mm3     \n\t" /* (U-128)8*/\
... ...
@@ -1237,19 +1227,19 @@ static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0,
1237 1237
     "packuswb          %%mm6, %%mm5     \n\t"\
1238 1238
     "packuswb          %%mm3, %%mm4     \n\t"\
1239 1239
 
1240
-#define YSCALEYUV2RGB1(index, c, uv_off)  REAL_YSCALEYUV2RGB1(index, c, uv_off)
1240
+#define YSCALEYUV2RGB1(index, c)  REAL_YSCALEYUV2RGB1(index, c)
1241 1241
 
1242 1242
 // do vertical chrominance interpolation
1243
-#define REAL_YSCALEYUV2RGB1b(index, c, uv_off) \
1243
+#define REAL_YSCALEYUV2RGB1b(index, c) \
1244 1244
     "xor            "#index", "#index"  \n\t"\
1245 1245
     ".p2align              4            \n\t"\
1246 1246
     "1:                                 \n\t"\
1247 1247
     "movq     (%2, "#index"), %%mm2     \n\t" /* uvbuf0[eax]*/\
1248 1248
     "movq     (%3, "#index"), %%mm3     \n\t" /* uvbuf1[eax]*/\
1249
-    "add           "#uv_off", "#index"  \n\t" \
1249
+    "add           "UV_OFFx2"("#c"), "#index"  \n\t" \
1250 1250
     "movq     (%2, "#index"), %%mm5     \n\t" /* uvbuf0[eax+2048]*/\
1251 1251
     "movq     (%3, "#index"), %%mm4     \n\t" /* uvbuf1[eax+2048]*/\
1252
-    "sub           "#uv_off", "#index"  \n\t" \
1252
+    "sub           "UV_OFFx2"("#c"), "#index"  \n\t" \
1253 1253
     "paddw             %%mm2, %%mm3     \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
1254 1254
     "paddw             %%mm5, %%mm4     \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
1255 1255
     "psrlw                $5, %%mm3     \n\t" /*FIXME might overflow*/\
... ...
@@ -1293,7 +1283,7 @@ static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0,
1293 1293
     "packuswb          %%mm6, %%mm5     \n\t"\
1294 1294
     "packuswb          %%mm3, %%mm4     \n\t"\
1295 1295
 
1296
-#define YSCALEYUV2RGB1b(index, c, uv_off)  REAL_YSCALEYUV2RGB1b(index, c, uv_off)
1296
+#define YSCALEYUV2RGB1b(index, c)  REAL_YSCALEYUV2RGB1b(index, c)
1297 1297
 
1298 1298
 #define REAL_YSCALEYUV2RGB1_ALPHA(index) \
1299 1299
     "movq  (%1, "#index", 2), %%mm7     \n\t" /* abuf0[index  ]     */\
... ...
@@ -1313,7 +1303,6 @@ static inline void RENAME(yuv2rgb32_1)(SwsContext *c, const uint16_t *buf0,
1313 1313
                                        int dstW, int uvalpha, enum PixelFormat dstFormat,
1314 1314
                                        int flags, int y)
1315 1315
 {
1316
-    x86_reg uv_off = c->uv_off << 1;
1317 1316
     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1318 1317
 
1319 1318
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
... ...
@@ -1322,26 +1311,26 @@ static inline void RENAME(yuv2rgb32_1)(SwsContext *c, const uint16_t *buf0,
1322 1322
                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1323 1323
                 "mov        %4, %%"REG_b"               \n\t"
1324 1324
                 "push %%"REG_BP"                        \n\t"
1325
-                YSCALEYUV2RGB1(%%REGBP, %5, %6)
1325
+                YSCALEYUV2RGB1(%%REGBP, %5)
1326 1326
                 YSCALEYUV2RGB1_ALPHA(%%REGBP)
1327 1327
                 WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1328 1328
                 "pop %%"REG_BP"                         \n\t"
1329 1329
                 "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1330 1330
                 :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1331
-                   "a" (&c->redDither), "m"(uv_off)
1331
+                   "a" (&c->redDither)
1332 1332
             );
1333 1333
         } else {
1334 1334
             __asm__ volatile(
1335 1335
                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1336 1336
                 "mov        %4, %%"REG_b"               \n\t"
1337 1337
                 "push %%"REG_BP"                        \n\t"
1338
-                YSCALEYUV2RGB1(%%REGBP, %5, %6)
1338
+                YSCALEYUV2RGB1(%%REGBP, %5)
1339 1339
                 "pcmpeqd %%mm7, %%mm7                   \n\t"
1340 1340
                 WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1341 1341
                 "pop %%"REG_BP"                         \n\t"
1342 1342
                 "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1343 1343
                 :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1344
-                   "a" (&c->redDither), "m"(uv_off)
1344
+                   "a" (&c->redDither)
1345 1345
             );
1346 1346
         }
1347 1347
     } else {
... ...
@@ -1350,26 +1339,26 @@ static inline void RENAME(yuv2rgb32_1)(SwsContext *c, const uint16_t *buf0,
1350 1350
                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1351 1351
                 "mov        %4, %%"REG_b"               \n\t"
1352 1352
                 "push %%"REG_BP"                        \n\t"
1353
-                YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1353
+                YSCALEYUV2RGB1b(%%REGBP, %5)
1354 1354
                 YSCALEYUV2RGB1_ALPHA(%%REGBP)
1355 1355
                 WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1356 1356
                 "pop %%"REG_BP"                         \n\t"
1357 1357
                 "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1358 1358
                 :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1359
-                   "a" (&c->redDither), "m"(uv_off)
1359
+                   "a" (&c->redDither)
1360 1360
             );
1361 1361
         } else {
1362 1362
             __asm__ volatile(
1363 1363
                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1364 1364
                 "mov        %4, %%"REG_b"               \n\t"
1365 1365
                 "push %%"REG_BP"                        \n\t"
1366
-                YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1366
+                YSCALEYUV2RGB1b(%%REGBP, %5)
1367 1367
                 "pcmpeqd %%mm7, %%mm7                   \n\t"
1368 1368
                 WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1369 1369
                 "pop %%"REG_BP"                         \n\t"
1370 1370
                 "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1371 1371
                 :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1372
-                   "a" (&c->redDither), "m"(uv_off)
1372
+                   "a" (&c->redDither)
1373 1373
             );
1374 1374
         }
1375 1375
     }
... ...
@@ -1382,7 +1371,6 @@ static inline void RENAME(yuv2bgr24_1)(SwsContext *c, const uint16_t *buf0,
1382 1382
                                        int dstW, int uvalpha, enum PixelFormat dstFormat,
1383 1383
                                        int flags, int y)
1384 1384
 {
1385
-    x86_reg uv_off = c->uv_off << 1;
1386 1385
     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1387 1386
 
1388 1387
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
... ...
@@ -1390,26 +1378,26 @@ static inline void RENAME(yuv2bgr24_1)(SwsContext *c, const uint16_t *buf0,
1390 1390
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1391 1391
             "mov        %4, %%"REG_b"               \n\t"
1392 1392
             "push %%"REG_BP"                        \n\t"
1393
-            YSCALEYUV2RGB1(%%REGBP, %5, %6)
1393
+            YSCALEYUV2RGB1(%%REGBP, %5)
1394 1394
             "pxor    %%mm7, %%mm7                   \n\t"
1395 1395
             WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
1396 1396
             "pop %%"REG_BP"                         \n\t"
1397 1397
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1398 1398
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1399
-               "a" (&c->redDither), "m"(uv_off)
1399
+               "a" (&c->redDither)
1400 1400
         );
1401 1401
     } else {
1402 1402
         __asm__ volatile(
1403 1403
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1404 1404
             "mov        %4, %%"REG_b"               \n\t"
1405 1405
             "push %%"REG_BP"                        \n\t"
1406
-            YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1406
+            YSCALEYUV2RGB1b(%%REGBP, %5)
1407 1407
             "pxor    %%mm7, %%mm7                   \n\t"
1408 1408
             WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
1409 1409
             "pop %%"REG_BP"                         \n\t"
1410 1410
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1411 1411
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1412
-               "a" (&c->redDither), "m"(uv_off)
1412
+               "a" (&c->redDither)
1413 1413
         );
1414 1414
     }
1415 1415
 }
... ...
@@ -1421,7 +1409,6 @@ static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0,
1421 1421
                                         int dstW, int uvalpha, enum PixelFormat dstFormat,
1422 1422
                                         int flags, int y)
1423 1423
 {
1424
-    x86_reg uv_off = c->uv_off << 1;
1425 1424
     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1426 1425
 
1427 1426
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
... ...
@@ -1429,7 +1416,7 @@ static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0,
1429 1429
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1430 1430
             "mov        %4, %%"REG_b"               \n\t"
1431 1431
             "push %%"REG_BP"                        \n\t"
1432
-            YSCALEYUV2RGB1(%%REGBP, %5, %6)
1432
+            YSCALEYUV2RGB1(%%REGBP, %5)
1433 1433
             "pxor    %%mm7, %%mm7                   \n\t"
1434 1434
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1435 1435
 #ifdef DITHER1XBPP
... ...
@@ -1441,14 +1428,14 @@ static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0,
1441 1441
             "pop %%"REG_BP"                         \n\t"
1442 1442
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1443 1443
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1444
-               "a" (&c->redDither), "m"(uv_off)
1444
+               "a" (&c->redDither)
1445 1445
         );
1446 1446
     } else {
1447 1447
         __asm__ volatile(
1448 1448
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1449 1449
             "mov        %4, %%"REG_b"               \n\t"
1450 1450
             "push %%"REG_BP"                        \n\t"
1451
-            YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1451
+            YSCALEYUV2RGB1b(%%REGBP, %5)
1452 1452
             "pxor    %%mm7, %%mm7                   \n\t"
1453 1453
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1454 1454
 #ifdef DITHER1XBPP
... ...
@@ -1460,7 +1447,7 @@ static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0,
1460 1460
             "pop %%"REG_BP"                         \n\t"
1461 1461
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1462 1462
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1463
-               "a" (&c->redDither), "m"(uv_off)
1463
+               "a" (&c->redDither)
1464 1464
         );
1465 1465
     }
1466 1466
 }
... ...
@@ -1472,7 +1459,6 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0,
1472 1472
                                         int dstW, int uvalpha, enum PixelFormat dstFormat,
1473 1473
                                         int flags, int y)
1474 1474
 {
1475
-    x86_reg uv_off = c->uv_off << 1;
1476 1475
     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1477 1476
 
1478 1477
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
... ...
@@ -1480,7 +1466,7 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0,
1480 1480
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1481 1481
             "mov        %4, %%"REG_b"               \n\t"
1482 1482
             "push %%"REG_BP"                        \n\t"
1483
-            YSCALEYUV2RGB1(%%REGBP, %5, %6)
1483
+            YSCALEYUV2RGB1(%%REGBP, %5)
1484 1484
             "pxor    %%mm7, %%mm7                   \n\t"
1485 1485
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1486 1486
 #ifdef DITHER1XBPP
... ...
@@ -1492,14 +1478,14 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0,
1492 1492
             "pop %%"REG_BP"                         \n\t"
1493 1493
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1494 1494
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1495
-               "a" (&c->redDither), "m"(uv_off)
1495
+               "a" (&c->redDither)
1496 1496
         );
1497 1497
     } else {
1498 1498
         __asm__ volatile(
1499 1499
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1500 1500
             "mov        %4, %%"REG_b"               \n\t"
1501 1501
             "push %%"REG_BP"                        \n\t"
1502
-            YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1502
+            YSCALEYUV2RGB1b(%%REGBP, %5)
1503 1503
             "pxor    %%mm7, %%mm7                   \n\t"
1504 1504
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1505 1505
 #ifdef DITHER1XBPP
... ...
@@ -1511,19 +1497,19 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0,
1511 1511
             "pop %%"REG_BP"                         \n\t"
1512 1512
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1513 1513
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1514
-               "a" (&c->redDither), "m"(uv_off)
1514
+               "a" (&c->redDither)
1515 1515
         );
1516 1516
     }
1517 1517
 }
1518 1518
 
1519
-#define REAL_YSCALEYUV2PACKED1(index, c, uv_off) \
1519
+#define REAL_YSCALEYUV2PACKED1(index, c) \
1520 1520
     "xor            "#index", "#index"  \n\t"\
1521 1521
     ".p2align              4            \n\t"\
1522 1522
     "1:                                 \n\t"\
1523 1523
     "movq     (%2, "#index"), %%mm3     \n\t" /* uvbuf0[eax]*/\
1524
-    "add           "#uv_off", "#index"  \n\t" \
1524
+    "add           "UV_OFFx2"("#c"), "#index"  \n\t" \
1525 1525
     "movq     (%2, "#index"), %%mm4     \n\t" /* uvbuf0[eax+2048]*/\
1526
-    "sub           "#uv_off", "#index"  \n\t" \
1526
+    "sub           "UV_OFFx2"("#c"), "#index"  \n\t" \
1527 1527
     "psraw                $7, %%mm3     \n\t" \
1528 1528
     "psraw                $7, %%mm4     \n\t" \
1529 1529
     "movq  (%0, "#index", 2), %%mm1     \n\t" /*buf0[eax]*/\
... ...
@@ -1531,18 +1517,18 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0,
1531 1531
     "psraw                $7, %%mm1     \n\t" \
1532 1532
     "psraw                $7, %%mm7     \n\t" \
1533 1533
 
1534
-#define YSCALEYUV2PACKED1(index, c, uv_off)  REAL_YSCALEYUV2PACKED1(index, c, uv_off)
1534
+#define YSCALEYUV2PACKED1(index, c)  REAL_YSCALEYUV2PACKED1(index, c)
1535 1535
 
1536
-#define REAL_YSCALEYUV2PACKED1b(index, c, uv_off) \
1536
+#define REAL_YSCALEYUV2PACKED1b(index, c) \
1537 1537
     "xor "#index", "#index"             \n\t"\
1538 1538
     ".p2align              4            \n\t"\
1539 1539
     "1:                                 \n\t"\
1540 1540
     "movq     (%2, "#index"), %%mm2     \n\t" /* uvbuf0[eax]*/\
1541 1541
     "movq     (%3, "#index"), %%mm3     \n\t" /* uvbuf1[eax]*/\
1542
-    "add           "#uv_off", "#index"  \n\t" \
1542
+    "add           "UV_OFFx2"("#c"), "#index"  \n\t" \
1543 1543
     "movq     (%2, "#index"), %%mm5     \n\t" /* uvbuf0[eax+2048]*/\
1544 1544
     "movq     (%3, "#index"), %%mm4     \n\t" /* uvbuf1[eax+2048]*/\
1545
-    "sub           "#uv_off", "#index"  \n\t" \
1545
+    "sub           "UV_OFFx2"("#c"), "#index"  \n\t" \
1546 1546
     "paddw             %%mm2, %%mm3     \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
1547 1547
     "paddw             %%mm5, %%mm4     \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
1548 1548
     "psrlw                $8, %%mm3     \n\t" \
... ...
@@ -1551,7 +1537,7 @@ static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0,
1551 1551
     "movq 8(%0, "#index", 2), %%mm7     \n\t" /*buf0[eax]*/\
1552 1552
     "psraw                $7, %%mm1     \n\t" \
1553 1553
     "psraw                $7, %%mm7     \n\t"
1554
-#define YSCALEYUV2PACKED1b(index, c, uv_off)  REAL_YSCALEYUV2PACKED1b(index, c, uv_off)
1554
+#define YSCALEYUV2PACKED1b(index, c)  REAL_YSCALEYUV2PACKED1b(index, c)
1555 1555
 
1556 1556
 static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0,
1557 1557
                                          const uint16_t *ubuf0, const uint16_t *ubuf1,
... ...
@@ -1560,7 +1546,6 @@ static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0,
1560 1560
                                          int dstW, int uvalpha, enum PixelFormat dstFormat,
1561 1561
                                          int flags, int y)
1562 1562
 {
1563
-    x86_reg uv_off = c->uv_off << 1;
1564 1563
     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1565 1564
 
1566 1565
     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
... ...
@@ -1568,24 +1553,24 @@ static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0,
1568 1568
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1569 1569
             "mov        %4, %%"REG_b"               \n\t"
1570 1570
             "push %%"REG_BP"                        \n\t"
1571
-            YSCALEYUV2PACKED1(%%REGBP, %5, %6)
1571
+            YSCALEYUV2PACKED1(%%REGBP, %5)
1572 1572
             WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
1573 1573
             "pop %%"REG_BP"                         \n\t"
1574 1574
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1575 1575
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1576
-               "a" (&c->redDither), "m"(uv_off)
1576
+               "a" (&c->redDither)
1577 1577
         );
1578 1578
     } else {
1579 1579
         __asm__ volatile(
1580 1580
             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1581 1581
             "mov        %4, %%"REG_b"               \n\t"
1582 1582
             "push %%"REG_BP"                        \n\t"
1583
-            YSCALEYUV2PACKED1b(%%REGBP, %5, %6)
1583
+            YSCALEYUV2PACKED1b(%%REGBP, %5)
1584 1584
             WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
1585 1585
             "pop %%"REG_BP"                         \n\t"
1586 1586
             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1587 1587
             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1588
-               "a" (&c->redDither), "m"(uv_off)
1588
+               "a" (&c->redDither)
1589 1589
         );
1590 1590
     }
1591 1591
 }
... ...
@@ -1593,7 +1578,7 @@ static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0,
1593 1593
 #if !COMPILE_TEMPLATE_MMX2
1594 1594
 //FIXME yuy2* can read up to 7 samples too much
1595 1595
 
1596
-static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1596
+static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
1597 1597
 {
1598 1598
     __asm__ volatile(
1599 1599
         "movq "MANGLE(bm01010101)", %%mm2           \n\t"
... ...
@@ -1612,7 +1597,7 @@ static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, long width,
1612 1612
     );
1613 1613
 }
1614 1614
 
1615
-static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1615
+static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
1616 1616
 {
1617 1617
     __asm__ volatile(
1618 1618
         "movq "MANGLE(bm01010101)", %%mm4           \n\t"
... ...
@@ -1638,7 +1623,7 @@ static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t
1638 1638
     assert(src1 == src2);
1639 1639
 }
1640 1640
 
1641
-static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1641
+static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
1642 1642
 {
1643 1643
     __asm__ volatile(
1644 1644
         "mov                    %0, %%"REG_a"       \n\t"
... ...
@@ -1664,7 +1649,7 @@ static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *s
1664 1664
 
1665 1665
 /* This is almost identical to the previous, end exists only because
1666 1666
  * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
1667
-static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1667
+static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
1668 1668
 {
1669 1669
     __asm__ volatile(
1670 1670
         "mov                  %0, %%"REG_a"         \n\t"
... ...
@@ -1682,7 +1667,7 @@ static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, long width,
1682 1682
     );
1683 1683
 }
1684 1684
 
1685
-static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1685
+static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
1686 1686
 {
1687 1687
     __asm__ volatile(
1688 1688
         "movq "MANGLE(bm01010101)", %%mm4           \n\t"
... ...
@@ -1708,7 +1693,7 @@ static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t
1708 1708
     assert(src1 == src2);
1709 1709
 }
1710 1710
 
1711
-static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1711
+static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
1712 1712
 {
1713 1713
     __asm__ volatile(
1714 1714
         "movq "MANGLE(bm01010101)", %%mm4           \n\t"
... ...
@@ -1734,7 +1719,7 @@ static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *s
1734 1734
 }
1735 1735
 
1736 1736
 static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2,
1737
-                                    const uint8_t *src, long width)
1737
+                                    const uint8_t *src, int width)
1738 1738
 {
1739 1739
     __asm__ volatile(
1740 1740
         "movq "MANGLE(bm01010101)", %%mm4           \n\t"
... ...
@@ -1761,20 +1746,20 @@ static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2,
1761 1761
 
1762 1762
 static inline void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV,
1763 1763
                                     const uint8_t *src1, const uint8_t *src2,
1764
-                                    long width, uint32_t *unused)
1764
+                                    int width, uint32_t *unused)
1765 1765
 {
1766 1766
     RENAME(nvXXtoUV)(dstU, dstV, src1, width);
1767 1767
 }
1768 1768
 
1769 1769
 static inline void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV,
1770 1770
                                     const uint8_t *src1, const uint8_t *src2,
1771
-                                    long width, uint32_t *unused)
1771
+                                    int width, uint32_t *unused)
1772 1772
 {
1773 1773
     RENAME(nvXXtoUV)(dstV, dstU, src1, width);
1774 1774
 }
1775 1775
 #endif /* !COMPILE_TEMPLATE_MMX2 */
1776 1776
 
1777
-static inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src, long width, enum PixelFormat srcFormat)
1777
+static inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src, int width, enum PixelFormat srcFormat)
1778 1778
 {
1779 1779
 
1780 1780
     if(srcFormat == PIX_FMT_BGR24) {
... ...
@@ -1826,7 +1811,7 @@ static inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src, long w
1826 1826
     );
1827 1827
 }
1828 1828
 
1829
-static inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV, const uint8_t *src, long width, enum PixelFormat srcFormat)
1829
+static inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV, const uint8_t *src, int width, enum PixelFormat srcFormat)
1830 1830
 {
1831 1831
     __asm__ volatile(
1832 1832
         "movq                    24(%4), %%mm6       \n\t"
... ...
@@ -1882,23 +1867,23 @@ static inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV, const uin
1882 1882
     );
1883 1883
 }
1884 1884
 
1885
-static inline void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
1885
+static inline void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
1886 1886
 {
1887 1887
     RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
1888 1888
 }
1889 1889
 
1890
-static inline void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1890
+static inline void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
1891 1891
 {
1892 1892
     RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
1893 1893
     assert(src1 == src2);
1894 1894
 }
1895 1895
 
1896
-static inline void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src, long width, uint32_t *unused)
1896
+static inline void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src, int width, uint32_t *unused)
1897 1897
 {
1898 1898
     RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
1899 1899
 }
1900 1900
 
1901
-static inline void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1901
+static inline void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused)
1902 1902
 {
1903 1903
     assert(src1==src2);
1904 1904
     RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
... ...
@@ -1907,7 +1892,7 @@ static inline void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV, const uint8_t
1907 1907
 #if !COMPILE_TEMPLATE_MMX2
1908 1908
 // bilinear / bicubic scaling
1909 1909
 static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW, int xInc,
1910
-                                  const int16_t *filter, const int16_t *filterPos, long filterSize)
1910
+                                  const int16_t *filter, const int16_t *filterPos, int filterSize)
1911 1911
 {
1912 1912
     assert(filterSize % 4 == 0 && filterSize>0);
1913 1913
     if (filterSize==4) { // Always true for upscaling, sometimes for down, too.
... ...
@@ -2220,7 +2205,7 @@ static inline void RENAME(hScale16)(int16_t *dst, int dstW, const uint16_t *src,
2220 2220
 
2221 2221
 #if COMPILE_TEMPLATE_MMX2
2222 2222
 static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
2223
-                                        long dstWidth, const uint8_t *src, int srcW,
2223
+                                        int dstWidth, const uint8_t *src, int srcW,
2224 2224
                                         int xInc)
2225 2225
 {
2226 2226
     int32_t *filterPos = c->hLumFilterPos;
... ...
@@ -2292,7 +2277,7 @@ static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
2292 2292
 }
2293 2293
 
2294 2294
 static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2,
2295
-                                        long dstWidth, const uint8_t *src1,
2295
+                                        int dstWidth, const uint8_t *src1,
2296 2296
                                         const uint8_t *src2, int srcW, int xInc)
2297 2297
 {
2298 2298
     int32_t *filterPos = c->hChrFilterPos;