Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong usage of smallmap cause server crash. switched to indexmap #457

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 154 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ convert-enum = "0.1"
clap = "4.5"
num_enum = "0.7"
log = "0.4"
smallmap = "1.4"
serde = "1.0"
derivative = "2.2"
derive_more = "1.0"
Expand Down
1 change: 1 addition & 0 deletions packages/audio_mixer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2021"

[dependencies]
log.workspace = true
indexmap.workspace = true
7 changes: 4 additions & 3 deletions packages/audio_mixer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{
collections::HashMap,
fmt::Debug,
hash::Hash,
time::{Duration, Instant},
};

use indexmap::IndexMap;

const SILENT_LEVEL: i8 = -127;
const SWITCH_AUDIO_THRESHOLD: i16 = 30;
/// if no audio pkt received in AUDIO_SLOT_TIMEOUT, set audio level to SILENT_LEVEL
Expand All @@ -28,7 +29,7 @@ struct OutputSlotState<Src> {
#[derive(Debug)]
pub struct AudioMixer<Src> {
len: usize,
sources: HashMap<Src, SourceState>,
sources: IndexMap<Src, SourceState>,
outputs: Vec<Option<OutputSlotState<Src>>>,
}

Expand All @@ -38,7 +39,7 @@ impl<Src: Debug + Clone + Eq + Hash> AudioMixer<Src> {

Self {
len: 0,
sources: HashMap::new(),
sources: Default::default(),
outputs: vec![None; output],
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/media_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
log = { workspace = true }
num_enum = { workspace = true }
smallmap = { workspace = true }
indexmap = { workspace = true }
derivative = { workspace = true }
derive_more = { workspace = true, features = ["full"] }
mockall = { workspace = true }
Expand All @@ -17,7 +17,6 @@ atm0s-sdn = { workspace = true }
media-server-protocol = { path = "../protocol" }
media-server-utils = { path = "../media_utils" }
audio-mixer = { path = "../audio_mixer" }
indexmap = { workspace = true }

[dev-dependencies]
tracing-subscriber = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions packages/media_core/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//!

use derive_more::{AsRef, Display, From};
use indexmap::IndexMap;
use sans_io_runtime::{return_if_none, TaskGroup, TaskGroupOutput, TaskSwitcherChild};
use std::{
collections::HashMap,
fmt::Debug,
hash::{Hash, Hasher},
time::Instant,
Expand Down Expand Up @@ -131,15 +131,15 @@ pub enum Output<Endpoint> {
}

pub struct MediaCluster<Endpoint: Debug + Copy + Clone + Hash + Eq> {
rooms_map: HashMap<ClusterRoomHash, usize>,
rooms_map: IndexMap<ClusterRoomHash, usize>,
rooms: TaskGroup<room::Input<Endpoint>, room::Output<Endpoint>, ClusterRoom<Endpoint>, 16>,
shutdown: bool,
}

impl<Endpoint: Debug + Copy + Hash + Eq + Clone> Default for MediaCluster<Endpoint> {
fn default() -> Self {
Self {
rooms_map: HashMap::new(),
rooms_map: IndexMap::new(),
rooms: TaskGroup::default(),
shutdown: false,
}
Expand Down Expand Up @@ -197,7 +197,7 @@ impl<Endpoint: Debug + Hash + Copy + Clone + Debug + Eq> TaskSwitcherChild<Outpu
room::Output::Endpoint(endpoints, event) => Some(Output::Endpoint(endpoints, event)),
room::Output::OnResourceEmpty(room) => {
log::info!("[MediaCluster] remove room index {index}, hash {room}");
self.rooms_map.remove(&room).expect("Should have room with index");
self.rooms_map.swap_remove(&room).expect("Should have room with index");
self.rooms.remove_task(index);
Some(Output::Continue)
}
Expand Down
Loading
Loading