audio_fifo.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Audio FIFO
  3. * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Audio FIFO Buffer
  24. */
  25. #ifndef AVUTIL_AUDIO_FIFO_H
  26. #define AVUTIL_AUDIO_FIFO_H
  27. #include "avutil.h"
  28. #include "fifo.h"
  29. #include "samplefmt.h"
  30. /**
  31. * @addtogroup lavu_audio
  32. * @{
  33. */
  34. /**
  35. * Context for an Audio FIFO Buffer.
  36. *
  37. * - Operates at the sample level rather than the byte level.
  38. * - Supports multiple channels with either planar or packed sample format.
  39. * - Automatic reallocation when writing to a full buffer.
  40. */
  41. typedef struct AVAudioFifo AVAudioFifo;
  42. /**
  43. * Free an AVAudioFifo.
  44. *
  45. * @param af AVAudioFifo to free
  46. */
  47. void av_audio_fifo_free(AVAudioFifo *af);
  48. /**
  49. * Allocate an AVAudioFifo.
  50. *
  51. * @param sample_fmt sample format
  52. * @param channels number of channels
  53. * @param nb_samples initial allocation size, in samples
  54. * @return newly allocated AVAudioFifo, or NULL on error
  55. */
  56. AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,
  57. int nb_samples);
  58. /**
  59. * Reallocate an AVAudioFifo.
  60. *
  61. * @param af AVAudioFifo to reallocate
  62. * @param nb_samples new allocation size, in samples
  63. * @return 0 if OK, or negative AVERROR code on failure
  64. */
  65. int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples);
  66. /**
  67. * Write data to an AVAudioFifo.
  68. *
  69. * The AVAudioFifo will be reallocated automatically if the available space
  70. * is less than nb_samples.
  71. *
  72. * @see enum AVSampleFormat
  73. * The documentation for AVSampleFormat describes the data layout.
  74. *
  75. * @param af AVAudioFifo to write to
  76. * @param data audio data plane pointers
  77. * @param nb_samples number of samples to write
  78. * @return number of samples actually written, or negative AVERROR
  79. * code on failure.
  80. */
  81. int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
  82. /**
  83. * Read data from an AVAudioFifo.
  84. *
  85. * @see enum AVSampleFormat
  86. * The documentation for AVSampleFormat describes the data layout.
  87. *
  88. * @param af AVAudioFifo to read from
  89. * @param data audio data plane pointers
  90. * @param nb_samples number of samples to read
  91. * @return number of samples actually read, or negative AVERROR code
  92. * on failure.
  93. */
  94. int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);
  95. /**
  96. * Drain data from an AVAudioFifo.
  97. *
  98. * Removes the data without reading it.
  99. *
  100. * @param af AVAudioFifo to drain
  101. * @param nb_samples number of samples to drain
  102. * @return 0 if OK, or negative AVERROR code on failure
  103. */
  104. int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples);
  105. /**
  106. * Reset the AVAudioFifo buffer.
  107. *
  108. * This empties all data in the buffer.
  109. *
  110. * @param af AVAudioFifo to reset
  111. */
  112. void av_audio_fifo_reset(AVAudioFifo *af);
  113. /**
  114. * Get the current number of samples in the AVAudioFifo available for reading.
  115. *
  116. * @param af the AVAudioFifo to query
  117. * @return number of samples available for reading
  118. */
  119. int av_audio_fifo_size(AVAudioFifo *af);
  120. /**
  121. * Get the current number of samples in the AVAudioFifo available for writing.
  122. *
  123. * @param af the AVAudioFifo to query
  124. * @return number of samples available for writing
  125. */
  126. int av_audio_fifo_space(AVAudioFifo *af);
  127. /**
  128. * @}
  129. */
  130. #endif /* AVUTIL_AUDIO_FIFO_H */