Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master:
rtmp: Add a new option 'rtmp_buffer', for setting the client buffer time
rtmp: Set the client buffer time to 3s instead of 0.26s
rtmp: Handle server bandwidth packets
rtmp: Display a verbose message when an unknown packet type is received
lavfi/audio: use av_samples_copy() instead of custom code.
configure: add all filters hardcoded into avconv to avconv_deps
avfiltergraph: remove a redundant call to avfilter_get_by_name().
lavfi: allow building without swscale.
build: Do not delete tests/vsynth2 directory, which is no longer created.
lavfi: replace AVFilterContext.input/output_count with nb_inputs/outputs
lavfi: make AVFilterPad opaque after two major bumps.
lavfi: add avfilter_pad_get_type() and avfilter_pad_get_name().
lavfi: make avfilter_get_video_buffer() private on next bump.
jack: update to new latency range API as the old one has been deprecated
rtmp: Tokenize the AMF connection parameters manually instead of using strtok_r
ppc: Rename H.264 optimization template file for consistency.
lavfi: add channelsplit audio filter.
golomb: check remaining bits during unary decoding in get_ur_golomb_jpegls()
sws: fix planar RGB input conversions for 9/10/16 bpp.

Conflicts:
Changelog
configure
doc/APIchanges
ffmpeg.c
libavcodec/golomb.h
libavcodec/v210dec.h
libavfilter/Makefile
libavfilter/allfilters.c
libavfilter/asrc_anullsrc.c
libavfilter/audio.c
libavfilter/avfilter.c
libavfilter/avfilter.h
libavfilter/avfiltergraph.c
libavfilter/buffersrc.c
libavfilter/formats.c
libavfilter/version.h
libavfilter/vf_frei0r.c
libavfilter/vf_pad.c
libavfilter/vf_scale.c
libavfilter/video.h
libavfilter/vsrc_color.c
libavformat/rtmpproto.c
libswscale/input.c
tests/Makefile

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

Michael Niedermayer authored on 2012/06/14 04:04:06
Showing 69 changed files
... ...
@@ -50,7 +50,6 @@ tests/rotozoom
50 50
 tests/tiny_psnr
51 51
 tests/videogen
52 52
 tests/vsynth1
53
-tests/vsynth2
54 53
 tools/aviocat
55 54
 tools/cws2fws
56 55
 tools/ffeval
... ...
@@ -5,6 +5,7 @@ version next:
5 5
 - INI and flat output in ffprobe
6 6
 - Scene detection in libavfilter
7 7
 - Indeo Audio decoder
8
+- channelsplit audio filter
8 9
 
9 10
 
10 11
 version 0.11:
... ...
@@ -1210,6 +1210,7 @@ HAVE_LIST="
1210 1210
     inet_aton
1211 1211
     inline_asm
1212 1212
     isatty
1213
+    jack_port_get_latency_range
1213 1214
     kbhit
1214 1215
     ldbrx
1215 1216
     libdc1394_1
... ...
@@ -1730,7 +1731,6 @@ yadif_filter_deps="gpl"
1730 1730
 
1731 1731
 # libraries
1732 1732
 avdevice_deps="avcodec avformat"
1733
-avfilter_deps="swscale"
1734 1733
 avformat_deps="avcodec"
1735 1734
 postproc_deps="gpl"
1736 1735
 
... ...
@@ -3354,7 +3354,8 @@ check_header soundcard.h
3354 3354
 
3355 3355
 enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
3356 3356
 
3357
-enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && check_func sem_timedwait
3357
+enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && check_func sem_timedwait &&
3358
+    check_func jack_port_get_latency_range -ljack
3358 3359
 
3359 3360
 enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
3360 3361
 
... ...
@@ -38,6 +38,15 @@ API changes, most recent first:
38 38
 2012-03-26 - a67d9cf - lavfi 2.66.100
39 39
   Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.
40 40
 
41
+2012-xx-xx - xxxxxxx - lavfi 2.23.0 - avfilter.h
42
+  Add AVFilterContext.nb_inputs/outputs. Deprecate
43
+  AVFilterContext.input/output_count.
44
+
45
+2012-xx-xx - xxxxxxx - lavfi 2.22.0 - avfilter.h
46
+  Add avfilter_pad_get_type() and avfilter_pad_get_name(). Those
47
+  should now be used instead of accessing AVFilterPad members
48
+  directly.
49
+
41 50
 2012-xx-xx - xxxxxxx - lavu 51.32.0 - audioconvert.h
42 51
   Add av_get_channel_layout_channel_index(), av_get_channel_name()
43 52
   and av_channel_layout_extract_channel().
... ...
@@ -576,6 +576,31 @@ Maximum compensation in samples per second.
576 576
 
577 577
 @end table
578 578
 
579
+@section channelsplit
580
+Split each channel in input audio stream into a separate output stream.
581
+
582
+This filter accepts the following named parameters:
583
+@table @option
584
+@item channel_layout
585
+Channel layout of the input stream. Default is "stereo".
586
+@end table
587
+
588
+For example, assuming a stereo input MP3 file
589
+@example
590
+ffmpeg -i in.mp3 -filter_complex channelsplit out.mkv
591
+@end example
592
+will create an output Matroska file with two audio streams, one containing only
593
+the left channel and the other the right channel.
594
+
595
+To split a 5.1 WAV file into per-channel files
596
+@example
597
+ffmpeg -i in.wav -filter_complex
598
+'channelsplit=channel_layout=5.1[FL][FR][FC][LFE][SL][SR]'
599
+-map '[FL]' front_left.wav -map '[FR]' front_right.wav -map '[FC]'
600
+front_center.wav -map '[LFE]' lfe.wav -map '[SL]' side_left.wav -map '[SR]'
601
+side_right.wav
602
+@end example
603
+
579 604
 @section resample
580 605
 Convert the audio sample format, sample rate and channel layout. This filter is
581 606
 not meant to be used directly.
... ...
@@ -228,6 +228,9 @@ Additionally, the following parameters can be set via command line options
228 228
 Name of application to connect on the RTMP server. This option
229 229
 overrides the parameter specified in the URI.
230 230
 
231
+@item rtmp_buffer
232
+Set the client buffer time in milliseconds. The default is 3000.
233
+
231 234
 @item rtmp_conn
232 235
 Extra arbitrary AMF connection parameters, parsed from a string,
233 236
 e.g. like @code{B:1 S:authMe O:1 NN:code:1.23 NS:flag:ok O:0}.
... ...
@@ -708,7 +708,7 @@ static FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost)
708 708
 static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
709 709
 {
710 710
     InputStream *ist = NULL;
711
-    enum AVMediaType type = in->filter_ctx->input_pads[in->pad_idx].type;
711
+    enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);
712 712
     int i;
713 713
 
714 714
     // TODO: support other filter types
... ...
@@ -978,7 +978,7 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
978 978
                                                                    \
979 979
     avio_printf(pb, "%s", ctx->filter->name);                      \
980 980
     if (nb_pads > 1)                                               \
981
-        avio_printf(pb, ":%s", pads[inout->pad_idx].name);         \
981
+        avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
982 982
     avio_w8(pb, 0);                                                \
983 983
     avio_close_dyn_buf(pb, &f->name);                              \
984 984
 }
... ...
@@ -988,7 +988,7 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFil
988 988
     av_freep(&ofilter->name);
989 989
     DESCRIBE_FILTER_LINK(ofilter, out, 0);
990 990
 
991
-    switch (out->filter_ctx->output_pads[out->pad_idx].type) {
991
+    switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
992 992
     case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
993 993
     case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
994 994
     default: av_assert0(0);
... ...
@@ -1132,7 +1132,7 @@ static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter,
1132 1132
     av_freep(&ifilter->name);
1133 1133
     DESCRIBE_FILTER_LINK(ifilter, in, 1);
1134 1134
 
1135
-    switch (in->filter_ctx->input_pads[in->pad_idx].type) {
1135
+    switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
1136 1136
     case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
1137 1137
     case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
1138 1138
     default: av_assert0(0);
... ...
@@ -4899,7 +4899,8 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o,
4899 4899
 {
4900 4900
     OutputStream *ost;
4901 4901
 
4902
-    switch (ofilter->out_tmp->filter_ctx->output_pads[ofilter->out_tmp->pad_idx].type) {
4902
+    switch (avfilter_pad_get_type(ofilter->out_tmp->filter_ctx->output_pads,
4903
+                                  ofilter->out_tmp->pad_idx)) {
4903 4904
     case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
4904 4905
     case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
4905 4906
     default:
... ...
@@ -4961,7 +4962,8 @@ static void opt_output_file(void *optctx, const char *filename)
4961 4961
             if (!ofilter->out_tmp || ofilter->out_tmp->name)
4962 4962
                 continue;
4963 4963
 
4964
-            switch (ofilter->out_tmp->filter_ctx->output_pads[ofilter->out_tmp->pad_idx].type) {
4964
+            switch (avfilter_pad_get_type(ofilter->out_tmp->filter_ctx->output_pads,
4965
+                                          ofilter->out_tmp->pad_idx)) {
4965 4966
             case AVMEDIA_TYPE_VIDEO:    o->video_disable    = 1; break;
4966 4967
             case AVMEDIA_TYPE_AUDIO:    o->audio_disable    = 1; break;
4967 4968
             case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
... ...
@@ -39,7 +39,7 @@
39 39
 #define PREFIX_h264_qpel16_v_lowpass_num       altivec_put_h264_qpel16_v_lowpass_num
40 40
 #define PREFIX_h264_qpel16_hv_lowpass_altivec  put_h264_qpel16_hv_lowpass_altivec
41 41
 #define PREFIX_h264_qpel16_hv_lowpass_num      altivec_put_h264_qpel16_hv_lowpass_num
42
-#include "h264_template_altivec.c"
42
+#include "h264_altivec_template.c"
43 43
 #undef OP_U8_ALTIVEC
44 44
 #undef PREFIX_h264_chroma_mc8_altivec
45 45
 #undef PREFIX_h264_chroma_mc8_num
... ...
@@ -59,7 +59,7 @@
59 59
 #define PREFIX_h264_qpel16_v_lowpass_num       altivec_avg_h264_qpel16_v_lowpass_num
60 60
 #define PREFIX_h264_qpel16_hv_lowpass_altivec  avg_h264_qpel16_hv_lowpass_altivec
61 61
 #define PREFIX_h264_qpel16_hv_lowpass_num      altivec_avg_h264_qpel16_hv_lowpass_num
62
-#include "h264_template_altivec.c"
62
+#include "h264_altivec_template.c"
63 63
 #undef OP_U8_ALTIVEC
64 64
 #undef PREFIX_h264_chroma_mc8_altivec
65 65
 #undef PREFIX_h264_chroma_mc8_num
66 66
new file mode 100644
... ...
@@ -0,0 +1,776 @@
0
+/*
1
+ * Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#ifdef DEBUG
21
+#define ASSERT_ALIGNED(ptr) assert(((unsigned long)ptr&0x0000000F));
22
+#else
23
+#define ASSERT_ALIGNED(ptr) ;
24
+#endif
25
+
26
+/* this code assume that stride % 16 == 0 */
27
+
28
+#define CHROMA_MC8_ALTIVEC_CORE(BIAS1, BIAS2) \
29
+        vsrc2ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc2uc);\
30
+        vsrc3ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc3uc);\
31
+\
32
+        psum = vec_mladd(vA, vsrc0ssH, BIAS1);\
33
+        psum = vec_mladd(vB, vsrc1ssH, psum);\
34
+        psum = vec_mladd(vC, vsrc2ssH, psum);\
35
+        psum = vec_mladd(vD, vsrc3ssH, psum);\
36
+        psum = BIAS2(psum);\
37
+        psum = vec_sr(psum, v6us);\
38
+\
39
+        vdst = vec_ld(0, dst);\
40
+        ppsum = (vec_u8)vec_pack(psum, psum);\
41
+        vfdst = vec_perm(vdst, ppsum, fperm);\
42
+\
43
+        OP_U8_ALTIVEC(fsum, vfdst, vdst);\
44
+\
45
+        vec_st(fsum, 0, dst);\
46
+\
47
+        vsrc0ssH = vsrc2ssH;\
48
+        vsrc1ssH = vsrc3ssH;\
49
+\
50
+        dst += stride;\
51
+        src += stride;
52
+
53
+#define CHROMA_MC8_ALTIVEC_CORE_SIMPLE \
54
+\
55
+        vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc0uc);\
56
+        vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc1uc);\
57
+\
58
+        psum = vec_mladd(vA, vsrc0ssH, v32ss);\
59
+        psum = vec_mladd(vE, vsrc1ssH, psum);\
60
+        psum = vec_sr(psum, v6us);\
61
+\
62
+        vdst = vec_ld(0, dst);\
63
+        ppsum = (vec_u8)vec_pack(psum, psum);\
64
+        vfdst = vec_perm(vdst, ppsum, fperm);\
65
+\
66
+        OP_U8_ALTIVEC(fsum, vfdst, vdst);\
67
+\
68
+        vec_st(fsum, 0, dst);\
69
+\
70
+        dst += stride;\
71
+        src += stride;
72
+
73
+#define noop(a) a
74
+#define add28(a) vec_add(v28ss, a)
75
+
76
+#ifdef PREFIX_h264_chroma_mc8_altivec
77
+static void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src,
78
+                                    int stride, int h, int x, int y) {
79
+    DECLARE_ALIGNED(16, signed int, ABCD)[4] =
80
+                        {((8 - x) * (8 - y)),
81
+                         ((    x) * (8 - y)),
82
+                         ((8 - x) * (    y)),
83
+                         ((    x) * (    y))};
84
+    register int i;
85
+    vec_u8 fperm;
86
+    const vec_s32 vABCD = vec_ld(0, ABCD);
87
+    const vec_s16 vA = vec_splat((vec_s16)vABCD, 1);
88
+    const vec_s16 vB = vec_splat((vec_s16)vABCD, 3);
89
+    const vec_s16 vC = vec_splat((vec_s16)vABCD, 5);
90
+    const vec_s16 vD = vec_splat((vec_s16)vABCD, 7);
91
+    LOAD_ZERO;
92
+    const vec_s16 v32ss = vec_sl(vec_splat_s16(1),vec_splat_u16(5));
93
+    const vec_u16 v6us = vec_splat_u16(6);
94
+    register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1;
95
+    register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0;
96
+
97
+    vec_u8 vsrcAuc, av_uninit(vsrcBuc), vsrcperm0, vsrcperm1;
98
+    vec_u8 vsrc0uc, vsrc1uc;
99
+    vec_s16 vsrc0ssH, vsrc1ssH;
100
+    vec_u8 vsrcCuc, vsrc2uc, vsrc3uc;
101
+    vec_s16 vsrc2ssH, vsrc3ssH, psum;
102
+    vec_u8 vdst, ppsum, vfdst, fsum;
103
+
104
+    if (((unsigned long)dst) % 16 == 0) {
105
+        fperm = (vec_u8){0x10, 0x11, 0x12, 0x13,
106
+                         0x14, 0x15, 0x16, 0x17,
107
+                         0x08, 0x09, 0x0A, 0x0B,
108
+                         0x0C, 0x0D, 0x0E, 0x0F};
109
+    } else {
110
+        fperm = (vec_u8){0x00, 0x01, 0x02, 0x03,
111
+                         0x04, 0x05, 0x06, 0x07,
112
+                         0x18, 0x19, 0x1A, 0x1B,
113
+                         0x1C, 0x1D, 0x1E, 0x1F};
114
+    }
115
+
116
+    vsrcAuc = vec_ld(0, src);
117
+
118
+    if (loadSecond)
119
+        vsrcBuc = vec_ld(16, src);
120
+    vsrcperm0 = vec_lvsl(0, src);
121
+    vsrcperm1 = vec_lvsl(1, src);
122
+
123
+    vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0);
124
+    if (reallyBadAlign)
125
+        vsrc1uc = vsrcBuc;
126
+    else
127
+        vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1);
128
+
129
+    vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc0uc);
130
+    vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc1uc);
131
+
132
+    if (ABCD[3]) {
133
+        if (!loadSecond) {// -> !reallyBadAlign
134
+            for (i = 0 ; i < h ; i++) {
135
+                vsrcCuc = vec_ld(stride + 0, src);
136
+                vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
137
+                vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1);
138
+
139
+                CHROMA_MC8_ALTIVEC_CORE(v32ss, noop)
140
+            }
141
+        } else {
142
+            vec_u8 vsrcDuc;
143
+            for (i = 0 ; i < h ; i++) {
144
+                vsrcCuc = vec_ld(stride + 0, src);
145
+                vsrcDuc = vec_ld(stride + 16, src);
146
+                vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
147
+                if (reallyBadAlign)
148
+                    vsrc3uc = vsrcDuc;
149
+                else
150
+                    vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1);
151
+
152
+                CHROMA_MC8_ALTIVEC_CORE(v32ss, noop)
153
+            }
154
+        }
155
+    } else {
156
+        const vec_s16 vE = vec_add(vB, vC);
157
+        if (ABCD[2]) { // x == 0 B == 0
158
+            if (!loadSecond) {// -> !reallyBadAlign
159
+                for (i = 0 ; i < h ; i++) {
160
+                    vsrcCuc = vec_ld(stride + 0, src);
161
+                    vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
162
+                    CHROMA_MC8_ALTIVEC_CORE_SIMPLE
163
+
164
+                    vsrc0uc = vsrc1uc;
165
+                }
166
+            } else {
167
+                vec_u8 vsrcDuc;
168
+                for (i = 0 ; i < h ; i++) {
169
+                    vsrcCuc = vec_ld(stride + 0, src);
170
+                    vsrcDuc = vec_ld(stride + 15, src);
171
+                    vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
172
+                    CHROMA_MC8_ALTIVEC_CORE_SIMPLE
173
+
174
+                    vsrc0uc = vsrc1uc;
175
+                }
176
+            }
177
+        } else { // y == 0 C == 0
178
+            if (!loadSecond) {// -> !reallyBadAlign
179
+                for (i = 0 ; i < h ; i++) {
180
+                    vsrcCuc = vec_ld(0, src);
181
+                    vsrc0uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
182
+                    vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1);
183
+
184
+                    CHROMA_MC8_ALTIVEC_CORE_SIMPLE
185
+                }
186
+            } else {
187
+                vec_u8 vsrcDuc;
188
+                for (i = 0 ; i < h ; i++) {
189
+                    vsrcCuc = vec_ld(0, src);
190
+                    vsrcDuc = vec_ld(15, src);
191
+                    vsrc0uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
192
+                    if (reallyBadAlign)
193
+                        vsrc1uc = vsrcDuc;
194
+                    else
195
+                        vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1);
196
+
197
+                    CHROMA_MC8_ALTIVEC_CORE_SIMPLE
198
+                }
199
+            }
200
+        }
201
+    }
202
+}
203
+#endif
204
+
205
+/* this code assume that stride % 16 == 0 */
206
+#ifdef PREFIX_no_rnd_vc1_chroma_mc8_altivec
207
+static void PREFIX_no_rnd_vc1_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) {
208
+   DECLARE_ALIGNED(16, signed int, ABCD)[4] =
209
+                        {((8 - x) * (8 - y)),
210
+                         ((    x) * (8 - y)),
211
+                         ((8 - x) * (    y)),
212
+                         ((    x) * (    y))};
213
+    register int i;
214
+    vec_u8 fperm;
215
+    const vec_s32 vABCD = vec_ld(0, ABCD);
216
+    const vec_s16 vA = vec_splat((vec_s16)vABCD, 1);
217
+    const vec_s16 vB = vec_splat((vec_s16)vABCD, 3);
218
+    const vec_s16 vC = vec_splat((vec_s16)vABCD, 5);
219
+    const vec_s16 vD = vec_splat((vec_s16)vABCD, 7);
220
+    LOAD_ZERO;
221
+    const vec_s16 v28ss = vec_sub(vec_sl(vec_splat_s16(1),vec_splat_u16(5)),vec_splat_s16(4));
222
+    const vec_u16 v6us  = vec_splat_u16(6);
223
+    register int loadSecond     = (((unsigned long)src) % 16) <= 7 ? 0 : 1;
224
+    register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0;
225
+
226
+    vec_u8 vsrcAuc, av_uninit(vsrcBuc), vsrcperm0, vsrcperm1;
227
+    vec_u8 vsrc0uc, vsrc1uc;
228
+    vec_s16 vsrc0ssH, vsrc1ssH;
229
+    vec_u8 vsrcCuc, vsrc2uc, vsrc3uc;
230
+    vec_s16 vsrc2ssH, vsrc3ssH, psum;
231
+    vec_u8 vdst, ppsum, vfdst, fsum;
232
+
233
+    if (((unsigned long)dst) % 16 == 0) {
234
+        fperm = (vec_u8){0x10, 0x11, 0x12, 0x13,
235
+                         0x14, 0x15, 0x16, 0x17,
236
+                         0x08, 0x09, 0x0A, 0x0B,
237
+                         0x0C, 0x0D, 0x0E, 0x0F};
238
+    } else {
239
+        fperm = (vec_u8){0x00, 0x01, 0x02, 0x03,
240
+                         0x04, 0x05, 0x06, 0x07,
241
+                         0x18, 0x19, 0x1A, 0x1B,
242
+                         0x1C, 0x1D, 0x1E, 0x1F};
243
+    }
244
+
245
+    vsrcAuc = vec_ld(0, src);
246
+
247
+    if (loadSecond)
248
+        vsrcBuc = vec_ld(16, src);
249
+    vsrcperm0 = vec_lvsl(0, src);
250
+    vsrcperm1 = vec_lvsl(1, src);
251
+
252
+    vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0);
253
+    if (reallyBadAlign)
254
+        vsrc1uc = vsrcBuc;
255
+    else
256
+        vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1);
257
+
258
+    vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v, (vec_u8)vsrc0uc);
259
+    vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v, (vec_u8)vsrc1uc);
260
+
261
+    if (!loadSecond) {// -> !reallyBadAlign
262
+        for (i = 0 ; i < h ; i++) {
263
+
264
+
265
+            vsrcCuc = vec_ld(stride + 0, src);
266
+
267
+            vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
268
+            vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1);
269
+
270
+            CHROMA_MC8_ALTIVEC_CORE(vec_splat_s16(0), add28)
271
+        }
272
+    } else {
273
+        vec_u8 vsrcDuc;
274
+        for (i = 0 ; i < h ; i++) {
275
+            vsrcCuc = vec_ld(stride + 0, src);
276
+            vsrcDuc = vec_ld(stride + 16, src);
277
+
278
+            vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
279
+            if (reallyBadAlign)
280
+                vsrc3uc = vsrcDuc;
281
+            else
282
+                vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1);
283
+
284
+            CHROMA_MC8_ALTIVEC_CORE(vec_splat_s16(0), add28)
285
+        }
286
+    }
287
+}
288
+#endif
289
+
290
+#undef noop
291
+#undef add28
292
+#undef CHROMA_MC8_ALTIVEC_CORE
293
+
294
+/* this code assume stride % 16 == 0 */
295
+#ifdef PREFIX_h264_qpel16_h_lowpass_altivec
296
+static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) {
297
+    register int i;
298
+
299
+    LOAD_ZERO;
300
+    const vec_u8 permM2 = vec_lvsl(-2, src);
301
+    const vec_u8 permM1 = vec_lvsl(-1, src);
302
+    const vec_u8 permP0 = vec_lvsl(+0, src);
303
+    const vec_u8 permP1 = vec_lvsl(+1, src);
304
+    const vec_u8 permP2 = vec_lvsl(+2, src);
305
+    const vec_u8 permP3 = vec_lvsl(+3, src);
306
+    const vec_s16 v5ss = vec_splat_s16(5);
307
+    const vec_u16 v5us = vec_splat_u16(5);
308
+    const vec_s16 v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
309
+    const vec_s16 v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4));
310
+
311
+    vec_u8 srcM2, srcM1, srcP0, srcP1, srcP2, srcP3;
312
+
313
+    register int align = ((((unsigned long)src) - 2) % 16);
314
+
315
+    vec_s16 srcP0A, srcP0B, srcP1A, srcP1B,
316
+              srcP2A, srcP2B, srcP3A, srcP3B,
317
+              srcM1A, srcM1B, srcM2A, srcM2B,
318
+              sum1A, sum1B, sum2A, sum2B, sum3A, sum3B,
319
+              pp1A, pp1B, pp2A, pp2B, pp3A, pp3B,
320
+              psumA, psumB, sumA, sumB;
321
+
322
+    vec_u8 sum, vdst, fsum;
323
+
324
+    for (i = 0 ; i < 16 ; i ++) {
325
+        vec_u8 srcR1 = vec_ld(-2, src);
326
+        vec_u8 srcR2 = vec_ld(14, src);
327
+
328
+        switch (align) {
329
+        default: {
330
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
331
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
332
+            srcP0 = vec_perm(srcR1, srcR2, permP0);
333
+            srcP1 = vec_perm(srcR1, srcR2, permP1);
334
+            srcP2 = vec_perm(srcR1, srcR2, permP2);
335
+            srcP3 = vec_perm(srcR1, srcR2, permP3);
336
+        } break;
337
+        case 11: {
338
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
339
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
340
+            srcP0 = vec_perm(srcR1, srcR2, permP0);
341
+            srcP1 = vec_perm(srcR1, srcR2, permP1);
342
+            srcP2 = vec_perm(srcR1, srcR2, permP2);
343
+            srcP3 = srcR2;
344
+        } break;
345
+        case 12: {
346
+            vec_u8 srcR3 = vec_ld(30, src);
347
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
348
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
349
+            srcP0 = vec_perm(srcR1, srcR2, permP0);
350
+            srcP1 = vec_perm(srcR1, srcR2, permP1);
351
+            srcP2 = srcR2;
352
+            srcP3 = vec_perm(srcR2, srcR3, permP3);
353
+        } break;
354
+        case 13: {
355
+            vec_u8 srcR3 = vec_ld(30, src);
356
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
357
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
358
+            srcP0 = vec_perm(srcR1, srcR2, permP0);
359
+            srcP1 = srcR2;
360
+            srcP2 = vec_perm(srcR2, srcR3, permP2);
361
+            srcP3 = vec_perm(srcR2, srcR3, permP3);
362
+        } break;
363
+        case 14: {
364
+            vec_u8 srcR3 = vec_ld(30, src);
365
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
366
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
367
+            srcP0 = srcR2;
368
+            srcP1 = vec_perm(srcR2, srcR3, permP1);
369
+            srcP2 = vec_perm(srcR2, srcR3, permP2);
370
+            srcP3 = vec_perm(srcR2, srcR3, permP3);
371
+        } break;
372
+        case 15: {
373
+            vec_u8 srcR3 = vec_ld(30, src);
374
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
375
+            srcM1 = srcR2;
376
+            srcP0 = vec_perm(srcR2, srcR3, permP0);
377
+            srcP1 = vec_perm(srcR2, srcR3, permP1);
378
+            srcP2 = vec_perm(srcR2, srcR3, permP2);
379
+            srcP3 = vec_perm(srcR2, srcR3, permP3);
380
+        } break;
381
+        }
382
+
383
+        srcP0A = (vec_s16) vec_mergeh(zero_u8v, srcP0);
384
+        srcP0B = (vec_s16) vec_mergel(zero_u8v, srcP0);
385
+        srcP1A = (vec_s16) vec_mergeh(zero_u8v, srcP1);
386
+        srcP1B = (vec_s16) vec_mergel(zero_u8v, srcP1);
387
+
388
+        srcP2A = (vec_s16) vec_mergeh(zero_u8v, srcP2);
389
+        srcP2B = (vec_s16) vec_mergel(zero_u8v, srcP2);
390
+        srcP3A = (vec_s16) vec_mergeh(zero_u8v, srcP3);
391
+        srcP3B = (vec_s16) vec_mergel(zero_u8v, srcP3);
392
+
393
+        srcM1A = (vec_s16) vec_mergeh(zero_u8v, srcM1);
394
+        srcM1B = (vec_s16) vec_mergel(zero_u8v, srcM1);
395
+        srcM2A = (vec_s16) vec_mergeh(zero_u8v, srcM2);
396
+        srcM2B = (vec_s16) vec_mergel(zero_u8v, srcM2);
397
+
398
+        sum1A = vec_adds(srcP0A, srcP1A);
399
+        sum1B = vec_adds(srcP0B, srcP1B);
400
+        sum2A = vec_adds(srcM1A, srcP2A);
401
+        sum2B = vec_adds(srcM1B, srcP2B);
402
+        sum3A = vec_adds(srcM2A, srcP3A);
403
+        sum3B = vec_adds(srcM2B, srcP3B);
404
+
405
+        pp1A = vec_mladd(sum1A, v20ss, v16ss);
406
+        pp1B = vec_mladd(sum1B, v20ss, v16ss);
407
+
408
+        pp2A = vec_mladd(sum2A, v5ss, zero_s16v);
409
+        pp2B = vec_mladd(sum2B, v5ss, zero_s16v);
410
+
411
+        pp3A = vec_add(sum3A, pp1A);
412
+        pp3B = vec_add(sum3B, pp1B);
413
+
414
+        psumA = vec_sub(pp3A, pp2A);
415
+        psumB = vec_sub(pp3B, pp2B);
416
+
417
+        sumA = vec_sra(psumA, v5us);
418
+        sumB = vec_sra(psumB, v5us);
419
+
420
+        sum = vec_packsu(sumA, sumB);
421
+
422
+        ASSERT_ALIGNED(dst);
423
+        vdst = vec_ld(0, dst);
424
+
425
+        OP_U8_ALTIVEC(fsum, sum, vdst);
426
+
427
+        vec_st(fsum, 0, dst);
428
+
429
+        src += srcStride;
430
+        dst += dstStride;
431
+    }
432
+}
433
+#endif
434
+
435
+/* this code assume stride % 16 == 0 */
436
+#ifdef PREFIX_h264_qpel16_v_lowpass_altivec
437
+static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) {
438
+    register int i;
439
+
440
+    LOAD_ZERO;
441
+    const vec_u8 perm = vec_lvsl(0, src);
442
+    const vec_s16 v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
443
+    const vec_u16 v5us = vec_splat_u16(5);
444
+    const vec_s16 v5ss = vec_splat_s16(5);
445
+    const vec_s16 v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4));
446
+
447
+    uint8_t *srcbis = src - (srcStride * 2);
448
+
449
+    const vec_u8 srcM2a = vec_ld(0, srcbis);
450
+    const vec_u8 srcM2b = vec_ld(16, srcbis);
451
+    const vec_u8 srcM2 = vec_perm(srcM2a, srcM2b, perm);
452
+    //srcbis += srcStride;
453
+    const vec_u8 srcM1a = vec_ld(0, srcbis += srcStride);
454
+    const vec_u8 srcM1b = vec_ld(16, srcbis);
455
+    const vec_u8 srcM1 = vec_perm(srcM1a, srcM1b, perm);
456
+    //srcbis += srcStride;
457
+    const vec_u8 srcP0a = vec_ld(0, srcbis += srcStride);
458
+    const vec_u8 srcP0b = vec_ld(16, srcbis);
459
+    const vec_u8 srcP0 = vec_perm(srcP0a, srcP0b, perm);
460
+    //srcbis += srcStride;
461
+    const vec_u8 srcP1a = vec_ld(0, srcbis += srcStride);
462
+    const vec_u8 srcP1b = vec_ld(16, srcbis);
463
+    const vec_u8 srcP1 = vec_perm(srcP1a, srcP1b, perm);
464
+    //srcbis += srcStride;
465
+    const vec_u8 srcP2a = vec_ld(0, srcbis += srcStride);
466
+    const vec_u8 srcP2b = vec_ld(16, srcbis);
467
+    const vec_u8 srcP2 = vec_perm(srcP2a, srcP2b, perm);
468
+    //srcbis += srcStride;
469
+
470
+    vec_s16 srcM2ssA = (vec_s16) vec_mergeh(zero_u8v, srcM2);
471
+    vec_s16 srcM2ssB = (vec_s16) vec_mergel(zero_u8v, srcM2);
472
+    vec_s16 srcM1ssA = (vec_s16) vec_mergeh(zero_u8v, srcM1);
473
+    vec_s16 srcM1ssB = (vec_s16) vec_mergel(zero_u8v, srcM1);
474
+    vec_s16 srcP0ssA = (vec_s16) vec_mergeh(zero_u8v, srcP0);
475
+    vec_s16 srcP0ssB = (vec_s16) vec_mergel(zero_u8v, srcP0);
476
+    vec_s16 srcP1ssA = (vec_s16) vec_mergeh(zero_u8v, srcP1);
477
+    vec_s16 srcP1ssB = (vec_s16) vec_mergel(zero_u8v, srcP1);
478
+    vec_s16 srcP2ssA = (vec_s16) vec_mergeh(zero_u8v, srcP2);
479
+    vec_s16 srcP2ssB = (vec_s16) vec_mergel(zero_u8v, srcP2);
480
+
481
+    vec_s16 pp1A, pp1B, pp2A, pp2B, pp3A, pp3B,
482
+              psumA, psumB, sumA, sumB,
483
+              srcP3ssA, srcP3ssB,
484
+              sum1A, sum1B, sum2A, sum2B, sum3A, sum3B;
485
+
486
+    vec_u8 sum, vdst, fsum, srcP3a, srcP3b, srcP3;
487
+
488
+    for (i = 0 ; i < 16 ; i++) {
489
+        srcP3a = vec_ld(0, srcbis += srcStride);
490
+        srcP3b = vec_ld(16, srcbis);
491
+        srcP3 = vec_perm(srcP3a, srcP3b, perm);
492
+        srcP3ssA = (vec_s16) vec_mergeh(zero_u8v, srcP3);
493
+        srcP3ssB = (vec_s16) vec_mergel(zero_u8v, srcP3);
494
+        //srcbis += srcStride;
495
+
496
+        sum1A = vec_adds(srcP0ssA, srcP1ssA);
497
+        sum1B = vec_adds(srcP0ssB, srcP1ssB);
498
+        sum2A = vec_adds(srcM1ssA, srcP2ssA);
499
+        sum2B = vec_adds(srcM1ssB, srcP2ssB);
500
+        sum3A = vec_adds(srcM2ssA, srcP3ssA);
501
+        sum3B = vec_adds(srcM2ssB, srcP3ssB);
502
+
503
+        srcM2ssA = srcM1ssA;
504
+        srcM2ssB = srcM1ssB;
505
+        srcM1ssA = srcP0ssA;
506
+        srcM1ssB = srcP0ssB;
507
+        srcP0ssA = srcP1ssA;
508
+        srcP0ssB = srcP1ssB;
509
+        srcP1ssA = srcP2ssA;
510
+        srcP1ssB = srcP2ssB;
511
+        srcP2ssA = srcP3ssA;
512
+        srcP2ssB = srcP3ssB;
513
+
514
+        pp1A = vec_mladd(sum1A, v20ss, v16ss);
515
+        pp1B = vec_mladd(sum1B, v20ss, v16ss);
516
+
517
+        pp2A = vec_mladd(sum2A, v5ss, zero_s16v);
518
+        pp2B = vec_mladd(sum2B, v5ss, zero_s16v);
519
+
520
+        pp3A = vec_add(sum3A, pp1A);
521
+        pp3B = vec_add(sum3B, pp1B);
522
+
523
+        psumA = vec_sub(pp3A, pp2A);
524
+        psumB = vec_sub(pp3B, pp2B);
525
+
526
+        sumA = vec_sra(psumA, v5us);
527
+        sumB = vec_sra(psumB, v5us);
528
+
529
+        sum = vec_packsu(sumA, sumB);
530
+
531
+        ASSERT_ALIGNED(dst);
532
+        vdst = vec_ld(0, dst);
533
+
534
+        OP_U8_ALTIVEC(fsum, sum, vdst);
535
+
536
+        vec_st(fsum, 0, dst);
537
+
538
+        dst += dstStride;
539
+    }
540
+}
541
+#endif
542
+
543
+/* this code assume stride % 16 == 0 *and* tmp is properly aligned */
544
+#ifdef PREFIX_h264_qpel16_hv_lowpass_altivec
545
+static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, uint8_t * src, int dstStride, int tmpStride, int srcStride) {
546
+    register int i;
547
+    LOAD_ZERO;
548
+    const vec_u8 permM2 = vec_lvsl(-2, src);
549
+    const vec_u8 permM1 = vec_lvsl(-1, src);
550
+    const vec_u8 permP0 = vec_lvsl(+0, src);
551
+    const vec_u8 permP1 = vec_lvsl(+1, src);
552
+    const vec_u8 permP2 = vec_lvsl(+2, src);
553
+    const vec_u8 permP3 = vec_lvsl(+3, src);
554
+    const vec_s16 v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
555
+    const vec_u32 v10ui = vec_splat_u32(10);
556
+    const vec_s16 v5ss = vec_splat_s16(5);
557
+    const vec_s16 v1ss = vec_splat_s16(1);
558
+    const vec_s32 v512si = vec_sl(vec_splat_s32(1),vec_splat_u32(9));
559
+    const vec_u32 v16ui = vec_sl(vec_splat_u32(1),vec_splat_u32(4));
560
+
561
+    register int align = ((((unsigned long)src) - 2) % 16);
562
+
563
+    vec_s16 srcP0A, srcP0B, srcP1A, srcP1B,
564
+              srcP2A, srcP2B, srcP3A, srcP3B,
565
+              srcM1A, srcM1B, srcM2A, srcM2B,
566
+              sum1A, sum1B, sum2A, sum2B, sum3A, sum3B,
567
+              pp1A, pp1B, pp2A, pp2B, psumA, psumB;
568
+
569
+    const vec_u8 mperm = (const vec_u8)
570
+        {0x00, 0x08, 0x01, 0x09, 0x02, 0x0A, 0x03, 0x0B,
571
+         0x04, 0x0C, 0x05, 0x0D, 0x06, 0x0E, 0x07, 0x0F};
572
+    int16_t *tmpbis = tmp;
573
+
574
+    vec_s16 tmpM1ssA, tmpM1ssB, tmpM2ssA, tmpM2ssB,
575
+              tmpP0ssA, tmpP0ssB, tmpP1ssA, tmpP1ssB,
576
+              tmpP2ssA, tmpP2ssB;
577
+
578
+    vec_s32 pp1Ae, pp1Ao, pp1Be, pp1Bo, pp2Ae, pp2Ao, pp2Be, pp2Bo,
579
+              pp3Ae, pp3Ao, pp3Be, pp3Bo, pp1cAe, pp1cAo, pp1cBe, pp1cBo,
580
+              pp32Ae, pp32Ao, pp32Be, pp32Bo, sumAe, sumAo, sumBe, sumBo,
581
+              ssumAe, ssumAo, ssumBe, ssumBo;
582
+    vec_u8 fsum, sumv, sum, vdst;
583
+    vec_s16 ssume, ssumo;
584
+
585
+    src -= (2 * srcStride);
586
+    for (i = 0 ; i < 21 ; i ++) {
587
+        vec_u8 srcM2, srcM1, srcP0, srcP1, srcP2, srcP3;
588
+        vec_u8 srcR1 = vec_ld(-2, src);
589
+        vec_u8 srcR2 = vec_ld(14, src);
590
+
591
+        switch (align) {
592
+        default: {
593
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
594
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
595
+            srcP0 = vec_perm(srcR1, srcR2, permP0);
596
+            srcP1 = vec_perm(srcR1, srcR2, permP1);
597
+            srcP2 = vec_perm(srcR1, srcR2, permP2);
598
+            srcP3 = vec_perm(srcR1, srcR2, permP3);
599
+        } break;
600
+        case 11: {
601
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
602
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
603
+            srcP0 = vec_perm(srcR1, srcR2, permP0);
604
+            srcP1 = vec_perm(srcR1, srcR2, permP1);
605
+            srcP2 = vec_perm(srcR1, srcR2, permP2);
606
+            srcP3 = srcR2;
607
+        } break;
608
+        case 12: {
609
+            vec_u8 srcR3 = vec_ld(30, src);
610
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
611
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
612
+            srcP0 = vec_perm(srcR1, srcR2, permP0);
613
+            srcP1 = vec_perm(srcR1, srcR2, permP1);
614
+            srcP2 = srcR2;
615
+            srcP3 = vec_perm(srcR2, srcR3, permP3);
616
+        } break;
617
+        case 13: {
618
+            vec_u8 srcR3 = vec_ld(30, src);
619
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
620
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
621
+            srcP0 = vec_perm(srcR1, srcR2, permP0);
622
+            srcP1 = srcR2;
623
+            srcP2 = vec_perm(srcR2, srcR3, permP2);
624
+            srcP3 = vec_perm(srcR2, srcR3, permP3);
625
+        } break;
626
+        case 14: {
627
+            vec_u8 srcR3 = vec_ld(30, src);
628
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
629
+            srcM1 = vec_perm(srcR1, srcR2, permM1);
630
+            srcP0 = srcR2;
631
+            srcP1 = vec_perm(srcR2, srcR3, permP1);
632
+            srcP2 = vec_perm(srcR2, srcR3, permP2);
633
+            srcP3 = vec_perm(srcR2, srcR3, permP3);
634
+        } break;
635
+        case 15: {
636
+            vec_u8 srcR3 = vec_ld(30, src);
637
+            srcM2 = vec_perm(srcR1, srcR2, permM2);
638
+            srcM1 = srcR2;
639
+            srcP0 = vec_perm(srcR2, srcR3, permP0);
640
+            srcP1 = vec_perm(srcR2, srcR3, permP1);
641
+            srcP2 = vec_perm(srcR2, srcR3, permP2);
642
+            srcP3 = vec_perm(srcR2, srcR3, permP3);
643
+        } break;
644
+        }
645
+
646
+        srcP0A = (vec_s16) vec_mergeh(zero_u8v, srcP0);
647
+        srcP0B = (vec_s16) vec_mergel(zero_u8v, srcP0);
648
+        srcP1A = (vec_s16) vec_mergeh(zero_u8v, srcP1);
649
+        srcP1B = (vec_s16) vec_mergel(zero_u8v, srcP1);
650
+
651
+        srcP2A = (vec_s16) vec_mergeh(zero_u8v, srcP2);
652
+        srcP2B = (vec_s16) vec_mergel(zero_u8v, srcP2);
653
+        srcP3A = (vec_s16) vec_mergeh(zero_u8v, srcP3);
654
+        srcP3B = (vec_s16) vec_mergel(zero_u8v, srcP3);
655
+
656
+        srcM1A = (vec_s16) vec_mergeh(zero_u8v, srcM1);
657
+        srcM1B = (vec_s16) vec_mergel(zero_u8v, srcM1);
658
+        srcM2A = (vec_s16) vec_mergeh(zero_u8v, srcM2);
659
+        srcM2B = (vec_s16) vec_mergel(zero_u8v, srcM2);
660
+
661
+        sum1A = vec_adds(srcP0A, srcP1A);
662
+        sum1B = vec_adds(srcP0B, srcP1B);
663
+        sum2A = vec_adds(srcM1A, srcP2A);
664
+        sum2B = vec_adds(srcM1B, srcP2B);
665
+        sum3A = vec_adds(srcM2A, srcP3A);
666
+        sum3B = vec_adds(srcM2B, srcP3B);
667
+
668
+        pp1A = vec_mladd(sum1A, v20ss, sum3A);
669
+        pp1B = vec_mladd(sum1B, v20ss, sum3B);
670
+
671
+        pp2A = vec_mladd(sum2A, v5ss, zero_s16v);
672
+        pp2B = vec_mladd(sum2B, v5ss, zero_s16v);
673
+
674
+        psumA = vec_sub(pp1A, pp2A);
675
+        psumB = vec_sub(pp1B, pp2B);
676
+
677
+        vec_st(psumA, 0, tmp);
678
+        vec_st(psumB, 16, tmp);
679
+
680
+        src += srcStride;
681
+        tmp += tmpStride; /* int16_t*, and stride is 16, so it's OK here */
682
+    }
683
+
684
+    tmpM2ssA = vec_ld(0, tmpbis);
685
+    tmpM2ssB = vec_ld(16, tmpbis);
686
+    tmpbis += tmpStride;
687
+    tmpM1ssA = vec_ld(0, tmpbis);
688
+    tmpM1ssB = vec_ld(16, tmpbis);
689
+    tmpbis += tmpStride;
690
+    tmpP0ssA = vec_ld(0, tmpbis);
691
+    tmpP0ssB = vec_ld(16, tmpbis);
692
+    tmpbis += tmpStride;
693
+    tmpP1ssA = vec_ld(0, tmpbis);
694
+    tmpP1ssB = vec_ld(16, tmpbis);
695
+    tmpbis += tmpStride;
696
+    tmpP2ssA = vec_ld(0, tmpbis);
697
+    tmpP2ssB = vec_ld(16, tmpbis);
698
+    tmpbis += tmpStride;
699
+
700
+    for (i = 0 ; i < 16 ; i++) {
701
+        const vec_s16 tmpP3ssA = vec_ld(0, tmpbis);
702
+        const vec_s16 tmpP3ssB = vec_ld(16, tmpbis);
703
+
704
+        const vec_s16 sum1A = vec_adds(tmpP0ssA, tmpP1ssA);
705
+        const vec_s16 sum1B = vec_adds(tmpP0ssB, tmpP1ssB);
706
+        const vec_s16 sum2A = vec_adds(tmpM1ssA, tmpP2ssA);
707
+        const vec_s16 sum2B = vec_adds(tmpM1ssB, tmpP2ssB);
708
+        const vec_s16 sum3A = vec_adds(tmpM2ssA, tmpP3ssA);
709
+        const vec_s16 sum3B = vec_adds(tmpM2ssB, tmpP3ssB);
710
+
711
+        tmpbis += tmpStride;
712
+
713
+        tmpM2ssA = tmpM1ssA;
714
+        tmpM2ssB = tmpM1ssB;
715
+        tmpM1ssA = tmpP0ssA;
716
+        tmpM1ssB = tmpP0ssB;
717
+        tmpP0ssA = tmpP1ssA;
718
+        tmpP0ssB = tmpP1ssB;
719
+        tmpP1ssA = tmpP2ssA;
720
+        tmpP1ssB = tmpP2ssB;
721
+        tmpP2ssA = tmpP3ssA;
722
+        tmpP2ssB = tmpP3ssB;
723
+
724
+        pp1Ae = vec_mule(sum1A, v20ss);
725
+        pp1Ao = vec_mulo(sum1A, v20ss);
726
+        pp1Be = vec_mule(sum1B, v20ss);
727
+        pp1Bo = vec_mulo(sum1B, v20ss);
728
+
729
+        pp2Ae = vec_mule(sum2A, v5ss);
730
+        pp2Ao = vec_mulo(sum2A, v5ss);
731
+        pp2Be = vec_mule(sum2B, v5ss);
732
+        pp2Bo = vec_mulo(sum2B, v5ss);
733
+
734
+        pp3Ae = vec_sra((vec_s32)sum3A, v16ui);
735
+        pp3Ao = vec_mulo(sum3A, v1ss);
736
+        pp3Be = vec_sra((vec_s32)sum3B, v16ui);
737
+        pp3Bo = vec_mulo(sum3B, v1ss);
738
+
739
+        pp1cAe = vec_add(pp1Ae, v512si);
740
+        pp1cAo = vec_add(pp1Ao, v512si);
741
+        pp1cBe = vec_add(pp1Be, v512si);
742
+        pp1cBo = vec_add(pp1Bo, v512si);
743
+
744
+        pp32Ae = vec_sub(pp3Ae, pp2Ae);
745
+        pp32Ao = vec_sub(pp3Ao, pp2Ao);
746
+        pp32Be = vec_sub(pp3Be, pp2Be);
747
+        pp32Bo = vec_sub(pp3Bo, pp2Bo);
748
+
749
+        sumAe = vec_add(pp1cAe, pp32Ae);
750
+        sumAo = vec_add(pp1cAo, pp32Ao);
751
+        sumBe = vec_add(pp1cBe, pp32Be);
752
+        sumBo = vec_add(pp1cBo, pp32Bo);
753
+
754
+        ssumAe = vec_sra(sumAe, v10ui);
755
+        ssumAo = vec_sra(sumAo, v10ui);
756
+        ssumBe = vec_sra(sumBe, v10ui);
757
+        ssumBo = vec_sra(sumBo, v10ui);
758
+
759
+        ssume = vec_packs(ssumAe, ssumBe);
760
+        ssumo = vec_packs(ssumAo, ssumBo);
761
+
762
+        sumv = vec_packsu(ssume, ssumo);
763
+        sum = vec_perm(sumv, sumv, mperm);
764
+
765
+        ASSERT_ALIGNED(dst);
766
+        vdst = vec_ld(0, dst);
767
+
768
+        OP_U8_ALTIVEC(fsum, sum, vdst);
769
+
770
+        vec_st(fsum, 0, dst);
771
+
772
+        dst += dstStride;
773
+    }
774
+}
775
+#endif
0 776
deleted file mode 100644
... ...
@@ -1,776 +0,0 @@
1
-/*
2
- * Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#ifdef DEBUG
22
-#define ASSERT_ALIGNED(ptr) assert(((unsigned long)ptr&0x0000000F));
23
-#else
24
-#define ASSERT_ALIGNED(ptr) ;
25
-#endif
26
-
27
-/* this code assume that stride % 16 == 0 */
28
-
29
-#define CHROMA_MC8_ALTIVEC_CORE(BIAS1, BIAS2) \
30
-        vsrc2ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc2uc);\
31
-        vsrc3ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc3uc);\
32
-\
33
-        psum = vec_mladd(vA, vsrc0ssH, BIAS1);\
34
-        psum = vec_mladd(vB, vsrc1ssH, psum);\
35
-        psum = vec_mladd(vC, vsrc2ssH, psum);\
36
-        psum = vec_mladd(vD, vsrc3ssH, psum);\
37
-        psum = BIAS2(psum);\
38
-        psum = vec_sr(psum, v6us);\
39
-\
40
-        vdst = vec_ld(0, dst);\
41
-        ppsum = (vec_u8)vec_pack(psum, psum);\
42
-        vfdst = vec_perm(vdst, ppsum, fperm);\
43
-\
44
-        OP_U8_ALTIVEC(fsum, vfdst, vdst);\
45
-\
46
-        vec_st(fsum, 0, dst);\
47
-\
48
-        vsrc0ssH = vsrc2ssH;\
49
-        vsrc1ssH = vsrc3ssH;\
50
-\
51
-        dst += stride;\
52
-        src += stride;
53
-
54
-#define CHROMA_MC8_ALTIVEC_CORE_SIMPLE \
55
-\
56
-        vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc0uc);\
57
-        vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc1uc);\
58
-\
59
-        psum = vec_mladd(vA, vsrc0ssH, v32ss);\
60
-        psum = vec_mladd(vE, vsrc1ssH, psum);\
61
-        psum = vec_sr(psum, v6us);\
62
-\
63
-        vdst = vec_ld(0, dst);\
64
-        ppsum = (vec_u8)vec_pack(psum, psum);\
65
-        vfdst = vec_perm(vdst, ppsum, fperm);\
66
-\
67
-        OP_U8_ALTIVEC(fsum, vfdst, vdst);\
68
-\
69
-        vec_st(fsum, 0, dst);\
70
-\
71
-        dst += stride;\
72
-        src += stride;
73
-
74
-#define noop(a) a
75
-#define add28(a) vec_add(v28ss, a)
76
-
77
-#ifdef PREFIX_h264_chroma_mc8_altivec
78
-static void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src,
79
-                                    int stride, int h, int x, int y) {
80
-    DECLARE_ALIGNED(16, signed int, ABCD)[4] =
81
-                        {((8 - x) * (8 - y)),
82
-                         ((    x) * (8 - y)),
83
-                         ((8 - x) * (    y)),
84
-                         ((    x) * (    y))};
85
-    register int i;
86
-    vec_u8 fperm;
87
-    const vec_s32 vABCD = vec_ld(0, ABCD);
88
-    const vec_s16 vA = vec_splat((vec_s16)vABCD, 1);
89
-    const vec_s16 vB = vec_splat((vec_s16)vABCD, 3);
90
-    const vec_s16 vC = vec_splat((vec_s16)vABCD, 5);
91
-    const vec_s16 vD = vec_splat((vec_s16)vABCD, 7);
92
-    LOAD_ZERO;
93
-    const vec_s16 v32ss = vec_sl(vec_splat_s16(1),vec_splat_u16(5));
94
-    const vec_u16 v6us = vec_splat_u16(6);
95
-    register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1;
96
-    register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0;
97
-
98
-    vec_u8 vsrcAuc, av_uninit(vsrcBuc), vsrcperm0, vsrcperm1;
99
-    vec_u8 vsrc0uc, vsrc1uc;
100
-    vec_s16 vsrc0ssH, vsrc1ssH;
101
-    vec_u8 vsrcCuc, vsrc2uc, vsrc3uc;
102
-    vec_s16 vsrc2ssH, vsrc3ssH, psum;
103
-    vec_u8 vdst, ppsum, vfdst, fsum;
104
-
105
-    if (((unsigned long)dst) % 16 == 0) {
106
-        fperm = (vec_u8){0x10, 0x11, 0x12, 0x13,
107
-                         0x14, 0x15, 0x16, 0x17,
108
-                         0x08, 0x09, 0x0A, 0x0B,
109
-                         0x0C, 0x0D, 0x0E, 0x0F};
110
-    } else {
111
-        fperm = (vec_u8){0x00, 0x01, 0x02, 0x03,
112
-                         0x04, 0x05, 0x06, 0x07,
113
-                         0x18, 0x19, 0x1A, 0x1B,
114
-                         0x1C, 0x1D, 0x1E, 0x1F};
115
-    }
116
-
117
-    vsrcAuc = vec_ld(0, src);
118
-
119
-    if (loadSecond)
120
-        vsrcBuc = vec_ld(16, src);
121
-    vsrcperm0 = vec_lvsl(0, src);
122
-    vsrcperm1 = vec_lvsl(1, src);
123
-
124
-    vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0);
125
-    if (reallyBadAlign)
126
-        vsrc1uc = vsrcBuc;
127
-    else
128
-        vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1);
129
-
130
-    vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc0uc);
131
-    vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v,(vec_u8)vsrc1uc);
132
-
133
-    if (ABCD[3]) {
134
-        if (!loadSecond) {// -> !reallyBadAlign
135
-            for (i = 0 ; i < h ; i++) {
136
-                vsrcCuc = vec_ld(stride + 0, src);
137
-                vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
138
-                vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1);
139
-
140
-                CHROMA_MC8_ALTIVEC_CORE(v32ss, noop)
141
-            }
142
-        } else {
143
-            vec_u8 vsrcDuc;
144
-            for (i = 0 ; i < h ; i++) {
145
-                vsrcCuc = vec_ld(stride + 0, src);
146
-                vsrcDuc = vec_ld(stride + 16, src);
147
-                vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
148
-                if (reallyBadAlign)
149
-                    vsrc3uc = vsrcDuc;
150
-                else
151
-                    vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1);
152
-
153
-                CHROMA_MC8_ALTIVEC_CORE(v32ss, noop)
154
-            }
155
-        }
156
-    } else {
157
-        const vec_s16 vE = vec_add(vB, vC);
158
-        if (ABCD[2]) { // x == 0 B == 0
159
-            if (!loadSecond) {// -> !reallyBadAlign
160
-                for (i = 0 ; i < h ; i++) {
161
-                    vsrcCuc = vec_ld(stride + 0, src);
162
-                    vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
163
-                    CHROMA_MC8_ALTIVEC_CORE_SIMPLE
164
-
165
-                    vsrc0uc = vsrc1uc;
166
-                }
167
-            } else {
168
-                vec_u8 vsrcDuc;
169
-                for (i = 0 ; i < h ; i++) {
170
-                    vsrcCuc = vec_ld(stride + 0, src);
171
-                    vsrcDuc = vec_ld(stride + 15, src);
172
-                    vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
173
-                    CHROMA_MC8_ALTIVEC_CORE_SIMPLE
174
-
175
-                    vsrc0uc = vsrc1uc;
176
-                }
177
-            }
178
-        } else { // y == 0 C == 0
179
-            if (!loadSecond) {// -> !reallyBadAlign
180
-                for (i = 0 ; i < h ; i++) {
181
-                    vsrcCuc = vec_ld(0, src);
182
-                    vsrc0uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
183
-                    vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1);
184
-
185
-                    CHROMA_MC8_ALTIVEC_CORE_SIMPLE
186
-                }
187
-            } else {
188
-                vec_u8 vsrcDuc;
189
-                for (i = 0 ; i < h ; i++) {
190
-                    vsrcCuc = vec_ld(0, src);
191
-                    vsrcDuc = vec_ld(15, src);
192
-                    vsrc0uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
193
-                    if (reallyBadAlign)
194
-                        vsrc1uc = vsrcDuc;
195
-                    else
196
-                        vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1);
197
-
198
-                    CHROMA_MC8_ALTIVEC_CORE_SIMPLE
199
-                }
200
-            }
201
-        }
202
-    }
203
-}
204
-#endif
205
-
206
-/* this code assume that stride % 16 == 0 */
207
-#ifdef PREFIX_no_rnd_vc1_chroma_mc8_altivec
208
-static void PREFIX_no_rnd_vc1_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) {
209
-   DECLARE_ALIGNED(16, signed int, ABCD)[4] =
210
-                        {((8 - x) * (8 - y)),
211
-                         ((    x) * (8 - y)),
212
-                         ((8 - x) * (    y)),
213
-                         ((    x) * (    y))};
214
-    register int i;
215
-    vec_u8 fperm;
216
-    const vec_s32 vABCD = vec_ld(0, ABCD);
217
-    const vec_s16 vA = vec_splat((vec_s16)vABCD, 1);
218
-    const vec_s16 vB = vec_splat((vec_s16)vABCD, 3);
219
-    const vec_s16 vC = vec_splat((vec_s16)vABCD, 5);
220
-    const vec_s16 vD = vec_splat((vec_s16)vABCD, 7);
221
-    LOAD_ZERO;
222
-    const vec_s16 v28ss = vec_sub(vec_sl(vec_splat_s16(1),vec_splat_u16(5)),vec_splat_s16(4));
223
-    const vec_u16 v6us  = vec_splat_u16(6);
224
-    register int loadSecond     = (((unsigned long)src) % 16) <= 7 ? 0 : 1;
225
-    register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0;
226
-
227
-    vec_u8 vsrcAuc, av_uninit(vsrcBuc), vsrcperm0, vsrcperm1;
228
-    vec_u8 vsrc0uc, vsrc1uc;
229
-    vec_s16 vsrc0ssH, vsrc1ssH;
230
-    vec_u8 vsrcCuc, vsrc2uc, vsrc3uc;
231
-    vec_s16 vsrc2ssH, vsrc3ssH, psum;
232
-    vec_u8 vdst, ppsum, vfdst, fsum;
233
-
234
-    if (((unsigned long)dst) % 16 == 0) {
235
-        fperm = (vec_u8){0x10, 0x11, 0x12, 0x13,
236
-                         0x14, 0x15, 0x16, 0x17,
237
-                         0x08, 0x09, 0x0A, 0x0B,
238
-                         0x0C, 0x0D, 0x0E, 0x0F};
239
-    } else {
240
-        fperm = (vec_u8){0x00, 0x01, 0x02, 0x03,
241
-                         0x04, 0x05, 0x06, 0x07,
242
-                         0x18, 0x19, 0x1A, 0x1B,
243
-                         0x1C, 0x1D, 0x1E, 0x1F};
244
-    }
245
-
246
-    vsrcAuc = vec_ld(0, src);
247
-
248
-    if (loadSecond)
249
-        vsrcBuc = vec_ld(16, src);
250
-    vsrcperm0 = vec_lvsl(0, src);
251
-    vsrcperm1 = vec_lvsl(1, src);
252
-
253
-    vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0);
254
-    if (reallyBadAlign)
255
-        vsrc1uc = vsrcBuc;
256
-    else
257
-        vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1);
258
-
259
-    vsrc0ssH = (vec_s16)vec_mergeh(zero_u8v, (vec_u8)vsrc0uc);
260
-    vsrc1ssH = (vec_s16)vec_mergeh(zero_u8v, (vec_u8)vsrc1uc);
261
-
262
-    if (!loadSecond) {// -> !reallyBadAlign
263
-        for (i = 0 ; i < h ; i++) {
264
-
265
-
266
-            vsrcCuc = vec_ld(stride + 0, src);
267
-
268
-            vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0);
269
-            vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1);
270
-
271
-            CHROMA_MC8_ALTIVEC_CORE(vec_splat_s16(0), add28)
272
-        }
273
-    } else {
274
-        vec_u8 vsrcDuc;
275
-        for (i = 0 ; i < h ; i++) {
276
-            vsrcCuc = vec_ld(stride + 0, src);
277
-            vsrcDuc = vec_ld(stride + 16, src);
278
-
279
-            vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0);
280
-            if (reallyBadAlign)
281
-                vsrc3uc = vsrcDuc;
282
-            else
283
-                vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1);
284
-
285
-            CHROMA_MC8_ALTIVEC_CORE(vec_splat_s16(0), add28)
286
-        }
287
-    }
288
-}
289
-#endif
290
-
291
-#undef noop
292
-#undef add28
293
-#undef CHROMA_MC8_ALTIVEC_CORE
294
-
295
-/* this code assume stride % 16 == 0 */
296
-#ifdef PREFIX_h264_qpel16_h_lowpass_altivec
297
-static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) {
298
-    register int i;
299
-
300
-    LOAD_ZERO;
301
-    const vec_u8 permM2 = vec_lvsl(-2, src);
302
-    const vec_u8 permM1 = vec_lvsl(-1, src);
303
-    const vec_u8 permP0 = vec_lvsl(+0, src);
304
-    const vec_u8 permP1 = vec_lvsl(+1, src);
305
-    const vec_u8 permP2 = vec_lvsl(+2, src);
306
-    const vec_u8 permP3 = vec_lvsl(+3, src);
307
-    const vec_s16 v5ss = vec_splat_s16(5);
308
-    const vec_u16 v5us = vec_splat_u16(5);
309
-    const vec_s16 v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
310
-    const vec_s16 v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4));
311
-
312
-    vec_u8 srcM2, srcM1, srcP0, srcP1, srcP2, srcP3;
313
-
314
-    register int align = ((((unsigned long)src) - 2) % 16);
315
-
316
-    vec_s16 srcP0A, srcP0B, srcP1A, srcP1B,
317
-              srcP2A, srcP2B, srcP3A, srcP3B,
318
-              srcM1A, srcM1B, srcM2A, srcM2B,
319
-              sum1A, sum1B, sum2A, sum2B, sum3A, sum3B,
320
-              pp1A, pp1B, pp2A, pp2B, pp3A, pp3B,
321
-              psumA, psumB, sumA, sumB;
322
-
323
-    vec_u8 sum, vdst, fsum;
324
-
325
-    for (i = 0 ; i < 16 ; i ++) {
326
-        vec_u8 srcR1 = vec_ld(-2, src);
327
-        vec_u8 srcR2 = vec_ld(14, src);
328
-
329
-        switch (align) {
330
-        default: {
331
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
332
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
333
-            srcP0 = vec_perm(srcR1, srcR2, permP0);
334
-            srcP1 = vec_perm(srcR1, srcR2, permP1);
335
-            srcP2 = vec_perm(srcR1, srcR2, permP2);
336
-            srcP3 = vec_perm(srcR1, srcR2, permP3);
337
-        } break;
338
-        case 11: {
339
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
340
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
341
-            srcP0 = vec_perm(srcR1, srcR2, permP0);
342
-            srcP1 = vec_perm(srcR1, srcR2, permP1);
343
-            srcP2 = vec_perm(srcR1, srcR2, permP2);
344
-            srcP3 = srcR2;
345
-        } break;
346
-        case 12: {
347
-            vec_u8 srcR3 = vec_ld(30, src);
348
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
349
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
350
-            srcP0 = vec_perm(srcR1, srcR2, permP0);
351
-            srcP1 = vec_perm(srcR1, srcR2, permP1);
352
-            srcP2 = srcR2;
353
-            srcP3 = vec_perm(srcR2, srcR3, permP3);
354
-        } break;
355
-        case 13: {
356
-            vec_u8 srcR3 = vec_ld(30, src);
357
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
358
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
359
-            srcP0 = vec_perm(srcR1, srcR2, permP0);
360
-            srcP1 = srcR2;
361
-            srcP2 = vec_perm(srcR2, srcR3, permP2);
362
-            srcP3 = vec_perm(srcR2, srcR3, permP3);
363
-        } break;
364
-        case 14: {
365
-            vec_u8 srcR3 = vec_ld(30, src);
366
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
367
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
368
-            srcP0 = srcR2;
369
-            srcP1 = vec_perm(srcR2, srcR3, permP1);
370
-            srcP2 = vec_perm(srcR2, srcR3, permP2);
371
-            srcP3 = vec_perm(srcR2, srcR3, permP3);
372
-        } break;
373
-        case 15: {
374
-            vec_u8 srcR3 = vec_ld(30, src);
375
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
376
-            srcM1 = srcR2;
377
-            srcP0 = vec_perm(srcR2, srcR3, permP0);
378
-            srcP1 = vec_perm(srcR2, srcR3, permP1);
379
-            srcP2 = vec_perm(srcR2, srcR3, permP2);
380
-            srcP3 = vec_perm(srcR2, srcR3, permP3);
381
-        } break;
382
-        }
383
-
384
-        srcP0A = (vec_s16) vec_mergeh(zero_u8v, srcP0);
385
-        srcP0B = (vec_s16) vec_mergel(zero_u8v, srcP0);
386
-        srcP1A = (vec_s16) vec_mergeh(zero_u8v, srcP1);
387
-        srcP1B = (vec_s16) vec_mergel(zero_u8v, srcP1);
388
-
389
-        srcP2A = (vec_s16) vec_mergeh(zero_u8v, srcP2);
390
-        srcP2B = (vec_s16) vec_mergel(zero_u8v, srcP2);
391
-        srcP3A = (vec_s16) vec_mergeh(zero_u8v, srcP3);
392
-        srcP3B = (vec_s16) vec_mergel(zero_u8v, srcP3);
393
-
394
-        srcM1A = (vec_s16) vec_mergeh(zero_u8v, srcM1);
395
-        srcM1B = (vec_s16) vec_mergel(zero_u8v, srcM1);
396
-        srcM2A = (vec_s16) vec_mergeh(zero_u8v, srcM2);
397
-        srcM2B = (vec_s16) vec_mergel(zero_u8v, srcM2);
398
-
399
-        sum1A = vec_adds(srcP0A, srcP1A);
400
-        sum1B = vec_adds(srcP0B, srcP1B);
401
-        sum2A = vec_adds(srcM1A, srcP2A);
402
-        sum2B = vec_adds(srcM1B, srcP2B);
403
-        sum3A = vec_adds(srcM2A, srcP3A);
404
-        sum3B = vec_adds(srcM2B, srcP3B);
405
-
406
-        pp1A = vec_mladd(sum1A, v20ss, v16ss);
407
-        pp1B = vec_mladd(sum1B, v20ss, v16ss);
408
-
409
-        pp2A = vec_mladd(sum2A, v5ss, zero_s16v);
410
-        pp2B = vec_mladd(sum2B, v5ss, zero_s16v);
411
-
412
-        pp3A = vec_add(sum3A, pp1A);
413
-        pp3B = vec_add(sum3B, pp1B);
414
-
415
-        psumA = vec_sub(pp3A, pp2A);
416
-        psumB = vec_sub(pp3B, pp2B);
417
-
418
-        sumA = vec_sra(psumA, v5us);
419
-        sumB = vec_sra(psumB, v5us);
420
-
421
-        sum = vec_packsu(sumA, sumB);
422
-
423
-        ASSERT_ALIGNED(dst);
424
-        vdst = vec_ld(0, dst);
425
-
426
-        OP_U8_ALTIVEC(fsum, sum, vdst);
427
-
428
-        vec_st(fsum, 0, dst);
429
-
430
-        src += srcStride;
431
-        dst += dstStride;
432
-    }
433
-}
434
-#endif
435
-
436
-/* this code assume stride % 16 == 0 */
437
-#ifdef PREFIX_h264_qpel16_v_lowpass_altivec
438
-static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) {
439
-    register int i;
440
-
441
-    LOAD_ZERO;
442
-    const vec_u8 perm = vec_lvsl(0, src);
443
-    const vec_s16 v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
444
-    const vec_u16 v5us = vec_splat_u16(5);
445
-    const vec_s16 v5ss = vec_splat_s16(5);
446
-    const vec_s16 v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4));
447
-
448
-    uint8_t *srcbis = src - (srcStride * 2);
449
-
450
-    const vec_u8 srcM2a = vec_ld(0, srcbis);
451
-    const vec_u8 srcM2b = vec_ld(16, srcbis);
452
-    const vec_u8 srcM2 = vec_perm(srcM2a, srcM2b, perm);
453
-    //srcbis += srcStride;
454
-    const vec_u8 srcM1a = vec_ld(0, srcbis += srcStride);
455
-    const vec_u8 srcM1b = vec_ld(16, srcbis);
456
-    const vec_u8 srcM1 = vec_perm(srcM1a, srcM1b, perm);
457
-    //srcbis += srcStride;
458
-    const vec_u8 srcP0a = vec_ld(0, srcbis += srcStride);
459
-    const vec_u8 srcP0b = vec_ld(16, srcbis);
460
-    const vec_u8 srcP0 = vec_perm(srcP0a, srcP0b, perm);
461
-    //srcbis += srcStride;
462
-    const vec_u8 srcP1a = vec_ld(0, srcbis += srcStride);
463
-    const vec_u8 srcP1b = vec_ld(16, srcbis);
464
-    const vec_u8 srcP1 = vec_perm(srcP1a, srcP1b, perm);
465
-    //srcbis += srcStride;
466
-    const vec_u8 srcP2a = vec_ld(0, srcbis += srcStride);
467
-    const vec_u8 srcP2b = vec_ld(16, srcbis);
468
-    const vec_u8 srcP2 = vec_perm(srcP2a, srcP2b, perm);
469
-    //srcbis += srcStride;
470
-
471
-    vec_s16 srcM2ssA = (vec_s16) vec_mergeh(zero_u8v, srcM2);
472
-    vec_s16 srcM2ssB = (vec_s16) vec_mergel(zero_u8v, srcM2);
473
-    vec_s16 srcM1ssA = (vec_s16) vec_mergeh(zero_u8v, srcM1);
474
-    vec_s16 srcM1ssB = (vec_s16) vec_mergel(zero_u8v, srcM1);
475
-    vec_s16 srcP0ssA = (vec_s16) vec_mergeh(zero_u8v, srcP0);
476
-    vec_s16 srcP0ssB = (vec_s16) vec_mergel(zero_u8v, srcP0);
477
-    vec_s16 srcP1ssA = (vec_s16) vec_mergeh(zero_u8v, srcP1);
478
-    vec_s16 srcP1ssB = (vec_s16) vec_mergel(zero_u8v, srcP1);
479
-    vec_s16 srcP2ssA = (vec_s16) vec_mergeh(zero_u8v, srcP2);
480
-    vec_s16 srcP2ssB = (vec_s16) vec_mergel(zero_u8v, srcP2);
481
-
482
-    vec_s16 pp1A, pp1B, pp2A, pp2B, pp3A, pp3B,
483
-              psumA, psumB, sumA, sumB,
484
-              srcP3ssA, srcP3ssB,
485
-              sum1A, sum1B, sum2A, sum2B, sum3A, sum3B;
486
-
487
-    vec_u8 sum, vdst, fsum, srcP3a, srcP3b, srcP3;
488
-
489
-    for (i = 0 ; i < 16 ; i++) {
490
-        srcP3a = vec_ld(0, srcbis += srcStride);
491
-        srcP3b = vec_ld(16, srcbis);
492
-        srcP3 = vec_perm(srcP3a, srcP3b, perm);
493
-        srcP3ssA = (vec_s16) vec_mergeh(zero_u8v, srcP3);
494
-        srcP3ssB = (vec_s16) vec_mergel(zero_u8v, srcP3);
495
-        //srcbis += srcStride;
496
-
497
-        sum1A = vec_adds(srcP0ssA, srcP1ssA);
498
-        sum1B = vec_adds(srcP0ssB, srcP1ssB);
499
-        sum2A = vec_adds(srcM1ssA, srcP2ssA);
500
-        sum2B = vec_adds(srcM1ssB, srcP2ssB);
501
-        sum3A = vec_adds(srcM2ssA, srcP3ssA);
502
-        sum3B = vec_adds(srcM2ssB, srcP3ssB);
503
-
504
-        srcM2ssA = srcM1ssA;
505
-        srcM2ssB = srcM1ssB;
506
-        srcM1ssA = srcP0ssA;
507
-        srcM1ssB = srcP0ssB;
508
-        srcP0ssA = srcP1ssA;
509
-        srcP0ssB = srcP1ssB;
510
-        srcP1ssA = srcP2ssA;
511
-        srcP1ssB = srcP2ssB;
512
-        srcP2ssA = srcP3ssA;
513
-        srcP2ssB = srcP3ssB;
514
-
515
-        pp1A = vec_mladd(sum1A, v20ss, v16ss);
516
-        pp1B = vec_mladd(sum1B, v20ss, v16ss);
517
-
518
-        pp2A = vec_mladd(sum2A, v5ss, zero_s16v);
519
-        pp2B = vec_mladd(sum2B, v5ss, zero_s16v);
520
-
521
-        pp3A = vec_add(sum3A, pp1A);
522
-        pp3B = vec_add(sum3B, pp1B);
523
-
524
-        psumA = vec_sub(pp3A, pp2A);
525
-        psumB = vec_sub(pp3B, pp2B);
526
-
527
-        sumA = vec_sra(psumA, v5us);
528
-        sumB = vec_sra(psumB, v5us);
529
-
530
-        sum = vec_packsu(sumA, sumB);
531
-
532
-        ASSERT_ALIGNED(dst);
533
-        vdst = vec_ld(0, dst);
534
-
535
-        OP_U8_ALTIVEC(fsum, sum, vdst);
536
-
537
-        vec_st(fsum, 0, dst);
538
-
539
-        dst += dstStride;
540
-    }
541
-}
542
-#endif
543
-
544
-/* this code assume stride % 16 == 0 *and* tmp is properly aligned */
545
-#ifdef PREFIX_h264_qpel16_hv_lowpass_altivec
546
-static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, uint8_t * src, int dstStride, int tmpStride, int srcStride) {
547
-    register int i;
548
-    LOAD_ZERO;
549
-    const vec_u8 permM2 = vec_lvsl(-2, src);
550
-    const vec_u8 permM1 = vec_lvsl(-1, src);
551
-    const vec_u8 permP0 = vec_lvsl(+0, src);
552
-    const vec_u8 permP1 = vec_lvsl(+1, src);
553
-    const vec_u8 permP2 = vec_lvsl(+2, src);
554
-    const vec_u8 permP3 = vec_lvsl(+3, src);
555
-    const vec_s16 v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2));
556
-    const vec_u32 v10ui = vec_splat_u32(10);
557
-    const vec_s16 v5ss = vec_splat_s16(5);
558
-    const vec_s16 v1ss = vec_splat_s16(1);
559
-    const vec_s32 v512si = vec_sl(vec_splat_s32(1),vec_splat_u32(9));
560
-    const vec_u32 v16ui = vec_sl(vec_splat_u32(1),vec_splat_u32(4));
561
-
562
-    register int align = ((((unsigned long)src) - 2) % 16);
563
-
564
-    vec_s16 srcP0A, srcP0B, srcP1A, srcP1B,
565
-              srcP2A, srcP2B, srcP3A, srcP3B,
566
-              srcM1A, srcM1B, srcM2A, srcM2B,
567
-              sum1A, sum1B, sum2A, sum2B, sum3A, sum3B,
568
-              pp1A, pp1B, pp2A, pp2B, psumA, psumB;
569
-
570
-    const vec_u8 mperm = (const vec_u8)
571
-        {0x00, 0x08, 0x01, 0x09, 0x02, 0x0A, 0x03, 0x0B,
572
-         0x04, 0x0C, 0x05, 0x0D, 0x06, 0x0E, 0x07, 0x0F};
573
-    int16_t *tmpbis = tmp;
574
-
575
-    vec_s16 tmpM1ssA, tmpM1ssB, tmpM2ssA, tmpM2ssB,
576
-              tmpP0ssA, tmpP0ssB, tmpP1ssA, tmpP1ssB,
577
-              tmpP2ssA, tmpP2ssB;
578
-
579
-    vec_s32 pp1Ae, pp1Ao, pp1Be, pp1Bo, pp2Ae, pp2Ao, pp2Be, pp2Bo,
580
-              pp3Ae, pp3Ao, pp3Be, pp3Bo, pp1cAe, pp1cAo, pp1cBe, pp1cBo,
581
-              pp32Ae, pp32Ao, pp32Be, pp32Bo, sumAe, sumAo, sumBe, sumBo,
582
-              ssumAe, ssumAo, ssumBe, ssumBo;
583
-    vec_u8 fsum, sumv, sum, vdst;
584
-    vec_s16 ssume, ssumo;
585
-
586
-    src -= (2 * srcStride);
587
-    for (i = 0 ; i < 21 ; i ++) {
588
-        vec_u8 srcM2, srcM1, srcP0, srcP1, srcP2, srcP3;
589
-        vec_u8 srcR1 = vec_ld(-2, src);
590
-        vec_u8 srcR2 = vec_ld(14, src);
591
-
592
-        switch (align) {
593
-        default: {
594
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
595
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
596
-            srcP0 = vec_perm(srcR1, srcR2, permP0);
597
-            srcP1 = vec_perm(srcR1, srcR2, permP1);
598
-            srcP2 = vec_perm(srcR1, srcR2, permP2);
599
-            srcP3 = vec_perm(srcR1, srcR2, permP3);
600
-        } break;
601
-        case 11: {
602
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
603
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
604
-            srcP0 = vec_perm(srcR1, srcR2, permP0);
605
-            srcP1 = vec_perm(srcR1, srcR2, permP1);
606
-            srcP2 = vec_perm(srcR1, srcR2, permP2);
607
-            srcP3 = srcR2;
608
-        } break;
609
-        case 12: {
610
-            vec_u8 srcR3 = vec_ld(30, src);
611
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
612
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
613
-            srcP0 = vec_perm(srcR1, srcR2, permP0);
614
-            srcP1 = vec_perm(srcR1, srcR2, permP1);
615
-            srcP2 = srcR2;
616
-            srcP3 = vec_perm(srcR2, srcR3, permP3);
617
-        } break;
618
-        case 13: {
619
-            vec_u8 srcR3 = vec_ld(30, src);
620
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
621
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
622
-            srcP0 = vec_perm(srcR1, srcR2, permP0);
623
-            srcP1 = srcR2;
624
-            srcP2 = vec_perm(srcR2, srcR3, permP2);
625
-            srcP3 = vec_perm(srcR2, srcR3, permP3);
626
-        } break;
627
-        case 14: {
628
-            vec_u8 srcR3 = vec_ld(30, src);
629
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
630
-            srcM1 = vec_perm(srcR1, srcR2, permM1);
631
-            srcP0 = srcR2;
632
-            srcP1 = vec_perm(srcR2, srcR3, permP1);
633
-            srcP2 = vec_perm(srcR2, srcR3, permP2);
634
-            srcP3 = vec_perm(srcR2, srcR3, permP3);
635
-        } break;
636
-        case 15: {
637
-            vec_u8 srcR3 = vec_ld(30, src);
638
-            srcM2 = vec_perm(srcR1, srcR2, permM2);
639
-            srcM1 = srcR2;
640
-            srcP0 = vec_perm(srcR2, srcR3, permP0);
641
-            srcP1 = vec_perm(srcR2, srcR3, permP1);
642
-            srcP2 = vec_perm(srcR2, srcR3, permP2);
643
-            srcP3 = vec_perm(srcR2, srcR3, permP3);
644
-        } break;
645
-        }
646
-
647
-        srcP0A = (vec_s16) vec_mergeh(zero_u8v, srcP0);
648
-        srcP0B = (vec_s16) vec_mergel(zero_u8v, srcP0);
649
-        srcP1A = (vec_s16) vec_mergeh(zero_u8v, srcP1);
650
-        srcP1B = (vec_s16) vec_mergel(zero_u8v, srcP1);
651
-
652
-        srcP2A = (vec_s16) vec_mergeh(zero_u8v, srcP2);
653
-        srcP2B = (vec_s16) vec_mergel(zero_u8v, srcP2);
654
-        srcP3A = (vec_s16) vec_mergeh(zero_u8v, srcP3);
655
-        srcP3B = (vec_s16) vec_mergel(zero_u8v, srcP3);
656
-
657
-        srcM1A = (vec_s16) vec_mergeh(zero_u8v, srcM1);
658
-        srcM1B = (vec_s16) vec_mergel(zero_u8v, srcM1);
659
-        srcM2A = (vec_s16) vec_mergeh(zero_u8v, srcM2);
660
-        srcM2B = (vec_s16) vec_mergel(zero_u8v, srcM2);
661
-
662
-        sum1A = vec_adds(srcP0A, srcP1A);
663
-        sum1B = vec_adds(srcP0B, srcP1B);
664
-        sum2A = vec_adds(srcM1A, srcP2A);
665
-        sum2B = vec_adds(srcM1B, srcP2B);
666
-        sum3A = vec_adds(srcM2A, srcP3A);
667
-        sum3B = vec_adds(srcM2B, srcP3B);
668
-
669
-        pp1A = vec_mladd(sum1A, v20ss, sum3A);
670
-        pp1B = vec_mladd(sum1B, v20ss, sum3B);
671
-
672
-        pp2A = vec_mladd(sum2A, v5ss, zero_s16v);
673
-        pp2B = vec_mladd(sum2B, v5ss, zero_s16v);
674
-
675
-        psumA = vec_sub(pp1A, pp2A);
676
-        psumB = vec_sub(pp1B, pp2B);
677
-
678
-        vec_st(psumA, 0, tmp);
679
-        vec_st(psumB, 16, tmp);
680
-
681
-        src += srcStride;
682
-        tmp += tmpStride; /* int16_t*, and stride is 16, so it's OK here */
683
-    }
684
-
685
-    tmpM2ssA = vec_ld(0, tmpbis);
686
-    tmpM2ssB = vec_ld(16, tmpbis);
687
-    tmpbis += tmpStride;
688
-    tmpM1ssA = vec_ld(0, tmpbis);
689
-    tmpM1ssB = vec_ld(16, tmpbis);
690
-    tmpbis += tmpStride;
691
-    tmpP0ssA = vec_ld(0, tmpbis);
692
-    tmpP0ssB = vec_ld(16, tmpbis);
693
-    tmpbis += tmpStride;
694
-    tmpP1ssA = vec_ld(0, tmpbis);
695
-    tmpP1ssB = vec_ld(16, tmpbis);
696
-    tmpbis += tmpStride;
697
-    tmpP2ssA = vec_ld(0, tmpbis);
698
-    tmpP2ssB = vec_ld(16, tmpbis);
699
-    tmpbis += tmpStride;
700
-
701
-    for (i = 0 ; i < 16 ; i++) {
702
-        const vec_s16 tmpP3ssA = vec_ld(0, tmpbis);
703
-        const vec_s16 tmpP3ssB = vec_ld(16, tmpbis);
704
-
705
-        const vec_s16 sum1A = vec_adds(tmpP0ssA, tmpP1ssA);
706
-        const vec_s16 sum1B = vec_adds(tmpP0ssB, tmpP1ssB);
707
-        const vec_s16 sum2A = vec_adds(tmpM1ssA, tmpP2ssA);
708
-        const vec_s16 sum2B = vec_adds(tmpM1ssB, tmpP2ssB);
709
-        const vec_s16 sum3A = vec_adds(tmpM2ssA, tmpP3ssA);
710
-        const vec_s16 sum3B = vec_adds(tmpM2ssB, tmpP3ssB);
711
-
712
-        tmpbis += tmpStride;
713
-
714
-        tmpM2ssA = tmpM1ssA;
715
-        tmpM2ssB = tmpM1ssB;
716
-        tmpM1ssA = tmpP0ssA;
717
-        tmpM1ssB = tmpP0ssB;
718
-        tmpP0ssA = tmpP1ssA;
719
-        tmpP0ssB = tmpP1ssB;
720
-        tmpP1ssA = tmpP2ssA;
721
-        tmpP1ssB = tmpP2ssB;
722
-        tmpP2ssA = tmpP3ssA;
723
-        tmpP2ssB = tmpP3ssB;
724
-
725
-        pp1Ae = vec_mule(sum1A, v20ss);
726
-        pp1Ao = vec_mulo(sum1A, v20ss);
727
-        pp1Be = vec_mule(sum1B, v20ss);
728
-        pp1Bo = vec_mulo(sum1B, v20ss);
729
-
730
-        pp2Ae = vec_mule(sum2A, v5ss);
731
-        pp2Ao = vec_mulo(sum2A, v5ss);
732
-        pp2Be = vec_mule(sum2B, v5ss);
733
-        pp2Bo = vec_mulo(sum2B, v5ss);
734
-
735
-        pp3Ae = vec_sra((vec_s32)sum3A, v16ui);
736
-        pp3Ao = vec_mulo(sum3A, v1ss);
737
-        pp3Be = vec_sra((vec_s32)sum3B, v16ui);
738
-        pp3Bo = vec_mulo(sum3B, v1ss);
739
-
740
-        pp1cAe = vec_add(pp1Ae, v512si);
741
-        pp1cAo = vec_add(pp1Ao, v512si);
742
-        pp1cBe = vec_add(pp1Be, v512si);
743
-        pp1cBo = vec_add(pp1Bo, v512si);
744
-
745
-        pp32Ae = vec_sub(pp3Ae, pp2Ae);
746
-        pp32Ao = vec_sub(pp3Ao, pp2Ao);
747
-        pp32Be = vec_sub(pp3Be, pp2Be);
748
-        pp32Bo = vec_sub(pp3Bo, pp2Bo);
749
-
750
-        sumAe = vec_add(pp1cAe, pp32Ae);
751
-        sumAo = vec_add(pp1cAo, pp32Ao);
752
-        sumBe = vec_add(pp1cBe, pp32Be);
753
-        sumBo = vec_add(pp1cBo, pp32Bo);
754
-
755
-        ssumAe = vec_sra(sumAe, v10ui);
756
-        ssumAo = vec_sra(sumAo, v10ui);
757
-        ssumBe = vec_sra(sumBe, v10ui);
758
-        ssumBo = vec_sra(sumBo, v10ui);
759
-
760
-        ssume = vec_packs(ssumAe, ssumBe);
761
-        ssumo = vec_packs(ssumAo, ssumBo);
762
-
763
-        sumv = vec_packsu(ssume, ssumo);
764
-        sum = vec_perm(sumv, sumv, mperm);
765
-
766
-        ASSERT_ALIGNED(dst);
767
-        vdst = vec_ld(0, dst);
768
-
769
-        OP_U8_ALTIVEC(fsum, sum, vdst);
770
-
771
-        vec_st(fsum, 0, dst);
772
-
773
-        dst += dstStride;
774
-    }
775
-}
776
-#endif
... ...
@@ -325,13 +325,13 @@ static void vc1_inv_trans_8x4_altivec(uint8_t *dest, int stride, DCTELEM *block)
325 325
 
326 326
 #define OP_U8_ALTIVEC                          PUT_OP_U8_ALTIVEC
327 327
 #define PREFIX_no_rnd_vc1_chroma_mc8_altivec   put_no_rnd_vc1_chroma_mc8_altivec
328
-#include "h264_template_altivec.c"
328
+#include "h264_altivec_template.c"
329 329
 #undef OP_U8_ALTIVEC
330 330
 #undef PREFIX_no_rnd_vc1_chroma_mc8_altivec
331 331
 
332 332
 #define OP_U8_ALTIVEC                          AVG_OP_U8_ALTIVEC
333 333
 #define PREFIX_no_rnd_vc1_chroma_mc8_altivec   avg_no_rnd_vc1_chroma_mc8_altivec
334
-#include "h264_template_altivec.c"
334
+#include "h264_altivec_template.c"
335 335
 #undef OP_U8_ALTIVEC
336 336
 #undef PREFIX_no_rnd_vc1_chroma_mc8_altivec
337 337
 
... ...
@@ -22,6 +22,7 @@
22 22
 #include "libavutil/log.h"
23 23
 #include "libavutil/opt.h"
24 24
 
25
+
25 26
 typedef struct {
26 27
     AVClass *av_class;
27 28
     int custom_stride;
... ...
@@ -92,7 +92,13 @@ static int process_callback(jack_nframes_t nframes, void *arg)
92 92
 
93 93
     /* Copy and interleave audio data from the JACK buffer into the packet */
94 94
     for (i = 0; i < self->nports; i++) {
95
+    #if HAVE_JACK_PORT_GET_LATENCY_RANGE
96
+        jack_latency_range_t range;
97
+        jack_port_get_latency_range(self->ports[i], JackCaptureLatency, &range);
98
+        latency += range.max;
99
+    #else
95 100
         latency += jack_port_get_total_latency(self->client, self->ports[i]);
101
+    #endif
96 102
         buffer = jack_port_get_buffer(self->ports[i], self->buffer_size);
97 103
         for (j = 0; j < self->buffer_size; j++)
98 104
             pkt_data[j * self->nports + i] = buffer[j];
... ...
@@ -1,9 +1,10 @@
1 1
 include $(SUBDIR)../config.mak
2 2
 
3 3
 NAME = avfilter
4
-FFLIBS = avutil swscale
4
+FFLIBS = avutil
5 5
 FFLIBS-$(CONFIG_ASYNCTS_FILTER) += avresample
6 6
 FFLIBS-$(CONFIG_RESAMPLE_FILTER) += avresample
7
+FFLIBS-$(CONFIG_SCALE_FILTER)   += swscale
7 8
 
8 9
 FFLIBS-$(CONFIG_ACONVERT_FILTER)             += swresample
9 10
 FFLIBS-$(CONFIG_AMOVIE_FILTER)               += avformat avcodec
... ...
@@ -54,6 +55,7 @@ OBJS-$(CONFIG_ASHOWINFO_FILTER)              += af_ashowinfo.o
54 54
 OBJS-$(CONFIG_ASPLIT_FILTER)                 += split.o
55 55
 OBJS-$(CONFIG_ASTREAMSYNC_FILTER)            += af_astreamsync.o
56 56
 OBJS-$(CONFIG_ASYNCTS_FILTER)                += af_asyncts.o
57
+OBJS-$(CONFIG_CHANNELSPLIT_FILTER)           += af_channelsplit.o
57 58
 OBJS-$(CONFIG_EARWAX_FILTER)                 += af_earwax.o
58 59
 OBJS-$(CONFIG_PAN_FILTER)                    += af_pan.o
59 60
 OBJS-$(CONFIG_RESAMPLE_FILTER)               += af_resample.o
... ...
@@ -102,6 +104,7 @@ OBJS-$(CONFIG_OVERLAY_FILTER)                += vf_overlay.o
102 102
 OBJS-$(CONFIG_PAD_FILTER)                    += vf_pad.o
103 103
 OBJS-$(CONFIG_PIXDESCTEST_FILTER)            += vf_pixdesctest.o
104 104
 OBJS-$(CONFIG_REMOVELOGO_FILTER)             += bbox.o lswsutils.o lavfutils.o vf_removelogo.o
105
+OBJS-$(CONFIG_SCALE_FILTER)                  += vf_scale.o
105 106
 OBJS-$(CONFIG_SELECT_FILTER)                 += vf_select.o
106 107
 OBJS-$(CONFIG_SETDAR_FILTER)                 += vf_aspect.o
107 108
 OBJS-$(CONFIG_SETFIELD_FILTER)               += vf_setfield.o
... ...
@@ -118,7 +118,7 @@ static int query_formats(AVFilterContext *ctx)
118 118
                 if ((inlayout[i] >> c) & 1)
119 119
                     *(route[i]++) = out_ch_number++;
120 120
     }
121
-    formats = avfilter_make_format_list(ff_packed_sample_fmts);
121
+    formats = avfilter_make_format_list(ff_packed_sample_fmts_array);
122 122
     avfilter_set_common_sample_formats(ctx, formats);
123 123
     for (i = 0; i < am->nb_inputs; i++) {
124 124
         layouts = NULL;
... ...
@@ -454,10 +454,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
454 454
     AVFilterLink *outlink = ctx->outputs[0];
455 455
     int i;
456 456
 
457
-    for (i = 0; i < ctx->input_count; i++)
457
+    for (i = 0; i < ctx->nb_inputs; i++)
458 458
         if (ctx->inputs[i] == inlink)
459 459
             break;
460
-    if (i >= ctx->input_count) {
460
+    if (i >= ctx->nb_inputs) {
461 461
         av_log(ctx, AV_LOG_ERROR, "unknown input link\n");
462 462
         return;
463 463
     }
... ...
@@ -518,7 +518,7 @@ static void uninit(AVFilterContext *ctx)
518 518
     av_freep(&s->input_state);
519 519
     av_freep(&s->input_scale);
520 520
 
521
-    for (i = 0; i < ctx->input_count; i++)
521
+    for (i = 0; i < ctx->nb_inputs; i++)
522 522
         av_freep(&ctx->input_pads[i].name);
523 523
 }
524 524
 
... ...
@@ -24,6 +24,7 @@
24 24
 
25 25
 #include "audio.h"
26 26
 #include "avfilter.h"
27
+#include "internal.h"
27 28
 
28 29
 AVFilter avfilter_af_anull = {
29 30
     .name      = "anull",
30 31
new file mode 100644
... ...
@@ -0,0 +1,146 @@
0
+/*
1
+ * This file is part of Libav.
2
+ *
3
+ * Libav is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * Libav is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with Libav; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+/**
19
+ * @file
20
+ * Channel split filter
21
+ *
22
+ * Split an audio stream into per-channel streams.
23
+ */
24
+
25
+#include "libavutil/audioconvert.h"
26
+#include "libavutil/opt.h"
27
+
28
+#include "audio.h"
29
+#include "avfilter.h"
30
+#include "formats.h"
31
+#include "internal.h"
32
+
33
+typedef struct ChannelSplitContext {
34
+    const AVClass *class;
35
+
36
+    uint64_t channel_layout;
37
+    char    *channel_layout_str;
38
+} ChannelSplitContext;
39
+
40
+#define OFFSET(x) offsetof(ChannelSplitContext, x)
41
+#define A AV_OPT_FLAG_AUDIO_PARAM
42
+static const AVOption options[] = {
43
+    { "channel_layout", "Input channel layout.", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, { .str = "stereo" }, .flags = A },
44
+    { NULL },
45
+};
46
+
47
+static const AVClass channelsplit_class = {
48
+    .class_name = "channelsplit filter",
49
+    .item_name  = av_default_item_name,
50
+    .option     = options,
51
+    .version    = LIBAVUTIL_VERSION_INT,
52
+};
53
+
54
+static int init(AVFilterContext *ctx, const char *arg, void *opaque)
55
+{
56
+    ChannelSplitContext *s = ctx->priv;
57
+    int nb_channels;
58
+    int ret = 0, i;
59
+
60
+    s->class = &channelsplit_class;
61
+    av_opt_set_defaults(s);
62
+    if ((ret = av_set_options_string(s, arg, "=", ":")) < 0) {
63
+        av_log(ctx, AV_LOG_ERROR, "Error parsing options string '%s'.\n", arg);
64
+        return ret;
65
+    }
66
+    if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) {
67
+        av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
68
+               s->channel_layout_str);
69
+        ret = AVERROR(EINVAL);
70
+        goto fail;
71
+    }
72
+
73
+    nb_channels = av_get_channel_layout_nb_channels(s->channel_layout);
74
+    for (i = 0; i < nb_channels; i++) {
75
+        uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i);
76
+        AVFilterPad pad  = { 0 };
77
+
78
+        pad.type = AVMEDIA_TYPE_AUDIO;
79
+        pad.name = av_get_channel_name(channel);
80
+
81
+        ff_insert_outpad(ctx, i, &pad);
82
+    }
83
+
84
+fail:
85
+    av_opt_free(s);
86
+    return ret;
87
+}
88
+
89
+static int query_formats(AVFilterContext *ctx)
90
+{
91
+    ChannelSplitContext *s = ctx->priv;
92
+    AVFilterChannelLayouts *in_layouts = NULL;
93
+    int i;
94
+
95
+    ff_set_common_formats    (ctx, ff_planar_sample_fmts());
96
+    ff_set_common_samplerates(ctx, ff_all_samplerates());
97
+
98
+    ff_add_channel_layout(&in_layouts, s->channel_layout);
99
+    ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts);
100
+
101
+    for (i = 0; i < ctx->nb_outputs; i++) {
102
+        AVFilterChannelLayouts *out_layouts = NULL;
103
+        uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i);
104
+
105
+        ff_add_channel_layout(&out_layouts, channel);
106
+        ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->in_channel_layouts);
107
+    }
108
+
109
+    return 0;
110
+}
111
+
112
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
113
+{
114
+    AVFilterContext *ctx = inlink->dst;
115
+    int i;
116
+
117
+    for (i = 0; i < ctx->nb_outputs; i++) {
118
+        AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE);
119
+
120
+        if (!buf_out)
121
+            return;
122
+
123
+        buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i];
124
+        buf_out->audio->channel_layout =
125
+            av_channel_layout_extract_channel(buf->audio->channel_layout, i);
126
+
127
+        ff_filter_samples(ctx->outputs[i], buf_out);
128
+    }
129
+    avfilter_unref_buffer(buf);
130
+}
131
+
132
+AVFilter avfilter_af_channelsplit = {
133
+    .name           = "channelsplit",
134
+    .description    = NULL_IF_CONFIG_SMALL("Split audio into per-channel streams"),
135
+    .priv_size      = sizeof(ChannelSplitContext),
136
+
137
+    .init           = init,
138
+    .query_formats  = query_formats,
139
+
140
+    .inputs  = (const AVFilterPad[]){{ .name           = "default",
141
+                                       .type           = AVMEDIA_TYPE_AUDIO,
142
+                                       .filter_samples = filter_samples, },
143
+                                     { NULL }},
144
+    .outputs = (const AVFilterPad[]){{ NULL }},
145
+};
... ...
@@ -44,6 +44,7 @@ void avfilter_register_all(void)
44 44
     REGISTER_FILTER (ASPLIT,      asplit,      af);
45 45
     REGISTER_FILTER (ASTREAMSYNC, astreamsync, af);
46 46
     REGISTER_FILTER (ASYNCTS,     asyncts,     af);
47
+    REGISTER_FILTER (CHANNELSPLIT,channelsplit,af);
47 48
     REGISTER_FILTER (EARWAX,      earwax,      af);
48 49
     REGISTER_FILTER (PAN,         pan,         af);
49 50
     REGISTER_FILTER (SILENCEDETECT, silencedetect, af);
... ...
@@ -92,6 +93,7 @@ void avfilter_register_all(void)
92 92
     REGISTER_FILTER (PAD,         pad,         vf);
93 93
     REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf);
94 94
     REGISTER_FILTER (REMOVELOGO,  removelogo,  vf);
95
+    REGISTER_FILTER (SCALE,       scale,       vf);
95 96
     REGISTER_FILTER (SELECT,      select,      vf);
96 97
     REGISTER_FILTER (SETDAR,      setdar,      vf);
97 98
     REGISTER_FILTER (SETFIELD,    setfield,    vf);
... ...
@@ -143,8 +145,4 @@ void avfilter_register_all(void)
143 143
         extern AVFilter avfilter_asink_abuffer;
144 144
         avfilter_register(&avfilter_asink_abuffer);
145 145
     }
146
-    {
147
-        extern AVFilter avfilter_vf_scale;
148
-        avfilter_register(&avfilter_vf_scale);
149
-    }
150 146
 }
... ...
@@ -19,6 +19,7 @@
19 19
  */
20 20
 
21 21
 #include "avfilter.h"
22
+#include "internal.h"
22 23
 
23 24
 static void null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { }
24 25
 
... ...
@@ -24,6 +24,7 @@
24 24
  * null audio source
25 25
  */
26 26
 
27
+#include "internal.h"
27 28
 #include "libavutil/audioconvert.h"
28 29
 #include "libavutil/opt.h"
29 30
 
... ...
@@ -160,7 +160,7 @@ void ff_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesr
160 160
 {
161 161
     AVFilterLink *outlink = NULL;
162 162
 
163
-    if (inlink->dst->output_count)
163
+    if (inlink->dst->nb_outputs)
164 164
         outlink = inlink->dst->outputs[0];
165 165
 
166 166
     if (outlink) {
... ...
@@ -190,10 +190,7 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
190 190
     /* prepare to copy the samples if the buffer has insufficient permissions */
191 191
     if ((dst->min_perms & samplesref->perms) != dst->min_perms ||
192 192
         dst->rej_perms & samplesref->perms) {
193
-        int  i, size, planar = av_sample_fmt_is_planar(samplesref->format);
194
-        int planes = !planar ? 1:
195
-                     av_get_channel_layout_nb_channels(samplesref->audio->channel_layout);
196
-
193
+        int size;
197 194
         av_log(link->dst, AV_LOG_DEBUG,
198 195
                "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n",
199 196
                samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);
... ...
@@ -204,13 +201,10 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
204 204
         link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
205 205
 
206 206
         /* Copy actual data into new samples buffer */
207
-        /* src can be larger than dst if it was allocated larger than necessary.
208
-           dst can be slightly larger due to extra alignment padding. */
209
-        size = FFMIN(samplesref->linesize[0], link->cur_buf->linesize[0]);
210
-        for (i = 0; samplesref->data[i] && i < 8; i++)
211
-            memcpy(link->cur_buf->data[i], samplesref->data[i], size);
212
-        for (i = 0; i < planes; i++)
213
-            memcpy(link->cur_buf->extended_data[i], samplesref->extended_data[i], size);
207
+        av_samples_copy(link->cur_buf->extended_data, samplesref->extended_data,
208
+                        0, 0, samplesref->audio->nb_samples,
209
+                        av_get_channel_layout_nb_channels(link->channel_layout),
210
+                        link->format);
214 211
 
215 212
         avfilter_unref_buffer(samplesref);
216 213
     } else
... ...
@@ -24,7 +24,7 @@
24 24
 
25 25
 #include "avfilter.h"
26 26
 
27
-static const enum AVSampleFormat ff_packed_sample_fmts[] = {
27
+static const enum AVSampleFormat ff_packed_sample_fmts_array[] = {
28 28
     AV_SAMPLE_FMT_U8,
29 29
     AV_SAMPLE_FMT_S16,
30 30
     AV_SAMPLE_FMT_S32,
... ...
@@ -33,7 +33,7 @@ static const enum AVSampleFormat ff_packed_sample_fmts[] = {
33 33
     AV_SAMPLE_FMT_NONE
34 34
 };
35 35
 
36
-static const enum AVSampleFormat ff_planar_sample_fmts[] = {
36
+static const enum AVSampleFormat ff_planar_sample_fmts_array[] = {
37 37
     AV_SAMPLE_FMT_U8P,
38 38
     AV_SAMPLE_FMT_S16P,
39 39
     AV_SAMPLE_FMT_S32P,
... ...
@@ -120,8 +120,8 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
120 120
 {
121 121
     AVFilterLink *link;
122 122
 
123
-    if (src->output_count <= srcpad || dst->input_count <= dstpad ||
124
-        src->outputs[srcpad]        || dst->inputs[dstpad])
123
+    if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad ||
124
+        src->outputs[srcpad]      || dst->inputs[dstpad])
125 125
         return -1;
126 126
 
127 127
     if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) {
... ...
@@ -200,9 +200,9 @@ int avfilter_config_links(AVFilterContext *filter)
200 200
     unsigned i;
201 201
     int ret;
202 202
 
203
-    for (i = 0; i < filter->input_count; i ++) {
203
+    for (i = 0; i < filter->nb_inputs; i ++) {
204 204
         AVFilterLink *link = filter->inputs[i];
205
-        AVFilterLink *inlink = link->src->input_count ?
205
+        AVFilterLink *inlink = link->src->nb_inputs ?
206 206
             link->src->inputs[0] : NULL;
207 207
 
208 208
         if (!link) continue;
... ...
@@ -222,7 +222,7 @@ int avfilter_config_links(AVFilterContext *filter)
222 222
                 return ret;
223 223
 
224 224
             if (!(config_link = link->srcpad->config_props)) {
225
-                if (link->src->input_count != 1) {
225
+                if (link->src->nb_inputs != 1) {
226 226
                     av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
227 227
                                                     "with more than one input "
228 228
                                                     "must set config_props() "
... ...
@@ -335,7 +335,7 @@ int ff_poll_frame(AVFilterLink *link)
335 335
     if (link->srcpad->poll_frame)
336 336
         return link->srcpad->poll_frame(link);
337 337
 
338
-    for (i = 0; i < link->src->input_count; i++) {
338
+    for (i = 0; i < link->src->nb_inputs; i++) {
339 339
         int val;
340 340
         if (!link->src->inputs[i])
341 341
             return -1;
... ...
@@ -450,27 +450,31 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in
450 450
             goto err;
451 451
     }
452 452
 
453
-    ret->input_count  = pad_count(filter->inputs);
454
-    if (ret->input_count) {
455
-        ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->input_count);
453
+    ret->nb_inputs = pad_count(filter->inputs);
454
+    if (ret->nb_inputs ) {
455
+        ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
456 456
         if (!ret->input_pads)
457 457
             goto err;
458
-        memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count);
459
-        ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
458
+        memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs);
459
+        ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs);
460 460
         if (!ret->inputs)
461 461
             goto err;
462 462
     }
463 463
 
464
-    ret->output_count = pad_count(filter->outputs);
465
-    if (ret->output_count) {
466
-        ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->output_count);
464
+    ret->nb_outputs = pad_count(filter->outputs);
465
+    if (ret->nb_outputs) {
466
+        ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs);
467 467
         if (!ret->output_pads)
468 468
             goto err;
469
-        memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count);
470
-        ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
469
+        memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs);
470
+        ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs);
471 471
         if (!ret->outputs)
472 472
             goto err;
473 473
     }
474
+#if FF_API_FOO_COUNT
475
+    ret->output_count = ret->nb_outputs;
476
+    ret->input_count  = ret->nb_inputs;
477
+#endif
474 478
 
475 479
     *filter_ctx = ret;
476 480
     return 0;
... ...
@@ -478,10 +482,10 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in
478 478
 err:
479 479
     av_freep(&ret->inputs);
480 480
     av_freep(&ret->input_pads);
481
-    ret->input_count = 0;
481
+    ret->nb_inputs = 0;
482 482
     av_freep(&ret->outputs);
483 483
     av_freep(&ret->output_pads);
484
-    ret->output_count = 0;
484
+    ret->nb_outputs = 0;
485 485
     av_freep(&ret->priv);
486 486
     av_free(ret);
487 487
     return AVERROR(ENOMEM);
... ...
@@ -498,7 +502,7 @@ void avfilter_free(AVFilterContext *filter)
498 498
     if (filter->filter->uninit)
499 499
         filter->filter->uninit(filter);
500 500
 
501
-    for (i = 0; i < filter->input_count; i++) {
501
+    for (i = 0; i < filter->nb_inputs; i++) {
502 502
         if ((link = filter->inputs[i])) {
503 503
             if (link->src)
504 504
                 link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
... ...
@@ -511,7 +515,7 @@ void avfilter_free(AVFilterContext *filter)
511 511
         }
512 512
         avfilter_link_free(&link);
513 513
     }
514
-    for (i = 0; i < filter->output_count; i++) {
514
+    for (i = 0; i < filter->nb_outputs; i++) {
515 515
         if ((link = filter->outputs[i])) {
516 516
             if (link->dst)
517 517
                 link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
... ...
@@ -546,6 +550,16 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
546 546
     return ret;
547 547
 }
548 548
 
549
+const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx)
550
+{
551
+    return pads[pad_idx].name;
552
+}
553
+
554
+enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx)
555
+{
556
+    return pads[pad_idx].type;
557
+}
558
+
549 559
 #if FF_API_DEFAULT_CONFIG_OUTPUT_LINK
550 560
 void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
551 561
                          AVFilterPad **pads, AVFilterLink ***links,
... ...
@@ -556,14 +570,20 @@ void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
556 556
 void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
557 557
                            AVFilterPad *p)
558 558
 {
559
-    ff_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad),
559
+    ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
560 560
                   &f->input_pads, &f->inputs, p);
561
+#if FF_API_FOO_COUNT
562
+    f->input_count = f->nb_inputs;
563
+#endif
561 564
 }
562 565
 void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
563 566
                             AVFilterPad *p)
564 567
 {
565
-    ff_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad),
568
+    ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
566 569
                   &f->output_pads, &f->outputs, p);
570
+#if FF_API_FOO_COUNT
571
+    f->output_count = f->nb_outputs;
572
+#endif
567 573
 }
568 574
 int avfilter_poll_frame(AVFilterLink *link)
569 575
 {
... ...
@@ -369,10 +369,16 @@ void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *
369 369
  */
370 370
 #endif
371 371
 
372
+#if FF_API_AVFILTERPAD_PUBLIC
372 373
 /**
373 374
  * A filter pad used for either input or output.
374 375
  *
375 376
  * See doc/filter_design.txt for details on how to implement the methods.
377
+ *
378
+ * @warning this struct might be removed from public API.
379
+ * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
380
+ * to access the name and type fields; there should be no need to access
381
+ * any other fields from outside of libavfilter.
376 382
  */
377 383
 struct AVFilterPad {
378 384
     /**
... ...
@@ -499,6 +505,29 @@ struct AVFilterPad {
499 499
      */
500 500
     int (*config_props)(AVFilterLink *link);
501 501
 };
502
+#endif
503
+
504
+/**
505
+ * Get the name of an AVFilterPad.
506
+ *
507
+ * @param pads an array of AVFilterPads
508
+ * @param pad_idx index of the pad in the array it; is the caller's
509
+ *                responsibility to ensure the index is valid
510
+ *
511
+ * @return name of the pad_idx'th pad in pads
512
+ */
513
+const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx);
514
+
515
+/**
516
+ * Get the type of an AVFilterPad.
517
+ *
518
+ * @param pads an array of AVFilterPads
519
+ * @param pad_idx index of the pad in the array; it is the caller's
520
+ *                responsibility to ensure the index is valid
521
+ *
522
+ * @return type of the pad_idx'th pad in pads
523
+ */
524
+enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx);
502 525
 
503 526
 #if FF_API_FILTERS_PUBLIC
504 527
 /** default handler for start_frame() for video inputs */
... ...
@@ -608,16 +637,23 @@ struct AVFilterContext {
608 608
 
609 609
     char *name;                     ///< name of this filter instance
610 610
 
611
-    unsigned input_count;           ///< number of input pads
611
+#if FF_API_FOO_COUNT
612
+    unsigned input_count;           ///< @deprecated use nb_inputs
613
+#endif
612 614
     AVFilterPad   *input_pads;      ///< array of input pads
613 615
     AVFilterLink **inputs;          ///< array of pointers to input links
614 616
 
615
-    unsigned output_count;          ///< number of output pads
617
+#if FF_API_FOO_COUNT
618
+    unsigned output_count;          ///< @deprecated use nb_outputs
619
+#endif
616 620
     AVFilterPad   *output_pads;     ///< array of output pads
617 621
     AVFilterLink **outputs;         ///< array of pointers to output links
618 622
 
619 623
     void *priv;                     ///< private data for use by the filter
620 624
 
625
+    unsigned nb_inputs;             ///< number of input pads
626
+    unsigned nb_outputs;            ///< number of output pads
627
+
621 628
     struct AVFilterCommand *command_queue;
622 629
 };
623 630
 
... ...
@@ -777,19 +813,11 @@ void avfilter_link_free(AVFilterLink **link);
777 777
  */
778 778
 int avfilter_config_links(AVFilterContext *filter);
779 779
 
780
-/**
781
- * Request a picture buffer with a specific set of permissions.
782
- *
783
- * @param link  the output link to the filter from which the buffer will
784
- *              be requested
785
- * @param perms the required access permissions
786
- * @param w     the minimum width of the buffer to allocate
787
- * @param h     the minimum height of the buffer to allocate
788
- * @return      A reference to the buffer. This must be unreferenced with
789
- *              avfilter_unref_buffer when you are finished with it.
790
- */
780
+#if FF_API_FILTERS_PUBLIC
781
+attribute_deprecated
791 782
 AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
792 783
                                           int w, int h);
784
+#endif
793 785
 
794 786
 /**
795 787
  * Create a buffer reference wrapped around an already allocated image
... ...
@@ -118,7 +118,7 @@ static int graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx)
118 118
     for (i = 0; i < graph->filter_count; i++) {
119 119
         filt = graph->filters[i];
120 120
 
121
-        for (j = 0; j < filt->input_count; j++) {
121
+        for (j = 0; j < filt->nb_inputs; j++) {
122 122
             if (!filt->inputs[j] || !filt->inputs[j]->src) {
123 123
                 av_log(log_ctx, AV_LOG_ERROR,
124 124
                        "Input pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any source\n",
... ...
@@ -127,7 +127,7 @@ static int graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx)
127 127
             }
128 128
         }
129 129
 
130
-        for (j = 0; j < filt->output_count; j++) {
130
+        for (j = 0; j < filt->nb_outputs; j++) {
131 131
             if (!filt->outputs[j] || !filt->outputs[j]->dst) {
132 132
                 av_log(log_ctx, AV_LOG_ERROR,
133 133
                        "Output pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any destination\n",
... ...
@@ -153,7 +153,7 @@ static int graph_config_links(AVFilterGraph *graph, AVClass *log_ctx)
153 153
     for (i=0; i < graph->filter_count; i++) {
154 154
         filt = graph->filters[i];
155 155
 
156
-        if (!filt->output_count) {
156
+        if (!filt->nb_outputs) {
157 157
             if ((ret = avfilter_config_links(filt)))
158 158
                 return ret;
159 159
         }
... ...
@@ -271,7 +271,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
271 271
         /* Call query_formats on sources first.
272 272
            This is a temporary workaround for amerge,
273 273
            until format renegociation is implemented. */
274
-        if (!graph->filters[i]->input_count == j)
274
+        if (!graph->filters[i]->nb_inputs == j)
275 275
             continue;
276 276
         if (graph->filters[i]->filter->query_formats)
277 277
             ret = filter_query_formats(graph->filters[i]);
... ...
@@ -286,7 +286,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
286 286
     for (i = 0; i < graph->filter_count; i++) {
287 287
         AVFilterContext *filter = graph->filters[i];
288 288
 
289
-        for (j = 0; j < filter->input_count; j++) {
289
+        for (j = 0; j < filter->nb_inputs; j++) {
290 290
             AVFilterLink *link = filter->inputs[j];
291 291
 #if 0
292 292
             if (!link) continue;
... ...
@@ -348,11 +348,16 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
348 348
                 /* couldn't merge format lists. auto-insert conversion filter */
349 349
                 switch (link->type) {
350 350
                 case AVMEDIA_TYPE_VIDEO:
351
+                    if (!(filter = avfilter_get_by_name("scale"))) {
352
+                        av_log(log_ctx, AV_LOG_ERROR, "'scale' filter "
353
+                               "not present, cannot convert pixel formats.\n");
354
+                        return AVERROR(EINVAL);
355
+                    }
356
+
351 357
                     snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d",
352 358
                              scaler_count++);
353 359
                     snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts);
354
-                    if ((ret = avfilter_graph_create_filter(&convert,
355
-                                                            avfilter_get_by_name("scale"),
360
+                    if ((ret = avfilter_graph_create_filter(&convert, filter,
356 361
                                                             inst_name, scale_args, NULL,
357 362
                                                             graph)) < 0)
358 363
                         return ret;
... ...
@@ -366,8 +371,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
366 366
 
367 367
                     snprintf(inst_name, sizeof(inst_name), "auto-inserted resampler %d",
368 368
                              resampler_count++);
369
-                    if ((ret = avfilter_graph_create_filter(&convert,
370
-                                                            avfilter_get_by_name("aresample"),
369
+                    if ((ret = avfilter_graph_create_filter(&convert, filter,
371 370
                                                             inst_name, NULL, NULL, graph)) < 0)
372 371
                         return ret;
373 372
                     break;
... ...
@@ -464,7 +468,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
464 464
 
465 465
 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
466 466
 do {                                                                   \
467
-    for (i = 0; i < filter->input_count; i++) {                        \
467
+    for (i = 0; i < filter->nb_inputs; i++) {                          \
468 468
         AVFilterLink *link = filter->inputs[i];                        \
469 469
         fmt_type fmt;                                                  \
470 470
                                                                        \
... ...
@@ -472,7 +476,7 @@ do {                                                                   \
472 472
             continue;                                                  \
473 473
         fmt = link->out_ ## list->var[0];                              \
474 474
                                                                        \
475
-        for (j = 0; j < filter->output_count; j++) {                   \
475
+        for (j = 0; j < filter->nb_outputs; j++) {                     \
476 476
             AVFilterLink *out_link = filter->outputs[j];               \
477 477
             list_type *fmts;                                           \
478 478
                                                                        \
... ...
@@ -529,19 +533,19 @@ static void swap_samplerates_on_filter(AVFilterContext *filter)
529 529
     int sample_rate;
530 530
     int i, j;
531 531
 
532
-    for (i = 0; i < filter->input_count; i++) {
532
+    for (i = 0; i < filter->nb_inputs; i++) {
533 533
         link = filter->inputs[i];
534 534
 
535 535
         if (link->type == AVMEDIA_TYPE_AUDIO &&
536 536
             link->out_samplerates->format_count == 1)
537 537
             break;
538 538
     }
539
-    if (i == filter->input_count)
539
+    if (i == filter->nb_inputs)
540 540
         return;
541 541
 
542 542
     sample_rate = link->out_samplerates->formats[0];
543 543
 
544
-    for (i = 0; i < filter->output_count; i++) {
544
+    for (i = 0; i < filter->nb_outputs; i++) {
545 545
         AVFilterLink *outlink = filter->outputs[i];
546 546
         int best_idx, best_diff = INT_MAX;
547 547
 
... ...
@@ -576,19 +580,19 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter)
576 576
     uint64_t chlayout;
577 577
     int i, j;
578 578
 
579
-    for (i = 0; i < filter->input_count; i++) {
579
+    for (i = 0; i < filter->nb_inputs; i++) {
580 580
         link = filter->inputs[i];
581 581
 
582 582
         if (link->type == AVMEDIA_TYPE_AUDIO &&
583 583
             link->out_channel_layouts->nb_channel_layouts == 1)
584 584
             break;
585 585
     }
586
-    if (i == filter->input_count)
586
+    if (i == filter->nb_inputs)
587 587
         return;
588 588
 
589 589
     chlayout = link->out_channel_layouts->channel_layouts[0];
590 590
 
591
-    for (i = 0; i < filter->output_count; i++) {
591
+    for (i = 0; i < filter->nb_outputs; i++) {
592 592
         AVFilterLink *outlink = filter->outputs[i];
593 593
         int best_idx, best_score = INT_MIN;
594 594
 
... ...
@@ -629,20 +633,20 @@ static void swap_sample_fmts_on_filter(AVFilterContext *filter)
629 629
     int format, bps;
630 630
     int i, j;
631 631
 
632
-    for (i = 0; i < filter->input_count; i++) {
632
+    for (i = 0; i < filter->nb_inputs; i++) {
633 633
         link = filter->inputs[i];
634 634
 
635 635
         if (link->type == AVMEDIA_TYPE_AUDIO &&
636 636
             link->out_formats->format_count == 1)
637 637
             break;
638 638
     }
639
-    if (i == filter->input_count)
639
+    if (i == filter->nb_inputs)
640 640
         return;
641 641
 
642 642
     format = link->out_formats->formats[0];
643 643
     bps    = av_get_bytes_per_sample(format);
644 644
 
645
-    for (i = 0; i < filter->output_count; i++) {
645
+    for (i = 0; i < filter->nb_outputs; i++) {
646 646
         AVFilterLink *outlink = filter->outputs[i];
647 647
         int best_idx, best_score = INT_MIN;
648 648
 
... ...
@@ -700,24 +704,24 @@ static int pick_formats(AVFilterGraph *graph)
700 700
         change = 0;
701 701
         for (i = 0; i < graph->filter_count; i++) {
702 702
             AVFilterContext *filter = graph->filters[i];
703
-            if (filter->input_count){
704
-                for (j = 0; j < filter->input_count; j++){
703
+            if (filter->nb_inputs){
704
+                for (j = 0; j < filter->nb_inputs; j++){
705 705
                     if(filter->inputs[j]->in_formats && filter->inputs[j]->in_formats->format_count == 1) {
706 706
                         pick_format(filter->inputs[j], NULL);
707 707
                         change = 1;
708 708
                     }
709 709
                 }
710 710
             }
711
-            if (filter->output_count){
712
-                for (j = 0; j < filter->output_count; j++){
711
+            if (filter->nb_outputs){
712
+                for (j = 0; j < filter->nb_outputs; j++){
713 713
                     if(filter->outputs[j]->in_formats && filter->outputs[j]->in_formats->format_count == 1) {
714 714
                         pick_format(filter->outputs[j], NULL);
715 715
                         change = 1;
716 716
                     }
717 717
                 }
718 718
             }
719
-            if (filter->input_count && filter->output_count && filter->inputs[0]->format>=0) {
720
-                for (j = 0; j < filter->output_count; j++) {
719
+            if (filter->nb_inputs && filter->nb_outputs && filter->inputs[0]->format>=0) {
720
+                for (j = 0; j < filter->nb_outputs; j++) {
721 721
                     if(filter->outputs[j]->format<0) {
722 722
                         pick_format(filter->outputs[j], filter->inputs[0]);
723 723
                         change = 1;
... ...
@@ -730,10 +734,10 @@ static int pick_formats(AVFilterGraph *graph)
730 730
     for (i = 0; i < graph->filter_count; i++) {
731 731
         AVFilterContext *filter = graph->filters[i];
732 732
 
733
-        for (j = 0; j < filter->input_count; j++)
733
+        for (j = 0; j < filter->nb_inputs; j++)
734 734
             if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
735 735
                 return ret;
736
-        for (j = 0; j < filter->output_count; j++)
736
+        for (j = 0; j < filter->nb_outputs; j++)
737 737
             if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
738 738
                 return ret;
739 739
     }
... ...
@@ -778,18 +782,18 @@ static int ff_avfilter_graph_config_pointers(AVFilterGraph *graph,
778 778
 
779 779
     for (i = 0; i < graph->filter_count; i++) {
780 780
         f = graph->filters[i];
781
-        for (j = 0; j < f->input_count; j++) {
781
+        for (j = 0; j < f->nb_inputs; j++) {
782 782
             f->inputs[j]->graph     = graph;
783 783
             f->inputs[j]->age_index = -1;
784 784
         }
785
-        for (j = 0; j < f->output_count; j++) {
785
+        for (j = 0; j < f->nb_outputs; j++) {
786 786
             f->outputs[j]->graph    = graph;
787 787
             f->outputs[j]->age_index= -1;
788 788
         }
789
-        if (!f->output_count) {
790
-            if (f->input_count > INT_MAX - sink_links_count)
789
+        if (!f->nb_outputs) {
790
+            if (f->nb_inputs > INT_MAX - sink_links_count)
791 791
                 return AVERROR(EINVAL);
792
-            sink_links_count += f->input_count;
792
+            sink_links_count += f->nb_inputs;
793 793
         }
794 794
     }
795 795
     sinks = av_calloc(sink_links_count, sizeof(*sinks));
... ...
@@ -797,8 +801,8 @@ static int ff_avfilter_graph_config_pointers(AVFilterGraph *graph,
797 797
         return AVERROR(ENOMEM);
798 798
     for (i = 0; i < graph->filter_count; i++) {
799 799
         f = graph->filters[i];
800
-        if (!f->output_count) {
801
-            for (j = 0; j < f->input_count; j++) {
800
+        if (!f->nb_outputs) {
801
+            for (j = 0; j < f->nb_inputs; j++) {
802 802
                 sinks[n] = f->inputs[j];
803 803
                 f->inputs[j]->age_index = n++;
804 804
             }
... ...
@@ -84,7 +84,7 @@ static AVFilterBufferRef *copy_buffer_ref(AVFilterContext *ctx,
84 84
     switch (outlink->type) {
85 85
 
86 86
     case AVMEDIA_TYPE_VIDEO:
87
-        buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
87
+        buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
88 88
                                         ref->video->w, ref->video->h);
89 89
         if(!buf)
90 90
             return NULL;
... ...
@@ -303,6 +303,18 @@ AVFilterFormats *avfilter_make_all_packing_formats(void)
303 303
 }
304 304
 #endif
305 305
 
306
+AVFilterFormats *ff_planar_sample_fmts(void)
307
+{
308
+    AVFilterFormats *ret = NULL;
309
+    int fmt;
310
+
311
+    for (fmt = 0; fmt < AV_SAMPLE_FMT_NB; fmt++)
312
+        if (av_sample_fmt_is_planar(fmt))
313
+            ff_add_format(&ret, fmt);
314
+
315
+    return ret;
316
+}
317
+
306 318
 AVFilterFormats *ff_all_samplerates(void)
307 319
 {
308 320
     AVFilterFormats *ret = av_mallocz(sizeof(*ret));
... ...
@@ -401,13 +413,13 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
401 401
 {                                                                   \
402 402
     int count = 0, i;                                               \
403 403
                                                                     \
404
-    for (i = 0; i < ctx->input_count; i++) {                        \
404
+    for (i = 0; i < ctx->nb_inputs; i++) {                          \
405 405
         if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) {          \
406 406
             ref(fmts, &ctx->inputs[i]->out_fmts);                   \
407 407
             count++;                                                \
408 408
         }                                                           \
409 409
     }                                                               \
410
-    for (i = 0; i < ctx->output_count; i++) {                       \
410
+    for (i = 0; i < ctx->nb_outputs; i++) {                         \
411 411
         if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) {         \
412 412
             ref(fmts, &ctx->outputs[i]->in_fmts);                   \
413 413
             count++;                                                \
... ...
@@ -163,6 +163,11 @@ int ff_add_format(AVFilterFormats **avff, int64_t fmt);
163 163
 AVFilterFormats *ff_all_formats(enum AVMediaType type);
164 164
 
165 165
 /**
166
+ * Construct a formats list containing all planar sample formats.
167
+ */
168
+AVFilterFormats *ff_planar_sample_fmts(void);
169
+
170
+/**
166 171
  * Return a format list which contains the intersection of the formats of
167 172
  * a and b. Also, all the references of a, all the references of b, and
168 173
  * a and b themselves will be deallocated.
... ...
@@ -226,7 +226,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx,
226 226
 {
227 227
     int pad, ret;
228 228
 
229
-    for (pad = 0; pad < filt_ctx->input_count; pad++) {
229
+    for (pad = 0; pad < filt_ctx->nb_inputs; pad++) {
230 230
         AVFilterInOut *p = *curr_inputs;
231 231
 
232 232
         if (p) {
... ...
@@ -254,7 +254,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx,
254 254
         return AVERROR(EINVAL);
255 255
     }
256 256
 
257
-    pad = filt_ctx->output_count;
257
+    pad = filt_ctx->nb_outputs;
258 258
     while (pad--) {
259 259
         AVFilterInOut *currlinkn = av_mallocz(sizeof(AVFilterInOut));
260 260
         if (!currlinkn)
... ...
@@ -50,6 +50,132 @@ typedef struct AVFilterCommand {
50 50
  */
51 51
 void ff_avfilter_graph_update_heap(AVFilterGraph *graph, AVFilterLink *link);
52 52
 
53
+#if !FF_API_AVFILTERPAD_PUBLIC
54
+/**
55
+ * A filter pad used for either input or output.
56
+ */
57
+struct AVFilterPad {
58
+    /**
59
+     * Pad name. The name is unique among inputs and among outputs, but an
60
+     * input may have the same name as an output. This may be NULL if this
61
+     * pad has no need to ever be referenced by name.
62
+     */
63
+    const char *name;
64
+
65
+    /**
66
+     * AVFilterPad type.
67
+     */
68
+    enum AVMediaType type;
69
+
70
+    /**
71
+     * Minimum required permissions on incoming buffers. Any buffer with
72
+     * insufficient permissions will be automatically copied by the filter
73
+     * system to a new buffer which provides the needed access permissions.
74
+     *
75
+     * Input pads only.
76
+     */
77
+    int min_perms;
78
+
79
+    /**
80
+     * Permissions which are not accepted on incoming buffers. Any buffer
81
+     * which has any of these permissions set will be automatically copied
82
+     * by the filter system to a new buffer which does not have those
83
+     * permissions. This can be used to easily disallow buffers with
84
+     * AV_PERM_REUSE.
85
+     *
86
+     * Input pads only.
87
+     */
88
+    int rej_perms;
89
+
90
+    /**
91
+     * Callback called before passing the first slice of a new frame. If
92
+     * NULL, the filter layer will default to storing a reference to the
93
+     * picture inside the link structure.
94
+     *
95
+     * Input video pads only.
96
+     */
97
+    void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
98
+
99
+    /**
100
+     * Callback function to get a video buffer. If NULL, the filter system will
101
+     * use avfilter_default_get_video_buffer().
102
+     *
103
+     * Input video pads only.
104
+     */
105
+    AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
106
+
107
+    /**
108
+     * Callback function to get an audio buffer. If NULL, the filter system will
109
+     * use avfilter_default_get_audio_buffer().
110
+     *
111
+     * Input audio pads only.
112
+     */
113
+    AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
114
+                                           int nb_samples);
115
+
116
+    /**
117
+     * Callback called after the slices of a frame are completely sent. If
118
+     * NULL, the filter layer will default to releasing the reference stored
119
+     * in the link structure during start_frame().
120
+     *
121
+     * Input video pads only.
122
+     */
123
+    void (*end_frame)(AVFilterLink *link);
124
+
125
+    /**
126
+     * Slice drawing callback. This is where a filter receives video data
127
+     * and should do its processing.
128
+     *
129
+     * Input video pads only.
130
+     */
131
+    void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
132
+
133
+    /**
134
+     * Samples filtering callback. This is where a filter receives audio data
135
+     * and should do its processing.
136
+     *
137
+     * Input audio pads only.
138
+     */
139
+    void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
140
+
141
+    /**
142
+     * Frame poll callback. This returns the number of immediately available
143
+     * samples. It should return a positive value if the next request_frame()
144
+     * is guaranteed to return one frame (with no delay).
145
+     *
146
+     * Defaults to just calling the source poll_frame() method.
147
+     *
148
+     * Output pads only.
149
+     */
150
+    int (*poll_frame)(AVFilterLink *link);
151
+
152
+    /**
153
+     * Frame request callback. A call to this should result in at least one
154
+     * frame being output over the given link. This should return zero on
155
+     * success, and another value on error.
156
+     *
157
+     * Output pads only.
158
+     */
159
+    int (*request_frame)(AVFilterLink *link);
160
+
161
+    /**
162
+     * Link configuration callback.
163
+     *
164
+     * For output pads, this should set the link properties such as
165
+     * width/height. This should NOT set the format property - that is
166
+     * negotiated between filters by the filter system using the
167
+     * query_formats() callback before this function is called.
168
+     *
169
+     * For input pads, this should check the properties of the link, and update
170
+     * the filter's internal state as necessary.
171
+     *
172
+     * For both input and output filters, this should return zero on success,
173
+     * and another value on error.
174
+     */
175
+    int (*config_props)(AVFilterLink *link);
176
+};
177
+#endif
178
+
53 179
 /** default handler for freeing audio/video buffer when there are no references left */
54 180
 void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
55 181
 
... ...
@@ -165,16 +291,22 @@ void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
165 165
 static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
166 166
                                    AVFilterPad *p)
167 167
 {
168
-    ff_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad),
168
+    ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
169 169
                   &f->input_pads, &f->inputs, p);
170
+#if FF_API_FOO_COUNT
171
+    f->input_count = f->nb_inputs;
172
+#endif
170 173
 }
171 174
 
172 175
 /** Insert a new output pad for the filter. */
173 176
 static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
174 177
                                     AVFilterPad *p)
175 178
 {
176
-    ff_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad),
179
+    ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
177 180
                   &f->output_pads, &f->outputs, p);
181
+#if FF_API_FOO_COUNT
182
+    f->output_count = f->nb_outputs;
183
+#endif
178 184
 }
179 185
 
180 186
 /**
... ...
@@ -59,7 +59,7 @@ static void split_uninit(AVFilterContext *ctx)
59 59
 {
60 60
     int i;
61 61
 
62
-    for (i = 0; i < ctx->output_count; i++)
62
+    for (i = 0; i < ctx->nb_outputs; i++)
63 63
         av_freep(&ctx->output_pads[i].name);
64 64
 }
65 65
 
... ...
@@ -68,7 +68,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
68 68
     AVFilterContext *ctx = inlink->dst;
69 69
     int i;
70 70
 
71
-    for (i = 0; i < ctx->output_count; i++)
71
+    for (i = 0; i < ctx->nb_outputs; i++)
72 72
         ff_start_frame(ctx->outputs[i],
73 73
                        avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
74 74
 }
... ...
@@ -78,7 +78,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
78 78
     AVFilterContext *ctx = inlink->dst;
79 79
     int i;
80 80
 
81
-    for (i = 0; i < ctx->output_count; i++)
81
+    for (i = 0; i < ctx->nb_outputs; i++)
82 82
         ff_draw_slice(ctx->outputs[i], y, h, slice_dir);
83 83
 }
84 84
 
... ...
@@ -87,7 +87,7 @@ static void end_frame(AVFilterLink *inlink)
87 87
     AVFilterContext *ctx = inlink->dst;
88 88
     int i;
89 89
 
90
-    for (i = 0; i < ctx->output_count; i++)
90
+    for (i = 0; i < ctx->nb_outputs; i++)
91 91
         ff_end_frame(ctx->outputs[i]);
92 92
 
93 93
     avfilter_unref_buffer(inlink->cur_buf);
... ...
@@ -115,7 +115,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
115 115
     AVFilterContext *ctx = inlink->dst;
116 116
     int i;
117 117
 
118
-    for (i = 0; i < ctx->output_count; i++)
118
+    for (i = 0; i < ctx->nb_outputs; i++)
119 119
         ff_filter_samples(inlink->dst->outputs[i],
120 120
                           avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
121 121
 }
... ...
@@ -39,6 +39,7 @@
39 39
 #include "avcodec.h"
40 40
 #include "avfilter.h"
41 41
 #include "formats.h"
42
+#include "internal.h"
42 43
 #include "video.h"
43 44
 
44 45
 typedef struct {
... ...
@@ -272,8 +273,8 @@ static int movie_get_frame(AVFilterLink *outlink)
272 272
 
273 273
             if (frame_decoded) {
274 274
                 /* FIXME: avoid the memcpy */
275
-                movie->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE |
276
-                                                          AV_PERM_REUSE2, outlink->w, outlink->h);
275
+                movie->picref = ff_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE |
276
+                                                    AV_PERM_REUSE2, outlink->w, outlink->h);
277 277
                 av_image_copy(movie->picref->data, movie->picref->linesize,
278 278
                               (void*)movie->frame->data,  movie->frame->linesize,
279 279
                               movie->picref->format, outlink->w, outlink->h);
... ...
@@ -29,8 +29,8 @@
29 29
 #include "libavutil/avutil.h"
30 30
 
31 31
 #define LIBAVFILTER_VERSION_MAJOR  2
32
-#define LIBAVFILTER_VERSION_MINOR 78
33
-#define LIBAVFILTER_VERSION_MICRO 101
32
+#define LIBAVFILTER_VERSION_MINOR 79
33
+#define LIBAVFILTER_VERSION_MICRO 100
34 34
 
35 35
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 36
                                                LIBAVFILTER_VERSION_MINOR, \
... ...
@@ -62,5 +62,11 @@
62 62
 #ifndef FF_API_FILTERS_PUBLIC
63 63
 #define FF_API_FILTERS_PUBLIC               (LIBAVFILTER_VERSION_MAJOR < 3)
64 64
 #endif
65
+#ifndef FF_API_AVFILTERPAD_PUBLIC
66
+#define FF_API_AVFILTERPAD_PUBLIC           (LIBAVFILTER_VERSION_MAJOR < 4)
67
+#endif
68
+#ifndef FF_API_FOO_COUNT
69
+#define FF_API_FOO_COUNT                    (LIBAVFILTER_VERSION_MAJOR < 4)
70
+#endif
65 71
 
66 72
 #endif // AVFILTER_VERSION_H
... ...
@@ -26,6 +26,7 @@
26 26
 #include "libavutil/mathematics.h"
27 27
 #include "libavutil/parseutils.h"
28 28
 #include "avfilter.h"
29
+#include "internal.h"
29 30
 #include "video.h"
30 31
 
31 32
 typedef struct {
... ...
@@ -30,6 +30,7 @@
30 30
 #include "avfilter.h"
31 31
 #include "internal.h"
32 32
 #include "formats.h"
33
+#include "internal.h"
33 34
 #include "video.h"
34 35
 
35 36
 typedef struct {
... ...
@@ -30,6 +30,7 @@
30 30
 #include "libavutil/pixdesc.h"
31 31
 #include "avfilter.h"
32 32
 #include "formats.h"
33
+#include "internal.h"
33 34
 #include "video.h"
34 35
 
35 36
 static const char *const var_names[] = {
... ...
@@ -22,6 +22,7 @@
22 22
  */
23 23
 
24 24
 #include "avfilter.h"
25
+#include "internal.h"
25 26
 #include "video.h"
26 27
 
27 28
 AVFilter avfilter_vf_copy = {
... ...
@@ -27,6 +27,7 @@
27 27
 
28 28
 #include "avfilter.h"
29 29
 #include "formats.h"
30
+#include "internal.h"
30 31
 #include "video.h"
31 32
 #include "libavutil/eval.h"
32 33
 #include "libavutil/avstring.h"
... ...
@@ -26,6 +26,7 @@
26 26
 #include "libavutil/imgutils.h"
27 27
 #include "avfilter.h"
28 28
 #include "formats.h"
29
+#include "internal.h"
29 30
 #include "video.h"
30 31
 
31 32
 typedef struct {
... ...
@@ -30,6 +30,7 @@
30 30
 #include "libavutil/pixdesc.h"
31 31
 #include "avfilter.h"
32 32
 #include "formats.h"
33
+#include "internal.h"
33 34
 #include "video.h"
34 35
 
35 36
 /**
... ...
@@ -218,8 +219,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
218 218
     AVFilterBufferRef *outpicref;
219 219
 
220 220
     if (inpicref->perms & AV_PERM_PRESERVE) {
221
-        outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
222
-                                              outlink->w, outlink->h);
221
+        outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE,
222
+                                        outlink->w, outlink->h);
223 223
         avfilter_copy_buffer_ref_props(outpicref, inpicref);
224 224
         outpicref->video->w = outlink->w;
225 225
         outpicref->video->h = outlink->h;
... ...
@@ -29,6 +29,7 @@
29 29
 #include "libavutil/parseutils.h"
30 30
 #include "avfilter.h"
31 31
 #include "formats.h"
32
+#include "internal.h"
32 33
 #include "video.h"
33 34
 
34 35
 enum { Y, U, V, A };
... ...
@@ -42,6 +42,7 @@
42 42
 #include "avfilter.h"
43 43
 #include "drawutils.h"
44 44
 #include "formats.h"
45
+#include "internal.h"
45 46
 #include "video.h"
46 47
 
47 48
 #undef time
... ...
@@ -33,6 +33,7 @@
33 33
 #include "drawutils.h"
34 34
 #include "internal.h"
35 35
 #include "formats.h"
36
+#include "internal.h"
36 37
 #include "video.h"
37 38
 
38 39
 #define R 0
... ...
@@ -29,6 +29,7 @@
29 29
 #include "libavutil/pixdesc.h"
30 30
 #include "avfilter.h"
31 31
 #include "formats.h"
32
+#include "internal.h"
32 33
 #include "video.h"
33 34
 
34 35
 typedef struct
... ...
@@ -112,7 +113,7 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int
112 112
     AVFilterContext   *ctx        = inlink->dst;
113 113
     AVFilterLink      *outlink    = ctx->outputs[0];
114 114
 
115
-    return avfilter_get_video_buffer(outlink, perms, w, h);
115
+    return ff_get_video_buffer(outlink, perms, w, h);
116 116
 }
117 117
 
118 118
 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
... ...
@@ -27,6 +27,7 @@
27 27
 #include "avfilter.h"
28 28
 #include "internal.h"
29 29
 #include "formats.h"
30
+#include "internal.h"
30 31
 #include "video.h"
31 32
 
32 33
 typedef struct {
... ...
@@ -32,6 +32,7 @@
32 32
 #include "libavutil/parseutils.h"
33 33
 #include "avfilter.h"
34 34
 #include "formats.h"
35
+#include "internal.h"
35 36
 #include "video.h"
36 37
 
37 38
 typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height);
... ...
@@ -433,7 +434,7 @@ static int source_config_props(AVFilterLink *outlink)
433 433
 static int source_request_frame(AVFilterLink *outlink)
434 434
 {
435 435
     Frei0rContext *frei0r = outlink->src->priv;
436
-    AVFilterBufferRef *picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
436
+    AVFilterBufferRef *picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
437 437
     picref->video->sample_aspect_ratio = (AVRational) {1, 1};
438 438
     picref->pts = frei0r->pts++;
439 439
     picref->pos = -1;
... ...
@@ -38,6 +38,7 @@
38 38
 #include "avfilter.h"
39 39
 #include "formats.h"
40 40
 #include "gradfun.h"
41
+#include "internal.h"
41 42
 #include "video.h"
42 43
 
43 44
 DECLARE_ALIGNED(16, static const uint16_t, dither)[8][8] = {
... ...
@@ -190,7 +191,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
190 190
     AVFilterBufferRef *outpicref;
191 191
 
192 192
     if (inpicref->perms & AV_PERM_PRESERVE) {
193
-        outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
193
+        outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
194 194
         avfilter_copy_buffer_ref_props(outpicref, inpicref);
195 195
         outpicref->video->w = outlink->w;
196 196
         outpicref->video->h = outlink->h;
... ...
@@ -26,6 +26,7 @@
26 26
 
27 27
 #include "avfilter.h"
28 28
 #include "formats.h"
29
+#include "internal.h"
29 30
 #include "video.h"
30 31
 #include "libavutil/pixdesc.h"
31 32
 #include "libavutil/intreadwrite.h"
... ...
@@ -28,6 +28,7 @@
28 28
 #include "libavutil/pixdesc.h"
29 29
 #include "avfilter.h"
30 30
 #include "formats.h"
31
+#include "internal.h"
31 32
 #include "video.h"
32 33
 
33 34
 typedef struct {
... ...
@@ -22,6 +22,7 @@
22 22
  */
23 23
 
24 24
 #include "avfilter.h"
25
+#include "internal.h"
25 26
 #include "video.h"
26 27
 
27 28
 AVFilter avfilter_vf_null = {
... ...
@@ -303,7 +303,7 @@ static int config_output(AVFilterLink *outlink)
303 303
 
304 304
 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, int w, int h)
305 305
 {
306
-    return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
306
+    return ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
307 307
 }
308 308
 
309 309
 // divide by 255 and round to nearest
... ...
@@ -26,6 +26,7 @@
26 26
 
27 27
 #include "avfilter.h"
28 28
 #include "formats.h"
29
+#include "internal.h"
29 30
 #include "video.h"
30 31
 #include "libavutil/avstring.h"
31 32
 #include "libavutil/eval.h"
... ...
@@ -220,9 +221,9 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int
220 220
     PadContext *pad = inlink->dst->priv;
221 221
     int align = (perms&AV_PERM_ALIGN) ? AVFILTER_ALIGN : 1;
222 222
 
223
-    AVFilterBufferRef *picref = avfilter_get_video_buffer(inlink->dst->outputs[0], perms,
224
-                                                       w + (pad->w - pad->in_w) + 4*align,
225
-                                                       h + (pad->h - pad->in_h));
223
+    AVFilterBufferRef *picref = ff_get_video_buffer(inlink->dst->outputs[0], perms,
224
+                                                    w + (pad->w - pad->in_w) + 4*align,
225
+                                                    h + (pad->h - pad->in_h));
226 226
     int plane;
227 227
 
228 228
     picref->video->w = w;
... ...
@@ -287,9 +288,9 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
287 287
     if(pad->needs_copy){
288 288
         av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
289 289
         avfilter_unref_buffer(outpicref);
290
-        outpicref = avfilter_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES,
291
-                                                       FFMAX(inlink->w, pad->w),
292
-                                                       FFMAX(inlink->h, pad->h));
290
+        outpicref = ff_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES,
291
+                                        FFMAX(inlink->w, pad->w),
292
+                                        FFMAX(inlink->h, pad->h));
293 293
         avfilter_copy_buffer_ref_props(outpicref, inpicref);
294 294
     }
295 295
 
... ...
@@ -25,6 +25,7 @@
25 25
 
26 26
 #include "libavutil/pixdesc.h"
27 27
 #include "avfilter.h"
28
+#include "internal.h"
28 29
 #include "video.h"
29 30
 
30 31
 typedef struct {
... ...
@@ -57,8 +58,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
57 57
     AVFilterBufferRef *outpicref;
58 58
     int i;
59 59
 
60
-    outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
61
-                                                outlink->w, outlink->h);
60
+    outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
61
+                                           outlink->w, outlink->h);
62 62
     outpicref = outlink->out_buf;
63 63
     avfilter_copy_buffer_ref_props(outpicref, picref);
64 64
 
... ...
@@ -25,6 +25,7 @@
25 25
 
26 26
 #include "avfilter.h"
27 27
 #include "formats.h"
28
+#include "internal.h"
28 29
 #include "video.h"
29 30
 #include "libavutil/avstring.h"
30 31
 #include "libavutil/eval.h"
... ...
@@ -302,7 +303,7 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
302 302
     scale->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
303 303
     scale->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
304 304
 
305
-    outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_ALIGN, outlink->w, outlink->h);
305
+    outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_ALIGN, outlink->w, outlink->h);
306 306
     avfilter_copy_buffer_ref_props(outpicref, picref);
307 307
     outpicref->video->w = outlink->w;
308 308
     outpicref->video->h = outlink->h;
... ...
@@ -29,6 +29,7 @@
29 29
 #include "libavutil/eval.h"
30 30
 #include "libavutil/mathematics.h"
31 31
 #include "avfilter.h"
32
+#include "internal.h"
32 33
 #include "video.h"
33 34
 
34 35
 static const char *const var_names[] = {
... ...
@@ -24,6 +24,7 @@
24 24
  */
25 25
 
26 26
 #include "avfilter.h"
27
+#include "internal.h"
27 28
 #include "video.h"
28 29
 #include "libavutil/pixdesc.h"
29 30
 
... ...
@@ -30,6 +30,7 @@
30 30
 #include "libavutil/imgutils.h"
31 31
 #include "avfilter.h"
32 32
 #include "formats.h"
33
+#include "internal.h"
33 34
 #include "video.h"
34 35
 
35 36
 typedef struct {
... ...
@@ -117,8 +118,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
117 117
 {
118 118
     AVFilterLink *outlink = inlink->dst->outputs[0];
119 119
 
120
-    outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
121
-                                                 outlink->w, outlink->h);
120
+    outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
121
+                                           outlink->w, outlink->h);
122 122
     outlink->out_buf->pts = picref->pts;
123 123
 
124 124
     if (picref->video->sample_aspect_ratio.num == 0) {
... ...
@@ -38,6 +38,7 @@
38 38
 
39 39
 #include "avfilter.h"
40 40
 #include "formats.h"
41
+#include "internal.h"
41 42
 #include "video.h"
42 43
 #include "libavutil/common.h"
43 44
 #include "libavutil/mem.h"
... ...
@@ -25,6 +25,7 @@
25 25
 
26 26
 #include "libavutil/pixdesc.h"
27 27
 #include "avfilter.h"
28
+#include "internal.h"
28 29
 #include "video.h"
29 30
 
30 31
 typedef struct {
... ...
@@ -50,7 +51,7 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
50 50
     if (!(perms & AV_PERM_NEG_LINESIZES))
51 51
         return ff_default_get_video_buffer(link, perms, w, h);
52 52
 
53
-    picref = avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
53
+    picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
54 54
     for (i = 0; i < 4; i ++) {
55 55
         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
56 56
 
... ...
@@ -207,8 +207,8 @@ static void return_frame(AVFilterContext *ctx, int is_second)
207 207
     }
208 208
 
209 209
     if (is_second) {
210
-        yadif->out = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
211
-                                               AV_PERM_REUSE, link->w, link->h);
210
+        yadif->out = ff_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
211
+                                         AV_PERM_REUSE, link->w, link->h);
212 212
         avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
213 213
         yadif->out->video->interlaced = 0;
214 214
     }
... ...
@@ -269,8 +269,8 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
269 269
     if (!yadif->prev)
270 270
         yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
271 271
 
272
-    yadif->out = avfilter_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE |
273
-                                       AV_PERM_REUSE, link->w, link->h);
272
+    yadif->out = ff_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE |
273
+                                     AV_PERM_REUSE, link->w, link->h);
274 274
 
275 275
     avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
276 276
     yadif->out->video->interlaced = 0;
... ...
@@ -28,7 +28,7 @@
28 28
 
29 29
 AVFilterBufferRef *ff_null_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
30 30
 {
31
-    return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
31
+    return ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
32 32
 }
33 33
 
34 34
 AVFilterBufferRef *ff_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
... ...
@@ -127,7 +127,7 @@ fail:
127 127
     return NULL;
128 128
 }
129 129
 
130
-AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
130
+AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
131 131
 {
132 132
     AVFilterBufferRef *ret = NULL;
133 133
 
... ...
@@ -158,11 +158,11 @@ static void default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
158 158
 {
159 159
     AVFilterLink *outlink = NULL;
160 160
 
161
-    if (inlink->dst->output_count)
161
+    if (inlink->dst->nb_outputs)
162 162
         outlink = inlink->dst->outputs[0];
163 163
 
164 164
     if (outlink) {
165
-        outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
165
+        outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
166 166
         avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
167 167
         ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
168 168
     }
... ...
@@ -191,7 +191,7 @@ void ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
191 191
                 picref->perms,
192 192
                 link->dstpad->min_perms, link->dstpad->rej_perms);
193 193
 
194
-        link->cur_buf = avfilter_get_video_buffer(link, dst->min_perms, link->w, link->h);
194
+        link->cur_buf = ff_get_video_buffer(link, dst->min_perms, link->w, link->h);
195 195
         link->src_buf = picref;
196 196
         avfilter_copy_buffer_ref_props(link->cur_buf, link->src_buf);
197 197
 
... ...
@@ -230,7 +230,7 @@ static void default_end_frame(AVFilterLink *inlink)
230 230
 {
231 231
     AVFilterLink *outlink = NULL;
232 232
 
233
-    if (inlink->dst->output_count)
233
+    if (inlink->dst->nb_outputs)
234 234
         outlink = inlink->dst->outputs[0];
235 235
 
236 236
     avfilter_unref_buffer(inlink->cur_buf);
... ...
@@ -271,7 +271,7 @@ static void default_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir
271 271
 {
272 272
     AVFilterLink *outlink = NULL;
273 273
 
274
-    if (inlink->dst->output_count)
274
+    if (inlink->dst->nb_outputs)
275 275
         outlink = inlink->dst->outputs[0];
276 276
 
277 277
     if (outlink)
... ...
@@ -364,4 +364,8 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
364 364
 {
365 365
     ff_draw_slice(link, y, h, slice_dir);
366 366
 }
367
+AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
368
+{
369
+    return ff_get_video_buffer(link, perms, w, h);
370
+}
367 371
 #endif
... ...
@@ -28,6 +28,19 @@ AVFilterBufferRef *ff_default_get_video_buffer(AVFilterLink *link,
28 28
                                                int perms, int w, int h);
29 29
 AVFilterBufferRef *ff_null_get_video_buffer(AVFilterLink *link, int perms, int w, int h);
30 30
 
31
+/**
32
+ * Request a picture buffer with a specific set of permissions.
33
+ *
34
+ * @param link  the output link to the filter from which the buffer will
35
+ *              be requested
36
+ * @param perms the required access permissions
37
+ * @param w     the minimum width of the buffer to allocate
38
+ * @param h     the minimum height of the buffer to allocate
39
+ * @return      A reference to the buffer. This must be unreferenced with
40
+ *              avfilter_unref_buffer when you are finished with it.
41
+ */
42
+AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms,
43
+                                       int w, int h);
31 44
 
32 45
 void ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
33 46
 void ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
... ...
@@ -17,6 +17,7 @@
17 17
  */
18 18
 
19 19
 #include "avfilter.h"
20
+#include "internal.h"
20 21
 
21 22
 static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
22 23
 {
... ...
@@ -25,6 +25,7 @@
25 25
 
26 26
 #include "avfilter.h"
27 27
 #include "formats.h"
28
+#include "internal.h"
28 29
 #include "video.h"
29 30
 #include "libavutil/pixdesc.h"
30 31
 #include "libavutil/colorspace.h"
... ...
@@ -105,7 +106,7 @@ static int color_config_props(AVFilterLink *inlink)
105 105
 static int color_request_frame(AVFilterLink *link)
106 106
 {
107 107
     ColorContext *color = link->src->priv;
108
-    AVFilterBufferRef *picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
108
+    AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
109 109
     picref->video->sample_aspect_ratio = (AVRational) {1, 1};
110 110
     picref->pts = color->pts++;
111 111
     picref->pos = -1;
... ...
@@ -37,6 +37,7 @@
37 37
 #include "libavutil/parseutils.h"
38 38
 #include "avfilter.h"
39 39
 #include "formats.h"
40
+#include "internal.h"
40 41
 #include "video.h"
41 42
 
42 43
 typedef struct {
... ...
@@ -137,8 +138,7 @@ static int request_frame(AVFilterLink *outlink)
137 137
 
138 138
     if (test->max_pts >= 0 && test->pts >= test->max_pts)
139 139
         return AVERROR_EOF;
140
-    picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
141
-                                       test->w, test->h);
140
+    picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
142 141
     picref->pts = test->pts++;
143 142
     picref->pos = -1;
144 143
     picref->video->key_frame = 1;
... ...
@@ -88,6 +88,8 @@ typedef struct RTMPContext {
88 88
     char*         tcurl;                      ///< url of the target stream
89 89
     char*         flashver;                   ///< version of the flash plugin
90 90
     char*         swfurl;                     ///< url of the swf player
91
+    int           server_bw;                  ///< server bandwidth
92
+    int           client_buffer_time;         ///< client buffer time in ms
91 93
 } RTMPContext;
92 94
 
93 95
 #define PLAYER_KEY_OPEN_PART_LEN 30   ///< length of partial key used for first client digest signing
... ...
@@ -115,7 +117,7 @@ static const uint8_t rtmp_server_key[] = {
115 115
 
116 116
 static int rtmp_write_amf_data(URLContext *s, char *param, uint8_t **p)
117 117
 {
118
-    char *field, *value, *saveptr;
118
+    char *field, *value;
119 119
     char type;
120 120
 
121 121
     /* The type must be B for Boolean, N for number, S for string, O for
... ...
@@ -130,8 +132,12 @@ static int rtmp_write_amf_data(URLContext *s, char *param, uint8_t **p)
130 130
         value = param + 2;
131 131
     } else if (param[0] == 'N' && param[1] && param[2] == ':') {
132 132
         type = param[1];
133
-        field = av_strtok(param + 3, ":", &saveptr);
134
-        value = av_strtok(NULL, ":", &saveptr);
133
+        field = param + 3;
134
+        value = strchr(field, ':');
135
+        if (!value)
136
+            goto fail;
137
+        *value = '\0';
138
+        value++;
135 139
 
136 140
         if (!field || !value)
137 141
             goto fail;
... ...
@@ -226,18 +232,27 @@ static int gen_connect(URLContext *s, RTMPContext *rt)
226 226
     ff_amf_write_object_end(&p);
227 227
 
228 228
     if (rt->conn) {
229
-        char *param, *saveptr;
229
+        char *param = rt->conn;
230 230
 
231 231
         // Write arbitrary AMF data to the Connect message.
232
-        param = av_strtok(rt->conn, " ", &saveptr);
233 232
         while (param != NULL) {
233
+            char *sep;
234
+            param += strspn(param, " ");
235
+            if (!*param)
236
+                break;
237
+            sep = strchr(param, ' ');
238
+            if (sep)
239
+                *sep = '\0';
234 240
             if ((ret = rtmp_write_amf_data(s, param, &p)) < 0) {
235 241
                 // Invalid AMF parameter.
236 242
                 ff_rtmp_packet_destroy(&pkt);
237 243
                 return ret;
238 244
             }
239 245
 
240
-            param = av_strtok(NULL, " ", &saveptr);
246
+            if (sep)
247
+                param = sep + 1;
248
+            else
249
+                break;
241 250
         }
242 251
     }
243 252
 
... ...
@@ -394,6 +409,31 @@ static int gen_delete_stream(URLContext *s, RTMPContext *rt)
394 394
 }
395 395
 
396 396
 /**
397
+ * Generate client buffer time and send it to the server.
398
+ */
399
+static int gen_buffer_time(URLContext *s, RTMPContext *rt)
400
+{
401
+    RTMPPacket pkt;
402
+    uint8_t *p;
403
+    int ret;
404
+
405
+    if ((ret = ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING,
406
+                                     1, 10)) < 0)
407
+        return ret;
408
+
409
+    p = pkt.data;
410
+    bytestream_put_be16(&p, 3);
411
+    bytestream_put_be32(&p, rt->main_channel_id);
412
+    bytestream_put_be32(&p, rt->client_buffer_time);
413
+
414
+    ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size,
415
+                               rt->prev_pkt[1]);
416
+    ff_rtmp_packet_destroy(&pkt);
417
+
418
+    return ret;
419
+}
420
+
421
+/**
397 422
  * Generate 'play' call and send it to the server, then ping the server
398 423
  * to start actual playing.
399 424
  */
... ...
@@ -422,23 +462,6 @@ static int gen_play(URLContext *s, RTMPContext *rt)
422 422
                                rt->prev_pkt[1]);
423 423
     ff_rtmp_packet_destroy(&pkt);
424 424
 
425
-    if (ret < 0)
426
-        return ret;
427
-
428
-    // set client buffer time disguised in ping packet
429
-    if ((ret = ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING,
430
-                                     1, 10)) < 0)
431
-        return ret;
432
-
433
-    p = pkt.data;
434
-    bytestream_put_be16(&p, 3);
435
-    bytestream_put_be32(&p, 1);
436
-    bytestream_put_be32(&p, 256); //TODO: what is a good value here?
437
-
438
-    ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size,
439
-                               rt->prev_pkt[1]);
440
-    ff_rtmp_packet_destroy(&pkt);
441
-
442 425
     return ret;
443 426
 }
444 427
 
... ...
@@ -510,7 +533,7 @@ static int gen_server_bw(URLContext *s, RTMPContext *rt)
510 510
         return ret;
511 511
 
512 512
     p = pkt.data;
513
-    bytestream_put_be32(&p, 2500000);
513
+    bytestream_put_be32(&p, rt->server_bw);
514 514
     ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size,
515 515
                                rt->prev_pkt[1]);
516 516
     ff_rtmp_packet_destroy(&pkt);
... ...
@@ -838,6 +861,14 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
838 838
         av_log(s, AV_LOG_DEBUG, "Client bandwidth = %d\n", AV_RB32(pkt->data));
839 839
         rt->client_report_size = AV_RB32(pkt->data) >> 1;
840 840
         break;
841
+    case RTMP_PT_SERVER_BW:
842
+        rt->server_bw = AV_RB32(pkt->data);
843
+        if (rt->server_bw <= 0) {
844
+            av_log(s, AV_LOG_ERROR, "Incorrect server bandwidth %d\n", rt->server_bw);
845
+            return AVERROR(EINVAL);
846
+        }
847
+        av_log(s, AV_LOG_DEBUG, "Server bandwidth = %d\n", rt->server_bw);
848
+        break;
841 849
     case RTMP_PT_INVOKE:
842 850
         //TODO: check for the messages sent for wrong state?
843 851
         if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
... ...
@@ -888,6 +919,8 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
888 888
                 if (rt->is_input) {
889 889
                     if ((ret = gen_play(s, rt)) < 0)
890 890
                         return ret;
891
+                    if ((ret = gen_buffer_time(s, rt)) < 0)
892
+                        return ret;
891 893
                 } else {
892 894
                     if ((ret = gen_publish(s, rt)) < 0)
893 895
                         return ret;
... ...
@@ -924,6 +957,9 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
924 924
                 return ret;
925 925
         }
926 926
         break;
927
+    default:
928
+        av_log(s, AV_LOG_VERBOSE, "Unknown packet type received 0x%02X\n", pkt->type);
929
+        break;
927 930
     }
928 931
     return 0;
929 932
 }
... ...
@@ -1182,6 +1218,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
1182 1182
     rt->client_report_size = 1048576;
1183 1183
     rt->bytes_read = 0;
1184 1184
     rt->last_bytes_read = 0;
1185
+    rt->server_bw = 2500000;
1185 1186
 
1186 1187
     av_log(s, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n",
1187 1188
            proto, path, rt->app, rt->playpath);
... ...
@@ -1328,6 +1365,7 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
1328 1328
 
1329 1329
 static const AVOption rtmp_options[] = {
1330 1330
     {"rtmp_app", "Name of application to connect to on the RTMP server", OFFSET(app), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
1331
+    {"rtmp_buffer", "Set buffer time in milliseconds. The default is 3000.", OFFSET(client_buffer_time), AV_OPT_TYPE_INT, {3000}, 0, INT_MAX, DEC|ENC},
1331 1332
     {"rtmp_conn", "Append arbitrary AMF data to the Connect message", OFFSET(conn), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
1332 1333
     {"rtmp_flashver", "Version of the Flash plugin used to run the SWF player.", OFFSET(flashver), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
1333 1334
     {"rtmp_live", "Specify that the media is a live stream.", OFFSET(live), AV_OPT_TYPE_INT, {-2}, INT_MIN, INT_MAX, DEC, "rtmp_live"},
... ...
@@ -677,80 +677,120 @@ static void planar_rgb_to_y(uint16_t *dst, const uint8_t *src[4], int width)
677 677
     }
678 678
 }
679 679
 
680
-static void planar_rgb16le_to_y(uint8_t *_dst, const uint8_t *_src[4], int width)
680
+static void planar_rgb_to_uv(uint16_t *dstU, uint16_t *dstV, const uint8_t *src[4], int width)
681 681
 {
682 682
     int i;
683
-    const uint16_t **src = (const uint16_t **)_src;
684
-    uint16_t *dst        = (uint16_t *)_dst;
685 683
     for (i = 0; i < width; i++) {
686
-        int g = AV_RL16(src[0] + i);
687
-        int b = AV_RL16(src[1] + i);
688
-        int r = AV_RL16(src[2] + i);
684
+        int g = src[0][i];
685
+        int b = src[1][i];
686
+        int r = src[2][i];
689 687
 
690
-        dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
688
+        dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
689
+        dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
691 690
     }
692 691
 }
693 692
 
694
-static void planar_rgb16be_to_y(uint8_t *_dst, const uint8_t *_src[4], int width)
693
+#define rdpx(src) \
694
+    is_be ? AV_RB16(src) : AV_RL16(src)
695
+static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4],
696
+                                               int width, int bpc, int is_be)
695 697
 {
696 698
     int i;
697 699
     const uint16_t **src = (const uint16_t **)_src;
698 700
     uint16_t *dst        = (uint16_t *)_dst;
699 701
     for (i = 0; i < width; i++) {
700
-        int g = AV_RB16(src[0] + i);
701
-        int b = AV_RB16(src[1] + i);
702
-        int r = AV_RB16(src[2] + i);
702
+        int g = rdpx(src[0] + i);
703
+        int b = rdpx(src[1] + i);
704
+        int r = rdpx(src[2] + i);
703 705
 
704
-        dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
706
+        dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT);
705 707
     }
706 708
 }
707 709
 
708
-static void planar_rgb_to_uv(uint16_t *dstU, uint16_t *dstV, const uint8_t *src[4], int width)
710
+static void planar_rgb9le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
709 711
 {
710
-    int i;
711
-    for (i = 0; i < width; i++) {
712
-        int g = src[0][i];
713
-        int b = src[1][i];
714
-        int r = src[2][i];
712
+    planar_rgb16_to_y(dst, src, w, 9, 0);
713
+}
715 714
 
716
-        dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
717
-        dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6);
718
-    }
715
+static void planar_rgb9be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
716
+{
717
+    planar_rgb16_to_y(dst, src, w, 9, 1);
719 718
 }
720 719
 
721
-static void planar_rgb16le_to_uv(uint8_t *_dstU, uint8_t *_dstV,
722
-                                 const uint8_t *_src[4], int width)
720
+static void planar_rgb10le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
723 721
 {
724
-    int i;
725
-    const uint16_t **src = (const uint16_t **)_src;
726
-    uint16_t *dstU       = (uint16_t *)_dstU;
727
-    uint16_t *dstV       = (uint16_t *)_dstV;
728
-    for (i = 0; i < width; i++) {
729
-        int g = AV_RL16(src[0] + i);
730
-        int b = AV_RL16(src[1] + i);
731
-        int r = AV_RL16(src[2] + i);
722
+    planar_rgb16_to_y(dst, src, w, 10, 0);
723
+}
732 724
 
733
-        dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
734
-        dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
735
-    }
725
+static void planar_rgb10be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
726
+{
727
+    planar_rgb16_to_y(dst, src, w, 10, 1);
728
+}
729
+
730
+static void planar_rgb16le_to_y(uint8_t *dst, const uint8_t *src[4], int w)
731
+{
732
+    planar_rgb16_to_y(dst, src, w, 16, 0);
736 733
 }
737 734
 
738
-static void planar_rgb16be_to_uv(uint8_t *_dstU, uint8_t *_dstV,
739
-                                 const uint8_t *_src[4], int width)
735
+static void planar_rgb16be_to_y(uint8_t *dst, const uint8_t *src[4], int w)
736
+{
737
+    planar_rgb16_to_y(dst, src, w, 16, 1);
738
+}
739
+
740
+static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV,
741
+                                                const uint8_t *_src[4], int width,
742
+                                                int bpc, int is_be)
740 743
 {
741 744
     int i;
742 745
     const uint16_t **src = (const uint16_t **)_src;
743 746
     uint16_t *dstU       = (uint16_t *)_dstU;
744 747
     uint16_t *dstV       = (uint16_t *)_dstV;
745 748
     for (i = 0; i < width; i++) {
746
-        int g = AV_RB16(src[0] + i);
747
-        int b = AV_RB16(src[1] + i);
748
-        int r = AV_RB16(src[2] + i);
749
+        int g = rdpx(src[0] + i);
750
+        int b = rdpx(src[1] + i);
751
+        int r = rdpx(src[2] + i);
749 752
 
750
-        dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
751
-        dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
753
+        dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
754
+        dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT;
752 755
     }
753 756
 }
757
+#undef rdpx
758
+
759
+static void planar_rgb9le_to_uv(uint8_t *dstU, uint8_t *dstV,
760
+                                const uint8_t *src[4], int w)
761
+{
762
+    planar_rgb16_to_uv(dstU, dstV, src, w, 9, 0);
763
+}
764
+
765
+static void planar_rgb9be_to_uv(uint8_t *dstU, uint8_t *dstV,
766
+                                const uint8_t *src[4], int w)
767
+{
768
+    planar_rgb16_to_uv(dstU, dstV, src, w, 9, 1);
769
+}
770
+
771
+static void planar_rgb10le_to_uv(uint8_t *dstU, uint8_t *dstV,
772
+                                 const uint8_t *src[4], int w)
773
+{
774
+    planar_rgb16_to_uv(dstU, dstV, src, w, 10, 0);
775
+}
776
+
777
+static void planar_rgb10be_to_uv(uint8_t *dstU, uint8_t *dstV,
778
+                                 const uint8_t *src[4], int w)
779
+{
780
+    planar_rgb16_to_uv(dstU, dstV, src, w, 10, 1);
781
+}
782
+
783
+static void planar_rgb16le_to_uv(uint8_t *dstU, uint8_t *dstV,
784
+                                 const uint8_t *src[4], int w)
785
+{
786
+    planar_rgb16_to_uv(dstU, dstV, src, w, 16, 0);
787
+}
788
+
789
+static void planar_rgb16be_to_uv(uint8_t *dstU, uint8_t *dstV,
790
+                                 const uint8_t *src[4], int w)
791
+{
792
+    planar_rgb16_to_uv(dstU, dstV, src, w, 16, 1);
793
+}
754 794
 
755 795
 av_cold void ff_sws_init_input_funcs(SwsContext *c)
756 796
 {
... ...
@@ -778,12 +818,20 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
778 778
         c->chrToYV12 = palToUV_c;
779 779
         break;
780 780
     case PIX_FMT_GBRP9LE:
781
+        c->readChrPlanar = planar_rgb9le_to_uv;
782
+        break;
781 783
     case PIX_FMT_GBRP10LE:
784
+        c->readChrPlanar = planar_rgb10le_to_uv;
785
+        break;
782 786
     case PIX_FMT_GBRP16LE:
783 787
         c->readChrPlanar = planar_rgb16le_to_uv;
784 788
         break;
785 789
     case PIX_FMT_GBRP9BE:
790
+        c->readChrPlanar = planar_rgb9be_to_uv;
791
+        break;
786 792
     case PIX_FMT_GBRP10BE:
793
+        c->readChrPlanar = planar_rgb10be_to_uv;
794
+        break;
787 795
     case PIX_FMT_GBRP16BE:
788 796
         c->readChrPlanar = planar_rgb16be_to_uv;
789 797
         break;
... ...
@@ -975,12 +1023,20 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
975 975
     c->alpToYV12 = NULL;
976 976
     switch (srcFormat) {
977 977
     case PIX_FMT_GBRP9LE:
978
+        c->readLumPlanar = planar_rgb9le_to_y;
979
+        break;
978 980
     case PIX_FMT_GBRP10LE:
981
+        c->readLumPlanar = planar_rgb10le_to_y;
982
+        break;
979 983
     case PIX_FMT_GBRP16LE:
980 984
         c->readLumPlanar = planar_rgb16le_to_y;
981 985
         break;
982 986
     case PIX_FMT_GBRP9BE:
987
+        c->readLumPlanar = planar_rgb9be_to_y;
988
+        break;
983 989
     case PIX_FMT_GBRP10BE:
990
+        c->readLumPlanar = planar_rgb10be_to_y;
991
+        break;
984 992
     case PIX_FMT_GBRP16BE:
985 993
         c->readLumPlanar = planar_rgb16be_to_y;
986 994
         break;
... ...
@@ -148,7 +148,7 @@ fate-list:
148 148
 clean:: testclean
149 149
 
150 150
 testclean:
151
-	$(RM) -r tests/vsynth1 tests/vsynth2 tests/data tools/lavfi-showfiltfmts$(EXESUF)
151
+	$(RM) -r tests/vsynth1 tests/data tools/lavfi-showfiltfmts$(EXESUF)
152 152
 	$(RM) $(CLEANSUFFIXES:%=tests/%)
153 153
 	$(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF))
154 154