AVIOContext

public final class AVIOContext

Bytestream IO Context.

  • Allocate and initialize an AVIOContext for buffered I/O.

    Declaration

    Swift

    public convenience init(
        buffer: UnsafeMutablePointer<UInt8>,
        size: Int,
        writable: Bool,
        opaque: UnsafeMutableRawPointer,
        readHandler: AVIOReadHandler?,
        writeHandler: AVIOWriteHandler?,
        seekHandler: AVIOSeekHandler?
    )

    Parameters

    buffer

    Memory block for input/output operations via AVIOContext.

    size

    The 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.

    writable

    Set to true if the buffer should be writable, false otherwise.

    opaque

    An opaque pointer to user-specific data.

    readHandler

    A handler for refilling the buffer, may be nil. For stream protocols, must never return 0 but rather a proper AVERROR code.

    writeHandler

    A handler for writing the buffer contents, may be nil. The function may not change the input buffers content.

    seekHandler

    A handler for seeking to specified byte position, may be nil.

  • Create and initialize a AVIOContext for accessing the resource indicated by url.

    Note

    When the resource indicated by url has been opened in read+write mode, the AVIOContext can be used only for writing.

    Throws

    AVError

    Declaration

    Swift

    public convenience init(
        url: String,
        flags: Flag,
        interruptCallback: AVIOInterruptCallback? = nil,
        options: [String: String]? = nil
    ) throws

    Parameters

    url

    resource to access

    flags

    flags which control how the resource indicated by url is to be opened

    interruptCallback

    an interrupt callback to be used at the protocols level

    options

    A 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

    AVError

    Declaration

    Swift

    public func seek(to offset: Int64, whence: SeekWhence) throws -> Int
  • Skip given number of bytes forward.

    Throws

    AVError

    Declaration

    Swift

    public func skip(to offset: Int64) throws -> Int
  • Returns the file position indicator for the file stream.

    Throws

    AVError

    Declaration

    Swift

    public func tell() throws -> Int
  • Get the filesize.

    Throws

    AVError

    Declaration

    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 AVIOContext into buffer.

    Throws

    AVError

    Declaration

    Swift

    public func read(_ buffer: UnsafeMutablePointer<UInt8>, size: Int) throws -> Int

    Parameters

    buffer

    The buffer into which the data is read.

    size

    The maximum number of bytes read.

    Return Value

    The total number of bytes read into the buffer.

  • Read size bytes from AVIOContext into buffer. Unlike read(_: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

    AVError

    Declaration

    Swift

    public func partialRead(_ buffer: UnsafeMutablePointer<UInt8>, size: Int) throws -> Int

    Parameters

    buffer

    The buffer into which the data is read.

    size

    The 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 -> Int

    Parameters

    timestamp

    timestamp in AVStream.timebase units or if there is no stream specified then in AVTimestamp.timebase units.

    streamIndex

    The stream index that the timestamp is relative to. If streamIndex is -1 the timestamp should be in AVTimestamp.timebase units from the beginning of the presentation. If a streamIndex >= 0 is used and the protocol does not support seeking based on component streams, the call will fail.

    flags

    Optional combination of SeekFlag.backward, SeekFlag.byte and SeekFlag.any. The protocol may silently ignore SeekFlag.backward and SeekFlag.any, but SeekFlag.byte will fail if used and not supported.

  • Accept and allocate a client context on a server context.

    Throws

    AVError

    Declaration

    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 from accept() 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

    AVError

    Declaration

    Swift

    public func handshake() throws -> Bool

    Return Value

    true on a complete and successful handshake, false if 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 more

    Declaration

    Swift

    public struct Flag : OptionSet