factor identical ff_inplace_start_frame out of two filters
[ffmpeg.git] / libavfilter / af_channelmap.c
index 14c2c0c..b5cd96a 100644 (file)
@@ -118,8 +118,7 @@ static int get_channel(char **map, uint64_t *ch, char delim)
     return 0;
 }
 
-static av_cold int channelmap_init(AVFilterContext *ctx, const char *args,
-                                   void *opaque)
+static av_cold int channelmap_init(AVFilterContext *ctx, const char *args)
 {
     ChannelMapContext *s = ctx->priv;
     int ret;
@@ -314,7 +313,7 @@ static int channelmap_query_formats(AVFilterContext *ctx)
     return 0;
 }
 
-static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
+static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
 {
     AVFilterContext  *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
@@ -331,8 +330,10 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b
         if (nch_out > FF_ARRAY_ELEMS(buf->data)) {
             uint8_t **new_extended_data =
                 av_mallocz(nch_out * sizeof(*buf->extended_data));
-            if (!new_extended_data)
-                return;
+            if (!new_extended_data) {
+                avfilter_unref_buffer(buf);
+                return AVERROR(ENOMEM);
+            }
             if (buf->extended_data == buf->data) {
                 buf->extended_data = new_extended_data;
             } else {
@@ -354,7 +355,7 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b
         memcpy(buf->data, buf->extended_data,
            FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));
 
-    ff_filter_samples(outlink, buf);
+    return ff_filter_samples(outlink, buf);
 }
 
 static int channelmap_config_input(AVFilterLink *inlink)
@@ -391,12 +392,12 @@ AVFilter avfilter_af_channelmap = {
     .query_formats = channelmap_query_formats,
     .priv_size     = sizeof(ChannelMapContext),
 
-    .inputs        = (AVFilterPad[]) {{ .name            = "default",
-                                        .type            = AVMEDIA_TYPE_AUDIO,
-                                        .filter_samples  = channelmap_filter_samples,
-                                        .config_props    = channelmap_config_input },
-                                      { .name = NULL }},
-    .outputs       = (AVFilterPad[]) {{ .name            = "default",
-                                        .type            = AVMEDIA_TYPE_AUDIO },
-                                      { .name = NULL }},
+    .inputs        = (const AVFilterPad[]) {{ .name            = "default",
+                                              .type            = AVMEDIA_TYPE_AUDIO,
+                                              .filter_samples  = channelmap_filter_samples,
+                                              .config_props    = channelmap_config_input },
+                                            { .name = NULL }},
+    .outputs       = (const AVFilterPad[]) {{ .name            = "default",
+                                              .type            = AVMEDIA_TYPE_AUDIO },
+                                            { .name = NULL }},
 };