From 1b56382ecc132f9a414486cad4ac9f75241955fb Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Tue, 23 Apr 2024 18:44:02 +0200 Subject: [PATCH] Introduce NAPacketiser::attach_stream() This allows packetisers to get initial stream information and act on it during parsing process or returning a new stream. --- nihav-core/src/codecs/mod.rs | 4 ++++ nihav-llaudio/src/codecs/flac.rs | 1 + nihav-mpeg/src/codecs/mpegaudio/mod.rs | 1 + 3 files changed, 6 insertions(+) diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index 37857d9..b7d7819 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -427,6 +427,10 @@ impl RegisteredEncoders { /// Trait for packetisers (objects that form full packets from raw stream data). pub trait NAPacketiser { + /// Provides the reference stream from the demuxer to the packetiser. + /// + /// This may be useful in cases when packetiser cannot determine stream parameters by itself. + fn attach_stream(&mut self, stream: NAStreamRef); /// Queues new raw stream data for parsing. /// /// Returns false is the internal buffer grows too large. diff --git a/nihav-llaudio/src/codecs/flac.rs b/nihav-llaudio/src/codecs/flac.rs index 6d71981..6ebc78d 100644 --- a/nihav-llaudio/src/codecs/flac.rs +++ b/nihav-llaudio/src/codecs/flac.rs @@ -552,6 +552,7 @@ impl FLACPacketiser { } impl NAPacketiser for FLACPacketiser { + fn attach_stream(&mut self, _stream: NAStreamRef) {} fn add_data(&mut self, src: &[u8]) -> bool { self.buf.extend_from_slice(src); self.buf.len() < 4096 diff --git a/nihav-mpeg/src/codecs/mpegaudio/mod.rs b/nihav-mpeg/src/codecs/mpegaudio/mod.rs index 677e81b..e883df8 100644 --- a/nihav-mpeg/src/codecs/mpegaudio/mod.rs +++ b/nihav-mpeg/src/codecs/mpegaudio/mod.rs @@ -373,6 +373,7 @@ impl MPAPacketiser { } impl NAPacketiser for MPAPacketiser { + fn attach_stream(&mut self, _stream: NAStreamRef) {} fn add_data(&mut self, src: &[u8]) -> bool { self.buf.extend_from_slice(src); self.buf.len() < 4096 -- 2.39.5