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.

108 lines
2.7KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file fifo.h
  20. * A very simple circular buffer FIFO implementation.
  21. */
  22. #ifndef FIFO_H
  23. #define FIFO_H
  24. typedef struct AVFifoBuffer {
  25. uint8_t *buffer;
  26. uint8_t *rptr, *wptr, *end;
  27. } AVFifoBuffer;
  28. /**
  29. * Initializes a FIFO *.
  30. * @param *f FIFO buffer
  31. * @param size of FIFO
  32. * @return <0 for failure >=0 otherwise
  33. */
  34. int av_fifo_init(AVFifoBuffer *f, int size);
  35. /**
  36. * Frees a FIFO *.
  37. * @param *f FIFO buffer
  38. */
  39. void av_fifo_free(AVFifoBuffer *f);
  40. /**
  41. * Returns the size of a FIFO *.
  42. * @param *f FIFO buffer
  43. * @return size
  44. */
  45. int av_fifo_size(AVFifoBuffer *f);
  46. /**
  47. * Reads the data from the FIFO *.
  48. * @param *f FIFO buffer
  49. * @param *buf data destination
  50. * @param buf_size data size
  51. * @return -1 if not enough data
  52. */
  53. int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size);
  54. /**
  55. * Reads the data from the FIFO *.
  56. * @param *f FIFO buffer
  57. * @param buf_size data size
  58. * @param *func generic read function
  59. * @param *dest data destination
  60. * @return -1 if not enough data
  61. */
  62. int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest);
  63. /**
  64. * Writes the data in the FIFO *.
  65. * @param *f FIFO buffer
  66. * @param *buf data source
  67. * @param size data size
  68. */
  69. void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size);
  70. /**
  71. * Resizes the FIFO *.
  72. * @param *f FIFO buffer
  73. * @param size data size
  74. */
  75. void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
  76. /**
  77. * Discards the data from the FIFO *.
  78. * @param *f FIFO buffer
  79. * @param size data size
  80. */
  81. void av_fifo_drain(AVFifoBuffer *f, int size);
  82. /**
  83. * Returns a pointer with circular offset from FIFO's read pointer.
  84. * @param *f FIFO buffer
  85. * @param offs offset
  86. * @return ptr=rptr+offs if rptr+offs<end else rptr+offs -(end-begin)
  87. */
  88. static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
  89. {
  90. uint8_t *ptr = f->rptr + offs;
  91. if (ptr >= f->end)
  92. ptr -= f->end - f->buffer;
  93. return *ptr;
  94. }
  95. #endif /* FIFO_H */