Statistics
| Branch: | Revision:

ffmpeg / libavformat / avio.h @ 727c7aa0

History | View | Annotate | Download (21.2 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 dce37564 Anton Khirnov
attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size);
110 925e908b Anton Khirnov
attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size);
111 58a48c65 Anton Khirnov
attribute_deprecated int64_t url_seek(URLContext *h, int64_t pos, int whence);
112 e52a9145 Anton Khirnov
attribute_deprecated int url_close(URLContext *h);
113 32a97d46 Anton Khirnov
attribute_deprecated int64_t url_filesize(URLContext *h);
114 1869ea03 Anton Khirnov
attribute_deprecated int url_get_file_handle(URLContext *h);
115 5958df34 Anton Khirnov
attribute_deprecated int url_get_max_packet_size(URLContext *h);
116 727c7aa0 Anton Khirnov
attribute_deprecated void url_get_filename(URLContext *h, char *buf, int buf_size);
117 333e8943 Anton Khirnov
#endif
118 333146dd Stefano Sabatini
119 b0634fd1 Stefano Sabatini
/**
120 49bd8e4b Måns Rullgård
 * Return a non-zero value if the resource indicated by url
121 8a36b59b Stefano Sabatini
 * exists, 0 otherwise.
122
 */
123 725b3da9 Stefano Sabatini
int url_exist(const char *url);
124 8a36b59b Stefano Sabatini
125 f3f5eb6e Stefano Sabatini
/**
126 8bfb108b Diego Biurrun
 * The callback is called in blocking functions to test regulary if
127 c76374c6 Nicolas George
 * asynchronous interruption is needed. AVERROR_EXIT is returned
128 c3316802 Panagiotis Issaris
 * in this case by the interrupted function. 'NULL' means no interrupt
129 8bfb108b Diego Biurrun
 * callback is given.
130 c3316802 Panagiotis Issaris
 */
131 019ac05a Fabrice Bellard
void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
132
133 e2307053 Anton Khirnov
#if FF_API_OLD_AVIO
134 de6d9b64 Fabrice Bellard
/* not implemented */
135 e2307053 Anton Khirnov
attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout);
136
#endif
137 de6d9b64 Fabrice Bellard
138 502bdf68 Michael Niedermayer
/**
139
 * Pause and resume playing - only meaningful if using a network streaming
140
 * protocol (e.g. MMS).
141
 * @param pause 1 for pause, 0 for resume
142
 */
143
int av_url_read_pause(URLContext *h, int pause);
144 8bfb108b Diego Biurrun
145 536333a0 Björn Axelsson
/**
146
 * Seek to a given timestamp relative to some component stream.
147 8bfb108b Diego Biurrun
 * Only meaningful if using a network streaming protocol (e.g. MMS.).
148 536333a0 Björn Axelsson
 * @param stream_index The stream index that the timestamp is relative to.
149
 *        If stream_index is (-1) the timestamp should be in AV_TIME_BASE
150
 *        units from the beginning of the presentation.
151
 *        If a stream_index >= 0 is used and the protocol does not support
152
 *        seeking based on component streams, the call will fail with ENOTSUP.
153 00ef4f58 Diego Biurrun
 * @param timestamp timestamp in AVStream.time_base units
154 536333a0 Björn Axelsson
 *        or if there is no stream specified then in AV_TIME_BASE units.
155
 * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
156
 *        and AVSEEK_FLAG_ANY. The protocol may silently ignore
157
 *        AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
158
 *        fail with ENOTSUP if used and not supported.
159
 * @return >= 0 on success
160
 * @see AVInputFormat::read_seek
161
 */
162 7f37f568 Diego Biurrun
int64_t av_url_read_seek(URLContext *h, int stream_index,
163
                         int64_t timestamp, int flags);
164 536333a0 Björn Axelsson
165 8f73c060 Martin Storsjö
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
166
167 de6d9b64 Fabrice Bellard
typedef struct URLProtocol {
168
    const char *name;
169 725b3da9 Stefano Sabatini
    int (*url_open)(URLContext *h, const char *url, int flags);
170 de6d9b64 Fabrice Bellard
    int (*url_read)(URLContext *h, unsigned char *buf, int size);
171 27241cbf Martin Storsjö
    int (*url_write)(URLContext *h, const unsigned char *buf, int size);
172 bc5c918e Diego Biurrun
    int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
173 de6d9b64 Fabrice Bellard
    int (*url_close)(URLContext *h);
174
    struct URLProtocol *next;
175 502bdf68 Michael Niedermayer
    int (*url_read_pause)(URLContext *h, int pause);
176 7f37f568 Diego Biurrun
    int64_t (*url_read_seek)(URLContext *h, int stream_index,
177
                             int64_t timestamp, int flags);
178 f0a80394 Ronald S. Bultje
    int (*url_get_file_handle)(URLContext *h);
179 735cf6b2 Martin Storsjö
    int priv_data_size;
180
    const AVClass *priv_data_class;
181 f3bea991 Martin Storsjö
    int flags;
182 de6d9b64 Fabrice Bellard
} URLProtocol;
183
184 838b27b4 Aurelien Jacobs
#if FF_API_REGISTER_PROTOCOL
185 de6d9b64 Fabrice Bellard
extern URLProtocol *first_protocol;
186 d1037c12 Stefano Sabatini
#endif
187
188 019ac05a Fabrice Bellard
extern URLInterruptCB *url_interrupt_cb;
189 de6d9b64 Fabrice Bellard
190 9075d1e0 Stefano Sabatini
/**
191
 * If protocol is NULL, returns the first registered protocol,
192 c1b02101 Stefano Sabatini
 * if protocol is non-NULL, returns the next registered protocol after protocol,
193 9075d1e0 Stefano Sabatini
 * or NULL if protocol is the last one.
194
 */
195 84be6e72 Michael Niedermayer
URLProtocol *av_protocol_next(URLProtocol *p);
196
197 838b27b4 Aurelien Jacobs
#if FF_API_REGISTER_PROTOCOL
198 65c40e4e Stefano Sabatini
/**
199
 * @deprecated Use av_register_protocol() instead.
200
 */
201
attribute_deprecated int register_protocol(URLProtocol *protocol);
202 9b07a2dc Martin Storsjö
203
/**
204
 * @deprecated Use av_register_protocol2() instead.
205
 */
206
attribute_deprecated int av_register_protocol(URLProtocol *protocol);
207 65c40e4e Stefano Sabatini
#endif
208
209 d19a046e Stefano Sabatini
/**
210 49bd8e4b Måns Rullgård
 * Register the URLProtocol protocol.
211 9b07a2dc Martin Storsjö
 *
212
 * @param size the size of the URLProtocol struct referenced
213 d19a046e Stefano Sabatini
 */
214 9b07a2dc Martin Storsjö
int av_register_protocol2(URLProtocol *protocol, int size);
215 de6d9b64 Fabrice Bellard
216 8978feda Anton Khirnov
#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
217
218 1308f273 Michael Niedermayer
/**
219 333e8943 Anton Khirnov
 * @}
220
 */
221
222
/**
223 1308f273 Michael Niedermayer
 * Bytestream IO Context.
224
 * New fields can be added to the end with minor version bumps.
225 8bfb108b Diego Biurrun
 * Removal, reordering and changes to existing fields require a major
226 1308f273 Michael Niedermayer
 * version bump.
227 ae628ec1 Anton Khirnov
 * sizeof(AVIOContext) must not be used outside libav*.
228 1308f273 Michael Niedermayer
 */
229 de6d9b64 Fabrice Bellard
typedef struct {
230
    unsigned char *buffer;
231
    int buffer_size;
232
    unsigned char *buf_ptr, *buf_end;
233
    void *opaque;
234 0c1a9eda Zdenek Kabelac
    int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
235 576ae256 Michael Niedermayer
    int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
236 bc5c918e Diego Biurrun
    int64_t (*seek)(void *opaque, int64_t offset, int whence);
237
    int64_t pos; /**< position in the file of the current buffer */
238 c3316802 Panagiotis Issaris
    int must_flush; /**< true if the next seek should flush */
239
    int eof_reached; /**< true if eof reached */
240
    int write_flag;  /**< true if open for writing */
241 8978feda Anton Khirnov
#if FF_API_OLD_AVIO
242
    attribute_deprecated int is_streamed;
243
#endif
244 f031df23 Fabrice Bellard
    int max_packet_size;
245 ee9f36a8 Michael Niedermayer
    unsigned long checksum;
246
    unsigned char *checksum_ptr;
247
    unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
248 576ae256 Michael Niedermayer
    int error;         ///< contains the error code or 0 if no error happened
249 502bdf68 Michael Niedermayer
    int (*read_pause)(void *opaque, int pause);
250 7f37f568 Diego Biurrun
    int64_t (*read_seek)(void *opaque, int stream_index,
251
                         int64_t timestamp, int flags);
252 8978feda Anton Khirnov
    /**
253
     * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
254
     */
255
    int seekable;
256 ae628ec1 Anton Khirnov
} AVIOContext;
257 de6d9b64 Fabrice Bellard
258 ae628ec1 Anton Khirnov
#if FF_API_OLD_AVIO
259
typedef attribute_deprecated AVIOContext ByteIOContext;
260
261 e731b8d8 Anton Khirnov
attribute_deprecated int init_put_byte(AVIOContext *s,
262 de6d9b64 Fabrice Bellard
                  unsigned char *buffer,
263
                  int buffer_size,
264
                  int write_flag,
265
                  void *opaque,
266 1e0f3468 Reimar Döffinger
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
267
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
268 bc5c918e Diego Biurrun
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
269 8d9ac969 Anton Khirnov
attribute_deprecated AVIOContext *av_alloc_put_byte(
270
                  unsigned char *buffer,
271
                  int buffer_size,
272
                  int write_flag,
273
                  void *opaque,
274
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
275
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
276
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
277 b7effd4e Anton Khirnov
278
/**
279
 * @defgroup old_avio_funcs Old put_/get_*() functions
280
 * @deprecated use the avio_ -prefixed functions instead.
281
 * @{
282
 */
283
attribute_deprecated int          get_buffer(AVIOContext *s, unsigned char *buf, int size);
284 b3db9cee Anton Khirnov
attribute_deprecated int          get_partial_buffer(AVIOContext *s, unsigned char *buf, int size);
285 b7effd4e Anton Khirnov
attribute_deprecated int          get_byte(AVIOContext *s);
286
attribute_deprecated unsigned int get_le16(AVIOContext *s);
287
attribute_deprecated unsigned int get_le24(AVIOContext *s);
288
attribute_deprecated unsigned int get_le32(AVIOContext *s);
289
attribute_deprecated uint64_t     get_le64(AVIOContext *s);
290
attribute_deprecated unsigned int get_be16(AVIOContext *s);
291
attribute_deprecated unsigned int get_be24(AVIOContext *s);
292
attribute_deprecated unsigned int get_be32(AVIOContext *s);
293
attribute_deprecated uint64_t     get_be64(AVIOContext *s);
294 77eb5504 Anton Khirnov
295
attribute_deprecated void         put_byte(AVIOContext *s, int b);
296 0ac8e2bf Anton Khirnov
attribute_deprecated void         put_nbyte(AVIOContext *s, int b, int count);
297 77eb5504 Anton Khirnov
attribute_deprecated void         put_buffer(AVIOContext *s, const unsigned char *buf, int size);
298
attribute_deprecated void         put_le64(AVIOContext *s, uint64_t val);
299
attribute_deprecated void         put_be64(AVIOContext *s, uint64_t val);
300
attribute_deprecated void         put_le32(AVIOContext *s, unsigned int val);
301
attribute_deprecated void         put_be32(AVIOContext *s, unsigned int val);
302
attribute_deprecated void         put_le24(AVIOContext *s, unsigned int val);
303
attribute_deprecated void         put_be24(AVIOContext *s, unsigned int val);
304
attribute_deprecated void         put_le16(AVIOContext *s, unsigned int val);
305
attribute_deprecated void         put_be16(AVIOContext *s, unsigned int val);
306 61840b43 Anton Khirnov
attribute_deprecated void         put_tag(AVIOContext *s, const char *tag);
307 b7effd4e Anton Khirnov
/**
308
 * @}
309
 */
310 22a3212e Anton Khirnov
311 933e90a6 Anton Khirnov
attribute_deprecated int     av_url_read_fpause(AVIOContext *h,    int pause);
312 491653ed Anton Khirnov
attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h,    int stream_index,
313 933e90a6 Anton Khirnov
                                                int64_t timestamp, int flags);
314 22a3212e Anton Khirnov
315
/**
316
 * @defgroup old_url_f_funcs Old url_f* functions
317
 * @deprecated use the avio_ -prefixed functions instead.
318
 * @{
319
 */
320
attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
321
attribute_deprecated int url_fclose(AVIOContext *s);
322 6b4aa5da Anton Khirnov
attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
323 0300db8a Anton Khirnov
attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
324 a2704c97 Anton Khirnov
attribute_deprecated int64_t url_ftell(AVIOContext *s);
325 76aa876e Anton Khirnov
attribute_deprecated int64_t url_fsize(AVIOContext *s);
326 e5197539 Anton Khirnov
#define URL_EOF (-1)
327
attribute_deprecated int url_fgetc(AVIOContext *s);
328 59f65d95 Anton Khirnov
attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
329 d9d86e00 Anton Khirnov
#ifdef __GNUC__
330
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
331
#else
332
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
333
#endif
334 b7f2fdde Anton Khirnov
attribute_deprecated void put_flush_packet(AVIOContext *s);
335 b92c5452 Anton Khirnov
attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
336 403ee835 Anton Khirnov
attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
337 6dc7d80d Anton Khirnov
attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
338 724f6a0f Anton Khirnov
attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h);
339 22a3212e Anton Khirnov
/**
340
 * @}
341
 */
342 66e5b1df Anton Khirnov
343
/**
344
 * @deprecated use AVIOContext.eof_reached
345
 */
346
attribute_deprecated int url_feof(AVIOContext *s);
347 3e68b3ba Anton Khirnov
attribute_deprecated int url_ferror(AVIOContext *s);
348 4ec153bb Anton Khirnov
349
attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri);
350
attribute_deprecated int udp_get_local_port(URLContext *h);
351 4c4427a7 Anton Khirnov
352
attribute_deprecated void init_checksum(AVIOContext *s,
353
                   unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
354
                   unsigned long checksum);
355 b64030f2 Anton Khirnov
attribute_deprecated unsigned long get_checksum(AVIOContext *s);
356 e731b8d8 Anton Khirnov
#endif
357 8d9ac969 Anton Khirnov
358 3c96c648 Anton Khirnov
/**
359
 * Allocate and initialize an AVIOContext for buffered I/O. It must be later
360
 * freed with av_free().
361
 *
362
 * @param buffer Memory block for input/output operations via AVIOContext.
363
 * @param buffer_size The buffer size is very important for performance.
364
 *        For protocols with fixed blocksize it should be set to this blocksize.
365
 *        For others a typical size is a cache page, e.g. 4kb.
366
 * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
367
 * @param opaque An opaque pointer to user-specific data.
368
 * @param read_packet  A function for refilling the buffer, may be NULL.
369
 * @param write_packet A function for writing the buffer contents, may be NULL.
370
 * @param seek A function for seeking to specified byte position, may be NULL.
371
 *
372
 * @return Allocated AVIOContext or NULL on failure.
373
 */
374 8d9ac969 Anton Khirnov
AVIOContext *avio_alloc_context(
375 1e0f3468 Reimar Döffinger
                  unsigned char *buffer,
376
                  int buffer_size,
377
                  int write_flag,
378
                  void *opaque,
379 0c1a9eda Zdenek Kabelac
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
380 576ae256 Michael Niedermayer
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
381 bc5c918e Diego Biurrun
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
382 de6d9b64 Fabrice Bellard
383 77eb5504 Anton Khirnov
void avio_w8(AVIOContext *s, int b);
384
void avio_write(AVIOContext *s, const unsigned char *buf, int size);
385
void avio_wl64(AVIOContext *s, uint64_t val);
386
void avio_wb64(AVIOContext *s, uint64_t val);
387
void avio_wl32(AVIOContext *s, unsigned int val);
388
void avio_wb32(AVIOContext *s, unsigned int val);
389
void avio_wl24(AVIOContext *s, unsigned int val);
390
void avio_wb24(AVIOContext *s, unsigned int val);
391
void avio_wl16(AVIOContext *s, unsigned int val);
392
void avio_wb16(AVIOContext *s, unsigned int val);
393 de6d9b64 Fabrice Bellard
394 4efd5cf3 Anton Khirnov
#if FF_API_OLD_AVIO
395 ae628ec1 Anton Khirnov
attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
396 4efd5cf3 Anton Khirnov
#endif
397
398
/**
399
 * Write a NULL-terminated string.
400
 * @return number of bytes written.
401
 */
402 ae628ec1 Anton Khirnov
int avio_put_str(AVIOContext *s, const char *str);
403 75bdb984 Philip Gladstone
404 67e21020 Michael Niedermayer
/**
405 dccbd97d Anton Khirnov
 * Convert an UTF-8 string to UTF-16LE and write it.
406
 * @return number of bytes written.
407
 */
408 ae628ec1 Anton Khirnov
int avio_put_str16le(AVIOContext *s, const char *str);
409 dccbd97d Anton Khirnov
410
/**
411 230a4686 Anton Khirnov
 * Passing this as the "whence" parameter to a seek function causes it to
412
 * return the filesize without seeking anywhere. Supporting this is optional.
413
 * If it is not supported then the seek function will return <0.
414
 */
415
#define AVSEEK_SIZE 0x10000
416
417
/**
418
 * Oring this flag as into the "whence" parameter to a seek function causes it to
419
 * seek by any means (like reopening and linear reading) or other normally unreasonble
420
 * means that can be extreemly slow.
421
 * This may be ignored by the seek code.
422
 */
423
#define AVSEEK_FORCE 0x20000
424
425
/**
426 ae628ec1 Anton Khirnov
 * fseek() equivalent for AVIOContext.
427 67e21020 Michael Niedermayer
 * @return new position or AVERROR.
428
 */
429 6b4aa5da Anton Khirnov
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
430 67e21020 Michael Niedermayer
431
/**
432 2af07d36 Peter Ross
 * Skip given number of bytes forward
433
 * @return new position or AVERROR.
434
 */
435 af020732 Anton Khirnov
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
436
{
437
    return avio_seek(s, offset, SEEK_CUR);
438
}
439 2af07d36 Peter Ross
440
/**
441 ae628ec1 Anton Khirnov
 * ftell() equivalent for AVIOContext.
442 67e21020 Michael Niedermayer
 * @return position or AVERROR.
443
 */
444 af020732 Anton Khirnov
static av_always_inline int64_t avio_tell(AVIOContext *s)
445
{
446
    return avio_seek(s, 0, SEEK_CUR);
447
}
448 67e21020 Michael Niedermayer
449
/**
450 49bd8e4b Måns Rullgård
 * Get the filesize.
451 67e21020 Michael Niedermayer
 * @return filesize or AVERROR
452
 */
453 76aa876e Anton Khirnov
int64_t avio_size(AVIOContext *s);
454 67e21020 Michael Niedermayer
455 c3316802 Panagiotis Issaris
/** @warning currently size is limited */
456 572f992e Michael Niedermayer
#ifdef __GNUC__
457 d9d86e00 Anton Khirnov
int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
458 572f992e Michael Niedermayer
#else
459 d9d86e00 Anton Khirnov
int avio_printf(AVIOContext *s, const char *fmt, ...);
460 572f992e Michael Niedermayer
#endif
461 a8c5ab27 Panagiotis Issaris
462 655e45e7 Anton Khirnov
#if FF_API_OLD_AVIO
463 c3316802 Panagiotis Issaris
/** @note unlike fgets, the EOL character is not returned and a whole
464 7f37f568 Diego Biurrun
    line is parsed. return NULL if first char read was EOF */
465 655e45e7 Anton Khirnov
attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
466
#endif
467 f031df23 Fabrice Bellard
468 b7f2fdde Anton Khirnov
void avio_flush(AVIOContext *s);
469 de6d9b64 Fabrice Bellard
470 4edfcecc Michael Niedermayer
471
/**
472 ae628ec1 Anton Khirnov
 * Read size bytes from AVIOContext into buf.
473 32e543f8 Benoit Fouet
 * @return number of bytes read or AVERROR
474 4edfcecc Michael Niedermayer
 */
475 b7effd4e Anton Khirnov
int avio_read(AVIOContext *s, unsigned char *buf, int size);
476 4edfcecc Michael Niedermayer
477 c3316802 Panagiotis Issaris
/** @note return 0 if EOF, so you cannot use it if EOF handling is
478 7f37f568 Diego Biurrun
    necessary */
479 b7effd4e Anton Khirnov
int          avio_r8  (AVIOContext *s);
480
unsigned int avio_rl16(AVIOContext *s);
481
unsigned int avio_rl24(AVIOContext *s);
482
unsigned int avio_rl32(AVIOContext *s);
483
uint64_t     avio_rl64(AVIOContext *s);
484 de6d9b64 Fabrice Bellard
485 93b78d12 Anton Khirnov
/**
486 41d8555f Reimar Döffinger
 * Read a string from pb into buf. The reading will terminate when either
487
 * a NULL character was encountered, maxlen bytes have been read, or nothing
488
 * more can be read from pb. The result is guaranteed to be NULL-terminated, it
489
 * will be truncated if buf is too small.
490
 * Note that the string is not interpreted or validated in any way, it
491
 * might get truncated in the middle of a sequence for multi-byte encodings.
492
 *
493
 * @return number of bytes read (is always <= maxlen).
494
 * If reading ends on EOF or error, the return value will be one more than
495
 * bytes actually read.
496
 */
497
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
498
499
/**
500 93b78d12 Anton Khirnov
 * Read a UTF-16 string from pb and convert it to UTF-8.
501
 * The reading will terminate when either a null or invalid character was
502
 * encountered or maxlen bytes have been read.
503
 * @return number of bytes read (is always <= maxlen)
504
 */
505 ae628ec1 Anton Khirnov
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
506
int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
507 93b78d12 Anton Khirnov
508 e16ead07 Anton Khirnov
#if FF_API_OLD_AVIO
509
/**
510
 * @deprecated use avio_get_str instead
511
 */
512
attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
513
#endif
514 b7effd4e Anton Khirnov
unsigned int avio_rb16(AVIOContext *s);
515
unsigned int avio_rb24(AVIOContext *s);
516
unsigned int avio_rb32(AVIOContext *s);
517
uint64_t     avio_rb64(AVIOContext *s);
518 de6d9b64 Fabrice Bellard
519 8978feda Anton Khirnov
#if FF_API_OLD_AVIO
520
/**
521
 * @deprecated Use AVIOContext.seekable field directly.
522
 */
523
attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
524 de6d9b64 Fabrice Bellard
{
525 8978feda Anton Khirnov
    return !s->seekable;
526 de6d9b64 Fabrice Bellard
}
527 8978feda Anton Khirnov
#endif
528 de6d9b64 Fabrice Bellard
529 364cacc7 Aurelien Jacobs
#if FF_API_URL_RESETBUF
530 770d9daf Björn Axelsson
/** Reset the buffer for reading or writing.
531
 * @note Will drop any data currently in the buffer without transmitting it.
532
 * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY
533
 *        to set up the buffer for writing. */
534 ae628ec1 Anton Khirnov
int url_resetbuf(AVIOContext *s, int flags);
535 08580cb0 Benoit Fouet
#endif
536 a8c5ab27 Panagiotis Issaris
537 fe4fbb58 Stefano Sabatini
/**
538 ae628ec1 Anton Khirnov
 * Create and initialize a AVIOContext for accessing the
539 fe4fbb58 Stefano Sabatini
 * resource indicated by url.
540
 * @note When the resource indicated by url has been opened in
541 ae628ec1 Anton Khirnov
 * read+write mode, the AVIOContext can be used only for writing.
542 fe4fbb58 Stefano Sabatini
 *
543 ae628ec1 Anton Khirnov
 * @param s Used to return the pointer to the created AVIOContext.
544 fe4fbb58 Stefano Sabatini
 * In case of failure the pointed to value is set to NULL.
545
 * @param flags flags which control how the resource indicated by url
546
 * is to be opened
547
 * @return 0 in case of success, a negative value corresponding to an
548
 * AVERROR code in case of failure
549
 */
550 22a3212e Anton Khirnov
int avio_open(AVIOContext **s, const char *url, int flags);
551 fe4fbb58 Stefano Sabatini
552 22a3212e Anton Khirnov
int avio_close(AVIOContext *s);
553 a8c5ab27 Panagiotis Issaris
554 e8bb2e24 Anton Khirnov
#if FF_API_OLD_AVIO
555 8d9769a7 Anton Khirnov
attribute_deprecated URLContext *url_fileno(AVIOContext *s);
556
557 c3316802 Panagiotis Issaris
/**
558 e8bb2e24 Anton Khirnov
 * @deprecated use AVIOContext.max_packet_size directly.
559 a8c5ab27 Panagiotis Issaris
 */
560 e8bb2e24 Anton Khirnov
attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
561 de6d9b64 Fabrice Bellard
562 83fddaeb Anton Khirnov
attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
563 a8c5ab27 Panagiotis Issaris
564 c3316802 Panagiotis Issaris
/** return the written or read size */
565 35f10235 Anton Khirnov
attribute_deprecated int url_close_buf(AVIOContext *s);
566
#endif
567 de6d9b64 Fabrice Bellard
568 c3316802 Panagiotis Issaris
/**
569 a8c5ab27 Panagiotis Issaris
 * Open a write only memory stream.
570
 *
571
 * @param s new IO context
572
 * @return zero if no error.
573
 */
574 b92c5452 Anton Khirnov
int avio_open_dyn_buf(AVIOContext **s);
575 a8c5ab27 Panagiotis Issaris
576 c3316802 Panagiotis Issaris
/**
577 a8c5ab27 Panagiotis Issaris
 * Return the written size and a pointer to the buffer. The buffer
578 403ee835 Anton Khirnov
 * must be freed with av_free().
579
 * Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer.
580 de1807bb Josh Allmann
 *
581 a8c5ab27 Panagiotis Issaris
 * @param s IO context
582 e8b7c70f Panagiotis Issaris
 * @param pbuffer pointer to a byte buffer
583 a8c5ab27 Panagiotis Issaris
 * @return the length of the byte buffer
584
 */
585 6dc7d80d Anton Khirnov
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
586 f031df23 Fabrice Bellard
587 8ef30ac1 Aurelien Jacobs
#if FF_API_UDP_GET_FILE
588 f031df23 Fabrice Bellard
int udp_get_file_handle(URLContext *h);
589 f0a80394 Ronald S. Bultje
#endif
590 f031df23 Fabrice Bellard
591 98790382 Stefano Sabatini
#endif /* AVFORMAT_AVIO_H */