Browse code

avfilter: rename vf_reverse.c to f_reverse.c

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2015/07/24 11:09:53
Showing 3 changed files
... ...
@@ -43,7 +43,7 @@ OBJS-$(CONFIG_APAD_FILTER)                   += af_apad.o
43 43
 OBJS-$(CONFIG_APERMS_FILTER)                 += f_perms.o
44 44
 OBJS-$(CONFIG_APHASER_FILTER)                += af_aphaser.o generate_wave_table.o
45 45
 OBJS-$(CONFIG_ARESAMPLE_FILTER)              += af_aresample.o
46
-OBJS-$(CONFIG_AREVERSE_FILTER)               += vf_reverse.o
46
+OBJS-$(CONFIG_AREVERSE_FILTER)               += f_reverse.o
47 47
 OBJS-$(CONFIG_ASELECT_FILTER)                += f_select.o
48 48
 OBJS-$(CONFIG_ASENDCMD_FILTER)               += f_sendcmd.o
49 49
 OBJS-$(CONFIG_ASETNSAMPLES_FILTER)           += af_asetnsamples.o
... ...
@@ -189,7 +189,7 @@ OBJS-$(CONFIG_RANDOM_FILTER)                 += vf_random.o
189 189
 OBJS-$(CONFIG_REMOVEGRAIN_FILTER)            += vf_removegrain.o
190 190
 OBJS-$(CONFIG_REMOVELOGO_FILTER)             += bbox.o lswsutils.o lavfutils.o vf_removelogo.o
191 191
 OBJS-$(CONFIG_REPEATFIELDS_FILTER)           += vf_repeatfields.o
192
-OBJS-$(CONFIG_REVERSE_FILTER)                += vf_reverse.o
192
+OBJS-$(CONFIG_REVERSE_FILTER)                += f_reverse.o
193 193
 OBJS-$(CONFIG_ROTATE_FILTER)                 += vf_rotate.o
194 194
 OBJS-$(CONFIG_SEPARATEFIELDS_FILTER)         += vf_separatefields.o
195 195
 OBJS-$(CONFIG_SAB_FILTER)                    += vf_sab.o
196 196
new file mode 100644
... ...
@@ -0,0 +1,259 @@
0
+/*
1
+ * Copyright (c) 2015 Derek Buitenhuis
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
+#include "libavutil/opt.h"
21
+#include "avfilter.h"
22
+#include "formats.h"
23
+#include "internal.h"
24
+#include "video.h"
25
+
26
+#define DEFAULT_LENGTH 300
27
+
28
+typedef struct ReverseContext {
29
+    int nb_frames;
30
+    AVFrame **frames;
31
+    unsigned int frames_size;
32
+    unsigned int pts_size;
33
+    int64_t *pts;
34
+    int flush_idx;
35
+} ReverseContext;
36
+
37
+static av_cold int init(AVFilterContext *ctx)
38
+{
39
+    ReverseContext *s = ctx->priv;
40
+
41
+    s->pts = av_fast_realloc(NULL, &s->pts_size,
42
+                             DEFAULT_LENGTH * sizeof(*(s->pts)));
43
+    if (!s->pts)
44
+        return AVERROR(ENOMEM);
45
+
46
+    s->frames = av_fast_realloc(NULL, &s->frames_size,
47
+                                DEFAULT_LENGTH * sizeof(*(s->frames)));
48
+    if (!s->frames) {
49
+        av_freep(&s->pts);
50
+        return AVERROR(ENOMEM);
51
+    }
52
+
53
+    return 0;
54
+}
55
+
56
+static av_cold void uninit(AVFilterContext *ctx)
57
+{
58
+    ReverseContext *s = ctx->priv;
59
+
60
+    av_freep(&s->pts);
61
+    av_freep(&s->frames);
62
+}
63
+
64
+static int config_output(AVFilterLink *outlink)
65
+{
66
+    outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
67
+    return 0;
68
+}
69
+
70
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
71
+{
72
+    AVFilterContext *ctx = inlink->dst;
73
+    ReverseContext *s    = ctx->priv;
74
+    void *ptr;
75
+
76
+    if (s->nb_frames + 1 > s->pts_size / sizeof(*(s->pts))) {
77
+        ptr = av_fast_realloc(s->pts, &s->pts_size, s->pts_size * 2);
78
+        if (!ptr)
79
+            return AVERROR(ENOMEM);
80
+        s->pts = ptr;
81
+    }
82
+
83
+    if (s->nb_frames + 1 > s->frames_size / sizeof(*(s->frames))) {
84
+        ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2);
85
+        if (!ptr)
86
+            return AVERROR(ENOMEM);
87
+        s->frames = ptr;
88
+    }
89
+
90
+    s->frames[s->nb_frames] = in;
91
+    s->pts[s->nb_frames]    = in->pts;
92
+    s->nb_frames++;
93
+
94
+    return 0;
95
+}
96
+
97
+#if CONFIG_REVERSE_FILTER
98
+
99
+static int request_frame(AVFilterLink *outlink)
100
+{
101
+    AVFilterContext *ctx = outlink->src;
102
+    ReverseContext *s = ctx->priv;
103
+    int ret;
104
+
105
+    ret = ff_request_frame(ctx->inputs[0]);
106
+
107
+    if (ret == AVERROR_EOF && s->nb_frames > 0) {
108
+        AVFrame *out = s->frames[s->nb_frames - 1];
109
+        out->pts     = s->pts[s->flush_idx++];
110
+        ret          = ff_filter_frame(outlink, out);
111
+        s->nb_frames--;
112
+    }
113
+
114
+    return ret;
115
+}
116
+
117
+static const AVFilterPad reverse_inputs[] = {
118
+    {
119
+        .name         = "default",
120
+        .type         = AVMEDIA_TYPE_VIDEO,
121
+        .filter_frame = filter_frame,
122
+    },
123
+    { NULL }
124
+};
125
+
126
+static const AVFilterPad reverse_outputs[] = {
127
+    {
128
+        .name          = "default",
129
+        .type          = AVMEDIA_TYPE_VIDEO,
130
+        .request_frame = request_frame,
131
+        .config_props  = config_output,
132
+    },
133
+    { NULL }
134
+};
135
+
136
+AVFilter ff_vf_reverse = {
137
+    .name        = "reverse",
138
+    .description = NULL_IF_CONFIG_SMALL("Reverse a clip."),
139
+    .priv_size   = sizeof(ReverseContext),
140
+    .init        = init,
141
+    .uninit      = uninit,
142
+    .inputs      = reverse_inputs,
143
+    .outputs     = reverse_outputs,
144
+};
145
+
146
+#endif /* CONFIG_REVERSE_FILTER */
147
+
148
+#if CONFIG_AREVERSE_FILTER
149
+
150
+static int query_formats(AVFilterContext *ctx)
151
+{
152
+    AVFilterFormats *formats;
153
+    AVFilterChannelLayouts *layouts;
154
+    int ret;
155
+
156
+    layouts = ff_all_channel_layouts();
157
+    if (!layouts)
158
+        return AVERROR(ENOMEM);
159
+    ret = ff_set_common_channel_layouts(ctx, layouts);
160
+    if (ret < 0)
161
+        return ret;
162
+
163
+    ret = ff_set_common_formats(ctx, ff_planar_sample_fmts());
164
+    if (ret < 0)
165
+        return ret;
166
+
167
+    formats = ff_all_samplerates();
168
+    if (!formats)
169
+        return AVERROR(ENOMEM);
170
+    return ff_set_common_samplerates(ctx, formats);
171
+}
172
+
173
+static int areverse_request_frame(AVFilterLink *outlink)
174
+{
175
+    AVFilterContext *ctx = outlink->src;
176
+    ReverseContext *s = ctx->priv;
177
+    int ret, p, i, j;
178
+
179
+    ret = ff_request_frame(ctx->inputs[0]);
180
+
181
+    if (ret == AVERROR_EOF && s->nb_frames > 0) {
182
+        AVFrame *out = s->frames[s->nb_frames - 1];
183
+        out->pts     = s->pts[s->flush_idx++];
184
+
185
+        for (p = 0; p < outlink->channels; p++) {
186
+            switch (outlink->format) {
187
+            case AV_SAMPLE_FMT_U8P: {
188
+                uint8_t *dst = (uint8_t *)out->extended_data[p];
189
+                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
190
+                    FFSWAP(uint8_t, dst[i], dst[j]);
191
+            }
192
+                break;
193
+            case AV_SAMPLE_FMT_S16P: {
194
+                int16_t *dst = (int16_t *)out->extended_data[p];
195
+                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
196
+                    FFSWAP(int16_t, dst[i], dst[j]);
197
+            }
198
+                break;
199
+            case AV_SAMPLE_FMT_S32P: {
200
+                int32_t *dst = (int32_t *)out->extended_data[p];
201
+                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
202
+                    FFSWAP(int32_t, dst[i], dst[j]);
203
+            }
204
+                break;
205
+            case AV_SAMPLE_FMT_FLTP: {
206
+                float *dst = (float *)out->extended_data[p];
207
+                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
208
+                    FFSWAP(float, dst[i], dst[j]);
209
+            }
210
+                break;
211
+            case AV_SAMPLE_FMT_DBLP: {
212
+                double *dst = (double *)out->extended_data[p];
213
+                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
214
+                    FFSWAP(double, dst[i], dst[j]);
215
+            }
216
+                break;
217
+            }
218
+        }
219
+
220
+        ret = ff_filter_frame(outlink, out);
221
+        s->nb_frames--;
222
+    }
223
+
224
+    return ret;
225
+}
226
+
227
+static const AVFilterPad areverse_inputs[] = {
228
+    {
229
+        .name           = "default",
230
+        .type           = AVMEDIA_TYPE_AUDIO,
231
+        .filter_frame   = filter_frame,
232
+        .needs_writable = 1,
233
+    },
234
+    { NULL }
235
+};
236
+
237
+static const AVFilterPad areverse_outputs[] = {
238
+    {
239
+        .name          = "default",
240
+        .type          = AVMEDIA_TYPE_AUDIO,
241
+        .request_frame = areverse_request_frame,
242
+        .config_props  = config_output,
243
+    },
244
+    { NULL }
245
+};
246
+
247
+AVFilter ff_af_areverse = {
248
+    .name          = "areverse",
249
+    .description   = NULL_IF_CONFIG_SMALL("Reverse an audio clip."),
250
+    .query_formats = query_formats,
251
+    .priv_size     = sizeof(ReverseContext),
252
+    .init          = init,
253
+    .uninit        = uninit,
254
+    .inputs        = areverse_inputs,
255
+    .outputs       = areverse_outputs,
256
+};
257
+
258
+#endif /* CONFIG_AREVERSE_FILTER */
0 259
deleted file mode 100644
... ...
@@ -1,259 +0,0 @@
1
-/*
2
- * Copyright (c) 2015 Derek Buitenhuis
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#include "libavutil/opt.h"
22
-#include "avfilter.h"
23
-#include "formats.h"
24
-#include "internal.h"
25
-#include "video.h"
26
-
27
-#define DEFAULT_LENGTH 300
28
-
29
-typedef struct ReverseContext {
30
-    int nb_frames;
31
-    AVFrame **frames;
32
-    unsigned int frames_size;
33
-    unsigned int pts_size;
34
-    int64_t *pts;
35
-    int flush_idx;
36
-} ReverseContext;
37
-
38
-static av_cold int init(AVFilterContext *ctx)
39
-{
40
-    ReverseContext *s = ctx->priv;
41
-
42
-    s->pts = av_fast_realloc(NULL, &s->pts_size,
43
-                             DEFAULT_LENGTH * sizeof(*(s->pts)));
44
-    if (!s->pts)
45
-        return AVERROR(ENOMEM);
46
-
47
-    s->frames = av_fast_realloc(NULL, &s->frames_size,
48
-                                DEFAULT_LENGTH * sizeof(*(s->frames)));
49
-    if (!s->frames) {
50
-        av_freep(&s->pts);
51
-        return AVERROR(ENOMEM);
52
-    }
53
-
54
-    return 0;
55
-}
56
-
57
-static av_cold void uninit(AVFilterContext *ctx)
58
-{
59
-    ReverseContext *s = ctx->priv;
60
-
61
-    av_freep(&s->pts);
62
-    av_freep(&s->frames);
63
-}
64
-
65
-static int config_output(AVFilterLink *outlink)
66
-{
67
-    outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
68
-    return 0;
69
-}
70
-
71
-static int filter_frame(AVFilterLink *inlink, AVFrame *in)
72
-{
73
-    AVFilterContext *ctx = inlink->dst;
74
-    ReverseContext *s    = ctx->priv;
75
-    void *ptr;
76
-
77
-    if (s->nb_frames + 1 > s->pts_size / sizeof(*(s->pts))) {
78
-        ptr = av_fast_realloc(s->pts, &s->pts_size, s->pts_size * 2);
79
-        if (!ptr)
80
-            return AVERROR(ENOMEM);
81
-        s->pts = ptr;
82
-    }
83
-
84
-    if (s->nb_frames + 1 > s->frames_size / sizeof(*(s->frames))) {
85
-        ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2);
86
-        if (!ptr)
87
-            return AVERROR(ENOMEM);
88
-        s->frames = ptr;
89
-    }
90
-
91
-    s->frames[s->nb_frames] = in;
92
-    s->pts[s->nb_frames]    = in->pts;
93
-    s->nb_frames++;
94
-
95
-    return 0;
96
-}
97
-
98
-#if CONFIG_REVERSE_FILTER
99
-
100
-static int request_frame(AVFilterLink *outlink)
101
-{
102
-    AVFilterContext *ctx = outlink->src;
103
-    ReverseContext *s = ctx->priv;
104
-    int ret;
105
-
106
-    ret = ff_request_frame(ctx->inputs[0]);
107
-
108
-    if (ret == AVERROR_EOF && s->nb_frames > 0) {
109
-        AVFrame *out = s->frames[s->nb_frames - 1];
110
-        out->pts     = s->pts[s->flush_idx++];
111
-        ret          = ff_filter_frame(outlink, out);
112
-        s->nb_frames--;
113
-    }
114
-
115
-    return ret;
116
-}
117
-
118
-static const AVFilterPad reverse_inputs[] = {
119
-    {
120
-        .name         = "default",
121
-        .type         = AVMEDIA_TYPE_VIDEO,
122
-        .filter_frame = filter_frame,
123
-    },
124
-    { NULL }
125
-};
126
-
127
-static const AVFilterPad reverse_outputs[] = {
128
-    {
129
-        .name          = "default",
130
-        .type          = AVMEDIA_TYPE_VIDEO,
131
-        .request_frame = request_frame,
132
-        .config_props  = config_output,
133
-    },
134
-    { NULL }
135
-};
136
-
137
-AVFilter ff_vf_reverse = {
138
-    .name        = "reverse",
139
-    .description = NULL_IF_CONFIG_SMALL("Reverse a clip."),
140
-    .priv_size   = sizeof(ReverseContext),
141
-    .init        = init,
142
-    .uninit      = uninit,
143
-    .inputs      = reverse_inputs,
144
-    .outputs     = reverse_outputs,
145
-};
146
-
147
-#endif /* CONFIG_REVERSE_FILTER */
148
-
149
-#if CONFIG_AREVERSE_FILTER
150
-
151
-static int query_formats(AVFilterContext *ctx)
152
-{
153
-    AVFilterFormats *formats;
154
-    AVFilterChannelLayouts *layouts;
155
-    int ret;
156
-
157
-    layouts = ff_all_channel_layouts();
158
-    if (!layouts)
159
-        return AVERROR(ENOMEM);
160
-    ret = ff_set_common_channel_layouts(ctx, layouts);
161
-    if (ret < 0)
162
-        return ret;
163
-
164
-    ret = ff_set_common_formats(ctx, ff_planar_sample_fmts());
165
-    if (ret < 0)
166
-        return ret;
167
-
168
-    formats = ff_all_samplerates();
169
-    if (!formats)
170
-        return AVERROR(ENOMEM);
171
-    return ff_set_common_samplerates(ctx, formats);
172
-}
173
-
174
-static int areverse_request_frame(AVFilterLink *outlink)
175
-{
176
-    AVFilterContext *ctx = outlink->src;
177
-    ReverseContext *s = ctx->priv;
178
-    int ret, p, i, j;
179
-
180
-    ret = ff_request_frame(ctx->inputs[0]);
181
-
182
-    if (ret == AVERROR_EOF && s->nb_frames > 0) {
183
-        AVFrame *out = s->frames[s->nb_frames - 1];
184
-        out->pts     = s->pts[s->flush_idx++];
185
-
186
-        for (p = 0; p < outlink->channels; p++) {
187
-            switch (outlink->format) {
188
-            case AV_SAMPLE_FMT_U8P: {
189
-                uint8_t *dst = (uint8_t *)out->extended_data[p];
190
-                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
191
-                    FFSWAP(uint8_t, dst[i], dst[j]);
192
-            }
193
-                break;
194
-            case AV_SAMPLE_FMT_S16P: {
195
-                int16_t *dst = (int16_t *)out->extended_data[p];
196
-                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
197
-                    FFSWAP(int16_t, dst[i], dst[j]);
198
-            }
199
-                break;
200
-            case AV_SAMPLE_FMT_S32P: {
201
-                int32_t *dst = (int32_t *)out->extended_data[p];
202
-                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
203
-                    FFSWAP(int32_t, dst[i], dst[j]);
204
-            }
205
-                break;
206
-            case AV_SAMPLE_FMT_FLTP: {
207
-                float *dst = (float *)out->extended_data[p];
208
-                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
209
-                    FFSWAP(float, dst[i], dst[j]);
210
-            }
211
-                break;
212
-            case AV_SAMPLE_FMT_DBLP: {
213
-                double *dst = (double *)out->extended_data[p];
214
-                for (i = 0, j = out->nb_samples - 1; i < j; i++, j--)
215
-                    FFSWAP(double, dst[i], dst[j]);
216
-            }
217
-                break;
218
-            }
219
-        }
220
-
221
-        ret = ff_filter_frame(outlink, out);
222
-        s->nb_frames--;
223
-    }
224
-
225
-    return ret;
226
-}
227
-
228
-static const AVFilterPad areverse_inputs[] = {
229
-    {
230
-        .name           = "default",
231
-        .type           = AVMEDIA_TYPE_AUDIO,
232
-        .filter_frame   = filter_frame,
233
-        .needs_writable = 1,
234
-    },
235
-    { NULL }
236
-};
237
-
238
-static const AVFilterPad areverse_outputs[] = {
239
-    {
240
-        .name          = "default",
241
-        .type          = AVMEDIA_TYPE_AUDIO,
242
-        .request_frame = areverse_request_frame,
243
-        .config_props  = config_output,
244
-    },
245
-    { NULL }
246
-};
247
-
248
-AVFilter ff_af_areverse = {
249
-    .name          = "areverse",
250
-    .description   = NULL_IF_CONFIG_SMALL("Reverse an audio clip."),
251
-    .query_formats = query_formats,
252
-    .priv_size     = sizeof(ReverseContext),
253
-    .init          = init,
254
-    .uninit        = uninit,
255
-    .inputs        = areverse_inputs,
256
-    .outputs       = areverse_outputs,
257
-};
258
-
259
-#endif /* CONFIG_AREVERSE_FILTER */