@@ -17,6 +17,10 @@ pub struct MockStream {
17
17
rtcp_writer : Mutex < Option < Arc < dyn RTCPWriter + Send + Sync > > > ,
18
18
rtp_writer : Mutex < Option < Arc < dyn RTPWriter + Send + Sync > > > ,
19
19
20
+ internal : Arc < MockStreamInternal > ,
21
+ }
22
+
23
+ struct MockStreamInternal {
20
24
rtcp_out_modified_tx : mpsc:: Sender < RTCPPackets > ,
21
25
rtp_out_modified_tx : mpsc:: Sender < rtp:: packet:: Packet > ,
22
26
rtcp_in_rx : Mutex < mpsc:: Receiver < RTCPPackets > > ,
@@ -46,44 +50,44 @@ impl MockStream {
46
50
47
51
let stream = Arc :: new ( MockStream {
48
52
interceptor : Arc :: clone ( & interceptor) ,
49
-
50
53
rtcp_writer : Mutex :: new ( None ) ,
51
54
rtp_writer : Mutex :: new ( None ) ,
52
-
53
- rtcp_in_tx : Mutex :: new ( Some ( rtcp_in_tx) ) ,
54
- rtp_in_tx : Mutex :: new ( Some ( rtp_in_tx) ) ,
55
- rtcp_in_rx : Mutex :: new ( rtcp_in_rx) ,
56
- rtp_in_rx : Mutex :: new ( rtp_in_rx) ,
57
-
58
- rtcp_out_modified_tx,
59
- rtp_out_modified_tx,
60
- rtcp_out_modified_rx : Mutex :: new ( rtcp_out_modified_rx) ,
61
- rtp_out_modified_rx : Mutex :: new ( rtp_out_modified_rx) ,
62
-
63
- rtcp_in_modified_rx : Mutex :: new ( rtcp_in_modified_rx) ,
64
- rtp_in_modified_rx : Mutex :: new ( rtp_in_modified_rx) ,
55
+ internal : Arc :: new ( MockStreamInternal {
56
+ rtcp_in_tx : Mutex :: new ( Some ( rtcp_in_tx) ) ,
57
+ rtp_in_tx : Mutex :: new ( Some ( rtp_in_tx) ) ,
58
+ rtcp_in_rx : Mutex :: new ( rtcp_in_rx) ,
59
+ rtp_in_rx : Mutex :: new ( rtp_in_rx) ,
60
+
61
+ rtcp_out_modified_tx,
62
+ rtp_out_modified_tx,
63
+ rtcp_out_modified_rx : Mutex :: new ( rtcp_out_modified_rx) ,
64
+ rtp_out_modified_rx : Mutex :: new ( rtp_out_modified_rx) ,
65
+
66
+ rtcp_in_modified_rx : Mutex :: new ( rtcp_in_modified_rx) ,
67
+ rtp_in_modified_rx : Mutex :: new ( rtp_in_modified_rx) ,
68
+ } ) ,
65
69
} ) ;
66
70
67
71
let rtcp_writer = interceptor
68
- . bind_rtcp_writer ( Arc :: clone ( & stream) as Arc < dyn RTCPWriter + Send + Sync > )
72
+ . bind_rtcp_writer ( Arc :: clone ( & stream. internal ) as Arc < dyn RTCPWriter + Send + Sync > )
69
73
. await ;
70
74
{
71
75
let mut rw = stream. rtcp_writer . lock ( ) . await ;
72
- * rw = Some ( rtcp_writer) ;
76
+ * rw = Some ( Arc :: clone ( & rtcp_writer) ) ;
73
77
}
74
78
let rtp_writer = interceptor
75
79
. bind_local_stream (
76
80
info,
77
- Arc :: clone ( & stream) as Arc < dyn RTPWriter + Send + Sync > ,
81
+ Arc :: clone ( & stream. internal ) as Arc < dyn RTPWriter + Send + Sync > ,
78
82
)
79
83
. await ;
80
84
{
81
85
let mut rw = stream. rtp_writer . lock ( ) . await ;
82
- * rw = Some ( rtp_writer) ;
86
+ * rw = Some ( Arc :: clone ( & rtp_writer) ) ;
83
87
}
84
88
85
89
let rtcp_reader = interceptor
86
- . bind_rtcp_reader ( Arc :: clone ( & stream) as Arc < dyn RTCPReader + Send + Sync > )
90
+ . bind_rtcp_reader ( Arc :: clone ( & stream. internal ) as Arc < dyn RTCPReader + Send + Sync > )
87
91
. await ;
88
92
tokio:: spawn ( async move {
89
93
let mut buf = vec ! [ 0u8 ; 1500 ] ;
@@ -104,7 +108,7 @@ impl MockStream {
104
108
let rtp_reader = interceptor
105
109
. bind_remote_stream (
106
110
info,
107
- Arc :: clone ( & stream) as Arc < dyn RTPReader + Send + Sync > ,
111
+ Arc :: clone ( & stream. internal ) as Arc < dyn RTPReader + Send + Sync > ,
108
112
)
109
113
. await ;
110
114
tokio:: spawn ( async move {
@@ -153,23 +157,23 @@ impl MockStream {
153
157
154
158
/// receive_rtcp schedules a new rtcp batch, so it can be read be the stream
155
159
pub async fn receive_rtcp ( & self , pkts : Vec < Box < dyn rtcp:: packet:: Packet + Send + Sync > > ) {
156
- let rtcp_in_tx = self . rtcp_in_tx . lock ( ) . await ;
160
+ let rtcp_in_tx = self . internal . rtcp_in_tx . lock ( ) . await ;
157
161
if let Some ( tx) = & * rtcp_in_tx {
158
162
let _ = tx. send ( pkts) . await ;
159
163
}
160
164
}
161
165
162
166
/// receive_rtp schedules a rtp packet, so it can be read be the stream
163
167
pub async fn receive_rtp ( & self , pkt : rtp:: packet:: Packet ) {
164
- let rtp_in_tx = self . rtp_in_tx . lock ( ) . await ;
168
+ let rtp_in_tx = self . internal . rtp_in_tx . lock ( ) . await ;
165
169
if let Some ( tx) = & * rtp_in_tx {
166
170
let _ = tx. send ( pkt) . await ;
167
171
}
168
172
}
169
173
170
174
/// written_rtcp returns a channel containing the rtcp batches written, modified by the interceptor
171
175
pub async fn written_rtcp ( & self ) -> Option < Vec < Box < dyn rtcp:: packet:: Packet + Send + Sync > > > {
172
- let mut rtcp_out_modified_rx = self . rtcp_out_modified_rx . lock ( ) . await ;
176
+ let mut rtcp_out_modified_rx = self . internal . rtcp_out_modified_rx . lock ( ) . await ;
173
177
rtcp_out_modified_rx. recv ( ) . await
174
178
}
175
179
@@ -180,7 +184,7 @@ impl MockStream {
180
184
& self ,
181
185
) -> Option < Vec < Box < dyn rtcp:: packet:: Packet + Send + Sync > > > {
182
186
let mut last = None ;
183
- let mut rtcp_out_modified_rx = self . rtcp_out_modified_rx . lock ( ) . await ;
187
+ let mut rtcp_out_modified_rx = self . internal . rtcp_out_modified_rx . lock ( ) . await ;
184
188
185
189
while let Ok ( v) = rtcp_out_modified_rx. try_recv ( ) {
186
190
last = Some ( v) ;
@@ -191,40 +195,40 @@ impl MockStream {
191
195
192
196
/// written_rtp returns a channel containing rtp packets written, modified by the interceptor
193
197
pub async fn written_rtp ( & self ) -> Option < rtp:: packet:: Packet > {
194
- let mut rtp_out_modified_rx = self . rtp_out_modified_rx . lock ( ) . await ;
198
+ let mut rtp_out_modified_rx = self . internal . rtp_out_modified_rx . lock ( ) . await ;
195
199
rtp_out_modified_rx. recv ( ) . await
196
200
}
197
201
198
202
/// read_rtcp returns a channel containing the rtcp batched read, modified by the interceptor
199
203
pub async fn read_rtcp (
200
204
& self ,
201
205
) -> Option < Result < Vec < Box < dyn rtcp:: packet:: Packet + Send + Sync > > > > {
202
- let mut rtcp_in_modified_rx = self . rtcp_in_modified_rx . lock ( ) . await ;
206
+ let mut rtcp_in_modified_rx = self . internal . rtcp_in_modified_rx . lock ( ) . await ;
203
207
rtcp_in_modified_rx. recv ( ) . await
204
208
}
205
209
206
210
/// read_rtp returns a channel containing the rtp packets read, modified by the interceptor
207
211
pub async fn read_rtp ( & self ) -> Option < Result < rtp:: packet:: Packet > > {
208
- let mut rtp_in_modified_rx = self . rtp_in_modified_rx . lock ( ) . await ;
212
+ let mut rtp_in_modified_rx = self . internal . rtp_in_modified_rx . lock ( ) . await ;
209
213
rtp_in_modified_rx. recv ( ) . await
210
214
}
211
215
212
- /// close closes the stream and the underlying interceptor
216
+ /// close closes the stream
213
217
pub async fn close ( & self ) -> Result < ( ) > {
214
218
{
215
- let mut rtcp_in_tx = self . rtcp_in_tx . lock ( ) . await ;
219
+ let mut rtcp_in_tx = self . internal . rtcp_in_tx . lock ( ) . await ;
216
220
rtcp_in_tx. take ( ) ;
217
221
}
218
222
{
219
- let mut rtp_in_tx = self . rtp_in_tx . lock ( ) . await ;
223
+ let mut rtp_in_tx = self . internal . rtp_in_tx . lock ( ) . await ;
220
224
rtp_in_tx. take ( ) ;
221
225
}
222
226
self . interceptor . close ( ) . await
223
227
}
224
228
}
225
229
226
230
#[ async_trait]
227
- impl RTCPWriter for MockStream {
231
+ impl RTCPWriter for MockStreamInternal {
228
232
async fn write (
229
233
& self ,
230
234
pkts : & [ Box < dyn rtcp:: packet:: Packet + Send + Sync > ] ,
@@ -237,7 +241,7 @@ impl RTCPWriter for MockStream {
237
241
}
238
242
239
243
#[ async_trait]
240
- impl RTCPReader for MockStream {
244
+ impl RTCPReader for MockStreamInternal {
241
245
async fn read (
242
246
& self ,
243
247
buf : & mut [ u8 ] ,
@@ -260,15 +264,15 @@ impl RTCPReader for MockStream {
260
264
}
261
265
262
266
#[ async_trait]
263
- impl RTPWriter for MockStream {
267
+ impl RTPWriter for MockStreamInternal {
264
268
async fn write ( & self , pkt : & rtp:: packet:: Packet , _a : & Attributes ) -> Result < usize > {
265
269
let _ = self . rtp_out_modified_tx . send ( pkt. clone ( ) ) . await ;
266
270
Ok ( 0 )
267
271
}
268
272
}
269
273
270
274
#[ async_trait]
271
- impl RTPReader for MockStream {
275
+ impl RTPReader for MockStreamInternal {
272
276
async fn read (
273
277
& self ,
274
278
buf : & mut [ u8 ] ,
0 commit comments