webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

[Interceptor] Rework Attributes

Open k0nserv opened this issue 3 years ago • 0 comments
trafficstars

Migrated issue from webrtc-rs/interceptor

The signature for RTPReader's read method currently accepts Attributes by reference, but then also returns Attributes. This makes it impossible to avoid at least one clone(in the last step of the interceptor chain).

By changing the type from &Attribute to &mut Attributes and not returning the Attributes i.e. making it an inout value, we can avoid this cloning.

This means that instead of:

    async fn read(
        &self,
        buf: &mut [u8],
        attributes: &Attributes,
    ) -> Result<(usize, Attributes)>;

we'll have:

    async fn read(
        &self,
        buf: &mut [u8],
        attributes: &mut Attributes,
    ) -> Result<usize>;

which results in a single allocation of Attributes.

Further, it should be possible to change the type of Attributes from HashMap<usize, usize> to HashMap<usize, Box<dyn Any>> which allows more freedom in the values stored within.

I'll try and make a PR to this effect at some point, but if someone sees this before then feel free to do it for me :)

EDIT: I'm actually slightly wrong about this, only the clone in the last part of the interceptor chain is required.

k0nserv avatar Aug 23 '22 12:08 k0nserv