author | unc0rr |
Fri, 28 Mar 2014 21:20:25 +0400 | |
changeset 10217 | 1a1da2342c5b |
parent 7813 | 7ac83d79b897 |
permissions | -rw-r--r-- |
7813
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
1 |
/* |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
2 |
* This file is part of Libav. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
3 |
* |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
4 |
* Libav is free software; you can redistribute it and/or |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
5 |
* modify it under the terms of the GNU Lesser General Public |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
6 |
* License as published by the Free Software Foundation; either |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
7 |
* version 2.1 of the License, or (at your option) any later version. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
8 |
* |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
9 |
* Libav is distributed in the hope that it will be useful, |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
12 |
* Lesser General Public License for more details. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
13 |
* |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU Lesser General Public |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
15 |
* License along with Libav; if not, write to the Free Software |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
17 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
18 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
19 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
20 |
* @file |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
21 |
* a very simple circular buffer FIFO implementation |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
22 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
23 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
24 |
#ifndef AVUTIL_FIFO_H |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
25 |
#define AVUTIL_FIFO_H |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
26 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
27 |
#include <stdint.h> |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
28 |
#include "avutil.h" |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
29 |
#include "attributes.h" |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
30 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
31 |
typedef struct AVFifoBuffer { |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
32 |
uint8_t *buffer; |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
33 |
uint8_t *rptr, *wptr, *end; |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
34 |
uint32_t rndx, wndx; |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
35 |
} AVFifoBuffer; |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
36 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
37 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
38 |
* Initialize an AVFifoBuffer. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
39 |
* @param size of FIFO |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
40 |
* @return AVFifoBuffer or NULL in case of memory allocation failure |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
41 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
42 |
AVFifoBuffer *av_fifo_alloc(unsigned int size); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
43 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
44 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
45 |
* Free an AVFifoBuffer. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
46 |
* @param f AVFifoBuffer to free |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
47 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
48 |
void av_fifo_free(AVFifoBuffer *f); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
49 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
50 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
51 |
* Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
52 |
* @param f AVFifoBuffer to reset |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
53 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
54 |
void av_fifo_reset(AVFifoBuffer *f); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
55 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
56 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
57 |
* Return the amount of data in bytes in the AVFifoBuffer, that is the |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
58 |
* amount of data you can read from it. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
59 |
* @param f AVFifoBuffer to read from |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
60 |
* @return size |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
61 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
62 |
int av_fifo_size(AVFifoBuffer *f); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
63 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
64 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
65 |
* Return the amount of space in bytes in the AVFifoBuffer, that is the |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
66 |
* amount of data you can write into it. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
67 |
* @param f AVFifoBuffer to write into |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
68 |
* @return size |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
69 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
70 |
int av_fifo_space(AVFifoBuffer *f); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
71 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
72 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
73 |
* Feed data from an AVFifoBuffer to a user-supplied callback. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
74 |
* @param f AVFifoBuffer to read from |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
75 |
* @param buf_size number of bytes to read |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
76 |
* @param func generic read function |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
77 |
* @param dest data destination |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
78 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
79 |
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int)); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
80 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
81 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
82 |
* Feed data from a user-supplied callback to an AVFifoBuffer. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
83 |
* @param f AVFifoBuffer to write to |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
84 |
* @param src data source; non-const since it may be used as a |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
85 |
* modifiable context by the function defined in func |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
86 |
* @param size number of bytes to write |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
87 |
* @param func generic write function; the first parameter is src, |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
88 |
* the second is dest_buf, the third is dest_buf_size. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
89 |
* func must return the number of bytes written to dest_buf, or <= 0 to |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
90 |
* indicate no more data available to write. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
91 |
* If func is NULL, src is interpreted as a simple byte array for source data. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
92 |
* @return the number of bytes written to the FIFO |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
93 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
94 |
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int)); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
95 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
96 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
97 |
* Resize an AVFifoBuffer. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
98 |
* @param f AVFifoBuffer to resize |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
99 |
* @param size new AVFifoBuffer size in bytes |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
100 |
* @return <0 for failure, >=0 otherwise |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
101 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
102 |
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
103 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
104 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
105 |
* Read and discard the specified amount of data from an AVFifoBuffer. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
106 |
* @param f AVFifoBuffer to read from |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
107 |
* @param size amount of data to read in bytes |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
108 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
109 |
void av_fifo_drain(AVFifoBuffer *f, int size); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
110 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
111 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
112 |
* Return a pointer to the data stored in a FIFO buffer at a certain offset. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
113 |
* The FIFO buffer is not modified. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
114 |
* |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
115 |
* @param f AVFifoBuffer to peek at, f must be non-NULL |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
116 |
* @param offs an offset in bytes, its absolute value must be less |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
117 |
* than the used buffer size or the returned pointer will |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
118 |
* point outside to the buffer data. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
119 |
* The used buffer size can be checked with av_fifo_size(). |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
120 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
121 |
static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs) |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
122 |
{ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
123 |
uint8_t *ptr = f->rptr + offs; |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
124 |
if (ptr >= f->end) |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
125 |
ptr = f->buffer + (ptr - f->end); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
126 |
else if (ptr < f->buffer) |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
127 |
ptr = f->end - (f->buffer - ptr); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
128 |
return ptr; |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
129 |
} |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
130 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
131 |
#if FF_API_AV_FIFO_PEEK |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
132 |
/** |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
133 |
* @deprecated Use av_fifo_peek2() instead. |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
134 |
*/ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
135 |
attribute_deprecated |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
136 |
static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs) |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
137 |
{ |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
138 |
return *av_fifo_peek2(f, offs); |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
139 |
} |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
140 |
#endif |
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
141 |
|
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
diff
changeset
|
142 |
#endif /* AVUTIL_FIFO_H */ |