aac

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2021 License: MIT Imports: 1 Imported by: 3

Documentation

Overview

The oryx AAC package includes some utilites.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ADTS

type ADTS interface {
	// Set the ASC, the codec information.
	// Before encoding raw frame, user must set the asc.
	SetASC(asc []byte) (err error)
	// Encode the raw aac frame to adts data.
	// @remark User must set the asc first.
	Encode(raw []byte) (adts []byte, err error)

	// Decode the adts data to raw frame.
	// @remark User can get the asc after decode ok.
	// @remark When left if not nil, user must decode it again.
	Decode(adts []byte) (raw, left []byte, err error)
	// Get the ASC, the codec information.
	// When decode a adts data or set the asc, user can use this API to get it.
	ASC() *AudioSpecificConfig
}

The ADTS is a format of AAC. We can encode the RAW AAC frame in ADTS muxer. We can also decode the ADTS data to RAW AAC frame.

func NewADTS

func NewADTS() (ADTS, error)

type ADTSImpl added in v0.0.5

type ADTSImpl struct {
	// contains filtered or unexported fields
}

Please use NewADTS() and interface ADTS instead. It's only exposed for example.

func (*ADTSImpl) ASC added in v0.0.5

func (v *ADTSImpl) ASC() *AudioSpecificConfig

func (*ADTSImpl) Decode added in v0.0.5

func (v *ADTSImpl) Decode(data []byte) (raw, left []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx-lib/aac"
)

func main() {
	var err error
	var adts aac.ADTS
	if adts, err = aac.NewADTS(); err != nil {
		fmt.Println(fmt.Sprintf("APP: Create ADTS failed, err is %+v", err))
		return
	}

	var data []byte // Read ADTS data from file or network.

	// Ignore the left, assume that the RAW only contains one AAC frame.
	var raw []byte
	if raw, _, err = adts.Decode(data); err != nil {
		fmt.Println(fmt.Sprintf("APP: ADTS decode failed, err is %+v", err))
		return
	}

	// Use the RAW data.
	_ = raw

	// Use the asc object, for example, used as RTMP audio sequence header.
	_ = adts.ASC()
}
Output:

func (*ADTSImpl) Encode added in v0.0.5

func (v *ADTSImpl) Encode(raw []byte) (data []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/ossrs/go-oryx-lib/aac"
)

func main() {
	var err error
	var adts aac.ADTS
	if adts, err = aac.NewADTS(); err != nil {
		fmt.Println(fmt.Sprintf("APP: Create ADTS failed, err is %+v", err))
		return
	}

	var raw []byte // Read RAW AAC from file or network.
	var data []byte
	if data, err = adts.Encode(raw); err != nil {
		fmt.Println(fmt.Sprintf("APP: ADTS encode failed, err is %+v", err))
		return
	}

	// Use the ADTS data.
	_ = data
}
Output:

func (*ADTSImpl) SetASC added in v0.0.5

func (v *ADTSImpl) SetASC(asc []byte) (err error)

type AudioSpecificConfig

type AudioSpecificConfig struct {
	Object     ObjectType      // AAC object type.
	SampleRate SampleRateIndex // AAC sample rate, not the FLV sampling rate.
	Channels   Channels        // AAC channel configuration.
}

Convert the ASC(Audio Specific Configuration). Refer to @doc ISO_IEC_14496-3-AAC-2001.pdf, @page 33, @section 1.6.2.1 AudioSpecificConfig

func (*AudioSpecificConfig) MarshalBinary

func (v *AudioSpecificConfig) MarshalBinary() (data []byte, err error)

func (*AudioSpecificConfig) UnmarshalBinary

func (v *AudioSpecificConfig) UnmarshalBinary(data []byte) (err error)

type Channels

type Channels uint8

The aac channel. Refer to @doc ISO_IEC_13818-7-AAC-2004.pdf, @page 72, @section Table 42 – Implicit speaker mapping

const (
	ChannelForbidden Channels = iota
	// center front speaker
	// FFMPEG: mono           FC
	ChannelMono
	// left, right front speakers
	// FFMPEG: stereo         FL+FR
	ChannelStereo
	// center front speaker, left, right front speakers
	// FFMPEG: 2.1            FL+FR+LFE
	// FFMPEG: 3.0            FL+FR+FC
	// FFMPEG: 3.0(back)      FL+FR+BC
	Channel3
	// center front speaker, left, right center front speakers, rear surround
	// FFMPEG: 4.0            FL+FR+FC+BC
	// FFMPEG: quad           FL+FR+BL+BR
	// FFMPEG: quad(side)     FL+FR+SL+SR
	// FFMPEG: 3.1            FL+FR+FC+LFE
	Channel4
	// center front speaker, left, right front speakers, left surround, right surround rear speakers
	// FFMPEG: 5.0            FL+FR+FC+BL+BR
	// FFMPEG: 5.0(side)      FL+FR+FC+SL+SR
	// FFMPEG: 4.1            FL+FR+FC+LFE+BC
	Channel5
	// center front speaker, left, right front speakers, left surround, right surround rear speakers,
	// front low frequency effects speaker
	// FFMPEG: 5.1            FL+FR+FC+LFE+BL+BR
	// FFMPEG: 5.1(side)      FL+FR+FC+LFE+SL+SR
	// FFMPEG: 6.0            FL+FR+FC+BC+SL+SR
	// FFMPEG: 6.0(front)     FL+FR+FLC+FRC+SL+SR
	// FFMPEG: hexagonal      FL+FR+FC+BL+BR+BC
	Channel5_1 // speakers: 6
	// center front speaker, left, right center front speakers, left, right outside front speakers,
	// left surround, right surround rear speakers, front low frequency effects speaker
	// FFMPEG: 7.1            FL+FR+FC+LFE+BL+BR+SL+SR
	// FFMPEG: 7.1(wide)      FL+FR+FC+LFE+BL+BR+FLC+FRC
	// FFMPEG: 7.1(wide-side) FL+FR+FC+LFE+FLC+FRC+SL+SR
	Channel7_1 // speakers: 7

)

func (Channels) String

func (v Channels) String() string

type ObjectType

type ObjectType uint8

The AAC object type in RAW AAC frame. Refer to @doc ISO_IEC_14496-3-AAC-2001.pdf, @page 23, @section 1.5.1.1 Audio object type definition

const (
	ObjectTypeForbidden ObjectType = iota

	ObjectTypeMain
	ObjectTypeLC
	ObjectTypeSSR

	ObjectTypeHE   ObjectType = 5  // HE=LC+SBR
	ObjectTypeHEv2 ObjectType = 29 // HEv2=LC+SBR+PS
)

func (ObjectType) String

func (v ObjectType) String() string

func (ObjectType) ToProfile

func (v ObjectType) ToProfile() Profile

type Profile

type Profile uint8

The profile of AAC in ADTS. Refer to @doc ISO_IEC_13818-7-AAC-2004.pdf, @page 40, @section 7.1 Profiles

const (
	ProfileMain Profile = iota
	ProfileLC
	ProfileSSR
	ProfileForbidden
)

func (Profile) String

func (v Profile) String() string

func (Profile) ToObjectType

func (v Profile) ToObjectType() ObjectType

type SampleRateIndex

type SampleRateIndex uint8

The aac sample rate index. Refer to @doc ISO_IEC_13818-7-AAC-2004.pdf, @page 46, @section Table 35 – Sampling frequency

const (
	SampleRateIndex96kHz SampleRateIndex = iota
	SampleRateIndex88kHz
	SampleRateIndex64kHz
	SampleRateIndex48kHz
	SampleRateIndex44kHz
	SampleRateIndex32kHz
	SampleRateIndex24kHz
	SampleRateIndex22kHz
	SampleRateIndex16kHz
	SampleRateIndex12kHz
	SampleRateIndex11kHz
	SampleRateIndex8kHz
	SampleRateIndex7kHz
	SampleRateIndexReserved0
	SampleRateIndexReserved1
	SampleRateIndexReserved2
	SampleRateIndexReserved3
	SampleRateIndexForbidden
)

func (SampleRateIndex) String

func (v SampleRateIndex) String() string

func (SampleRateIndex) ToHz

func (v SampleRateIndex) ToHz() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL