xref: /webrtc/interceptor/src/noop.rs (revision ffe74184)
1 use crate::error::Result;
2 
3 use super::*;
4 
5 /// NoOp is an Interceptor that does not modify any packets. It can embedded in other interceptors, so it's
6 /// possible to implement only a subset of the methods.
7 pub struct NoOp;
8 
9 #[async_trait]
10 impl Interceptor for NoOp {
11     /// bind_rtcp_reader lets you modify any incoming RTCP packets. It is called once per sender/receiver, however this might
12     /// change in the future. The returned method will be called once per packet batch.
bind_rtcp_reader( &self, reader: Arc<dyn RTCPReader + Send + Sync>, ) -> Arc<dyn RTCPReader + Send + Sync>13     async fn bind_rtcp_reader(
14         &self,
15         reader: Arc<dyn RTCPReader + Send + Sync>,
16     ) -> Arc<dyn RTCPReader + Send + Sync> {
17         reader
18     }
19 
20     /// bind_rtcp_writer lets you modify any outgoing RTCP packets. It is called once per PeerConnection. The returned method
21     /// will be called once per packet batch.
bind_rtcp_writer( &self, writer: Arc<dyn RTCPWriter + Send + Sync>, ) -> Arc<dyn RTCPWriter + Send + Sync>22     async fn bind_rtcp_writer(
23         &self,
24         writer: Arc<dyn RTCPWriter + Send + Sync>,
25     ) -> Arc<dyn RTCPWriter + Send + Sync> {
26         writer
27     }
28 
29     /// bind_local_stream lets you modify any outgoing RTP packets. It is called once for per LocalStream. The returned method
30     /// will be called once per rtp packet.
bind_local_stream( &self, _info: &StreamInfo, writer: Arc<dyn RTPWriter + Send + Sync>, ) -> Arc<dyn RTPWriter + Send + Sync>31     async fn bind_local_stream(
32         &self,
33         _info: &StreamInfo,
34         writer: Arc<dyn RTPWriter + Send + Sync>,
35     ) -> Arc<dyn RTPWriter + Send + Sync> {
36         writer
37     }
38 
39     /// unbind_local_stream is called when the Stream is removed. It can be used to clean up any data related to that track.
unbind_local_stream(&self, _info: &StreamInfo)40     async fn unbind_local_stream(&self, _info: &StreamInfo) {}
41 
42     /// bind_remote_stream lets you modify any incoming RTP packets. It is called once for per RemoteStream. The returned method
43     /// will be called once per rtp packet.
bind_remote_stream( &self, _info: &StreamInfo, reader: Arc<dyn RTPReader + Send + Sync>, ) -> Arc<dyn RTPReader + Send + Sync>44     async fn bind_remote_stream(
45         &self,
46         _info: &StreamInfo,
47         reader: Arc<dyn RTPReader + Send + Sync>,
48     ) -> Arc<dyn RTPReader + Send + Sync> {
49         reader
50     }
51 
52     /// unbind_remote_stream is called when the Stream is removed. It can be used to clean up any data related to that track.
unbind_remote_stream(&self, _info: &StreamInfo)53     async fn unbind_remote_stream(&self, _info: &StreamInfo) {}
54 
55     /// close closes the Interceptor, cleaning up any data if necessary.
close(&self) -> Result<()>56     async fn close(&self) -> Result<()> {
57         Ok(())
58     }
59 }
60 
61 #[async_trait]
62 impl RTPReader for NoOp {
read(&self, _buf: &mut [u8], a: &Attributes) -> Result<(usize, Attributes)>63     async fn read(&self, _buf: &mut [u8], a: &Attributes) -> Result<(usize, Attributes)> {
64         Ok((0, a.clone()))
65     }
66 }
67 
68 #[async_trait]
69 impl RTCPReader for NoOp {
read(&self, _buf: &mut [u8], a: &Attributes) -> Result<(usize, Attributes)>70     async fn read(&self, _buf: &mut [u8], a: &Attributes) -> Result<(usize, Attributes)> {
71         Ok((0, a.clone()))
72     }
73 }
74