Package dash (v1.32.9) [up] [repository]

Index

Functions

func FormatRange(start, end uint64) string
func ParseRange(input string) (uint64, uint64, error)
func SortByBandwidth(reps []*Representation)

SortByBandwidth sorts a slice of Representations in-place by their Bandwidth in ascending order (lowest to highest). This function requires Go 1.21+.

Types

type AdaptationSet

AdaptationSet groups Representations.

type AdaptationSet struct {
	Codecs            string               `xml:"codecs,attr"`
	ContentProtection []*ContentProtection `xml:"ContentProtection"`
	Height            int                  `xml:"height,attr"`
	Label             string               `xml:"Label"`
	Lang              string               `xml:"lang,attr"`
	MimeType          string               `xml:"mimeType,attr"`
	Representations   []*Representation    `xml:"Representation"`
	Role              *Role                `xml:"Role"`
	SegmentTemplate   *SegmentTemplate     `xml:"SegmentTemplate"`
	Width             int                  `xml:"width,attr"`
	// Navigation
	Parent *Period `xml:"-"`
}

type ContentProtection

ContentProtection specifies DRM schemes.

type ContentProtection struct {
	SchemeIdUri string `xml:"schemeIdUri,attr"`
	// DefaultKid maps to cenc:default_KID (urn:mpeg:cenc:2013)
	DefaultKid string `xml:"urn:mpeg:cenc:2013 default_KID,attr"`
	// Pssh maps to the cenc:pssh element (urn:mpeg:cenc:2013)
	Pssh string `xml:"urn:mpeg:cenc:2013 pssh"`
}

Methods

func (cp *ContentProtection) GetDefaultKid() ([]byte, error)

GetDefaultKid returns the DefaultKid as a byte slice.

func (cp *ContentProtection) GetPssh() ([]byte, error)

GetPssh returns the PSSH data as a byte slice.

type Initialization

Initialization contains URL and byte range information for initialization segments.

type Initialization struct {
	// Used in SegmentBase
	Range string `xml:"range,attr"`
	// Used in SegmentList
	SourceUrl string `xml:"sourceURL,attr"`
	// Navigation
	Parent *SegmentList `xml:"-"`
}

Methods

func (i *Initialization) ResolveSourceUrl() (*url.URL, error)

ResolveSourceUrl resolves the @sourceURL attribute against the parent SegmentList's context.

type Mpd

Mpd represents the root element of the DASH MPD file.

type Mpd struct {
	MediaPresentationDuration string    `xml:"mediaPresentationDuration,attr"`
	BaseUrl                   string    `xml:"BaseURL"`
	Periods                   []*Period `xml:"Period"`
	MpdUrl                    *url.URL  `xml:"-"`
}

Functions

func Parse(data []byte) (*Mpd, error)

Parse takes a byte slice of an MPD file, unmarshals it, links navigation parents, and normalizes Representation IDs.

Methods

func (m *Mpd) GetRepresentations() map[string][]*Representation

GetRepresentations returns a map of all Representations keyed by their Id.

func (m *Mpd) ResolveBaseUrl() (*url.URL, error)

ResolveBaseUrl resolves the MPD's BaseURL against the MpdUrl.

type Period

Period represents a temporal part of the media content.

type Period struct {
	Duration       string           `xml:"duration,attr"`
	Id             string           `xml:"id,attr"`
	BaseUrl        string           `xml:"BaseURL"`
	AdaptationSets []*AdaptationSet `xml:"AdaptationSet"`
	// Navigation
	Parent *Mpd `xml:"-"`
}

Methods

func (p *Period) GetDuration() (time.Duration, error)

GetDuration parses the ISO 8601 Duration attribute.

func (p *Period) ResolveBaseUrl() (*url.URL, error)

ResolveBaseUrl resolves the Period's BaseURL against the parent Mpd's resolved BaseUrl.

type Representation

Representation describes a version of the media content.

type Representation struct {
	Bandwidth         int                  `xml:"bandwidth,attr"`
	Codecs            string               `xml:"codecs,attr"`
	Height            int                  `xml:"height,attr"`
	Id                string               `xml:"id,attr"`
	MimeType          string               `xml:"mimeType,attr"`
	Width             int                  `xml:"width,attr"`
	BaseUrl           string               `xml:"BaseURL"`
	SegmentTemplate   *SegmentTemplate     `xml:"SegmentTemplate"`
	ContentProtection []*ContentProtection `xml:"ContentProtection"`
	SegmentBase       *SegmentBase         `xml:"SegmentBase"`
	SegmentList       *SegmentList         `xml:"SegmentList"`
	Parent            *AdaptationSet       `xml:"-"`
}

Methods

func (r *Representation) GetCodecs() string
func (r *Representation) GetContentProtection() []*ContentProtection
func (r *Representation) GetHeight() int
func (r *Representation) GetLabel() string
func (r *Representation) GetLang() string
func (r *Representation) GetMimeType() string
func (r *Representation) GetPeriodId() string
func (r *Representation) GetRole() string
func (r *Representation) GetSegmentTemplate() *SegmentTemplate
func (r *Representation) GetWidth() int
func (r *Representation) ResolveBaseUrl() (*url.URL, error)

ResolveBaseUrl resolves the Representation's BaseURL against the parent hierarchy.

func (r *Representation) String() string

String returns a multi-line summary of the Representation.

type Role

Role defines the role of the media content.

type Role struct {
	Value string `xml:"value,attr"`
}

type S

S represents a segment within the timeline.

type S struct {
	D uint `xml:"d,attr"` // Duration
	R int  `xml:"r,attr"` // Repeat count
}

type SegmentBase

SegmentBase defines base information for segments.

type SegmentBase struct {
	IndexRange     string          `xml:"indexRange,attr"`
	Initialization *Initialization `xml:"Initialization"`
}

type SegmentList

SegmentList contains a list of SegmentUrls.

type SegmentList struct {
	Duration       uint            `xml:"duration,attr"`
	Timescale      *uint           `xml:"timescale,attr"`
	Initialization *Initialization `xml:"Initialization"`
	SegmentUrls    []*SegmentUrl   `xml:"SegmentURL"`
	// Navigation
	Parent *Representation `xml:"-"`
}

Methods

func (sl *SegmentList) GetTimescale() uint

type SegmentTemplate

SegmentTemplate defines specific rules for generating segment URLs.

type SegmentTemplate struct {
	Duration               uint             `xml:"duration,attr"`
	EndNumber              uint             `xml:"endNumber,attr"`
	Initialization         string           `xml:"initialization,attr"`
	Media                  string           `xml:"media,attr"`
	PresentationTimeOffset uint             `xml:"presentationTimeOffset,attr"`
	StartNumber            *uint            `xml:"startNumber,attr"`
	Timescale              *uint            `xml:"timescale,attr"`
	SegmentTimeline        *SegmentTimeline `xml:"SegmentTimeline"`
	// Navigation
	ParentAdaptationSet  *AdaptationSet  `xml:"-"`
	ParentRepresentation *Representation `xml:"-"`
}

Methods

func (st *SegmentTemplate) GetDurationBasedNumbers() ([]uint, error)
func (st *SegmentTemplate) GetNumberRange() []uint
func (st *SegmentTemplate) GetSegmentUrls(rep *Representation) ([]*url.URL, error)
func (st *SegmentTemplate) GetStartNumber() uint
func (st *SegmentTemplate) GetTimelineNumbers() []uint
func (st *SegmentTemplate) GetTimelineTimes() []uint
func (st *SegmentTemplate) GetTimescale() uint
func (st *SegmentTemplate) ResolveInitialization(rep *Representation) (*url.URL, error)
func (st *SegmentTemplate) ResolveMedia(rep *Representation, number int) (*url.URL, error)
func (st *SegmentTemplate) ResolveMediaTime(rep *Representation, timeVal int) (*url.URL, error)

type SegmentTimeline

SegmentTimeline defines specific timing for segments.

type SegmentTimeline struct {
	S []*S `xml:"S"`
}

type SegmentUrl

SegmentUrl defines a specific media segment source.

type SegmentUrl struct {
	Media string `xml:"media,attr"`
	// Navigation
	Parent *SegmentList `xml:"-"`
}

Methods

func (su *SegmentUrl) ResolveMedia() (*url.URL, error)

ResolveMedia resolves the @media attribute against the parent SegmentList's context.