Skip to content

Commit 65ced18

Browse files
pencil in SendingPacket and StreamDirection
1 parent aafb00f commit 65ced18

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

src/client/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use url::Url;
2424

2525
use crate::client::parse::SessionHeader;
2626
use crate::codec::CodecItem;
27+
use crate::rtp::SendingPacket;
2728
use crate::{
2829
Error, ErrorInt, RtspMessageContext, StreamContext, StreamContextInner, TcpStreamContext,
2930
UdpStreamContext,
@@ -687,6 +688,13 @@ impl std::ops::Deref for Tool {
687688
}
688689
}
689690

691+
//enum sending or Receiving
692+
#[derive(Copy, Clone, Debug)]
693+
pub enum StreamDirection{
694+
Receiving,
695+
Sending,
696+
}
697+
690698
/// Information about a stream offered within a presentation.
691699
///
692700
/// Currently if multiple formats are offered, this only describes the first.
@@ -702,6 +710,7 @@ pub struct Stream {
702710
channels: Option<NonZeroU16>,
703711
framerate: Option<f32>,
704712
control: Option<Url>,
713+
direction: StreamDirection
705714
}
706715

707716
impl std::fmt::Debug for Stream {
@@ -714,6 +723,7 @@ impl std::fmt::Debug for Stream {
714723
.field("clock_rate", &self.clock_rate_hz)
715724
.field("channels", &self.channels)
716725
.field("framerate", &self.framerate)
726+
.field("direction", &self.direction)
717727
.field("depacketizer", &self.depacketizer)
718728
.field("state", &self.state)
719729
.finish()
@@ -781,6 +791,10 @@ impl Stream {
781791
pub fn control(&self) -> Option<&Url> {
782792
self.control.as_ref()
783793
}
794+
795+
pub fn direction(&self) -> StreamDirection {
796+
self.direction
797+
}
784798
}
785799

786800
struct UdpSockets {
@@ -2330,6 +2344,28 @@ impl PinnedDrop for SessionInner {
23302344
}
23312345
}
23322346

2347+
impl futures::Sink<SendingPacket> for Session<Playing>{
2348+
type Error = futures::io::Error;
2349+
2350+
fn poll_ready(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
2351+
Poll::Ready(Ok(()))
2352+
}
2353+
2354+
fn start_send(self: Pin<&mut Self>, item: SendingPacket) -> Result<(), Self::Error> {
2355+
//self.0.conn.as_mut().unwrap().inner.send(item);
2356+
Ok(())
2357+
}
2358+
2359+
fn poll_flush(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
2360+
Poll::Ready(Ok(()))
2361+
}
2362+
2363+
fn poll_close(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
2364+
Poll::Ready(Ok(()))
2365+
}
2366+
}
2367+
2368+
23332369
impl futures::Stream for Session<Playing> {
23342370
type Item = Result<PacketItem, Error>;
23352371

src/client/parse.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use sdp_types::Media;
77
use std::{net::IpAddr, num::NonZeroU16};
88
use url::Url;
99

10-
use super::{Presentation, Stream};
10+
use super::{Presentation, Stream, StreamDirection};
1111

1212
/// A static payload type in the [RTP parameters
1313
/// registry](https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-1).
@@ -257,6 +257,7 @@ fn parse_media(base_url: &Url, media_description: &Media) -> Result<Stream, Stri
257257
let mut fmtp = None;
258258
let mut control = None;
259259
let mut framerate = None;
260+
let mut direction = StreamDirection::Receiving;
260261
for a in &media_description.attributes {
261262
match a.attribute.as_str() {
262263
"rtpmap" => {
@@ -313,6 +314,9 @@ fn parse_media(base_url: &Url, media_description: &Media) -> Result<Stream, Stri
313314
}
314315
}
315316
}
317+
"sendonly" => {
318+
direction=StreamDirection::Sending;
319+
}
316320
_ => (),
317321
}
318322
}
@@ -376,6 +380,7 @@ fn parse_media(base_url: &Url, media_description: &Media) -> Result<Stream, Stri
376380
channels,
377381
framerate,
378382
state: super::StreamState::Uninit,
383+
direction,
379384
})
380385
}
381386

src/rtp.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ impl RawPacketBuilder {
229229
}
230230
}
231231

232+
pub struct SendingPacket{
233+
stream_id: usize,
234+
raw: RawPacket,
235+
payload_range: Range<u16>,
236+
}
237+
238+
impl std::fmt::Debug for SendingPacket {
239+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
240+
f.debug_struct("SendingPacket")
241+
.field("streamId", &self.stream_id)
242+
.field("payload_type", &self.raw.payload_type())
243+
.finish()
244+
}
245+
}
246+
232247
/// A received RTP packet.
233248
///
234249
/// This holds more information than the packet itself: also a

0 commit comments

Comments
 (0)