astilibav

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventNameFiltererSwitchInDone  = "astilibav.filterer.switch.in.done"
	EventNameFiltererSwitchOutDone = "astilibav.filterer.switch.out.done"
	EventNameRateEnforcerSwitched  = "astilibav.rate.enforcer.switched"
)

Event names

Variables

View Source
var PktDumpFile = func(pkt *avcodec.Packet, args PktDumperHandlerArgs) (err error) {
	// Create file
	var f *os.File
	if f, err = os.Create(args.Pattern); err != nil {
		err = errors.Wrapf(err, "astilibav: creating file %s failed", args.Pattern)
		return
	}
	defer f.Close()

	if _, err = f.Write(C.GoBytes(unsafe.Pointer(pkt.Data()), (C.int)(pkt.Size()))); err != nil {
		err = errors.Wrapf(err, "astilibav: writing to file %s failed", args.Pattern)
		return
	}
	return
}

PktDumpFunc is a PktDumpFunc that dumps the packet to a file

View Source
var Version = Versions{
	AvCodec:  avcodec.AvcodecVersion(),
	AvDevice: avdevice.AvdeviceVersion(),
	AvFilter: avfilter.AvfilterVersion(),
	AvUtil:   avutil.AvutilVersion(),
	Resample: swresample.SwresampleLicense(),
	SWScale:  swscale.SwscaleVersion(),
}

Version stores the versions

Functions

func AddStream

func AddStream(ctxFormat *avformat.Context) *avformat.Stream

AddStream adds a stream to the format ctx

func CloneStream

func CloneStream(i *avformat.Stream, ctxFormat *avformat.Context) (o *avformat.Stream, err error)

CloneStream clones a stream and add it to the format ctx

Types

type AvError

type AvError int

AvError represents a libav error

func NewAvError

func NewAvError(ret int) AvError

NewAvError creates a new av error

func (AvError) Error

func (e AvError) Error() string

Error implements the error interface

func (AvError) IsOneOf

func (e AvError) IsOneOf(rs ...int) bool

IsOneOf checks whether the error is one of the specified raw return code such as avutil.AVERROR_* codes

type Context

type Context struct {
	// Shared
	BitRate      int
	CodecID      avcodec.CodecId
	CodecName    string
	CodecType    avcodec.MediaType
	Dict         string
	GlobalHeader bool
	ThreadCount  *int
	TimeBase     avutil.Rational

	// Audio
	ChannelLayout uint64
	Channels      int
	SampleFmt     avcodec.AvSampleFormat
	SampleRate    int

	// Video
	FrameRate         avutil.Rational
	GopSize           int
	Height            int
	PixelFormat       avutil.PixelFormat
	SampleAspectRatio avutil.Rational
	Width             int
}

Context represents parameters of an audio or a video context

func NewContextFromStream

func NewContextFromStream(s *avformat.Stream) Context

NewContextFromStream creates a new context from a stream

type Decoder

type Decoder struct {
	*astiencoder.BaseNode
	// contains filtered or unexported fields
}

Decoder represents an object capable of decoding packets

func NewDecoder

func NewDecoder(o DecoderOptions, eh *astiencoder.EventHandler, c *astidefer.Closer) (d *Decoder, err error)

NewDecoder creates a new decoder

func (*Decoder) Connect

func (d *Decoder) Connect(h FrameHandler)

Connect implements the FrameHandlerConnector interface

func (*Decoder) Disconnect

func (d *Decoder) Disconnect(h FrameHandler)

Disconnect implements the FrameHandlerConnector interface

func (*Decoder) HandlePkt

func (d *Decoder) HandlePkt(p *PktHandlerPayload)

HandlePkt implements the PktHandler interface

func (*Decoder) Start

Start starts the decoder

type DecoderOptions

type DecoderOptions struct {
	CodecParams *avcodec.CodecParameters
	Node        astiencoder.NodeOptions
}

DecoderOptions represents decoder options

type Demuxer

type Demuxer struct {
	*astiencoder.BaseNode
	// contains filtered or unexported fields
}

Demuxer represents an object capable of demuxing packets out of an input

func NewDemuxer

func NewDemuxer(o DemuxerOptions, eh *astiencoder.EventHandler, c *astidefer.Closer) (d *Demuxer, err error)

NewDemuxer creates a new demuxer

func (*Demuxer) Connect

func (d *Demuxer) Connect(h PktHandler)

Connect implements the PktHandlerConnector interface

func (*Demuxer) ConnectForStream

func (d *Demuxer) ConnectForStream(h PktHandler, i *avformat.Stream)

ConnectForStream connects the demuxer to a PktHandler for a specific stream

func (*Demuxer) CtxFormat

func (d *Demuxer) CtxFormat() *avformat.Context

CtxFormat returns the format ctx

func (*Demuxer) Disconnect

func (d *Demuxer) Disconnect(h PktHandler)

Disconnect implements the PktHandlerConnector interface

func (*Demuxer) DisconnectForStream

func (d *Demuxer) DisconnectForStream(h PktHandler, i *avformat.Stream)

DisconnectForStream disconnects the demuxer from a PktHandler for a specific stream

func (*Demuxer) Start

Start starts the demuxer

type DemuxerOptions

type DemuxerOptions struct {
	// String content of the demuxer as you would use in ffmpeg
	Dict string
	// If true, the demuxer will sleep between packets for the exact duration of the packet
	EmulateRate bool
	// Context used to cancel finding stream info
	FindStreamInfoCtx context.Context
	// Exact input format
	Format *avformat.InputFormat
	// If true, at the end of the input the demuxer will seek to its beginning and start over
	// In this case the packets are restamped
	Loop bool
	// Basic node options
	Node astiencoder.NodeOptions
	// If true, the demuxer will not dispatch packets until, for at least one stream, 2 consecutive packets are received
	// at an interval >= to the first packet's duration
	SeekToLive bool
	// URL of the input
	URL string
}

DemuxerOptions represents demuxer options

type Descriptor

type Descriptor interface {
	TimeBase() avutil.Rational
}

Descriptor is an object that can describe a set of parameters

type Encoder

type Encoder struct {
	*astiencoder.BaseNode
	// contains filtered or unexported fields
}

Encoder represents an object capable of encoding frames

func NewEncoder

func NewEncoder(o EncoderOptions, eh *astiencoder.EventHandler, c *astidefer.Closer) (e *Encoder, err error)

NewEncoder creates a new encoder

func (*Encoder) AddStream

func (e *Encoder) AddStream(ctxFormat *avformat.Context) (o *avformat.Stream, err error)

AddStream adds a stream based on the codec ctx

func (*Encoder) Connect

func (e *Encoder) Connect(h PktHandler)

Connect implements the PktHandlerConnector interface

func (*Encoder) Disconnect

func (e *Encoder) Disconnect(h PktHandler)

Disconnect implements the PktHandlerConnector interface

func (*Encoder) FrameSize

func (e *Encoder) FrameSize() int

FrameSize returns the encoder frame size

func (*Encoder) HandleFrame

func (e *Encoder) HandleFrame(p *FrameHandlerPayload)

HandleFrame implements the FrameHandler interface

func (*Encoder) Start

Start starts the encoder

type EncoderOptions

type EncoderOptions struct {
	Ctx  Context
	Node astiencoder.NodeOptions
}

EncoderOptions represents encoder options

type Filterer

type Filterer struct {
	*astiencoder.BaseNode
	// contains filtered or unexported fields
}

Filterer represents an object capable of applying a filter to frames

func NewFilterer

func NewFilterer(o FiltererOptions, eh *astiencoder.EventHandler, c *astidefer.Closer) (f *Filterer, err error)

NewFilterer creates a new filterer

func (*Filterer) Connect

func (f *Filterer) Connect(h FrameHandler)

Connect implements the FrameHandlerConnector interface

func (*Filterer) Disconnect

func (f *Filterer) Disconnect(h FrameHandler)

Disconnect implements the FrameHandlerConnector interface

func (*Filterer) HandleFrame

func (f *Filterer) HandleFrame(p *FrameHandlerPayload)

HandleFrame implements the FrameHandler interface

func (*Filterer) SendCommand

func (f *Filterer) SendCommand(target, cmd, arg string, flags int) (err error)

SendCommand sends a command to the filterer

func (*Filterer) Start

Start starts the filterer

func (*Filterer) Switch

func (f *Filterer) Switch(opt FiltererSwitchOptions) (nf *Filterer, err error)

Switch disconnects/stops/closes the current filterer and starts/connects the new filterer properly

type FiltererInput

type FiltererInput struct {
	Context Context
	Node    astiencoder.Node
}

FiltererInput represents a filterer input

type FiltererOptions

type FiltererOptions struct {
	Content   string
	Inputs    map[string]FiltererInput
	Node      astiencoder.NodeOptions
	Restamper FrameRestamper
	Switcher  FiltererSwitcher
}

FiltererOptions represents filterer options

type FiltererSwitchOptions

type FiltererSwitchOptions struct {
	Filter   FiltererOptions
	Workflow *astiencoder.Workflow
}

FiltererSwitchOptions represents filterer switch options

type FiltererSwitcher

type FiltererSwitcher interface {
	IncIn(n astiencoder.Node)
	IncOut()
	Reset()
	ShouldIn(n astiencoder.Node) (ko bool)
	ShouldOut() (ko bool)
	Switch()
}

FiltererSwitcher represents an object that can take care of synchronizing things when switching a filterer

type Forwarder

type Forwarder struct {
	*astiencoder.BaseNode
	// contains filtered or unexported fields
}

Forwarder represents an object capable of forwarding frames

func NewForwarder

func NewForwarder(o ForwarderOptions, eh *astiencoder.EventHandler, c *astidefer.Closer) (f *Forwarder)

NewForwarder creates a new forwarder

func (*Forwarder) Connect

func (f *Forwarder) Connect(h FrameHandler)

Connect implements the FrameHandlerConnector interface

func (*Forwarder) Disconnect

func (f *Forwarder) Disconnect(h FrameHandler)

Disconnect implements the FrameHandlerConnector interface

func (*Forwarder) HandleFrame

func (f *Forwarder) HandleFrame(p *FrameHandlerPayload)

HandleFrame implements the FrameHandler interface

func (*Forwarder) Start

Start starts the forwarder

type ForwarderOptions

type ForwarderOptions struct {
	Node      astiencoder.NodeOptions
	Restamper FrameRestamper
}

ForwarderOptions represents forwarder options

type FrameHandler

type FrameHandler interface {
	astiencoder.Node
	HandleFrame(p *FrameHandlerPayload)
}

FrameHandler represents a node that can handle a frame

type FrameHandlerConnector

type FrameHandlerConnector interface {
	Connect(next FrameHandler)
	Disconnect(next FrameHandler)
}

FrameHandlerConnector represents an object that can connect/disconnect with a frame handler

type FrameHandlerPayload

type FrameHandlerPayload struct {
	Descriptor Descriptor
	Frame      *avutil.Frame
	Node       astiencoder.Node
}

FrameHandlerPayload represents a FrameHandler payload

type FrameRestamper

type FrameRestamper interface {
	Restamp(f *avutil.Frame)
}

FrameRestamper represents an object capable of restamping frames

func NewFrameRestamperWithFrameDuration

func NewFrameRestamperWithFrameDuration(frameDuration int64) FrameRestamper

NewFrameRestamperWithFrameDuration creates a new frame restamper that starts timestamps from 0 and increments them of frameDuration frameDuration must be a duration in frame time base

func NewFrameRestamperWithModulo

func NewFrameRestamperWithModulo(frameDuration int64) FrameRestamper

NewFrameRestamperWithModulo creates a new frame restamper that makes sure that PTS % frame duration = 0 frameDuration must be a duration in frame time base

type Muxer

type Muxer struct {
	*astiencoder.BaseNode
	// contains filtered or unexported fields
}

Muxer represents an object capable of muxing packets into an output

func NewMuxer

func NewMuxer(o MuxerOptions, eh *astiencoder.EventHandler, c *astidefer.Closer) (m *Muxer, err error)

NewMuxer creates a new muxer

func (*Muxer) CtxFormat

func (m *Muxer) CtxFormat() *avformat.Context

CtxFormat returns the format ctx

func (*Muxer) NewPktHandler

func (m *Muxer) NewPktHandler(o *avformat.Stream) *MuxerPktHandler

NewHandler creates

func (*Muxer) Start

func (m *Muxer) Start(ctx context.Context, t astiencoder.CreateTaskFunc)

Start starts the muxer

type MuxerOptions

type MuxerOptions struct {
	Format     *avformat.OutputFormat
	FormatName string
	Node       astiencoder.NodeOptions
	Restamper  PktRestamper
	URL        string
}

MuxerOptions represents muxer options

type MuxerPktHandler

type MuxerPktHandler struct {
	*Muxer
	// contains filtered or unexported fields
}

MuxerPktHandler is an object that can handle a pkt for the muxer

func (*MuxerPktHandler) HandlePkt

func (h *MuxerPktHandler) HandlePkt(p *PktHandlerPayload)

HandlePkt implements the PktHandler interface

type PktCond

type PktCond interface {
	UsePkt(pkt *avcodec.Packet) bool
}

PktCond represents an object that can decide whether to use a pkt

type PktDumper

type PktDumper struct {
	*astiencoder.BaseNode
	// contains filtered or unexported fields
}

PktDumper represents an object capable of dumping packets

func NewPktDumper

func NewPktDumper(o PktDumperOptions, eh *astiencoder.EventHandler) (d *PktDumper, err error)

NewPktDumper creates a new pk dumper

func (*PktDumper) HandlePkt

func (d *PktDumper) HandlePkt(p *PktHandlerPayload)

HandlePkt implements the PktHandler interface

func (*PktDumper) Start

func (d *PktDumper) Start(ctx context.Context, t astiencoder.CreateTaskFunc)

Start starts the pkt dumper

type PktDumperHandlerArgs

type PktDumperHandlerArgs struct {
	Pattern string
}

PktDumperHandlerArgs represents pkt dumper handler args

type PktDumperOptions

type PktDumperOptions struct {
	Data    map[string]interface{}
	Handler func(pkt *avcodec.Packet, args PktDumperHandlerArgs) error
	Node    astiencoder.NodeOptions
	Pattern string
}

PktDumperOptions represents pkt dumper options

type PktHandler

type PktHandler interface {
	astiencoder.Node
	HandlePkt(p *PktHandlerPayload)
}

PktHandler represents a node that can handle a pkt

type PktHandlerConnector

type PktHandlerConnector interface {
	Connect(next PktHandler)
	Disconnect(next PktHandler)
}

PktHandlerConnector represents an object that can connect/disconnect with a pkt handler

type PktHandlerPayload

type PktHandlerPayload struct {
	Descriptor Descriptor
	Pkt        *avcodec.Packet
}

PktHandlerPayload represents a PktHandler payload

type PktRestamper

type PktRestamper interface {
	Restamp(pkt *avcodec.Packet)
}

PktRestamper represents an object capable of restamping packets

func NewPktRestamperStartFromZero

func NewPktRestamperStartFromZero() PktRestamper

NewPktRestamperStartFromZero creates a new pkt restamper that starts timestamps from 0

func NewPktRestamperWithPktDuration

func NewPktRestamperWithPktDuration() PktRestamper

NewPktRestamperWithPktDuration creates a new pkt restamper that starts timestamps from 0 and increments them of the previous pkt.Duration()

type RateEnforcer

type RateEnforcer struct {
	*astiencoder.BaseNode
	// contains filtered or unexported fields
}

RateEnforcer represents an object capable of enforcing rate based on PTS

func NewRateEnforcer

NewRateEnforcer creates a new rate enforcer

func (*RateEnforcer) Connect

func (r *RateEnforcer) Connect(h FrameHandler)

Connect implements the FrameHandlerConnector interface

func (*RateEnforcer) Disconnect

func (r *RateEnforcer) Disconnect(h FrameHandler)

Disconnect implements the FrameHandlerConnector interface

func (*RateEnforcer) HandleFrame

func (r *RateEnforcer) HandleFrame(p *FrameHandlerPayload)

HandleFrame implements the FrameHandler interface

func (*RateEnforcer) Start

Start starts the rate enforcer

func (*RateEnforcer) Switch

func (r *RateEnforcer) Switch(n astiencoder.Node)

Switch switches the source

type RateEnforcerOptions

type RateEnforcerOptions struct {
	Delay     time.Duration
	FrameRate avutil.Rational
	Node      astiencoder.NodeOptions
	Restamper FrameRestamper
}

RateEnforcerOptions represents rate enforcer options

type Versions

type Versions struct {
	AvCodec  uint
	AvDevice uint
	AvFilter uint
	AvUtil   uint
	Resample string
	SWScale  uint
}

Versions represents the versions

func (Versions) String

func (v Versions) String() string

String implements the Stringer interface

Jump to

Keyboard shortcuts

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