FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
avio.c File Reference
#include "libavutil/avstring.h"
#include "libavutil/dict.h"
#include "libavutil/opt.h"
#include "libavutil/time.h"
#include "libavutil/avassert.h"
#include "os_support.h"
#include "avformat.h"
#include "url.h"

Go to the source code of this file.

Macros

#define URL_SCHEME_CHARS
 

Functions

static int url_alloc_for_protocol (URLContext **puc, const URLProtocol *up, const char *filename, int flags, const AVIOInterruptCB *int_cb)
 
int ffurl_connect (URLContext *uc, AVDictionary **options)
 Connect an URLContext that has been allocated by ffurl_alloc. More...
 
int ffurl_accept (URLContext *s, URLContext **c)
 Accept an URLContext c on an URLContext s. More...
 
int ffurl_handshake (URLContext *c)
 Perform one step of the protocol handshake to accept a new client. More...
 
static const struct URLProtocolurl_find_protocol (const char *filename)
 
int ffurl_alloc (URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb)
 Create a URLContext for accessing to the resource indicated by url, but do not initiate the connection yet. More...
 
int ffurl_open_whitelist (URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
 Create an URLContext for accessing to the resource indicated by url, and open it. More...
 
int ffurl_open (URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
 
static int retry_transfer_wrapper (URLContext *h, uint8_t *buf, int size, int size_min, int(*transfer_func)(URLContext *h, uint8_t *buf, int size))
 
int ffurl_read (URLContext *h, unsigned char *buf, int size)
 Read up to size bytes from the resource accessed by h, and store the read bytes in buf. More...
 
int ffurl_read_complete (URLContext *h, unsigned char *buf, int size)
 Read as many bytes as possible (up to size), calling the read function multiple times if necessary. More...
 
int ffurl_write (URLContext *h, const unsigned char *buf, int size)
 Write size bytes from buf to the resource accessed by h. More...
 
int64_t ffurl_seek (URLContext *h, int64_t pos, int whence)
 Change the position that will be used by the next read/write operation on the resource accessed by h. More...
 
int ffurl_closep (URLContext **hh)
 Close the resource accessed by the URLContext h, and free the memory used by it. More...
 
int ffurl_close (URLContext *h)
 
const char * avio_find_protocol_name (const char *url)
 Return the name of the protocol that will handle the passed URL. More...
 
int avio_check (const char *url, int flags)
 Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url, or a negative value corresponding to an AVERROR code in case of failure. More...
 
int avpriv_io_move (const char *url_src, const char *url_dst)
 Move or rename a resource. More...
 
int avpriv_io_delete (const char *url)
 Delete a resource. More...
 
int avio_open_dir (AVIODirContext **s, const char *url, AVDictionary **options)
 Open directory for reading. More...
 
int avio_read_dir (AVIODirContext *s, AVIODirEntry **next)
 Get next directory entry. More...
 
int avio_close_dir (AVIODirContext **s)
 Close directory. More...
 
void avio_free_directory_entry (AVIODirEntry **entry)
 Free entry allocated by avio_read_dir(). More...
 
int64_t ffurl_size (URLContext *h)
 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. More...
 
int ffurl_get_file_handle (URLContext *h)
 Return the file descriptor associated with this URL. More...
 
int ffurl_get_multi_file_handle (URLContext *h, int **handles, int *numhandles)
 Return the file descriptors associated with this URL. More...
 
int ffurl_shutdown (URLContext *h, int flags)
 Signal the URLContext that we are done reading or writing the stream. More...
 
int ff_check_interrupt (AVIOInterruptCB *cb)
 Check if the user has requested to interrupt a blocking function associated with cb. More...
 

Logging context.

#define OFFSET(x)   offsetof(URLContext,x)
 
#define E   AV_OPT_FLAG_ENCODING_PARAM
 
#define D   AV_OPT_FLAG_DECODING_PARAM
 
static const AVOption options []
 
const AVClass ffurl_context_class
 
static const char * urlcontext_to_name (void *ptr)
 
static voidurlcontext_child_next (void *obj, void *prev)
 

Macro Definition Documentation

#define OFFSET (   x)    offsetof(URLContext,x)

Definition at line 53 of file avio.c.

Definition at line 54 of file avio.c.

Definition at line 55 of file avio.c.

#define URL_SCHEME_CHARS
Value:
"abcdefghijklmnopqrstuvwxyz" \
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
"0123456789+-."

Definition at line 246 of file avio.c.

Referenced by url_find_protocol().

Function Documentation

static const char* urlcontext_to_name ( void ptr)
static

Definition at line 36 of file avio.c.

static void* urlcontext_child_next ( void obj,
void prev 
)
static

Definition at line 45 of file avio.c.

static int url_alloc_for_protocol ( URLContext **  puc,
const URLProtocol up,
const char *  filename,
int  flags,
const AVIOInterruptCB int_cb 
)
static

Definition at line 73 of file avio.c.

Referenced by ffurl_alloc().

int ffurl_connect ( URLContext uc,
AVDictionary **  options 
)

Connect an URLContext that has been allocated by ffurl_alloc.

Parameters
optionsA dictionary filled with options for nested protocols, i.e. it will be passed to url_open2() for protocols implementing it. This parameter will be destroyed and replaced with a dict containing options that were not found. May be NULL.

Definition at line 166 of file avio.c.

Referenced by avio_check(), ffurl_open_whitelist(), mmsh_open_internal(), and rtmp_http_open().

int ffurl_accept ( URLContext s,
URLContext **  c 
)

Accept an URLContext c on an URLContext s.

Parameters
sserver context
cclient context, must be unallocated.
Returns
>= 0 on success, ff_neterrno() on failure.

Definition at line 226 of file avio.c.

Referenced by avio_accept(), and http_accept().

int ffurl_handshake ( URLContext c)

Perform one step of the protocol handshake to accept a new client.

See avio_handshake() for details. Implementations should try to return decreasing values. If the protocol uses an underlying protocol, the underlying handshake is usually the first step, and the return value can be: (largest value for this protocol) + (return value from other protocol)

Parameters
cthe client context
Returns
>= 0 on success or a negative value corresponding to an AVERROR code on failure

Definition at line 234 of file avio.c.

Referenced by avio_handshake(), and http_handshake().

static const struct URLProtocol* url_find_protocol ( const char *  filename)
static

Definition at line 251 of file avio.c.

Referenced by avio_find_protocol_name(), and ffurl_alloc().

int ffurl_alloc ( URLContext **  puc,
const char *  filename,
int  flags,
const AVIOInterruptCB int_cb 
)

Create a URLContext for accessing to the resource indicated by url, but do not initiate the connection yet.

Parameters
pucpointer to the location where, in case of success, the function puts the pointer to the created URLContext
flagsflags which control how the resource indicated by url is to be opened
int_cbinterrupt callback to use for the URLContext, may be NULL
Returns
>= 0 in case of success, a negative value corresponding to an AVERROR code in case of failure

Definition at line 292 of file avio.c.

Referenced by avio_check(), avio_open_dir(), avpriv_io_delete(), avpriv_io_move(), ffurl_open_whitelist(), http_accept(), mmsh_open_internal(), rtmp_http_open(), and tcp_accept().

int ffurl_open_whitelist ( URLContext **  puc,
const char *  filename,
int  flags,
const AVIOInterruptCB int_cb,
AVDictionary **  options,
const char *  whitelist,
const char *  blacklist,
URLContext parent 
)

Create an URLContext for accessing to the resource indicated by url, and open it.

Parameters
pucpointer to the location where, in case of success, the function puts the pointer to the created URLContext
flagsflags which control how the resource indicated by url is to be opened
int_cbinterrupt callback to use for the URLContext, may be NULL
optionsA dictionary filled with protocol-private options. On return this parameter will be destroyed and replaced with a dict containing options that were not found. May be NULL.
parentAn enclosing URLContext, whose generic options should be applied to this URLContext as well.
Returns
>= 0 in case of success, a negative value corresponding to an AVERROR code in case of failure

Definition at line 309 of file avio.c.

Referenced by async_open(), cache_open(), concat_open(), crypto_open2(), ff_tls_open_underlying(), ffio_open_whitelist(), ffurl_open(), ftp_connect_control_connection(), ftp_connect_data_connection(), gopher_open(), hls_read(), http_listen(), http_open_cnx_internal(), icecast_open(), ism_flush(), ism_seek(), md5_close(), mms_open(), rtmp_calc_swfhash(), rtmp_open(), rtmpe_open(), rtp_open(), rtsp_listen(), rtsp_read_setup(), sap_read_header(), sap_write_header(), srtp_open(), and subfile_open().

int ffurl_open ( URLContext **  puc,
const char *  filename,
int  flags,
const AVIOInterruptCB int_cb,
AVDictionary **  options 
)

Definition at line 357 of file avio.c.

Referenced by rtp_new_av_stream().

static int retry_transfer_wrapper ( URLContext h,
uint8_t buf,
int  size,
int  size_min,
int(*)(URLContext *h, uint8_t *buf, int size transfer_func 
)
inlinestatic

Definition at line 364 of file avio.c.

Referenced by ffurl_read(), ffurl_read_complete(), and ffurl_write().

int ffurl_read ( URLContext h,
unsigned char *  buf,
int  size 
)

Read up to size bytes from the resource accessed by h, and store the read bytes in buf.

Returns
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).

Definition at line 407 of file avio.c.

Referenced by cache_read(), concat_read(), crypto_read(), ff_rtmp_packet_read(), ff_rtmp_packet_read_internal(), ftp_getc(), ftp_read(), ftp_read_dir(), gnutls_url_pull(), gopher_read(), hls_read(), http_buf_read(), http_getc(), io_read_packet(), rtmp_http_open(), rtmp_http_read(), rtmp_http_send_cmd(), rtmp_write(), rtmpe_read(), sap_fetch_packet(), sap_read_header(), srtp_read(), subfile_read(), tls_client_handshake_loop(), tls_read(), url_bio_bread(), and wrapped_url_read().

int ffurl_read_complete ( URLContext h,
unsigned char *  buf,
int  size 
)

Read as many bytes as possible (up to size), calling the read function multiple times if necessary.

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.

Definition at line 414 of file avio.c.

Referenced by ff_rtsp_tcp_read_packet(), get_chunk_header(), get_http_header_data(), get_tcp_server_response(), read_data_packet(), read_line(), rtmp_calc_swfhash(), rtmp_handshake(), rtmp_packet_read_one_chunk(), rtmp_receive_hs_packet(), rtmp_server_handshake(), rtsp_read_announce(), and tls_read_cb().

int ffurl_write ( URLContext h,
const unsigned char *  buf,
int  size 
)
int64_t ffurl_seek ( URLContext h,
int64_t  pos,
int  whence 
)

Change the position that will be used by the next read/write operation on the resource accessed by h.

Parameters
posspecifies the new position to set
whencespecifies 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).
Returns
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.

Definition at line 434 of file avio.c.

Referenced by async_buffer_task(), cache_read(), cache_seek(), concat_read(), concat_seek(), ffurl_connect(), ffurl_size(), io_seek(), ism_seek(), rtmp_calc_swfhash(), and slave_seek().

int ffurl_closep ( URLContext **  h)

Close the resource accessed by the URLContext h, and free the memory used by it.

Also set the URLContext pointer to NULL.

Returns
a negative value if an error condition occurred, 0 otherwise

Definition at line 444 of file avio.c.

Referenced by ffurl_close(), ftp_abort(), ftp_close_both_connections(), ftp_close_data_connection(), ftp_close_dir(), ftp_open_dir(), http_close(), http_open_cnx(), and mmsh_close().

int ffurl_close ( URLContext h)
const char* avio_find_protocol_name ( const char *  url)

Return the name of the protocol that will handle the passed URL.

NULL is returned if no protocol could be found for the given URL.

Returns
Name of the protocol or NULL.

Definition at line 473 of file avio.c.

Referenced by add_file(), assert_file_overwrite(), ff_configure_buffers_for_index(), hls_window(), open_url(), and seg_init().

int avio_check ( const char *  url,
int  flags 
)

Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url, or a negative value corresponding to an AVERROR code in case of failure.

The returned access flags are masked by the value in flags.

Note
This function is intrinsically unsafe, in the sense that the checked resource may change its existence or permission status from one call to another. Thus you should not trust the returned value, unless you are sure that no other processes are accessing the checked resource.

Definition at line 480 of file avio.c.

Referenced by assert_file_overwrite(), build_feed_streams(), and find_image_range().

int avpriv_io_move ( const char *  url_src,
const char *  url_dst 
)

Move or rename a resource.

Note
url_src and url_dst should share the same protocol and authority.
Parameters
url_srcurl to resource to be moved
url_dstnew url to resource if the operation succeeded
Returns
>=0 on success or negative on error.

Definition at line 499 of file avio.c.

Referenced by dash_flush(), move_op(), and write_manifest().

int avpriv_io_delete ( const char *  url)

Delete a resource.

Parameters
urlresource to be deleted.
Returns
>=0 on success or negative on error.

Definition at line 521 of file avio.c.

Referenced by del_op().

int avio_open_dir ( AVIODirContext **  s,
const char *  url,
AVDictionary **  options 
)

Open directory for reading.

Parameters
sdirectory read context. Pointer to a NULL pointer must be passed.
urldirectory to be listed.
optionsA dictionary filled with protocol-private options. On return this parameter will be destroyed and replaced with a dictionary containing options that were not found. May be NULL.
Returns
>=0 on success or negative on error.

Definition at line 537 of file avio.c.

Referenced by list_op().

int avio_read_dir ( AVIODirContext s,
AVIODirEntry **  next 
)

Get next directory entry.

Returned entry must be freed with avio_free_directory_entry(). In particular it may outlive AVIODirContext.

Parameters
sdirectory read context.
[out]nextnext entry or NULL when no more entries.
Returns
>=0 on success or negative on error. End of list is not considered an error.

Definition at line 575 of file avio.c.

Referenced by list_op().

int avio_close_dir ( AVIODirContext **  s)

Close directory.

Note
Entries created using avio_read_dir() are not deleted and must be freeded with avio_free_directory_entry().
Parameters
sdirectory read context.
Returns
>=0 on success or negative on error.

Definition at line 588 of file avio.c.

Referenced by list_op().

void avio_free_directory_entry ( AVIODirEntry **  entry)

Free entry allocated by avio_read_dir().

Parameters
entryentry to be freed.

Definition at line 603 of file avio.c.

Referenced by avio_read_dir(), ftp_read_dir(), and list_op().

int64_t ffurl_size ( URLContext h)

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.

Definition at line 611 of file avio.c.

Referenced by async_open(), and concat_open().

int ffurl_get_file_handle ( URLContext h)

Return the file descriptor associated with this URL.

For RTP, this will return only the RTP file descriptor, not the RTCP file descriptor.

Returns
the file descriptor associated with this URL, or <0 on error.

Definition at line 626 of file avio.c.

Referenced by ftp_get_file_handle(), http_get_file_handle(), rtp_open(), rtsp_write_packet(), sap_fetch_packet(), sap_write_header(), and srtp_get_file_handle().

int ffurl_get_multi_file_handle ( URLContext h,
int **  handles,
int *  numhandles 
)

Return the file descriptors associated with this URL.

Returns
0 on success or <0 on error.

Definition at line 633 of file avio.c.

Referenced by srtp_get_multi_file_handle().

int ffurl_shutdown ( URLContext h,
int  flags 
)

Signal the URLContext that we are done reading or writing the stream.

Parameters
hpointer to the resource
flagsflags which control how the resource indicated by url is to be shutdown
Returns
a negative value if an error condition occurred, 0 otherwise

Definition at line 648 of file avio.c.

Referenced by ftp_shutdown().

int ff_check_interrupt ( AVIOInterruptCB cb)

Check if the user has requested to interrupt a blocking function associated with cb.

Definition at line 655 of file avio.c.

Referenced by async_check_interrupt(), avformat_find_stream_info(), ff_listen_connect(), ff_network_wait_fd_timeout(), ff_poll_interrupt(), hls_read(), read_data(), retry_transfer_wrapper(), and rtp_read().

Variable Documentation

const AVOption options[]
static
Initial value:
= {
{"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
{"protocol_blacklist", "List of protocols that are not allowed to be used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
{"rw_timeout", "Timeout for IO operations (in microseconds)", 0x42, AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_DECODING_PARAM },
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: avio.c:53
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:275
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:276
#define D
Definition: avio.c:55

Definition at line 56 of file avio.c.

const AVClass ffurl_context_class
Initial value:
= {
.class_name = "URLContext",
.item_name = urlcontext_to_name,
.option = options,
.child_next = urlcontext_child_next,
.child_class_next = ff_urlcontext_child_class_next,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
static void * urlcontext_child_next(void *obj, void *prev)
Definition: avio.c:45
const AVClass * ff_urlcontext_child_class_next(const AVClass *prev)
Definition: protocols.c:74
static const char * urlcontext_to_name(void *ptr)
Definition: avio.c:36
static const AVOption options[]
Definition: avio.c:56

Definition at line 63 of file avio.c.

Referenced by ff_avio_child_class_next(), and url_alloc_for_protocol().