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

WIP: audio mix-minus #126

Merged
merged 7 commits into from
Dec 22, 2023
Merged

WIP: audio mix-minus #126

merged 7 commits into from
Dec 22, 2023

Conversation

giangndm
Copy link
Contributor

This PR implements an audio mixer with a mix-minus mechanism. This allows for semi-mixed audio in large conference rooms without decoding and encoding audio codecs.

The main idea is to select the tracks with the highest audio levels and send them to the client. These tracks are automatically switched on the server side without any control from the client. Additionally, the client can adjust which source track they are interested in, which is very useful in open-workspace applications like Gather.town.

packages/audio-mixer/src/mixer.rs Fixed Show fixed Hide fixed
packages/audio-mixer/src/mixer.rs Fixed Show fixed Hide fixed
packages/audio-mixer/src/mixer.rs Fixed Show fixed Hide fixed
packages/audio-mixer/src/mixer.rs Fixed Show fixed Hide fixed
packages/audio-mixer/src/mixer.rs Fixed Show fixed Hide fixed
packages/audio-mixer/src/mixer.rs Fixed Show fixed Hide fixed
/// Implement lightweight audio mixer with mix-minus feature
/// We will select n highest audio-level tracks
pub struct AudioMixer<Pkt: Clone, Src: Debug + Clone + Eq + Hash> {
extractor: Box<dyn (Fn(&Pkt) -> Option<i8>) + Send + Sync>,

Check warning

Code scanning / clippy

very complex type used. Consider factoring parts into type definitions Warning

very complex type used. Consider factoring parts into type definitions
}

impl<Pkt: Clone, Src: Debug + Clone + Eq + Hash> AudioMixer<Pkt, Src> {
pub fn new(extractor: Box<dyn (Fn(&Pkt) -> Option<i8>) + Send + Sync>, config: AudioMixerConfig) -> Self {

Check warning

Code scanning / clippy

very complex type used. Consider factoring parts into type definitions Warning

very complex type used. Consider factoring parts into type definitions
packages/endpoint/src/middleware/mix_minus.rs Fixed Show fixed Hide fixed
Comment on lines +49 to +58
pub fn new(
transport: T,
mut cluster: C,
room: &str,
peer: &str,
sub_scope: EndpointSubscribeScope,
bitrate_type: BitrateLimiterType,
mix_minus_mode: MixMinusAudioMode,
mix_minus_size: usize,
) -> Self {

Check warning

Code scanning / clippy

this function has too many arguments (8/7) Warning

this function has too many arguments (8/7)
@giangndm giangndm mentioned this pull request Dec 22, 2023
33 tasks
Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 159 lines in your changes are missing coverage. Please review.

Comparison is base (8c46983) 47.21% compared to head (251321e) 50.34%.

Files Patch % Lines
packages/cluster/src/implement/endpoint.rs 0.00% 55 Missing ⚠️
packages/endpoint/src/middleware/mix_minus.rs 94.59% 26 Missing ⚠️
packages/endpoint/src/endpoint_wrap.rs 0.00% 20 Missing ⚠️
packages/audio-mixer/src/mixer.rs 96.28% 12 Missing ⚠️
servers/media-server/src/server/webrtc/session.rs 0.00% 9 Missing ⚠️
...vers/media-server/src/server/sip/sip_in_session.rs 0.00% 8 Missing ⚠️
...ers/media-server/src/server/sip/sip_out_session.rs 0.00% 8 Missing ⚠️
packages/endpoint/src/endpoint_pre.rs 0.00% 6 Missing ⚠️
servers/media-server/src/server/webrtc.rs 0.00% 5 Missing ⚠️
packages/cluster/src/define/mod.rs 76.92% 3 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #126      +/-   ##
==========================================
+ Coverage   47.21%   50.34%   +3.13%     
==========================================
  Files         131      134       +3     
  Lines       10604    11472     +868     
==========================================
+ Hits         5007     5776     +769     
- Misses       5597     5696      +99     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +165 to +172
if matches!(self.mode, MixMinusAudioMode::AllAudioStreams) && meta.kind.is_audio() {
if self.mixer.add_source(now_ms, ClusterTrackUuid::from_info(&self.room, peer, track)).is_some() {
self.outputs.push_back(MediaEndpointMiddlewareOutput::Cluster(ClusterEndpointOutgoingEvent::LocalTrackEvent(
self.virtual_track_id,
ClusterLocalTrackOutgoingEvent::Subscribe(peer.clone(), track.clone()),
)));
}
}

Check warning

Code scanning / clippy

this if statement can be collapsed Warning

this if statement can be collapsed
Comment on lines +176 to +183
if matches!(self.mode, MixMinusAudioMode::AllAudioStreams) {
if self.mixer.remove_source(now_ms, ClusterTrackUuid::from_info(&self.room, peer, track)).is_some() {
self.outputs.push_back(MediaEndpointMiddlewareOutput::Cluster(ClusterEndpointOutgoingEvent::LocalTrackEvent(
self.virtual_track_id,
ClusterLocalTrackOutgoingEvent::Unsubscribe(peer.clone(), track.clone()),
)));
}
}

Check warning

Code scanning / clippy

this if statement can be collapsed Warning

this if statement can be collapsed
max: value,
min: value,
if let Some(consumers) = self.track_sub_map.get(&track_id) {
for (_, consumer) in consumers {

Check warning

Code scanning / clippy

you seem to want to iterate on a map's values Warning

you seem to want to iterate on a map's values
max: bitrate as i64,
min: bitrate as i64,
if let Some(consumers) = self.track_sub_map.get(&track_id) {
for (_, consumer) in consumers {

Check warning

Code scanning / clippy

you seem to want to iterate on a map's values Warning

you seem to want to iterate on a map's values
packages/cluster/src/implement/endpoint.rs Fixed Show fixed Hide fixed
self.consumer_map.insert(consumer.uuid(), track_id);
self.track_sub_map.insert(track_id, consumer);
let entry = self.track_sub_map.entry(track_id).or_insert_with(Default::default);

Check warning

Code scanning / clippy

use of or_insert_with to construct default value Warning

use of or\_insert\_with to construct default value
@giangndm giangndm marked this pull request as ready for review December 22, 2023 15:06
@giangndm giangndm merged commit 09d5892 into 8xFF:master Dec 22, 2023
9 checks passed
@github-actions github-actions bot mentioned this pull request Dec 22, 2023
@giangndm giangndm deleted the feat-audio-mix-minus branch June 6, 2024 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant