media

package
v2.8.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultOpusSampleRate     = 48000
	DefaultOpusSampleDuration = 20 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type PCMLocalTrack

type PCMLocalTrack struct {
	*webrtc.TrackLocalStaticSample
	// contains filtered or unexported fields
}

func NewPCMLocalTrack

func NewPCMLocalTrack(sourceSampleRate int, sourceChannels int, logger protoLogger.Logger, opts ...PCMLocalTrackOption) (*PCMLocalTrack, error)

NewPCMLocalTrack creates a wrapper around a webrtc.TrackLocalStaticSample that accepts PCM16 samples via the WriteSample method, encodes them to opus, and writes them to the track. PCMLocalTrack can directly be used as a local track to publish to a room. The sourceSampleRate and sourceChannels are the sample rate and channels of the source audio. It also provides an option to write silence when no data is available, which is disabled by default. Stereo tracks are not supported, they may result in unpleasant audio.

func (*PCMLocalTrack) ClearQueue added in v2.7.1

func (t *PCMLocalTrack) ClearQueue()

func (*PCMLocalTrack) Close

func (t *PCMLocalTrack) Close()

func (*PCMLocalTrack) WaitForPlayout added in v2.7.1

func (t *PCMLocalTrack) WaitForPlayout()

func (*PCMLocalTrack) WriteSample

func (t *PCMLocalTrack) WriteSample(sample media.PCM16Sample) error

type PCMLocalTrackOption

type PCMLocalTrackOption func(*PCMLocalTrackParams)

func WithWriteSilenceOnNoData

func WithWriteSilenceOnNoData(writeSilenceOnNoData bool) PCMLocalTrackOption

type PCMLocalTrackParams

type PCMLocalTrackParams struct {
	WriteSilenceOnNoData bool
}

type PCMRemoteTrack

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

func NewPCMRemoteTrack

func NewPCMRemoteTrack(track *webrtc.TrackRemote, writer PCMRemoteTrackWriter, opts ...PCMRemoteTrackOption) (*PCMRemoteTrack, error)

PCMRemoteTrack takes a remote track (currently only opus is supported) and a WriterCloser interface that writes implements a WriteSample method to write PCM16 samples, where the user desires. The PCMRemoteTrack will read RTP packets from the remote track, decode them to PCM16 samples, and write them to the writer. Audio is resampled to targetSampleRate and upmixed/downmixed to targetChannels. It also provides an option to handle jitter, which is enabled by default. Stereo remote tracks are currently not supported, and are known to have a lot of unpleasant noise.

func (*PCMRemoteTrack) Close

func (t *PCMRemoteTrack) Close()

type PCMRemoteTrackOption

type PCMRemoteTrackOption func(*PCMRemoteTrackParams)

func WithHandleJitter

func WithHandleJitter(handleJitter bool) PCMRemoteTrackOption

func WithTargetChannels

func WithTargetChannels(targetChannels int) PCMRemoteTrackOption

func WithTargetSampleRate

func WithTargetSampleRate(targetSampleRate int) PCMRemoteTrackOption

type PCMRemoteTrackParams

type PCMRemoteTrackParams struct {
	HandleJitter     bool
	TargetSampleRate int
	TargetChannels   int
}

type PCMRemoteTrackWriter

type PCMRemoteTrackWriter interface {
	WriteSample(sample media.PCM16Sample) error
	Close() error
}

Jump to

Keyboard shortcuts

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