scottlamb / retina

High-level RTSP multimedia streaming library, in Rust
https://crates.io/crates/retina
Apache License 2.0
220 stars 46 forks source link

API design: should depacketizers provide data as impl Buf or Bytes/Vec<u8>? #4

Closed scottlamb closed 3 years ago

scottlamb commented 3 years ago

Right now retina::codec::VideoFrame implements Buf and supports only H.264. It always has two chunks: an AVC length prefix and the header+body of the (single) picture NAL (note I'll need to extend it for multiple NALs). The idea was to support zero-copy, but I think right now it's kind of the worst of all worlds:

AudioFrame and MessageFrame provide a Bytes directly; there's no good reason all three frame bytes shouldn't present their data in the same way.

I'd prefer to follow one of two paths. I haven't made up my mind as to which:

Arguments in favor of zero-copy (custom Buf implementation with multiple chunks):

Arguments in favor of a single Bytes or Vec<u8>:

Right now I'm leaning toward single Bytes. I might try benchmarking both but if the performance is close I think simplicity should win.