Documentation
¶
Index ¶
- Constants
- func CalcLOCGroupRange(track *ContentTrack, groupNr uint64, constantDurMS uint32) (startNr, endNr uint64)
- func CheckVersion(printVersion bool)
- func CurrMoQGroupNr(track *ContentTrack, nowMS uint64, constantDurMS uint32) uint64
- func CurrSubtitleGroupNr(nowMS uint64, groupDurMS uint32) uint64
- func DecryptFragment(payload []byte, decryptInfo mp4.DecryptInfo, key mp4.UUID) ([]byte, error)
- func DecryptInit(initData []byte) ([]byte, mp4.UUID, mp4.DecryptInfo, error)
- func GetVersion() string
- func PrintVersion()
- func Ptr[T any](v T) *T
- func WriteMoQGroup(ctx context.Context, track *ContentTrack, moq *MoQGroup, cb ObjectWriter) error
- type AACData
- type AC3Data
- type AVCData
- type Asset
- func LoadAsset(dirPath string, audioSampleBatch, videoSampleBatch int) (*Asset, error)
- func LoadAssetWithDRM(dirPath string, audioSampleBatch, videoSampleBatch int, drm *DRMInfo) (*Asset, error)
- func LoadAssetWithProtection(dirPath string, audioSampleBatch, videoSampleBatch int, drm, eccp *DRMInfo) (*Asset, error)
- func (a *Asset) AddSubtitleTracks(wvttLangs, stppLangs []string) error
- func (a *Asset) GenCMAFCatalogEntry(namespace string, prot ProtectionType, generatedAtMS int64) (*Catalog, error)
- func (a *Asset) GenLOCCatalogEntry(generatedAtMS int64) (*Catalog, error)
- func (a *Asset) GetSubtitleTrackByName(name string) *SubtitleTrack
- func (a *Asset) GetTrackByName(name string) *ContentTrack
- type CENCInfo
- type Catalog
- type CodecSpecificData
- type ContentProtection
- type ContentTrack
- type DRMInfo
- type DRMService
- type DRMSystem
- type HEVCData
- type MoQGroup
- type MoQObject
- type ObjectWriter
- type OpusData
- type ProtectionType
- type StppTimeCue
- type StppTimeData
- type SubtitleData
- type SubtitleFormat
- type SubtitleTrack
- type Track
- type TrackGroup
Constants ¶
const ( SubsTimeTimescale = 1000 // 1ms resolution DefaultCueDurMS = 900 // Cue duration in ms )
Subtitle constants
const CommonSystemID = "1077efec-c0b2-4d02-ace3-3c1e52e2fb4b" //https://www.w3.org/TR/eme-initdata-cenc/#clear-key
const (
MoqGroupDurMS = 1000
)
Variables ¶
This section is empty.
Functions ¶
func CalcLOCGroupRange ¶ added in v0.8.0
func CalcLOCGroupRange(track *ContentTrack, groupNr uint64, constantDurMS uint32) (startNr, endNr uint64)
CalcLOCGroupRange returns the [startNr, endNr) sample range for the LOC-packaged group with the given group number, for a track whose groups have an average duration of constantDurMS milliseconds.
func CurrMoQGroupNr ¶ added in v0.2.0
func CurrMoQGroupNr(track *ContentTrack, nowMS uint64, constantDurMS uint32) uint64
CurrMoQGroupNr returns the current MoQGroup number/ID for a given time.
func CurrSubtitleGroupNr ¶ added in v0.5.0
CurrSubtitleGroupNr returns the current MoQ group number for subtitle tracks
func DecryptFragment ¶ added in v0.6.0
DecryptFragment decrypts an enocoded fragment (moof+mdat) and returns the unencrypted encoding.
func DecryptInit ¶ added in v0.6.0
DecryptInit decrypts an encoded init segment and returns the decrypted encoding, the KID and decryption decryption information..
func GetVersion ¶
func GetVersion() string
GetVersion - get version, commitHash and commitDate depending on what is inserted
func WriteMoQGroup ¶ added in v0.2.0
func WriteMoQGroup(ctx context.Context, track *ContentTrack, moq *MoQGroup, cb ObjectWriter) error
WriteMoQGroup write all MoQGroup objects to a MoQWriter. The MoQGroup is sent in the correct time order and at appropriate times if ongoing session. If the context is done, the function returns the error from the context.
Types ¶
type AACData ¶ added in v0.2.0
type AACData struct {
// contains filtered or unexported fields
}
func (*AACData) ChannelConfig ¶ added in v0.8.0
ChannelConfig returns the AAC channel configuration string (decimal integer).
func (*AACData) Clone ¶ added in v0.6.0
func (d *AACData) Clone() (CodecSpecificData, error)
func (*AACData) GenCMAFInitData ¶ added in v0.2.0
GenCMAFInitData returns a base64 encoded CMAF initialization segment.
func (*AACData) GetInit ¶ added in v0.6.0
func (d *AACData) GetInit() *mp4.InitSegment
GetInit returns the output init segment.
func (*AACData) SampleRate ¶ added in v0.8.0
SampleRate returns the AAC sample rate in Hz.
type AC3Data ¶ added in v0.5.0
type AC3Data struct {
// contains filtered or unexported fields
}
func (*AC3Data) Clone ¶ added in v0.6.0
func (d *AC3Data) Clone() (CodecSpecificData, error)
func (*AC3Data) GenCMAFInitData ¶ added in v0.5.0
GenCMAFInitData returns a base64 encoded CMAF initialization segment.
func (*AC3Data) GetInit ¶ added in v0.6.0
func (d *AC3Data) GetInit() *mp4.InitSegment
GetInit returns the output init segment.
type AVCData ¶ added in v0.2.0
func (*AVCData) Clone ¶ added in v0.6.0
func (d *AVCData) Clone() (CodecSpecificData, error)
func (*AVCData) GenAVCDecoderConfigurationRecord ¶ added in v0.8.0
GenAVCDecoderConfigurationRecord returns the encoded AVCDecoderConfigurationRecord (ISO/IEC 14496-15 §5.3.3.1) for this track's SPS/PPS. This is the payload for the moqmi Video H264 AVCC Extradata extension header (0x0D).
func (*AVCData) GenCMAFInitData ¶ added in v0.2.0
GenCMAFInitData returns a base64 encoded CMAF initialization segment.
func (*AVCData) GenLOCVideoConfig ¶ added in v0.8.0
GenLOCVideoConfig returns SPS and PPS NALUs as length-prefixed data suitable for prepending to IDR frames in LOC payloads. Format: [4-byte-len][SPS] [4-byte-len][PPS]
func (*AVCData) GetInit ¶ added in v0.6.0
func (d *AVCData) GetInit() *mp4.InitSegment
GetInit returns the output init segment.
type Asset ¶ added in v0.2.0
type Asset struct {
Name string
Groups []TrackGroup
LoopDurMS uint32
SubtitleTracks []*SubtitleTrack
Drm *DRMInfo
Eccp *DRMInfo
}
func LoadAsset ¶ added in v0.2.0
LoadAsset opens a directory, reads all *.mp4 files, creates ContentTrack from each, groups them by contentType, and returns a pointer to an Asset.
func LoadAssetWithDRM ¶ added in v0.6.0
func LoadAssetWithDRM(dirPath string, audioSampleBatch, videoSampleBatch int, drm *DRMInfo) (*Asset, error)
LoadAssetWithDRM creates an asset with a single DRM config (backward compatibility).
func LoadAssetWithProtection ¶ added in v0.6.1
func LoadAssetWithProtection(dirPath string, audioSampleBatch, videoSampleBatch int, drm, eccp *DRMInfo) (*Asset, error)
LoadAssetWithProtection creates an asset from the *.mp4 files in the specified dirPath. If drm is not nil, protected tracks with "_drm" suffix are created (commercial DRM via CPIX). If eccp is not nil, protected tracks with "_eccp" suffix are created (ClearKey/ECCP). Both can be provided simultaneously to create two independent sets of encrypted tracks.
func (*Asset) AddSubtitleTracks ¶ added in v0.5.0
AddSubtitleTracks adds WVTT and STPP subtitle tracks for the given languages. wvttLangs and stppLangs are lists of language codes (e.g., "en", "sv"). Track names are formatted as "subs_wvtt_{lang}" and "subs_stpp_{lang}".
func (*Asset) GenCMAFCatalogEntry ¶ added in v0.2.0
func (a *Asset) GenCMAFCatalogEntry(namespace string, prot ProtectionType, generatedAtMS int64) (*Catalog, error)
GenCMAFCatalogEntry generates an MSF/CMSF catalog entry for this asset, populating all available fields. Conforms to draft-ietf-moq-msf-00 and draft-ietf-moq-cmsf-00, except for the extra contentProtection field.
The namespace parameter sets the Track.Namespace field in each catalog track entry. The prot parameter selects which tracks to include: ProtectionNone for clear tracks, ProtectionDRM for commercial DRM tracks, ProtectionECCP for ClearKey/ECCP tracks. Subtitle tracks are always included regardless of the filter. The generatedAtMS parameter is the wallclock time in milliseconds since the Unix epoch to be set as the catalog's generatedAt value.
func (*Asset) GenLOCCatalogEntry ¶ added in v0.8.0
GenLOCCatalogEntry generates an MSF catalog with LOC packaging for this asset. Conforms to draft-ietf-moq-msf-00 with packaging="loc" per draft-ietf-moq-loc-02.
Only AVC/HEVC video and AAC/Opus audio tracks with ProtectionNone are included. No initData is set (LOC sends video config in-band with keyframes). AVC tracks use "avc3" and HEVC tracks use "hev1" codec prefixes since parameter sets travel in the payload (draft-ietf-moq-loc-02 §2.1.1).
func (*Asset) GetSubtitleTrackByName ¶ added in v0.5.0
func (a *Asset) GetSubtitleTrackByName(name string) *SubtitleTrack
GetSubtitleTrackByName returns a pointer to a SubtitleTrack with the given name, or nil if not found.
func (*Asset) GetTrackByName ¶ added in v0.2.0
func (a *Asset) GetTrackByName(name string) *ContentTrack
GetTrackByName returns a pointer to a ContentTrack with the given name, or nil if not found.
type CENCInfo ¶ added in v0.6.0
type CENCInfo struct {
// contains filtered or unexported fields
}
CENCInfo contains information unique to CENC and is not signaled in the catalog
type Catalog ¶ added in v0.2.0
type Catalog struct {
// Version specifies the version of MSF referenced by this catalog.
// Required field at the root level.
Version int `json:"version"`
// GeneratedAt is the wallclock time at which this catalog was generated,
// expressed as milliseconds since the Unix epoch.
// Optional field at the root level. Should be present when tracks are live.
GeneratedAt *int64 `json:"generatedAt,omitempty"`
// IsComplete signals that a previously live broadcast is complete.
// All tracks are complete, no new tracks will be added.
// Optional field at the root level. Must not be included if false.
IsComplete bool `json:"isComplete,omitempty"`
// DeltaUpdate indicates that this catalog object represents a delta (or partial) update.
// Optional field at the root level.
DeltaUpdate bool `json:"deltaUpdate,omitempty"`
// AddTracks indicates a delta processing instruction to add new tracks.
// Optional field at the root level, only used in delta updates.
AddTracks []Track `json:"addTracks,omitempty"`
// RemoveTracks indicates a delta processing instruction to remove tracks.
// Optional field at the root level, only used in delta updates.
RemoveTracks []Track `json:"removeTracks,omitempty"`
// CloneTracks indicates a delta processing instruction to clone new tracks from previously declared tracks.
// Optional field at the root level, only used in delta updates.
CloneTracks []Track `json:"cloneTracks,omitempty"`
// Tracks is an array of track objects.
// Required field at the root level for non-delta updates.
Tracks []Track `json:"tracks,omitempty"`
// ContentProtections contains content protection information.
// No content protection is information is repeated at the track level,
// all tracks must refer to this common field.
// Optional field at the root level, only used if content is protected.
ContentProtections []ContentProtection `json:"contentProtections,omitempty"`
}
Catalog represents the MSF JSON catalog as defined in draft-ietf-moq-msf-00 (MOQT Streaming Format) and draft-ietf-moq-cmsf-00 (CMAF MOQT Streaming Format). It provides information about the tracks being produced by an MSF publisher.
func (*Catalog) GetTrackByName ¶ added in v0.2.0
type CodecSpecificData ¶ added in v0.2.0
type CodecSpecificData interface {
GenCMAFInitData() ([]byte, error)
Codec() string
GetInit() *mp4.InitSegment
Clone() (CodecSpecificData, error)
}
type ContentProtection ¶ added in v0.6.0
type ContentProtection struct {
RefID string `json:"refID,omitempty"`
DefaultKIDs []string `json:"defaultKID,omitempty"`
Scheme string `json:"scheme,omitempty"`
DRMSystem *DRMSystem `json:"drmSystem,omitempty"`
}
ContentProtection contains all information needed to create DRM request
type ContentTrack ¶ added in v0.2.0
type ContentTrack struct {
Name string
ContentType string
Language string
SampleBitrate uint32
TimeScale uint32
Duration uint32
GopLength uint32
SampleDur uint32
NrSamples uint32
LoopDur uint32 // Loop duration in local timescale
SampleBatch int
Samples []mp4.FullSample
SpecData CodecSpecificData
Protection ProtectionType
// contains filtered or unexported fields
}
func InitContentTrack ¶ added in v0.2.0
func InitContentTrack(r io.Reader, name string, audioSampleBatch, videoSampleBatch int) (*ContentTrack, error)
InitContentTrack initializes a ContentTrack from an io.Reader (expects a fragmented MP4). The name is stripped of any extension.
func (*ContentTrack) CalcSample ¶ added in v0.8.0
func (t *ContentTrack) CalcSample(nr uint64) (startTime, origNr uint64)
CalcSample calculates the start time and original sample number for a given output sample number.
func (*ContentTrack) GenCMAFChunk ¶ added in v0.3.0
func (t *ContentTrack) GenCMAFChunk(chunkNr uint32, startNr, endNr uint64) ([]byte, error)
GenCMAFChunk returns a raw CMAF chunk consisting of endNr-startNr samples. The number is 0-based relative to the UNIX epoch. Therefore nr is translated into data for the time interval [nr*d.sampleDur, (nr+1)*d.sampleDur]. This is calculated based on wrap-around given the loopDuration of the asset.
type DRMInfo ¶ added in v0.6.0
type DRMInfo struct {
ContentProtections []ContentProtection
// contains filtered or unexported fields
}
DRMInfo keeps track of all information regarding DRM
func ConfigureDRMFromFile ¶ added in v0.6.0
ConfigureDRMFromFile reads a DRM config file and returns a *DRMInfo struct. The config file must be of the same format as assets/testdrm/drm_config_test.json
func ParseCENCflags ¶ added in v0.6.0
ParseCENCflags converts the string CENC-related parameters into a ClearKey-compliant *DRMInfo struct. If all flags are empty (except scheme) nil is returned. The laURL parameter is the license acquisition URL announced in the catalog.
type DRMService ¶ added in v0.6.0
DRMService represents a license or authorization service.
type DRMSystem ¶ added in v0.6.0
type DRMSystem struct {
SystemID string `json:"systemID,omitempty"`
Robustness string `json:"robustness,omitempty"`
LaURL *DRMService `json:"laURL,omitempty"`
AuthzURL *DRMService `json:"authzURL,omitempty"`
CertURL *DRMService `json:"certURL,omitempty"`
Pssh string `json:"pssh,omitempty"`
}
DRMSystem represents information related to a DRM system
type HEVCData ¶ added in v0.5.0
type HEVCData struct {
Vpss [][]byte
Spss [][]byte
Ppss [][]byte
// contains filtered or unexported fields
}
func (*HEVCData) Clone ¶ added in v0.6.0
func (d *HEVCData) Clone() (CodecSpecificData, error)
func (*HEVCData) GenCMAFInitData ¶ added in v0.5.0
GenCMAFInitData returns the CMAF init segment.
func (*HEVCData) GenLOCVideoConfig ¶ added in v0.8.0
GenLOCVideoConfig returns VPS, SPS, and PPS NALUs as length-prefixed data suitable for prepending to IRAP frames in LOC payloads. Format: [4-byte-len][VPS] [4-byte-len][SPS] [4-byte-len][PPS]
func (*HEVCData) GetInit ¶ added in v0.6.0
func (d *HEVCData) GetInit() *mp4.InitSegment
GetInit returns the output init segment.
type MoQGroup ¶ added in v0.2.0
type MoQGroup struct {
MoQObjects []MoQObject
// contains filtered or unexported fields
}
func GenMoQGroup ¶ added in v0.2.0
func GenMoQGroup(track *ContentTrack, groupNr uint64, sampleBatch int, constantDurMS uint32) (*MoQGroup, error)
GenMoQGroup generates a MoQGroup for a given track and number. The MoQGroup is generated based on the track's sample duration and the constant (average) duration of all MoQGroups for this track.
func GenSubtitleGroup ¶ added in v0.5.0
func GenSubtitleGroup(st *SubtitleTrack, groupNr uint64, groupDurMS uint32) (*MoQGroup, error)
GenSubtitleGroup generates a MoQ group for subtitle content
type ObjectWriter ¶ added in v0.2.0
type OpusData ¶ added in v0.5.0
type OpusData struct {
// contains filtered or unexported fields
}
func (*OpusData) ChannelConfig ¶ added in v0.8.0
ChannelConfig returns the Opus channel configuration string (decimal integer).
func (*OpusData) Clone ¶ added in v0.6.0
func (d *OpusData) Clone() (CodecSpecificData, error)
func (*OpusData) GenCMAFInitData ¶ added in v0.5.0
GenCMAFInitData returns a CMAF initialization segment for Opus.
func (*OpusData) GetInit ¶ added in v0.6.0
func (d *OpusData) GetInit() *mp4.InitSegment
GetInit returns the output init segment.
func (*OpusData) SampleRate ¶ added in v0.8.0
SampleRate returns the Opus input sample rate in Hz.
type ProtectionType ¶ added in v0.6.1
type ProtectionType int
ProtectionType identifies how a track is encrypted.
const ( ProtectionNone ProtectionType = iota ProtectionDRM // Commercial DRM (Widevine/PlayReady/FairPlay via CPIX) ProtectionECCP // ClearKey / ECCP (explicit key over HTTP) )
type StppTimeCue ¶ added in v0.5.0
StppTimeCue is cue information to put in template
type StppTimeData ¶ added in v0.5.0
type StppTimeData struct {
Lang string
Region int
Cues []StppTimeCue
}
StppTimeData is information for creating an stpp media segment
type SubtitleData ¶ added in v0.5.0
type SubtitleData struct {
// contains filtered or unexported fields
}
SubtitleData implements CodecSpecificData interface for subtitles
func (*SubtitleData) Codec ¶ added in v0.5.0
func (d *SubtitleData) Codec() string
Codec returns the codec string for this subtitle format
func (*SubtitleData) GenCMAFInitData ¶ added in v0.5.0
func (d *SubtitleData) GenCMAFInitData() ([]byte, error)
GenCMAFInitData generates the CMAF init segment data for subtitles
type SubtitleFormat ¶ added in v0.5.0
type SubtitleFormat string
SubtitleFormat represents the subtitle format type
const ( SubtitleFormatWVTT SubtitleFormat = "wvtt" SubtitleFormatSTPP SubtitleFormat = "stpp" )
type SubtitleTrack ¶ added in v0.5.0
type SubtitleTrack struct {
Name string
Format SubtitleFormat
Language string
TimeScale uint32
CueDurMS int
Region int // 0=bottom, 1=top
SpecData *SubtitleData
}
SubtitleTrack represents a dynamically generated subtitle track
func NewSubtitleTrack ¶ added in v0.5.0
func NewSubtitleTrack(name string, format SubtitleFormat, lang string) (*SubtitleTrack, error)
NewSubtitleTrack creates a new subtitle track with the given parameters
type Track ¶ added in v0.2.0
type Track struct {
// Name defines the name of the track.
// Required field at the track level.
Name string `json:"name"`
// Namespace is the namespace under which the track name is defined.
// Optional field at the track level.
Namespace string `json:"namespace,omitempty"`
// Packaging defines the type of payload encapsulation.
// Required field at the track level. MSF values: "loc", "mediatimeline", "eventtimeline".
// CMSF adds: "cmaf".
Packaging string `json:"packaging"`
// IsLive indicates whether new objects will be added to the track.
// Required field at the track level (MSF Section 5.1.15).
IsLive bool `json:"isLive"`
// TargetLatency is the target latency in milliseconds.
// Optional field at the track level. Must not be included if IsLive is false.
TargetLatency *int `json:"targetLatency,omitempty"`
// Role defines the role of content carried by the track.
// Optional field at the track level. Reserved values include:
// "video", "audio", "subtitle", "caption", "audiodescription",
// "mediatimeline", "eventtimeline", "signlanguage".
Role string `json:"role,omitempty"`
// Label is a human-readable label for the track.
// Optional field at the track level.
Label string `json:"label,omitempty"`
// RenderGroup specifies a group of tracks which are designed to be rendered together.
// Optional field at the track level.
RenderGroup *int `json:"renderGroup,omitempty"`
// AltGroup specifies a group of tracks which are alternate versions of one-another.
// Optional field at the track level.
AltGroup *int `json:"altGroup,omitempty"`
// InitData holds Base64 encoded initialization data for the track.
// Optional field at the track level. Used for CMAF init segments.
InitData string `json:"initData,omitempty"`
// Dependencies holds an array of track names on which the current track is dependent.
// Optional field at the track level.
Dependencies []string `json:"depends,omitempty"`
// TemporalID identifies the temporal layer/sub-layer encoding of the track.
// Optional field at the track level.
TemporalID *int `json:"temporalId,omitempty"`
// SpatialID identifies the spatial layer encoding of the track.
// Optional field at the track level.
SpatialID *int `json:"spatialId,omitempty"`
// Codec defines the codec used to encode the track.
// Optional field at the track level.
Codec string `json:"codec,omitempty"`
// Framerate defines the video framerate of the track, expressed as frames per second.
// Optional field at the track level.
Framerate *float64 `json:"framerate,omitempty"`
// Timescale is the number of time units that pass per second.
// Optional field at the track level (MSF Section 5.1.27).
Timescale *int `json:"timescale,omitempty"`
// Bitrate defines the bitrate of track, expressed in bits per second.
// Optional field at the track level.
Bitrate *int `json:"bitrate,omitempty"`
// Width expresses the encoded width of the video frames in pixels.
// Optional field at the track level.
Width *int `json:"width,omitempty"`
// Height expresses the encoded height of the video frames in pixels.
// Optional field at the track level.
Height *int `json:"height,omitempty"`
// SampleRate is the number of audio frame samples per second.
// Optional field at the track level, should only accompany audio codecs.
SampleRate *int `json:"samplerate,omitempty"`
// ChannelConfig specifies the audio channel configuration.
// Optional field at the track level, should only accompany audio codecs.
ChannelConfig string `json:"channelConfig,omitempty"`
// DisplayWidth expresses the intended display width of the track content in pixels.
// Optional field at the track level.
DisplayWidth *int `json:"displayWidth,omitempty"`
// DisplayHeight expresses the intended display height of the track content in pixels.
// Optional field at the track level.
DisplayHeight *int `json:"displayHeight,omitempty"`
// Language defines the dominant language of the track.
// Optional field at the track level.
Language string `json:"lang,omitempty"`
// TrackDuration is the duration of the track in integer milliseconds.
// Optional field at the track level. Must not be included if IsLive is true.
TrackDuration *int `json:"trackDuration,omitempty"`
// EventType defines the type & structure of data in an event timeline track.
// Optional field at the track level. Required when packaging is "eventtimeline".
EventType string `json:"eventType,omitempty"`
// ParentName defines the parent track name to be cloned.
// This field is only included inside a CloneTracks object.
ParentName string `json:"parentName,omitempty"`
// ContentProtectionRefIDs defines which content protection information should be used for this track.
// The ID is used as a key in the root-level field ContentProtection.
// Optional field at the track level, only used when the track is protected.
ContentProtectionRefIDs []string `json:"contentProtectionRefIDs,omitempty"`
}
Track represents a track object in the MSF/CMSF catalog.
type TrackGroup ¶ added in v0.2.0
type TrackGroup struct {
AltGroupID uint32
Tracks []ContentTrack
}