Encoded frames say whether they are keyframes; StreamSink gets the layer methods

Viewers switch simulcast layers on a keyframe of the new layer, so the
stream sessions need to know which frames are keyframes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
Claude committed 2026-09-26 23:15:42 +00:00
1 parent d6bc1920f6
commit 3aba9a165d
4 files changed
+42 -2

No files matched your search

+16 -1
View File
@@ -165,6 +165,14 @@ impl MediaSink for StreamSink {
fn take_keyframe_request(&self) -> bool {
StreamSink::take_keyframe_request(self)
}
fn take_layer_keyframes(&self, layers: &mut LayerSet) {
StreamSink::take_layer_keyframes(self, layers);
}
fn layer_bitrate(&self, layer: LayerId) -> Option<u64> {
StreamSink::layer_bitrate(self, layer)
}
}
/// Which backend captures monitors and windows.
@@ -458,6 +466,7 @@ fn video_loop(
time: MediaTime::from_90khz(f.pts_90khz),
data: f.data.into(),
layer: 0,
keyframe: f.keyframe,
};
if sink.send(frame) {
shared.video_frames.fetch_add(1, Ordering::Relaxed);
@@ -522,7 +531,13 @@ fn audio_loop(shared: &Shared, mut buffers: FrameReceiver<AudioBuffer>, mut enco
pending.drain(..OPUS_FRAME * 2);
if let Some(data) = data {
let time = MediaTime::new(frames * OPUS_FRAME as u64, Frequency::FORTY_EIGHT_KHZ);
if sink.send(EncodedFrame { kind: MediaKind::Audio, time, data, layer: 0 }) {
if sink.send(EncodedFrame {
kind: MediaKind::Audio,
time,
data,
layer: 0,
keyframe: false,
}) {
shared.audio_frames.fetch_add(1, Ordering::Relaxed);
}
}
+14
View File
@@ -79,6 +79,20 @@ impl StreamSink {
self.keyframe.swap(false, Ordering::Relaxed)
}
/// Adds to `layers` the simulcast layers viewers asked a keyframe for
/// since the last call.
pub fn take_layer_keyframes(&self, layers: &mut voelin_stream::LayerSet) {
if self.take_keyframe_request() {
layers.insert(0);
}
}
/// Bitrate (bit/s) the bandwidth estimates of `layer`'s viewers allow.
pub fn layer_bitrate(&self, layer: voelin_stream::LayerId) -> Option<u64> {
let _ = layer;
None
}
pub fn is_live(&self) -> bool {
self.live.load(Ordering::Relaxed)
}
+1
View File
@@ -225,6 +225,7 @@ async fn ts6_stream_between_sessions() {
time: voelin_core::stream::MediaTime::from_90khz(0),
data: vec![0].into(),
layer: 0,
keyframe: false,
}));
feeder.await.unwrap();
+11 -1
View File
@@ -21,6 +21,9 @@ pub struct EncodedFrame {
/// The simulcast layer of a video frame (0 without simulcast, and for
/// audio).
pub layer: LayerId,
/// A video keyframe: viewers can start decoding (or switch to this layer)
/// here.
pub keyframe: bool,
}
/// Produces encoded frames in real time.
@@ -106,6 +109,7 @@ impl FrameSource for SyntheticSource {
time: MediaTime::from_90khz(n * 90_000 / u64::from(self.fps)),
data: Self::video_frame(n, self.video_size).into(),
layer: 0,
keyframe: true,
});
self.video_frames += 1;
}
@@ -115,7 +119,13 @@ impl FrameSource for SyntheticSource {
let time =
MediaTime::new(self.audio_frames * OPUS_FRAME, Frequency::FORTY_EIGHT_KHZ);
let data = Arc::from(&OPUS_SILENCE[..]);
out.push(EncodedFrame { kind: MediaKind::Audio, time, data, layer: 0 });
out.push(EncodedFrame {
kind: MediaKind::Audio,
time,
data,
layer: 0,
keyframe: false,
});
self.audio_frames += 1;
}
}