media

package
v0.0.0-...-b172891 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioSource

type AudioSource interface {
	Source

	Codec() string

	SampleRate() int
	BytesPerSample() int
}

type Flow

type Flow struct {
	// Start is called when the first receiver is added.
	Start func()

	// Stop is called when the last receiver is removed.
	Stop func()

	sync.Mutex
	// contains filtered or unexported fields
}

Flow is a concrete implementation of Source that can be embedded into a struct.

func (*Flow) AddReceiver

func (f *Flow) AddReceiver(capacity int) Receiver

func (*Flow) Put

func (f *Flow) Put(buf *packet.SharedBuffer) error

func (*Flow) PutBuffer

func (f *Flow) PutBuffer(data []byte, done func()) error

TODO: Do we need this?

func (*Flow) RemoveReceiver

func (f *Flow) RemoveReceiver(r Receiver)

func (*Flow) Shutdown

func (f *Flow) Shutdown(cause error)

type Receiver

type Receiver interface {
	// Buffers returns a channel from which callers can read Source buffers.
	Buffers() <-chan *packet.SharedBuffer

	// Err returns the reason when the Buffers() channel is closed.
	Err() error
}

type Source

type Source interface {
	// AddReceiver creates a new Receiver r, and starts passing incoming data
	// buffers to it. The source will not block sending to r, so the capacity
	// must be sufficient to keep up with the rate of incoming data. (In
	// particular, capacity must be > 0.) The Receiver channel may be closed if
	// the source is interrupted, in which case r.Err will be populated.
	//
	// Callers must ensure that the receiver is removed when processing is
	// complete (e.g. a defer statement immediately following AddReceiver()).
	AddReceiver(capacity int) Receiver

	// RemoveReceiver tells the source to stop passing data buffers to r. Upon
	// return, it is guaranteed r will not receive any more data.
	RemoveReceiver(r Receiver)
}

A Source is a stream of media data that can have multiple consumers. The media data is chunked into packets (which may represent discrete video frames, or spans of multiple audio frames). Consumer functions register a Receiver, to which the Source sends packets. Each packet is delivered as a *packet.SharedBuffer instance, which the consumer must process and then release.

If the Source encounters an error, all receiver channels will be closed. The Receiver's Err() function will return the reason for the interruption.

The Source interface represents only the consumer-facing side of a media stream; it makes no assumptions about how the data is produced. Nor does it describe the nature of the data packets being delivered. It merely provides an interface for common behavior between AudioSource and VideoSource, which extend Source.

Example usage:

var src Source = ...
r := src.AddReceiver(4)
defer src.RemoveReceiver(r)
for {
	buf, more := <-r.Buffers()
	if !more {
		// Process r.Err()
		break
	}
	// Do something with buf.Bytes(), then call buf.Release()
}

type VideoSource

type VideoSource interface {
	Source

	Codec() string

	Width() int
	Height() int
}

func OpenMP4

func OpenMP4(filename string) (VideoSource, error)

Open an MP4 file and return the video stream as a VideoSource. TODO: Return an AudioSource as well.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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