Skip to content

Commit

Permalink
fix: webrtc stream missing info if sdk stop then create new with same…
Browse files Browse the repository at this point in the history
… name (8xFF#100)
  • Loading branch information
giangndm authored Nov 29, 2023
1 parent c4d0cc2 commit f082bfa
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions transports/webrtc/src/transport/internal/track_info_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,37 @@ pub struct MsidInfo {
pub label: String,
pub kind: String,
pub name: String,
pub uuid: String,
}

#[derive(Default)]
pub struct TrackInfoQueue {
pushed_track: HashMap<String, ()>,
pushed_track: HashMap<String, String>,
audios: VecDeque<MsidInfo>,
videos: VecDeque<MsidInfo>,
}

impl TrackInfoQueue {
pub fn add(&mut self, _uuid: &str, label: &str, kind: &str, name: &str) {
if self.pushed_track.contains_key(name) {
return;
pub fn add(&mut self, uuid: &str, label: &str, kind: &str, name: &str) {
if let Some(old_uuid) = self.pushed_track.get(name) {
if old_uuid.eq(uuid) {
return;
}
}
self.pushed_track.insert(name.to_string(), ());
self.pushed_track.insert(name.to_string(), uuid.to_string());

match kind {
"audio" | "Audio" | "AUDIO" => self.audios.push_back(MsidInfo {
label: label.to_string(),
kind: kind.to_string(),
name: name.to_string(),
uuid: uuid.to_string(),
}),
"video" | "Video" | "VIDEO" => self.videos.push_back(MsidInfo {
label: label.to_string(),
kind: kind.to_string(),
name: name.to_string(),
uuid: uuid.to_string(),
}),
_ => {}
}
Expand Down Expand Up @@ -61,6 +66,7 @@ mod test {
label: "audio_label".to_string(),
kind: "audio".to_string(),
name: "audio_main".to_string(),
uuid: "audio_uuid".to_string(),
})
);
assert_eq!(
Expand All @@ -69,6 +75,7 @@ mod test {
label: "video_label".to_string(),
kind: "video".to_string(),
name: "video_main".to_string(),
uuid: "video_uuid".to_string(),
})
);
}
Expand All @@ -83,10 +90,37 @@ mod test {
label: "audio_label".to_string(),
kind: "audio".to_string(),
name: "name".to_string(),
uuid: "audio_uuid".to_string(),
})
);

queue.add("audio_uuid", "audio_label", "audio", "name");
assert_eq!(queue.pop(str0m::media::MediaKind::Audio), None);
}

#[test]
fn rewrite_new_uuid() {
let mut queue = super::TrackInfoQueue::default();
queue.add("audio_uuid1", "audio_label", "audio", "name");
assert_eq!(
queue.pop(str0m::media::MediaKind::Audio),
Some(MsidInfo {
label: "audio_label".to_string(),
kind: "audio".to_string(),
name: "name".to_string(),
uuid: "audio_uuid1".to_string(),
})
);

queue.add("audio_uuid2", "audio_label", "audio", "name");
assert_eq!(
queue.pop(str0m::media::MediaKind::Audio),
Some(MsidInfo {
label: "audio_label".to_string(),
kind: "audio".to_string(),
name: "name".to_string(),
uuid: "audio_uuid2".to_string(),
})
);
}
}

0 comments on commit f082bfa

Please sign in to comment.