videocall_codecs/messages.rs
1/*
2 * Copyright 2025 Security Union LLC
3 *
4 * Licensed under either of
5 *
6 * * Apache License, Version 2.0
7 * (http://www.apache.org/licenses/LICENSE-2.0)
8 * * MIT license
9 * (http://opensource.org/licenses/MIT)
10 *
11 * at your option.
12 *
13 * Unless you explicitly state otherwise, any contribution intentionally
14 * submitted for inclusion in the work by you, as defined in the Apache-2.0
15 * license, shall be dual licensed as above, without any additional terms or
16 * conditions.
17 */
18
19//! Shared message types for worker communication
20
21use crate::frame::FrameBuffer;
22use serde::{Deserialize, Serialize};
23
24/// Messages that can be sent to the web worker
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub enum WorkerMessage {
27 /// Decode a frame
28 DecodeFrame(FrameBuffer),
29 /// Flush the decoder buffer and reset state
30 Flush,
31 /// Reset decoder to initial state (waiting for keyframe)
32 Reset,
33 /// Set diagnostic context so worker can tag events with original IDs
34 SetContext { from_peer: String, to_peer: String },
35}
36
37/// Video statistics message sent by the worker
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct VideoStatsMessage {
40 pub kind: String,
41 pub from_peer: Option<String>,
42 pub to_peer: Option<String>,
43 pub frames_buffered: Option<u64>,
44}
45
46impl VideoStatsMessage {
47 pub fn new(from_peer: String, to_peer: String, frames_buffered: u64) -> Self {
48 Self {
49 kind: "video_stats".to_string(),
50 from_peer: Some(from_peer),
51 to_peer: Some(to_peer),
52 frames_buffered: Some(frames_buffered),
53 }
54 }
55}