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.

101 lines
2.8KB

  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 an AVFifoBuffer.
  30. * @param *f AVFifoBuffer to initialize
  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 an AVFifoBuffer.
  37. * @param *f AVFifoBuffer to free
  38. */
  39. void av_fifo_free(AVFifoBuffer *f);
  40. /**
  41. * Returns the amount of data in bytes in the AVFifoBuffer, that is the
  42. * amount of data you can read from it.
  43. * @param *f AVFifoBuffer to read from
  44. * @return size
  45. */
  46. int av_fifo_size(AVFifoBuffer *f);
  47. /**
  48. * Reads data from an AVFifoBuffer.
  49. * @param *f AVFifoBuffer to read from
  50. * @param *buf data destination
  51. * @param buf_size number of bytes to read
  52. */
  53. int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size);
  54. /**
  55. * Feeds data from an AVFifoBuffer to a user supplied callback.
  56. * @param *f AVFifoBuffer to read from
  57. * @param buf_size number of bytes to read
  58. * @param *func generic read function
  59. * @param *dest data destination
  60. */
  61. int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest);
  62. /**
  63. * Writes data into an AVFifoBuffer.
  64. * @param *f AVFifoBuffer to write to
  65. * @param *buf data source
  66. * @param size data size
  67. */
  68. void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size);
  69. /**
  70. * Resizes an AVFifoBuffer.
  71. * @param *f AVFifoBuffer to resize
  72. * @param size new AVFifoBuffer size in bytes
  73. */
  74. void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
  75. /**
  76. * Reads and discards the specified amount of data from an AVFifoBuffer.
  77. * @param *f AVFifoBuffer to read from
  78. * @param size amount of data to read in bytes
  79. */
  80. void av_fifo_drain(AVFifoBuffer *f, int size);
  81. static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
  82. {
  83. uint8_t *ptr = f->rptr + offs;
  84. if (ptr >= f->end)
  85. ptr -= f->end - f->buffer;
  86. return *ptr;
  87. }
  88. #endif /* FIFO_H */