You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.1KB

  1. /*
  2. * Copyright (c) 2007 Bobby Bingham
  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. * @file
  22. * audio and video splitter
  23. */
  24. #include "avfilter.h"
  25. #include "audio.h"
  26. static int split_init(AVFilterContext *ctx, const char *args, void *opaque)
  27. {
  28. int i, nb_outputs = 2;
  29. if (args) {
  30. nb_outputs = strtol(args, NULL, 0);
  31. if (nb_outputs <= 0) {
  32. av_log(ctx, AV_LOG_ERROR, "Invalid number of outputs specified: %d.\n",
  33. nb_outputs);
  34. return AVERROR(EINVAL);
  35. }
  36. }
  37. for (i = 0; i < nb_outputs; i++) {
  38. char name[32];
  39. AVFilterPad pad = { 0 };
  40. snprintf(name, sizeof(name), "output%d", i);
  41. pad.type = ctx->filter->inputs[0].type;
  42. pad.name = av_strdup(name);
  43. avfilter_insert_outpad(ctx, i, &pad);
  44. }
  45. return 0;
  46. }
  47. static void split_uninit(AVFilterContext *ctx)
  48. {
  49. int i;
  50. for (i = 0; i < ctx->output_count; i++)
  51. av_freep(&ctx->output_pads[i].name);
  52. }
  53. static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
  54. {
  55. AVFilterContext *ctx = inlink->dst;
  56. int i;
  57. for (i = 0; i < ctx->output_count; i++)
  58. avfilter_start_frame(ctx->outputs[i],
  59. avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
  60. }
  61. static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
  62. {
  63. AVFilterContext *ctx = inlink->dst;
  64. int i;
  65. for (i = 0; i < ctx->output_count; i++)
  66. avfilter_draw_slice(ctx->outputs[i], y, h, slice_dir);
  67. }
  68. static void end_frame(AVFilterLink *inlink)
  69. {
  70. AVFilterContext *ctx = inlink->dst;
  71. int i;
  72. for (i = 0; i < ctx->output_count; i++)
  73. avfilter_end_frame(ctx->outputs[i]);
  74. avfilter_unref_buffer(inlink->cur_buf);
  75. }
  76. AVFilter avfilter_vf_split = {
  77. .name = "split",
  78. .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
  79. .init = split_init,
  80. .uninit = split_uninit,
  81. .inputs = (const AVFilterPad[]) {{ .name = "default",
  82. .type = AVMEDIA_TYPE_VIDEO,
  83. .get_video_buffer= avfilter_null_get_video_buffer,
  84. .start_frame = start_frame,
  85. .draw_slice = draw_slice,
  86. .end_frame = end_frame, },
  87. { .name = NULL}},
  88. .outputs = (AVFilterPad[]) {{ .name = NULL}},
  89. };
  90. static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
  91. {
  92. AVFilterContext *ctx = inlink->dst;
  93. int i;
  94. for (i = 0; i < ctx->output_count; i++)
  95. ff_filter_samples(inlink->dst->outputs[i],
  96. avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
  97. }
  98. AVFilter avfilter_af_asplit = {
  99. .name = "asplit",
  100. .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
  101. .init = split_init,
  102. .uninit = split_uninit,
  103. .inputs = (const AVFilterPad[]) {{ .name = "default",
  104. .type = AVMEDIA_TYPE_AUDIO,
  105. .get_audio_buffer = ff_null_get_audio_buffer,
  106. .filter_samples = filter_samples },
  107. { .name = NULL }},
  108. .outputs = (const AVFilterPad[]) {{ .name = NULL }},
  109. };