Path: blob/a-new-beginning/libavformat.xcframework/ios-arm64/libavformat.framework/Headers/url.h
2 views
/*1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718/**19* @file20* unbuffered private I/O API21*/2223#ifndef AVFORMAT_URL_H24#define AVFORMAT_URL_H2526#include "avio.h"2728#include "libavutil/dict.h"29#include "libavutil/log.h"3031#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */32#define URL_PROTOCOL_FLAG_NETWORK 2 /*< The protocol uses network */3334extern const AVClass ffurl_context_class;3536typedef struct URLContext {37const AVClass *av_class; /**< information for av_log(). Set by url_open(). */38const struct URLProtocol *prot;39void *priv_data;40char *filename; /**< specified URL */41int flags;42int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */43int is_streamed; /**< true if streamed (no seek possible), default = false */44int is_connected;45AVIOInterruptCB interrupt_callback;46int64_t rw_timeout; /**< maximum time to wait for (network) read/write operation completion, in mcs */47const char *protocol_whitelist;48const char *protocol_blacklist;49int min_packet_size; /**< if non zero, the stream is packetized with this min packet size */50} URLContext;5152typedef struct URLProtocol {53const char *name;54int (*url_open)( URLContext *h, const char *url, int flags);55/**56* This callback is to be used by protocols which open further nested57* protocols. options are then to be passed to ffurl_open_whitelist()58* or ffurl_connect() for those nested protocols.59*/60int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options);61int (*url_accept)(URLContext *s, URLContext **c);62int (*url_handshake)(URLContext *c);6364/**65* Read data from the protocol.66* If data is immediately available (even less than size), EOF is67* reached or an error occurs (including EINTR), return immediately.68* Otherwise:69* In non-blocking mode, return AVERROR(EAGAIN) immediately.70* In blocking mode, wait for data/EOF/error with a short timeout (0.1s),71* and return AVERROR(EAGAIN) on timeout.72* Checking interrupt_callback, looping on EINTR and EAGAIN and until73* enough data has been read is left to the calling function; see74* retry_transfer_wrapper in avio.c.75*/76int (*url_read)( URLContext *h, unsigned char *buf, int size);77int (*url_write)(URLContext *h, const unsigned char *buf, int size);78int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);79int (*url_close)(URLContext *h);80int (*url_read_pause)(URLContext *h, int pause);81int64_t (*url_read_seek)(URLContext *h, int stream_index,82int64_t timestamp, int flags);83int (*url_get_file_handle)(URLContext *h);84int (*url_get_multi_file_handle)(URLContext *h, int **handles,85int *numhandles);86int (*url_get_short_seek)(URLContext *h);87int (*url_shutdown)(URLContext *h, int flags);88const AVClass *priv_data_class;89int priv_data_size;90int flags;91int (*url_check)(URLContext *h, int mask);92int (*url_open_dir)(URLContext *h);93int (*url_read_dir)(URLContext *h, AVIODirEntry **next);94int (*url_close_dir)(URLContext *h);95int (*url_delete)(URLContext *h);96int (*url_move)(URLContext *h_src, URLContext *h_dst);97const char *default_whitelist;98} URLProtocol;99100/**101* Create a URLContext for accessing to the resource indicated by102* url, but do not initiate the connection yet.103*104* @param puc pointer to the location where, in case of success, the105* function puts the pointer to the created URLContext106* @param flags flags which control how the resource indicated by url107* is to be opened108* @param int_cb interrupt callback to use for the URLContext, may be109* NULL110* @return >= 0 in case of success, a negative value corresponding to an111* AVERROR code in case of failure112*/113int ffurl_alloc(URLContext **puc, const char *filename, int flags,114const AVIOInterruptCB *int_cb);115116/**117* Connect an URLContext that has been allocated by ffurl_alloc118*119* @param options A dictionary filled with options for nested protocols,120* i.e. it will be passed to url_open2() for protocols implementing it.121* This parameter will be destroyed and replaced with a dict containing options122* that were not found. May be NULL.123*/124int ffurl_connect(URLContext *uc, AVDictionary **options);125126/**127* Create an URLContext for accessing to the resource indicated by128* url, and open it.129*130* @param puc pointer to the location where, in case of success, the131* function puts the pointer to the created URLContext132* @param flags flags which control how the resource indicated by url133* is to be opened134* @param int_cb interrupt callback to use for the URLContext, may be135* NULL136* @param options A dictionary filled with protocol-private options. On return137* this parameter will be destroyed and replaced with a dict containing options138* that were not found. May be NULL.139* @param parent An enclosing URLContext, whose generic options should140* be applied to this URLContext as well.141* @return >= 0 in case of success, a negative value corresponding to an142* AVERROR code in case of failure143*/144int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags,145const AVIOInterruptCB *int_cb, AVDictionary **options,146const char *whitelist, const char* blacklist,147URLContext *parent);148149/**150* Accept an URLContext c on an URLContext s151*152* @param s server context153* @param c client context, must be unallocated.154* @return >= 0 on success, ff_neterrno() on failure.155*/156int ffurl_accept(URLContext *s, URLContext **c);157158/**159* Perform one step of the protocol handshake to accept a new client.160* See avio_handshake() for details.161* Implementations should try to return decreasing values.162* If the protocol uses an underlying protocol, the underlying handshake is163* usually the first step, and the return value can be:164* (largest value for this protocol) + (return value from other protocol)165*166* @param c the client context167* @return >= 0 on success or a negative value corresponding168* to an AVERROR code on failure169*/170int ffurl_handshake(URLContext *c);171172/**173* Read up to size bytes from the resource accessed by h, and store174* the read bytes in buf.175*176* @return The number of bytes actually read, or a negative value177* corresponding to an AVERROR code in case of error. A value of zero178* indicates that it is not possible to read more from the accessed179* resource (except if the value of the size argument is also zero).180*/181int ffurl_read(URLContext *h, unsigned char *buf, int size);182183/**184* Read as many bytes as possible (up to size), calling the185* read function multiple times if necessary.186* This makes special short-read handling in applications187* unnecessary, if the return value is < size then it is188* certain there was either an error or the end of file was reached.189*/190int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);191192/**193* Write size bytes from buf to the resource accessed by h.194*195* @return the number of bytes actually written, or a negative value196* corresponding to an AVERROR code in case of failure197*/198int ffurl_write(URLContext *h, const unsigned char *buf, int size);199200/**201* Change the position that will be used by the next read/write202* operation on the resource accessed by h.203*204* @param pos specifies the new position to set205* @param whence specifies how pos should be interpreted, it must be206* one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the207* current position), SEEK_END (seek from the end), or AVSEEK_SIZE208* (return the filesize of the requested resource, pos is ignored).209* @return a negative value corresponding to an AVERROR code in case210* of failure, or the resulting file position, measured in bytes from211* the beginning of the file. You can use this feature together with212* SEEK_CUR to read the current file position.213*/214int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);215216/**217* Close the resource accessed by the URLContext h, and free the218* memory used by it. Also set the URLContext pointer to NULL.219*220* @return a negative value if an error condition occurred, 0221* otherwise222*/223int ffurl_closep(URLContext **h);224int ffurl_close(URLContext *h);225226/**227* Return the filesize of the resource accessed by h, AVERROR(ENOSYS)228* if the operation is not supported by h, or another negative value229* corresponding to an AVERROR error code in case of failure.230*/231int64_t ffurl_size(URLContext *h);232233/**234* Return the file descriptor associated with this URL. For RTP, this235* will return only the RTP file descriptor, not the RTCP file descriptor.236*237* @return the file descriptor associated with this URL, or <0 on error.238*/239int ffurl_get_file_handle(URLContext *h);240241/**242* Return the file descriptors associated with this URL.243*244* @return 0 on success or <0 on error.245*/246int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles);247248/**249* Return the current short seek threshold value for this URL.250*251* @return threshold (>0) on success or <=0 on error.252*/253int ffurl_get_short_seek(URLContext *h);254255/**256* Signal the URLContext that we are done reading or writing the stream.257*258* @param h pointer to the resource259* @param flags flags which control how the resource indicated by url260* is to be shutdown261*262* @return a negative value if an error condition occurred, 0263* otherwise264*/265int ffurl_shutdown(URLContext *h, int flags);266267/**268* Check if the user has requested to interrupt a blocking function269* associated with cb.270*/271int ff_check_interrupt(AVIOInterruptCB *cb);272273/* udp.c */274int ff_udp_set_remote_url(URLContext *h, const char *uri);275int ff_udp_get_local_port(URLContext *h);276277/**278* Assemble a URL string from components. This is the reverse operation279* of av_url_split.280*281* Note, this requires networking to be initialized, so the caller must282* ensure ff_network_init has been called.283*284* @see av_url_split285*286* @param str the buffer to fill with the url287* @param size the size of the str buffer288* @param proto the protocol identifier, if null, the separator289* after the identifier is left out, too290* @param authorization an optional authorization string, may be null.291* An empty string is treated the same as a null string.292* @param hostname the host name string293* @param port the port number, left out from the string if negative294* @param fmt a generic format string for everything to add after the295* host/port, may be null296* @return the number of characters written to the destination buffer297*/298int ff_url_join(char *str, int size, const char *proto,299const char *authorization, const char *hostname,300int port, const char *fmt, ...) av_printf_format(7, 8);301302/**303* Convert a relative url into an absolute url, given a base url.304*305* @param buf the buffer where output absolute url is written306* @param size the size of buf307* @param base the base url, may be equal to buf.308* @param rel the new url, which is interpreted relative to base309* @param handle_dos_paths handle DOS paths for file or unspecified protocol310*/311int ff_make_absolute_url2(char *buf, int size, const char *base,312const char *rel, int handle_dos_paths);313314/**315* Convert a relative url into an absolute url, given a base url.316*317* Same as ff_make_absolute_url2 with handle_dos_paths being equal to318* HAVE_DOS_PATHS config variable.319*/320int ff_make_absolute_url(char *buf, int size, const char *base,321const char *rel);322323/**324* Allocate directory entry with default values.325*326* @return entry or NULL on error327*/328AVIODirEntry *ff_alloc_dir_entry(void);329330const AVClass *ff_urlcontext_child_class_iterate(void **iter);331332/**333* Construct a list of protocols matching a given whitelist and/or blacklist.334*335* @param whitelist a comma-separated list of allowed protocol names or NULL. If336* this is a non-empty string, only protocols in this list will337* be included.338* @param blacklist a comma-separated list of forbidden protocol names or NULL.339* If this is a non-empty string, all protocols in this list340* will be excluded.341*342* @return a NULL-terminated array of matching protocols. The array must be343* freed by the caller.344*/345const URLProtocol **ffurl_get_protocols(const char *whitelist,346const char *blacklist);347348typedef struct URLComponents {349const char *url; /**< whole URL, for reference */350const char *scheme; /**< possibly including lavf-specific options */351const char *authority; /**< "//" if it is a real URL */352const char *userinfo; /**< including final '@' if present */353const char *host;354const char *port; /**< including initial ':' if present */355const char *path;356const char *query; /**< including initial '?' if present */357const char *fragment; /**< including initial '#' if present */358const char *end;359} URLComponents;360361#define url_component_end_scheme authority362#define url_component_end_authority userinfo363#define url_component_end_userinfo host364#define url_component_end_host port365#define url_component_end_port path366#define url_component_end_path query367#define url_component_end_query fragment368#define url_component_end_fragment end369#define url_component_end_authority_full path370371#define URL_COMPONENT_HAVE(uc, component) \372((uc).url_component_end_##component > (uc).component)373374/**375* Parse an URL to find the components.376*377* Each component runs until the start of the next component,378* possibly including a mandatory delimiter.379*380* @param uc structure to fill with pointers to the components.381* @param url URL to parse.382* @param end end of the URL, or NULL to parse to the end of string.383*384* @return >= 0 for success or an AVERROR code, especially if the URL is385* malformed.386*/387int ff_url_decompose(URLComponents *uc, const char *url, const char *end);388389/**390* Move or rename a resource.391*392* @note url_src and url_dst should share the same protocol and authority.393*394* @param url_src url to resource to be moved395* @param url_dst new url to resource if the operation succeeded396* @return >=0 on success or negative on error.397*/398int ffurl_move(const char *url_src, const char *url_dst);399400/**401* Delete a resource.402*403* @param url resource to be deleted.404* @return >=0 on success or negative on error.405*/406int ffurl_delete(const char *url);407408#endif /* AVFORMAT_URL_H */409410411