audio_frame_queue.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Audio Frame Queue
  3. * Copyright (c) 2012 Justin Ruggles
  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. #ifndef AVCODEC_AUDIO_FRAME_QUEUE_H
  22. #define AVCODEC_AUDIO_FRAME_QUEUE_H
  23. #include "avcodec.h"
  24. typedef struct AudioFrame {
  25. int64_t pts;
  26. int duration;
  27. } AudioFrame;
  28. typedef struct AudioFrameQueue {
  29. AVCodecContext *avctx;
  30. int remaining_delay;
  31. int remaining_samples;
  32. AudioFrame *frames;
  33. unsigned frame_count;
  34. unsigned frame_alloc;
  35. } AudioFrameQueue;
  36. /**
  37. * Initialize AudioFrameQueue.
  38. *
  39. * @param avctx context to use for time_base and av_log
  40. * @param afq queue context
  41. */
  42. void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq);
  43. /**
  44. * Close AudioFrameQueue.
  45. *
  46. * Frees memory if needed.
  47. *
  48. * @param afq queue context
  49. */
  50. void ff_af_queue_close(AudioFrameQueue *afq);
  51. /**
  52. * Add a frame to the queue.
  53. *
  54. * @param afq queue context
  55. * @param f frame to add to the queue
  56. */
  57. int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f);
  58. /**
  59. * Remove frame(s) from the queue.
  60. *
  61. * Retrieves the pts of the next available frame, or a generated pts based on
  62. * the last frame duration if there are no frames left in the queue. The number
  63. * of requested samples should be the full number of samples represented by the
  64. * packet that will be output by the encoder. If fewer samples are available
  65. * in the queue, a smaller value will be used for the output duration.
  66. *
  67. * @param afq queue context
  68. * @param nb_samples number of samples to remove from the queue
  69. * @param[out] pts output packet pts
  70. * @param[out] duration output packet duration
  71. */
  72. void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts,
  73. int64_t *duration);
  74. #endif /* AVCODEC_AUDIO_FRAME_QUEUE_H */