kinesisvideomanager

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 23 Imported by: 2

README

kinesisvideomanager

PkgGoDev CI codecov

Kinesis Video Streams Producer/Consumer Library for Go

Documentation

Index

Constants

View Source
const (
	TagNameFragmentNumber     = "AWS_KINESISVIDEO_FRAGMENT_NUMBER"
	TagNameServerTimestamp    = "AWS_KINESISVIDEO_SERVER_TIMESTAMP"
	TagNameProducerTimestamp  = "AWS_KINESISVIDEO_PRODUCER_TIMESTAMP"
	TagNameExceptionErrorCode = "AWS_KINESISVIDEO_EXCEPTION_ERROR_CODE"
	TagNameExceptionMessage   = "AWS_KINESISVIDEO_EXCEPTION_MESSAGE"
)
View Source
const TimecodeScale = 1000000

Variables

View Source
var (
	ErrInvalidTimecode = errors.New("invalid timecode")
	ErrWriteTimeout    = errors.New("write timeout")
)

Functions

func ParseTimestamp

func ParseTimestamp(timestamp string) (time.Time, error)

func SetLogger

func SetLogger(l LoggerIF)

func ToTimestamp

func ToTimestamp(t time.Time) string

Types

type BlockChWithBaseTimecode

type BlockChWithBaseTimecode struct {
	Timecode chan uint64
	Block    chan ebml.Block
	Tag      chan *Tag
}

type BlockReader added in v1.0.0

type BlockReader interface {
	// Read returns media block.
	Read() (*BlockWithBaseTimecode, error)
	// ReadTag returns stored tag.
	ReadTag() (*Tag, error)
	// Close the connenction to Kinesis Video Stream.
	Close() (*Container, error)
}

type BlockWithBaseTimecode

type BlockWithBaseTimecode struct {
	Timecode uint64
	Block    ebml.Block
}

func (*BlockWithBaseTimecode) AbsTimecode

func (bt *BlockWithBaseTimecode) AbsTimecode() int64

type BlockWithMetadata

type BlockWithMetadata struct {
	*BlockWithBaseTimecode
	*FragmentMetadata
}

type BlockWriter added in v0.9.0

type BlockWriter interface {
	// Write a block to Kinesis Video Stream.
	Write(*BlockWithBaseTimecode) error
	// ReadResponse reads a response from Kinesis Video Stream.
	ReadResponse() (*FragmentEvent, error)
	// Close immediately shuts down the client.
	Close() error
	// Shutdown gracefully shuts down the client without interrupting on-going PutMedia request.
	// If Shotdown returned an error, some of the internal resources might not released yet and
	// caller should call Shutdown or Close again.
	Shutdown(ctx context.Context) error
}

type Client

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

func New

func New(sess client.ConfigProvider, cfgs ...*aws.Config) (*Client, error)

func (*Client) Consumer

func (c *Client) Consumer(streamID StreamID) (*Consumer, error)

func (*Client) Provider

func (c *Client) Provider(streamID StreamID, tracks []TrackEntry) (*Provider, error)

type Cluster

type Cluster struct {
	Timecode    chan uint64
	Position    uint64 `ebml:",omitempty"`
	SimpleBlock chan ebml.Block
}

type ClusterWrite

type ClusterWrite struct {
	Timecode    chan uint64
	Position    uint64 `ebml:",omitempty"`
	SimpleBlock chan ebml.Block
}

type Consumer

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

func (*Consumer) GetMedia

func (c *Consumer) GetMedia(opts ...GetMediaOption) (BlockReader, error)

GetMedia opens connection to Kinesis Video Stream to get media blocks. This function immediately returns BlockReader. Both BlockWriter.Read() and BlockWriter.ReadTag() must be called until getting io.EOF as error, otherwise Reader will be blocked after the buffer is filled.

type Container

type Container struct {
	Header  EBMLHeader `ebml:"EBML"`
	Segment Segment    `ebml:",size=unknown"`
}

type EBMLHeader

type EBMLHeader struct {
	EBMLVersion            uint64
	EBMLReadVersion        uint64
	EBMLMaxIDLength        uint64
	EBMLMaxSizeLength      uint64
	EBMLDocType            string
	EBMLDocTypeVersion     uint64
	EBMLDocTypeReadVersion uint64
}

type ErrorID added in v0.6.1

type ErrorID int

ErrorID represents ErrorId enum of PutMedia API. See https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/API_dataplane_PutMedia.html for details.

const (
	STREAM_READ_ERROR                      ErrorID = 4000
	MAX_FRAGMENT_SIZE_REACHED              ErrorID = 4001
	MAX_FRAGMENT_DURATION_REACHED          ErrorID = 4002
	MAX_CONNECTION_DURATION_REACHED        ErrorID = 4003
	FRAGMENT_TIMECODE_LESSER_THAN_PREVIOUS ErrorID = 4004
	MORE_THAN_ALLOWED_TRACKS_FOUND         ErrorID = 4005
	INVALID_MKV_DATA                       ErrorID = 4006
	INVALID_PRODUCER_TIMESTAMP             ErrorID = 4007
	STREAM_NOT_ACTIVE                      ErrorID = 4008
	FRAGMENT_METADATA_LIMIT_REACHED        ErrorID = 4009
	TRACK_NUMBER_MISMATCH                  ErrorID = 4010
	FRAMES_MISSING_FOR_TRACK               ErrorID = 4011
	KMS_KEY_ACCESS_DENIED                  ErrorID = 4500
	KMS_KEY_DISABLED                       ErrorID = 4501
	KMS_KEY_VALIDATION_ERROR               ErrorID = 4502
	KMS_KEY_UNAVAILABLE                    ErrorID = 4503
	KMS_KEY_INVALID_USAGE                  ErrorID = 4504
	KMS_KEY_INVALID_STATE                  ErrorID = 4505
	KMS_KEY_NOT_FOUND                      ErrorID = 4506
	INTERNAL_ERROR                         ErrorID = 5000
	ARCHIVAL_ERROR                         ErrorID = 5001
)

type Fragment

type Fragment []*BlockWithMetadata

type FragmentEvent

type FragmentEvent struct {
	EventType        FragmentEventType
	FragmentTimecode uint64
	FragmentNumber   string // 158-bit number, handle as string
	ErrorId          ErrorID
	ErrorCode        string
	// contains filtered or unexported fields
}

FragmentEvent represents Acknowledgement object of PutMedia API. See https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/API_dataplane_PutMedia.html for details.

func (*FragmentEvent) AsError added in v1.0.0

func (e *FragmentEvent) AsError() error

func (*FragmentEvent) Dump added in v0.7.0

func (e *FragmentEvent) Dump() []byte

func (*FragmentEvent) IsError added in v0.5.4

func (e *FragmentEvent) IsError() bool

type FragmentEventError added in v1.0.0

type FragmentEventError struct {
	FragmentEvent
}

func (FragmentEventError) Error added in v1.0.0

func (e FragmentEventError) Error() string

type FragmentEventType added in v1.0.0

type FragmentEventType string

FragmentEventType represents AckEventType enum of PutMedia API. See https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/API_dataplane_PutMedia.html for details.

const (
	FRAGMENT_EVENT_BUFFERING FragmentEventType = "BUFFERING"
	FRAGMENT_EVENT_RECEIVED  FragmentEventType = "RECEIVED"
	FRAGMENT_EVENT_PERSISTED FragmentEventType = "PERSISTED"
	FRAGMENT_EVENT_ERROR     FragmentEventType = "ERROR"
	FRAGMENT_EVENT_IDLE      FragmentEventType = "IDLE"
)

type FragmentMetadata

type FragmentMetadata struct {
	FragmentNumber    string
	ProducerTimestamp time.Time
	ServerTimestamp   time.Time
	Tags              map[string]SimpleTag
}

type FragmentTimecodeType

type FragmentTimecodeType string
const (
	FragmentTimecodeTypeAbsolute FragmentTimecodeType = "ABSOLUTE"
	FragmentTimecodeTypeRelative FragmentTimecodeType = "RELATIVE"
)

type GetMediaBody

type GetMediaBody struct {
	StartSelector StartSelector
	StreamARN     *string `json:",omitempty"`
	StreamName    *string `json:",omitempty"`
}

type GetMediaOption

type GetMediaOption func(*GetMediaOptions)

func WithGetMediaBufferLen added in v1.0.0

func WithGetMediaBufferLen(n int) GetMediaOption

func WithGetMediaTagBufferLen added in v1.0.0

func WithGetMediaTagBufferLen(n int) GetMediaOption

func WithStartSelectorContinuationToken

func WithStartSelectorContinuationToken(token string) GetMediaOption

func WithStartSelectorNow

func WithStartSelectorNow() GetMediaOption

func WithStartSelectorProducerTimestamp

func WithStartSelectorProducerTimestamp(timestamp time.Time) GetMediaOption

type GetMediaOptions

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

type Info

type Info struct {
	TimecodeScale   uint64
	SegmentUID      []byte
	SegmentFilename string
	Title           string
	MuxingApp       string
	WritingApp      string
}

type LoggerIF

type LoggerIF interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Warn(args ...interface{})
	Warnf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
}

func Logger

func Logger() LoggerIF

type Provider

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

func (*Provider) PutMedia

func (p *Provider) PutMedia(opts ...PutMediaOption) (BlockWriter, error)

PutMedia opens connection to Kinesis Video Stream to put media blocks. This function immediately returns BlockWriter. BlockWriter.ReadResponse() must be called until getting io.EOF as error, otherwise Write() call will be blocked after the buffer is filled.

type PutMediaOption

type PutMediaOption func(*PutMediaOptions)

func OnError

func OnError(onError func(error)) PutMediaOption

func OnPutMediaNewConn added in v1.1.0

func OnPutMediaNewConn(onNewConn func()) PutMediaOption

OnPutMediaNewConn registers a func that will be called before creating a new PutMedia API connection. Media stream processing is blocked until the func returns.

func OnPutMediaSwitchConn added in v1.1.0

func OnPutMediaSwitchConn(onSwitchConn func(timecode uint64)) PutMediaOption

OnPutMediaSwitchConn registers a func that will be called before switching a PutMedia API connection. Media stream processing is blocked until the func returns.

func WithConnectionTimeout

func WithConnectionTimeout(timeout time.Duration) PutMediaOption

func WithFragmentHeadDumpLen added in v0.7.0

func WithFragmentHeadDumpLen(n int) PutMediaOption

WithFragmentHeadDumpLen sets fragment data head dump length embedded to the FragmentEvent error message. Data dump is enabled only if PutMediaRetry is enabled. Set zero to disable.

func WithFragmentTimecodeType

func WithFragmentTimecodeType(fragmentTimecodeType FragmentTimecodeType) PutMediaOption

func WithHttpClient

func WithHttpClient(client http.Client) PutMediaOption

func WithProducerStartTimestamp

func WithProducerStartTimestamp(producerStartTimestamp time.Time) PutMediaOption

func WithPutMediaBufferLen added in v1.0.0

func WithPutMediaBufferLen(n int) PutMediaOption

func WithPutMediaLogger added in v0.8.0

func WithPutMediaLogger(logger LoggerIF) PutMediaOption

func WithPutMediaResponseBufferLen added in v1.0.0

func WithPutMediaResponseBufferLen(n int) PutMediaOption

func WithPutMediaRetry added in v0.5.0

func WithPutMediaRetry(count int, intervalBase time.Duration) PutMediaOption

func WithSegmentUID

func WithSegmentUID(segmentUID []byte) PutMediaOption

func WithTags

func WithTags(tags func() []SimpleTag) PutMediaOption

func WithTitle

func WithTitle(title string) PutMediaOption

type PutMediaOptions

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

type Segment

type Segment struct {
	Info    Info
	Tracks  Tracks
	Cluster Cluster `ebml:",size=unknown"`
	Tags    Tags
}

type SegmentWrite

type SegmentWrite struct {
	Info    Info
	Tracks  Tracks
	Cluster ClusterWrite `ebml:",size=unknown"`
	Tags    Tags
}

type SimpleTag

type SimpleTag struct {
	TagName   string
	TagString string `ebml:",omitempty"`
	TagBinary string `ebml:",omitempty"`
}

type StartSelector

type StartSelector struct {
	AfterFragmentNumber string `json:",omitempty"`
	ContinuationToken   string `json:",omitempty"`
	StartSelectorType   StartSelectorType
	StartTimestamp      int `json:",omitempty"`
}

type StartSelectorType

type StartSelectorType string
const (
	StartSelectorTypeNow               StartSelectorType = "NOW"
	StartSelectorTypeEarliest          StartSelectorType = "EARLIEST"
	StartSelectorTypeFragmentNumber    StartSelectorType = "FRAGMENT_NUMBER"
	StartSelectorTypeProducerTimestamp StartSelectorType = "PRODUCER_TIMESTAMP"
	StartSelectorTypeServerTimestamp   StartSelectorType = "SERVER_TIMESTAMP"
	StartSelectorTypeContinuationToken StartSelectorType = "CONTINUATION_TOKEN"
)

type StreamID

type StreamID interface {
	StreamARN() *string
	StreamName() *string
}

func StreamARN

func StreamARN(arn string) StreamID

func StreamName

func StreamName(name string) StreamID

type Tag

type Tag struct {
	SimpleTag []SimpleTag
}

type Tags

type Tags struct {
	Tag chan *Tag `ebml:",omitempty"`
}

type TrackEntry

type TrackEntry struct {
	Name        string
	TrackNumber uint64
	TrackUID    uint64
	CodecID     string
	CodecName   string
	TrackType   uint64
}

type Tracks

type Tracks struct {
	TrackEntry []TrackEntry
}

Directories

Path Synopsis
examples module

Jump to

Keyboard shortcuts

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