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.

148 lines
4.3KB

  1. /*
  2. * Copyright (c) 2007 Bobby Bingham
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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)
  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->nb_outputs; i++)
  53. av_freep(&ctx->output_pads[i].name);
  54. }
  55. static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
  56. {
  57. AVFilterContext *ctx = inlink->dst;
  58. int i, ret = 0;
  59. for (i = 0; i < ctx->nb_outputs; i++) {
  60. ret = ff_start_frame(ctx->outputs[i],
  61. avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
  62. if (ret < 0)
  63. break;
  64. }
  65. return ret;
  66. }
  67. static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
  68. {
  69. AVFilterContext *ctx = inlink->dst;
  70. int i, ret = 0;
  71. for (i = 0; i < ctx->nb_outputs; i++) {
  72. ret = ff_draw_slice(ctx->outputs[i], y, h, slice_dir);
  73. if (ret < 0)
  74. break;
  75. }
  76. return ret;
  77. }
  78. static void end_frame(AVFilterLink *inlink)
  79. {
  80. AVFilterContext *ctx = inlink->dst;
  81. int i;
  82. for (i = 0; i < ctx->nb_outputs; i++)
  83. ff_end_frame(ctx->outputs[i]);
  84. }
  85. AVFilter avfilter_vf_split = {
  86. .name = "split",
  87. .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
  88. .init = split_init,
  89. .uninit = split_uninit,
  90. .inputs = (const AVFilterPad[]) {{ .name = "default",
  91. .type = AVMEDIA_TYPE_VIDEO,
  92. .get_video_buffer= ff_null_get_video_buffer,
  93. .start_frame = start_frame,
  94. .draw_slice = draw_slice,
  95. .end_frame = end_frame, },
  96. { .name = NULL}},
  97. .outputs = (const AVFilterPad[]) {{ .name = NULL}},
  98. };
  99. static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
  100. {
  101. AVFilterContext *ctx = inlink->dst;
  102. int i, ret = 0;
  103. for (i = 0; i < ctx->nb_outputs; i++) {
  104. ret = ff_filter_samples(inlink->dst->outputs[i],
  105. avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
  106. if (ret < 0)
  107. break;
  108. }
  109. avfilter_unref_buffer(samplesref);
  110. return ret;
  111. }
  112. AVFilter avfilter_af_asplit = {
  113. .name = "asplit",
  114. .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
  115. .init = split_init,
  116. .uninit = split_uninit,
  117. .inputs = (const AVFilterPad[]) {{ .name = "default",
  118. .type = AVMEDIA_TYPE_AUDIO,
  119. .get_audio_buffer = ff_null_get_audio_buffer,
  120. .filter_samples = filter_samples },
  121. { .name = NULL }},
  122. .outputs = (const AVFilterPad[]) {{ .name = NULL }},
  123. };