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.

121 lines
3.7KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file
  20. * null audio source
  21. */
  22. #include "libavutil/audioconvert.h"
  23. #include "libavutil/opt.h"
  24. #include "avfilter.h"
  25. #include "internal.h"
  26. typedef struct {
  27. const AVClass *class;
  28. char *channel_layout_str;
  29. int64_t channel_layout;
  30. char *sample_rate_str;
  31. int sample_rate;
  32. } ANullContext;
  33. #define OFFSET(x) offsetof(ANullContext, x)
  34. static const AVOption anullsrc_options[]= {
  35. { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
  36. { "cl", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
  37. { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
  38. { "r", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
  39. { NULL },
  40. };
  41. static const char *anullsrc_get_name(void *ctx)
  42. {
  43. return "anullsrc";
  44. }
  45. static const AVClass anullsrc_class = {
  46. "ANullSrcContext",
  47. anullsrc_get_name,
  48. anullsrc_options
  49. };
  50. static int init(AVFilterContext *ctx, const char *args, void *opaque)
  51. {
  52. ANullContext *priv = ctx->priv;
  53. int ret;
  54. priv->class = &anullsrc_class;
  55. av_opt_set_defaults(priv);
  56. if ((ret = (av_set_options_string(priv, args, "=", ":"))) < 0) {
  57. av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
  58. return ret;
  59. }
  60. if ((ret = ff_parse_sample_rate(&priv->sample_rate,
  61. priv->sample_rate_str, ctx)) < 0)
  62. return ret;
  63. if ((ret = ff_parse_channel_layout(&priv->channel_layout,
  64. priv->channel_layout_str, ctx)) < 0)
  65. return ret;
  66. return 0;
  67. }
  68. static int config_props(AVFilterLink *outlink)
  69. {
  70. ANullContext *priv = outlink->src->priv;
  71. char buf[128];
  72. int chans_nb;
  73. outlink->sample_rate = priv->sample_rate;
  74. outlink->channel_layout = priv->channel_layout;
  75. chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
  76. av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
  77. av_log(outlink->src, AV_LOG_INFO,
  78. "sample_rate:%d channel_layout:%"PRId64 " channel_layout_description:'%s'\n",
  79. priv->sample_rate, priv->channel_layout, buf);
  80. return 0;
  81. }
  82. static int request_frame(AVFilterLink *link)
  83. {
  84. return -1;
  85. }
  86. AVFilter avfilter_asrc_anullsrc = {
  87. .name = "anullsrc",
  88. .description = NULL_IF_CONFIG_SMALL("Null audio source, never return audio frames."),
  89. .init = init,
  90. .priv_size = sizeof(ANullContext),
  91. .inputs = (AVFilterPad[]) {{ .name = NULL}},
  92. .outputs = (AVFilterPad[]) {{ .name = "default",
  93. .type = AVMEDIA_TYPE_AUDIO,
  94. .config_props = config_props,
  95. .request_frame = request_frame, },
  96. { .name = NULL}},
  97. };