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.

76 lines
2.3KB

  1. /*
  2. * Copyright (c) Stefano Sabatini | stefasab at gmail.com
  3. * Copyright (c) S.N. Hemanth Meenakshisundaram | smeenaks at ucsd.edu
  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. #include "libavutil/avassert.h"
  22. #include "libavutil/channel_layout.h"
  23. #include "libavutil/common.h"
  24. #include "audio.h"
  25. #include "avfilter.h"
  26. #include "internal.h"
  27. AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
  28. {
  29. return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
  30. }
  31. AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
  32. {
  33. AVFrame *frame = av_frame_alloc();
  34. int channels = link->channels;
  35. int ret;
  36. av_assert0(channels == av_get_channel_layout_nb_channels(link->channel_layout) || !av_get_channel_layout_nb_channels(link->channel_layout));
  37. if (!frame)
  38. return NULL;
  39. frame->nb_samples = nb_samples;
  40. frame->format = link->format;
  41. av_frame_set_channels(frame, link->channels);
  42. frame->channel_layout = link->channel_layout;
  43. frame->sample_rate = link->sample_rate;
  44. ret = av_frame_get_buffer(frame, 0);
  45. if (ret < 0) {
  46. av_frame_free(&frame);
  47. return NULL;
  48. }
  49. av_samples_set_silence(frame->extended_data, 0, nb_samples, channels,
  50. link->format);
  51. return frame;
  52. }
  53. AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
  54. {
  55. AVFrame *ret = NULL;
  56. if (link->dstpad->get_audio_buffer)
  57. ret = link->dstpad->get_audio_buffer(link, nb_samples);
  58. if (!ret)
  59. ret = ff_default_get_audio_buffer(link, nb_samples);
  60. return ret;
  61. }