Documentation
¶
Overview ¶
Package audio contains bindings for the gstaudio C API.
Index ¶
- Constants
- Variables
- func AreValidChannelPositions(positions []ChannelPosition, forceOrder bool) bool
- func ChannelPositionsToMask(positions []ChannelPosition, forceOrder bool) (mask uint64, ok bool)
- func ChannelPositionsToString(positions []ChannelPosition) string
- func ChannelPositionsToValidOrder(positions []ChannelPosition) (ok bool)
- func ClipBuffer(buffer *gst.Buffer, segment *gst.Segment, rate, bytesPerFrame int) *gst.Buffer
- func DurationToFrames(dur time.Duration, rate int) int
- func FramesToDuration(frames, rate int) time.Duration
- func GetFallbackChannelMask(channels int) uint64
- func MakeRawCaps(formats []Format, layout Layout) *gst.Caps
- func ReorderChannels(buffer *gst.Buffer, format Format, from []ChannelPosition, ...) bool
- func TruncateBuffer(buffer *gst.Buffer, bytesPerFrame int, trim, samples int64) *gst.Buffer
- type Buffer
- type ChannelPosition
- type Flags
- type Format
- type FormatFlags
- type FormatInfo
- func (f *FormatInfo) Depth() int
- func (f *FormatInfo) Description() string
- func (f *FormatInfo) Endianness() int
- func (f *FormatInfo) Flags() FormatFlags
- func (f *FormatInfo) Format() Format
- func (f *FormatInfo) Name() string
- func (f *FormatInfo) Silence() []byte
- func (f *FormatInfo) UnpackFormat() Format
- func (f *FormatInfo) Width() int
- type Info
- func (i *Info) BPF() int
- func (i *Info) Channels() int
- func (i *Info) Convert(srcFmt gst.Format, srcVal int64, destFmt gst.Format) (int64, bool)
- func (i *Info) Copy() *Info
- func (i *Info) Flags() Flags
- func (i *Info) FormatInfo() *FormatInfo
- func (i *Info) Free()
- func (i *Info) Init()
- func (i *Info) IsEqual(info *Info) bool
- func (i *Info) Layout() Layout
- func (i *Info) Positions() []ChannelPosition
- func (i *Info) Rate() int
- func (i *Info) SetFormat(format Format, rate int, positions []ChannelPosition)
- func (i *Info) ToCaps() *gst.Caps
- type Layout
- type PackFlags
Constants ¶
const BigEndian int = C.G_BIG_ENDIAN
BigEndian represents big-endian format
const DefaultRate = 44100
DefaultRate is the default sampling rate used in consumer audio
const LittleEndian int = C.G_LITTLE_ENDIAN
LittleEndian represents little-endian format
Variables ¶
var TypeFormat = glib.Type(C.gst_audio_format_get_type())
TypeFormat is the GType for a GstAudioFormat.
Functions ¶
func AreValidChannelPositions ¶
func AreValidChannelPositions(positions []ChannelPosition, forceOrder bool) bool
AreValidChannelPositions checks if the positions are all valid. If forceOrder is true, it also checks if they are in the order required by GStreamer.
func ChannelPositionsToMask ¶
func ChannelPositionsToMask(positions []ChannelPosition, forceOrder bool) (mask uint64, ok bool)
ChannelPositionsToMask converts the given channel positions to a bitmask. If forceOrder is true it additionally checks the channels in the order required by GStreamer.
func ChannelPositionsToString ¶
func ChannelPositionsToString(positions []ChannelPosition) string
ChannelPositionsToString converts the given positions into a human-readable string.
func ChannelPositionsToValidOrder ¶
func ChannelPositionsToValidOrder(positions []ChannelPosition) (ok bool)
ChannelPositionsToValidOrder reorders the given positions from any order to the GStreamer order.
func ClipBuffer ¶
ClipBuffer will return a new buffer clipped to the given segment. The given buffer is no longer valid. The returned buffer may be nil if it is completely outside the configured segment.
func DurationToFrames ¶
DurationToFrames calculates the number of frames from the given duration and sample rate.
func FramesToDuration ¶
FramesToDuration calculates the Clocktime (which is usually referred to as a time.Duration in the bindings) from the given frames and rate.
func GetFallbackChannelMask ¶
GetFallbackChannelMask gets the fallback channel-mask for the given number of channels.
func MakeRawCaps ¶
MakeRawCaps returns a generic raw audio caps for the formats defined. If formats is nil, all supported formats are used.
func ReorderChannels ¶
func ReorderChannels(buffer *gst.Buffer, format Format, from []ChannelPosition, to []ChannelPosition) bool
ReorderChannels reorders the buffer against the given positions. The number of channels in each slice must be identical.
func TruncateBuffer ¶
TruncateBuffer truncates the buffer to finally have the given number of samples, removing the necessary amount of samples from the end and trim number of samples from the beginning. The original buffer is no longer valid. The returned buffer may be nil if the arguments were invalid.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a structure containing the result of a MapBuffer operation. For non-interleaved (planar) buffers, the beginning of each channel in the buffer has its own pointer in the planes array. For interleaved buffers, the Planes slice only contains one item, which is the pointer to the beginning of the buffer, and NumPlanes equals 1.
The different channels in planes are always in the GStreamer channel order.
func MapBuffer ¶
MapBuffer maps an audio gst.Buffer so that it can be read or written.
This is especially useful when the gstbuffer is in non-interleaved (planar) layout, in which case this function will use the information in the gstbuffer's attached GstAudioMeta in order to map each channel in a separate "plane" in GstAudioBuffer. If a GstAudioMeta is not attached on the gstbuffer, then it must be in interleaved layout.
If a GstAudioMeta is attached, then the GstAudioInfo on the meta is checked against info. Normally, they should be equal, but in case they are not, a g_critical will be printed and the GstAudioInfo from the meta will be used.
In non-interleaved buffers, it is possible to have each channel on a separate GstMemory. In this case, each memory will be mapped separately to avoid copying their contents in a larger memory area. Do note though that it is not supported to have a single channel spanning over two or more different GstMemory objects. Although the map operation will likely succeed in this case, it will be highly sub-optimal and it is recommended to merge all the memories in the buffer before calling this function.
func (*Buffer) NumSamples ¶
NumSamples returns the size of the buffer in samples.
func (*Buffer) Unmap ¶
func (b *Buffer) Unmap()
Unmap will unmap the mapped buffer. Use this after calling MapBuffer.
func (*Buffer) WritePlane ¶
WritePlane writes data to the plane at the given index.
type ChannelPosition ¶
type ChannelPosition int
ChannelPosition represents audio channel positions.
These are the channels defined in SMPTE 2036-2-2008 Table 1 for 22.2 audio systems with the Surround and Wide channels from DTS Coherent Acoustics (v.1.3.1) and 10.2 and 7.1 layouts. In the caps the actual channel layout is expressed with a channel count and a channel mask, which describes the existing channels. The positions in the bit mask correspond to the enum values. For negotiation it is allowed to have more bits set in the channel mask than the number of channels to specify the allowed channel positions but this is not allowed in negotiated caps. It is not allowed in any situation other than the one mentioned below to have less bits set in the channel mask than the number of channels.
ChannelPositionMono can only be used with a single mono channel that has no direction information and would be mixed into all directional channels. This is expressed in caps by having a single channel and no channel mask.
ChannelPositionNone can only be used if all channels have this position. This is expressed in caps by having a channel mask with no bits set.
As another special case it is allowed to have two channels without a channel mask. This implicitly means that this is a stereo stream with a front left and front right channel.
const ( ChannelPositionNone ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_NONE // (-3) – used for position-less channels, e.g. from a sound card that records 1024 channels; mutually exclusive with any other channel position ChannelPositionMono ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_MONO // (-2) – Mono without direction; can only be used with 1 channel ChannelPositionInvalid ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_INVALID // (-1) – invalid position ChannelPositionFrontLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT // (0) – Front left ChannelPositionFrontRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT // (1) – Front right ChannelPositionFrontCenter ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER // (2) – Front center ChannelPositionLFE1 ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_LFE1 // (3) – Low-frequency effects 1 (subwoofer) ChannelPositionRearLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_REAR_LEFT // (4) – Rear left ChannelPositionRearRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT // (5) – Rear right ChannelPositionFrontLeftOfCenter ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER // (6) – Front left of center ChannelPositionFrontRightOfCenter ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER // (7) – Front right of center ChannelPositionRearCenter ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_REAR_CENTER // (8) – Rear center ChannelPositionLFE2 ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_LFE2 // (9) – Low-frequency effects 2 (subwoofer) ChannelPositionSideLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT // (10) – Side left ChannelPositionSideRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT // (11) – Side right ChannelPositionTopFrontLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT // (12) – Top front left ChannelPositionTopFrontRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT // (13) – Top front right ChannelPositionTopFrontCenter ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER // (14) – Top front center ChannelPositionTopCenter ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_CENTER // (15) – Top center ChannelPositionTopRearLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT // (16) – Top rear left ChannelPositionTopRearRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT // (17) – Top rear right ChannelPositionTopSideLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_LEFT // (18) – Top side right ChannelPositionTopSideRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_RIGHT // (19) – Top rear right ChannelPositionTopRearCenter ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER // (20) – Top rear center ChannelPositionBottomFrontCenter ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_CENTER // (21) – Bottom front center ChannelPositionBottomFrontLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_LEFT // (22) – Bottom front left ChannelPositionBottomFrontRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_RIGHT // (23) – Bottom front right ChannelPositionWideLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_WIDE_LEFT // (24) – Wide left (between front left and side left) ChannelPositionWideRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_WIDE_RIGHT // (25) – Wide right (between front right and side right) ChannelPositionSurroundLeft ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_SURROUND_LEFT // (26) – Surround left (between rear left and side left) ChannelPositionSurroundRight ChannelPosition = C.GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT // (27) – Surround right (between rear right and side right) )
ChannelPosition castings
func ChannelPositionsFromMask ¶
func ChannelPositionsFromMask(channels int, mask uint64) []ChannelPosition
ChannelPositionsFromMask converts the channels present in mask to a position array (which should have at least channels entries ensured by caller). If mask is set to 0, it is considered as 'not present' for purpose of conversion. A partially valid mask with less bits set than the number of channels is considered valid. This function returns nil if the arguments are invalid.
func (ChannelPosition) String ¶
func (c ChannelPosition) String() string
type Flags ¶
type Flags int
Flags contains extra audio flags
const ( FlagNone Flags = C.GST_AUDIO_FLAG_NONE // (0) - no valid flag FlagUnpositioned Flags = C.GST_AUDIO_FLAG_UNPOSITIONED // (1) – the position array explicitly contains unpositioned channels. )
Flags castings
type Format ¶
type Format int
Format is an enum describing the most common audio formats
const ( // DefaultFormat is the default format used in consumer audio DefaultFormat Format = FormatS16LE FormatUnknown Format = C.GST_AUDIO_FORMAT_UNKNOWN // (0) – unknown or unset audio format FormatEncoded Format = C.GST_AUDIO_FORMAT_ENCODED // (1) – encoded audio format FormatS8 Format = C.GST_AUDIO_FORMAT_S8 // (2) – 8 bits in 8 bits, signed FormatU8 Format = C.GST_AUDIO_FORMAT_U8 // (3) – 8 bits in 8 bits, unsigned FormatS16LE Format = C.GST_AUDIO_FORMAT_S16LE // (4) – 16 bits in 16 bits, signed, little endian FormatS16BE Format = C.GST_AUDIO_FORMAT_S16BE // (5) – 16 bits in 16 bits, signed, big endian FormatU16LE Format = C.GST_AUDIO_FORMAT_U16LE // (6) – 16 bits in 16 bits, unsigned, little endian FormatU16BE Format = C.GST_AUDIO_FORMAT_U16BE // (7) – 16 bits in 16 bits, unsigned, big endian FormatS2432LE Format = C.GST_AUDIO_FORMAT_S24_32LE // (8) – 24 bits in 32 bits, signed, little endian FormatS2332BE Format = C.GST_AUDIO_FORMAT_S24_32BE // (9) – 24 bits in 32 bits, signed, big endian FormatU2432LE Format = C.GST_AUDIO_FORMAT_U24_32LE // (10) – 24 bits in 32 bits, unsigned, little endian FormatU2432BE Format = C.GST_AUDIO_FORMAT_U24_32BE // (11) – 24 bits in 32 bits, unsigned, big endian FormatS32LE Format = C.GST_AUDIO_FORMAT_S32LE // (12) – 32 bits in 32 bits, signed, little endian FormatS32BE Format = C.GST_AUDIO_FORMAT_S32BE // (13) – 32 bits in 32 bits, signed, big endian FormatU32LE Format = C.GST_AUDIO_FORMAT_U32LE // (14) – 32 bits in 32 bits, unsigned, little endian FormatU32BE Format = C.GST_AUDIO_FORMAT_U32BE // (15) – 32 bits in 32 bits, unsigned, big endian FormatS24LE Format = C.GST_AUDIO_FORMAT_S24LE // (16) – 24 bits in 24 bits, signed, little endian FormatS24BE Format = C.GST_AUDIO_FORMAT_S24BE // (17) – 24 bits in 24 bits, signed, big endian FormatU24LE Format = C.GST_AUDIO_FORMAT_U24LE // (18) – 24 bits in 24 bits, unsigned, little endian FormatU24BE Format = C.GST_AUDIO_FORMAT_U24BE // (19) – 24 bits in 24 bits, unsigned, big endian FormatS20LE Format = C.GST_AUDIO_FORMAT_S20LE // (20) – 20 bits in 24 bits, signed, little endian FormatS20BE Format = C.GST_AUDIO_FORMAT_S20BE // (21) – 20 bits in 24 bits, signed, big endian FormatU20LE Format = C.GST_AUDIO_FORMAT_U20LE // (22) – 20 bits in 24 bits, unsigned, little endian FormatU20BE Format = C.GST_AUDIO_FORMAT_U20BE // (23) – 20 bits in 24 bits, unsigned, big endian FormatS18LE Format = C.GST_AUDIO_FORMAT_S18LE // (24) – 18 bits in 24 bits, signed, little endian FormatS18BE Format = C.GST_AUDIO_FORMAT_S18BE // (25) – 18 bits in 24 bits, signed, big endian FormatU18LE Format = C.GST_AUDIO_FORMAT_U18LE // (26) – 18 bits in 24 bits, unsigned, little endian FormatU18BE Format = C.GST_AUDIO_FORMAT_U18BE // (27) – 18 bits in 24 bits, unsigned, big endian FormatF32LE Format = C.GST_AUDIO_FORMAT_F32LE // (28) – 32-bit floating point samples, little endian FormatF32BE Format = C.GST_AUDIO_FORMAT_F32BE // (29) – 32-bit floating point samples, big endian FormatF64LE Format = C.GST_AUDIO_FORMAT_F64LE // (30) – 64-bit floating point samples, little endian FormatF64BE Format = C.GST_AUDIO_FORMAT_F64BE // (31) – 64-bit floating point samples, big endian FormatS16 Format = C.GST_AUDIO_FORMAT_S16 // (4) – 16 bits in 16 bits, signed, native endianness FormatU16 Format = C.GST_AUDIO_FORMAT_U16 // (6) – 16 bits in 16 bits, unsigned, native endianness FormatS2432 Format = C.GST_AUDIO_FORMAT_S24_32 // (8) – 24 bits in 32 bits, signed, native endianness FormatU2432 Format = C.GST_AUDIO_FORMAT_U24_32 // (10) – 24 bits in 32 bits, unsigned, native endianness FormatS32 Format = C.GST_AUDIO_FORMAT_S32 // (12) – 32 bits in 32 bits, signed, native endianness FormatU32 Format = C.GST_AUDIO_FORMAT_U32 // (14) – 32 bits in 32 bits, unsigned, native endianness FormatS24 Format = C.GST_AUDIO_FORMAT_S24 // (16) – 24 bits in 24 bits, signed, native endianness FormatU24 Format = C.GST_AUDIO_FORMAT_U24 // (18) – 24 bits in 24 bits, unsigned, native endianness FormatS20 Format = C.GST_AUDIO_FORMAT_S20 // (20) – 20 bits in 24 bits, signed, native endianness FormatU20 Format = C.GST_AUDIO_FORMAT_U20 // (22) – 20 bits in 24 bits, unsigned, native endianness FormatS18 Format = C.GST_AUDIO_FORMAT_S18 // (24) – 18 bits in 24 bits, signed, native endianness FormatU18 Format = C.GST_AUDIO_FORMAT_U18 // (26) – 18 bits in 24 bits, unsigned, native endianness FormatF32 Format = C.GST_AUDIO_FORMAT_F32 // (28) – 32-bit floating point samples, native endianness FormatF64 Format = C.GST_AUDIO_FORMAT_F64 // (30) – 64-bit floating point samples, native endianness )
Castings for Formats
func FormatFromInteger ¶
FormatFromInteger returns a Format with the given parameters. Signed is whether signed or unsigned format. Endianness can be either LittleEndian or BigEndian. Width is the amount of bits used per sample, and depth is the amount of used bits in width.
func FormatFromString ¶
FormatFromString returns the format for the given string representation.
func RawFormats ¶
func RawFormats() []Format
RawFormats returns all the raw formats supported by GStreamer.
type FormatFlags ¶
type FormatFlags int
FormatFlags are the different audio flags that a format can have.
const ( FormatFlagInteger FormatFlags = C.GST_AUDIO_FORMAT_FLAG_INTEGER // (1) – integer samples FormatFlagFloat FormatFlags = C.GST_AUDIO_FORMAT_FLAG_FLOAT // (2) – float samples FormatFlagSigned FormatFlags = C.GST_AUDIO_FORMAT_FLAG_SIGNED // (4) – signed samples FormatFlagComplex FormatFlags = C.GST_AUDIO_FORMAT_FLAG_COMPLEX // (16) – complex layout FormatFlagUnpack FormatFlags = C.GST_AUDIO_FORMAT_FLAG_UNPACK // (32) – the format can be used in GstAudioFormatUnpack and GstAudioFormatPack functions )
Castings for FormatFlags
type FormatInfo ¶
type FormatInfo struct {
// contains filtered or unexported fields
}
FormatInfo is a structure containing information about an audio format.
func (*FormatInfo) Depth ¶
func (f *FormatInfo) Depth() int
Depth returns the amount of valid bits in width.
func (*FormatInfo) Description ¶
func (f *FormatInfo) Description() string
Description returns a user readable description for this info.
func (*FormatInfo) Endianness ¶
func (f *FormatInfo) Endianness() int
Endianness returns the endianness for this info.
func (*FormatInfo) Flags ¶
func (f *FormatInfo) Flags() FormatFlags
Flags returns the flags on this info.
func (*FormatInfo) Format ¶
func (f *FormatInfo) Format() Format
Format returns the format for this info.
func (*FormatInfo) Silence ¶
func (f *FormatInfo) Silence() []byte
Silence returns the data for a single silent sample.
func (*FormatInfo) UnpackFormat ¶
func (f *FormatInfo) UnpackFormat() Format
UnpackFormat is the format of unpacked samples.
func (*FormatInfo) Width ¶
func (f *FormatInfo) Width() int
Width returns the amount of bits used for one sample.
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info is a structure used for describing audio properties. This can be filled in from caps or coverted back to caps.
func InfoFromCaps ¶
InfoFromCaps parses the provided caps and creates an info. It returns true if the caps could be parsed.
func (*Info) BPF ¶
BPF returns the number of bytes for one frame. This is the size of one sample * Channels.
func (*Info) Convert ¶
Convert converts among various gst.Format types. This function handles gst.FormatBytes, gst.FormatTime, and gst.FormatDefault. For raw audio, gst.FormatDefault corresponds to audio frames. This function can be used to handle pad queries of the type gst.QueryConvert. To provide a value from a time.Duration, use the Nanoseconds() method.
func (*Info) FormatInfo ¶
func (i *Info) FormatInfo() *FormatInfo
FormatInfo returns the format info for the audio.
func (*Info) Free ¶
func (i *Info) Free()
Free frees the AudioInfo structure. This is usually handled for you by the bindings.
func (*Info) Positions ¶
func (i *Info) Positions() []ChannelPosition
Positions returns the positions for each channel.
type Layout ¶
type Layout int
Layout represents the layout of audio samples for different channels.
const ( LayoutInterleaved Layout = C.GST_AUDIO_LAYOUT_INTERLEAVED // (0) – interleaved audio LayoutNonInterleaved Layout = C.GST_AUDIO_LAYOUT_NON_INTERLEAVED // (1) – non-interleaved audio )
Castings for Layouts
type PackFlags ¶
type PackFlags int
PackFlags are the different flags that can be used when packing and unpacking.
const ( PackFlagNone PackFlags = C.GST_AUDIO_PACK_FLAG_NONE // (0) – No flag PackFlagTruncateRange PackFlags = C.GST_AUDIO_PACK_FLAG_TRUNCATE_RANGE // (1) – When the source has a smaller depth than the target format, set the least significant bits of the target to 0. This is likely slightly faster but less accurate. When this flag is not specified, the most significant bits of the source are duplicated in the least significant bits of the destination. )
Castings for PackFlags