Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

110 wiersze
3.4 KiB

  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 libavutil/fifo.h
  20. * a very simple circular buffer FIFO implementation
  21. */
  22. #ifndef AVUTIL_FIFO_H
  23. #define AVUTIL_FIFO_H
  24. #include <stdint.h>
  25. #include "avutil.h"
  26. #include "common.h"
  27. typedef struct AVFifoBuffer {
  28. uint8_t *buffer;
  29. uint8_t *rptr, *wptr, *end;
  30. uint32_t rndx, wndx;
  31. } AVFifoBuffer;
  32. /**
  33. * Initializes an AVFifoBuffer.
  34. * @param size of FIFO
  35. * @return AVFifoBuffer or NULL if mem allocation failure
  36. */
  37. AVFifoBuffer *av_fifo_alloc(unsigned int size);
  38. /**
  39. * Frees an AVFifoBuffer.
  40. * @param *f AVFifoBuffer to free
  41. */
  42. void av_fifo_free(AVFifoBuffer *f);
  43. /**
  44. * Resets the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
  45. * @param *f AVFifoBuffer to reset
  46. */
  47. void av_fifo_reset(AVFifoBuffer *f);
  48. /**
  49. * Returns the amount of data in bytes in the AVFifoBuffer, that is the
  50. * amount of data you can read from it.
  51. * @param *f AVFifoBuffer to read from
  52. * @return size
  53. */
  54. int av_fifo_size(AVFifoBuffer *f);
  55. /**
  56. * Feeds data from an AVFifoBuffer to a user-supplied callback.
  57. * @param *f AVFifoBuffer to read from
  58. * @param buf_size number of bytes to read
  59. * @param *func generic read function
  60. * @param *dest data destination
  61. */
  62. int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));
  63. /**
  64. * Feeds data from a user-supplied callback to an AVFifoBuffer.
  65. * @param *f AVFifoBuffer to write to
  66. * @param *src data source
  67. * @param size number of bytes to write
  68. * @param *func generic write function; the first parameter is src,
  69. * the second is dest_buf, the third is dest_buf_size.
  70. * func must return the number of bytes written to dest_buf, or <= 0 to
  71. * indicate no more data available to write.
  72. * If func is NULL, src is interpreted as a simple byte array for source data.
  73. * @return the number of bytes written to the FIFO
  74. */
  75. int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));
  76. /**
  77. * Resizes an AVFifoBuffer.
  78. * @param *f AVFifoBuffer to resize
  79. * @param size new AVFifoBuffer size in bytes
  80. * @return <0 for failure, >=0 otherwise
  81. */
  82. int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
  83. /**
  84. * Reads and discards the specified amount of data from an AVFifoBuffer.
  85. * @param *f AVFifoBuffer to read from
  86. * @param size amount of data to read in bytes
  87. */
  88. void av_fifo_drain(AVFifoBuffer *f, int size);
  89. __inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
  90. {
  91. uint8_t *ptr = f->rptr + offs;
  92. if (ptr >= f->end)
  93. ptr -= f->end - f->buffer;
  94. return *ptr;
  95. }
  96. #endif /* AVUTIL_FIFO_H */