Skip to content

Commit

Permalink
fix: md count send
Browse files Browse the repository at this point in the history
  • Loading branch information
hongcha98 committed Oct 10, 2023
1 parent 9f01efa commit 612d36e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/forward/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io::Cursor;
use std::sync::Arc;

use crate::forward::forward_internal::{get_peer_key, PeerForwardInternal};
use anyhow::Result;
use log::info;
use tokio::sync::Mutex;
Expand All @@ -12,6 +11,10 @@ use webrtc::peer_connection::sdp::session_description::RTCSessionDescription;
use webrtc::peer_connection::RTCPeerConnection;
use webrtc::rtp_transceiver::rtp_codec::RTPCodecType;
use webrtc::sdp::{MediaDescription, SessionDescription};

use crate::forward::forward_internal::{get_peer_key, PeerForwardInternal};
use crate::media;

mod forward_internal;
mod track_match;

Expand Down Expand Up @@ -191,19 +194,7 @@ fn parse_ice_candidate(content: String) -> Result<Vec<RTCIceCandidateInit>> {

fn get_media_descriptions(sd: SessionDescription, publish: bool) -> Result<Vec<MediaDescription>> {
let mut media_descriptions = sd.media_descriptions;
media_descriptions.retain(|media_description| {
let mut is_publish = false;
for attribute in &media_description.attributes {
match attribute.key.as_str() {
"sendonly" | "simulcast:send" => {
is_publish = true;
break;
}
_ => {}
}
}
publish == is_publish
});
media_descriptions.retain(|md| publish == (media::count_send(md) > 0));
let mut video = false;
let mut audio = false;
for md in &media_descriptions {
Expand Down
23 changes: 23 additions & 0 deletions src/media/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,26 @@ pub fn codecs_from_media_description(

Ok(out)
}

pub fn count_send(md: &MediaDescription) -> usize {
let mut count = 0;
let mut minus = 0;
for attribute in &md.attributes {
match attribute.key.as_str() {
"sendonly" => {
count += 1;
minus += 1;
}
"simulcast" => {
let val = attribute.value.clone().unwrap_or("".to_string());
if !val.starts_with("send ") {
break;
}
count += val.replace("send ", "").split(";").count() - minus;
break;
}
_ => {}
}
}
count
}

0 comments on commit 612d36e

Please sign in to comment.