Skip to content

Commit

Permalink
Use location header from offer for delete
Browse files Browse the repository at this point in the history
  • Loading branch information
kc5nra committed Dec 15, 2022
1 parent ca0a724 commit 19710d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
19 changes: 6 additions & 13 deletions plugins/obs-webrtc/webrtc/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ use webrtc::rtp_transceiver::RTCRtpTransceiverInit;
use webrtc::stats::StatsReportType;
use webrtc::track::track_local::track_local_static_sample::TrackLocalStaticSample;

struct WHIPResource {
url: String,
}

pub struct OutputStream {
video_track: Arc<TrackLocalStaticSample>,
audio_track: Arc<TrackLocalStaticSample>,
peer_connection: Arc<RTCPeerConnection>,
done_tx: Sender<()>,
bytes_sent: Arc<Mutex<u64>>,
stats_future: Arc<Mutex<Option<JoinHandle<()>>>>,
whip_resource: Arc<Mutex<Option<WHIPResource>>>,
whip_resource: Arc<Mutex<Option<String>>>,
}

impl OutputStream {
Expand Down Expand Up @@ -162,11 +158,11 @@ impl OutputStream {
.await
.ok_or_else(|| anyhow!("No local description available"))?;
let answer = whip::offer(url, bearer_token, offer).await?;
self.peer_connection.set_remote_description(answer).await?;
self.peer_connection
.set_remote_description(answer.0)
.await?;

*self.whip_resource.lock().unwrap() = Some(WHIPResource {
url: String::from(""), // todo
});
*self.whip_resource.lock().unwrap() = answer.1;

Ok(())
}
Expand All @@ -183,10 +179,7 @@ impl OutputStream {

let whip_resource = self.whip_resource.lock().unwrap().take();
if let Some(whip_resource) = whip_resource {
whip::delete(
&whip_resource.url.clone(),
)
.await?;
whip::delete(&whip_resource).await?;
}
Ok(self.peer_connection.close().await?)
}
Expand Down
13 changes: 10 additions & 3 deletions plugins/obs-webrtc/webrtc/src/whip.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use anyhow::Result;
use log::{debug, warn};
use reqwest::header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE};
use reqwest::header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE, LOCATION};
use webrtc::peer_connection::sdp::session_description::RTCSessionDescription;

pub async fn offer(
url: &str,
bearer_token: &str,
local_desc: RTCSessionDescription,
) -> Result<RTCSessionDescription> {
) -> Result<(RTCSessionDescription, Option<String>)> {
let client = reqwest::Client::new();

let mut headers = reqwest::header::HeaderMap::new();
Expand All @@ -27,9 +27,16 @@ pub async fn offer(
.send()
.await?;

let whip_resource = res
.headers()
.get(LOCATION)
.map(|v| v.to_str().map(|v| v.to_owned()).ok())
.flatten();

let body = res.text().await?;
let sdp = RTCSessionDescription::answer(body)?;
Ok(sdp)

Ok((sdp, whip_resource))
}

pub async fn delete(url: &str) -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions plugins/obs-webrtc/whip-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static void whip_service_apply_encoder_settings(void *data,
obs_data_t *video_settings,
obs_data_t *audio_settings)
{
UNUSED_PARAMETER(data);
UNUSED_PARAMETER(audio_settings);

// For now, ensure maximum compatibility with webrtc peers
Expand Down

0 comments on commit 19710d1

Please sign in to comment.