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 #ifndef AVFORMAT_AVIO_INTERNAL_H
20 #define AVFORMAT_AVIO_INTERNAL_H
21
23
25
27
30 /**
31 * A callback that is used instead of short_seek_threshold.
32 */
34
35 /**
36 * Threshold to favor readahead over seek.
37 */
39
42
43 /**
44 * max filesize, used to limit allocations
45 */
47
48 /**
49 * Bytes read statistic
50 */
52
53 /**
54 * Bytes written statistic
55 */
57
58 /**
59 * seek statistic
60 */
62
63 /**
64 * writeout statistic
65 */
67
68 /**
69 * Original buffer size
70 * used after probing to ensure seekback and to reset the buffer size
71 */
73
74 /**
75 * Written output size
76 * is updated each time a successful writeout ends up further position-wise
77 */
80
82 {
84 }
85
88 int buffer_size,
89 int write_flag,
90 void *opaque,
91 int (*
read_packet)(
void *opaque, uint8_t *buf,
int buf_size),
92 int (*
write_packet)(
void *opaque,
const uint8_t *buf,
int buf_size),
94
95 /**
96 * Wrap a buffer in an AVIOContext for reading.
97 */
99
100 /**
101 * Wrap a buffer in an AVIOContext for writing.
102 */
104
105 /**
106 * Read size bytes from AVIOContext, returning a pointer.
107 * Note that the data pointed at by the returned pointer is only
108 * valid until the next call that references the same IO context.
109 * @param s IO context
110 * @param buf pointer to buffer into which to assemble the requested
111 * data if it is not available in contiguous addresses in the
112 * underlying buffer
113 * @param size number of bytes requested
114 * @param data address at which to store pointer: this will be a
115 * a direct pointer into the underlying buffer if the requested
116 * number of bytes are available at contiguous addresses, otherwise
117 * will be a copy of buf
118 * @return number of bytes read or AVERROR
119 */
121
123
125 {
127 }
128
129 /**
130 * Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file.
131 * Used after probing to avoid seeking.
132 * Joins buf and s->buffer, taking any overlap into consideration.
133 * @note s->buffer must overlap with buf or they can't be joined and the function fails
134 *
135 * @param s The read-only AVIOContext to rewind
136 * @param buf The probe buffer containing the first buf_size bytes of the file
137 * @param buf_size The size of buf
138 * @return >= 0 in case of success, a negative value corresponding to an
139 * AVERROR code in case of failure
140 */
142
144
145 /**
146 * Read a unsigned integer coded as a variable number of up to eight
147 * little-endian bytes, where the MSB in a byte signals another byte
148 * must be read.
149 * All coded bytes are read, but values > UINT_MAX are truncated.
150 */
152
154
155 /**
156 * Write a sequence of text lines, converting line endings.
157 * All input line endings (LF, CRLF, CR) are converted to the configured line ending.
158 * @param s The AVIOContext to write to
159 * @param buf The buffer to write
160 * @param size The size of the buffer, or <0 to use the full length of a null-terminated string
161 * @param ending The line ending sequence to convert to, or NULL for \n
162 */
164 const unsigned char *ending);
165
166 /**
167 * Read size bytes from AVIOContext into buf.
168 * Check that exactly size bytes have been read.
169 * @return number of bytes read or AVERROR
170 */
172
173 /**
174 * Reallocate a given buffer for AVIOContext.
175 *
176 * @param s the AVIOContext to realloc.
177 * @param buf_size required new buffer size.
178 * @return 0 on success, a negative AVERROR on failure.
179 */
181
182 /**
183 * Ensures that the requested seekback buffer size will be available
184 *
185 * Will ensure that when reading sequentially up to buf_size, seeking
186 * within the current pos and pos+buf_size is possible.
187 * Once the stream position moves outside this window or another
188 * ffio_ensure_seekback call requests a buffer outside this window this
189 * guarantee is lost.
190 */
192
194
197 unsigned long checksum);
205
206 /**
207 * Open a write only packetized memory stream with a maximum packet
208 * size of 'max_packet_size'. The stream is stored in a memory buffer
209 * with a big-endian 4 byte header giving the packet size in bytes.
210 *
211 * @param s new IO context
212 * @param max_packet_size maximum packet size (must be > 0)
213 * @return zero if no error.
214 */
216
217 /**
218 * Return the URLContext associated with the AVIOContext
219 *
220 * @param s IO context
221 * @return pointer to URLContext or NULL.
222 */
224
225 /**
226 * Create and initialize a AVIOContext for accessing the
227 * resource referenced by the URLContext h.
228 * @note When the URLContext h has been opened in read+write mode, the
229 * AVIOContext can be used only for writing.
230 *
231 * @param s Used to return the pointer to the created AVIOContext.
232 * In case of failure the pointed to value is set to NULL.
233 * @return >= 0 in case of success, a negative value corresponding to an
234 * AVERROR code in case of failure
235 */
237
238
239 /**
240 * Read url related dictionary options from the AVIOContext and write to the given dictionary
241 */
243
244 /**
245 * Open a write-only fake memory stream. The written data is not stored
246 * anywhere - this is only used for measuring the amount of data
247 * written.
248 *
249 * @param s new IO context
250 * @return zero if no error.
251 */
253
256 const char *whitelist, const char *blacklist);
257
258 /**
259 * Close a null buffer.
260 *
261 * @param s an IO context opened by ffio_open_null_buf
262 * @return the number of bytes written to the null buffer
263 */
265
266 /**
267 * Reset a dynamic buffer.
268 *
269 * Resets everything, but keeps the allocated buffer for later use.
270 */
272
273 /**
274 * Free a dynamic buffer.
275 *
276 * @param s a pointer to an IO context opened by avio_open_dyn_buf()
277 */
279
280 struct AVBPrint;
281 /**
282 * Read a whole line of text from AVIOContext to an AVBPrint buffer overwriting
283 * its contents. Stop reading after reaching a \\r, a \\n, a \\r\\n, a \0円 or
284 * EOF. The line ending characters are NOT included in the buffer, but they
285 * are skipped on the input.
286 *
287 * @param s the read-only AVIOContext
288 * @param bp the AVBPrint buffer
289 * @return the length of the read line not including the line endings,
290 * negative on error, or if the buffer becomes truncated.
291 */
293
294 /**
295 * Read a whole null-terminated string of text from AVIOContext to an AVBPrint
296 * buffer overwriting its contents. Stop reading after reaching the maximum
297 * length, a \0円 or EOF.
298 *
299 * @param s the read-only AVIOContext
300 * @param bp the AVBPrint buffer
301 * @param max_len the maximum length to be read from the AVIOContext.
302 * Negative (< 0) values signal that there is no known maximum
303 * length applicable. A maximum length of zero means that the
304 * AVIOContext is not touched, and the function returns
305 * with a read length of zero. In all cases the AVBprint
306 * is cleared.
307 * @return the length of the read string not including the terminating null,
308 * negative on error, or if the buffer becomes truncated.
309 */
312
313 #endif /* AVFORMAT_AVIO_INTERNAL_H */