1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * copyright (c) 2001 Fabrice Bellard 3cabdff1aSopenharmony_ci * 4cabdff1aSopenharmony_ci * This file is part of FFmpeg. 5cabdff1aSopenharmony_ci * 6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 10cabdff1aSopenharmony_ci * 11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14cabdff1aSopenharmony_ci * Lesser General Public License for more details. 15cabdff1aSopenharmony_ci * 16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19cabdff1aSopenharmony_ci */ 20cabdff1aSopenharmony_ci#ifndef AVFORMAT_AVIO_H 21cabdff1aSopenharmony_ci#define AVFORMAT_AVIO_H 22cabdff1aSopenharmony_ci 23cabdff1aSopenharmony_ci/** 24cabdff1aSopenharmony_ci * @file 25cabdff1aSopenharmony_ci * @ingroup lavf_io 26cabdff1aSopenharmony_ci * Buffered I/O operations 27cabdff1aSopenharmony_ci */ 28cabdff1aSopenharmony_ci 29cabdff1aSopenharmony_ci#include <stdint.h> 30cabdff1aSopenharmony_ci#include <stdio.h> 31cabdff1aSopenharmony_ci 32cabdff1aSopenharmony_ci#include "libavutil/attributes.h" 33cabdff1aSopenharmony_ci#include "libavutil/dict.h" 34cabdff1aSopenharmony_ci#include "libavutil/log.h" 35cabdff1aSopenharmony_ci 36cabdff1aSopenharmony_ci#include "libavformat/version_major.h" 37cabdff1aSopenharmony_ci 38cabdff1aSopenharmony_ci/** 39cabdff1aSopenharmony_ci * Seeking works like for a local file. 40cabdff1aSopenharmony_ci */ 41cabdff1aSopenharmony_ci#define AVIO_SEEKABLE_NORMAL (1 << 0) 42cabdff1aSopenharmony_ci 43cabdff1aSopenharmony_ci/** 44cabdff1aSopenharmony_ci * Seeking by timestamp with avio_seek_time() is possible. 45cabdff1aSopenharmony_ci */ 46cabdff1aSopenharmony_ci#define AVIO_SEEKABLE_TIME (1 << 1) 47cabdff1aSopenharmony_ci 48cabdff1aSopenharmony_ci/** 49cabdff1aSopenharmony_ci * Callback for checking whether to abort blocking functions. 50cabdff1aSopenharmony_ci * AVERROR_EXIT is returned in this case by the interrupted 51cabdff1aSopenharmony_ci * function. During blocking operations, callback is called with 52cabdff1aSopenharmony_ci * opaque as parameter. If the callback returns 1, the 53cabdff1aSopenharmony_ci * blocking operation will be aborted. 54cabdff1aSopenharmony_ci * 55cabdff1aSopenharmony_ci * No members can be added to this struct without a major bump, if 56cabdff1aSopenharmony_ci * new elements have been added after this struct in AVFormatContext 57cabdff1aSopenharmony_ci * or AVIOContext. 58cabdff1aSopenharmony_ci */ 59cabdff1aSopenharmony_citypedef struct AVIOInterruptCB { 60cabdff1aSopenharmony_ci int (*callback)(void*); 61cabdff1aSopenharmony_ci void *opaque; 62cabdff1aSopenharmony_ci} AVIOInterruptCB; 63cabdff1aSopenharmony_ci 64cabdff1aSopenharmony_ci/** 65cabdff1aSopenharmony_ci * Directory entry types. 66cabdff1aSopenharmony_ci */ 67cabdff1aSopenharmony_cienum AVIODirEntryType { 68cabdff1aSopenharmony_ci AVIO_ENTRY_UNKNOWN, 69cabdff1aSopenharmony_ci AVIO_ENTRY_BLOCK_DEVICE, 70cabdff1aSopenharmony_ci AVIO_ENTRY_CHARACTER_DEVICE, 71cabdff1aSopenharmony_ci AVIO_ENTRY_DIRECTORY, 72cabdff1aSopenharmony_ci AVIO_ENTRY_NAMED_PIPE, 73cabdff1aSopenharmony_ci AVIO_ENTRY_SYMBOLIC_LINK, 74cabdff1aSopenharmony_ci AVIO_ENTRY_SOCKET, 75cabdff1aSopenharmony_ci AVIO_ENTRY_FILE, 76cabdff1aSopenharmony_ci AVIO_ENTRY_SERVER, 77cabdff1aSopenharmony_ci AVIO_ENTRY_SHARE, 78cabdff1aSopenharmony_ci AVIO_ENTRY_WORKGROUP, 79cabdff1aSopenharmony_ci}; 80cabdff1aSopenharmony_ci 81cabdff1aSopenharmony_ci/** 82cabdff1aSopenharmony_ci * Describes single entry of the directory. 83cabdff1aSopenharmony_ci * 84cabdff1aSopenharmony_ci * Only name and type fields are guaranteed be set. 85cabdff1aSopenharmony_ci * Rest of fields are protocol or/and platform dependent and might be unknown. 86cabdff1aSopenharmony_ci */ 87cabdff1aSopenharmony_citypedef struct AVIODirEntry { 88cabdff1aSopenharmony_ci char *name; /**< Filename */ 89cabdff1aSopenharmony_ci int type; /**< Type of the entry */ 90cabdff1aSopenharmony_ci int utf8; /**< Set to 1 when name is encoded with UTF-8, 0 otherwise. 91cabdff1aSopenharmony_ci Name can be encoded with UTF-8 even though 0 is set. */ 92cabdff1aSopenharmony_ci int64_t size; /**< File size in bytes, -1 if unknown. */ 93cabdff1aSopenharmony_ci int64_t modification_timestamp; /**< Time of last modification in microseconds since unix 94cabdff1aSopenharmony_ci epoch, -1 if unknown. */ 95cabdff1aSopenharmony_ci int64_t access_timestamp; /**< Time of last access in microseconds since unix epoch, 96cabdff1aSopenharmony_ci -1 if unknown. */ 97cabdff1aSopenharmony_ci int64_t status_change_timestamp; /**< Time of last status change in microseconds since unix 98cabdff1aSopenharmony_ci epoch, -1 if unknown. */ 99cabdff1aSopenharmony_ci int64_t user_id; /**< User ID of owner, -1 if unknown. */ 100cabdff1aSopenharmony_ci int64_t group_id; /**< Group ID of owner, -1 if unknown. */ 101cabdff1aSopenharmony_ci int64_t filemode; /**< Unix file mode, -1 if unknown. */ 102cabdff1aSopenharmony_ci} AVIODirEntry; 103cabdff1aSopenharmony_ci 104cabdff1aSopenharmony_citypedef struct AVIODirContext { 105cabdff1aSopenharmony_ci struct URLContext *url_context; 106cabdff1aSopenharmony_ci} AVIODirContext; 107cabdff1aSopenharmony_ci 108cabdff1aSopenharmony_ci/** 109cabdff1aSopenharmony_ci * Different data types that can be returned via the AVIO 110cabdff1aSopenharmony_ci * write_data_type callback. 111cabdff1aSopenharmony_ci */ 112cabdff1aSopenharmony_cienum AVIODataMarkerType { 113cabdff1aSopenharmony_ci /** 114cabdff1aSopenharmony_ci * Header data; this needs to be present for the stream to be decodeable. 115cabdff1aSopenharmony_ci */ 116cabdff1aSopenharmony_ci AVIO_DATA_MARKER_HEADER, 117cabdff1aSopenharmony_ci /** 118cabdff1aSopenharmony_ci * A point in the output bytestream where a decoder can start decoding 119cabdff1aSopenharmony_ci * (i.e. a keyframe). A demuxer/decoder given the data flagged with 120cabdff1aSopenharmony_ci * AVIO_DATA_MARKER_HEADER, followed by any AVIO_DATA_MARKER_SYNC_POINT, 121cabdff1aSopenharmony_ci * should give decodeable results. 122cabdff1aSopenharmony_ci */ 123cabdff1aSopenharmony_ci AVIO_DATA_MARKER_SYNC_POINT, 124cabdff1aSopenharmony_ci /** 125cabdff1aSopenharmony_ci * A point in the output bytestream where a demuxer can start parsing 126cabdff1aSopenharmony_ci * (for non self synchronizing bytestream formats). That is, any 127cabdff1aSopenharmony_ci * non-keyframe packet start point. 128cabdff1aSopenharmony_ci */ 129cabdff1aSopenharmony_ci AVIO_DATA_MARKER_BOUNDARY_POINT, 130cabdff1aSopenharmony_ci /** 131cabdff1aSopenharmony_ci * This is any, unlabelled data. It can either be a muxer not marking 132cabdff1aSopenharmony_ci * any positions at all, it can be an actual boundary/sync point 133cabdff1aSopenharmony_ci * that the muxer chooses not to mark, or a later part of a packet/fragment 134cabdff1aSopenharmony_ci * that is cut into multiple write callbacks due to limited IO buffer size. 135cabdff1aSopenharmony_ci */ 136cabdff1aSopenharmony_ci AVIO_DATA_MARKER_UNKNOWN, 137cabdff1aSopenharmony_ci /** 138cabdff1aSopenharmony_ci * Trailer data, which doesn't contain actual content, but only for 139cabdff1aSopenharmony_ci * finalizing the output file. 140cabdff1aSopenharmony_ci */ 141cabdff1aSopenharmony_ci AVIO_DATA_MARKER_TRAILER, 142cabdff1aSopenharmony_ci /** 143cabdff1aSopenharmony_ci * A point in the output bytestream where the underlying AVIOContext might 144cabdff1aSopenharmony_ci * flush the buffer depending on latency or buffering requirements. Typically 145cabdff1aSopenharmony_ci * means the end of a packet. 146cabdff1aSopenharmony_ci */ 147cabdff1aSopenharmony_ci AVIO_DATA_MARKER_FLUSH_POINT, 148cabdff1aSopenharmony_ci}; 149cabdff1aSopenharmony_ci 150cabdff1aSopenharmony_ci/** 151cabdff1aSopenharmony_ci * Bytestream IO Context. 152cabdff1aSopenharmony_ci * New public fields can be added with minor version bumps. 153cabdff1aSopenharmony_ci * Removal, reordering and changes to existing public fields require 154cabdff1aSopenharmony_ci * a major version bump. 155cabdff1aSopenharmony_ci * sizeof(AVIOContext) must not be used outside libav*. 156cabdff1aSopenharmony_ci * 157cabdff1aSopenharmony_ci * @note None of the function pointers in AVIOContext should be called 158cabdff1aSopenharmony_ci * directly, they should only be set by the client application 159cabdff1aSopenharmony_ci * when implementing custom I/O. Normally these are set to the 160cabdff1aSopenharmony_ci * function pointers specified in avio_alloc_context() 161cabdff1aSopenharmony_ci */ 162cabdff1aSopenharmony_citypedef struct AVIOContext { 163cabdff1aSopenharmony_ci /** 164cabdff1aSopenharmony_ci * A class for private options. 165cabdff1aSopenharmony_ci * 166cabdff1aSopenharmony_ci * If this AVIOContext is created by avio_open2(), av_class is set and 167cabdff1aSopenharmony_ci * passes the options down to protocols. 168cabdff1aSopenharmony_ci * 169cabdff1aSopenharmony_ci * If this AVIOContext is manually allocated, then av_class may be set by 170cabdff1aSopenharmony_ci * the caller. 171cabdff1aSopenharmony_ci * 172cabdff1aSopenharmony_ci * warning -- this field can be NULL, be sure to not pass this AVIOContext 173cabdff1aSopenharmony_ci * to any av_opt_* functions in that case. 174cabdff1aSopenharmony_ci */ 175cabdff1aSopenharmony_ci const AVClass *av_class; 176cabdff1aSopenharmony_ci 177cabdff1aSopenharmony_ci /* 178cabdff1aSopenharmony_ci * The following shows the relationship between buffer, buf_ptr, 179cabdff1aSopenharmony_ci * buf_ptr_max, buf_end, buf_size, and pos, when reading and when writing 180cabdff1aSopenharmony_ci * (since AVIOContext is used for both): 181cabdff1aSopenharmony_ci * 182cabdff1aSopenharmony_ci ********************************************************************************** 183cabdff1aSopenharmony_ci * READING 184cabdff1aSopenharmony_ci ********************************************************************************** 185cabdff1aSopenharmony_ci * 186cabdff1aSopenharmony_ci * | buffer_size | 187cabdff1aSopenharmony_ci * |---------------------------------------| 188cabdff1aSopenharmony_ci * | | 189cabdff1aSopenharmony_ci * 190cabdff1aSopenharmony_ci * buffer buf_ptr buf_end 191cabdff1aSopenharmony_ci * +---------------+-----------------------+ 192cabdff1aSopenharmony_ci * |/ / / / / / / /|/ / / / / / /| | 193cabdff1aSopenharmony_ci * read buffer: |/ / consumed / | to be read /| | 194cabdff1aSopenharmony_ci * |/ / / / / / / /|/ / / / / / /| | 195cabdff1aSopenharmony_ci * +---------------+-----------------------+ 196cabdff1aSopenharmony_ci * 197cabdff1aSopenharmony_ci * pos 198cabdff1aSopenharmony_ci * +-------------------------------------------+-----------------+ 199cabdff1aSopenharmony_ci * input file: | | | 200cabdff1aSopenharmony_ci * +-------------------------------------------+-----------------+ 201cabdff1aSopenharmony_ci * 202cabdff1aSopenharmony_ci * 203cabdff1aSopenharmony_ci ********************************************************************************** 204cabdff1aSopenharmony_ci * WRITING 205cabdff1aSopenharmony_ci ********************************************************************************** 206cabdff1aSopenharmony_ci * 207cabdff1aSopenharmony_ci * | buffer_size | 208cabdff1aSopenharmony_ci * |--------------------------------------| 209cabdff1aSopenharmony_ci * | | 210cabdff1aSopenharmony_ci * 211cabdff1aSopenharmony_ci * buf_ptr_max 212cabdff1aSopenharmony_ci * buffer (buf_ptr) buf_end 213cabdff1aSopenharmony_ci * +-----------------------+--------------+ 214cabdff1aSopenharmony_ci * |/ / / / / / / / / / / /| | 215cabdff1aSopenharmony_ci * write buffer: | / / to be flushed / / | | 216cabdff1aSopenharmony_ci * |/ / / / / / / / / / / /| | 217cabdff1aSopenharmony_ci * +-----------------------+--------------+ 218cabdff1aSopenharmony_ci * buf_ptr can be in this 219cabdff1aSopenharmony_ci * due to a backward seek 220cabdff1aSopenharmony_ci * 221cabdff1aSopenharmony_ci * pos 222cabdff1aSopenharmony_ci * +-------------+----------------------------------------------+ 223cabdff1aSopenharmony_ci * output file: | | | 224cabdff1aSopenharmony_ci * +-------------+----------------------------------------------+ 225cabdff1aSopenharmony_ci * 226cabdff1aSopenharmony_ci */ 227cabdff1aSopenharmony_ci unsigned char *buffer; /**< Start of the buffer. */ 228cabdff1aSopenharmony_ci int buffer_size; /**< Maximum buffer size */ 229cabdff1aSopenharmony_ci unsigned char *buf_ptr; /**< Current position in the buffer */ 230cabdff1aSopenharmony_ci unsigned char *buf_end; /**< End of the data, may be less than 231cabdff1aSopenharmony_ci buffer+buffer_size if the read function returned 232cabdff1aSopenharmony_ci less data than requested, e.g. for streams where 233cabdff1aSopenharmony_ci no more data has been received yet. */ 234cabdff1aSopenharmony_ci void *opaque; /**< A private pointer, passed to the read/write/seek/... 235cabdff1aSopenharmony_ci functions. */ 236cabdff1aSopenharmony_ci int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); 237cabdff1aSopenharmony_ci int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); 238cabdff1aSopenharmony_ci int64_t (*seek)(void *opaque, int64_t offset, int whence); 239cabdff1aSopenharmony_ci int64_t pos; /**< position in the file of the current buffer */ 240cabdff1aSopenharmony_ci int eof_reached; /**< true if was unable to read due to error or eof */ 241cabdff1aSopenharmony_ci int error; /**< contains the error code or 0 if no error happened */ 242cabdff1aSopenharmony_ci int write_flag; /**< true if open for writing */ 243cabdff1aSopenharmony_ci int max_packet_size; 244cabdff1aSopenharmony_ci int min_packet_size; /**< Try to buffer at least this amount of data 245cabdff1aSopenharmony_ci before flushing it. */ 246cabdff1aSopenharmony_ci unsigned long checksum; 247cabdff1aSopenharmony_ci unsigned char *checksum_ptr; 248cabdff1aSopenharmony_ci unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); 249cabdff1aSopenharmony_ci /** 250cabdff1aSopenharmony_ci * Pause or resume playback for network streaming protocols - e.g. MMS. 251cabdff1aSopenharmony_ci */ 252cabdff1aSopenharmony_ci int (*read_pause)(void *opaque, int pause); 253cabdff1aSopenharmony_ci /** 254cabdff1aSopenharmony_ci * Seek to a given timestamp in stream with the specified stream_index. 255cabdff1aSopenharmony_ci * Needed for some network streaming protocols which don't support seeking 256cabdff1aSopenharmony_ci * to byte position. 257cabdff1aSopenharmony_ci */ 258cabdff1aSopenharmony_ci int64_t (*read_seek)(void *opaque, int stream_index, 259cabdff1aSopenharmony_ci int64_t timestamp, int flags); 260cabdff1aSopenharmony_ci /** 261cabdff1aSopenharmony_ci * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable. 262cabdff1aSopenharmony_ci */ 263cabdff1aSopenharmony_ci int seekable; 264cabdff1aSopenharmony_ci 265cabdff1aSopenharmony_ci /** 266cabdff1aSopenharmony_ci * avio_read and avio_write should if possible be satisfied directly 267cabdff1aSopenharmony_ci * instead of going through a buffer, and avio_seek will always 268cabdff1aSopenharmony_ci * call the underlying seek function directly. 269cabdff1aSopenharmony_ci */ 270cabdff1aSopenharmony_ci int direct; 271cabdff1aSopenharmony_ci 272cabdff1aSopenharmony_ci /** 273cabdff1aSopenharmony_ci * ',' separated list of allowed protocols. 274cabdff1aSopenharmony_ci */ 275cabdff1aSopenharmony_ci const char *protocol_whitelist; 276cabdff1aSopenharmony_ci 277cabdff1aSopenharmony_ci /** 278cabdff1aSopenharmony_ci * ',' separated list of disallowed protocols. 279cabdff1aSopenharmony_ci */ 280cabdff1aSopenharmony_ci const char *protocol_blacklist; 281cabdff1aSopenharmony_ci 282cabdff1aSopenharmony_ci /** 283cabdff1aSopenharmony_ci * A callback that is used instead of write_packet. 284cabdff1aSopenharmony_ci */ 285cabdff1aSopenharmony_ci int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size, 286cabdff1aSopenharmony_ci enum AVIODataMarkerType type, int64_t time); 287cabdff1aSopenharmony_ci /** 288cabdff1aSopenharmony_ci * If set, don't call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT, 289cabdff1aSopenharmony_ci * but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly 290cabdff1aSopenharmony_ci * small chunks of data returned from the callback). 291cabdff1aSopenharmony_ci */ 292cabdff1aSopenharmony_ci int ignore_boundary_point; 293cabdff1aSopenharmony_ci 294cabdff1aSopenharmony_ci#if FF_API_AVIOCONTEXT_WRITTEN 295cabdff1aSopenharmony_ci /** 296cabdff1aSopenharmony_ci * @deprecated field utilized privately by libavformat. For a public 297cabdff1aSopenharmony_ci * statistic of how many bytes were written out, see 298cabdff1aSopenharmony_ci * AVIOContext::bytes_written. 299cabdff1aSopenharmony_ci */ 300cabdff1aSopenharmony_ci attribute_deprecated 301cabdff1aSopenharmony_ci int64_t written; 302cabdff1aSopenharmony_ci#endif 303cabdff1aSopenharmony_ci 304cabdff1aSopenharmony_ci /** 305cabdff1aSopenharmony_ci * Maximum reached position before a backward seek in the write buffer, 306cabdff1aSopenharmony_ci * used keeping track of already written data for a later flush. 307cabdff1aSopenharmony_ci */ 308cabdff1aSopenharmony_ci unsigned char *buf_ptr_max; 309cabdff1aSopenharmony_ci 310cabdff1aSopenharmony_ci /** 311cabdff1aSopenharmony_ci * Read-only statistic of bytes read for this AVIOContext. 312cabdff1aSopenharmony_ci */ 313cabdff1aSopenharmony_ci int64_t bytes_read; 314cabdff1aSopenharmony_ci 315cabdff1aSopenharmony_ci /** 316cabdff1aSopenharmony_ci * Read-only statistic of bytes written for this AVIOContext. 317cabdff1aSopenharmony_ci */ 318cabdff1aSopenharmony_ci int64_t bytes_written; 319cabdff1aSopenharmony_ci} AVIOContext; 320cabdff1aSopenharmony_ci 321cabdff1aSopenharmony_ci/** 322cabdff1aSopenharmony_ci * Return the name of the protocol that will handle the passed URL. 323cabdff1aSopenharmony_ci * 324cabdff1aSopenharmony_ci * NULL is returned if no protocol could be found for the given URL. 325cabdff1aSopenharmony_ci * 326cabdff1aSopenharmony_ci * @return Name of the protocol or NULL. 327cabdff1aSopenharmony_ci */ 328cabdff1aSopenharmony_ciconst char *avio_find_protocol_name(const char *url); 329cabdff1aSopenharmony_ci 330cabdff1aSopenharmony_ci/** 331cabdff1aSopenharmony_ci * Return AVIO_FLAG_* access flags corresponding to the access permissions 332cabdff1aSopenharmony_ci * of the resource in url, or a negative value corresponding to an 333cabdff1aSopenharmony_ci * AVERROR code in case of failure. The returned access flags are 334cabdff1aSopenharmony_ci * masked by the value in flags. 335cabdff1aSopenharmony_ci * 336cabdff1aSopenharmony_ci * @note This function is intrinsically unsafe, in the sense that the 337cabdff1aSopenharmony_ci * checked resource may change its existence or permission status from 338cabdff1aSopenharmony_ci * one call to another. Thus you should not trust the returned value, 339cabdff1aSopenharmony_ci * unless you are sure that no other processes are accessing the 340cabdff1aSopenharmony_ci * checked resource. 341cabdff1aSopenharmony_ci */ 342cabdff1aSopenharmony_ciint avio_check(const char *url, int flags); 343cabdff1aSopenharmony_ci 344cabdff1aSopenharmony_ci/** 345cabdff1aSopenharmony_ci * Open directory for reading. 346cabdff1aSopenharmony_ci * 347cabdff1aSopenharmony_ci * @param s directory read context. Pointer to a NULL pointer must be passed. 348cabdff1aSopenharmony_ci * @param url directory to be listed. 349cabdff1aSopenharmony_ci * @param options A dictionary filled with protocol-private options. On return 350cabdff1aSopenharmony_ci * this parameter will be destroyed and replaced with a dictionary 351cabdff1aSopenharmony_ci * containing options that were not found. May be NULL. 352cabdff1aSopenharmony_ci * @return >=0 on success or negative on error. 353cabdff1aSopenharmony_ci */ 354cabdff1aSopenharmony_ciint avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options); 355cabdff1aSopenharmony_ci 356cabdff1aSopenharmony_ci/** 357cabdff1aSopenharmony_ci * Get next directory entry. 358cabdff1aSopenharmony_ci * 359cabdff1aSopenharmony_ci * Returned entry must be freed with avio_free_directory_entry(). In particular 360cabdff1aSopenharmony_ci * it may outlive AVIODirContext. 361cabdff1aSopenharmony_ci * 362cabdff1aSopenharmony_ci * @param s directory read context. 363cabdff1aSopenharmony_ci * @param[out] next next entry or NULL when no more entries. 364cabdff1aSopenharmony_ci * @return >=0 on success or negative on error. End of list is not considered an 365cabdff1aSopenharmony_ci * error. 366cabdff1aSopenharmony_ci */ 367cabdff1aSopenharmony_ciint avio_read_dir(AVIODirContext *s, AVIODirEntry **next); 368cabdff1aSopenharmony_ci 369cabdff1aSopenharmony_ci/** 370cabdff1aSopenharmony_ci * Close directory. 371cabdff1aSopenharmony_ci * 372cabdff1aSopenharmony_ci * @note Entries created using avio_read_dir() are not deleted and must be 373cabdff1aSopenharmony_ci * freeded with avio_free_directory_entry(). 374cabdff1aSopenharmony_ci * 375cabdff1aSopenharmony_ci * @param s directory read context. 376cabdff1aSopenharmony_ci * @return >=0 on success or negative on error. 377cabdff1aSopenharmony_ci */ 378cabdff1aSopenharmony_ciint avio_close_dir(AVIODirContext **s); 379cabdff1aSopenharmony_ci 380cabdff1aSopenharmony_ci/** 381cabdff1aSopenharmony_ci * Free entry allocated by avio_read_dir(). 382cabdff1aSopenharmony_ci * 383cabdff1aSopenharmony_ci * @param entry entry to be freed. 384cabdff1aSopenharmony_ci */ 385cabdff1aSopenharmony_civoid avio_free_directory_entry(AVIODirEntry **entry); 386cabdff1aSopenharmony_ci 387cabdff1aSopenharmony_ci/** 388cabdff1aSopenharmony_ci * Allocate and initialize an AVIOContext for buffered I/O. It must be later 389cabdff1aSopenharmony_ci * freed with avio_context_free(). 390cabdff1aSopenharmony_ci * 391cabdff1aSopenharmony_ci * @param buffer Memory block for input/output operations via AVIOContext. 392cabdff1aSopenharmony_ci * The buffer must be allocated with av_malloc() and friends. 393cabdff1aSopenharmony_ci * It may be freed and replaced with a new buffer by libavformat. 394cabdff1aSopenharmony_ci * AVIOContext.buffer holds the buffer currently in use, 395cabdff1aSopenharmony_ci * which must be later freed with av_free(). 396cabdff1aSopenharmony_ci * @param buffer_size The buffer size is very important for performance. 397cabdff1aSopenharmony_ci * For protocols with fixed blocksize it should be set to this blocksize. 398cabdff1aSopenharmony_ci * For others a typical size is a cache page, e.g. 4kb. 399cabdff1aSopenharmony_ci * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise. 400cabdff1aSopenharmony_ci * @param opaque An opaque pointer to user-specific data. 401cabdff1aSopenharmony_ci * @param read_packet A function for refilling the buffer, may be NULL. 402cabdff1aSopenharmony_ci * For stream protocols, must never return 0 but rather 403cabdff1aSopenharmony_ci * a proper AVERROR code. 404cabdff1aSopenharmony_ci * @param write_packet A function for writing the buffer contents, may be NULL. 405cabdff1aSopenharmony_ci * The function may not change the input buffers content. 406cabdff1aSopenharmony_ci * @param seek A function for seeking to specified byte position, may be NULL. 407cabdff1aSopenharmony_ci * 408cabdff1aSopenharmony_ci * @return Allocated AVIOContext or NULL on failure. 409cabdff1aSopenharmony_ci */ 410cabdff1aSopenharmony_ciAVIOContext *avio_alloc_context( 411cabdff1aSopenharmony_ci unsigned char *buffer, 412cabdff1aSopenharmony_ci int buffer_size, 413cabdff1aSopenharmony_ci int write_flag, 414cabdff1aSopenharmony_ci void *opaque, 415cabdff1aSopenharmony_ci int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), 416cabdff1aSopenharmony_ci int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), 417cabdff1aSopenharmony_ci int64_t (*seek)(void *opaque, int64_t offset, int whence)); 418cabdff1aSopenharmony_ci 419cabdff1aSopenharmony_ci/** 420cabdff1aSopenharmony_ci * Free the supplied IO context and everything associated with it. 421cabdff1aSopenharmony_ci * 422cabdff1aSopenharmony_ci * @param s Double pointer to the IO context. This function will write NULL 423cabdff1aSopenharmony_ci * into s. 424cabdff1aSopenharmony_ci */ 425cabdff1aSopenharmony_civoid avio_context_free(AVIOContext **s); 426cabdff1aSopenharmony_ci 427cabdff1aSopenharmony_civoid avio_w8(AVIOContext *s, int b); 428cabdff1aSopenharmony_civoid avio_write(AVIOContext *s, const unsigned char *buf, int size); 429cabdff1aSopenharmony_civoid avio_wl64(AVIOContext *s, uint64_t val); 430cabdff1aSopenharmony_civoid avio_wb64(AVIOContext *s, uint64_t val); 431cabdff1aSopenharmony_civoid avio_wl32(AVIOContext *s, unsigned int val); 432cabdff1aSopenharmony_civoid avio_wb32(AVIOContext *s, unsigned int val); 433cabdff1aSopenharmony_civoid avio_wl24(AVIOContext *s, unsigned int val); 434cabdff1aSopenharmony_civoid avio_wb24(AVIOContext *s, unsigned int val); 435cabdff1aSopenharmony_civoid avio_wl16(AVIOContext *s, unsigned int val); 436cabdff1aSopenharmony_civoid avio_wb16(AVIOContext *s, unsigned int val); 437cabdff1aSopenharmony_ci 438cabdff1aSopenharmony_ci/** 439cabdff1aSopenharmony_ci * Write a NULL-terminated string. 440cabdff1aSopenharmony_ci * @return number of bytes written. 441cabdff1aSopenharmony_ci */ 442cabdff1aSopenharmony_ciint avio_put_str(AVIOContext *s, const char *str); 443cabdff1aSopenharmony_ci 444cabdff1aSopenharmony_ci/** 445cabdff1aSopenharmony_ci * Convert an UTF-8 string to UTF-16LE and write it. 446cabdff1aSopenharmony_ci * @param s the AVIOContext 447cabdff1aSopenharmony_ci * @param str NULL-terminated UTF-8 string 448cabdff1aSopenharmony_ci * 449cabdff1aSopenharmony_ci * @return number of bytes written. 450cabdff1aSopenharmony_ci */ 451cabdff1aSopenharmony_ciint avio_put_str16le(AVIOContext *s, const char *str); 452cabdff1aSopenharmony_ci 453cabdff1aSopenharmony_ci/** 454cabdff1aSopenharmony_ci * Convert an UTF-8 string to UTF-16BE and write it. 455cabdff1aSopenharmony_ci * @param s the AVIOContext 456cabdff1aSopenharmony_ci * @param str NULL-terminated UTF-8 string 457cabdff1aSopenharmony_ci * 458cabdff1aSopenharmony_ci * @return number of bytes written. 459cabdff1aSopenharmony_ci */ 460cabdff1aSopenharmony_ciint avio_put_str16be(AVIOContext *s, const char *str); 461cabdff1aSopenharmony_ci 462cabdff1aSopenharmony_ci/** 463cabdff1aSopenharmony_ci * Mark the written bytestream as a specific type. 464cabdff1aSopenharmony_ci * 465cabdff1aSopenharmony_ci * Zero-length ranges are omitted from the output. 466cabdff1aSopenharmony_ci * 467cabdff1aSopenharmony_ci * @param time the stream time the current bytestream pos corresponds to 468cabdff1aSopenharmony_ci * (in AV_TIME_BASE units), or AV_NOPTS_VALUE if unknown or not 469cabdff1aSopenharmony_ci * applicable 470cabdff1aSopenharmony_ci * @param type the kind of data written starting at the current pos 471cabdff1aSopenharmony_ci */ 472cabdff1aSopenharmony_civoid avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type); 473cabdff1aSopenharmony_ci 474cabdff1aSopenharmony_ci/** 475cabdff1aSopenharmony_ci * ORing this as the "whence" parameter to a seek function causes it to 476cabdff1aSopenharmony_ci * return the filesize without seeking anywhere. Supporting this is optional. 477cabdff1aSopenharmony_ci * If it is not supported then the seek function will return <0. 478cabdff1aSopenharmony_ci */ 479cabdff1aSopenharmony_ci#define AVSEEK_SIZE 0x10000 480cabdff1aSopenharmony_ci 481cabdff1aSopenharmony_ci/** 482cabdff1aSopenharmony_ci * Passing this flag as the "whence" parameter to a seek function causes it to 483cabdff1aSopenharmony_ci * seek by any means (like reopening and linear reading) or other normally unreasonable 484cabdff1aSopenharmony_ci * means that can be extremely slow. 485cabdff1aSopenharmony_ci * This may be ignored by the seek code. 486cabdff1aSopenharmony_ci */ 487cabdff1aSopenharmony_ci#define AVSEEK_FORCE 0x20000 488cabdff1aSopenharmony_ci 489cabdff1aSopenharmony_ci/** 490cabdff1aSopenharmony_ci * fseek() equivalent for AVIOContext. 491cabdff1aSopenharmony_ci * @return new position or AVERROR. 492cabdff1aSopenharmony_ci */ 493cabdff1aSopenharmony_ciint64_t avio_seek(AVIOContext *s, int64_t offset, int whence); 494cabdff1aSopenharmony_ci 495cabdff1aSopenharmony_ci/** 496cabdff1aSopenharmony_ci * Skip given number of bytes forward 497cabdff1aSopenharmony_ci * @return new position or AVERROR. 498cabdff1aSopenharmony_ci */ 499cabdff1aSopenharmony_ciint64_t avio_skip(AVIOContext *s, int64_t offset); 500cabdff1aSopenharmony_ci 501cabdff1aSopenharmony_ci/** 502cabdff1aSopenharmony_ci * ftell() equivalent for AVIOContext. 503cabdff1aSopenharmony_ci * @return position or AVERROR. 504cabdff1aSopenharmony_ci */ 505cabdff1aSopenharmony_cistatic av_always_inline int64_t avio_tell(AVIOContext *s) 506cabdff1aSopenharmony_ci{ 507cabdff1aSopenharmony_ci return avio_seek(s, 0, SEEK_CUR); 508cabdff1aSopenharmony_ci} 509cabdff1aSopenharmony_ci 510cabdff1aSopenharmony_ci/** 511cabdff1aSopenharmony_ci * Get the filesize. 512cabdff1aSopenharmony_ci * @return filesize or AVERROR 513cabdff1aSopenharmony_ci */ 514cabdff1aSopenharmony_ciint64_t avio_size(AVIOContext *s); 515cabdff1aSopenharmony_ci 516cabdff1aSopenharmony_ci/** 517cabdff1aSopenharmony_ci * Similar to feof() but also returns nonzero on read errors. 518cabdff1aSopenharmony_ci * @return non zero if and only if at end of file or a read error happened when reading. 519cabdff1aSopenharmony_ci */ 520cabdff1aSopenharmony_ciint avio_feof(AVIOContext *s); 521cabdff1aSopenharmony_ci 522cabdff1aSopenharmony_ci/** 523cabdff1aSopenharmony_ci * Writes a formatted string to the context taking a va_list. 524cabdff1aSopenharmony_ci * @return number of bytes written, < 0 on error. 525cabdff1aSopenharmony_ci */ 526cabdff1aSopenharmony_ciint avio_vprintf(AVIOContext *s, const char *fmt, va_list ap); 527cabdff1aSopenharmony_ci 528cabdff1aSopenharmony_ci/** 529cabdff1aSopenharmony_ci * Writes a formatted string to the context. 530cabdff1aSopenharmony_ci * @return number of bytes written, < 0 on error. 531cabdff1aSopenharmony_ci */ 532cabdff1aSopenharmony_ciint avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3); 533cabdff1aSopenharmony_ci 534cabdff1aSopenharmony_ci/** 535cabdff1aSopenharmony_ci * Write a NULL terminated array of strings to the context. 536cabdff1aSopenharmony_ci * Usually you don't need to use this function directly but its macro wrapper, 537cabdff1aSopenharmony_ci * avio_print. 538cabdff1aSopenharmony_ci */ 539cabdff1aSopenharmony_civoid avio_print_string_array(AVIOContext *s, const char *strings[]); 540cabdff1aSopenharmony_ci 541cabdff1aSopenharmony_ci/** 542cabdff1aSopenharmony_ci * Write strings (const char *) to the context. 543cabdff1aSopenharmony_ci * This is a convenience macro around avio_print_string_array and it 544cabdff1aSopenharmony_ci * automatically creates the string array from the variable argument list. 545cabdff1aSopenharmony_ci * For simple string concatenations this function is more performant than using 546cabdff1aSopenharmony_ci * avio_printf since it does not need a temporary buffer. 547cabdff1aSopenharmony_ci */ 548cabdff1aSopenharmony_ci#define avio_print(s, ...) \ 549cabdff1aSopenharmony_ci avio_print_string_array(s, (const char*[]){__VA_ARGS__, NULL}) 550cabdff1aSopenharmony_ci 551cabdff1aSopenharmony_ci/** 552cabdff1aSopenharmony_ci * Force flushing of buffered data. 553cabdff1aSopenharmony_ci * 554cabdff1aSopenharmony_ci * For write streams, force the buffered data to be immediately written to the output, 555cabdff1aSopenharmony_ci * without to wait to fill the internal buffer. 556cabdff1aSopenharmony_ci * 557cabdff1aSopenharmony_ci * For read streams, discard all currently buffered data, and advance the 558cabdff1aSopenharmony_ci * reported file position to that of the underlying stream. This does not 559cabdff1aSopenharmony_ci * read new data, and does not perform any seeks. 560cabdff1aSopenharmony_ci */ 561cabdff1aSopenharmony_civoid avio_flush(AVIOContext *s); 562cabdff1aSopenharmony_ci 563cabdff1aSopenharmony_ci/** 564cabdff1aSopenharmony_ci * Read size bytes from AVIOContext into buf. 565cabdff1aSopenharmony_ci * @return number of bytes read or AVERROR 566cabdff1aSopenharmony_ci */ 567cabdff1aSopenharmony_ciint avio_read(AVIOContext *s, unsigned char *buf, int size); 568cabdff1aSopenharmony_ci 569cabdff1aSopenharmony_ci/** 570cabdff1aSopenharmony_ci * Read size bytes from AVIOContext into buf. Unlike avio_read(), this is allowed 571cabdff1aSopenharmony_ci * to read fewer bytes than requested. The missing bytes can be read in the next 572cabdff1aSopenharmony_ci * call. This always tries to read at least 1 byte. 573cabdff1aSopenharmony_ci * Useful to reduce latency in certain cases. 574cabdff1aSopenharmony_ci * @return number of bytes read or AVERROR 575cabdff1aSopenharmony_ci */ 576cabdff1aSopenharmony_ciint avio_read_partial(AVIOContext *s, unsigned char *buf, int size); 577cabdff1aSopenharmony_ci 578cabdff1aSopenharmony_ci/** 579cabdff1aSopenharmony_ci * @name Functions for reading from AVIOContext 580cabdff1aSopenharmony_ci * @{ 581cabdff1aSopenharmony_ci * 582cabdff1aSopenharmony_ci * @note return 0 if EOF, so you cannot use it if EOF handling is 583cabdff1aSopenharmony_ci * necessary 584cabdff1aSopenharmony_ci */ 585cabdff1aSopenharmony_ciint avio_r8 (AVIOContext *s); 586cabdff1aSopenharmony_ciunsigned int avio_rl16(AVIOContext *s); 587cabdff1aSopenharmony_ciunsigned int avio_rl24(AVIOContext *s); 588cabdff1aSopenharmony_ciunsigned int avio_rl32(AVIOContext *s); 589cabdff1aSopenharmony_ciuint64_t avio_rl64(AVIOContext *s); 590cabdff1aSopenharmony_ciunsigned int avio_rb16(AVIOContext *s); 591cabdff1aSopenharmony_ciunsigned int avio_rb24(AVIOContext *s); 592cabdff1aSopenharmony_ciunsigned int avio_rb32(AVIOContext *s); 593cabdff1aSopenharmony_ciuint64_t avio_rb64(AVIOContext *s); 594cabdff1aSopenharmony_ci/** 595cabdff1aSopenharmony_ci * @} 596cabdff1aSopenharmony_ci */ 597cabdff1aSopenharmony_ci 598cabdff1aSopenharmony_ci/** 599cabdff1aSopenharmony_ci * Read a string from pb into buf. The reading will terminate when either 600cabdff1aSopenharmony_ci * a NULL character was encountered, maxlen bytes have been read, or nothing 601cabdff1aSopenharmony_ci * more can be read from pb. The result is guaranteed to be NULL-terminated, it 602cabdff1aSopenharmony_ci * will be truncated if buf is too small. 603cabdff1aSopenharmony_ci * Note that the string is not interpreted or validated in any way, it 604cabdff1aSopenharmony_ci * might get truncated in the middle of a sequence for multi-byte encodings. 605cabdff1aSopenharmony_ci * 606cabdff1aSopenharmony_ci * @return number of bytes read (is always <= maxlen). 607cabdff1aSopenharmony_ci * If reading ends on EOF or error, the return value will be one more than 608cabdff1aSopenharmony_ci * bytes actually read. 609cabdff1aSopenharmony_ci */ 610cabdff1aSopenharmony_ciint avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen); 611cabdff1aSopenharmony_ci 612cabdff1aSopenharmony_ci/** 613cabdff1aSopenharmony_ci * Read a UTF-16 string from pb and convert it to UTF-8. 614cabdff1aSopenharmony_ci * The reading will terminate when either a null or invalid character was 615cabdff1aSopenharmony_ci * encountered or maxlen bytes have been read. 616cabdff1aSopenharmony_ci * @return number of bytes read (is always <= maxlen) 617cabdff1aSopenharmony_ci */ 618cabdff1aSopenharmony_ciint avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen); 619cabdff1aSopenharmony_ciint avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen); 620cabdff1aSopenharmony_ci 621cabdff1aSopenharmony_ci 622cabdff1aSopenharmony_ci/** 623cabdff1aSopenharmony_ci * @name URL open modes 624cabdff1aSopenharmony_ci * The flags argument to avio_open must be one of the following 625cabdff1aSopenharmony_ci * constants, optionally ORed with other flags. 626cabdff1aSopenharmony_ci * @{ 627cabdff1aSopenharmony_ci */ 628cabdff1aSopenharmony_ci#define AVIO_FLAG_READ 1 /**< read-only */ 629cabdff1aSopenharmony_ci#define AVIO_FLAG_WRITE 2 /**< write-only */ 630cabdff1aSopenharmony_ci#define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE) /**< read-write pseudo flag */ 631cabdff1aSopenharmony_ci/** 632cabdff1aSopenharmony_ci * @} 633cabdff1aSopenharmony_ci */ 634cabdff1aSopenharmony_ci 635cabdff1aSopenharmony_ci/** 636cabdff1aSopenharmony_ci * Use non-blocking mode. 637cabdff1aSopenharmony_ci * If this flag is set, operations on the context will return 638cabdff1aSopenharmony_ci * AVERROR(EAGAIN) if they can not be performed immediately. 639cabdff1aSopenharmony_ci * If this flag is not set, operations on the context will never return 640cabdff1aSopenharmony_ci * AVERROR(EAGAIN). 641cabdff1aSopenharmony_ci * Note that this flag does not affect the opening/connecting of the 642cabdff1aSopenharmony_ci * context. Connecting a protocol will always block if necessary (e.g. on 643cabdff1aSopenharmony_ci * network protocols) but never hang (e.g. on busy devices). 644cabdff1aSopenharmony_ci * Warning: non-blocking protocols is work-in-progress; this flag may be 645cabdff1aSopenharmony_ci * silently ignored. 646cabdff1aSopenharmony_ci */ 647cabdff1aSopenharmony_ci#define AVIO_FLAG_NONBLOCK 8 648cabdff1aSopenharmony_ci 649cabdff1aSopenharmony_ci/** 650cabdff1aSopenharmony_ci * Use direct mode. 651cabdff1aSopenharmony_ci * avio_read and avio_write should if possible be satisfied directly 652cabdff1aSopenharmony_ci * instead of going through a buffer, and avio_seek will always 653cabdff1aSopenharmony_ci * call the underlying seek function directly. 654cabdff1aSopenharmony_ci */ 655cabdff1aSopenharmony_ci#define AVIO_FLAG_DIRECT 0x8000 656cabdff1aSopenharmony_ci 657cabdff1aSopenharmony_ci/** 658cabdff1aSopenharmony_ci * Create and initialize a AVIOContext for accessing the 659cabdff1aSopenharmony_ci * resource indicated by url. 660cabdff1aSopenharmony_ci * @note When the resource indicated by url has been opened in 661cabdff1aSopenharmony_ci * read+write mode, the AVIOContext can be used only for writing. 662cabdff1aSopenharmony_ci * 663cabdff1aSopenharmony_ci * @param s Used to return the pointer to the created AVIOContext. 664cabdff1aSopenharmony_ci * In case of failure the pointed to value is set to NULL. 665cabdff1aSopenharmony_ci * @param url resource to access 666cabdff1aSopenharmony_ci * @param flags flags which control how the resource indicated by url 667cabdff1aSopenharmony_ci * is to be opened 668cabdff1aSopenharmony_ci * @return >= 0 in case of success, a negative value corresponding to an 669cabdff1aSopenharmony_ci * AVERROR code in case of failure 670cabdff1aSopenharmony_ci */ 671cabdff1aSopenharmony_ciint avio_open(AVIOContext **s, const char *url, int flags); 672cabdff1aSopenharmony_ci 673cabdff1aSopenharmony_ci/** 674cabdff1aSopenharmony_ci * Create and initialize a AVIOContext for accessing the 675cabdff1aSopenharmony_ci * resource indicated by url. 676cabdff1aSopenharmony_ci * @note When the resource indicated by url has been opened in 677cabdff1aSopenharmony_ci * read+write mode, the AVIOContext can be used only for writing. 678cabdff1aSopenharmony_ci * 679cabdff1aSopenharmony_ci * @param s Used to return the pointer to the created AVIOContext. 680cabdff1aSopenharmony_ci * In case of failure the pointed to value is set to NULL. 681cabdff1aSopenharmony_ci * @param url resource to access 682cabdff1aSopenharmony_ci * @param flags flags which control how the resource indicated by url 683cabdff1aSopenharmony_ci * is to be opened 684cabdff1aSopenharmony_ci * @param int_cb an interrupt callback to be used at the protocols level 685cabdff1aSopenharmony_ci * @param options A dictionary filled with protocol-private options. On return 686cabdff1aSopenharmony_ci * this parameter will be destroyed and replaced with a dict containing options 687cabdff1aSopenharmony_ci * that were not found. May be NULL. 688cabdff1aSopenharmony_ci * @return >= 0 in case of success, a negative value corresponding to an 689cabdff1aSopenharmony_ci * AVERROR code in case of failure 690cabdff1aSopenharmony_ci */ 691cabdff1aSopenharmony_ciint avio_open2(AVIOContext **s, const char *url, int flags, 692cabdff1aSopenharmony_ci const AVIOInterruptCB *int_cb, AVDictionary **options); 693cabdff1aSopenharmony_ci 694cabdff1aSopenharmony_ci/** 695cabdff1aSopenharmony_ci * Close the resource accessed by the AVIOContext s and free it. 696cabdff1aSopenharmony_ci * This function can only be used if s was opened by avio_open(). 697cabdff1aSopenharmony_ci * 698cabdff1aSopenharmony_ci * The internal buffer is automatically flushed before closing the 699cabdff1aSopenharmony_ci * resource. 700cabdff1aSopenharmony_ci * 701cabdff1aSopenharmony_ci * @return 0 on success, an AVERROR < 0 on error. 702cabdff1aSopenharmony_ci * @see avio_closep 703cabdff1aSopenharmony_ci */ 704cabdff1aSopenharmony_ciint avio_close(AVIOContext *s); 705cabdff1aSopenharmony_ci 706cabdff1aSopenharmony_ci/** 707cabdff1aSopenharmony_ci * Close the resource accessed by the AVIOContext *s, free it 708cabdff1aSopenharmony_ci * and set the pointer pointing to it to NULL. 709cabdff1aSopenharmony_ci * This function can only be used if s was opened by avio_open(). 710cabdff1aSopenharmony_ci * 711cabdff1aSopenharmony_ci * The internal buffer is automatically flushed before closing the 712cabdff1aSopenharmony_ci * resource. 713cabdff1aSopenharmony_ci * 714cabdff1aSopenharmony_ci * @return 0 on success, an AVERROR < 0 on error. 715cabdff1aSopenharmony_ci * @see avio_close 716cabdff1aSopenharmony_ci */ 717cabdff1aSopenharmony_ciint avio_closep(AVIOContext **s); 718cabdff1aSopenharmony_ci 719cabdff1aSopenharmony_ci 720cabdff1aSopenharmony_ci/** 721cabdff1aSopenharmony_ci * Open a write only memory stream. 722cabdff1aSopenharmony_ci * 723cabdff1aSopenharmony_ci * @param s new IO context 724cabdff1aSopenharmony_ci * @return zero if no error. 725cabdff1aSopenharmony_ci */ 726cabdff1aSopenharmony_ciint avio_open_dyn_buf(AVIOContext **s); 727cabdff1aSopenharmony_ci 728cabdff1aSopenharmony_ci/** 729cabdff1aSopenharmony_ci * Return the written size and a pointer to the buffer. 730cabdff1aSopenharmony_ci * The AVIOContext stream is left intact. 731cabdff1aSopenharmony_ci * The buffer must NOT be freed. 732cabdff1aSopenharmony_ci * No padding is added to the buffer. 733cabdff1aSopenharmony_ci * 734cabdff1aSopenharmony_ci * @param s IO context 735cabdff1aSopenharmony_ci * @param pbuffer pointer to a byte buffer 736cabdff1aSopenharmony_ci * @return the length of the byte buffer 737cabdff1aSopenharmony_ci */ 738cabdff1aSopenharmony_ciint avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer); 739cabdff1aSopenharmony_ci 740cabdff1aSopenharmony_ci/** 741cabdff1aSopenharmony_ci * Return the written size and a pointer to the buffer. The buffer 742cabdff1aSopenharmony_ci * must be freed with av_free(). 743cabdff1aSopenharmony_ci * Padding of AV_INPUT_BUFFER_PADDING_SIZE is added to the buffer. 744cabdff1aSopenharmony_ci * 745cabdff1aSopenharmony_ci * @param s IO context 746cabdff1aSopenharmony_ci * @param pbuffer pointer to a byte buffer 747cabdff1aSopenharmony_ci * @return the length of the byte buffer 748cabdff1aSopenharmony_ci */ 749cabdff1aSopenharmony_ciint avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer); 750cabdff1aSopenharmony_ci 751cabdff1aSopenharmony_ci/** 752cabdff1aSopenharmony_ci * Iterate through names of available protocols. 753cabdff1aSopenharmony_ci * 754cabdff1aSopenharmony_ci * @param opaque A private pointer representing current protocol. 755cabdff1aSopenharmony_ci * It must be a pointer to NULL on first iteration and will 756cabdff1aSopenharmony_ci * be updated by successive calls to avio_enum_protocols. 757cabdff1aSopenharmony_ci * @param output If set to 1, iterate over output protocols, 758cabdff1aSopenharmony_ci * otherwise over input protocols. 759cabdff1aSopenharmony_ci * 760cabdff1aSopenharmony_ci * @return A static string containing the name of current protocol or NULL 761cabdff1aSopenharmony_ci */ 762cabdff1aSopenharmony_ciconst char *avio_enum_protocols(void **opaque, int output); 763cabdff1aSopenharmony_ci 764cabdff1aSopenharmony_ci/** 765cabdff1aSopenharmony_ci * Get AVClass by names of available protocols. 766cabdff1aSopenharmony_ci * 767cabdff1aSopenharmony_ci * @return A AVClass of input protocol name or NULL 768cabdff1aSopenharmony_ci */ 769cabdff1aSopenharmony_ciconst AVClass *avio_protocol_get_class(const char *name); 770cabdff1aSopenharmony_ci 771cabdff1aSopenharmony_ci/** 772cabdff1aSopenharmony_ci * Pause and resume playing - only meaningful if using a network streaming 773cabdff1aSopenharmony_ci * protocol (e.g. MMS). 774cabdff1aSopenharmony_ci * 775cabdff1aSopenharmony_ci * @param h IO context from which to call the read_pause function pointer 776cabdff1aSopenharmony_ci * @param pause 1 for pause, 0 for resume 777cabdff1aSopenharmony_ci */ 778cabdff1aSopenharmony_ciint avio_pause(AVIOContext *h, int pause); 779cabdff1aSopenharmony_ci 780cabdff1aSopenharmony_ci/** 781cabdff1aSopenharmony_ci * Seek to a given timestamp relative to some component stream. 782cabdff1aSopenharmony_ci * Only meaningful if using a network streaming protocol (e.g. MMS.). 783cabdff1aSopenharmony_ci * 784cabdff1aSopenharmony_ci * @param h IO context from which to call the seek function pointers 785cabdff1aSopenharmony_ci * @param stream_index The stream index that the timestamp is relative to. 786cabdff1aSopenharmony_ci * If stream_index is (-1) the timestamp should be in AV_TIME_BASE 787cabdff1aSopenharmony_ci * units from the beginning of the presentation. 788cabdff1aSopenharmony_ci * If a stream_index >= 0 is used and the protocol does not support 789cabdff1aSopenharmony_ci * seeking based on component streams, the call will fail. 790cabdff1aSopenharmony_ci * @param timestamp timestamp in AVStream.time_base units 791cabdff1aSopenharmony_ci * or if there is no stream specified then in AV_TIME_BASE units. 792cabdff1aSopenharmony_ci * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE 793cabdff1aSopenharmony_ci * and AVSEEK_FLAG_ANY. The protocol may silently ignore 794cabdff1aSopenharmony_ci * AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will 795cabdff1aSopenharmony_ci * fail if used and not supported. 796cabdff1aSopenharmony_ci * @return >= 0 on success 797cabdff1aSopenharmony_ci * @see AVInputFormat::read_seek 798cabdff1aSopenharmony_ci */ 799cabdff1aSopenharmony_ciint64_t avio_seek_time(AVIOContext *h, int stream_index, 800cabdff1aSopenharmony_ci int64_t timestamp, int flags); 801cabdff1aSopenharmony_ci 802cabdff1aSopenharmony_ci/* Avoid a warning. The header can not be included because it breaks c++. */ 803cabdff1aSopenharmony_cistruct AVBPrint; 804cabdff1aSopenharmony_ci 805cabdff1aSopenharmony_ci/** 806cabdff1aSopenharmony_ci * Read contents of h into print buffer, up to max_size bytes, or up to EOF. 807cabdff1aSopenharmony_ci * 808cabdff1aSopenharmony_ci * @return 0 for success (max_size bytes read or EOF reached), negative error 809cabdff1aSopenharmony_ci * code otherwise 810cabdff1aSopenharmony_ci */ 811cabdff1aSopenharmony_ciint avio_read_to_bprint(AVIOContext *h, struct AVBPrint *pb, size_t max_size); 812cabdff1aSopenharmony_ci 813cabdff1aSopenharmony_ci/** 814cabdff1aSopenharmony_ci * Accept and allocate a client context on a server context. 815cabdff1aSopenharmony_ci * @param s the server context 816cabdff1aSopenharmony_ci * @param c the client context, must be unallocated 817cabdff1aSopenharmony_ci * @return >= 0 on success or a negative value corresponding 818cabdff1aSopenharmony_ci * to an AVERROR on failure 819cabdff1aSopenharmony_ci */ 820cabdff1aSopenharmony_ciint avio_accept(AVIOContext *s, AVIOContext **c); 821cabdff1aSopenharmony_ci 822cabdff1aSopenharmony_ci/** 823cabdff1aSopenharmony_ci * Perform one step of the protocol handshake to accept a new client. 824cabdff1aSopenharmony_ci * This function must be called on a client returned by avio_accept() before 825cabdff1aSopenharmony_ci * using it as a read/write context. 826cabdff1aSopenharmony_ci * It is separate from avio_accept() because it may block. 827cabdff1aSopenharmony_ci * A step of the handshake is defined by places where the application may 828cabdff1aSopenharmony_ci * decide to change the proceedings. 829cabdff1aSopenharmony_ci * For example, on a protocol with a request header and a reply header, each 830cabdff1aSopenharmony_ci * one can constitute a step because the application may use the parameters 831cabdff1aSopenharmony_ci * from the request to change parameters in the reply; or each individual 832cabdff1aSopenharmony_ci * chunk of the request can constitute a step. 833cabdff1aSopenharmony_ci * If the handshake is already finished, avio_handshake() does nothing and 834cabdff1aSopenharmony_ci * returns 0 immediately. 835cabdff1aSopenharmony_ci * 836cabdff1aSopenharmony_ci * @param c the client context to perform the handshake on 837cabdff1aSopenharmony_ci * @return 0 on a complete and successful handshake 838cabdff1aSopenharmony_ci * > 0 if the handshake progressed, but is not complete 839cabdff1aSopenharmony_ci * < 0 for an AVERROR code 840cabdff1aSopenharmony_ci */ 841cabdff1aSopenharmony_ciint avio_handshake(AVIOContext *c); 842cabdff1aSopenharmony_ci#endif /* AVFORMAT_AVIO_H */ 843