2006-09-10 17:02:42 +03:00
|
|
|
/*
|
|
|
|
* unbuffered io for ffmpeg system
|
|
|
|
* copyright (c) 2001 Fabrice Bellard
|
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2006-09-10 17:02:42 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-09-10 17:02:42 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2006-09-10 17:02:42 +03: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 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-09-10 17:02:42 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-10-17 12:37:46 +03:00
|
|
|
#ifndef FFMPEG_AVIO_H
|
|
|
|
#define FFMPEG_AVIO_H
|
2002-07-24 20:49:11 +03:00
|
|
|
|
2007-06-17 01:59:13 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
/* output byte stream handling */
|
|
|
|
|
2003-02-11 18:35:48 +02:00
|
|
|
typedef int64_t offset_t;
|
2001-07-22 17:18:56 +03:00
|
|
|
|
|
|
|
/* unbuffered I/O */
|
|
|
|
|
|
|
|
struct URLContext {
|
|
|
|
struct URLProtocol *prot;
|
2005-12-17 20:14:38 +02:00
|
|
|
int flags;
|
2007-03-05 17:18:50 +02: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 17:18:56 +03:00
|
|
|
void *priv_data;
|
2007-01-15 00:07:19 +02:00
|
|
|
#if LIBAVFORMAT_VERSION_INT >= (52<<16)
|
2007-03-05 17:18:50 +02:00
|
|
|
char *filename; /**< specified filename */
|
2007-01-15 00:07:19 +02:00
|
|
|
#else
|
2007-03-05 17:18:50 +02:00
|
|
|
char filename[1]; /**< specified filename */
|
2007-01-15 00:07:19 +02:00
|
|
|
#endif
|
2001-07-22 17:18:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct URLContext URLContext;
|
|
|
|
|
|
|
|
typedef struct URLPollEntry {
|
|
|
|
URLContext *handle;
|
|
|
|
int events;
|
|
|
|
int revents;
|
|
|
|
} URLPollEntry;
|
|
|
|
|
|
|
|
#define URL_RDONLY 0
|
|
|
|
#define URL_WRONLY 1
|
2002-07-24 20:49:11 +03:00
|
|
|
#define URL_RDWR 2
|
|
|
|
|
2003-07-17 13:25:36 +03:00
|
|
|
typedef int URLInterruptCB(void);
|
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
int url_open(URLContext **h, const char *filename, int flags);
|
|
|
|
int url_read(URLContext *h, unsigned char *buf, int size);
|
|
|
|
int url_write(URLContext *h, unsigned char *buf, int size);
|
|
|
|
offset_t url_seek(URLContext *h, offset_t pos, int whence);
|
|
|
|
int url_close(URLContext *h);
|
|
|
|
int url_exist(const char *filename);
|
|
|
|
offset_t url_filesize(URLContext *h);
|
2007-03-05 16:26:50 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/**
|
2007-03-05 16:26:50 +02:00
|
|
|
* Return the maximum packet size associated to packetized file
|
|
|
|
* handle. If the file is not packetized (stream like http or file on
|
|
|
|
* disk), then 0 is returned.
|
|
|
|
*
|
|
|
|
* @param h file handle
|
|
|
|
* @return maximum packet size in bytes
|
|
|
|
*/
|
2002-07-24 20:49:11 +03:00
|
|
|
int url_get_max_packet_size(URLContext *h);
|
2003-01-11 06:59:17 +02:00
|
|
|
void url_get_filename(URLContext *h, char *buf, int buf_size);
|
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/**
|
|
|
|
* the callback is called in blocking functions to test regulary if
|
|
|
|
* asynchronous interruption is needed. AVERROR(EINTR) is returned
|
|
|
|
* in this case by the interrupted function. 'NULL' means no interrupt
|
|
|
|
* callback is given. i
|
|
|
|
*/
|
2003-07-17 13:25:36 +03:00
|
|
|
void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
|
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
/* not implemented */
|
|
|
|
int url_poll(URLPollEntry *poll_table, int n, int timeout);
|
|
|
|
|
2007-01-01 23:53:15 +02:00
|
|
|
/**
|
2007-06-12 21:50:50 +03: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.
|
2007-01-01 23:53:15 +02:00
|
|
|
*/
|
2007-01-01 23:49:09 +02:00
|
|
|
#define AVSEEK_SIZE 0x10000
|
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
typedef struct URLProtocol {
|
|
|
|
const char *name;
|
|
|
|
int (*url_open)(URLContext *h, const char *filename, int flags);
|
|
|
|
int (*url_read)(URLContext *h, unsigned char *buf, int size);
|
|
|
|
int (*url_write)(URLContext *h, unsigned char *buf, int size);
|
|
|
|
offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
|
|
|
|
int (*url_close)(URLContext *h);
|
|
|
|
struct URLProtocol *next;
|
|
|
|
} URLProtocol;
|
|
|
|
|
|
|
|
extern URLProtocol *first_protocol;
|
2003-07-17 13:25:36 +03:00
|
|
|
extern URLInterruptCB *url_interrupt_cb;
|
2001-07-22 17:18:56 +03:00
|
|
|
|
|
|
|
int register_protocol(URLProtocol *protocol);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned char *buffer;
|
|
|
|
int buffer_size;
|
|
|
|
unsigned char *buf_ptr, *buf_end;
|
|
|
|
void *opaque;
|
2003-02-11 18:35:48 +02:00
|
|
|
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
|
2004-10-08 23:09:52 +03:00
|
|
|
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
|
2005-05-30 19:45:08 +03:00
|
|
|
offset_t (*seek)(void *opaque, offset_t offset, int whence);
|
2007-03-05 17:18:50 +02:00
|
|
|
offset_t pos; /**< position in the file of the current buffer */
|
|
|
|
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 17:18:56 +03:00
|
|
|
int is_streamed;
|
2002-07-24 20:49:11 +03:00
|
|
|
int max_packet_size;
|
2004-04-05 15:02:10 +03: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 23:09:52 +03:00
|
|
|
int error; ///< contains the error code or 0 if no error happened
|
2001-07-22 17:18:56 +03:00
|
|
|
} ByteIOContext;
|
|
|
|
|
|
|
|
int init_put_byte(ByteIOContext *s,
|
|
|
|
unsigned char *buffer,
|
|
|
|
int buffer_size,
|
|
|
|
int write_flag,
|
|
|
|
void *opaque,
|
2003-02-11 18:35:48 +02:00
|
|
|
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
|
2004-10-08 23:09:52 +03:00
|
|
|
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
|
2005-05-30 19:45:08 +03:00
|
|
|
offset_t (*seek)(void *opaque, offset_t offset, int whence));
|
2001-07-22 17:18:56 +03:00
|
|
|
|
|
|
|
void put_byte(ByteIOContext *s, int b);
|
2002-09-12 05:26:58 +03:00
|
|
|
void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
|
2003-02-11 18:35:48 +02:00
|
|
|
void put_le64(ByteIOContext *s, uint64_t val);
|
|
|
|
void put_be64(ByteIOContext *s, uint64_t val);
|
2001-07-22 17:18:56 +03:00
|
|
|
void put_le32(ByteIOContext *s, unsigned int val);
|
|
|
|
void put_be32(ByteIOContext *s, unsigned int val);
|
2006-02-10 00:52:23 +02:00
|
|
|
void put_le24(ByteIOContext *s, unsigned int val);
|
2005-07-19 17:41:08 +03:00
|
|
|
void put_be24(ByteIOContext *s, unsigned int val);
|
2001-07-22 17:18:56 +03:00
|
|
|
void put_le16(ByteIOContext *s, unsigned int val);
|
|
|
|
void put_be16(ByteIOContext *s, unsigned int val);
|
2002-11-11 11:20:53 +02:00
|
|
|
void put_tag(ByteIOContext *s, const char *tag);
|
2001-07-22 17:18:56 +03:00
|
|
|
|
2002-10-22 12:23:14 +03:00
|
|
|
void put_strz(ByteIOContext *s, const char *buf);
|
2002-09-12 05:26:58 +03:00
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
|
|
|
|
void url_fskip(ByteIOContext *s, offset_t offset);
|
|
|
|
offset_t url_ftell(ByteIOContext *s);
|
2005-05-19 03:06:27 +03:00
|
|
|
offset_t url_fsize(ByteIOContext *s);
|
2001-07-22 17:18:56 +03:00
|
|
|
int url_feof(ByteIOContext *s);
|
2004-10-08 23:09:52 +03:00
|
|
|
int url_ferror(ByteIOContext *s);
|
2001-07-22 17:18:56 +03:00
|
|
|
|
2002-07-24 20:49:11 +03:00
|
|
|
#define URL_EOF (-1)
|
2007-03-05 17:18:50 +02:00
|
|
|
/** @note return URL_EOF (-1) if EOF */
|
2002-07-24 20:49:11 +03:00
|
|
|
int url_fgetc(ByteIOContext *s);
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/** @warning currently size is limited */
|
2003-08-29 23:33:57 +03:00
|
|
|
#ifdef __GNUC__
|
2003-09-30 20:54:30 +03:00
|
|
|
int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
|
2003-08-29 23:33:57 +03:00
|
|
|
#else
|
|
|
|
int url_fprintf(ByteIOContext *s, const char *fmt, ...);
|
|
|
|
#endif
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/** @note unlike fgets, the EOL character is not returned and a whole
|
2007-03-05 15:55:45 +02:00
|
|
|
line is parsed. return NULL if first char read was EOF */
|
2002-07-24 20:49:11 +03:00
|
|
|
char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
|
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
void put_flush_packet(ByteIOContext *s);
|
|
|
|
|
|
|
|
int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
|
2004-03-15 05:29:32 +02:00
|
|
|
int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/** @note return 0 if EOF, so you cannot use it if EOF handling is
|
2007-03-05 15:55:45 +02:00
|
|
|
necessary */
|
2001-07-22 17:18:56 +03:00
|
|
|
int get_byte(ByteIOContext *s);
|
2006-02-10 00:52:23 +02:00
|
|
|
unsigned int get_le24(ByteIOContext *s);
|
2001-07-22 17:18:56 +03:00
|
|
|
unsigned int get_le32(ByteIOContext *s);
|
2003-02-11 18:35:48 +02:00
|
|
|
uint64_t get_le64(ByteIOContext *s);
|
2001-07-22 17:18:56 +03:00
|
|
|
unsigned int get_le16(ByteIOContext *s);
|
|
|
|
|
2002-10-22 12:23:14 +03:00
|
|
|
char *get_strz(ByteIOContext *s, char *buf, int maxlen);
|
2001-07-22 17:18:56 +03:00
|
|
|
unsigned int get_be16(ByteIOContext *s);
|
2005-07-19 17:41:08 +03:00
|
|
|
unsigned int get_be24(ByteIOContext *s);
|
2001-07-22 17:18:56 +03:00
|
|
|
unsigned int get_be32(ByteIOContext *s);
|
2003-02-11 18:35:48 +02:00
|
|
|
uint64_t get_be64(ByteIOContext *s);
|
2001-07-22 17:18:56 +03:00
|
|
|
|
2007-11-03 20:29:16 +02:00
|
|
|
uint64_t ff_get_v(ByteIOContext *bc);
|
2007-11-03 20:26:42 +02:00
|
|
|
|
2002-05-09 04:16:45 +03:00
|
|
|
static inline int url_is_streamed(ByteIOContext *s)
|
2001-07-22 17:18:56 +03:00
|
|
|
{
|
|
|
|
return s->is_streamed;
|
|
|
|
}
|
|
|
|
|
2007-09-28 18:12:26 +03:00
|
|
|
/** @note when opened as read/write, the buffers are only used for
|
|
|
|
writing */
|
2001-07-22 17:18:56 +03:00
|
|
|
int url_fdopen(ByteIOContext *s, URLContext *h);
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/** @warning must be called before any I/O */
|
2001-07-22 17:18:56 +03:00
|
|
|
int url_setbufsize(ByteIOContext *s, int buf_size);
|
2007-10-11 17:57:47 +03: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);
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/** @note when opened as read/write, the buffers are only used for
|
2007-09-28 18:12:26 +03:00
|
|
|
writing */
|
2001-07-22 17:18:56 +03:00
|
|
|
int url_fopen(ByteIOContext *s, const char *filename, int flags);
|
|
|
|
int url_fclose(ByteIOContext *s);
|
|
|
|
URLContext *url_fileno(ByteIOContext *s);
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/**
|
2007-03-05 15:55:45 +02: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.
|
|
|
|
*
|
|
|
|
* @param h buffered file handle
|
|
|
|
* @return maximum packet size in bytes
|
|
|
|
*/
|
2002-07-24 20:49:11 +03:00
|
|
|
int url_fget_max_packet_size(ByteIOContext *s);
|
2001-07-22 17:18:56 +03:00
|
|
|
|
2003-02-11 18:35:48 +02:00
|
|
|
int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags);
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/** return the written or read size */
|
2001-07-22 17:18:56 +03:00
|
|
|
int url_close_buf(ByteIOContext *s);
|
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/**
|
2007-03-05 15:55:45 +02:00
|
|
|
* Open a write only memory stream.
|
|
|
|
*
|
|
|
|
* @param s new IO context
|
|
|
|
* @return zero if no error.
|
|
|
|
*/
|
2002-07-24 20:49:11 +03:00
|
|
|
int url_open_dyn_buf(ByteIOContext *s);
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/**
|
2007-03-05 15:55:45 +02: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.
|
|
|
|
*/
|
2002-07-24 20:49:11 +03:00
|
|
|
int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
|
2007-03-05 15:55:45 +02:00
|
|
|
|
2007-03-05 17:18:50 +02:00
|
|
|
/**
|
2007-03-05 15:55:45 +02:00
|
|
|
* Return the written size and a pointer to the buffer. The buffer
|
|
|
|
* must be freed with av_free().
|
|
|
|
* @param s IO context
|
|
|
|
* @param pointer to a byte buffer
|
|
|
|
* @return the length of the byte buffer
|
|
|
|
*/
|
2003-02-11 18:35:48 +02:00
|
|
|
int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
|
2002-07-24 20:49:11 +03:00
|
|
|
|
2007-10-30 02:01:25 +02:00
|
|
|
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len);
|
2004-04-05 15:02:10 +03:00
|
|
|
unsigned long get_checksum(ByteIOContext *s);
|
|
|
|
void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum);
|
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
/* udp.c */
|
2002-07-24 20:49:11 +03:00
|
|
|
int udp_set_remote_url(URLContext *h, const char *uri);
|
|
|
|
int udp_get_local_port(URLContext *h);
|
|
|
|
int udp_get_file_handle(URLContext *h);
|
|
|
|
|
2007-10-17 12:37:46 +03:00
|
|
|
#endif /* FFMPEG_AVIO_H */
|