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.

108 lines
3.0KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; 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 <inttypes.h>
  23. #include <stdio.h>
  24. #include "libavutil/channel_layout.h"
  25. #include "libavutil/internal.h"
  26. #include "avfilter.h"
  27. #include "internal.h"
  28. typedef struct {
  29. uint64_t channel_layout;
  30. int64_t sample_rate;
  31. } ANullContext;
  32. static int init(AVFilterContext *ctx, const char *args)
  33. {
  34. ANullContext *priv = ctx->priv;
  35. char channel_layout_str[128] = "";
  36. priv->sample_rate = 44100;
  37. priv->channel_layout = AV_CH_LAYOUT_STEREO;
  38. if (args)
  39. sscanf(args, "%"PRId64":%s", &priv->sample_rate, channel_layout_str);
  40. if (priv->sample_rate < 0) {
  41. av_log(ctx, AV_LOG_ERROR, "Invalid negative sample rate: %"PRId64"\n", priv->sample_rate);
  42. return AVERROR(EINVAL);
  43. }
  44. if (*channel_layout_str)
  45. if (!(priv->channel_layout = av_get_channel_layout(channel_layout_str))
  46. && sscanf(channel_layout_str, "%"PRId64, &priv->channel_layout) != 1) {
  47. av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for channel layout\n",
  48. channel_layout_str);
  49. return AVERROR(EINVAL);
  50. }
  51. return 0;
  52. }
  53. static int config_props(AVFilterLink *outlink)
  54. {
  55. ANullContext *priv = outlink->src->priv;
  56. char buf[128];
  57. int chans_nb;
  58. outlink->sample_rate = priv->sample_rate;
  59. outlink->channel_layout = priv->channel_layout;
  60. chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
  61. av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
  62. av_log(outlink->src, AV_LOG_VERBOSE,
  63. "sample_rate:%"PRId64 " channel_layout:%"PRId64 " channel_layout_description:'%s'\n",
  64. priv->sample_rate, priv->channel_layout, buf);
  65. return 0;
  66. }
  67. static int request_frame(AVFilterLink *link)
  68. {
  69. return -1;
  70. }
  71. static const AVFilterPad avfilter_asrc_anullsrc_outputs[] = {
  72. {
  73. .name = "default",
  74. .type = AVMEDIA_TYPE_AUDIO,
  75. .config_props = config_props,
  76. .request_frame = request_frame,
  77. },
  78. { NULL }
  79. };
  80. AVFilter avfilter_asrc_anullsrc = {
  81. .name = "anullsrc",
  82. .description = NULL_IF_CONFIG_SMALL("Null audio source, never return audio frames."),
  83. .init = init,
  84. .priv_size = sizeof(ANullContext),
  85. .inputs = NULL,
  86. .outputs = avfilter_asrc_anullsrc_outputs,
  87. };