Skip to content

Commit ad555d1

Browse files
author
yngrtc
committed
[RTP] remove unnecessary async function/trait
1 parent 461ef34 commit ad555d1

File tree

4 files changed

+22
-35
lines changed

4 files changed

+22
-35
lines changed

rtp/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ util = { version = "0.7.0", path = "../util", package = "webrtc-util", default-f
1616
bytes = "1"
1717
rand = "0.8.5"
1818
thiserror = "1.0"
19-
async-trait = "0.1.56"
2019
serde = { version = "1.0.102", features = ["derive"] }
2120

2221
[dev-dependencies]
2322
chrono = "0.4.23"
2423
criterion = "0.4.0"
25-
tokio = { version = "1.19", features = ["full"] }
26-
tokio-test = "0.4.0" # must match the min version of the `tokio` crate above
2724

2825
[[bench]]
2926
name = "packet_bench"

rtp/src/packetizer/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ use crate::error::Result;
55
use crate::{extension::abs_send_time_extension::*, header::*, packet::*, sequence::*};
66
use util::marshal::{Marshal, MarshalSize};
77

8-
use async_trait::async_trait;
98
use bytes::{Bytes, BytesMut};
109
use std::fmt;
11-
use std::future::Future;
12-
use std::pin::Pin;
1310
use std::sync::Arc;
1411
use std::time::SystemTime;
1512

@@ -26,10 +23,9 @@ impl Clone for Box<dyn Payloader + Send + Sync> {
2623
}
2724

2825
/// Packetizer packetizes a payload
29-
#[async_trait]
3026
pub trait Packetizer: fmt::Debug {
3127
fn enable_abs_send_time(&mut self, value: u8);
32-
async fn packetize(&mut self, payload: &Bytes, samples: u32) -> Result<Vec<Packet>>;
28+
fn packetize(&mut self, payload: &Bytes, samples: u32) -> Result<Vec<Packet>>;
3329
fn skip_samples(&mut self, skipped_samples: u32);
3430
fn clone_to(&self) -> Box<dyn Packetizer + Send + Sync>;
3531
}
@@ -57,8 +53,7 @@ pub trait Depacketizer {
5753
//TODO: SystemTime vs Instant?
5854
// non-monotonic clock vs monotonically non-decreasing clock
5955
/// FnTimeGen provides current SystemTime
60-
pub type FnTimeGen =
61-
Arc<dyn (Fn() -> Pin<Box<dyn Future<Output = SystemTime> + Send + 'static>>) + Send + Sync>;
56+
pub type FnTimeGen = Arc<dyn (Fn() -> SystemTime) + Send + Sync>;
6257

6358
#[derive(Clone)]
6459
pub(crate) struct PacketizerImpl {
@@ -107,13 +102,12 @@ pub fn new_packetizer(
107102
}
108103
}
109104

110-
#[async_trait]
111105
impl Packetizer for PacketizerImpl {
112106
fn enable_abs_send_time(&mut self, value: u8) {
113107
self.abs_send_time = value
114108
}
115109

116-
async fn packetize(&mut self, payload: &Bytes, samples: u32) -> Result<Vec<Packet>> {
110+
fn packetize(&mut self, payload: &Bytes, samples: u32) -> Result<Vec<Packet>> {
117111
let payloads = self.payloader.payload(self.mtu - 12, payload)?;
118112
let payloads_len = payloads.len();
119113
let mut packets = Vec::with_capacity(payloads_len);
@@ -138,7 +132,7 @@ impl Packetizer for PacketizerImpl {
138132

139133
if payloads_len != 0 && self.abs_send_time != 0 {
140134
let st = if let Some(fn_time_gen) = &self.time_gen {
141-
fn_time_gen().await
135+
fn_time_gen()
142136
} else {
143137
SystemTime::now()
144138
};

rtp/src/packetizer/packetizer_test.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use crate::error::Result;
55
use chrono::prelude::*;
66
use std::time::{Duration, UNIX_EPOCH};
77

8-
#[tokio::test]
9-
async fn test_packetizer() -> Result<()> {
8+
#[test]
9+
fn test_packetizer() -> Result<()> {
1010
let multiple_payload = Bytes::from_static(&[0; 128]);
1111
let g722 = Box::new(g7xx::G722Payloader {});
1212
let seq = Box::new(new_random_sequencer());
1313

1414
//use the G722 payloader here, because it's very simple and all 0s is valid G722 data.
1515
let mut packetizer = new_packetizer(100, 98, 0x1234ABCD, g722, seq, 90000);
16-
let packets = packetizer.packetize(&multiple_payload, 2000).await?;
16+
let packets = packetizer.packetize(&multiple_payload, 2000)?;
1717

1818
if packets.len() != 2 {
1919
let mut packet_lengths = String::new();
@@ -31,22 +31,18 @@ async fn test_packetizer() -> Result<()> {
3131
Ok(())
3232
}
3333

34-
#[tokio::test]
35-
async fn test_packetizer_abs_send_time() -> Result<()> {
34+
#[test]
35+
fn test_packetizer_abs_send_time() -> Result<()> {
3636
let g722 = Box::new(g7xx::G722Payloader {});
3737
let sequencer = Box::new(new_fixed_sequencer(1234));
3838

39-
let time_gen: Option<FnTimeGen> = Some(Arc::new(
40-
|| -> Pin<Box<dyn Future<Output = SystemTime> + Send + 'static>> {
41-
Box::pin(async move {
42-
let loc = FixedOffset::west_opt(5 * 60 * 60).unwrap(); // UTC-5
43-
let t = loc.with_ymd_and_hms(1985, 6, 23, 4, 0, 0).unwrap();
44-
UNIX_EPOCH
45-
.checked_add(Duration::from_nanos(t.timestamp_nanos() as u64))
46-
.unwrap_or(UNIX_EPOCH)
47-
})
48-
},
49-
));
39+
let time_gen: Option<FnTimeGen> = Some(Arc::new(|| -> SystemTime {
40+
let loc = FixedOffset::west_opt(5 * 60 * 60).unwrap(); // UTC-5
41+
let t = loc.with_ymd_and_hms(1985, 6, 23, 4, 0, 0).unwrap();
42+
UNIX_EPOCH
43+
.checked_add(Duration::from_nanos(t.timestamp_nanos() as u64))
44+
.unwrap_or(UNIX_EPOCH)
45+
}));
5046

5147
//use the G722 payloader here, because it's very simple and all 0s is valid G722 data.
5248
let mut pktizer = PacketizerImpl {
@@ -63,7 +59,7 @@ async fn test_packetizer_abs_send_time() -> Result<()> {
6359
pktizer.enable_abs_send_time(1);
6460

6561
let payload = Bytes::from_static(&[0x11, 0x12, 0x13, 0x14]);
66-
let packets = pktizer.packetize(&payload, 2000).await?;
62+
let packets = pktizer.packetize(&payload, 2000)?;
6763

6864
let expected = Packet {
6965
header: Header {
@@ -94,17 +90,17 @@ async fn test_packetizer_abs_send_time() -> Result<()> {
9490
Ok(())
9591
}
9692

97-
#[tokio::test]
98-
async fn test_packetizer_timestamp_rollover_does_not_panic() -> Result<()> {
93+
#[test]
94+
fn test_packetizer_timestamp_rollover_does_not_panic() -> Result<()> {
9995
let g722 = Box::new(g7xx::G722Payloader {});
10096
let seq = Box::new(new_random_sequencer());
10197

10298
let payload = Bytes::from_static(&[0; 128]);
10399
let mut packetizer = new_packetizer(100, 98, 0x1234ABCD, g722, seq, 90000);
104100

105-
packetizer.packetize(&payload, 10).await?;
101+
packetizer.packetize(&payload, 10)?;
106102

107-
packetizer.packetize(&payload, u32::MAX).await?;
103+
packetizer.packetize(&payload, u32::MAX)?;
108104

109105
packetizer.skip_samples(u32::MAX);
110106

webrtc/src/track/track_local/track_local_static_sample.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl TrackLocalStaticSample {
118118
if sample.prev_dropped_packets > 0 {
119119
packetizer.skip_samples(samples * sample.prev_dropped_packets as u32);
120120
}
121-
packetizer.packetize(&sample.data, samples).await?
121+
packetizer.packetize(&sample.data, samples)?
122122
} else {
123123
vec![]
124124
};

0 commit comments

Comments
 (0)