moqt.TrackReader, which provides access to groups and frames as they are received. This is typically done by the subscriber or receiver.
moqt.TrackReader is created when calling Session.Subscribe method.
Overview
Overview
Subscribe to a Track
By subscribing to a track, amoqt.TrackReader is created, allowing the receiver to read media data from the track.
Subscribe to a Track
Accept a Group
To receive the next available group from a track, useTrackReader.AcceptGroup method. This returns a moqt.GroupReader for reading frames from the group.
Note: Closing a Group Reader
moqt.GroupReader has no Close method. A group ends on its own when ReadFrame returns io.EOF.
Call GroupReader.CancelRead only when you want to stop reading before the end of the group.Read Frames
To read frames from a group, useGroupReader.ReadFrame method. Each call decodes the next frame in the group into the internal moqt.Frame object. The frame is reused for each call. To cache the frame data, you have to clone it via Frame.Clone before reading the next frame.
Iterate Frames
Instead of a loop withReadFrame, you can use GroupReader.Frames to get a lazy iterator. Reuse a buffer to minimize allocations; the iterator populates it on each yield.
Clone Frame
To clone a frame, useFrame.Clone method. This creates a deep copy of the frame, including its data, allowing you to retain the frame data even after reading the next frame.
Copy and Cache Frame Data
To copy the frame data into a provided buffer, useFrame.WriteTo method, implementing the io.WriterTo interface. It is useful for efficiently caching the frame data.
Cancel Group Reading
To cancel a group and stop receiving frames, callGroupReader.CancelRead method with an error code.
- Group Error Code: The group error code is used to indicate the reason for canceling the group reading. It helps the sender understand why the group was canceled.
Unsubscribe from a Track
To unsubscribe from a track and stop receiving any further groups or frames with no errors, callTrackReader.Close method.
TrackReader.CloseWithError method with an error code.
- Subscribe Error Code: The subscribe error code is used to indicate the reason for closing the track subscription. It helps the subscriber understand why the subscription was terminated.
moqt.SubscribeCanceledErrorCode when the track is closed. This ensures that all resources are released properly and no unexpected behavior occurs.