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