2006-09-10 14:02:42 +00:00
|
|
|
/*
|
|
|
|
* copyright (c) 2001 Fabrice Bellard
|
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2006-09-10 14:02:42 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-09-10 14:02:42 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2006-09-10 14:02:42 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-09-10 14:02:42 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2008-08-31 07:39:47 +00:00
|
|
|
#ifndef AVFORMAT_AVIO_H
|
|
|
|
#define AVFORMAT_AVIO_H
|
2002-07-24 17:49:11 +00:00
|
|
|
|
2009-02-26 22:28:42 +00:00
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2009-02-26 22:28:42 +00:00
|
|
|
* unbuffered I/O operations
|
2009-02-26 22:34:18 +00:00
|
|
|
*
|
|
|
|
* @warning This file has to be considered an internal but installed
|
|
|
|
* header, so it should not be directly included in your projects.
|
2009-02-26 22:28:42 +00:00
|
|
|
*/
|
|
|
|
|
2007-06-16 22:59:13 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2009-02-17 21:43:57 +00:00
|
|
|
#include "libavutil/common.h"
|
2010-06-23 11:26:33 +00:00
|
|
|
#include "libavutil/log.h"
|
2009-02-17 21:43:57 +00:00
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
/* unbuffered I/O */
|
|
|
|
|
2007-12-20 22:33:53 +00:00
|
|
|
/**
|
|
|
|
* URL Context.
|
|
|
|
* New fields can be added to the end with minor version bumps.
|
2007-12-21 11:50:18 +00:00
|
|
|
* Removal, reordering and changes to existing fields require a major
|
2007-12-20 22:33:53 +00:00
|
|
|
* version bump.
|
2007-12-21 11:50:18 +00:00
|
|
|
* sizeof(URLContext) must not be used outside libav*.
|
2007-12-20 22:33:53 +00:00
|
|
|
*/
|
2009-05-25 22:17:27 +00:00
|
|
|
typedef struct URLContext {
|
2010-08-19 16:49:08 +00:00
|
|
|
#if FF_API_URL_CLASS
|
2008-03-10 19:03:39 +00:00
|
|
|
const AVClass *av_class; ///< information for av_log(). Set by url_open().
|
|
|
|
#endif
|
2001-07-22 14:18:56 +00:00
|
|
|
struct URLProtocol *prot;
|
2005-12-17 18:14:38 +00:00
|
|
|
int flags;
|
2007-03-05 15:18:50 +00:00
|
|
|
int is_streamed; /**< true if streamed (no seek possible), default = false */
|
|
|
|
int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
|
2001-07-22 14:18:56 +00:00
|
|
|
void *priv_data;
|
2010-01-24 18:18:03 +00:00
|
|
|
char *filename; /**< specified URL */
|
2010-06-22 14:03:37 +00:00
|
|
|
int is_connected;
|
2009-05-25 22:17:27 +00:00
|
|
|
} URLContext;
|
2001-07-22 14:18:56 +00:00
|
|
|
|
|
|
|
typedef struct URLPollEntry {
|
|
|
|
URLContext *handle;
|
|
|
|
int events;
|
|
|
|
int revents;
|
|
|
|
} URLPollEntry;
|
|
|
|
|
|
|
|
#define URL_RDONLY 0
|
|
|
|
#define URL_WRONLY 1
|
2002-07-24 17:49:11 +00:00
|
|
|
#define URL_RDWR 2
|
|
|
|
|
2003-07-17 10:25:36 +00:00
|
|
|
typedef int URLInterruptCB(void);
|
|
|
|
|
2010-01-24 13:31:25 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Create a URLContext for accessing to the resource indicated by
|
|
|
|
* url, and open it using the URLProtocol up.
|
2010-01-24 13:31:25 +00:00
|
|
|
*
|
|
|
|
* @param puc pointer to the location where, in case of success, the
|
|
|
|
* function puts the pointer to the created URLContext
|
2010-01-24 18:18:03 +00:00
|
|
|
* @param flags flags which control how the resource indicated by url
|
2010-01-24 13:31:25 +00:00
|
|
|
* is to be opened
|
|
|
|
* @return 0 in case of success, a negative value corresponding to an
|
|
|
|
* AVERROR code in case of failure
|
|
|
|
*/
|
2008-08-19 23:44:23 +00:00
|
|
|
int url_open_protocol (URLContext **puc, struct URLProtocol *up,
|
2010-01-24 18:18:03 +00:00
|
|
|
const char *url, int flags);
|
2010-01-24 13:31:25 +00:00
|
|
|
|
2010-06-22 14:03:37 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Create a URLContext for accessing to the resource indicated by
|
|
|
|
* url, but do not initiate the connection yet.
|
2010-06-22 14:03:37 +00:00
|
|
|
*
|
|
|
|
* @param puc pointer to the location where, in case of success, the
|
|
|
|
* function puts the pointer to the created URLContext
|
|
|
|
* @param flags flags which control how the resource indicated by url
|
|
|
|
* is to be opened
|
|
|
|
* @return 0 in case of success, a negative value corresponding to an
|
|
|
|
* AVERROR code in case of failure
|
|
|
|
*/
|
|
|
|
int url_alloc(URLContext **h, const char *url, int flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect an URLContext that has been allocated by url_alloc
|
|
|
|
*/
|
|
|
|
int url_connect(URLContext *h);
|
|
|
|
|
2010-01-24 22:07:32 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Create an URLContext for accessing to the resource indicated by
|
|
|
|
* url, and open it.
|
2010-01-24 22:07:32 +00:00
|
|
|
*
|
|
|
|
* @param puc pointer to the location where, in case of success, the
|
|
|
|
* function puts the pointer to the created URLContext
|
|
|
|
* @param flags flags which control how the resource indicated by url
|
|
|
|
* is to be opened
|
|
|
|
* @return 0 in case of success, a negative value corresponding to an
|
|
|
|
* AVERROR code in case of failure
|
|
|
|
*/
|
2010-01-24 18:18:03 +00:00
|
|
|
int url_open(URLContext **h, const char *url, int flags);
|
2010-01-24 13:07:54 +00:00
|
|
|
|
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Read up to size bytes from the resource accessed by h, and store
|
2010-01-24 13:07:54 +00:00
|
|
|
* the read bytes in buf.
|
|
|
|
*
|
|
|
|
* @return The number of bytes actually read, or a negative value
|
|
|
|
* corresponding to an AVERROR code in case of error. A value of zero
|
|
|
|
* indicates that it is not possible to read more from the accessed
|
|
|
|
* resource (except if the value of the size argument is also zero).
|
|
|
|
*/
|
2001-07-22 14:18:56 +00:00
|
|
|
int url_read(URLContext *h, unsigned char *buf, int size);
|
2010-01-24 13:07:54 +00:00
|
|
|
|
2010-01-23 10:23:47 +00:00
|
|
|
/**
|
|
|
|
* Read as many bytes as possible (up to size), calling the
|
|
|
|
* read function multiple times if necessary.
|
|
|
|
* Will also retry if the read function returns AVERROR(EAGAIN).
|
|
|
|
* This makes special short-read handling in applications
|
|
|
|
* unnecessary, if the return value is < size then it is
|
|
|
|
* certain there was either an error or the end of file was reached.
|
|
|
|
*/
|
2009-06-04 06:25:53 +00:00
|
|
|
int url_read_complete(URLContext *h, unsigned char *buf, int size);
|
2010-10-31 16:11:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write size bytes from buf to the resource accessed by h.
|
|
|
|
*
|
|
|
|
* @return the number of bytes actually written, or a negative value
|
|
|
|
* corresponding to an AVERROR code in case of failure
|
|
|
|
*/
|
2010-06-01 07:46:23 +00:00
|
|
|
int url_write(URLContext *h, const unsigned char *buf, int size);
|
2010-03-28 10:31:22 +00:00
|
|
|
|
2010-10-06 18:42:46 +00:00
|
|
|
/**
|
|
|
|
* Passing this as the "whence" parameter to a seek function causes it to
|
|
|
|
* return the filesize without seeking anywhere. Supporting this is optional.
|
|
|
|
* If it is not supported then the seek function will return <0.
|
|
|
|
*/
|
|
|
|
#define AVSEEK_SIZE 0x10000
|
|
|
|
|
2010-03-28 10:31:22 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Change the position that will be used by the next read/write
|
2010-03-28 10:31:22 +00:00
|
|
|
* operation on the resource accessed by h.
|
|
|
|
*
|
|
|
|
* @param pos specifies the new position to set
|
|
|
|
* @param whence specifies how pos should be interpreted, it must be
|
|
|
|
* one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
|
|
|
|
* current position), SEEK_END (seek from the end), or AVSEEK_SIZE
|
|
|
|
* (return the filesize of the requested resource, pos is ignored).
|
|
|
|
* @return a negative value corresponding to an AVERROR code in case
|
|
|
|
* of failure, or the resulting file position, measured in bytes from
|
|
|
|
* the beginning of the file. You can use this feature together with
|
|
|
|
* SEEK_CUR to read the current file position.
|
|
|
|
*/
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t url_seek(URLContext *h, int64_t pos, int whence);
|
2010-01-24 16:33:56 +00:00
|
|
|
|
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Close the resource accessed by the URLContext h, and free the
|
2010-01-24 16:33:56 +00:00
|
|
|
* memory used by it.
|
|
|
|
*
|
|
|
|
* @return a negative value if an error condition occurred, 0
|
|
|
|
* otherwise
|
|
|
|
*/
|
2001-07-22 14:18:56 +00:00
|
|
|
int url_close(URLContext *h);
|
2010-01-24 16:33:56 +00:00
|
|
|
|
2010-03-29 22:29:14 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Return a non-zero value if the resource indicated by url
|
2010-03-29 22:29:14 +00:00
|
|
|
* exists, 0 otherwise.
|
|
|
|
*/
|
2010-01-24 18:18:03 +00:00
|
|
|
int url_exist(const char *url);
|
2010-03-29 22:29:14 +00:00
|
|
|
|
2010-09-30 10:55:08 +00:00
|
|
|
/**
|
|
|
|
* Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
|
|
|
|
* if the operation is not supported by h, or another negative value
|
|
|
|
* corresponding to an AVERROR error code in case of failure.
|
|
|
|
*/
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t url_filesize(URLContext *h);
|
2007-03-05 14:26:50 +00:00
|
|
|
|
2009-03-03 17:04:51 +00:00
|
|
|
/**
|
|
|
|
* Return the file descriptor associated with this URL. For RTP, this
|
|
|
|
* will return only the RTP file descriptor, not the RTCP file descriptor.
|
|
|
|
*
|
|
|
|
* @return the file descriptor associated with this URL, or <0 on error.
|
|
|
|
*/
|
|
|
|
int url_get_file_handle(URLContext *h);
|
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/**
|
2007-03-05 14:26:50 +00:00
|
|
|
* Return the maximum packet size associated to packetized file
|
2007-12-21 11:50:18 +00:00
|
|
|
* handle. If the file is not packetized (stream like HTTP or file on
|
2007-03-05 14:26:50 +00:00
|
|
|
* disk), then 0 is returned.
|
|
|
|
*
|
|
|
|
* @param h file handle
|
|
|
|
* @return maximum packet size in bytes
|
|
|
|
*/
|
2002-07-24 17:49:11 +00:00
|
|
|
int url_get_max_packet_size(URLContext *h);
|
2010-10-02 09:16:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the filename of the resource accessed by h to buf.
|
|
|
|
*
|
|
|
|
* @param buf_size size in bytes of buf
|
|
|
|
*/
|
2003-01-11 04:59:17 +00:00
|
|
|
void url_get_filename(URLContext *h, char *buf, int buf_size);
|
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/**
|
2007-12-21 11:50:18 +00:00
|
|
|
* The callback is called in blocking functions to test regulary if
|
2007-03-05 15:18:50 +00:00
|
|
|
* asynchronous interruption is needed. AVERROR(EINTR) is returned
|
|
|
|
* in this case by the interrupted function. 'NULL' means no interrupt
|
2007-12-21 11:50:18 +00:00
|
|
|
* callback is given.
|
2007-03-05 15:18:50 +00:00
|
|
|
*/
|
2003-07-17 10:25:36 +00:00
|
|
|
void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
|
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
/* not implemented */
|
|
|
|
int url_poll(URLPollEntry *poll_table, int n, int timeout);
|
|
|
|
|
2007-12-19 20:57:13 +00:00
|
|
|
/**
|
|
|
|
* Pause and resume playing - only meaningful if using a network streaming
|
|
|
|
* protocol (e.g. MMS).
|
|
|
|
* @param pause 1 for pause, 0 for resume
|
|
|
|
*/
|
|
|
|
int av_url_read_pause(URLContext *h, int pause);
|
2007-12-21 11:50:18 +00:00
|
|
|
|
2007-11-24 07:09:32 +00:00
|
|
|
/**
|
|
|
|
* Seek to a given timestamp relative to some component stream.
|
2007-12-21 11:50:18 +00:00
|
|
|
* Only meaningful if using a network streaming protocol (e.g. MMS.).
|
2007-11-24 07:09:32 +00:00
|
|
|
* @param stream_index The stream index that the timestamp is relative to.
|
|
|
|
* If stream_index is (-1) the timestamp should be in AV_TIME_BASE
|
|
|
|
* units from the beginning of the presentation.
|
|
|
|
* If a stream_index >= 0 is used and the protocol does not support
|
|
|
|
* seeking based on component streams, the call will fail with ENOTSUP.
|
2007-12-21 11:51:39 +00:00
|
|
|
* @param timestamp timestamp in AVStream.time_base units
|
2007-11-24 07:09:32 +00:00
|
|
|
* or if there is no stream specified then in AV_TIME_BASE units.
|
|
|
|
* @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
|
|
|
|
* and AVSEEK_FLAG_ANY. The protocol may silently ignore
|
|
|
|
* AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
|
|
|
|
* fail with ENOTSUP if used and not supported.
|
|
|
|
* @return >= 0 on success
|
|
|
|
* @see AVInputFormat::read_seek
|
|
|
|
*/
|
2008-12-13 13:39:13 +00:00
|
|
|
int64_t av_url_read_seek(URLContext *h, int stream_index,
|
|
|
|
int64_t timestamp, int flags);
|
2007-11-24 07:09:32 +00:00
|
|
|
|
2010-03-15 22:54:22 +00:00
|
|
|
/**
|
|
|
|
* Oring this flag as into the "whence" parameter to a seek function causes it to
|
|
|
|
* seek by any means (like reopening and linear reading) or other normally unreasonble
|
|
|
|
* means that can be extreemly slow.
|
|
|
|
* This may be ignored by the seek code.
|
|
|
|
*/
|
|
|
|
#define AVSEEK_FORCE 0x20000
|
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
typedef struct URLProtocol {
|
|
|
|
const char *name;
|
2010-01-24 18:18:03 +00:00
|
|
|
int (*url_open)(URLContext *h, const char *url, int flags);
|
2001-07-22 14:18:56 +00:00
|
|
|
int (*url_read)(URLContext *h, unsigned char *buf, int size);
|
2010-06-01 07:46:23 +00:00
|
|
|
int (*url_write)(URLContext *h, const unsigned char *buf, int size);
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
|
2001-07-22 14:18:56 +00:00
|
|
|
int (*url_close)(URLContext *h);
|
|
|
|
struct URLProtocol *next;
|
2007-12-19 20:57:13 +00:00
|
|
|
int (*url_read_pause)(URLContext *h, int pause);
|
2008-12-13 13:39:13 +00:00
|
|
|
int64_t (*url_read_seek)(URLContext *h, int stream_index,
|
|
|
|
int64_t timestamp, int flags);
|
2009-03-03 17:04:51 +00:00
|
|
|
int (*url_get_file_handle)(URLContext *h);
|
2010-06-22 14:09:08 +00:00
|
|
|
int priv_data_size;
|
|
|
|
const AVClass *priv_data_class;
|
2001-07-22 14:18:56 +00:00
|
|
|
} URLProtocol;
|
|
|
|
|
2010-08-19 21:21:32 +00:00
|
|
|
#if FF_API_REGISTER_PROTOCOL
|
2001-07-22 14:18:56 +00:00
|
|
|
extern URLProtocol *first_protocol;
|
2009-02-15 14:34:23 +00:00
|
|
|
#endif
|
|
|
|
|
2003-07-17 10:25:36 +00:00
|
|
|
extern URLInterruptCB *url_interrupt_cb;
|
2001-07-22 14:18:56 +00:00
|
|
|
|
2009-02-15 14:31:18 +00:00
|
|
|
/**
|
|
|
|
* If protocol is NULL, returns the first registered protocol,
|
2009-02-15 20:45:10 +00:00
|
|
|
* if protocol is non-NULL, returns the next registered protocol after protocol,
|
2009-02-15 14:31:18 +00:00
|
|
|
* or NULL if protocol is the last one.
|
|
|
|
*/
|
2007-12-12 19:01:58 +00:00
|
|
|
URLProtocol *av_protocol_next(URLProtocol *p);
|
|
|
|
|
2010-08-19 21:21:32 +00:00
|
|
|
#if FF_API_REGISTER_PROTOCOL
|
2009-02-15 14:25:23 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Use av_register_protocol() instead.
|
|
|
|
*/
|
|
|
|
attribute_deprecated int register_protocol(URLProtocol *protocol);
|
2010-06-22 13:58:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated Use av_register_protocol2() instead.
|
|
|
|
*/
|
|
|
|
attribute_deprecated int av_register_protocol(URLProtocol *protocol);
|
2009-02-15 14:25:23 +00:00
|
|
|
#endif
|
|
|
|
|
2010-01-27 00:21:28 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Register the URLProtocol protocol.
|
2010-06-22 13:58:48 +00:00
|
|
|
*
|
|
|
|
* @param size the size of the URLProtocol struct referenced
|
2010-01-27 00:21:28 +00:00
|
|
|
*/
|
2010-06-22 13:58:48 +00:00
|
|
|
int av_register_protocol2(URLProtocol *protocol, int size);
|
2001-07-22 14:18:56 +00:00
|
|
|
|
2007-12-20 22:33:53 +00:00
|
|
|
/**
|
|
|
|
* Bytestream IO Context.
|
|
|
|
* New fields can be added to the end with minor version bumps.
|
2007-12-21 11:50:18 +00:00
|
|
|
* Removal, reordering and changes to existing fields require a major
|
2007-12-20 22:33:53 +00:00
|
|
|
* version bump.
|
2007-12-21 11:50:18 +00:00
|
|
|
* sizeof(ByteIOContext) must not be used outside libav*.
|
2007-12-20 22:33:53 +00:00
|
|
|
*/
|
2001-07-22 14:18:56 +00:00
|
|
|
typedef struct {
|
|
|
|
unsigned char *buffer;
|
|
|
|
int buffer_size;
|
|
|
|
unsigned char *buf_ptr, *buf_end;
|
|
|
|
void *opaque;
|
2003-02-11 16:35:48 +00:00
|
|
|
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
|
2004-10-08 20:09:52 +00:00
|
|
|
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t (*seek)(void *opaque, int64_t offset, int whence);
|
|
|
|
int64_t pos; /**< position in the file of the current buffer */
|
2007-03-05 15:18:50 +00:00
|
|
|
int must_flush; /**< true if the next seek should flush */
|
|
|
|
int eof_reached; /**< true if eof reached */
|
|
|
|
int write_flag; /**< true if open for writing */
|
2001-07-22 14:18:56 +00:00
|
|
|
int is_streamed;
|
2002-07-24 17:49:11 +00:00
|
|
|
int max_packet_size;
|
2004-04-05 12:02:10 +00:00
|
|
|
unsigned long checksum;
|
|
|
|
unsigned char *checksum_ptr;
|
|
|
|
unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
|
2004-10-08 20:09:52 +00:00
|
|
|
int error; ///< contains the error code or 0 if no error happened
|
2007-12-19 20:57:13 +00:00
|
|
|
int (*read_pause)(void *opaque, int pause);
|
2008-12-13 13:39:13 +00:00
|
|
|
int64_t (*read_seek)(void *opaque, int stream_index,
|
|
|
|
int64_t timestamp, int flags);
|
2001-07-22 14:18:56 +00:00
|
|
|
} ByteIOContext;
|
|
|
|
|
|
|
|
int init_put_byte(ByteIOContext *s,
|
|
|
|
unsigned char *buffer,
|
|
|
|
int buffer_size,
|
|
|
|
int write_flag,
|
|
|
|
void *opaque,
|
2007-12-22 16:18:07 +00:00
|
|
|
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
|
|
|
|
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t (*seek)(void *opaque, int64_t offset, int whence));
|
2007-12-22 16:18:07 +00:00
|
|
|
ByteIOContext *av_alloc_put_byte(
|
|
|
|
unsigned char *buffer,
|
|
|
|
int buffer_size,
|
|
|
|
int write_flag,
|
|
|
|
void *opaque,
|
2003-02-11 16:35:48 +00:00
|
|
|
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
|
2004-10-08 20:09:52 +00:00
|
|
|
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t (*seek)(void *opaque, int64_t offset, int whence));
|
2001-07-22 14:18:56 +00:00
|
|
|
|
|
|
|
void put_byte(ByteIOContext *s, int b);
|
2002-09-12 02:26:58 +00:00
|
|
|
void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
|
2003-02-11 16:35:48 +00:00
|
|
|
void put_le64(ByteIOContext *s, uint64_t val);
|
|
|
|
void put_be64(ByteIOContext *s, uint64_t val);
|
2001-07-22 14:18:56 +00:00
|
|
|
void put_le32(ByteIOContext *s, unsigned int val);
|
|
|
|
void put_be32(ByteIOContext *s, unsigned int val);
|
2006-02-09 22:52:23 +00:00
|
|
|
void put_le24(ByteIOContext *s, unsigned int val);
|
2005-07-19 14:41:08 +00:00
|
|
|
void put_be24(ByteIOContext *s, unsigned int val);
|
2001-07-22 14:18:56 +00:00
|
|
|
void put_le16(ByteIOContext *s, unsigned int val);
|
|
|
|
void put_be16(ByteIOContext *s, unsigned int val);
|
2002-11-11 09:20:53 +00:00
|
|
|
void put_tag(ByteIOContext *s, const char *tag);
|
2001-07-22 14:18:56 +00:00
|
|
|
|
2002-10-22 09:23:14 +00:00
|
|
|
void put_strz(ByteIOContext *s, const char *buf);
|
2002-09-12 02:26:58 +00:00
|
|
|
|
2008-03-21 11:27:07 +00:00
|
|
|
/**
|
|
|
|
* fseek() equivalent for ByteIOContext.
|
|
|
|
* @return new position or AVERROR.
|
|
|
|
*/
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence);
|
2008-03-21 11:27:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Skip given number of bytes forward.
|
|
|
|
* @param offset number of bytes
|
2010-07-16 23:20:03 +00:00
|
|
|
* @return 0 on success, <0 on error
|
2008-03-21 11:27:07 +00:00
|
|
|
*/
|
2010-07-16 23:20:03 +00:00
|
|
|
int url_fskip(ByteIOContext *s, int64_t offset);
|
2008-03-21 11:27:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ftell() equivalent for ByteIOContext.
|
|
|
|
* @return position or AVERROR.
|
|
|
|
*/
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t url_ftell(ByteIOContext *s);
|
2008-03-21 11:27:07 +00:00
|
|
|
|
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Get the filesize.
|
2008-03-21 11:27:07 +00:00
|
|
|
* @return filesize or AVERROR
|
|
|
|
*/
|
2008-10-03 10:16:29 +00:00
|
|
|
int64_t url_fsize(ByteIOContext *s);
|
2008-03-21 11:27:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* feof() equivalent for ByteIOContext.
|
|
|
|
* @return non zero if and only if end of file
|
|
|
|
*/
|
2001-07-22 14:18:56 +00:00
|
|
|
int url_feof(ByteIOContext *s);
|
2008-03-21 11:27:07 +00:00
|
|
|
|
2004-10-08 20:09:52 +00:00
|
|
|
int url_ferror(ByteIOContext *s);
|
2001-07-22 14:18:56 +00:00
|
|
|
|
2007-12-19 20:57:13 +00:00
|
|
|
int av_url_read_fpause(ByteIOContext *h, int pause);
|
2008-12-13 13:39:13 +00:00
|
|
|
int64_t av_url_read_fseek(ByteIOContext *h, int stream_index,
|
|
|
|
int64_t timestamp, int flags);
|
2007-11-28 19:46:49 +00:00
|
|
|
|
2002-07-24 17:49:11 +00:00
|
|
|
#define URL_EOF (-1)
|
2007-03-05 15:18:50 +00:00
|
|
|
/** @note return URL_EOF (-1) if EOF */
|
2002-07-24 17:49:11 +00:00
|
|
|
int url_fgetc(ByteIOContext *s);
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/** @warning currently size is limited */
|
2003-08-29 20:33:57 +00:00
|
|
|
#ifdef __GNUC__
|
2003-09-30 17:54:30 +00:00
|
|
|
int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
|
2003-08-29 20:33:57 +00:00
|
|
|
#else
|
|
|
|
int url_fprintf(ByteIOContext *s, const char *fmt, ...);
|
|
|
|
#endif
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/** @note unlike fgets, the EOL character is not returned and a whole
|
2008-12-13 13:39:13 +00:00
|
|
|
line is parsed. return NULL if first char read was EOF */
|
2002-07-24 17:49:11 +00:00
|
|
|
char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
|
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
void put_flush_packet(ByteIOContext *s);
|
|
|
|
|
2008-03-21 22:17:56 +00:00
|
|
|
|
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Read size bytes from ByteIOContext into buf.
|
2010-03-30 15:50:57 +00:00
|
|
|
* @return number of bytes read or AVERROR
|
2008-03-21 22:17:56 +00:00
|
|
|
*/
|
2001-07-22 14:18:56 +00:00
|
|
|
int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
|
2008-03-21 22:17:56 +00:00
|
|
|
|
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Read size bytes from ByteIOContext into buf.
|
2008-03-31 17:31:11 +00:00
|
|
|
* This reads at most 1 packet. If that is not enough fewer bytes will be
|
2008-03-21 22:17:56 +00:00
|
|
|
* returned.
|
2010-03-30 15:50:57 +00:00
|
|
|
* @return number of bytes read or AVERROR
|
2008-03-21 22:17:56 +00:00
|
|
|
*/
|
2004-03-15 03:29:32 +00:00
|
|
|
int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/** @note return 0 if EOF, so you cannot use it if EOF handling is
|
2008-12-13 13:39:13 +00:00
|
|
|
necessary */
|
2001-07-22 14:18:56 +00:00
|
|
|
int get_byte(ByteIOContext *s);
|
2006-02-09 22:52:23 +00:00
|
|
|
unsigned int get_le24(ByteIOContext *s);
|
2001-07-22 14:18:56 +00:00
|
|
|
unsigned int get_le32(ByteIOContext *s);
|
2003-02-11 16:35:48 +00:00
|
|
|
uint64_t get_le64(ByteIOContext *s);
|
2001-07-22 14:18:56 +00:00
|
|
|
unsigned int get_le16(ByteIOContext *s);
|
|
|
|
|
2002-10-22 09:23:14 +00:00
|
|
|
char *get_strz(ByteIOContext *s, char *buf, int maxlen);
|
2001-07-22 14:18:56 +00:00
|
|
|
unsigned int get_be16(ByteIOContext *s);
|
2005-07-19 14:41:08 +00:00
|
|
|
unsigned int get_be24(ByteIOContext *s);
|
2001-07-22 14:18:56 +00:00
|
|
|
unsigned int get_be32(ByteIOContext *s);
|
2003-02-11 16:35:48 +00:00
|
|
|
uint64_t get_be64(ByteIOContext *s);
|
2001-07-22 14:18:56 +00:00
|
|
|
|
2007-11-03 18:29:16 +00:00
|
|
|
uint64_t ff_get_v(ByteIOContext *bc);
|
2007-11-03 18:26:42 +00:00
|
|
|
|
2002-05-09 01:16:45 +00:00
|
|
|
static inline int url_is_streamed(ByteIOContext *s)
|
2001-07-22 14:18:56 +00:00
|
|
|
{
|
|
|
|
return s->is_streamed;
|
|
|
|
}
|
|
|
|
|
2010-02-05 23:03:32 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Create and initialize a ByteIOContext for accessing the
|
2010-02-05 23:03:32 +00:00
|
|
|
* resource referenced by the URLContext h.
|
|
|
|
* @note When the URLContext h has been opened in read+write mode, the
|
|
|
|
* ByteIOContext can be used only for writing.
|
|
|
|
*
|
|
|
|
* @param s Used to return the pointer to the created ByteIOContext.
|
|
|
|
* In case of failure the pointed to value is set to NULL.
|
|
|
|
* @return 0 in case of success, a negative value corresponding to an
|
|
|
|
* AVERROR code in case of failure
|
|
|
|
*/
|
2007-11-21 07:41:00 +00:00
|
|
|
int url_fdopen(ByteIOContext **s, URLContext *h);
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/** @warning must be called before any I/O */
|
2001-07-22 14:18:56 +00:00
|
|
|
int url_setbufsize(ByteIOContext *s, int buf_size);
|
2010-08-19 21:28:43 +00:00
|
|
|
#if FF_API_URL_RESETBUF
|
2007-10-11 14:57:47 +00:00
|
|
|
/** Reset the buffer for reading or writing.
|
|
|
|
* @note Will drop any data currently in the buffer without transmitting it.
|
|
|
|
* @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY
|
|
|
|
* to set up the buffer for writing. */
|
|
|
|
int url_resetbuf(ByteIOContext *s, int flags);
|
2009-10-20 06:40:01 +00:00
|
|
|
#endif
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2010-04-08 09:02:27 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Rewind the ByteIOContext using the specified buffer containing the first buf_size bytes of the file.
|
2010-04-08 09:02:27 +00:00
|
|
|
* Used after probing to avoid seeking.
|
|
|
|
* Joins buf and s->buffer, taking any overlap into consideration.
|
|
|
|
* @note s->buffer must overlap with buf or they can't be joined and the function fails
|
|
|
|
* @note This function is NOT part of the public API
|
|
|
|
*
|
|
|
|
* @param s The read-only ByteIOContext to rewind
|
|
|
|
* @param buf The probe buffer containing the first buf_size bytes of the file
|
|
|
|
* @param buf_size The size of buf
|
|
|
|
* @return 0 in case of success, a negative value corresponding to an
|
|
|
|
* AVERROR code in case of failure
|
|
|
|
*/
|
|
|
|
int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size);
|
|
|
|
|
2010-02-09 18:59:34 +00:00
|
|
|
/**
|
2010-06-30 15:38:06 +00:00
|
|
|
* Create and initialize a ByteIOContext for accessing the
|
2010-02-09 18:59:34 +00:00
|
|
|
* resource indicated by url.
|
|
|
|
* @note When the resource indicated by url has been opened in
|
|
|
|
* read+write mode, the ByteIOContext can be used only for writing.
|
|
|
|
*
|
|
|
|
* @param s Used to return the pointer to the created ByteIOContext.
|
|
|
|
* In case of failure the pointed to value is set to NULL.
|
|
|
|
* @param flags flags which control how the resource indicated by url
|
|
|
|
* is to be opened
|
|
|
|
* @return 0 in case of success, a negative value corresponding to an
|
|
|
|
* AVERROR code in case of failure
|
|
|
|
*/
|
2010-01-24 18:18:03 +00:00
|
|
|
int url_fopen(ByteIOContext **s, const char *url, int flags);
|
2010-02-09 18:59:34 +00:00
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
int url_fclose(ByteIOContext *s);
|
|
|
|
URLContext *url_fileno(ByteIOContext *s);
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/**
|
2007-03-05 13:55:45 +00:00
|
|
|
* Return the maximum packet size associated to packetized buffered file
|
|
|
|
* handle. If the file is not packetized (stream like http or file on
|
|
|
|
* disk), then 0 is returned.
|
|
|
|
*
|
2007-11-15 11:43:21 +00:00
|
|
|
* @param s buffered file handle
|
2007-03-05 13:55:45 +00:00
|
|
|
* @return maximum packet size in bytes
|
|
|
|
*/
|
2002-07-24 17:49:11 +00:00
|
|
|
int url_fget_max_packet_size(ByteIOContext *s);
|
2001-07-22 14:18:56 +00:00
|
|
|
|
2007-11-21 07:41:00 +00:00
|
|
|
int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags);
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/** return the written or read size */
|
2001-07-22 14:18:56 +00:00
|
|
|
int url_close_buf(ByteIOContext *s);
|
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/**
|
2007-03-05 13:55:45 +00:00
|
|
|
* Open a write only memory stream.
|
|
|
|
*
|
|
|
|
* @param s new IO context
|
|
|
|
* @return zero if no error.
|
|
|
|
*/
|
2007-11-21 07:41:00 +00:00
|
|
|
int url_open_dyn_buf(ByteIOContext **s);
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/**
|
2007-03-05 13:55:45 +00:00
|
|
|
* Open a write only packetized memory stream with a maximum packet
|
|
|
|
* size of 'max_packet_size'. The stream is stored in a memory buffer
|
|
|
|
* with a big endian 4 byte header giving the packet size in bytes.
|
|
|
|
*
|
|
|
|
* @param s new IO context
|
|
|
|
* @param max_packet_size maximum packet size (must be > 0)
|
|
|
|
* @return zero if no error.
|
|
|
|
*/
|
2007-11-21 07:41:00 +00:00
|
|
|
int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size);
|
2007-03-05 13:55:45 +00:00
|
|
|
|
2007-03-05 15:18:50 +00:00
|
|
|
/**
|
2007-03-05 13:55:45 +00:00
|
|
|
* Return the written size and a pointer to the buffer. The buffer
|
2010-07-01 20:15:49 +00:00
|
|
|
* must be freed with av_free(). If the buffer is opened with
|
|
|
|
* url_open_dyn_buf, then padding of FF_INPUT_BUFFER_PADDING_SIZE is
|
|
|
|
* added; if opened with url_open_dyn_packet_buf, no padding is added.
|
|
|
|
*
|
2007-03-05 13:55:45 +00:00
|
|
|
* @param s IO context
|
2007-11-15 11:44:15 +00:00
|
|
|
* @param pbuffer pointer to a byte buffer
|
2007-03-05 13:55:45 +00:00
|
|
|
* @return the length of the byte buffer
|
|
|
|
*/
|
2003-02-11 16:35:48 +00:00
|
|
|
int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
|
2002-07-24 17:49:11 +00:00
|
|
|
|
2008-12-13 13:39:13 +00:00
|
|
|
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
|
|
|
|
unsigned int len);
|
2004-04-05 12:02:10 +00:00
|
|
|
unsigned long get_checksum(ByteIOContext *s);
|
2008-12-13 13:39:13 +00:00
|
|
|
void init_checksum(ByteIOContext *s,
|
|
|
|
unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
|
|
|
|
unsigned long checksum);
|
2004-04-05 12:02:10 +00:00
|
|
|
|
2001-07-22 14:18:56 +00:00
|
|
|
/* udp.c */
|
2002-07-24 17:49:11 +00:00
|
|
|
int udp_set_remote_url(URLContext *h, const char *uri);
|
|
|
|
int udp_get_local_port(URLContext *h);
|
2010-10-15 12:49:48 +00:00
|
|
|
#if FF_API_UDP_GET_FILE
|
2002-07-24 17:49:11 +00:00
|
|
|
int udp_get_file_handle(URLContext *h);
|
2009-03-03 17:04:51 +00:00
|
|
|
#endif
|
2002-07-24 17:49:11 +00:00
|
|
|
|
2008-08-31 07:39:47 +00:00
|
|
|
#endif /* AVFORMAT_AVIO_H */
|