~ubuntu-branches/ubuntu/quantal/mplayer2/quantal-proposed

« back to all changes in this revision

Viewing changes to ffmpeg-mt/libavformat/avio.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-21 09:21:39 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110421092139-7a21foqroxvir3wr
Tags: 2.0-54-gd33877a-1
* New upstream version
* Bug fix: "internal MP3 decoder miscompiles with gcc 4.6", thanks to
  Norbert Preining (Closes: #623279). Fixed by no longer using internal
  mp3lib copy.
* drop build host specific optimizations

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * copyright (c) 2001 Fabrice Bellard
3
3
 *
4
 
 * This file is part of FFmpeg.
 
4
 * This file is part of Libav.
5
5
 *
6
 
 * FFmpeg is free software; you can redistribute it and/or
 
6
 * Libav is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU Lesser General Public
8
8
 * License as published by the Free Software Foundation; either
9
9
 * version 2.1 of the License, or (at your option) any later version.
10
10
 *
11
 
 * FFmpeg is distributed in the hope that it will be useful,
 
11
 * Libav is distributed in the hope that it will be useful,
12
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
14
 * Lesser General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with FFmpeg; if not, write to the Free Software
 
17
 * License along with Libav; if not, write to the Free Software
18
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 */
20
20
#ifndef AVFORMAT_AVIO_H
33
33
#include "libavutil/common.h"
34
34
#include "libavutil/log.h"
35
35
 
 
36
#include "libavformat/version.h"
 
37
 
36
38
/* unbuffered I/O */
37
39
 
 
40
#if FF_API_OLD_AVIO
38
41
/**
39
42
 * URL Context.
40
43
 * New fields can be added to the end with minor version bumps.
41
44
 * Removal, reordering and changes to existing fields require a major
42
45
 * version bump.
43
46
 * sizeof(URLContext) must not be used outside libav*.
 
47
 * @deprecated This struct will be made private
44
48
 */
45
49
typedef struct URLContext {
46
50
#if FF_API_URL_CLASS
61
65
    int revents;
62
66
} URLPollEntry;
63
67
 
64
 
#define URL_RDONLY 0
65
 
#define URL_WRONLY 1
66
 
#define URL_RDWR   2
 
68
/**
 
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
67
94
 
68
95
typedef int URLInterruptCB(void);
69
96
 
70
97
/**
71
 
 * Create a URLContext for accessing to the resource indicated by
72
 
 * url, and open it using the URLProtocol up.
73
 
 *
74
 
 * @param puc pointer to the location where, in case of success, the
75
 
 * function puts the pointer to the created URLContext
76
 
 * @param flags flags which control how the resource indicated by url
77
 
 * is to be opened
78
 
 * @return 0 in case of success, a negative value corresponding to an
79
 
 * AVERROR code in case of failure
80
 
 */
81
 
int url_open_protocol (URLContext **puc, struct URLProtocol *up,
82
 
                       const char *url, int flags);
83
 
 
84
 
/**
85
 
 * Create a URLContext for accessing to the resource indicated by
86
 
 * url, but do not initiate the connection yet.
87
 
 *
88
 
 * @param puc pointer to the location where, in case of success, the
89
 
 * function puts the pointer to the created URLContext
90
 
 * @param flags flags which control how the resource indicated by url
91
 
 * is to be opened
92
 
 * @return 0 in case of success, a negative value corresponding to an
93
 
 * AVERROR code in case of failure
94
 
 */
95
 
int url_alloc(URLContext **h, const char *url, int flags);
96
 
 
97
 
/**
98
 
 * Connect an URLContext that has been allocated by url_alloc
99
 
 */
100
 
int url_connect(URLContext *h);
101
 
 
102
 
/**
103
 
 * Create an URLContext for accessing to the resource indicated by
104
 
 * url, and open it.
105
 
 *
106
 
 * @param puc pointer to the location where, in case of success, the
107
 
 * function puts the pointer to the created URLContext
108
 
 * @param flags flags which control how the resource indicated by url
109
 
 * is to be opened
110
 
 * @return 0 in case of success, a negative value corresponding to an
111
 
 * AVERROR code in case of failure
112
 
 */
113
 
int url_open(URLContext **h, const char *url, int flags);
114
 
 
115
 
/**
116
 
 * Read up to size bytes from the resource accessed by h, and store
117
 
 * the read bytes in buf.
118
 
 *
119
 
 * @return The number of bytes actually read, or a negative value
120
 
 * corresponding to an AVERROR code in case of error. A value of zero
121
 
 * indicates that it is not possible to read more from the accessed
122
 
 * resource (except if the value of the size argument is also zero).
123
 
 */
124
 
int url_read(URLContext *h, unsigned char *buf, int size);
125
 
 
126
 
/**
127
 
 * Read as many bytes as possible (up to size), calling the
128
 
 * read function multiple times if necessary.
129
 
 * Will also retry if the read function returns AVERROR(EAGAIN).
130
 
 * This makes special short-read handling in applications
131
 
 * unnecessary, if the return value is < size then it is
132
 
 * certain there was either an error or the end of file was reached.
133
 
 */
134
 
int url_read_complete(URLContext *h, unsigned char *buf, int size);
135
 
 
136
 
/**
137
 
 * Write size bytes from buf to the resource accessed by h.
138
 
 *
139
 
 * @return the number of bytes actually written, or a negative value
140
 
 * corresponding to an AVERROR code in case of failure
141
 
 */
142
 
int url_write(URLContext *h, const unsigned char *buf, int size);
143
 
 
144
 
/**
145
 
 * Passing this as the "whence" parameter to a seek function causes it to
146
 
 * return the filesize without seeking anywhere. Supporting this is optional.
147
 
 * If it is not supported then the seek function will return <0.
148
 
 */
149
 
#define AVSEEK_SIZE 0x10000
150
 
 
151
 
/**
152
 
 * Change the position that will be used by the next read/write
153
 
 * operation on the resource accessed by h.
154
 
 *
155
 
 * @param pos specifies the new position to set
156
 
 * @param whence specifies how pos should be interpreted, it must be
157
 
 * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
158
 
 * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
159
 
 * (return the filesize of the requested resource, pos is ignored).
160
 
 * @return a negative value corresponding to an AVERROR code in case
161
 
 * of failure, or the resulting file position, measured in bytes from
162
 
 * the beginning of the file. You can use this feature together with
163
 
 * SEEK_CUR to read the current file position.
164
 
 */
165
 
int64_t url_seek(URLContext *h, int64_t pos, int whence);
166
 
 
167
 
/**
168
 
 * Close the resource accessed by the URLContext h, and free the
169
 
 * memory used by it.
170
 
 *
171
 
 * @return a negative value if an error condition occurred, 0
172
 
 * otherwise
173
 
 */
174
 
int url_close(URLContext *h);
 
98
 * @defgroup old_url_funcs Old url_* functions
 
99
 * @deprecated use the buffered API based on AVIOContext instead
 
100
 * @{
 
101
 */
 
102
attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol *up,
 
103
                                            const char *url, int flags);
 
104
attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags);
 
105
attribute_deprecated int url_connect(URLContext *h);
 
106
attribute_deprecated int url_open(URLContext **h, const char *url, int flags);
 
107
attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size);
 
108
attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size);
 
109
attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size);
 
110
attribute_deprecated int64_t url_seek(URLContext *h, int64_t pos, int whence);
 
111
attribute_deprecated int url_close(URLContext *h);
 
112
attribute_deprecated int64_t url_filesize(URLContext *h);
 
113
attribute_deprecated int url_get_file_handle(URLContext *h);
 
114
attribute_deprecated int url_get_max_packet_size(URLContext *h);
 
115
attribute_deprecated void url_get_filename(URLContext *h, char *buf, int buf_size);
 
116
attribute_deprecated int av_url_read_pause(URLContext *h, int pause);
 
117
attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index,
 
118
                                              int64_t timestamp, int flags);
 
119
attribute_deprecated void url_set_interrupt_cb(int (*interrupt_cb)(void));
 
120
#endif
175
121
 
176
122
/**
177
123
 * Return a non-zero value if the resource indicated by url
180
126
int url_exist(const char *url);
181
127
 
182
128
/**
183
 
 * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
184
 
 * if the operation is not supported by h, or another negative value
185
 
 * corresponding to an AVERROR error code in case of failure.
186
 
 */
187
 
int64_t url_filesize(URLContext *h);
188
 
 
189
 
/**
190
 
 * Return the file descriptor associated with this URL. For RTP, this
191
 
 * will return only the RTP file descriptor, not the RTCP file descriptor.
192
 
 *
193
 
 * @return the file descriptor associated with this URL, or <0 on error.
194
 
 */
195
 
int url_get_file_handle(URLContext *h);
196
 
 
197
 
/**
198
 
 * Return the maximum packet size associated to packetized file
199
 
 * handle. If the file is not packetized (stream like HTTP or file on
200
 
 * disk), then 0 is returned.
201
 
 *
202
 
 * @param h file handle
203
 
 * @return maximum packet size in bytes
204
 
 */
205
 
int url_get_max_packet_size(URLContext *h);
206
 
 
207
 
/**
208
 
 * Copy the filename of the resource accessed by h to buf.
209
 
 *
210
 
 * @param buf_size size in bytes of buf
211
 
 */
212
 
void url_get_filename(URLContext *h, char *buf, int buf_size);
213
 
 
214
 
/**
215
129
 * The callback is called in blocking functions to test regulary if
216
 
 * asynchronous interruption is needed. AVERROR(EINTR) is returned
 
130
 * asynchronous interruption is needed. AVERROR_EXIT is returned
217
131
 * in this case by the interrupted function. 'NULL' means no interrupt
218
132
 * callback is given.
219
133
 */
220
 
void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
 
134
void avio_set_interrupt_cb(int (*interrupt_cb)(void));
221
135
 
 
136
#if FF_API_OLD_AVIO
222
137
/* not implemented */
223
 
int url_poll(URLPollEntry *poll_table, int n, int timeout);
224
 
 
225
 
/**
226
 
 * Pause and resume playing - only meaningful if using a network streaming
227
 
 * protocol (e.g. MMS).
228
 
 * @param pause 1 for pause, 0 for resume
229
 
 */
230
 
int av_url_read_pause(URLContext *h, int pause);
231
 
 
232
 
/**
233
 
 * Seek to a given timestamp relative to some component stream.
234
 
 * Only meaningful if using a network streaming protocol (e.g. MMS.).
235
 
 * @param stream_index The stream index that the timestamp is relative to.
236
 
 *        If stream_index is (-1) the timestamp should be in AV_TIME_BASE
237
 
 *        units from the beginning of the presentation.
238
 
 *        If a stream_index >= 0 is used and the protocol does not support
239
 
 *        seeking based on component streams, the call will fail with ENOTSUP.
240
 
 * @param timestamp timestamp in AVStream.time_base units
241
 
 *        or if there is no stream specified then in AV_TIME_BASE units.
242
 
 * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
243
 
 *        and AVSEEK_FLAG_ANY. The protocol may silently ignore
244
 
 *        AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
245
 
 *        fail with ENOTSUP if used and not supported.
246
 
 * @return >= 0 on success
247
 
 * @see AVInputFormat::read_seek
248
 
 */
249
 
int64_t av_url_read_seek(URLContext *h, int stream_index,
250
 
                         int64_t timestamp, int flags);
251
 
 
252
 
/**
253
 
 * Oring this flag as into the "whence" parameter to a seek function causes it to
254
 
 * seek by any means (like reopening and linear reading) or other normally unreasonble
255
 
 * means that can be extreemly slow.
256
 
 * This may be ignored by the seek code.
257
 
 */
258
 
#define AVSEEK_FORCE 0x20000
259
 
 
 
138
attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout);
 
139
 
 
140
 
 
141
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
 
142
 
 
143
/**
 
144
 * @deprecated This struct is to be made private. Use the higher-level
 
145
 *             AVIOContext-based API instead.
 
146
 */
260
147
typedef struct URLProtocol {
261
148
    const char *name;
262
149
    int (*url_open)(URLContext *h, const char *url, int flags);
271
158
    int (*url_get_file_handle)(URLContext *h);
272
159
    int priv_data_size;
273
160
    const AVClass *priv_data_class;
 
161
    int flags;
274
162
} URLProtocol;
 
163
#endif
275
164
 
276
165
#if FF_API_REGISTER_PROTOCOL
277
166
extern URLProtocol *first_protocol;
278
167
#endif
279
168
 
 
169
#if FF_API_OLD_AVIO
280
170
extern URLInterruptCB *url_interrupt_cb;
 
171
#endif
281
172
 
 
173
#if FF_API_OLD_AVIO
282
174
/**
283
175
 * If protocol is NULL, returns the first registered protocol,
284
176
 * if protocol is non-NULL, returns the next registered protocol after protocol,
285
177
 * or NULL if protocol is the last one.
286
178
 */
287
 
URLProtocol *av_protocol_next(URLProtocol *p);
 
179
attribute_deprecated URLProtocol *av_protocol_next(URLProtocol *p);
 
180
#endif
288
181
 
289
182
#if FF_API_REGISTER_PROTOCOL
290
183
/**
298
191
attribute_deprecated int av_register_protocol(URLProtocol *protocol);
299
192
#endif
300
193
 
 
194
#if FF_API_OLD_AVIO
301
195
/**
302
196
 * Register the URLProtocol protocol.
303
197
 *
304
198
 * @param size the size of the URLProtocol struct referenced
305
199
 */
306
 
int av_register_protocol2(URLProtocol *protocol, int size);
 
200
attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size);
 
201
#endif
 
202
 
 
203
#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
 
204
 
 
205
/**
 
206
 * @}
 
207
 */
307
208
 
308
209
/**
309
210
 * Bytestream IO Context.
310
211
 * New fields can be added to the end with minor version bumps.
311
212
 * Removal, reordering and changes to existing fields require a major
312
213
 * version bump.
313
 
 * sizeof(ByteIOContext) must not be used outside libav*.
 
214
 * sizeof(AVIOContext) must not be used outside libav*.
314
215
 */
315
216
typedef struct {
316
217
    unsigned char *buffer;
324
225
    int must_flush; /**< true if the next seek should flush */
325
226
    int eof_reached; /**< true if eof reached */
326
227
    int write_flag;  /**< true if open for writing */
327
 
    int is_streamed;
 
228
#if FF_API_OLD_AVIO
 
229
    attribute_deprecated int is_streamed;
 
230
#endif
328
231
    int max_packet_size;
329
232
    unsigned long checksum;
330
233
    unsigned char *checksum_ptr;
333
236
    int (*read_pause)(void *opaque, int pause);
334
237
    int64_t (*read_seek)(void *opaque, int stream_index,
335
238
                         int64_t timestamp, int flags);
336
 
} ByteIOContext;
337
 
 
338
 
int init_put_byte(ByteIOContext *s,
339
 
                  unsigned char *buffer,
340
 
                  int buffer_size,
341
 
                  int write_flag,
342
 
                  void *opaque,
343
 
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
344
 
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
345
 
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
346
 
ByteIOContext *av_alloc_put_byte(
347
 
                  unsigned char *buffer,
348
 
                  int buffer_size,
349
 
                  int write_flag,
350
 
                  void *opaque,
351
 
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
352
 
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
353
 
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
354
 
 
355
 
void put_byte(ByteIOContext *s, int b);
356
 
void put_nbyte(ByteIOContext *s, int b, int count);
357
 
void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
358
 
void put_le64(ByteIOContext *s, uint64_t val);
359
 
void put_be64(ByteIOContext *s, uint64_t val);
360
 
void put_le32(ByteIOContext *s, unsigned int val);
361
 
void put_be32(ByteIOContext *s, unsigned int val);
362
 
void put_le24(ByteIOContext *s, unsigned int val);
363
 
void put_be24(ByteIOContext *s, unsigned int val);
364
 
void put_le16(ByteIOContext *s, unsigned int val);
365
 
void put_be16(ByteIOContext *s, unsigned int val);
366
 
void put_tag(ByteIOContext *s, const char *tag);
367
 
 
368
 
void put_strz(ByteIOContext *s, const char *buf);
369
 
 
370
 
/**
371
 
 * fseek() equivalent for ByteIOContext.
372
 
 * @return new position or AVERROR.
373
 
 */
374
 
int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence);
375
 
 
376
 
/**
377
 
 * Skip given number of bytes forward.
378
 
 * @param offset number of bytes
379
 
 * @return 0 on success, <0 on error
380
 
 */
381
 
int url_fskip(ByteIOContext *s, int64_t offset);
382
 
 
383
 
/**
384
 
 * ftell() equivalent for ByteIOContext.
 
239
    /**
 
240
     * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
 
241
     */
 
242
    int seekable;
 
243
} AVIOContext;
 
244
 
 
245
#if FF_API_OLD_AVIO
 
246
typedef attribute_deprecated AVIOContext ByteIOContext;
 
247
 
 
248
attribute_deprecated int init_put_byte(AVIOContext *s,
 
249
                  unsigned char *buffer,
 
250
                  int buffer_size,
 
251
                  int write_flag,
 
252
                  void *opaque,
 
253
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
 
254
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
 
255
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
 
256
attribute_deprecated AVIOContext *av_alloc_put_byte(
 
257
                  unsigned char *buffer,
 
258
                  int buffer_size,
 
259
                  int write_flag,
 
260
                  void *opaque,
 
261
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
 
262
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
 
263
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
 
264
 
 
265
/**
 
266
 * @defgroup old_avio_funcs Old put_/get_*() functions
 
267
 * @deprecated use the avio_ -prefixed functions instead.
 
268
 * @{
 
269
 */
 
270
attribute_deprecated int          get_buffer(AVIOContext *s, unsigned char *buf, int size);
 
271
attribute_deprecated int          get_partial_buffer(AVIOContext *s, unsigned char *buf, int size);
 
272
attribute_deprecated int          get_byte(AVIOContext *s);
 
273
attribute_deprecated unsigned int get_le16(AVIOContext *s);
 
274
attribute_deprecated unsigned int get_le24(AVIOContext *s);
 
275
attribute_deprecated unsigned int get_le32(AVIOContext *s);
 
276
attribute_deprecated uint64_t     get_le64(AVIOContext *s);
 
277
attribute_deprecated unsigned int get_be16(AVIOContext *s);
 
278
attribute_deprecated unsigned int get_be24(AVIOContext *s);
 
279
attribute_deprecated unsigned int get_be32(AVIOContext *s);
 
280
attribute_deprecated uint64_t     get_be64(AVIOContext *s);
 
281
 
 
282
attribute_deprecated void         put_byte(AVIOContext *s, int b);
 
283
attribute_deprecated void         put_nbyte(AVIOContext *s, int b, int count);
 
284
attribute_deprecated void         put_buffer(AVIOContext *s, const unsigned char *buf, int size);
 
285
attribute_deprecated void         put_le64(AVIOContext *s, uint64_t val);
 
286
attribute_deprecated void         put_be64(AVIOContext *s, uint64_t val);
 
287
attribute_deprecated void         put_le32(AVIOContext *s, unsigned int val);
 
288
attribute_deprecated void         put_be32(AVIOContext *s, unsigned int val);
 
289
attribute_deprecated void         put_le24(AVIOContext *s, unsigned int val);
 
290
attribute_deprecated void         put_be24(AVIOContext *s, unsigned int val);
 
291
attribute_deprecated void         put_le16(AVIOContext *s, unsigned int val);
 
292
attribute_deprecated void         put_be16(AVIOContext *s, unsigned int val);
 
293
attribute_deprecated void         put_tag(AVIOContext *s, const char *tag);
 
294
/**
 
295
 * @}
 
296
 */
 
297
 
 
298
attribute_deprecated int     av_url_read_fpause(AVIOContext *h,    int pause);
 
299
attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h,    int stream_index,
 
300
                                                int64_t timestamp, int flags);
 
301
 
 
302
/**
 
303
 * @defgroup old_url_f_funcs Old url_f* functions
 
304
 * @deprecated use the avio_ -prefixed functions instead.
 
305
 * @{
 
306
 */
 
307
attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
 
308
attribute_deprecated int url_fclose(AVIOContext *s);
 
309
attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
 
310
attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
 
311
attribute_deprecated int64_t url_ftell(AVIOContext *s);
 
312
attribute_deprecated int64_t url_fsize(AVIOContext *s);
 
313
#define URL_EOF (-1)
 
314
attribute_deprecated int url_fgetc(AVIOContext *s);
 
315
attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
 
316
#ifdef __GNUC__
 
317
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
 
318
#else
 
319
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
 
320
#endif
 
321
attribute_deprecated void put_flush_packet(AVIOContext *s);
 
322
attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
 
323
attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
 
324
attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
 
325
attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h);
 
326
/**
 
327
 * @}
 
328
 */
 
329
 
 
330
/**
 
331
 * @deprecated use AVIOContext.eof_reached
 
332
 */
 
333
attribute_deprecated int url_feof(AVIOContext *s);
 
334
attribute_deprecated int url_ferror(AVIOContext *s);
 
335
 
 
336
attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri);
 
337
attribute_deprecated int udp_get_local_port(URLContext *h);
 
338
 
 
339
attribute_deprecated void init_checksum(AVIOContext *s,
 
340
                   unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
 
341
                   unsigned long checksum);
 
342
attribute_deprecated unsigned long get_checksum(AVIOContext *s);
 
343
#endif
 
344
 
 
345
/**
 
346
 * Allocate and initialize an AVIOContext for buffered I/O. It must be later
 
347
 * freed with av_free().
 
348
 *
 
349
 * @param buffer Memory block for input/output operations via AVIOContext.
 
350
 * @param buffer_size The buffer size is very important for performance.
 
351
 *        For protocols with fixed blocksize it should be set to this blocksize.
 
352
 *        For others a typical size is a cache page, e.g. 4kb.
 
353
 * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
 
354
 * @param opaque An opaque pointer to user-specific data.
 
355
 * @param read_packet  A function for refilling the buffer, may be NULL.
 
356
 * @param write_packet A function for writing the buffer contents, may be NULL.
 
357
 * @param seek A function for seeking to specified byte position, may be NULL.
 
358
 *
 
359
 * @return Allocated AVIOContext or NULL on failure.
 
360
 */
 
361
AVIOContext *avio_alloc_context(
 
362
                  unsigned char *buffer,
 
363
                  int buffer_size,
 
364
                  int write_flag,
 
365
                  void *opaque,
 
366
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
 
367
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
 
368
                  int64_t (*seek)(void *opaque, int64_t offset, int whence));
 
369
 
 
370
void avio_w8(AVIOContext *s, int b);
 
371
void avio_write(AVIOContext *s, const unsigned char *buf, int size);
 
372
void avio_wl64(AVIOContext *s, uint64_t val);
 
373
void avio_wb64(AVIOContext *s, uint64_t val);
 
374
void avio_wl32(AVIOContext *s, unsigned int val);
 
375
void avio_wb32(AVIOContext *s, unsigned int val);
 
376
void avio_wl24(AVIOContext *s, unsigned int val);
 
377
void avio_wb24(AVIOContext *s, unsigned int val);
 
378
void avio_wl16(AVIOContext *s, unsigned int val);
 
379
void avio_wb16(AVIOContext *s, unsigned int val);
 
380
 
 
381
#if FF_API_OLD_AVIO
 
382
attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
 
383
#endif
 
384
 
 
385
/**
 
386
 * Write a NULL-terminated string.
 
387
 * @return number of bytes written.
 
388
 */
 
389
int avio_put_str(AVIOContext *s, const char *str);
 
390
 
 
391
/**
 
392
 * Convert an UTF-8 string to UTF-16LE and write it.
 
393
 * @return number of bytes written.
 
394
 */
 
395
int avio_put_str16le(AVIOContext *s, const char *str);
 
396
 
 
397
/**
 
398
 * Passing this as the "whence" parameter to a seek function causes it to
 
399
 * return the filesize without seeking anywhere. Supporting this is optional.
 
400
 * If it is not supported then the seek function will return <0.
 
401
 */
 
402
#define AVSEEK_SIZE 0x10000
 
403
 
 
404
/**
 
405
 * Oring this flag as into the "whence" parameter to a seek function causes it to
 
406
 * seek by any means (like reopening and linear reading) or other normally unreasonble
 
407
 * means that can be extreemly slow.
 
408
 * This may be ignored by the seek code.
 
409
 */
 
410
#define AVSEEK_FORCE 0x20000
 
411
 
 
412
/**
 
413
 * fseek() equivalent for AVIOContext.
 
414
 * @return new position or AVERROR.
 
415
 */
 
416
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
 
417
 
 
418
/**
 
419
 * Skip given number of bytes forward
 
420
 * @return new position or AVERROR.
 
421
 */
 
422
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
 
423
{
 
424
    return avio_seek(s, offset, SEEK_CUR);
 
425
}
 
426
 
 
427
/**
 
428
 * ftell() equivalent for AVIOContext.
385
429
 * @return position or AVERROR.
386
430
 */
387
 
int64_t url_ftell(ByteIOContext *s);
 
431
static av_always_inline int64_t avio_tell(AVIOContext *s)
 
432
{
 
433
    return avio_seek(s, 0, SEEK_CUR);
 
434
}
388
435
 
389
436
/**
390
437
 * Get the filesize.
391
438
 * @return filesize or AVERROR
392
439
 */
393
 
int64_t url_fsize(ByteIOContext *s);
394
 
 
395
 
/**
396
 
 * feof() equivalent for ByteIOContext.
397
 
 * @return non zero if and only if end of file
398
 
 */
399
 
int url_feof(ByteIOContext *s);
400
 
 
401
 
int url_ferror(ByteIOContext *s);
402
 
 
403
 
int av_url_read_fpause(ByteIOContext *h, int pause);
404
 
int64_t av_url_read_fseek(ByteIOContext *h, int stream_index,
405
 
                          int64_t timestamp, int flags);
406
 
 
407
 
#define URL_EOF (-1)
408
 
/** @note return URL_EOF (-1) if EOF */
409
 
int url_fgetc(ByteIOContext *s);
 
440
int64_t avio_size(AVIOContext *s);
410
441
 
411
442
/** @warning currently size is limited */
412
443
#ifdef __GNUC__
413
 
int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
 
444
int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
414
445
#else
415
 
int url_fprintf(ByteIOContext *s, const char *fmt, ...);
 
446
int avio_printf(AVIOContext *s, const char *fmt, ...);
416
447
#endif
417
448
 
 
449
#if FF_API_OLD_AVIO
418
450
/** @note unlike fgets, the EOL character is not returned and a whole
419
451
    line is parsed. return NULL if first char read was EOF */
420
 
char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
421
 
 
422
 
void put_flush_packet(ByteIOContext *s);
423
 
 
424
 
 
425
 
/**
426
 
 * Read size bytes from ByteIOContext into buf.
427
 
 * @return number of bytes read or AVERROR
428
 
 */
429
 
int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
430
 
 
431
 
/**
432
 
 * Read size bytes from ByteIOContext into buf.
433
 
 * This reads at most 1 packet. If that is not enough fewer bytes will be
434
 
 * returned.
435
 
 * @return number of bytes read or AVERROR
436
 
 */
437
 
int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
 
452
attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
 
453
#endif
 
454
 
 
455
void avio_flush(AVIOContext *s);
 
456
 
 
457
 
 
458
/**
 
459
 * Read size bytes from AVIOContext into buf.
 
460
 * @return number of bytes read or AVERROR
 
461
 */
 
462
int avio_read(AVIOContext *s, unsigned char *buf, int size);
438
463
 
439
464
/** @note return 0 if EOF, so you cannot use it if EOF handling is
440
465
    necessary */
441
 
int get_byte(ByteIOContext *s);
442
 
unsigned int get_le24(ByteIOContext *s);
443
 
unsigned int get_le32(ByteIOContext *s);
444
 
uint64_t get_le64(ByteIOContext *s);
445
 
unsigned int get_le16(ByteIOContext *s);
446
 
 
447
 
char *get_strz(ByteIOContext *s, char *buf, int maxlen);
448
 
unsigned int get_be16(ByteIOContext *s);
449
 
unsigned int get_be24(ByteIOContext *s);
450
 
unsigned int get_be32(ByteIOContext *s);
451
 
uint64_t get_be64(ByteIOContext *s);
452
 
 
453
 
uint64_t ff_get_v(ByteIOContext *bc);
454
 
 
455
 
static inline int url_is_streamed(ByteIOContext *s)
 
466
int          avio_r8  (AVIOContext *s);
 
467
unsigned int avio_rl16(AVIOContext *s);
 
468
unsigned int avio_rl24(AVIOContext *s);
 
469
unsigned int avio_rl32(AVIOContext *s);
 
470
uint64_t     avio_rl64(AVIOContext *s);
 
471
 
 
472
/**
 
473
 * Read a string from pb into buf. The reading will terminate when either
 
474
 * a NULL character was encountered, maxlen bytes have been read, or nothing
 
475
 * more can be read from pb. The result is guaranteed to be NULL-terminated, it
 
476
 * will be truncated if buf is too small.
 
477
 * Note that the string is not interpreted or validated in any way, it
 
478
 * might get truncated in the middle of a sequence for multi-byte encodings.
 
479
 *
 
480
 * @return number of bytes read (is always <= maxlen).
 
481
 * If reading ends on EOF or error, the return value will be one more than
 
482
 * bytes actually read.
 
483
 */
 
484
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
 
485
 
 
486
/**
 
487
 * Read a UTF-16 string from pb and convert it to UTF-8.
 
488
 * The reading will terminate when either a null or invalid character was
 
489
 * encountered or maxlen bytes have been read.
 
490
 * @return number of bytes read (is always <= maxlen)
 
491
 */
 
492
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
 
493
int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
 
494
 
 
495
#if FF_API_OLD_AVIO
 
496
/**
 
497
 * @deprecated use avio_get_str instead
 
498
 */
 
499
attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
 
500
#endif
 
501
unsigned int avio_rb16(AVIOContext *s);
 
502
unsigned int avio_rb24(AVIOContext *s);
 
503
unsigned int avio_rb32(AVIOContext *s);
 
504
uint64_t     avio_rb64(AVIOContext *s);
 
505
 
 
506
#if FF_API_OLD_AVIO
 
507
/**
 
508
 * @deprecated Use AVIOContext.seekable field directly.
 
509
 */
 
510
attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
456
511
{
457
 
    return s->is_streamed;
 
512
    return !s->seekable;
458
513
}
459
 
 
460
 
/**
461
 
 * Create and initialize a ByteIOContext for accessing the
462
 
 * resource referenced by the URLContext h.
463
 
 * @note When the URLContext h has been opened in read+write mode, the
464
 
 * ByteIOContext can be used only for writing.
465
 
 *
466
 
 * @param s Used to return the pointer to the created ByteIOContext.
467
 
 * In case of failure the pointed to value is set to NULL.
468
 
 * @return 0 in case of success, a negative value corresponding to an
469
 
 * AVERROR code in case of failure
470
 
 */
471
 
int url_fdopen(ByteIOContext **s, URLContext *h);
472
 
 
473
 
/** @warning must be called before any I/O */
474
 
int url_setbufsize(ByteIOContext *s, int buf_size);
 
514
#endif
 
515
 
475
516
#if FF_API_URL_RESETBUF
476
517
/** Reset the buffer for reading or writing.
477
518
 * @note Will drop any data currently in the buffer without transmitting it.
478
519
 * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY
479
520
 *        to set up the buffer for writing. */
480
 
int url_resetbuf(ByteIOContext *s, int flags);
 
521
int url_resetbuf(AVIOContext *s, int flags);
481
522
#endif
482
523
 
483
524
/**
484
 
 * Rewind the ByteIOContext using the specified buffer containing the first buf_size bytes of the file.
485
 
 * Used after probing to avoid seeking.
486
 
 * Joins buf and s->buffer, taking any overlap into consideration.
487
 
 * @note s->buffer must overlap with buf or they can't be joined and the function fails
488
 
 * @note This function is NOT part of the public API
489
 
 *
490
 
 * @param s The read-only ByteIOContext to rewind
491
 
 * @param buf The probe buffer containing the first buf_size bytes of the file
492
 
 * @param buf_size The size of buf
493
 
 * @return 0 in case of success, a negative value corresponding to an
494
 
 * AVERROR code in case of failure
495
 
 */
496
 
int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size);
497
 
 
498
 
/**
499
 
 * Create and initialize a ByteIOContext for accessing the
 
525
 * @defgroup open_modes URL open modes
 
526
 * The flags argument to avio_open must be one of the following
 
527
 * constants, optionally ORed with other flags.
 
528
 * @{
 
529
 */
 
530
#define AVIO_RDONLY 0  /**< read-only */
 
531
#define AVIO_WRONLY 1  /**< write-only */
 
532
#define AVIO_RDWR   2  /**< read-write */
 
533
/**
 
534
 * @}
 
535
 */
 
536
 
 
537
/**
 
538
 * Use non-blocking mode.
 
539
 * If this flag is set, operations on the context will return
 
540
 * AVERROR(EAGAIN) if they can not be performed immediately.
 
541
 * If this flag is not set, operations on the context will never return
 
542
 * AVERROR(EAGAIN).
 
543
 * Note that this flag does not affect the opening/connecting of the
 
544
 * context. Connecting a protocol will always block if necessary (e.g. on
 
545
 * network protocols) but never hang (e.g. on busy devices).
 
546
 * Warning: non-blocking protocols is work-in-progress; this flag may be
 
547
 * silently ignored.
 
548
 */
 
549
#define AVIO_FLAG_NONBLOCK 4
 
550
 
 
551
/**
 
552
 * Create and initialize a AVIOContext for accessing the
500
553
 * resource indicated by url.
501
554
 * @note When the resource indicated by url has been opened in
502
 
 * read+write mode, the ByteIOContext can be used only for writing.
 
555
 * read+write mode, the AVIOContext can be used only for writing.
503
556
 *
504
 
 * @param s Used to return the pointer to the created ByteIOContext.
 
557
 * @param s Used to return the pointer to the created AVIOContext.
505
558
 * In case of failure the pointed to value is set to NULL.
506
559
 * @param flags flags which control how the resource indicated by url
507
560
 * is to be opened
508
561
 * @return 0 in case of success, a negative value corresponding to an
509
562
 * AVERROR code in case of failure
510
563
 */
511
 
int url_fopen(ByteIOContext **s, const char *url, int flags);
512
 
 
513
 
int url_fclose(ByteIOContext *s);
514
 
URLContext *url_fileno(ByteIOContext *s);
 
564
int avio_open(AVIOContext **s, const char *url, int flags);
 
565
 
 
566
int avio_close(AVIOContext *s);
 
567
 
 
568
#if FF_API_OLD_AVIO
 
569
attribute_deprecated URLContext *url_fileno(AVIOContext *s);
515
570
 
516
571
/**
517
 
 * Return the maximum packet size associated to packetized buffered file
518
 
 * handle. If the file is not packetized (stream like http or file on
519
 
 * disk), then 0 is returned.
520
 
 *
521
 
 * @param s buffered file handle
522
 
 * @return maximum packet size in bytes
 
572
 * @deprecated use AVIOContext.max_packet_size directly.
523
573
 */
524
 
int url_fget_max_packet_size(ByteIOContext *s);
 
574
attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
525
575
 
526
 
int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags);
 
576
attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
527
577
 
528
578
/** return the written or read size */
529
 
int url_close_buf(ByteIOContext *s);
 
579
attribute_deprecated int url_close_buf(AVIOContext *s);
 
580
#endif
530
581
 
531
582
/**
532
583
 * Open a write only memory stream.
534
585
 * @param s new IO context
535
586
 * @return zero if no error.
536
587
 */
537
 
int url_open_dyn_buf(ByteIOContext **s);
538
 
 
539
 
/**
540
 
 * Open a write only packetized memory stream with a maximum packet
541
 
 * size of 'max_packet_size'.  The stream is stored in a memory buffer
542
 
 * with a big endian 4 byte header giving the packet size in bytes.
543
 
 *
544
 
 * @param s new IO context
545
 
 * @param max_packet_size maximum packet size (must be > 0)
546
 
 * @return zero if no error.
547
 
 */
548
 
int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size);
 
588
int avio_open_dyn_buf(AVIOContext **s);
549
589
 
550
590
/**
551
591
 * Return the written size and a pointer to the buffer. The buffer
552
 
 * must be freed with av_free(). If the buffer is opened with
553
 
 * url_open_dyn_buf, then padding of FF_INPUT_BUFFER_PADDING_SIZE is
554
 
 * added; if opened with url_open_dyn_packet_buf, no padding is added.
 
592
 * must be freed with av_free().
 
593
 * Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer.
555
594
 *
556
595
 * @param s IO context
557
596
 * @param pbuffer pointer to a byte buffer
558
597
 * @return the length of the byte buffer
559
598
 */
560
 
int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
561
 
 
562
 
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
563
 
                                    unsigned int len);
564
 
unsigned long get_checksum(ByteIOContext *s);
565
 
void init_checksum(ByteIOContext *s,
566
 
                   unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
567
 
                   unsigned long checksum);
568
 
 
569
 
/* udp.c */
570
 
int udp_set_remote_url(URLContext *h, const char *uri);
571
 
int udp_get_local_port(URLContext *h);
 
599
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
 
600
 
572
601
#if FF_API_UDP_GET_FILE
573
602
int udp_get_file_handle(URLContext *h);
574
603
#endif
575
604
 
 
605
/**
 
606
 * Iterate through names of available protocols.
 
607
 *
 
608
 * @param opaque A private pointer representing current protocol.
 
609
 *        It must be a pointer to NULL on first iteration and will
 
610
 *        be updated by successive calls to avio_enum_protocols.
 
611
 * @param output If set to 1, iterate over output protocols,
 
612
 *               otherwise over input protocols.
 
613
 *
 
614
 * @return A static string containing the name of current protocol or NULL
 
615
 */
 
616
const char *avio_enum_protocols(void **opaque, int output);
 
617
 
576
618
#endif /* AVFORMAT_AVIO_H */