Skip to content

add whipinto rtsp client#205

Merged
a-wing merged 4 commits intobinbat:feat/rtspfrom
Marsyew:feat/rtsp
Jul 15, 2024
Merged

add whipinto rtsp client#205
a-wing merged 4 commits intobinbat:feat/rtspfrom
Marsyew:feat/rtsp

Conversation

@Marsyew
Copy link
Copy Markdown
Contributor

@Marsyew Marsyew commented Jul 13, 2024

No description provided.

Copy link
Copy Markdown
Member

@a-wing a-wing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why don't use rtsp-types and sdp-types

method: &str,
response: String,
) -> Result<String> {
if response.contains("401 Unauthorized") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

if response.contains("401 Unauthorized") {
let auth_line = response
.lines()
.find(|line| line.starts_with("WWW-Authenticate"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

async fn send_describe(&mut self) -> Result<String> {
let describe_request = format!("DESCRIBE {} RTSP/1.0", self.rtsp_url);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let mut video_codec = None;

for line in sdp.lines() {
if line.starts_with("m=video") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Err(anyhow!("No tracks found in SDP"));
}

let rtp_port = pick_unused_port().ok_or_else(|| anyhow!("No available port found"))?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

}

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

@a-wing a-wing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

// Send OPTIONS request
let options_request = Request::builder(Method::Options, Version::V1_0)
.header(
HeaderName::from_static_str("CSeq").unwrap(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.header(rtsp_types::headers::CSEQ, cseq.to_string())

cseq.to_string(),
)
.header(
HeaderName::from_static_str("User-Agent").unwrap(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.header(rtsp_types::headers::USER_AGENT, USER_AGENT)

USER_AGENT,
)
.header(
HeaderName::from_static_str("Authorization").unwrap(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.header(rtsp_types::headers::AUTHORIZATION, auth_header_value)

return Err(anyhow!("No tracks found in SDP"));
}

let listener = TcpListener::bind("0.0.0.0:0").await?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This listener only pick port and unless and closed

)
.header(
HeaderName::from_static_str("Transport").unwrap(),
format!("RTP/AVP;unicast;client_port={}-{}", rtp_port, rtcp_port),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time::{self, Duration},
};
use tracing::info;
use url::Url;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-wing a-wing added this to the 0.6.0 milestone Jul 15, 2024
@a-wing a-wing added enhancement New feature or request mod::whipinto whipinto labels Jul 15, 2024
@a-wing a-wing merged commit c735031 into binbat:feat/rtsp Jul 15, 2024
a-wing added a commit that referenced this pull request Jul 24, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request mod::whipinto whipinto

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants