Statistics
| Branch: | Revision:

ffmpeg / libavformat / avio.h @ 403ee835

History | View | Annotate | Download (24.9 KB)

1
/*
2
 * copyright (c) 2001 Fabrice Bellard
3
 *
4
 * This file is part of Libav.
5
 *
6
 * Libav is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * Libav is distributed in the hope that it will be useful,
12
 * 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
 * License along with Libav; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
#ifndef AVFORMAT_AVIO_H
21
#define AVFORMAT_AVIO_H
22

    
23
/**
24
 * @file
25
 * unbuffered I/O operations
26
 *
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
 */
30

    
31
#include <stdint.h>
32

    
33
#include "libavutil/common.h"
34
#include "libavutil/log.h"
35

    
36
#include "libavformat/version.h"
37

    
38
/* unbuffered I/O */
39

    
40
/**
41
 * URL Context.
42
 * New fields can be added to the end with minor version bumps.
43
 * Removal, reordering and changes to existing fields require a major
44
 * version bump.
45
 * sizeof(URLContext) must not be used outside libav*.
46
 */
47
typedef struct URLContext {
48
#if FF_API_URL_CLASS
49
    const AVClass *av_class; ///< information for av_log(). Set by url_open().
50
#endif
51
    struct URLProtocol *prot;
52
    int flags;
53
    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
    void *priv_data;
56
    char *filename; /**< specified URL */
57
    int is_connected;
58
} URLContext;
59

    
60
typedef struct URLPollEntry {
61
    URLContext *handle;
62
    int events;
63
    int revents;
64
} URLPollEntry;
65

    
66
/**
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

    
93
typedef int URLInterruptCB(void);
94

    
95
/**
96
 * Create a URLContext for accessing to the resource indicated by
97
 * url, and open it using the URLProtocol up.
98
 *
99
 * @param puc pointer to the location where, in case of success, the
100
 * function puts the pointer to the created URLContext
101
 * @param flags flags which control how the resource indicated by url
102
 * 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
int url_open_protocol (URLContext **puc, struct URLProtocol *up,
107
                       const char *url, int flags);
108

    
109
/**
110
 * Create a URLContext for accessing to the resource indicated by
111
 * url, but do not initiate the connection yet.
112
 *
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
 * Create an URLContext for accessing to the resource indicated by
129
 * url, and open it.
130
 *
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
int url_open(URLContext **h, const char *url, int flags);
139

    
140
/**
141
 * Read up to size bytes from the resource accessed by h, and store
142
 * 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
int url_read(URLContext *h, unsigned char *buf, int size);
150

    
151
/**
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
int url_read_complete(URLContext *h, unsigned char *buf, int size);
159

    
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
int url_write(URLContext *h, const unsigned char *buf, int size);
167

    
168
/**
169
 * 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
 * Change the position that will be used by the next read/write
177
 * 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
int64_t url_seek(URLContext *h, int64_t pos, int whence);
190

    
191
/**
192
 * Close the resource accessed by the URLContext h, and free the
193
 * memory used by it.
194
 *
195
 * @return a negative value if an error condition occurred, 0
196
 * otherwise
197
 */
198
int url_close(URLContext *h);
199

    
200
/**
201
 * Return a non-zero value if the resource indicated by url
202
 * exists, 0 otherwise.
203
 */
204
int url_exist(const char *url);
205

    
206
/**
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
int64_t url_filesize(URLContext *h);
212

    
213
/**
214
 * 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
 * Return the maximum packet size associated to packetized file
223
 * handle. If the file is not packetized (stream like HTTP or file on
224
 * disk), then 0 is returned.
225
 *
226
 * @param h file handle
227
 * @return maximum packet size in bytes
228
 */
229
int url_get_max_packet_size(URLContext *h);
230

    
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
void url_get_filename(URLContext *h, char *buf, int buf_size);
237

    
238
/**
239
 * The callback is called in blocking functions to test regulary if
240
 * asynchronous interruption is needed. AVERROR_EXIT is returned
241
 * in this case by the interrupted function. 'NULL' means no interrupt
242
 * callback is given.
243
 */
244
void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
245

    
246
/* not implemented */
247
int url_poll(URLPollEntry *poll_table, int n, int timeout);
248

    
249
/**
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

    
256
/**
257
 * Seek to a given timestamp relative to some component stream.
258
 * Only meaningful if using a network streaming protocol (e.g. MMS.).
259
 * @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
 * @param timestamp timestamp in AVStream.time_base units
265
 *        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
int64_t av_url_read_seek(URLContext *h, int stream_index,
274
                         int64_t timestamp, int flags);
275

    
276
/**
277
 * 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
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
285

    
286
typedef struct URLProtocol {
287
    const char *name;
288
    int (*url_open)(URLContext *h, const char *url, int flags);
289
    int (*url_read)(URLContext *h, unsigned char *buf, int size);
290
    int (*url_write)(URLContext *h, const unsigned char *buf, int size);
291
    int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
292
    int (*url_close)(URLContext *h);
293
    struct URLProtocol *next;
294
    int (*url_read_pause)(URLContext *h, int pause);
295
    int64_t (*url_read_seek)(URLContext *h, int stream_index,
296
                             int64_t timestamp, int flags);
297
    int (*url_get_file_handle)(URLContext *h);
298
    int priv_data_size;
299
    const AVClass *priv_data_class;
300
    int flags;
301
} URLProtocol;
302

    
303
#if FF_API_REGISTER_PROTOCOL
304
extern URLProtocol *first_protocol;
305
#endif
306

    
307
extern URLInterruptCB *url_interrupt_cb;
308

    
309
/**
310
 * If protocol is NULL, returns the first registered protocol,
311
 * if protocol is non-NULL, returns the next registered protocol after protocol,
312
 * or NULL if protocol is the last one.
313
 */
314
URLProtocol *av_protocol_next(URLProtocol *p);
315

    
316
#if FF_API_REGISTER_PROTOCOL
317
/**
318
 * @deprecated Use av_register_protocol() instead.
319
 */
320
attribute_deprecated int register_protocol(URLProtocol *protocol);
321

    
322
/**
323
 * @deprecated Use av_register_protocol2() instead.
324
 */
325
attribute_deprecated int av_register_protocol(URLProtocol *protocol);
326
#endif
327

    
328
/**
329
 * Register the URLProtocol protocol.
330
 *
331
 * @param size the size of the URLProtocol struct referenced
332
 */
333
int av_register_protocol2(URLProtocol *protocol, int size);
334

    
335
#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
336

    
337
/**
338
 * Bytestream IO Context.
339
 * New fields can be added to the end with minor version bumps.
340
 * Removal, reordering and changes to existing fields require a major
341
 * version bump.
342
 * sizeof(AVIOContext) must not be used outside libav*.
343
 */
344
typedef struct {
345
    unsigned char *buffer;
346
    int buffer_size;
347
    unsigned char *buf_ptr, *buf_end;
348
    void *opaque;
349
    int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
350
    int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
351
    int64_t (*seek)(void *opaque, int64_t offset, int whence);
352
    int64_t pos; /**< position in the file of the current buffer */
353
    int must_flush; /**< true if the next seek should flush */
354
    int eof_reached; /**< true if eof reached */
355
    int write_flag;  /**< true if open for writing */
356
#if FF_API_OLD_AVIO
357
    attribute_deprecated int is_streamed;
358
#endif
359
    int max_packet_size;
360
    unsigned long checksum;
361
    unsigned char *checksum_ptr;
362
    unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
363
    int error;         ///< contains the error code or 0 if no error happened
364
    int (*read_pause)(void *opaque, int pause);
365
    int64_t (*read_seek)(void *opaque, int stream_index,
366
                         int64_t timestamp, int flags);
367
    /**
368
     * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
369
     */
370
    int seekable;
371
} AVIOContext;
372

    
373
#if FF_API_OLD_AVIO
374
typedef attribute_deprecated AVIOContext ByteIOContext;
375

    
376
attribute_deprecated int init_put_byte(AVIOContext *s,
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
attribute_deprecated AVIOContext *av_alloc_put_byte(
385
                  unsigned char *buffer,
386
                  int buffer_size,
387
                  int write_flag,
388
                  void *opaque,
389
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
390
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
391
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
392

    
393
/**
394
 * @defgroup old_avio_funcs Old put_/get_*() functions
395
 * @deprecated use the avio_ -prefixed functions instead.
396
 * @{
397
 */
398
attribute_deprecated int          get_buffer(AVIOContext *s, unsigned char *buf, int size);
399
attribute_deprecated int          get_partial_buffer(AVIOContext *s, unsigned char *buf, int size);
400
attribute_deprecated int          get_byte(AVIOContext *s);
401
attribute_deprecated unsigned int get_le16(AVIOContext *s);
402
attribute_deprecated unsigned int get_le24(AVIOContext *s);
403
attribute_deprecated unsigned int get_le32(AVIOContext *s);
404
attribute_deprecated uint64_t     get_le64(AVIOContext *s);
405
attribute_deprecated unsigned int get_be16(AVIOContext *s);
406
attribute_deprecated unsigned int get_be24(AVIOContext *s);
407
attribute_deprecated unsigned int get_be32(AVIOContext *s);
408
attribute_deprecated uint64_t     get_be64(AVIOContext *s);
409

    
410
attribute_deprecated void         put_byte(AVIOContext *s, int b);
411
attribute_deprecated void         put_nbyte(AVIOContext *s, int b, int count);
412
attribute_deprecated void         put_buffer(AVIOContext *s, const unsigned char *buf, int size);
413
attribute_deprecated void         put_le64(AVIOContext *s, uint64_t val);
414
attribute_deprecated void         put_be64(AVIOContext *s, uint64_t val);
415
attribute_deprecated void         put_le32(AVIOContext *s, unsigned int val);
416
attribute_deprecated void         put_be32(AVIOContext *s, unsigned int val);
417
attribute_deprecated void         put_le24(AVIOContext *s, unsigned int val);
418
attribute_deprecated void         put_be24(AVIOContext *s, unsigned int val);
419
attribute_deprecated void         put_le16(AVIOContext *s, unsigned int val);
420
attribute_deprecated void         put_be16(AVIOContext *s, unsigned int val);
421
attribute_deprecated void         put_tag(AVIOContext *s, const char *tag);
422
/**
423
 * @}
424
 */
425

    
426
attribute_deprecated int     av_url_read_fpause(AVIOContext *h,    int pause);
427
attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h,    int stream_index,
428
                                                int64_t timestamp, int flags);
429

    
430
/**
431
 * @defgroup old_url_f_funcs Old url_f* functions
432
 * @deprecated use the avio_ -prefixed functions instead.
433
 * @{
434
 */
435
attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
436
attribute_deprecated int url_fclose(AVIOContext *s);
437
attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
438
attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
439
attribute_deprecated int64_t url_ftell(AVIOContext *s);
440
attribute_deprecated int64_t url_fsize(AVIOContext *s);
441
#define URL_EOF (-1)
442
attribute_deprecated int url_fgetc(AVIOContext *s);
443
attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
444
#ifdef __GNUC__
445
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
446
#else
447
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
448
#endif
449
attribute_deprecated void put_flush_packet(AVIOContext *s);
450
attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
451
attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
452
attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
453
/**
454
 * @}
455
 */
456

    
457
/**
458
 * @deprecated use AVIOContext.eof_reached
459
 */
460
attribute_deprecated int url_feof(AVIOContext *s);
461
attribute_deprecated int url_ferror(AVIOContext *s);
462

    
463
attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri);
464
attribute_deprecated int udp_get_local_port(URLContext *h);
465

    
466
attribute_deprecated void init_checksum(AVIOContext *s,
467
                   unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
468
                   unsigned long checksum);
469
attribute_deprecated unsigned long get_checksum(AVIOContext *s);
470
#endif
471

    
472
/**
473
 * Allocate and initialize an AVIOContext for buffered I/O. It must be later
474
 * freed with av_free().
475
 *
476
 * @param buffer Memory block for input/output operations via AVIOContext.
477
 * @param buffer_size The buffer size is very important for performance.
478
 *        For protocols with fixed blocksize it should be set to this blocksize.
479
 *        For others a typical size is a cache page, e.g. 4kb.
480
 * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
481
 * @param opaque An opaque pointer to user-specific data.
482
 * @param read_packet  A function for refilling the buffer, may be NULL.
483
 * @param write_packet A function for writing the buffer contents, may be NULL.
484
 * @param seek A function for seeking to specified byte position, may be NULL.
485
 *
486
 * @return Allocated AVIOContext or NULL on failure.
487
 */
488
AVIOContext *avio_alloc_context(
489
                  unsigned char *buffer,
490
                  int buffer_size,
491
                  int write_flag,
492
                  void *opaque,
493
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
494
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
495
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
496

    
497
void avio_w8(AVIOContext *s, int b);
498
void avio_write(AVIOContext *s, const unsigned char *buf, int size);
499
void avio_wl64(AVIOContext *s, uint64_t val);
500
void avio_wb64(AVIOContext *s, uint64_t val);
501
void avio_wl32(AVIOContext *s, unsigned int val);
502
void avio_wb32(AVIOContext *s, unsigned int val);
503
void avio_wl24(AVIOContext *s, unsigned int val);
504
void avio_wb24(AVIOContext *s, unsigned int val);
505
void avio_wl16(AVIOContext *s, unsigned int val);
506
void avio_wb16(AVIOContext *s, unsigned int val);
507

    
508
#if FF_API_OLD_AVIO
509
attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
510
#endif
511

    
512
/**
513
 * Write a NULL-terminated string.
514
 * @return number of bytes written.
515
 */
516
int avio_put_str(AVIOContext *s, const char *str);
517

    
518
/**
519
 * Convert an UTF-8 string to UTF-16LE and write it.
520
 * @return number of bytes written.
521
 */
522
int avio_put_str16le(AVIOContext *s, const char *str);
523

    
524
/**
525
 * fseek() equivalent for AVIOContext.
526
 * @return new position or AVERROR.
527
 */
528
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
529

    
530
/**
531
 * Skip given number of bytes forward
532
 * @return new position or AVERROR.
533
 */
534
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
535
{
536
    return avio_seek(s, offset, SEEK_CUR);
537
}
538

    
539
/**
540
 * ftell() equivalent for AVIOContext.
541
 * @return position or AVERROR.
542
 */
543
static av_always_inline int64_t avio_tell(AVIOContext *s)
544
{
545
    return avio_seek(s, 0, SEEK_CUR);
546
}
547

    
548
/**
549
 * Get the filesize.
550
 * @return filesize or AVERROR
551
 */
552
int64_t avio_size(AVIOContext *s);
553

    
554
/** @warning currently size is limited */
555
#ifdef __GNUC__
556
int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
557
#else
558
int avio_printf(AVIOContext *s, const char *fmt, ...);
559
#endif
560

    
561
#if FF_API_OLD_AVIO
562
/** @note unlike fgets, the EOL character is not returned and a whole
563
    line is parsed. return NULL if first char read was EOF */
564
attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
565
#endif
566

    
567
void avio_flush(AVIOContext *s);
568

    
569

    
570
/**
571
 * Read size bytes from AVIOContext into buf.
572
 * @return number of bytes read or AVERROR
573
 */
574
int avio_read(AVIOContext *s, unsigned char *buf, int size);
575

    
576
/** @note return 0 if EOF, so you cannot use it if EOF handling is
577
    necessary */
578
int          avio_r8  (AVIOContext *s);
579
unsigned int avio_rl16(AVIOContext *s);
580
unsigned int avio_rl24(AVIOContext *s);
581
unsigned int avio_rl32(AVIOContext *s);
582
uint64_t     avio_rl64(AVIOContext *s);
583

    
584
/**
585
 * Read a string from pb into buf. The reading will terminate when either
586
 * a NULL character was encountered, maxlen bytes have been read, or nothing
587
 * more can be read from pb. The result is guaranteed to be NULL-terminated, it
588
 * will be truncated if buf is too small.
589
 * Note that the string is not interpreted or validated in any way, it
590
 * might get truncated in the middle of a sequence for multi-byte encodings.
591
 *
592
 * @return number of bytes read (is always <= maxlen).
593
 * If reading ends on EOF or error, the return value will be one more than
594
 * bytes actually read.
595
 */
596
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
597

    
598
/**
599
 * Read a UTF-16 string from pb and convert it to UTF-8.
600
 * The reading will terminate when either a null or invalid character was
601
 * encountered or maxlen bytes have been read.
602
 * @return number of bytes read (is always <= maxlen)
603
 */
604
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
605
int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
606

    
607
#if FF_API_OLD_AVIO
608
/**
609
 * @deprecated use avio_get_str instead
610
 */
611
attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
612
#endif
613
unsigned int avio_rb16(AVIOContext *s);
614
unsigned int avio_rb24(AVIOContext *s);
615
unsigned int avio_rb32(AVIOContext *s);
616
uint64_t     avio_rb64(AVIOContext *s);
617

    
618
#if FF_API_OLD_AVIO
619
/**
620
 * @deprecated Use AVIOContext.seekable field directly.
621
 */
622
attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
623
{
624
    return !s->seekable;
625
}
626
#endif
627

    
628
/**
629
 * Create and initialize a AVIOContext for accessing the
630
 * resource referenced by the URLContext h.
631
 * @note When the URLContext h has been opened in read+write mode, the
632
 * AVIOContext can be used only for writing.
633
 *
634
 * @param s Used to return the pointer to the created AVIOContext.
635
 * In case of failure the pointed to value is set to NULL.
636
 * @return 0 in case of success, a negative value corresponding to an
637
 * AVERROR code in case of failure
638
 */
639
int url_fdopen(AVIOContext **s, URLContext *h);
640

    
641
#if FF_API_URL_RESETBUF
642
/** Reset the buffer for reading or writing.
643
 * @note Will drop any data currently in the buffer without transmitting it.
644
 * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY
645
 *        to set up the buffer for writing. */
646
int url_resetbuf(AVIOContext *s, int flags);
647
#endif
648

    
649
/**
650
 * Create and initialize a AVIOContext for accessing the
651
 * resource indicated by url.
652
 * @note When the resource indicated by url has been opened in
653
 * read+write mode, the AVIOContext can be used only for writing.
654
 *
655
 * @param s Used to return the pointer to the created AVIOContext.
656
 * In case of failure the pointed to value is set to NULL.
657
 * @param flags flags which control how the resource indicated by url
658
 * is to be opened
659
 * @return 0 in case of success, a negative value corresponding to an
660
 * AVERROR code in case of failure
661
 */
662
int avio_open(AVIOContext **s, const char *url, int flags);
663

    
664
int avio_close(AVIOContext *s);
665

    
666
#if FF_API_OLD_AVIO
667
attribute_deprecated URLContext *url_fileno(AVIOContext *s);
668

    
669
/**
670
 * @deprecated use AVIOContext.max_packet_size directly.
671
 */
672
attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
673

    
674
attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
675

    
676
/** return the written or read size */
677
attribute_deprecated int url_close_buf(AVIOContext *s);
678
#endif
679

    
680
/**
681
 * Open a write only memory stream.
682
 *
683
 * @param s new IO context
684
 * @return zero if no error.
685
 */
686
int avio_open_dyn_buf(AVIOContext **s);
687

    
688
/**
689
 * Return the written size and a pointer to the buffer. The buffer
690
 * must be freed with av_free().
691
 * Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer.
692
 *
693
 * @param s IO context
694
 * @param pbuffer pointer to a byte buffer
695
 * @return the length of the byte buffer
696
 */
697
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
698

    
699
#if FF_API_UDP_GET_FILE
700
int udp_get_file_handle(URLContext *h);
701
#endif
702

    
703
#endif /* AVFORMAT_AVIO_H */