]> git.nihav.org Git - nihav.git/commitdiff
h264: implement decoder wrappers
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 7 Mar 2026 14:12:32 +0000 (15:12 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 7 Mar 2026 17:45:46 +0000 (18:45 +0100)
nihav-itu/src/codecs/h264/baseline/decoder_mt.rs
nihav-itu/src/codecs/h264/baseline/decoder_st.rs
nihav-itu/src/codecs/h264/baseline/dispatch.rs
nihav-itu/src/codecs/h264/baseline/mod.rs
nihav-itu/src/codecs/h264/mod.rs

index 216b810d754ab295fe66ab48b1cabf0d559a9978..d5323f613390a8572c28c51fac3d0cfc75654d70 100644 (file)
@@ -472,7 +472,7 @@ impl FrameDecoder {
     }
 }
 
-struct H264MTDecoder {
+pub struct H264MTDecoder {
     info:           NACodecInfoRef,
     nal_len:        u8,
     dispatch:       Shareable<ThreadDispatcher>,
@@ -492,7 +492,7 @@ struct H264MTDecoder {
 }
 
 impl H264MTDecoder {
-    fn new() -> Self {
+    pub fn new() -> Self {
         Self {
             info:           NACodecInfoRef::default(),
             nal_len:        0,
@@ -981,7 +981,3 @@ impl NAOptionHandler for H264MTDecoder {
         }
     }
 }
-
-pub fn get_decoder_mt() -> Box<dyn NADecoderMT + Send> {
-    Box::new(H264MTDecoder::new())
-}
index 85771177ff60032dafd4b43a357a528e71af5758..683c03153de763efd422bdf1c0aacbda171f4932 100644 (file)
@@ -6,7 +6,7 @@ use nihav_core::io::bitreader::*;
 use super::super::*;
 use super::*;
 
-struct H264Decoder {
+pub struct H264Decoder {
     info:       NACodecInfoRef,
     width:      usize,
     height:     usize,
@@ -47,7 +47,7 @@ struct H264Decoder {
 }
 
 impl H264Decoder {
-    fn new() -> Self {
+    pub fn new() -> Self {
         H264Decoder{
             info:       NACodecInfoRef::default(),
             width:      0,
@@ -942,7 +942,3 @@ impl NAOptionHandler for H264Decoder {
         }
     }
 }
-
-pub fn get_decoder() -> Box<dyn NADecoder + Send> {
-    Box::new(H264Decoder::new())
-}
index e3e27fc20999633af9b3d096ca97d7acbd4ff7ae..e2adfb096c0ce67933038be969f6320fa8d88187 100644 (file)
@@ -4,7 +4,8 @@ use std::thread;
 
 use nihav_core::codecs::{DecoderError, DecoderResult};
 
-use super::{FrameDecoder, PictureInfo};
+use super::PictureInfo;
+use super::decoder_mt::FrameDecoder;
 use super::super::Shareable;
 
 #[derive(Clone,Copy,Debug,PartialEq)]
index 89606fce1c0064532eedb97d33b47d786f765bea..c7e28f406af4ea7b9bb148e36500331b8d4e9d5a 100644 (file)
@@ -20,11 +20,9 @@ use mb_recon::*;
 use super::sets::*;
 use super::slice::*;
 
-mod decoder_st;
-pub use decoder_st::*;
+pub mod decoder_st;
 mod dispatch;
-mod decoder_mt;
-pub use decoder_mt::*;
+pub mod decoder_mt;
 
 use super::common_types::*;
 
index 52e8d0e4f2b02cef2376621663d08b1fc9b96266..160970e454df0c09bd5415c1b7c3b24eb81f5571 100644 (file)
@@ -16,7 +16,6 @@ mod baseline;
 mod cabac_coder;
 mod common_types;
 use common_types::*;
-pub use baseline::{get_decoder, get_decoder_mt};
 mod sets;
 mod slice;
 use slice::*;
@@ -167,6 +166,83 @@ fn unescape_nal(src: &[u8], dst: &mut Vec<u8>) -> usize {
     off
 }
 
+struct STDecoderWrapper {
+    h264:       Box<baseline::decoder_st::H264Decoder>,
+}
+
+impl NADecoder for STDecoderWrapper {
+    fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
+        self.h264.init(supp, info)
+    }
+    fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
+        self.h264.decode(supp, pkt)
+    }
+    fn flush(&mut self) {
+        self.h264.flush();
+    }
+}
+
+impl NAOptionHandler for STDecoderWrapper {
+    fn get_supported_options(&self) -> &[NAOptionDefinition] {
+        self.h264.get_supported_options()
+    }
+    fn set_options(&mut self, options: &[NAOption]) {
+        self.h264.set_options(options);
+    }
+    fn query_option_value(&self, name: &str) -> Option<NAValue> {
+        self.h264.query_option_value(name)
+    }
+}
+
+pub fn get_decoder() -> Box<dyn NADecoder + Send> {
+    Box::new(STDecoderWrapper {
+        h264:       Box::new(baseline::decoder_st::H264Decoder::new()),
+    })
+}
+
+struct MTDecoderWrapper {
+    h264:       Box<baseline::decoder_mt::H264MTDecoder>,
+}
+
+impl NADecoderMT for MTDecoderWrapper {
+    fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef, nthreads: usize) -> DecoderResult<()> {
+        self.h264.init(supp, info, nthreads)
+    }
+    fn can_take_input(&mut self) -> bool {
+        self.h264.can_take_input()
+    }
+    fn queue_pkt(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket, user_id: u32) -> DecoderResult<bool> {
+        self.h264.queue_pkt(supp, pkt, user_id)
+    }
+    fn has_output(&mut self) -> bool {
+        self.h264.has_output()
+    }
+    fn get_frame(&mut self) -> (DecoderResult<NAFrameRef>, u32) {
+        self.h264.get_frame()
+    }
+    fn flush(&mut self) {
+        self.h264.flush();
+    }
+}
+
+impl NAOptionHandler for MTDecoderWrapper {
+    fn get_supported_options(&self) -> &[NAOptionDefinition] {
+        self.h264.get_supported_options()
+    }
+    fn set_options(&mut self, options: &[NAOption]) {
+        self.h264.set_options(options);
+    }
+    fn query_option_value(&self, name: &str) -> Option<NAValue> {
+        self.h264.query_option_value(name)
+    }
+}
+
+pub fn get_decoder_mt() -> Box<dyn NADecoderMT + Send> {
+    Box::new(MTDecoderWrapper {
+        h264:       Box::new(baseline::decoder_mt::H264MTDecoder::new()),
+    })
+}
+
 const DEBLOCK_SKIP_OPTION: &str = "skip_deblock";
 
 const DECODER_OPTIONS: &[NAOptionDefinition] = &[