Skip to content

Commit

Permalink
chore: update 'Receive video frames of a subscribed track' docs (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
cs50victor authored Nov 11, 2023
1 parent 147eff5 commit 30e4ca3
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,29 @@ async fn main() -> Result<()> {
### Receive video frames of a subscribed track

```rust
...
use futures::StreamExt; // this trait is required for iterating on audio & video frames
use livekit::prelude::*;

match event {
RoomEvent::TrackSubscribed { track, publication, participant } => {
if let RemoteTrackHandle::Video(video_track) => {
let rtc_track = video_track.rtc_track();
rtc_track.on_frame(Box::new(move |frame, buffer| {
// Just received a video frame!
// The buffer is YuvEncoded, you can decode it to ABGR by using our yuv_helper
// See the basic_room example for the conversion
});
} else {
// Audio Track..
match track {
RemoteTrack::Audio(audio_track) => {
let audio_rtc_track = audio_track.rtc_track();
let audio_stream = NativeAudioStream::new(audio_rtc_track);
while let Some(audio) = audio_stream.next().await {
info!("audio buffer info - {audio:#?}");
}
},
RemoteTrack::Video(video_track) => {
let video_rtc_track = video_track.rtc_track();
let video_stream = NativeVideoStream::new(video_rtc_track);
while let Some(video_frame) = video_stream.next().await {
info!("video frame info - {video_frame:#?}");
}
},
}
}
},
_ => {}
}
```
Expand Down

0 comments on commit 30e4ca3

Please sign in to comment.