Statistics
| Branch: | Revision:

ffmpeg / libavformat / avio.h @ 491653ed

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