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.

151 lines
4.1KB

  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. * @defgroup lavu_audiofifo Audio FIFO Buffer
  35. * @{
  36. */
  37. /**
  38. * Context for an Audio FIFO Buffer.
  39. *
  40. * - Operates at the sample level rather than the byte level.
  41. * - Supports multiple channels with either planar or packed sample format.
  42. * - Automatic reallocation when writing to a full buffer.
  43. */
  44. typedef struct AVAudioFifo AVAudioFifo;
  45. /**
  46. * Free an AVAudioFifo.
  47. *
  48. * @param af AVAudioFifo to free
  49. */
  50. void av_audio_fifo_free(AVAudioFifo *af);
  51. /**
  52. * Allocate an AVAudioFifo.
  53. *
  54. * @param sample_fmt sample format
  55. * @param channels number of channels
  56. * @param nb_samples initial allocation size, in samples
  57. * @return newly allocated AVAudioFifo, or NULL on error
  58. */
  59. AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,
  60. int nb_samples);
  61. /**
  62. * Reallocate an AVAudioFifo.
  63. *
  64. * @param af AVAudioFifo to reallocate
  65. * @param nb_samples new allocation size, in samples
  66. * @return 0 if OK, or negative AVERROR code on failure
  67. */
  68. int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples);
  69. /**
  70. * Write data to an AVAudioFifo.
  71. *
  72. * The AVAudioFifo will be reallocated automatically if the available space
  73. * is less than nb_samples.
  74. *
  75. * @see enum AVSampleFormat
  76. * The documentation for AVSampleFormat describes the data layout.
  77. *
  78. * @param af AVAudioFifo to write to
  79. * @param data audio data plane pointers
  80. * @param nb_samples number of samples to write
  81. * @return number of samples actually written, or negative AVERROR
  82. * code on failure.
  83. */
  84. int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
  85. /**
  86. * Read data from an AVAudioFifo.
  87. *
  88. * @see enum AVSampleFormat
  89. * The documentation for AVSampleFormat describes the data layout.
  90. *
  91. * @param af AVAudioFifo to read from
  92. * @param data audio data plane pointers
  93. * @param nb_samples number of samples to read
  94. * @return number of samples actually read, or negative AVERROR code
  95. * on failure.
  96. */
  97. int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);
  98. /**
  99. * Drain data from an AVAudioFifo.
  100. *
  101. * Removes the data without reading it.
  102. *
  103. * @param af AVAudioFifo to drain
  104. * @param nb_samples number of samples to drain
  105. * @return 0 if OK, or negative AVERROR code on failure
  106. */
  107. int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples);
  108. /**
  109. * Reset the AVAudioFifo buffer.
  110. *
  111. * This empties all data in the buffer.
  112. *
  113. * @param af AVAudioFifo to reset
  114. */
  115. void av_audio_fifo_reset(AVAudioFifo *af);
  116. /**
  117. * Get the current number of samples in the AVAudioFifo available for reading.
  118. *
  119. * @param af the AVAudioFifo to query
  120. * @return number of samples available for reading
  121. */
  122. int av_audio_fifo_size(AVAudioFifo *af);
  123. /**
  124. * Get the current number of samples in the AVAudioFifo available for writing.
  125. *
  126. * @param af the AVAudioFifo to query
  127. * @return number of samples available for writing
  128. */
  129. int av_audio_fifo_space(AVAudioFifo *af);
  130. /**
  131. * @}
  132. * @}
  133. */
  134. #endif /* AVUTIL_AUDIO_FIFO_H */