Conversation
a-wing
left a comment
There was a problem hiding this comment.
I don't understand why don't use rtsp-types and sdp-types
tools/whipinto/src/rtspclient.rs
Outdated
| method: &str, | ||
| response: String, | ||
| ) -> Result<String> { | ||
| if response.contains("401 Unauthorized") { |
There was a problem hiding this comment.
The 401 shouldn't use response.contains("401 Unauthorized")
Should use RTSP StatusCode, Because different rtsp server response body is different
https://docs.rs/rtsp-types/latest/rtsp_types/struct.Response.html#method.status
tools/whipinto/src/rtspclient.rs
Outdated
| if response.contains("401 Unauthorized") { | ||
| let auth_line = response | ||
| .lines() | ||
| .find(|line| line.starts_with("WWW-Authenticate")) |
There was a problem hiding this comment.
tools/whipinto/src/rtspclient.rs
Outdated
| async fn send_options(&mut self) -> Result<()> { | ||
| let options_request = format!("OPTIONS {} RTSP/1.0", self.rtsp_url); | ||
| self.send_request(&format!( | ||
| "{}\r\nCSeq: {}\r\nUser-Agent: {}\r\n\r\n", |
There was a problem hiding this comment.
tools/whipinto/src/rtspclient.rs
Outdated
| } | ||
|
|
||
| async fn send_describe(&mut self) -> Result<String> { | ||
| let describe_request = format!("DESCRIBE {} RTSP/1.0", self.rtsp_url); |
There was a problem hiding this comment.
tools/whipinto/src/rtspclient.rs
Outdated
| async fn send_play(&mut self, session_id: &str) -> Result<String> { | ||
| let play_request = format!("PLAY {} RTSP/1.0", self.rtsp_url); | ||
| let play_request = format!( | ||
| "{}\r\nCSeq: {}\r\nSession: {}\r\nRange: npt=0.000-\r\nAuthorization: Digest username=\"{}\", realm=\"{}\", nonce=\"{}\", uri=\"{}\", response=\"{}\"\r\nUser-Agent: {}\r\n\r\n", |
There was a problem hiding this comment.
tools/whipinto/src/rtspclient.rs
Outdated
| let mut video_codec = None; | ||
|
|
||
| for line in sdp.lines() { | ||
| if line.starts_with("m=video") { |
There was a problem hiding this comment.
| return Err(anyhow!("No tracks found in SDP")); | ||
| } | ||
|
|
||
| let rtp_port = pick_unused_port().ok_or_else(|| anyhow!("No available port found"))?; |
There was a problem hiding this comment.
I suggest first bind port, and after return port
Look like, port is 0 is range allocation port.
let listener = tokio::net::TcpListener::bind("0.0.0.0:0")
.await
.unwrap();
// get binding address and port
listener.local_addr()
For example: If pick_unused_port pick port = 12345, There have a application is this computer use 12345, This application just start.
Concurrent the port maybe conflict, Although this possibility is low
BTW: It's a little problem
pick_unused_port range port is 15000..25000
let port = rng.gen_range(15000..25000);https://github.com/Dentosal/portpicker-rs/blob/master/src/lib.rs#L57
tools/whipinto/src/rtspclient.rs
Outdated
| } | ||
|
|
||
| async fn send_setup(&mut self, rtp_port: u16, rtcp_port: u16) -> Result<String> { | ||
| let setup_request = format!("SETUP {}/trackID=1 RTSP/1.0", self.rtsp_url); |
There was a problem hiding this comment.
If my SDP content:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=
c=IN IP4 0.0.0.0
t=0 0
m=video 0 RTP/AVP 96
a=control:rtsp://localhost:8554/mystream/trackID=0
a=rtpmap:96 VP8/90000
m=audio 0 RTP/AVP 111
a=control:rtsp://localhost:8554/mystream/trackID=1
a=rtpmap:111 opus/48000/2
a=fmtp:111 sprop-stereo=0
The url should from sdp
a-wing
left a comment
There was a problem hiding this comment.
In file top, add this:
use rtsp_types::{headers, headers::transport, Message, Method, Request, Response, StatusCode};and rtsp-typs support header: https://docs.rs/rtsp-types/latest/rtsp_types/headers/index.html
tools/whipinto/src/rtspclient.rs
Outdated
| // Send OPTIONS request | ||
| let options_request = Request::builder(Method::Options, Version::V1_0) | ||
| .header( | ||
| HeaderName::from_static_str("CSeq").unwrap(), |
There was a problem hiding this comment.
.header(rtsp_types::headers::CSEQ, cseq.to_string())
tools/whipinto/src/rtspclient.rs
Outdated
| cseq.to_string(), | ||
| ) | ||
| .header( | ||
| HeaderName::from_static_str("User-Agent").unwrap(), |
There was a problem hiding this comment.
.header(rtsp_types::headers::USER_AGENT, USER_AGENT)
tools/whipinto/src/rtspclient.rs
Outdated
| USER_AGENT, | ||
| ) | ||
| .header( | ||
| HeaderName::from_static_str("Authorization").unwrap(), |
There was a problem hiding this comment.
.header(rtsp_types::headers::AUTHORIZATION, auth_header_value)
tools/whipinto/src/rtspclient.rs
Outdated
| return Err(anyhow!("No tracks found in SDP")); | ||
| } | ||
|
|
||
| let listener = TcpListener::bind("0.0.0.0:0").await?; |
There was a problem hiding this comment.
This listener only pick port and unless and closed
tools/whipinto/src/rtspclient.rs
Outdated
| ) | ||
| .header( | ||
| HeaderName::from_static_str("Transport").unwrap(), | ||
| format!("RTP/AVP;unicast;client_port={}-{}", rtp_port, rtcp_port), |
There was a problem hiding this comment.
tools/whipinto/src/rtspclient.rs
Outdated
| time::{self, Duration}, | ||
| }; | ||
| use tracing::info; | ||
| use url::Url; |
There was a problem hiding this comment.
* add feat whipinto rtsp * add feat whepfrom rtsp * fix rtsp error * fix rtsp stream pushing issue * Add sdp message support (#146) * Add sdp message support * Add sdp message support * fix clippy warnings * fix clippy warning * add whipinto rtp 'pkt_size'>1200 on h264 (#151) * Add sdp message support * Add sdp message support * fix clippy warnings * fix clippy warning * add whipinto rtp 'pkt_size'>1200 on h264 * add whipinto rtp 'pkt_size'>1200 on h264 * style: reformat code * add whipinto/whepfrom rtcp support (#182) * Add sdp message support * Add sdp message support * fix clippy warnings * fix clippy warning * add whipinto rtp 'pkt_size'>1200 on h264 * add whipinto rtp 'pkt_size'>1200 on h264 * style: reformat code * add whipinto/whepfrom rtcp support * style: format code using cargo fmt * feat(liveman): add file route/stream * cargo fmt * add whipinto rtsp client (#205) * add whipinto rtsp client * cargo clippy * add whipinto rtsp client * refactor RTSP session setup * fix(whipinto): fix rtsp server target * breeak change(whipinto): change cmd cli flags * fix(whipinto): rtsp auth * fix(whipinto): listener host address * Refactor credentials from RTSP URL * Format code with cargo fmt * refactor:enhanced server compatibility * Refactor RTSP session handling * update(docs): whipinto rtp input sdp file support #140 --------- Co-authored-by: Marsyew <yew0024@163.com>
No description provided.