xref: /aosp_15_r20/external/libdav1d/examples/dp_fifo.h (revision c09093415860a1c2373dacd84c4fde00c507cdfd)
1*c0909341SAndroid Build Coastguard Worker /*
2*c0909341SAndroid Build Coastguard Worker  * Copyright © 2019, VideoLAN and dav1d authors
3*c0909341SAndroid Build Coastguard Worker  * All rights reserved.
4*c0909341SAndroid Build Coastguard Worker  *
5*c0909341SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
6*c0909341SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions are met:
7*c0909341SAndroid Build Coastguard Worker  *
8*c0909341SAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright notice, this
9*c0909341SAndroid Build Coastguard Worker  *    list of conditions and the following disclaimer.
10*c0909341SAndroid Build Coastguard Worker  *
11*c0909341SAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright notice,
12*c0909341SAndroid Build Coastguard Worker  *    this list of conditions and the following disclaimer in the documentation
13*c0909341SAndroid Build Coastguard Worker  *    and/or other materials provided with the distribution.
14*c0909341SAndroid Build Coastguard Worker  *
15*c0909341SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16*c0909341SAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*c0909341SAndroid Build Coastguard Worker  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*c0909341SAndroid Build Coastguard Worker  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19*c0909341SAndroid Build Coastguard Worker  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20*c0909341SAndroid Build Coastguard Worker  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21*c0909341SAndroid Build Coastguard Worker  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22*c0909341SAndroid Build Coastguard Worker  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*c0909341SAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24*c0909341SAndroid Build Coastguard Worker  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*c0909341SAndroid Build Coastguard Worker  */
26*c0909341SAndroid Build Coastguard Worker 
27*c0909341SAndroid Build Coastguard Worker /*
28*c0909341SAndroid Build Coastguard Worker  * Dav1dPlay FIFO helper
29*c0909341SAndroid Build Coastguard Worker  */
30*c0909341SAndroid Build Coastguard Worker 
31*c0909341SAndroid Build Coastguard Worker typedef struct dp_fifo Dav1dPlayPtrFifo;
32*c0909341SAndroid Build Coastguard Worker 
33*c0909341SAndroid Build Coastguard Worker /* Create a FIFO
34*c0909341SAndroid Build Coastguard Worker  *
35*c0909341SAndroid Build Coastguard Worker  * Creates a FIFO with the given capacity.
36*c0909341SAndroid Build Coastguard Worker  * If the capacity is reached, new inserts into the FIFO
37*c0909341SAndroid Build Coastguard Worker  * will block until enough space is available again.
38*c0909341SAndroid Build Coastguard Worker  */
39*c0909341SAndroid Build Coastguard Worker Dav1dPlayPtrFifo *dp_fifo_create(size_t capacity);
40*c0909341SAndroid Build Coastguard Worker 
41*c0909341SAndroid Build Coastguard Worker /* Destroy a FIFO
42*c0909341SAndroid Build Coastguard Worker  *
43*c0909341SAndroid Build Coastguard Worker  * The FIFO must be empty before it is destroyed!
44*c0909341SAndroid Build Coastguard Worker  */
45*c0909341SAndroid Build Coastguard Worker void dp_fifo_destroy(Dav1dPlayPtrFifo *fifo);
46*c0909341SAndroid Build Coastguard Worker 
47*c0909341SAndroid Build Coastguard Worker /* Shift FIFO
48*c0909341SAndroid Build Coastguard Worker  *
49*c0909341SAndroid Build Coastguard Worker  * Return the first item from the FIFO, thereby removing it from
50*c0909341SAndroid Build Coastguard Worker  * the FIFO and making room for new entries.
51*c0909341SAndroid Build Coastguard Worker  */
52*c0909341SAndroid Build Coastguard Worker void *dp_fifo_shift(Dav1dPlayPtrFifo *fifo);
53*c0909341SAndroid Build Coastguard Worker 
54*c0909341SAndroid Build Coastguard Worker /* Push to FIFO
55*c0909341SAndroid Build Coastguard Worker  *
56*c0909341SAndroid Build Coastguard Worker  * Add an item to the end of the FIFO.
57*c0909341SAndroid Build Coastguard Worker  * If the FIFO is full, this call will block until there is again enough
58*c0909341SAndroid Build Coastguard Worker  * space in the FIFO, so calling this from the "consumer" thread if no
59*c0909341SAndroid Build Coastguard Worker  * other thread will call dp_fifo_shift will lead to a deadlock.
60*c0909341SAndroid Build Coastguard Worker  */
61*c0909341SAndroid Build Coastguard Worker void dp_fifo_push(Dav1dPlayPtrFifo *fifo, void *element);
62*c0909341SAndroid Build Coastguard Worker 
63*c0909341SAndroid Build Coastguard Worker void dp_fifo_flush(Dav1dPlayPtrFifo *fifo, void (*destroy_elem)(void *));
64