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.

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