asrc_anullsrc.c 3.0 KB

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