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.

102 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;
  44. int ret;
  45. formats = NULL;
  46. if ((ret = avfilter_add_format(&formats, abuffersink->sample_fmt)) < 0)
  47. return ret;
  48. avfilter_set_common_sample_formats(ctx, formats);
  49. formats = NULL;
  50. if ((ret = avfilter_add_format(&formats, abuffersink->channel_layout)) < 0)
  51. return ret;
  52. avfilter_set_common_channel_layouts(ctx, formats);
  53. formats = NULL;
  54. if ((ret = avfilter_add_format(&formats, abuffersink->planar)) < 0)
  55. return ret;
  56. avfilter_set_common_packing_formats(ctx, formats);
  57. return 0;
  58. }
  59. int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffersink,
  60. AVFilterBufferRef **samplesref,
  61. int av_unused flags)
  62. {
  63. int ret;
  64. AVFilterLink * const inlink = abuffersink->inputs[0];
  65. if ((ret = avfilter_request_frame(inlink)))
  66. return ret;
  67. if (!inlink->cur_buf)
  68. return AVERROR(EINVAL);
  69. *samplesref = inlink->cur_buf;
  70. inlink->cur_buf = NULL;
  71. return 0;
  72. }
  73. AVFilter avfilter_asink_abuffersink = {
  74. .name = "abuffersink",
  75. .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
  76. .init = init,
  77. .priv_size = sizeof(ABufferSinkContext),
  78. .query_formats = query_formats,
  79. .inputs = (AVFilterPad[]) {{ .name = "default",
  80. .type = AVMEDIA_TYPE_AUDIO,
  81. .filter_samples = filter_samples,
  82. .min_perms = AV_PERM_READ, },
  83. { .name = NULL }},
  84. .outputs = (AVFilterPad[]) {{ .name = NULL }},
  85. };