SwrContext
public final class SwrContext
Undocumented
-
Create
SwrContext
.If you use this function you will need to set the parameters before calling
initialize()
.Declaration
Swift
public init()
-
init(dstChannelLayout:dstSampleFormat:dstSampleRate:srcChannelLayout:srcSampleFormat:srcSampleRate:)
Create
SwrContext
if needed and set/reset common parameters.Declaration
Swift
public init( dstChannelLayout: AVChannelLayout, dstSampleFormat: AVSampleFormat, dstSampleRate: Int, srcChannelLayout: AVChannelLayout, srcSampleFormat: AVSampleFormat, srcSampleRate: Int )
Parameters
dstChannelLayout
output channel layout
dstSampleFormat
output sample format
dstSampleRate
output sample rate (frequency in Hz)
srcChannelLayout
input channel layout
srcSampleFormat
input sample format
srcSampleRate
input sample rate (frequency in Hz)
-
A Boolean value indicating whether the context has been initialized or not.
Declaration
Swift
public var isInitialized: Bool { get }
-
setOptions(dstChannelLayout:dstSampleFormat:dstSampleRate:srcChannelLayout:srcSampleFormat:srcSampleRate:)
Set/reset common parameters.
Throws
AVError
Declaration
Swift
public func setOptions( dstChannelLayout: AVChannelLayout, dstSampleFormat: AVSampleFormat, dstSampleRate: Int, srcChannelLayout: AVChannelLayout, srcSampleFormat: AVSampleFormat, srcSampleRate: Int ) throws
Parameters
dstChannelLayout
output channel layout
dstSampleFormat
output sample format
dstSampleRate
output sample rate (frequency in Hz)
srcChannelLayout
input channel layout
srcSampleFormat
input sample format
srcSampleRate
input sample rate (frequency in Hz)
-
Initialize context after user parameters have been set.
Throws
AVErrorDeclaration
Swift
public func initialize() throws
-
Closes the context so that
isInitialized
returnsfalse
.The context can be brought back to life by running
initialize()
,initialize()
can also be used withoutclose()
. This function is mainly provided for simplifying the usecase where one tries to support libavresample and libswresample.Declaration
Swift
public func close()
-
Gets the delay the next input sample will experience relative to the next output sample.
Declaration
Swift
public func getDelay(_ timebase: Int64) -> Int
Parameters
timebase
timebase in which the returned delay will be
- if it’s set to 1 the returned delay is in seconds
- if it’s set to 1000 the returned delay is in milliseconds
- if it’s set to the input sample rate then the returned delay is in input samples
- if it’s set to the output sample rate then the returned delay is in output samples
- if it’s the least common multiple of
in_sample_rate
andout_sample_rate
then an exact rounding-free delay will be returned
Return Value
the delay in 1 / base units.
-
Find an upper bound on the number of samples that the next
convert(dst:dstCount:src:srcCount:)
call will output, if called withsampleCount
of input samples. This depends on the internal state, and anything changing the internal state (like furtherconvert(dst:dstCount:src:srcCount:)
calls) will may change the number of samplesgetOutSamples(_:)
returns for the same number of input samples.Note
any call to swr_inject_silence(), swr_convert(), swr_next_pts() or swr_set_compensation() invalidates this limit
Note
it is recommended to pass the correct available buffer size to all functions like
convert(dst:dstCount:src:srcCount:)
even ifgetOutSamples(_:)
indicates that less would be used.Throws
AVError
Declaration
Swift
public func getOutSamples(_ sampleCount: Int64) throws -> Int
Parameters
sampleCount
number of input samples
Return Value
an upper bound on the number of samples that the next
convert(dst:dstCount:src:srcCount:)
will output -
Convert audio.
dst
anddstCount
can be set to 0 to flush the last few samples out at the end.If more input is provided than output space, then the input will be buffered. You can avoid this buffering by using
getOutSamples(_:)
to retrieve an upper bound on the required number of output samples for the given number of input samples. Conversion will run directly without copying whenever possible.Throws
AVErrorDeclaration
Swift
@discardableResult public func convert( dst: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>, dstCount: Int, src: UnsafeMutablePointer<UnsafePointer<UInt8>?>, srcCount: Int ) throws -> Int
Parameters
dst
output buffers, only the first one need be set in case of packed audio
dstCount
amount of space available for output in samples per channel
src
input buffers, only the first one need to be set in case of packed audio
srcCount
number of input samples available in one channel
Return Value
number of samples output per channel
-
Undocumented
Declaration
Swift
public static let `class`: AVClass
-
Undocumented
Declaration
Swift
public func withUnsafeClassObjectPointer<T>(_ body: (UnsafeMutableRawPointer) throws -> T) rethrows -> T
-
Undocumented
Declaration
Swift
public func withUnsafeObjectPointer<T>(_ body: (UnsafeMutableRawPointer) throws -> T) rethrows -> T