From: Kostya Shishkov Date: Mon, 18 Aug 2025 17:09:28 +0000 (+0200) Subject: switch to ByteIO X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=7d46fb05406fef01b4c418b392c4064456af42ce;p=nihav-player.git switch to ByteIO --- diff --git a/hwdec-vaapi/src/lib.rs b/hwdec-vaapi/src/lib.rs index 85749d4..7b89a2a 100644 --- a/hwdec-vaapi/src/lib.rs +++ b/hwdec-vaapi/src/lib.rs @@ -522,8 +522,7 @@ impl VaapiH264Decoder { let profile; let mut nal_buf = Vec::with_capacity(1024); if edata.len() > 11 && &edata[0..4] == b"avcC" { - let mut mr = MemoryReader::new_read(edata.as_slice()); - let mut br = ByteReader::new(&mut mr); + let mut br = MemoryReader::new_read(edata.as_slice()); br.read_skip(4)?; let version = br.read_byte()?; @@ -695,8 +694,7 @@ panic!("ran out of free surfaces"); self.tb_num = pkt.ts.tb_num; self.tb_den = pkt.ts.tb_den; - let mut mr = MemoryReader::new_read(&src); - let mut br = ByteReader::new(&mut mr); + let mut br = MemoryReader::new_read(&src); let mut frame_type = FrameType::I; let mut nal_buf = Vec::with_capacity(1024); while br.left() > 0 { @@ -1360,8 +1358,7 @@ mod test { fn decode_h264(name: &str, dname: &str, dmx_reg: &RegisteredDemuxers, opfx: &str) -> DecoderResult<()> { let dmx_f = dmx_reg.find_demuxer(dname).expect("demuxer exists"); let file = std::fs::File::open(name).expect("file exists"); - let mut fr = FileReader::new_read(file); - let mut br = ByteReader::new(&mut fr); + let mut br = FileReader::new_read(file); let mut dmx = create_demuxer(dmx_f, &mut br).expect("create demuxer"); let mut vstream_id = 0; diff --git a/sndplay/src/demux.rs b/sndplay/src/demux.rs index d050bce..f8e3c75 100644 --- a/sndplay/src/demux.rs +++ b/sndplay/src/demux.rs @@ -2,19 +2,19 @@ use std::io::SeekFrom; use nihav_core::codecs::*; use nihav_core::demuxers::*; use nihav_registry::detect; -use nihav_core::io::byteio::ByteReader; +use nihav_core::io::byteio::ByteIO; use super::allreg::FullRegister; pub struct RawStreamCtx<'a> { stream: NAStreamRef, pkt: Box, - br: &'a mut ByteReader<'a>, + br: &'a mut dyn ByteIO, pts: u64, seek: SeekIndex, } impl<'a> RawStreamCtx<'a> { - fn new(stream: NAStreamRef, packetiser: Box, br: &'a mut ByteReader<'a>) -> Self { + fn new(stream: NAStreamRef, packetiser: Box, br: &'a mut dyn ByteIO) -> Self { let mut seek = SeekIndex::new(); seek.add_stream(0); Self { stream, pkt: packetiser, br, pts: 0, seek } @@ -77,7 +77,7 @@ pub enum DemuxerObject<'a> { } impl<'a> DemuxerObject<'a> { - pub fn create(br: &'a mut ByteReader<'a>, reg: &FullRegister, name: &str, is_raw: bool) -> DemuxerObject<'a> { + pub fn create(br: &'a mut dyn ByteIO, reg: &FullRegister, name: &str, is_raw: bool) -> DemuxerObject<'a> { if !is_raw { let res = detect::detect_format(name, br); let (dmx_name, _) = res.unwrap_or(("", detect::DetectionScore::No)); @@ -273,7 +273,7 @@ impl<'a> DemuxerObject<'a> { } } -pub fn detect_tags(br: &mut ByteReader) -> (bool, u64, Option) { +pub fn detect_tags(br: &mut dyn ByteIO) -> (bool, u64, Option) { let mut is_raw = false; let mut start = 0; let mut end = None; diff --git a/sndplay/src/main.rs b/sndplay/src/main.rs index 97ed349..4baf2ac 100644 --- a/sndplay/src/main.rs +++ b/sndplay/src/main.rs @@ -10,7 +10,7 @@ use std::sync::mpsc; use std::time::Duration; use std::thread; use sdl2_sys::{SDL_AudioSpec, Uint32}; -use nihav_core::io::byteio::{FileReader, ByteReader}; +use nihav_core::io::byteio::{ByteIO,FileReader}; use nihav_core::frame::*; use nihav_core::codecs::*; use nihav_core::demuxers::*; @@ -247,23 +247,21 @@ impl Player { let file = BufReader::new(file); let mut fr = FileReader::new_read(file); - let mut br = ByteReader::new(&mut fr); - if br.peek_byte().is_err() { + if fr.peek_byte().is_err() { println!("Cannot read {}", name); return; } - let (is_raw, start, end) = detect_tags(&mut br); + let (is_raw, start, end) = detect_tags(&mut fr); - let mut nfr: Box; + let mut br: Box; if start != 0 || end.is_some() { //println!(" limiting range to {:X}-{:X}", start, end.unwrap_or(0)); let file = fr.finish(); - nfr = Box::new(BoundedFileReader::new_read(file, start, end).unwrap()); + br = Box::new(BoundedFileReader::new_read(file, start, end).unwrap()); } else { - nfr = Box::new(fr); + br = Box::new(fr); } - let mut br = ByteReader::new(nfr.as_mut()); - let dmx = DemuxerObject::create(&mut br, &self.full_reg, name, is_raw); + let dmx = DemuxerObject::create(br.as_mut(), &self.full_reg, name, is_raw); if dmx.is_none() { println!("No demuxer found!"); return; diff --git a/videoplayer/src/main.rs b/videoplayer/src/main.rs index 94dea16..bb1231d 100644 --- a/videoplayer/src/main.rs +++ b/videoplayer/src/main.rs @@ -20,7 +20,7 @@ use sdl2::video::{Window, WindowContext}; use nihav_registry::detect; use nihav_core::frame::*; -use nihav_core::io::byteio::{FileReader, ByteReader}; +use nihav_core::io::byteio::{ByteIO,FileReader}; use nihav_core::reorder::*; use nihav_core::codecs::*; use nihav_core::demuxers::*; @@ -608,8 +608,7 @@ impl Player { println!("failed to open {}", name); return window; }; - let mut fr = FileReader::new_read(&mut file); - let mut br = ByteReader::new(&mut fr); + let mut br = FileReader::new_read(&mut file); let res = detect::detect_format(name, &mut br); if res.is_none() { println!("cannot detect format for {}", name);