AVIOContext
public final class AVIOContext
Bytestream IO Context.
-
Allocate and initialize an
AVIOContextfor buffered I/O.Declaration
Swift
public convenience init( buffer: UnsafeMutablePointer<UInt8>, size: Int, writable: Bool, opaque: UnsafeMutableRawPointer, readHandler: AVIOReadHandler?, writeHandler: AVIOWriteHandler?, seekHandler: AVIOSeekHandler? )Parameters
bufferMemory block for input/output operations via
AVIOContext.sizeThe buffer size is very important for performance. For protocols with fixed blocksize it should be set to this blocksize. For others a typical size is a cache page, e.g. 4kb.
writableSet to
trueif the buffer should be writable,falseotherwise.opaqueAn opaque pointer to user-specific data.
readHandlerA handler for refilling the buffer, may be
nil. For stream protocols, must never return 0 but rather a proper AVERROR code.writeHandlerA handler for writing the buffer contents, may be
nil. The function may not change the input buffers content.seekHandlerA handler for seeking to specified byte position, may be
nil. -
Create and initialize a
AVIOContextfor accessing the resource indicated by url.Note
When the resource indicated by url has been opened in read+write mode, the
AVIOContextcan be used only for writing.Throws
AVError
Declaration
Swift
public convenience init( url: String, flags: Flag, interruptCallback: AVIOInterruptCallback? = nil, options: [String: String]? = nil ) throwsParameters
urlresource to access
flagsflags which control how the resource indicated by url is to be opened
interruptCallbackan interrupt callback to be used at the protocols level
optionsA dictionary filled with protocol-private options.
-
Writes the contents of a provided data buffer to the receiver.
Declaration
Swift
public func write(_ buffer: UnsafePointer<UInt8>, size: Int) -
Sets the file position indicator for the file stream to the value pointed to by offset.
Throws
AVErrorDeclaration
Swift
public func seek(to offset: Int64, whence: SeekWhence) throws -> Int -
Skip given number of bytes forward.
Throws
AVErrorDeclaration
Swift
public func skip(to offset: Int64) throws -> Int -
Returns the file position indicator for the file stream.
Throws
AVErrorDeclaration
Swift
public func tell() throws -> Int -
Get the filesize.
Throws
AVErrorDeclaration
Swift
public func size() throws -> Int64 -
Checks if the end of the given file stream has been reached.
Declaration
Swift
public func feof() -> Bool -
Force flushing of buffered data.
For write streams, force the buffered data to be immediately written to the output, without to wait to fill the internal buffer.
For read streams, discard all currently buffered data, and advance the reported file position to that of the underlying stream. This does not read new data, and does not perform any seeks.
Declaration
Swift
public func flush() -
Read size bytes from
AVIOContextinto buffer.Throws
AVErrorDeclaration
Swift
public func read(_ buffer: UnsafeMutablePointer<UInt8>, size: Int) throws -> IntParameters
bufferThe buffer into which the data is read.
sizeThe maximum number of bytes read.
Return Value
The total number of bytes read into the buffer.
-
Read size bytes from
AVIOContextinto buffer. Unlikeread(_:size:), this is allowed to read fewer bytes than requested. The missing bytes can be read in the next call. This always tries to read at least 1 byte. Useful to reduce latency in certain cases.Throws
AVErrorDeclaration
Swift
public func partialRead(_ buffer: UnsafeMutablePointer<UInt8>, size: Int) throws -> IntParameters
bufferThe buffer into which the data is read.
sizeThe maximum number of bytes read.
Return Value
number of bytes read
-
Pause playing.
Note
Only meaningful if using a network streaming protocol (e.g. MMS).
Throws
AVError
Declaration
Swift
public func pause() throws -
Resume playing.
Note
Only meaningful if using a network streaming protocol (e.g. MMS).
Throws
AVError
Declaration
Swift
public func resume() throws -
Seek to a given timestamp relative to some component stream.
Note
Only meaningful if using a network streaming protocol (e.g. MMS.).
Throws
AVError
Declaration
Swift
public func seek(to timestamp: Int64, streamIndex: Int64, flags: AVFormatContext.SeekFlag) throws -> IntParameters
timestamptimestamp in
AVStream.timebaseunits or if there is no stream specified then inAVTimestamp.timebaseunits.streamIndexThe stream index that the timestamp is relative to. If
streamIndexis -1 the timestamp should be inAVTimestamp.timebaseunits from the beginning of the presentation. If astreamIndex>= 0 is used and the protocol does not support seeking based on component streams, the call will fail.flagsOptional combination of
SeekFlag.backward,SeekFlag.byteandSeekFlag.any. The protocol may silently ignoreSeekFlag.backwardandSeekFlag.any, butSeekFlag.bytewill fail if used and not supported. -
Accept and allocate a client context on a server context.
Throws
AVErrorDeclaration
Swift
public func accept() throws -> AVIOContext -
Perform one step of the protocol handshake to accept a new client.
This function must be called on a client returned by
accept()before using it as a read/write context. It is separate fromaccept()because it may block. A step of the handshake is defined by places where the application may decide to change the proceedings. For example, on a protocol with a request header and a reply header, each one can constitute a step because the application may use the parameters from the request to change parameters in the reply; or each individual chunk of the request can constitute a step. If the handshake is already finished,handshake()does nothing and returns 0 immediately.Throws
AVErrorDeclaration
Swift
public func handshake() throws -> BoolReturn Value
trueon a complete and successful handshake,falseif the handshake progressed, but is not complete. -
Close the resource accessed by the
AVIOContext.The internal buffer is automatically flushed before closing the resource.
Declaration
Swift
public func close() -
Return the name of the protocol that will handle the passed url.
Declaration
Swift
public static func protocolName(for url: String) -> String?Return Value
The name of the protocol or nil.
-
Returns an array of the input protocols supported by the
AVIOContext.Declaration
Swift
public static var supportedInputProtocols: [String] { get } -
Returns an array of the output protocols supported by the
AVIOContext.Declaration
Swift
public static var supportedOutputProtocols: [String] { get }
-
Undocumented
Declaration
Swift
public func withUnsafeObjectPointer<T>(_ body: (UnsafeMutableRawPointer) throws -> T) rethrows -> T
-
URL open modes
The flags argument to avio_open must be one of the following constants, optionally ORed with other flags.
See moreDeclaration
Swift
public struct Flag : OptionSet
-
Undocumented
See moreDeclaration
Swift
public struct SeekWhence
View on GitHub
Install in Dash
AVIOContext Class Reference