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.

98 lines
3.1KB

  1. /*
  2. * Copyright (c) 2011 Stefano Sabatini
  3. * Copyright (c) 2011 Mina Nagy Zaki
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * audio buffer sink
  24. */
  25. #include "avfilter.h"
  26. #include "asink_abuffer.h"
  27. static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
  28. {
  29. }
  30. static int init(AVFilterContext *ctx, const char *args, void *opaque)
  31. {
  32. if (!opaque) {
  33. av_log(ctx, AV_LOG_ERROR, "Opaque field required, please pass"
  34. " an initialized ABufferSinkContext");
  35. return AVERROR(EINVAL);
  36. }
  37. memcpy(ctx->priv, opaque, sizeof(ABufferSinkContext));
  38. return 0;
  39. }
  40. static int query_formats(AVFilterContext *ctx)
  41. {
  42. ABufferSinkContext *abuffersink = ctx->priv;
  43. AVFilterFormats *formats = NULL;
  44. if (!(formats = avfilter_make_format_list(abuffersink->sample_fmts)))
  45. return AVERROR(ENOMEM);
  46. avfilter_set_common_sample_formats(ctx, formats);
  47. if (!(formats = avfilter_make_format64_list(abuffersink->channel_layouts)))
  48. return AVERROR(ENOMEM);
  49. avfilter_set_common_channel_layouts(ctx, formats);
  50. if (!(formats = avfilter_make_format_list(abuffersink->packing_fmts)))
  51. return AVERROR(ENOMEM);
  52. avfilter_set_common_packing_formats(ctx, formats);
  53. return 0;
  54. }
  55. int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffersink,
  56. AVFilterBufferRef **samplesref,
  57. int av_unused flags)
  58. {
  59. int ret;
  60. AVFilterLink * const inlink = abuffersink->inputs[0];
  61. if ((ret = avfilter_request_frame(inlink)))
  62. return ret;
  63. if (!inlink->cur_buf)
  64. return AVERROR(EINVAL);
  65. *samplesref = inlink->cur_buf;
  66. inlink->cur_buf = NULL;
  67. return 0;
  68. }
  69. AVFilter avfilter_asink_abuffersink = {
  70. .name = "abuffersink",
  71. .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
  72. .init = init,
  73. .priv_size = sizeof(ABufferSinkContext),
  74. .query_formats = query_formats,
  75. .inputs = (AVFilterPad[]) {{ .name = "default",
  76. .type = AVMEDIA_TYPE_AUDIO,
  77. .filter_samples = filter_samples,
  78. .min_perms = AV_PERM_READ, },
  79. { .name = NULL }},
  80. .outputs = (AVFilterPad[]) {{ .name = NULL }},
  81. };