| 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 | #ifndef AVUTIL_CONTAINER_FIFO_H |
| 20 | #define AVUTIL_CONTAINER_FIFO_H |
| 21 |
| 22 | #include <stddef.h> |
| 23 |
| 24 | /** |
| 25 | * AVContainerFifo is a FIFO for "containers" - dynamically allocated reusable |
| 26 | * structs (e.g. AVFrame or AVPacket). AVContainerFifo uses an internal pool of |
| 27 | * such containers to avoid allocating and freeing them repeatedly. |
| 28 | */ |
| 29 | typedef struct AVContainerFifo AVContainerFifo; |
| 30 |
| 31 | enum AVContainerFifoFlags { |
| 32 | /** |
| 33 | * Signal to av_container_fifo_write() that it should make a new reference |
| 34 | * to data in src rather than consume its contents. |
| 35 | * |
| 36 | * @note you must handle this flag manually in your own fifo_transfer() |
| 37 | * callback |
| 38 | */ |
| 39 | AV_CONTAINER_FIFO_FLAG_REF = (1 << 0), |
| 40 |
| 41 | /** |
| 42 | * This and all higher bits in flags may be set to any value by the caller |
| 43 | * and are guaranteed to be passed through to the fifo_transfer() callback |
| 44 | * and not be interpreted by AVContainerFifo code. |
| 45 | */ |
| 46 | AV_CONTAINER_FIFO_FLAG_USER = (1 << 16), |
| 47 | }; |
| 48 |
| 49 | /** |
| 50 | * Allocate a new AVContainerFifo for the container type defined by provided |
| 51 | * callbacks. |
| 52 | * |
| 53 | * @param opaque user data that will be passed to the callbacks provided to this |
| 54 | * function |
| 55 | * @param container_alloc allocate a new container instance and return a pointer |
| 56 | * to it, or NULL on failure |
| 57 | * @param container_reset reset the provided container instance to a clean state |
| 58 | * @param container_free free the provided container instance |
| 59 | * @param fifo_transfer Transfer the contents of container src to dst. |
| 60 | * @param flags currently unused |
| 61 | * |
| 62 | * @return newly allocated AVContainerFifo, or NULL on failure |
| 63 | */ |
| 64 | AVContainerFifo* |
| 65 | av_container_fifo_alloc(void *opaque, |
| 66 | void* (*container_alloc)(void *opaque), |
| 67 | void (*container_reset)(void *opaque, void *obj), |
| 68 | void (*container_free) (void *opaque, void *obj), |
| 69 | int (*fifo_transfer) (void *opaque, void *dst, void *src, unsigned flags), |
| 70 | unsigned flags); |
| 71 |
| 72 | /** |
| 73 | * Allocate an AVContainerFifo instance for AVFrames. |
| 74 | * |
| 75 | * @param flags currently unused |
| 76 | */ |
| 77 | AVContainerFifo *av_container_fifo_alloc_avframe(unsigned flags); |
| 78 |
| 79 | /** |
| 80 | * Free a AVContainerFifo and everything in it. |
| 81 | */ |
| 82 | void av_container_fifo_free(AVContainerFifo **cf); |
| 83 |
| 84 | /** |
| 85 | * Write the contents of obj to the FIFO. |
| 86 | * |
| 87 | * The fifo_transfer() callback previously provided to av_container_fifo_alloc() |
| 88 | * will be called with obj as src in order to perform the actual transfer. |
| 89 | */ |
| 90 | int av_container_fifo_write(AVContainerFifo *cf, void *obj, unsigned flags); |
| 91 |
| 92 | /** |
| 93 | * Read the next available object from the FIFO into obj. |
| 94 | * |
| 95 | * The fifo_read() callback previously provided to av_container_fifo_alloc() |
| 96 | * will be called with obj as dst in order to perform the actual transfer. |
| 97 | */ |
| 98 | int av_container_fifo_read(AVContainerFifo *cf, void *obj, unsigned flags); |
| 99 |
| 100 | /** |
| 101 | * Access objects stored in the FIFO without retrieving them. The |
| 102 | * fifo_transfer() callback will NOT be invoked and the FIFO state will not be |
| 103 | * modified. |
| 104 | * |
| 105 | * @param pobj Pointer to the object stored in the FIFO will be written here on |
| 106 | * success. The object remains owned by the FIFO and the caller may |
| 107 | * only access it as long as the FIFO is not modified. |
| 108 | * @param offset Position of the object to retrieve - 0 is the next item that |
| 109 | * would be read, 1 the one after, etc. Must be smaller than |
| 110 | * av_container_fifo_can_read(). |
| 111 | * |
| 112 | * @retval 0 success, a pointer was written into pobj |
| 113 | * @retval AVERROR(EINVAL) invalid offset value |
| 114 | */ |
| 115 | int av_container_fifo_peek(AVContainerFifo *cf, void **pobj, size_t offset); |
| 116 |
| 117 | /** |
| 118 | * Discard the specified number of elements from the FIFO. |
| 119 | * |
| 120 | * @param nb_elems number of elements to discard, MUST NOT be larger than |
| 121 | * av_fifo_can_read(f) |
| 122 | */ |
| 123 | void av_container_fifo_drain(AVContainerFifo *cf, size_t nb_elems); |
| 124 |
| 125 | /** |
| 126 | * @return number of objects available for reading |
| 127 | */ |
| 128 | size_t av_container_fifo_can_read(const AVContainerFifo *cf); |
| 129 |
| 130 | #endif // AVCODEC_CONTAINER_FIFO_H |
| 131 |