]> git.nihav.org Git - nihav-encoder.git/commitdiff
switch to ByteIO master
authorKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 18 Aug 2025 16:54:37 +0000 (18:54 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 18 Aug 2025 17:08:19 +0000 (19:08 +0200)
src/demux.rs
src/imgseq.rs
src/main.rs
src/null.rs
src/transcoder.rs

index 75b53e309a2cad35561b28d9763f62681421dc12..8533c9550c65d4dbfdacda11ddcce73abd8906b4 100644 (file)
@@ -3,7 +3,7 @@ use nihav_core::codecs::*;
 use nihav_core::demuxers::*;
 use nihav_core::muxers::*;
 use nihav_registry::detect;
-use nihav_core::io::byteio::ByteReader;
+use nihav_core::io::byteio::ByteIO;
 use nihav_allstuff::*;
 use crate::null::*;
 use crate::imgseq::*;
@@ -42,35 +42,34 @@ pub struct RawStreamCtx<'a> {
     stream:     NAStreamRef,
     sm:         StreamManager,
     packetiser: Box<dyn NAPacketiser + Send>,
-    br:         &'a mut ByteReader<'a>,
+    br:         &'a mut dyn ByteIO,
     pts:        u64,
 }
 
 impl<'a> RawStreamCtx<'a> {
-    fn new(stream: NAStreamRef, packetiser: Box<dyn NAPacketiser + Send>, br: &'a mut ByteReader<'a>) -> Self {
+    fn new(stream: NAStreamRef, packetiser: Box<dyn NAPacketiser + Send>, br: &'a mut dyn ByteIO) -> Self {
         let mut sm = StreamManager::new();
         sm.add_stream_ref(stream.clone());
         Self { stream, sm, packetiser, br, pts: 0 }
     }
 }
 
-type ReaderBox<'a> = SBBox<Box<dyn ByteIO>, ByteReader<'a>>;
+type ReaderBox = Box<dyn ByteIO>;
 
 pub enum DemuxerObject<'a> {
     None,
-    Normal(SBBox<ReaderBox<'a>, Demuxer<'a>>),
-    Raw(SBBox<ReaderBox<'a>, RawDemuxer<'a>>, Vec<Option<Box<dyn NAPacketiser + Send>>>, bool),
-    RawStream(SBBox<ReaderBox<'a>, RawStreamCtx<'a>>),
+    Normal(SBBox<ReaderBox, Demuxer<'a>>),
+    Raw(SBBox<ReaderBox, RawDemuxer<'a>>, Vec<Option<Box<dyn NAPacketiser + Send>>>, bool),
+    RawStream(SBBox<ReaderBox, RawStreamCtx<'a>>),
     ImageSequence(ImgSeqDemuxer),
 }
 
 impl<'a> DemuxerObject<'a> {
-    pub fn create(mut brb: ReaderBox<'a>, reg: &FullRegister, name: &str, ifmt: &Option<String>, is_raw: bool, print_info: bool) -> DemuxerObject<'a> {
-        let br = brb.get_object_mut();
+    pub fn create(mut br: ReaderBox, reg: &FullRegister, name: &str, ifmt: &Option<String>, is_raw: bool, print_info: bool) -> DemuxerObject<'a> {
         if !is_raw {
             let dmx_name = if let Some(ref dname) = ifmt {
                     dname.as_str()
-                } else if let Some((dname, score)) = detect::detect_format(name, br) {
+                } else if let Some((dname, score)) = detect::detect_format(name, &mut *br) {
                     if print_info {
                         println!("detected {} with score {:?}", dname, score);
                     }
@@ -85,9 +84,9 @@ impl<'a> DemuxerObject<'a> {
                 if let Some(dmx_fact) = reg.dmx_reg.find_demuxer(dmx_name) {
                     br.seek(SeekFrom::Start(0)).unwrap();
 
-                    let ret = SelfBorrow::try_new(brb, |br_| {
+                    let ret = SelfBorrow::try_new(br, |br_| {
                             unsafe {
-                                create_demuxer(dmx_fact, br_.as_mut().unwrap().get_object_mut()).ok()
+                                create_demuxer(dmx_fact, (*br_).as_mut()).ok()
                             }
                         });
                     if let Some(dmx) = ret {
@@ -107,9 +106,9 @@ impl<'a> DemuxerObject<'a> {
                 }
                 if let Some(rdmx_fact) = reg.rdmx_reg.find_demuxer(dmx_name) {
                     br.seek(SeekFrom::Start(0)).unwrap();
-                    let ret = SelfBorrow::try_new(brb, |br_| {
+                    let ret = SelfBorrow::try_new(br, |br_| {
                             unsafe {
-                                create_raw_demuxer(rdmx_fact, br_.as_mut().unwrap().get_object_mut()).ok()
+                                create_raw_demuxer(rdmx_fact, (*br_).as_mut()).ok()
                             }
                         });
                     if let Some(dmx) = ret {
@@ -131,14 +130,14 @@ impl<'a> DemuxerObject<'a> {
                 }
             }
             for rdmx in reg.rdmx_reg.iter() {
-                if rdmx.check_format(br) {
+                if rdmx.check_format(&mut *br) {
                     if print_info {
                         println!("detected {} as {}", name, rdmx.get_name());
                     }
                     br.seek(SeekFrom::Start(0)).unwrap();
-                    let ret = SelfBorrow::try_new(brb, |br_| {
+                    let ret = SelfBorrow::try_new(br, |br_| {
                             unsafe {
-                                create_raw_demuxer(*rdmx, br_.as_mut().unwrap().get_object_mut()).ok()
+                                create_raw_demuxer(*rdmx, (*br_).as_mut()).ok()
                             }
                         });
                     if let Some(dmx) = ret {
@@ -180,13 +179,13 @@ impl<'a> DemuxerObject<'a> {
                 println!("found raw stream of type {} for {}", pname, name);
             }
             let pcreate = reg.pkt_reg.find_packetiser(pname).unwrap();
-            let rctx = SelfBorrow::new(brb, |br_| {
+            let rctx = SelfBorrow::new(br, |br_| {
                     unsafe {
                         let mut packetiser = (pcreate)();
                         packetiser.add_data(&buf[..size]);
                         let stream = packetiser.parse_stream(0).unwrap();
                         packetiser.reset();
-                        RawStreamCtx::new(stream, packetiser, br_.as_mut().unwrap().get_object_mut())
+                        RawStreamCtx::new(stream, packetiser, (*br_).as_mut())
                     }
                 });
             DemuxerObject::RawStream(rctx)
@@ -365,7 +364,7 @@ impl<'a> NAOptionHandler for DemuxerObject<'a> {
     }
 }
 
-pub fn detect_tags(br: &mut ByteReader) -> (bool, u64, Option<u64>) {
+pub fn detect_tags(br: &mut dyn ByteIO) -> (bool, u64, Option<u64>) {
     let mut is_raw = false;
     let mut start = 0;
     let mut end = None;
index 7de339b42b43fa0d04eaa25bb4bc32f8e2198fa4..6d6f598f40e7ab5ff7cde9903df897c159ba7a94 100644 (file)
@@ -246,8 +246,7 @@ impl<'a> NAOptionHandler for ImgSeqDemuxerCreator<'a> {
 }
 
 fn read_pnm_header(file: &mut BufReader<File>, pgmyuv: bool) -> DemuxerResult<NAVideoInfo> {
-    let mut fr = FileReader::new_read(file);
-    let mut br = ByteReader::new(&mut fr);
+    let mut br = FileReader::new_read(file);
 
     let mut magic = [0; 2];
     br.read_buf(&mut magic)?;
@@ -311,7 +310,7 @@ fn read_pnm_header(file: &mut BufReader<File>, pgmyuv: bool) -> DemuxerResult<NA
     Ok(vinfo)
 }
 
-fn read_number(br: &mut ByteReader) -> DemuxerResult<usize> {
+fn read_number(br: &mut dyn ByteIO) -> DemuxerResult<usize> {
     let mut val = 0;
     loop {
         let c = br.read_byte()?;
index 4db5f1adb8ec2fc8cfdc82a05dfb03791c13efe3..bca697ab25e15975d68b20a6e61702ca0c02d7f8 100644 (file)
@@ -248,8 +248,7 @@ fn main() {
             "--query-demuxer-options" => {
                 next_arg!(args, arg_idx);
                 let dname = args[arg_idx].as_str();
-                let mut mr = MemoryReader::new_read(&[]);
-                let mut br = ByteReader::new(&mut mr);
+                let mut br = MemoryReader::new_read(&[]);
                 if let Some(dmx_creator) = full_reg.dmx_reg.find_demuxer(dname) {
                     let dmx = dmx_creator.new_demuxer(&mut br);
                     let opts = dmx.get_supported_options();
@@ -275,8 +274,7 @@ fn main() {
                 next_arg!(args, arg_idx);
                 let name = args[arg_idx].as_str();
                 let mut data = [];
-                let mut mw = MemoryWriter::new_write(&mut data);
-                let mut bw = ByteWriter::new(&mut mw);
+                let mut bw = MemoryWriter::new_write(&mut data);
                 if let Some(mux_creator) = full_reg.mux_reg.find_muxer(name) {
                     let mux = mux_creator.new_muxer(&mut bw);
                     let opts = mux.get_supported_options();
@@ -574,8 +572,7 @@ fn main() {
         println!("cannot open output file");
         return;
     }
-    let mut fw = FileWriter::new_write(ret.unwrap());
-    let mut bw = ByteWriter::new(&mut fw);
+    let mut bw = FileWriter::new_write(ret.unwrap());
     let ret = create_muxer(mux_creator, out_sm, &mut bw);
     if let Err(err) = ret {
         println!("cannot create muxer instance {:?}", err);
index f9e5ed8c068272c283d7835287f0f592f6f50608..5d06ce1a936a5eb2914aa714ea381ab0f8084314 100644 (file)
@@ -59,11 +59,11 @@ pub const NULL_ENCODER: EncoderInfo = EncoderInfo { name: "null", get_encoder };
 
 #[derive(Default)]
 struct NullMuxer<'a> {
-    bw:             PhantomData<&'a mut ByteWriter<'a>>,
+    bw:             PhantomData<&'a mut dyn ByteIO>,
 }
 
 impl<'a> NullMuxer<'a> {
-    fn new(_bw: &'a mut ByteWriter<'a>) -> Self { Self::default() }
+    fn new(_bw: &'a mut dyn ByteIO) -> Self { Self::default() }
 }
 
 impl<'a> MuxCore<'a> for NullMuxer<'a> {
@@ -90,7 +90,7 @@ impl<'a> NAOptionHandler for NullMuxer<'a> {
 pub struct NullMuxerCreator {}
 
 impl MuxerCreator for NullMuxerCreator {
-    fn new_muxer<'a>(&self, bw: &'a mut ByteWriter<'a>) -> Box<dyn MuxCore<'a> + 'a> {
+    fn new_muxer<'a>(&self, bw: &'a mut dyn ByteIO) -> Box<dyn MuxCore<'a> + 'a> {
         Box::new(NullMuxer::new(bw))
     }
     fn get_name(&self) -> &'static str { "null" }
index 5104037aa6f2f90768bdf98bfd634d7e5325e74d..f5520f5a5ffd21a7b07510514d6508f3907b3476 100644 (file)
@@ -1193,24 +1193,18 @@ println!("encoder {} is not supported by output (expected {})", istr.id, istr.ge
                     let file = res.unwrap();
                     let file = BufReader::new(file);
                     let mut fr = FileReader::new_read(file);
-                    let mut br = ByteReader::new(&mut fr);
                     let (is_raw, start, end) = if ifmt.is_none() {
-                            detect_tags(&mut br)
+                            detect_tags(&mut fr)
                         } else {
                             (false, 0, None)
                         };
 
-                    let nfr: Box<dyn ByteIO> = if start != 0 || end.is_some() {
+                    let sb: Box<dyn ByteIO> = if start != 0 || end.is_some() {
                             let file = fr.finish();
                             Box::new(BoundedFileReader::new_read(file, start, end).unwrap())
                         } else {
                             Box::new(fr)
                         };
-                    let sb = SelfBorrow::new(nfr, |rd| {
-                            unsafe {
-                                ByteReader::new(rd.as_mut().unwrap().as_mut())
-                            }
-                        });
 
                     let mut dmx = DemuxerObject::create(sb, full_reg, name, ifmt, is_raw, print_info);
                     if dmx.is_none() {