yading@11: /* yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: /** yading@11: * @file yading@11: * unbuffered private I/O API yading@11: */ yading@11: yading@11: #ifndef AVFORMAT_URL_H yading@11: #define AVFORMAT_URL_H yading@11: yading@11: #include "avio.h" yading@11: #include "libavformat/version.h" yading@11: yading@11: #include "libavutil/dict.h" yading@11: #include "libavutil/log.h" yading@11: yading@11: #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */ yading@11: #define URL_PROTOCOL_FLAG_NETWORK 2 /*< The protocol uses network */ yading@11: yading@11: extern int (*url_interrupt_cb)(void); yading@11: yading@11: extern const AVClass ffurl_context_class; yading@11: yading@11: typedef struct URLContext { yading@11: const AVClass *av_class; /**< information for av_log(). Set by url_open(). */ yading@11: struct URLProtocol *prot; yading@11: void *priv_data; yading@11: char *filename; /**< specified URL */ yading@11: int flags; yading@11: int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */ yading@11: int is_streamed; /**< true if streamed (no seek possible), default = false */ yading@11: int is_connected; yading@11: AVIOInterruptCB interrupt_callback; yading@11: int64_t rw_timeout; /**< maximum time to wait for (network) read/write operation completion, in mcs */ yading@11: } URLContext; yading@11: yading@11: typedef struct URLProtocol { yading@11: const char *name; yading@11: int (*url_open)( URLContext *h, const char *url, int flags); yading@11: /** yading@11: * This callback is to be used by protocols which open further nested yading@11: * protocols. options are then to be passed to ffurl_open()/ffurl_connect() yading@11: * for those nested protocols. yading@11: */ yading@11: int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options); yading@11: yading@11: /** yading@11: * Read data from the protocol. yading@11: * If data is immediately available (even less than size), EOF is yading@11: * reached or an error occurs (including EINTR), return immediately. yading@11: * Otherwise: yading@11: * In non-blocking mode, return AVERROR(EAGAIN) immediately. yading@11: * In blocking mode, wait for data/EOF/error with a short timeout (0.1s), yading@11: * and return AVERROR(EAGAIN) on timeout. yading@11: * Checking interrupt_callback, looping on EINTR and EAGAIN and until yading@11: * enough data has been read is left to the calling function; see yading@11: * retry_transfer_wrapper in avio.c. yading@11: */ yading@11: int (*url_read)( URLContext *h, unsigned char *buf, int size); yading@11: int (*url_write)(URLContext *h, const unsigned char *buf, int size); yading@11: int64_t (*url_seek)( URLContext *h, int64_t pos, int whence); yading@11: int (*url_close)(URLContext *h); yading@11: struct URLProtocol *next; yading@11: int (*url_read_pause)(URLContext *h, int pause); yading@11: int64_t (*url_read_seek)(URLContext *h, int stream_index, yading@11: int64_t timestamp, int flags); yading@11: int (*url_get_file_handle)(URLContext *h); yading@11: int (*url_get_multi_file_handle)(URLContext *h, int **handles, yading@11: int *numhandles); yading@11: int (*url_shutdown)(URLContext *h, int flags); yading@11: int priv_data_size; yading@11: const AVClass *priv_data_class; yading@11: int flags; yading@11: int (*url_check)(URLContext *h, int mask); yading@11: } URLProtocol; yading@11: yading@11: /** yading@11: * Create a URLContext for accessing to the resource indicated by yading@11: * url, but do not initiate the connection yet. yading@11: * yading@11: * @param puc pointer to the location where, in case of success, the yading@11: * function puts the pointer to the created URLContext yading@11: * @param flags flags which control how the resource indicated by url yading@11: * is to be opened yading@11: * @param int_cb interrupt callback to use for the URLContext, may be yading@11: * NULL yading@11: * @return 0 in case of success, a negative value corresponding to an yading@11: * AVERROR code in case of failure yading@11: */ yading@11: int ffurl_alloc(URLContext **puc, const char *filename, int flags, yading@11: const AVIOInterruptCB *int_cb); yading@11: yading@11: /** yading@11: * Connect an URLContext that has been allocated by ffurl_alloc yading@11: * yading@11: * @param options A dictionary filled with options for nested protocols, yading@11: * i.e. it will be passed to url_open2() for protocols implementing it. yading@11: * This parameter will be destroyed and replaced with a dict containing options yading@11: * that were not found. May be NULL. yading@11: */ yading@11: int ffurl_connect(URLContext *uc, AVDictionary **options); yading@11: yading@11: /** yading@11: * Create an URLContext for accessing to the resource indicated by yading@11: * url, and open it. yading@11: * yading@11: * @param puc pointer to the location where, in case of success, the yading@11: * function puts the pointer to the created URLContext yading@11: * @param flags flags which control how the resource indicated by url yading@11: * is to be opened yading@11: * @param int_cb interrupt callback to use for the URLContext, may be yading@11: * NULL yading@11: * @param options A dictionary filled with protocol-private options. On return yading@11: * this parameter will be destroyed and replaced with a dict containing options yading@11: * that were not found. May be NULL. yading@11: * @return 0 in case of success, a negative value corresponding to an yading@11: * AVERROR code in case of failure yading@11: */ yading@11: int ffurl_open(URLContext **puc, const char *filename, int flags, yading@11: const AVIOInterruptCB *int_cb, AVDictionary **options); yading@11: yading@11: /** yading@11: * Read up to size bytes from the resource accessed by h, and store yading@11: * the read bytes in buf. yading@11: * yading@11: * @return The number of bytes actually read, or a negative value yading@11: * corresponding to an AVERROR code in case of error. A value of zero yading@11: * indicates that it is not possible to read more from the accessed yading@11: * resource (except if the value of the size argument is also zero). yading@11: */ yading@11: int ffurl_read(URLContext *h, unsigned char *buf, int size); yading@11: yading@11: /** yading@11: * Read as many bytes as possible (up to size), calling the yading@11: * read function multiple times if necessary. yading@11: * This makes special short-read handling in applications yading@11: * unnecessary, if the return value is < size then it is yading@11: * certain there was either an error or the end of file was reached. yading@11: */ yading@11: int ffurl_read_complete(URLContext *h, unsigned char *buf, int size); yading@11: yading@11: /** yading@11: * Write size bytes from buf to the resource accessed by h. yading@11: * yading@11: * @return the number of bytes actually written, or a negative value yading@11: * corresponding to an AVERROR code in case of failure yading@11: */ yading@11: int ffurl_write(URLContext *h, const unsigned char *buf, int size); yading@11: yading@11: /** yading@11: * Change the position that will be used by the next read/write yading@11: * operation on the resource accessed by h. yading@11: * yading@11: * @param pos specifies the new position to set yading@11: * @param whence specifies how pos should be interpreted, it must be yading@11: * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the yading@11: * current position), SEEK_END (seek from the end), or AVSEEK_SIZE yading@11: * (return the filesize of the requested resource, pos is ignored). yading@11: * @return a negative value corresponding to an AVERROR code in case yading@11: * of failure, or the resulting file position, measured in bytes from yading@11: * the beginning of the file. You can use this feature together with yading@11: * SEEK_CUR to read the current file position. yading@11: */ yading@11: int64_t ffurl_seek(URLContext *h, int64_t pos, int whence); yading@11: yading@11: /** yading@11: * Close the resource accessed by the URLContext h, and free the yading@11: * memory used by it. Also set the URLContext pointer to NULL. yading@11: * yading@11: * @return a negative value if an error condition occurred, 0 yading@11: * otherwise yading@11: */ yading@11: int ffurl_closep(URLContext **h); yading@11: int ffurl_close(URLContext *h); yading@11: yading@11: /** yading@11: * Return the filesize of the resource accessed by h, AVERROR(ENOSYS) yading@11: * if the operation is not supported by h, or another negative value yading@11: * corresponding to an AVERROR error code in case of failure. yading@11: */ yading@11: int64_t ffurl_size(URLContext *h); yading@11: yading@11: /** yading@11: * Return the file descriptor associated with this URL. For RTP, this yading@11: * will return only the RTP file descriptor, not the RTCP file descriptor. yading@11: * yading@11: * @return the file descriptor associated with this URL, or <0 on error. yading@11: */ yading@11: int ffurl_get_file_handle(URLContext *h); yading@11: yading@11: /** yading@11: * Return the file descriptors associated with this URL. yading@11: * yading@11: * @return 0 on success or <0 on error. yading@11: */ yading@11: int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles); yading@11: yading@11: /** yading@11: * Signal the URLContext that we are done reading or writing the stream. yading@11: * yading@11: * @param h pointer to the resource yading@11: * @param flags flags which control how the resource indicated by url yading@11: * is to be shutdown yading@11: * yading@11: * @return a negative value if an error condition occurred, 0 yading@11: * otherwise yading@11: */ yading@11: int ffurl_shutdown(URLContext *h, int flags); yading@11: yading@11: /** yading@11: * Register the URLProtocol protocol. yading@11: * yading@11: * @param size the size of the URLProtocol struct referenced yading@11: */ yading@11: int ffurl_register_protocol(URLProtocol *protocol, int size); yading@11: yading@11: /** yading@11: * Check if the user has requested to interrup a blocking function yading@11: * associated with cb. yading@11: */ yading@11: int ff_check_interrupt(AVIOInterruptCB *cb); yading@11: yading@11: /** yading@11: * Iterate over all available protocols. yading@11: * yading@11: * @param prev result of the previous call to this functions or NULL. yading@11: */ yading@11: URLProtocol *ffurl_protocol_next(URLProtocol *prev); yading@11: yading@11: /* udp.c */ yading@11: int ff_udp_set_remote_url(URLContext *h, const char *uri); yading@11: int ff_udp_get_local_port(URLContext *h); yading@11: yading@11: #endif /* AVFORMAT_URL_H */