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 nihav_allstuff::*;
pub struct FullRegister {
pub struct RawStreamCtx<'a> {
stream: NAStreamRef,
pkt: Box<dyn NAPacketiser + Send>,
- br: &'a mut ByteReader<'a>,
+ br: &'a mut dyn ByteIO,
pts: u64,
seek: SeekIndex,
}
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 seek = SeekIndex::new();
seek.add_stream(0);
Self { stream, pkt: packetiser, br, pts: 0, seek }
}
impl<'a> DemuxerObject<'a> {
- pub fn create(br: &'a mut ByteReader<'a>, reg: &FullRegister, name: &str, force_dmx: Option<&str>, is_raw: bool, opts: &[NAOption]) -> DemuxerObject<'a> {
+ pub fn create(br: &'a mut dyn ByteIO, reg: &FullRegister, name: &str, force_dmx: Option<&str>, is_raw: bool, opts: &[NAOption]) -> DemuxerObject<'a> {
if !is_raw {
let res = detect::detect_format(name, br);
if let Some(dmx_name) = force_dmx {
}
}
-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;
}
struct AudioOutput {
- wwr: WavWriter<'static>,
+ wwr: WavWriter,
wrote_header: bool,
}
let file = File::open(path).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) = detect_tags(&mut br);
+ let (is_raw, start, end) = detect_tags(&mut fr);
- let mut nfr: Box<dyn ByteIO>;
+ let mut br: Box<dyn ByteIO>;
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 full_reg = FullRegister::new();
- let mut demuxer = DemuxerObject::create(&mut br, &full_reg, name, force_dmx, is_raw, &demux_opts);
+ let mut demuxer = DemuxerObject::create(br.as_mut(), &full_reg, name, force_dmx, is_raw, &demux_opts);
if demuxer.is_none() {
println!("No demuxer found!");
return;
use nihav_core::io::byteio::*;
use nihav_core::frame::*;
use std::fs::File;
-use std::io::SeekFrom;
+use std::io::{BufWriter,SeekFrom};
-pub struct WavWriter<'a> {
- io: Box<ByteWriter<'a>>,
+pub struct WavWriter {
+ io: FileWriter<BufWriter<File>>,
data_pos: u64,
be: bool,
bits: u8,
}
-fn write_byte(wr: &mut ByteWriter, sample: u8) -> ByteIOResult<()> {
+fn write_byte(wr: &mut dyn ByteIO, sample: u8) -> ByteIOResult<()> {
wr.write_byte(sample)
}
-fn write_s16(wr: &mut ByteWriter, sample: i16) -> ByteIOResult<()> {
+fn write_s16(wr: &mut dyn ByteIO, sample: i16) -> ByteIOResult<()> {
wr.write_u16le(sample as u16)
}
-fn write_s32(wr: &mut ByteWriter, sample: i32) -> ByteIOResult<()> {
+fn write_s32(wr: &mut dyn ByteIO, sample: i32) -> ByteIOResult<()> {
wr.write_u16le((sample >> 16) as u16)
}
-fn write_f32(wr: &mut ByteWriter, sample: f32) -> ByteIOResult<()> {
+fn write_f32(wr: &mut dyn ByteIO, sample: f32) -> ByteIOResult<()> {
let mut out = (sample * 32768.0) as i32;
if out < -32768 { out = -32768; }
if out > 32767 { out = 32767; }
})
}
-impl<'a> WavWriter<'a> {
+impl WavWriter {
pub fn new(name: &str) -> Self {
let file = File::create(name).unwrap();
- let file = std::io::BufWriter::new(file);
- let fw = Box::new(FileWriter::new_write(file));
- let io = ByteWriter::new(Box::leak(fw));
- WavWriter { io: Box::new(io), data_pos: 0, be: false, bits: 0 }
+ let file = BufWriter::new(file);
+ WavWriter { io: FileWriter::new_write(file), data_pos: 0, be: false, bits: 0 }
}
pub fn write_header(&mut self, ainfo: NAAudioInfo) -> ByteIOResult<()> {
let bits = ainfo.get_format().get_bits() as usize;
}
}
-impl<'a> Drop for WavWriter<'a> {
+impl Drop for WavWriter {
#[allow(unused_variables)]
fn drop(&mut self) {
let size = self.io.tell();