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