@@ -23,11 +23,26 @@ use crate::rtp_transceiver::*;
2323/// TrackLocalWriter is the Writer for outbound RTP Packets
2424#[ async_trait]
2525pub trait TrackLocalWriter : fmt:: Debug {
26+ /// write_rtp_with_attributes encrypts a RTP packet and writes to the connection.
27+ /// attributes are delivered to the interceptor chain
28+ async fn write_rtp_with_attributes (
29+ & self ,
30+ pkt : & rtp:: packet:: Packet ,
31+ attr : & Attributes ,
32+ ) -> Result < usize > ;
33+
2634 /// write_rtp encrypts a RTP packet and writes to the connection
27- async fn write_rtp ( & self , p : & rtp:: packet:: Packet ) -> Result < usize > ;
35+ async fn write_rtp ( & self , pkt : & rtp:: packet:: Packet ) -> Result < usize > {
36+ let attr = Attributes :: new ( ) ;
37+ self . write_rtp_with_attributes ( pkt, & attr) . await
38+ }
2839
2940 /// write encrypts and writes a full RTP packet
30- async fn write ( & self , b : & [ u8 ] ) -> Result < usize > ;
41+ async fn write ( & self , mut b : & [ u8 ] ) -> Result < usize > {
42+ let pkt = rtp:: packet:: Packet :: unmarshal ( & mut b) ?;
43+ let attr = Attributes :: new ( ) ;
44+ self . write_rtp_with_attributes ( & pkt, & attr) . await
45+ }
3146}
3247
3348/// TrackLocalContext is the Context passed when a TrackLocal has been Binded/Unbinded from a PeerConnection, and used
@@ -149,22 +164,20 @@ impl std::fmt::Debug for InterceptorToTrackLocalWriter {
149164
150165#[ async_trait]
151166impl TrackLocalWriter for InterceptorToTrackLocalWriter {
152- async fn write_rtp ( & self , pkt : & rtp:: packet:: Packet ) -> Result < usize > {
167+ async fn write_rtp_with_attributes (
168+ & self ,
169+ pkt : & rtp:: packet:: Packet ,
170+ attr : & Attributes ,
171+ ) -> Result < usize > {
153172 if self . is_sender_paused ( ) {
154173 return Ok ( 0 ) ;
155174 }
156175
157176 let interceptor_rtp_writer = self . interceptor_rtp_writer . lock ( ) . await ;
158177 if let Some ( writer) = & * interceptor_rtp_writer {
159- let a = Attributes :: new ( ) ;
160- Ok ( writer. write ( pkt, & a) . await ?)
178+ Ok ( writer. write ( pkt, attr) . await ?)
161179 } else {
162180 Ok ( 0 )
163181 }
164182 }
165-
166- async fn write ( & self , mut b : & [ u8 ] ) -> Result < usize > {
167- let pkt = rtp:: packet:: Packet :: unmarshal ( & mut b) ?;
168- self . write_rtp ( & pkt) . await
169- }
170183}
0 commit comments