Statistics
| Branch: | Revision:

ffmpeg / libavformat / avio.h @ bc371aca

History | View | Annotate | Download (23.1 KB)

1 04d7f601 Diego Biurrun
/*
2
 * copyright (c) 2001 Fabrice Bellard
3
 *
4 2912e87a Mans Rullgard
 * This file is part of Libav.
5 b78e7197 Diego Biurrun
 *
6 2912e87a Mans Rullgard
 * Libav is free software; you can redistribute it and/or
7 04d7f601 Diego Biurrun
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 04d7f601 Diego Biurrun
 *
11 2912e87a Mans Rullgard
 * Libav is distributed in the hope that it will be useful,
12 04d7f601 Diego Biurrun
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17 2912e87a Mans Rullgard
 * License along with Libav; if not, write to the Free Software
18 04d7f601 Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20 98790382 Stefano Sabatini
#ifndef AVFORMAT_AVIO_H
21
#define AVFORMAT_AVIO_H
22 f031df23 Fabrice Bellard
23 aafe9b63 Stefano Sabatini
/**
24 ba87f080 Diego Biurrun
 * @file
25 aafe9b63 Stefano Sabatini
 * unbuffered I/O operations
26 3f4c2bf9 Stefano Sabatini
 *
27
 * @warning This file has to be considered an internal but installed
28
 * header, so it should not be directly included in your projects.
29 aafe9b63 Stefano Sabatini
 */
30
31 99545457 Måns Rullgård
#include <stdint.h>
32
33 30f68128 Diego Biurrun
#include "libavutil/common.h"
34 ed8d5766 Martin Storsjö
#include "libavutil/log.h"
35 30f68128 Diego Biurrun
36 50196a98 Anton Khirnov
#include "libavformat/version.h"
37
38 de6d9b64 Fabrice Bellard
/* unbuffered I/O */
39
40 1308f273 Michael Niedermayer
/**
41
 * URL Context.
42
 * New fields can be added to the end with minor version bumps.
43 8bfb108b Diego Biurrun
 * Removal, reordering and changes to existing fields require a major
44 1308f273 Michael Niedermayer
 * version bump.
45 8bfb108b Diego Biurrun
 * sizeof(URLContext) must not be used outside libav*.
46 1308f273 Michael Niedermayer
 */
47 597b4b3f Stefano Sabatini
typedef struct URLContext {
48 404eba44 Aurelien Jacobs
#if FF_API_URL_CLASS
49 5acef35f Björn Axelsson
    const AVClass *av_class; ///< information for av_log(). Set by url_open().
50
#endif
51 de6d9b64 Fabrice Bellard
    struct URLProtocol *prot;
52 115329f1 Diego Biurrun
    int flags;
53 c3316802 Panagiotis Issaris
    int is_streamed;  /**< true if streamed (no seek possible), default = false */
54
    int max_packet_size;  /**< if non zero, the stream is packetized with this max packet size */
55 de6d9b64 Fabrice Bellard
    void *priv_data;
56 725b3da9 Stefano Sabatini
    char *filename; /**< specified URL */
57 ffbb289a Martin Storsjö
    int is_connected;
58 597b4b3f Stefano Sabatini
} URLContext;
59 de6d9b64 Fabrice Bellard
60 e2307053 Anton Khirnov
#if FF_API_OLD_AVIO
61 de6d9b64 Fabrice Bellard
typedef struct URLPollEntry {
62
    URLContext *handle;
63
    int events;
64
    int revents;
65
} URLPollEntry;
66 e2307053 Anton Khirnov
#endif
67 de6d9b64 Fabrice Bellard
68 fe174fc8 Nicolas George
/**
69
 * @defgroup open_modes URL open modes
70
 * The flags argument to url_open and cosins must be one of the following
71
 * constants, optionally ORed with other flags.
72
 * @{
73
 */
74
#define URL_RDONLY 0  /**< read-only */
75
#define URL_WRONLY 1  /**< write-only */
76
#define URL_RDWR   2  /**< read-write */
77
/**
78
 * @}
79
 */
80
81
/**
82
 * Use non-blocking mode.
83
 * If this flag is set, operations on the context will return
84
 * AVERROR(EAGAIN) if they can not be performed immediately.
85
 * If this flag is not set, operations on the context will never return
86
 * AVERROR(EAGAIN).
87
 * Note that this flag does not affect the opening/connecting of the
88
 * context. Connecting a protocol will always block if necessary (e.g. on
89
 * network protocols) but never hang (e.g. on busy devices).
90
 * Warning: non-blocking protocols is work-in-progress; this flag may be
91
 * silently ignored.
92
 */
93
#define URL_FLAG_NONBLOCK 4
94 f031df23 Fabrice Bellard
95 019ac05a Fabrice Bellard
typedef int URLInterruptCB(void);
96
97 333e8943 Anton Khirnov
#if FF_API_OLD_AVIO
98 333146dd Stefano Sabatini
/**
99 333e8943 Anton Khirnov
 * @defgroup old_url_funcs Old url_* functions
100
 * @deprecated use the buffered API based on AVIOContext instead
101
 * @{
102 333146dd Stefano Sabatini
 */
103 333e8943 Anton Khirnov
attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol *up,
104
                                            const char *url, int flags);
105 5652bb94 Anton Khirnov
attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags);
106 62eaaeac Anton Khirnov
attribute_deprecated int url_connect(URLContext *h);
107 0589da0a Anton Khirnov
attribute_deprecated int url_open(URLContext **h, const char *url, int flags);
108 bc371aca Anton Khirnov
attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size);
109 333e8943 Anton Khirnov
#endif
110 333146dd Stefano Sabatini
111 b0634fd1 Stefano Sabatini
/**
112 ddb901b7 Reimar Döffinger
 * Read as many bytes as possible (up to size), calling the
113
 * read function multiple times if necessary.
114
 * This makes special short-read handling in applications
115
 * unnecessary, if the return value is < size then it is
116
 * certain there was either an error or the end of file was reached.
117
 */
118 0e848977 Kostya Shishkov
int url_read_complete(URLContext *h, unsigned char *buf, int size);
119 267ff3ae Stefano Sabatini
120
/**
121
 * Write size bytes from buf to the resource accessed by h.
122
 *
123
 * @return the number of bytes actually written, or a negative value
124
 * corresponding to an AVERROR code in case of failure
125
 */
126 27241cbf Martin Storsjö
int url_write(URLContext *h, const unsigned char *buf, int size);
127 9bee2459 Stefano Sabatini
128
/**
129 85c15960 Stefano Sabatini
 * Passing this as the "whence" parameter to a seek function causes it to
130
 * return the filesize without seeking anywhere. Supporting this is optional.
131
 * If it is not supported then the seek function will return <0.
132
 */
133
#define AVSEEK_SIZE 0x10000
134
135
/**
136 49bd8e4b Måns Rullgård
 * Change the position that will be used by the next read/write
137 9bee2459 Stefano Sabatini
 * operation on the resource accessed by h.
138
 *
139
 * @param pos specifies the new position to set
140
 * @param whence specifies how pos should be interpreted, it must be
141
 * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
142
 * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
143
 * (return the filesize of the requested resource, pos is ignored).
144
 * @return a negative value corresponding to an AVERROR code in case
145
 * of failure, or the resulting file position, measured in bytes from
146
 * the beginning of the file. You can use this feature together with
147
 * SEEK_CUR to read the current file position.
148
 */
149 bc5c918e Diego Biurrun
int64_t url_seek(URLContext *h, int64_t pos, int whence);
150 f1f78a9d Stefano Sabatini
151
/**
152 49bd8e4b Måns Rullgård
 * Close the resource accessed by the URLContext h, and free the
153 f1f78a9d Stefano Sabatini
 * memory used by it.
154
 *
155
 * @return a negative value if an error condition occurred, 0
156
 * otherwise
157
 */
158 de6d9b64 Fabrice Bellard
int url_close(URLContext *h);
159 f1f78a9d Stefano Sabatini
160 8a36b59b Stefano Sabatini
/**
161 49bd8e4b Måns Rullgård
 * Return a non-zero value if the resource indicated by url
162 8a36b59b Stefano Sabatini
 * exists, 0 otherwise.
163
 */
164 725b3da9 Stefano Sabatini
int url_exist(const char *url);
165 8a36b59b Stefano Sabatini
166 f3f5eb6e Stefano Sabatini
/**
167
 * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
168
 * if the operation is not supported by h, or another negative value
169
 * corresponding to an AVERROR error code in case of failure.
170
 */
171 bc5c918e Diego Biurrun
int64_t url_filesize(URLContext *h);
172 c306748c Panagiotis Issaris
173 c3316802 Panagiotis Issaris
/**
174 f0a80394 Ronald S. Bultje
 * Return the file descriptor associated with this URL. For RTP, this
175
 * will return only the RTP file descriptor, not the RTCP file descriptor.
176
 *
177
 * @return the file descriptor associated with this URL, or <0 on error.
178
 */
179
int url_get_file_handle(URLContext *h);
180
181
/**
182 c306748c Panagiotis Issaris
 * Return the maximum packet size associated to packetized file
183 8bfb108b Diego Biurrun
 * handle. If the file is not packetized (stream like HTTP or file on
184 c306748c Panagiotis Issaris
 * disk), then 0 is returned.
185
 *
186
 * @param h file handle
187
 * @return maximum packet size in bytes
188
 */
189 f031df23 Fabrice Bellard
int url_get_max_packet_size(URLContext *h);
190 8bf256bc Stefano Sabatini
191
/**
192
 * Copy the filename of the resource accessed by h to buf.
193
 *
194
 * @param buf_size size in bytes of buf
195
 */
196 f746a046 Fabrice Bellard
void url_get_filename(URLContext *h, char *buf, int buf_size);
197
198 c3316802 Panagiotis Issaris
/**
199 8bfb108b Diego Biurrun
 * The callback is called in blocking functions to test regulary if
200 c76374c6 Nicolas George
 * asynchronous interruption is needed. AVERROR_EXIT is returned
201 c3316802 Panagiotis Issaris
 * in this case by the interrupted function. 'NULL' means no interrupt
202 8bfb108b Diego Biurrun
 * callback is given.
203 c3316802 Panagiotis Issaris
 */
204 019ac05a Fabrice Bellard
void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
205
206 e2307053 Anton Khirnov
#if FF_API_OLD_AVIO
207 de6d9b64 Fabrice Bellard
/* not implemented */
208 e2307053 Anton Khirnov
attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout);
209
#endif
210 de6d9b64 Fabrice Bellard
211 502bdf68 Michael Niedermayer
/**
212
 * Pause and resume playing - only meaningful if using a network streaming
213
 * protocol (e.g. MMS).
214
 * @param pause 1 for pause, 0 for resume
215
 */
216
int av_url_read_pause(URLContext *h, int pause);
217 8bfb108b Diego Biurrun
218 536333a0 Björn Axelsson
/**
219
 * Seek to a given timestamp relative to some component stream.
220 8bfb108b Diego Biurrun
 * Only meaningful if using a network streaming protocol (e.g. MMS.).
221 536333a0 Björn Axelsson
 * @param stream_index The stream index that the timestamp is relative to.
222
 *        If stream_index is (-1) the timestamp should be in AV_TIME_BASE
223
 *        units from the beginning of the presentation.
224
 *        If a stream_index >= 0 is used and the protocol does not support
225
 *        seeking based on component streams, the call will fail with ENOTSUP.
226 00ef4f58 Diego Biurrun
 * @param timestamp timestamp in AVStream.time_base units
227 536333a0 Björn Axelsson
 *        or if there is no stream specified then in AV_TIME_BASE units.
228
 * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
229
 *        and AVSEEK_FLAG_ANY. The protocol may silently ignore
230
 *        AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
231
 *        fail with ENOTSUP if used and not supported.
232
 * @return >= 0 on success
233
 * @see AVInputFormat::read_seek
234
 */
235 7f37f568 Diego Biurrun
int64_t av_url_read_seek(URLContext *h, int stream_index,
236
                         int64_t timestamp, int flags);
237 536333a0 Björn Axelsson
238 aa38b097 Michael Niedermayer
/**
239 493f54ad Michael Niedermayer
 * Oring this flag as into the "whence" parameter to a seek function causes it to
240
 * seek by any means (like reopening and linear reading) or other normally unreasonble
241
 * means that can be extreemly slow.
242
 * This may be ignored by the seek code.
243
 */
244
#define AVSEEK_FORCE 0x20000
245
246 8f73c060 Martin Storsjö
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
247
248 de6d9b64 Fabrice Bellard
typedef struct URLProtocol {
249
    const char *name;
250 725b3da9 Stefano Sabatini
    int (*url_open)(URLContext *h, const char *url, int flags);
251 de6d9b64 Fabrice Bellard
    int (*url_read)(URLContext *h, unsigned char *buf, int size);
252 27241cbf Martin Storsjö
    int (*url_write)(URLContext *h, const unsigned char *buf, int size);
253 bc5c918e Diego Biurrun
    int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
254 de6d9b64 Fabrice Bellard
    int (*url_close)(URLContext *h);
255
    struct URLProtocol *next;
256 502bdf68 Michael Niedermayer
    int (*url_read_pause)(URLContext *h, int pause);
257 7f37f568 Diego Biurrun
    int64_t (*url_read_seek)(URLContext *h, int stream_index,
258
                             int64_t timestamp, int flags);
259 f0a80394 Ronald S. Bultje
    int (*url_get_file_handle)(URLContext *h);
260 735cf6b2 Martin Storsjö
    int priv_data_size;
261
    const AVClass *priv_data_class;
262 f3bea991 Martin Storsjö
    int flags;
263 de6d9b64 Fabrice Bellard
} URLProtocol;
264
265 838b27b4 Aurelien Jacobs
#if FF_API_REGISTER_PROTOCOL
266 de6d9b64 Fabrice Bellard
extern URLProtocol *first_protocol;
267 d1037c12 Stefano Sabatini
#endif
268
269 019ac05a Fabrice Bellard
extern URLInterruptCB *url_interrupt_cb;
270 de6d9b64 Fabrice Bellard
271 9075d1e0 Stefano Sabatini
/**
272
 * If protocol is NULL, returns the first registered protocol,
273 c1b02101 Stefano Sabatini
 * if protocol is non-NULL, returns the next registered protocol after protocol,
274 9075d1e0 Stefano Sabatini
 * or NULL if protocol is the last one.
275
 */
276 84be6e72 Michael Niedermayer
URLProtocol *av_protocol_next(URLProtocol *p);
277
278 838b27b4 Aurelien Jacobs
#if FF_API_REGISTER_PROTOCOL
279 65c40e4e Stefano Sabatini
/**
280
 * @deprecated Use av_register_protocol() instead.
281
 */
282
attribute_deprecated int register_protocol(URLProtocol *protocol);
283 9b07a2dc Martin Storsjö
284
/**
285
 * @deprecated Use av_register_protocol2() instead.
286
 */
287
attribute_deprecated int av_register_protocol(URLProtocol *protocol);
288 65c40e4e Stefano Sabatini
#endif
289
290 d19a046e Stefano Sabatini
/**
291 49bd8e4b Måns Rullgård
 * Register the URLProtocol protocol.
292 9b07a2dc Martin Storsjö
 *
293
 * @param size the size of the URLProtocol struct referenced
294 d19a046e Stefano Sabatini
 */
295 9b07a2dc Martin Storsjö
int av_register_protocol2(URLProtocol *protocol, int size);
296 de6d9b64 Fabrice Bellard
297 8978feda Anton Khirnov
#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
298
299 1308f273 Michael Niedermayer
/**
300 333e8943 Anton Khirnov
 * @}
301
 */
302
303
/**
304 1308f273 Michael Niedermayer
 * Bytestream IO Context.
305
 * New fields can be added to the end with minor version bumps.
306 8bfb108b Diego Biurrun
 * Removal, reordering and changes to existing fields require a major
307 1308f273 Michael Niedermayer
 * version bump.
308 ae628ec1 Anton Khirnov
 * sizeof(AVIOContext) must not be used outside libav*.
309 1308f273 Michael Niedermayer
 */
310 de6d9b64 Fabrice Bellard
typedef struct {
311
    unsigned char *buffer;
312
    int buffer_size;
313
    unsigned char *buf_ptr, *buf_end;
314
    void *opaque;
315 0c1a9eda Zdenek Kabelac
    int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
316 576ae256 Michael Niedermayer
    int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
317 bc5c918e Diego Biurrun
    int64_t (*seek)(void *opaque, int64_t offset, int whence);
318
    int64_t pos; /**< position in the file of the current buffer */
319 c3316802 Panagiotis Issaris
    int must_flush; /**< true if the next seek should flush */
320
    int eof_reached; /**< true if eof reached */
321
    int write_flag;  /**< true if open for writing */
322 8978feda Anton Khirnov
#if FF_API_OLD_AVIO
323
    attribute_deprecated int is_streamed;
324
#endif
325 f031df23 Fabrice Bellard
    int max_packet_size;
326 ee9f36a8 Michael Niedermayer
    unsigned long checksum;
327
    unsigned char *checksum_ptr;
328
    unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
329 576ae256 Michael Niedermayer
    int error;         ///< contains the error code or 0 if no error happened
330 502bdf68 Michael Niedermayer
    int (*read_pause)(void *opaque, int pause);
331 7f37f568 Diego Biurrun
    int64_t (*read_seek)(void *opaque, int stream_index,
332
                         int64_t timestamp, int flags);
333 8978feda Anton Khirnov
    /**
334
     * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
335
     */
336
    int seekable;
337 ae628ec1 Anton Khirnov
} AVIOContext;
338 de6d9b64 Fabrice Bellard
339 ae628ec1 Anton Khirnov
#if FF_API_OLD_AVIO
340
typedef attribute_deprecated AVIOContext ByteIOContext;
341
342 e731b8d8 Anton Khirnov
attribute_deprecated int init_put_byte(AVIOContext *s,
343 de6d9b64 Fabrice Bellard
                  unsigned char *buffer,
344
                  int buffer_size,
345
                  int write_flag,
346
                  void *opaque,
347 1e0f3468 Reimar Döffinger
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
348
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
349 bc5c918e Diego Biurrun
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
350 8d9ac969 Anton Khirnov
attribute_deprecated AVIOContext *av_alloc_put_byte(
351
                  unsigned char *buffer,
352
                  int buffer_size,
353
                  int write_flag,
354
                  void *opaque,
355
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
356
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
357
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
358 b7effd4e Anton Khirnov
359
/**
360
 * @defgroup old_avio_funcs Old put_/get_*() functions
361
 * @deprecated use the avio_ -prefixed functions instead.
362
 * @{
363
 */
364
attribute_deprecated int          get_buffer(AVIOContext *s, unsigned char *buf, int size);
365 b3db9cee Anton Khirnov
attribute_deprecated int          get_partial_buffer(AVIOContext *s, unsigned char *buf, int size);
366 b7effd4e Anton Khirnov
attribute_deprecated int          get_byte(AVIOContext *s);
367
attribute_deprecated unsigned int get_le16(AVIOContext *s);
368
attribute_deprecated unsigned int get_le24(AVIOContext *s);
369
attribute_deprecated unsigned int get_le32(AVIOContext *s);
370
attribute_deprecated uint64_t     get_le64(AVIOContext *s);
371
attribute_deprecated unsigned int get_be16(AVIOContext *s);
372
attribute_deprecated unsigned int get_be24(AVIOContext *s);
373
attribute_deprecated unsigned int get_be32(AVIOContext *s);
374
attribute_deprecated uint64_t     get_be64(AVIOContext *s);
375 77eb5504 Anton Khirnov
376
attribute_deprecated void         put_byte(AVIOContext *s, int b);
377 0ac8e2bf Anton Khirnov
attribute_deprecated void         put_nbyte(AVIOContext *s, int b, int count);
378 77eb5504 Anton Khirnov
attribute_deprecated void         put_buffer(AVIOContext *s, const unsigned char *buf, int size);
379
attribute_deprecated void         put_le64(AVIOContext *s, uint64_t val);
380
attribute_deprecated void         put_be64(AVIOContext *s, uint64_t val);
381
attribute_deprecated void         put_le32(AVIOContext *s, unsigned int val);
382
attribute_deprecated void         put_be32(AVIOContext *s, unsigned int val);
383
attribute_deprecated void         put_le24(AVIOContext *s, unsigned int val);
384
attribute_deprecated void         put_be24(AVIOContext *s, unsigned int val);
385
attribute_deprecated void         put_le16(AVIOContext *s, unsigned int val);
386
attribute_deprecated void         put_be16(AVIOContext *s, unsigned int val);
387 61840b43 Anton Khirnov
attribute_deprecated void         put_tag(AVIOContext *s, const char *tag);
388 b7effd4e Anton Khirnov
/**
389
 * @}
390
 */
391 22a3212e Anton Khirnov
392 933e90a6 Anton Khirnov
attribute_deprecated int     av_url_read_fpause(AVIOContext *h,    int pause);
393 491653ed Anton Khirnov
attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h,    int stream_index,
394 933e90a6 Anton Khirnov
                                                int64_t timestamp, int flags);
395 22a3212e Anton Khirnov
396
/**
397
 * @defgroup old_url_f_funcs Old url_f* functions
398
 * @deprecated use the avio_ -prefixed functions instead.
399
 * @{
400
 */
401
attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
402
attribute_deprecated int url_fclose(AVIOContext *s);
403 6b4aa5da Anton Khirnov
attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
404 0300db8a Anton Khirnov
attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
405 a2704c97 Anton Khirnov
attribute_deprecated int64_t url_ftell(AVIOContext *s);
406 76aa876e Anton Khirnov
attribute_deprecated int64_t url_fsize(AVIOContext *s);
407 e5197539 Anton Khirnov
#define URL_EOF (-1)
408
attribute_deprecated int url_fgetc(AVIOContext *s);
409 59f65d95 Anton Khirnov
attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
410 d9d86e00 Anton Khirnov
#ifdef __GNUC__
411
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
412
#else
413
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
414
#endif
415 b7f2fdde Anton Khirnov
attribute_deprecated void put_flush_packet(AVIOContext *s);
416 b92c5452 Anton Khirnov
attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
417 403ee835 Anton Khirnov
attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
418 6dc7d80d Anton Khirnov
attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
419 724f6a0f Anton Khirnov
attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h);
420 22a3212e Anton Khirnov
/**
421
 * @}
422
 */
423 66e5b1df Anton Khirnov
424
/**
425
 * @deprecated use AVIOContext.eof_reached
426
 */
427
attribute_deprecated int url_feof(AVIOContext *s);
428 3e68b3ba Anton Khirnov
attribute_deprecated int url_ferror(AVIOContext *s);
429 4ec153bb Anton Khirnov
430
attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri);
431
attribute_deprecated int udp_get_local_port(URLContext *h);
432 4c4427a7 Anton Khirnov
433
attribute_deprecated void init_checksum(AVIOContext *s,
434
                   unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
435
                   unsigned long checksum);
436 b64030f2 Anton Khirnov
attribute_deprecated unsigned long get_checksum(AVIOContext *s);
437 e731b8d8 Anton Khirnov
#endif
438 8d9ac969 Anton Khirnov
439 3c96c648 Anton Khirnov
/**
440
 * Allocate and initialize an AVIOContext for buffered I/O. It must be later
441
 * freed with av_free().
442
 *
443
 * @param buffer Memory block for input/output operations via AVIOContext.
444
 * @param buffer_size The buffer size is very important for performance.
445
 *        For protocols with fixed blocksize it should be set to this blocksize.
446
 *        For others a typical size is a cache page, e.g. 4kb.
447
 * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
448
 * @param opaque An opaque pointer to user-specific data.
449
 * @param read_packet  A function for refilling the buffer, may be NULL.
450
 * @param write_packet A function for writing the buffer contents, may be NULL.
451
 * @param seek A function for seeking to specified byte position, may be NULL.
452
 *
453
 * @return Allocated AVIOContext or NULL on failure.
454
 */
455 8d9ac969 Anton Khirnov
AVIOContext *avio_alloc_context(
456 1e0f3468 Reimar Döffinger
                  unsigned char *buffer,
457
                  int buffer_size,
458
                  int write_flag,
459
                  void *opaque,
460 0c1a9eda Zdenek Kabelac
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
461 576ae256 Michael Niedermayer
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
462 bc5c918e Diego Biurrun
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
463 de6d9b64 Fabrice Bellard
464 77eb5504 Anton Khirnov
void avio_w8(AVIOContext *s, int b);
465
void avio_write(AVIOContext *s, const unsigned char *buf, int size);
466
void avio_wl64(AVIOContext *s, uint64_t val);
467
void avio_wb64(AVIOContext *s, uint64_t val);
468
void avio_wl32(AVIOContext *s, unsigned int val);
469
void avio_wb32(AVIOContext *s, unsigned int val);
470
void avio_wl24(AVIOContext *s, unsigned int val);
471
void avio_wb24(AVIOContext *s, unsigned int val);
472
void avio_wl16(AVIOContext *s, unsigned int val);
473
void avio_wb16(AVIOContext *s, unsigned int val);
474 de6d9b64 Fabrice Bellard
475 4efd5cf3 Anton Khirnov
#if FF_API_OLD_AVIO
476 ae628ec1 Anton Khirnov
attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
477 4efd5cf3 Anton Khirnov
#endif
478
479
/**
480
 * Write a NULL-terminated string.
481
 * @return number of bytes written.
482
 */
483 ae628ec1 Anton Khirnov
int avio_put_str(AVIOContext *s, const char *str);
484 75bdb984 Philip Gladstone
485 67e21020 Michael Niedermayer
/**
486 dccbd97d Anton Khirnov
 * Convert an UTF-8 string to UTF-16LE and write it.
487
 * @return number of bytes written.
488
 */
489 ae628ec1 Anton Khirnov
int avio_put_str16le(AVIOContext *s, const char *str);
490 dccbd97d Anton Khirnov
491
/**
492 ae628ec1 Anton Khirnov
 * fseek() equivalent for AVIOContext.
493 67e21020 Michael Niedermayer
 * @return new position or AVERROR.
494
 */
495 6b4aa5da Anton Khirnov
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
496 67e21020 Michael Niedermayer
497
/**
498 2af07d36 Peter Ross
 * Skip given number of bytes forward
499
 * @return new position or AVERROR.
500
 */
501 af020732 Anton Khirnov
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
502
{
503
    return avio_seek(s, offset, SEEK_CUR);
504
}
505 2af07d36 Peter Ross
506
/**
507 ae628ec1 Anton Khirnov
 * ftell() equivalent for AVIOContext.
508 67e21020 Michael Niedermayer
 * @return position or AVERROR.
509
 */
510 af020732 Anton Khirnov
static av_always_inline int64_t avio_tell(AVIOContext *s)
511
{
512
    return avio_seek(s, 0, SEEK_CUR);
513
}
514 67e21020 Michael Niedermayer
515
/**
516 49bd8e4b Måns Rullgård
 * Get the filesize.
517 67e21020 Michael Niedermayer
 * @return filesize or AVERROR
518
 */
519 76aa876e Anton Khirnov
int64_t avio_size(AVIOContext *s);
520 67e21020 Michael Niedermayer
521 c3316802 Panagiotis Issaris
/** @warning currently size is limited */
522 572f992e Michael Niedermayer
#ifdef __GNUC__
523 d9d86e00 Anton Khirnov
int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
524 572f992e Michael Niedermayer
#else
525 d9d86e00 Anton Khirnov
int avio_printf(AVIOContext *s, const char *fmt, ...);
526 572f992e Michael Niedermayer
#endif
527 a8c5ab27 Panagiotis Issaris
528 655e45e7 Anton Khirnov
#if FF_API_OLD_AVIO
529 c3316802 Panagiotis Issaris
/** @note unlike fgets, the EOL character is not returned and a whole
530 7f37f568 Diego Biurrun
    line is parsed. return NULL if first char read was EOF */
531 655e45e7 Anton Khirnov
attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
532
#endif
533 f031df23 Fabrice Bellard
534 b7f2fdde Anton Khirnov
void avio_flush(AVIOContext *s);
535 de6d9b64 Fabrice Bellard
536 4edfcecc Michael Niedermayer
537
/**
538 ae628ec1 Anton Khirnov
 * Read size bytes from AVIOContext into buf.
539 32e543f8 Benoit Fouet
 * @return number of bytes read or AVERROR
540 4edfcecc Michael Niedermayer
 */
541 b7effd4e Anton Khirnov
int avio_read(AVIOContext *s, unsigned char *buf, int size);
542 4edfcecc Michael Niedermayer
543 c3316802 Panagiotis Issaris
/** @note return 0 if EOF, so you cannot use it if EOF handling is
544 7f37f568 Diego Biurrun
    necessary */
545 b7effd4e Anton Khirnov
int          avio_r8  (AVIOContext *s);
546
unsigned int avio_rl16(AVIOContext *s);
547
unsigned int avio_rl24(AVIOContext *s);
548
unsigned int avio_rl32(AVIOContext *s);
549
uint64_t     avio_rl64(AVIOContext *s);
550 de6d9b64 Fabrice Bellard
551 93b78d12 Anton Khirnov
/**
552 41d8555f Reimar Döffinger
 * Read a string from pb into buf. The reading will terminate when either
553
 * a NULL character was encountered, maxlen bytes have been read, or nothing
554
 * more can be read from pb. The result is guaranteed to be NULL-terminated, it
555
 * will be truncated if buf is too small.
556
 * Note that the string is not interpreted or validated in any way, it
557
 * might get truncated in the middle of a sequence for multi-byte encodings.
558
 *
559
 * @return number of bytes read (is always <= maxlen).
560
 * If reading ends on EOF or error, the return value will be one more than
561
 * bytes actually read.
562
 */
563
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
564
565
/**
566 93b78d12 Anton Khirnov
 * Read a UTF-16 string from pb and convert it to UTF-8.
567
 * The reading will terminate when either a null or invalid character was
568
 * encountered or maxlen bytes have been read.
569
 * @return number of bytes read (is always <= maxlen)
570
 */
571 ae628ec1 Anton Khirnov
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
572
int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
573 93b78d12 Anton Khirnov
574 e16ead07 Anton Khirnov
#if FF_API_OLD_AVIO
575
/**
576
 * @deprecated use avio_get_str instead
577
 */
578
attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
579
#endif
580 b7effd4e Anton Khirnov
unsigned int avio_rb16(AVIOContext *s);
581
unsigned int avio_rb24(AVIOContext *s);
582
unsigned int avio_rb32(AVIOContext *s);
583
uint64_t     avio_rb64(AVIOContext *s);
584 de6d9b64 Fabrice Bellard
585 8978feda Anton Khirnov
#if FF_API_OLD_AVIO
586
/**
587
 * @deprecated Use AVIOContext.seekable field directly.
588
 */
589
attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
590 de6d9b64 Fabrice Bellard
{
591 8978feda Anton Khirnov
    return !s->seekable;
592 de6d9b64 Fabrice Bellard
}
593 8978feda Anton Khirnov
#endif
594 de6d9b64 Fabrice Bellard
595 364cacc7 Aurelien Jacobs
#if FF_API_URL_RESETBUF
596 770d9daf Björn Axelsson
/** Reset the buffer for reading or writing.
597
 * @note Will drop any data currently in the buffer without transmitting it.
598
 * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY
599
 *        to set up the buffer for writing. */
600 ae628ec1 Anton Khirnov
int url_resetbuf(AVIOContext *s, int flags);
601 08580cb0 Benoit Fouet
#endif
602 a8c5ab27 Panagiotis Issaris
603 fe4fbb58 Stefano Sabatini
/**
604 ae628ec1 Anton Khirnov
 * Create and initialize a AVIOContext for accessing the
605 fe4fbb58 Stefano Sabatini
 * resource indicated by url.
606
 * @note When the resource indicated by url has been opened in
607 ae628ec1 Anton Khirnov
 * read+write mode, the AVIOContext can be used only for writing.
608 fe4fbb58 Stefano Sabatini
 *
609 ae628ec1 Anton Khirnov
 * @param s Used to return the pointer to the created AVIOContext.
610 fe4fbb58 Stefano Sabatini
 * In case of failure the pointed to value is set to NULL.
611
 * @param flags flags which control how the resource indicated by url
612
 * is to be opened
613
 * @return 0 in case of success, a negative value corresponding to an
614
 * AVERROR code in case of failure
615
 */
616 22a3212e Anton Khirnov
int avio_open(AVIOContext **s, const char *url, int flags);
617 fe4fbb58 Stefano Sabatini
618 22a3212e Anton Khirnov
int avio_close(AVIOContext *s);
619 a8c5ab27 Panagiotis Issaris
620 e8bb2e24 Anton Khirnov
#if FF_API_OLD_AVIO
621 8d9769a7 Anton Khirnov
attribute_deprecated URLContext *url_fileno(AVIOContext *s);
622
623 c3316802 Panagiotis Issaris
/**
624 e8bb2e24 Anton Khirnov
 * @deprecated use AVIOContext.max_packet_size directly.
625 a8c5ab27 Panagiotis Issaris
 */
626 e8bb2e24 Anton Khirnov
attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
627 de6d9b64 Fabrice Bellard
628 83fddaeb Anton Khirnov
attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
629 a8c5ab27 Panagiotis Issaris
630 c3316802 Panagiotis Issaris
/** return the written or read size */
631 35f10235 Anton Khirnov
attribute_deprecated int url_close_buf(AVIOContext *s);
632
#endif
633 de6d9b64 Fabrice Bellard
634 c3316802 Panagiotis Issaris
/**
635 a8c5ab27 Panagiotis Issaris
 * Open a write only memory stream.
636
 *
637
 * @param s new IO context
638
 * @return zero if no error.
639
 */
640 b92c5452 Anton Khirnov
int avio_open_dyn_buf(AVIOContext **s);
641 a8c5ab27 Panagiotis Issaris
642 c3316802 Panagiotis Issaris
/**
643 a8c5ab27 Panagiotis Issaris
 * Return the written size and a pointer to the buffer. The buffer
644 403ee835 Anton Khirnov
 * must be freed with av_free().
645
 * Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer.
646 de1807bb Josh Allmann
 *
647 a8c5ab27 Panagiotis Issaris
 * @param s IO context
648 e8b7c70f Panagiotis Issaris
 * @param pbuffer pointer to a byte buffer
649 a8c5ab27 Panagiotis Issaris
 * @return the length of the byte buffer
650
 */
651 6dc7d80d Anton Khirnov
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
652 f031df23 Fabrice Bellard
653 8ef30ac1 Aurelien Jacobs
#if FF_API_UDP_GET_FILE
654 f031df23 Fabrice Bellard
int udp_get_file_handle(URLContext *h);
655 f0a80394 Ronald S. Bultje
#endif
656 f031df23 Fabrice Bellard
657 98790382 Stefano Sabatini
#endif /* AVFORMAT_AVIO_H */