From c537f60123fff4019f007a3eb9a17a15df4f61ef Mon Sep 17 00:00:00 2001 From: haohuiming Date: Fri, 18 Oct 2024 20:17:12 +0800 Subject: [PATCH 1/2] rtsp udp remote address fix --- protocol/rtsp/src/session/server_session.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/protocol/rtsp/src/session/server_session.rs b/protocol/rtsp/src/session/server_session.rs index 19c7dad..c738390 100644 --- a/protocol/rtsp/src/session/server_session.rs +++ b/protocol/rtsp/src/session/server_session.rs @@ -48,6 +48,7 @@ use bytesio::bytesio::TcpIO; use std::collections::HashMap; use std::sync::Arc; +use std::net::SocketAddr; use tokio::sync::mpsc; use commonlib::auth::Auth; @@ -81,6 +82,7 @@ pub struct RtspServerSession { pub stream_identifier: Option, pub is_normal_exit: bool, + remote_addr: SocketAddr, } pub struct InterleavedBinaryData { @@ -125,6 +127,7 @@ impl RtspServerSession { // None // }; + let remote_addr = stream.peer_addr().unwrap_or(stream.local_addr().unwrap()); let net_io: Box = Box::new(TcpIO::new(stream)); let io = Arc::new(Mutex::new(net_io)); @@ -141,6 +144,7 @@ impl RtspServerSession { auth, stream_identifier: None, is_normal_exit: false, + remote_addr, } } @@ -159,7 +163,7 @@ impl RtspServerSession { if let Ok(data) = InterleavedBinaryData::new(&mut self.reader) { match data { Some(a) => { - if self.reader.len() < a.length as usize { + while self.reader.len() < a.length as usize { let data = self.io.lock().await.read().await?; self.reader.extend_from_slice(&data[..]); } @@ -428,7 +432,7 @@ impl RtspServerSession { (0, 0) }; - let address = rtsp_request.uri.host.clone(); + let address = self.remote_addr.ip().to_string(); if let Some(rtp_io) = UdpIO::new(address.clone(), rtp_port, 0).await { rtp_server_port = rtp_io.get_local_port(); From 3e31b595d43c6b1b5fba14413745414de6c78d49 Mon Sep 17 00:00:00 2001 From: haohuiming Date: Fri, 6 Dec 2024 17:27:43 +0800 Subject: [PATCH 2/2] ignore lint warning:non_local_definitions --- application/xiu/src/config/errors.rs | 1 + library/bytesio/src/bits_errors.rs | 1 + library/bytesio/src/bytes_errors.rs | 1 + library/bytesio/src/bytesio_errors.rs | 1 + library/codec/h264/src/errors.rs | 1 + library/common/src/errors.rs | 1 + library/container/flv/src/amf0/errors.rs | 1 + library/container/flv/src/errors.rs | 1 + library/container/mpegts/src/errors.rs | 1 + library/logger/src/errors.rs | 1 + library/streamhub/src/errors.rs | 1 + protocol/hls/src/errors.rs | 1 + protocol/httpflv/src/errors.rs | 1 + protocol/rtmp/src/cache/errors.rs | 1 + protocol/rtmp/src/chunk/errors.rs | 1 + protocol/rtmp/src/handshake/errors.rs | 1 + protocol/rtmp/src/messages/errors.rs | 1 + protocol/rtmp/src/netconnection/errors.rs | 1 + protocol/rtmp/src/netstream/errors.rs | 1 + protocol/rtmp/src/protocol_control_messages/errors.rs | 1 + protocol/rtmp/src/relay/errors.rs | 1 + protocol/rtmp/src/remuxer/errors.rs | 1 + protocol/rtmp/src/session/errors.rs | 1 + protocol/rtmp/src/user_control_messages/errors.rs | 1 + protocol/rtmp/src/utils/errors.rs | 1 + protocol/rtsp/src/relay/errors.rs | 1 + protocol/rtsp/src/rtp/errors.rs | 1 + protocol/rtsp/src/rtp/rtcp/errors.rs | 1 + protocol/rtsp/src/session/errors.rs | 1 + protocol/webrtc/src/errors.rs | 1 + protocol/webrtc/src/session/errors.rs | 1 + 31 files changed, 31 insertions(+) diff --git a/application/xiu/src/config/errors.rs b/application/xiu/src/config/errors.rs index baa6768..66d32b3 100644 --- a/application/xiu/src/config/errors.rs +++ b/application/xiu/src/config/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { failure::{Backtrace, Fail}, std::{fmt, io::Error}, diff --git a/library/bytesio/src/bits_errors.rs b/library/bytesio/src/bits_errors.rs index dbab804..a9100af 100644 --- a/library/bytesio/src/bits_errors.rs +++ b/library/bytesio/src/bits_errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use super::bytes_errors::BytesReadError; use super::bytes_errors::BytesWriteError; use failure::{Backtrace, Fail}; diff --git a/library/bytesio/src/bytes_errors.rs b/library/bytesio/src/bytes_errors.rs index e1c32e1..73662f4 100644 --- a/library/bytesio/src/bytes_errors.rs +++ b/library/bytesio/src/bytes_errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use super::bytesio_errors::BytesIOError; use std::io; // use tokio::time::Elapsed; diff --git a/library/bytesio/src/bytesio_errors.rs b/library/bytesio/src/bytesio_errors.rs index 73fe415..d812015 100644 --- a/library/bytesio/src/bytesio_errors.rs +++ b/library/bytesio/src/bytesio_errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use failure::{Backtrace, Fail}; use std::fmt; use std::io; diff --git a/library/codec/h264/src/errors.rs b/library/codec/h264/src/errors.rs index db35b19..0613f10 100644 --- a/library/codec/h264/src/errors.rs +++ b/library/codec/h264/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use bytesio::bits_errors::BitError; use failure::{Backtrace, Fail}; use std::fmt; diff --git a/library/common/src/errors.rs b/library/common/src/errors.rs index 2e385b2..ded4a2d 100644 --- a/library/common/src/errors.rs +++ b/library/common/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use failure::{Backtrace, Fail}; use std::fmt; diff --git a/library/container/flv/src/amf0/errors.rs b/library/container/flv/src/amf0/errors.rs index 6a4b090..4aaceec 100644 --- a/library/container/flv/src/amf0/errors.rs +++ b/library/container/flv/src/amf0/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { bytesio::bytes_errors::{BytesReadError, BytesWriteError}, failure::{Backtrace, Fail}, diff --git a/library/container/flv/src/errors.rs b/library/container/flv/src/errors.rs index df565f6..39754b1 100644 --- a/library/container/flv/src/errors.rs +++ b/library/container/flv/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { bytesio::bits_errors::BitError, bytesio::bytes_errors::{BytesReadError, BytesWriteError}, diff --git a/library/container/mpegts/src/errors.rs b/library/container/mpegts/src/errors.rs index 6602b8a..a041c3d 100644 --- a/library/container/mpegts/src/errors.rs +++ b/library/container/mpegts/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { bytesio::bytes_errors::{BytesReadError, BytesWriteError}, failure::{Backtrace, Fail}, diff --git a/library/logger/src/errors.rs b/library/logger/src/errors.rs index 9d259d9..c9d7f20 100644 --- a/library/logger/src/errors.rs +++ b/library/logger/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use failure::Fail; pub struct LogError { diff --git a/library/streamhub/src/errors.rs b/library/streamhub/src/errors.rs index f57b648..b5afabf 100644 --- a/library/streamhub/src/errors.rs +++ b/library/streamhub/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use bytesio::bytes_errors::BytesReadError; use bytesio::bytes_errors::BytesWriteError; use failure::Backtrace; diff --git a/protocol/hls/src/errors.rs b/protocol/hls/src/errors.rs index 6668556..5e296cd 100644 --- a/protocol/hls/src/errors.rs +++ b/protocol/hls/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { failure::{Backtrace, Fail}, std::fmt, diff --git a/protocol/httpflv/src/errors.rs b/protocol/httpflv/src/errors.rs index 704c6cb..966e537 100644 --- a/protocol/httpflv/src/errors.rs +++ b/protocol/httpflv/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use streamhub::errors::StreamHubError; use { diff --git a/protocol/rtmp/src/cache/errors.rs b/protocol/rtmp/src/cache/errors.rs index 387f2a9..b4bfba8 100644 --- a/protocol/rtmp/src/cache/errors.rs +++ b/protocol/rtmp/src/cache/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { crate::chunk::errors::PackError, bytesio::bytes_errors::BytesReadError, diff --git a/protocol/rtmp/src/chunk/errors.rs b/protocol/rtmp/src/chunk/errors.rs index e13decc..31ee772 100644 --- a/protocol/rtmp/src/chunk/errors.rs +++ b/protocol/rtmp/src/chunk/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { failure::{Backtrace, Fail}, bytesio::bytes_errors::{BytesReadError, BytesWriteError}, diff --git a/protocol/rtmp/src/handshake/errors.rs b/protocol/rtmp/src/handshake/errors.rs index dc53a26..ef2963b 100644 --- a/protocol/rtmp/src/handshake/errors.rs +++ b/protocol/rtmp/src/handshake/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { bytesio::bytes_errors::{BytesReadError, BytesWriteError}, failure::{Backtrace, Fail}, diff --git a/protocol/rtmp/src/messages/errors.rs b/protocol/rtmp/src/messages/errors.rs index 68bdc2d..f5c5c4c 100644 --- a/protocol/rtmp/src/messages/errors.rs +++ b/protocol/rtmp/src/messages/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { crate::{ protocol_control_messages::errors::ProtocolControlMessageReaderError, diff --git a/protocol/rtmp/src/netconnection/errors.rs b/protocol/rtmp/src/netconnection/errors.rs index bad50ef..a1b30d7 100644 --- a/protocol/rtmp/src/netconnection/errors.rs +++ b/protocol/rtmp/src/netconnection/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { crate::chunk::errors::PackError, failure::{Backtrace, Fail}, diff --git a/protocol/rtmp/src/netstream/errors.rs b/protocol/rtmp/src/netstream/errors.rs index 364b3e8..05e65f8 100644 --- a/protocol/rtmp/src/netstream/errors.rs +++ b/protocol/rtmp/src/netstream/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { crate::chunk::errors::PackError, failure::{Backtrace, Fail}, diff --git a/protocol/rtmp/src/protocol_control_messages/errors.rs b/protocol/rtmp/src/protocol_control_messages/errors.rs index df4f207..7af6505 100644 --- a/protocol/rtmp/src/protocol_control_messages/errors.rs +++ b/protocol/rtmp/src/protocol_control_messages/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { failure::{Backtrace, Fail}, bytesio::bytes_errors::{BytesReadError, BytesWriteError}, diff --git a/protocol/rtmp/src/relay/errors.rs b/protocol/rtmp/src/relay/errors.rs index a3a4496..dfd2c55 100644 --- a/protocol/rtmp/src/relay/errors.rs +++ b/protocol/rtmp/src/relay/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { failure::Fail, std::{fmt, io::Error}, diff --git a/protocol/rtmp/src/remuxer/errors.rs b/protocol/rtmp/src/remuxer/errors.rs index 675e37a..8c7f46a 100644 --- a/protocol/rtmp/src/remuxer/errors.rs +++ b/protocol/rtmp/src/remuxer/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { crate::{cache::errors::MetadataError, session::errors::SessionError}, bytesio::bytes_errors::{BytesReadError, BytesWriteError}, diff --git a/protocol/rtmp/src/session/errors.rs b/protocol/rtmp/src/session/errors.rs index 7ca306e..0b3240d 100644 --- a/protocol/rtmp/src/session/errors.rs +++ b/protocol/rtmp/src/session/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { crate::{ cache::errors::CacheError, diff --git a/protocol/rtmp/src/user_control_messages/errors.rs b/protocol/rtmp/src/user_control_messages/errors.rs index 6292e25..cffeba1 100644 --- a/protocol/rtmp/src/user_control_messages/errors.rs +++ b/protocol/rtmp/src/user_control_messages/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { bytesio::bytes_errors::{BytesReadError, BytesWriteError}, failure::{Backtrace, Fail}, diff --git a/protocol/rtmp/src/utils/errors.rs b/protocol/rtmp/src/utils/errors.rs index 766c095..f42e5d2 100644 --- a/protocol/rtmp/src/utils/errors.rs +++ b/protocol/rtmp/src/utils/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { failure::{Backtrace, Fail}, std::fmt, diff --git a/protocol/rtsp/src/relay/errors.rs b/protocol/rtsp/src/relay/errors.rs index 9606786..715031e 100644 --- a/protocol/rtsp/src/relay/errors.rs +++ b/protocol/rtsp/src/relay/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { failure::Fail, std::{fmt, io::Error}, diff --git a/protocol/rtsp/src/rtp/errors.rs b/protocol/rtsp/src/rtp/errors.rs index ed42b83..49b8863 100644 --- a/protocol/rtsp/src/rtp/errors.rs +++ b/protocol/rtsp/src/rtp/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { failure::{Backtrace, Fail}, std::fmt, diff --git a/protocol/rtsp/src/rtp/rtcp/errors.rs b/protocol/rtsp/src/rtp/rtcp/errors.rs index 9827253..4b3c783 100644 --- a/protocol/rtsp/src/rtp/rtcp/errors.rs +++ b/protocol/rtsp/src/rtp/rtcp/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use bytesio::bytes_errors::BytesReadError; use bytesio::bytes_errors::BytesWriteError; use failure::Fail; diff --git a/protocol/rtsp/src/session/errors.rs b/protocol/rtsp/src/session/errors.rs index d359e6e..9d2680f 100644 --- a/protocol/rtsp/src/session/errors.rs +++ b/protocol/rtsp/src/session/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { crate::rtp::errors::{PackerError, UnPackerError}, bytesio::bytes_errors::BytesReadError, diff --git a/protocol/webrtc/src/errors.rs b/protocol/webrtc/src/errors.rs index 4185c2a..7d29ffb 100644 --- a/protocol/webrtc/src/errors.rs +++ b/protocol/webrtc/src/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use { audiopus::error::Error as OpusError, failure::{Backtrace, Fail}, diff --git a/protocol/webrtc/src/session/errors.rs b/protocol/webrtc/src/session/errors.rs index 280b4f1..cb75560 100644 --- a/protocol/webrtc/src/session/errors.rs +++ b/protocol/webrtc/src/session/errors.rs @@ -1,3 +1,4 @@ +#![allow(non_local_definitions)] use streamhub::errors::StreamHubError; use { bytesio::bytes_errors::BytesReadError,