Track, Group, and Frame
Media streams are organized into a hierarchy of tracks, groups, and frames.
- Track: A continuous media stream, such as video or audio, within a broadcast path.
- Group: A self-contained segment of a track, often corresponding to a time-based unit like a video GOP or an audio packet group.
- Frame: The smallest unit of media data, such as a single video image or audio sample.
Track
Each track has a name that distinguishes it within the broadcast path, often corresponding to a specific media layer (e.g., SVC).
moqt.TrackWriter
The moqt.TrackWriter handles all aspects of writing data to a track, including managing the lifecycle of the track, opening and closing groups, transmitting media data, and dealing with errors.
type TrackWriter struct {
BroadcastPath BroadcastPath
TrackName TrackName
// contains filtered or unexported fields
}
func (*TrackWriter) Close() error
func (*TrackWriter) CloseWithError(SubscribeErrorCode)
func (*TrackWriter) OpenGroup(GroupSequence) (*GroupWriter, error)
func (TrackWriter) SubscribeID() SubscribeID // through internal stream
func (*TrackWriter) TrackConfig() *TrackConfig // through internal stream
func (TrackWriter) Updated() <-chan struct{} // through internal stream
func (*TrackWriter) WriteInfo(Info) error // through internal stream
func (TrackWriter) Context() context.Context // through internal streammoqt.TrackReader
The moqt.TrackReader is responsible for reading data from a track, receiving groups and frames in order, and managing any errors that occur during the process.
type TrackReader struct {
BroadcastPath BroadcastPath
TrackName TrackName
// contains filtered or unexported fields
}
func (*TrackReader) AcceptGroup(context.Context) (*GroupReader, error)
func (*TrackReader) Close() error
func (*TrackReader) CloseWithError(SubscribeErrorCode) error
func (*TrackReader) Update(*TrackConfig) error // through internal stream
func (*TrackReader) TrackConfig() *TrackConfig // through internal stream
func (TrackReader) SubscribeID() SubscribeID // through internal stream
func (TrackReader) Context() context.Context // through internal streamGroup
Groups are processed and transmitted independently, and may contain frames that are either standalone or interdependent (for example, I/P/B frames in video).
moqt.GroupWriter
The GroupWriter writes frames, can set deadlines, cancel or close groups, and exposes the group’s sequence.
type GroupWriter struct {
// contains filtered or unexported fields
}
func (*GroupWriter) GroupSequence() GroupSequence
func (*GroupWriter) WriteFrame(*Frame) error
func (*GroupWriter) SetWriteDeadline(time.Time) error
func (*GroupWriter) CancelWrite(GroupErrorCode)
func (*GroupWriter) Close() error
func (*GroupWriter) Context() context.Contextmoqt.GroupReader
The GroupReader reads frames sequentially, can cancel reads, and provides group sequencing and deadline control.
type GroupReader struct {
// contains filtered or unexported fields
}
func (*GroupReader) GroupSequence() GroupSequence
func (*GroupReader) ReadFrame(*Frame) error
func (*GroupReader) CancelRead(GroupErrorCode)
func (*GroupReader) SetReadDeadline(time.Time) error
func (*GroupReader) Frames(*Frame) iter.Seq[*Frame]Frame
Frames can be independent (like keyframes) or rely on other frames (like delta frames in video), and together they form the building blocks of a track.
moqt.Frame
The Frame struct represents the smallest unit of media data. It ensures that data is stored immutably.
type Frame struct {
// contains filtered or unexported fields
}
func NewFrame(int) *Frame
func (*Frame) Body() []byte
func (*Frame) Cap() int
func (*Frame) Len() int
func (*Frame) Reset()
func (*Frame) Clone() *Frame
func (*Frame) Write([]byte) (int, error)
func (*Frame) WriteTo(w io.Writer) (int64, error)