pub struct MediaFrameRegistry { /* private fields */ }Expand description
MediaFrameRegistry - WebRTC native media track callback manager
§Architecture
MediaFrameRegistry works with WebRTC PeerConnection to receive native media:
WebRTC PeerConnection
└─ RTCTrackRemote (native RTP channel)
└─ on_track callback
└─ MediaFrameRegistry::dispatch()
└─ User callback (MediaSample, sender_id)§Key Points
- No protobuf: Uses WebRTC native sample data
- No DataChannel: Media goes through RTCTrackRemote (RTP)
- Zero serialization: Direct sample bytes from RTP packets
- Low latency: ~1-2ms from network to callback
§Typical Use Cases
- Real-time audio/video calls
- Screen sharing
- Audio/video recording
- Media transcoding
Implementations§
Source§impl MediaFrameRegistry
impl MediaFrameRegistry
pub fn new() -> Self
Sourcepub fn register(&self, track_id: String, callback: MediaTrackCallback)
pub fn register(&self, track_id: String, callback: MediaTrackCallback)
Register media track callback
§Arguments
track_id: Track identifier (must be globally unique)callback: Media sample handler callback
§Example
ⓘ
registry.register("video-track-1", Arc::new(|sample, sender| {
Box::pin(async move {
println!("Received {} bytes from {:?}", sample.data.len(), sender);
// Decode and render video frame...
Ok(())
})
}));Sourcepub fn unregister(&self, track_id: &str)
pub fn unregister(&self, track_id: &str)
Sourcepub async fn dispatch(
&self,
track_id: &str,
sample: MediaSample,
sender_id: ActrId,
)
pub async fn dispatch( &self, track_id: &str, sample: MediaSample, sender_id: ActrId, )
Dispatch media sample to callback (concurrent execution)
Called by WebRTC on_track handler when a media sample arrives.
§Arguments
track_id: Track identifiersample: Media sample from RTCTrackRemotesender_id: Sender ActrId
§Performance
- Direct callback invocation, no queueing overhead
- Latency: ~1-2μs dispatch time (excluding callback execution)
- Concurrent execution, doesn’t block other tracks
Sourcepub fn active_tracks(&self) -> usize
pub fn active_tracks(&self) -> usize
Get active track count
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MediaFrameRegistry
impl !RefUnwindSafe for MediaFrameRegistry
impl Send for MediaFrameRegistry
impl Sync for MediaFrameRegistry
impl Unpin for MediaFrameRegistry
impl !UnwindSafe for MediaFrameRegistry
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more