audio.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "libavutil/channel_layout.h"
  19. #include "libavutil/common.h"
  20. #include "audio.h"
  21. #include "avfilter.h"
  22. #include "internal.h"
  23. AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
  24. {
  25. return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
  26. }
  27. AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
  28. {
  29. AVFrame *frame = av_frame_alloc();
  30. int channels = av_get_channel_layout_nb_channels(link->channel_layout);
  31. int ret;
  32. if (!frame)
  33. return NULL;
  34. frame->nb_samples = nb_samples;
  35. frame->format = link->format;
  36. frame->channel_layout = link->channel_layout;
  37. frame->sample_rate = link->sample_rate;
  38. ret = av_frame_get_buffer(frame, 0);
  39. if (ret < 0) {
  40. av_frame_free(&frame);
  41. return NULL;
  42. }
  43. av_samples_set_silence(frame->extended_data, 0, nb_samples, channels,
  44. link->format);
  45. return frame;
  46. }
  47. AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
  48. {
  49. AVFrame *ret = NULL;
  50. if (link->dstpad->get_audio_buffer)
  51. ret = link->dstpad->get_audio_buffer(link, nb_samples);
  52. if (!ret)
  53. ret = ff_default_get_audio_buffer(link, nb_samples);
  54. return ret;
  55. }