-use std::rc::Rc;
pub use crate::frame::*;
pub use crate::io::byteio::*;
}
pub trait NAPacketReader {
- fn read_packet(&mut self, str: Rc<NAStream>, ts: NATimeInfo, keyframe: bool, size: usize) -> DemuxerResult<NAPacket>;
+ fn read_packet(&mut self, str: NAStreamRef, ts: NATimeInfo, keyframe: bool, size: usize) -> DemuxerResult<NAPacket>;
fn fill_packet(&mut self, pkt: &mut NAPacket) -> DemuxerResult<()>;
}
impl<'a> NAPacketReader for ByteReader<'a> {
- fn read_packet(&mut self, str: Rc<NAStream>, ts: NATimeInfo, kf: bool, size: usize) -> DemuxerResult<NAPacket> {
+ fn read_packet(&mut self, str: NAStreamRef, ts: NATimeInfo, kf: bool, size: usize) -> DemuxerResult<NAPacket> {
let mut buf: Vec<u8> = Vec::with_capacity(size);
if buf.capacity() < size { return Err(DemuxerError::MemoryError); }
buf.resize(size, 0);
}
pub struct StreamManager {
- streams: Vec<Rc<NAStream>>,
+ streams: Vec<NAStreamRef>,
ignored: Vec<bool>,
no_ign: bool,
}
let stream_num = self.streams.len();
let mut str = stream.clone();
str.set_num(stream_num);
- self.streams.push(Rc::new(str));
+ self.streams.push(str.into_ref());
self.ignored.push(false);
Some(stream_num)
}
- pub fn get_stream(&self, idx: usize) -> Option<Rc<NAStream>> {
+ pub fn get_stream(&self, idx: usize) -> Option<NAStreamRef> {
if idx < self.streams.len() {
Some(self.streams[idx].clone())
} else {
None
}
}
- pub fn get_stream_by_id(&self, id: u32) -> Option<Rc<NAStream>> {
+ pub fn get_stream_by_id(&self, id: u32) -> Option<NAStreamRef> {
for i in 0..self.streams.len() {
if self.streams[i].get_id() == id {
return Some(self.streams[i].clone());
}
pub struct StreamIter<'a> {
- streams: &'a Vec<Rc<NAStream>>,
+ streams: &'a Vec<NAStreamRef>,
pos: usize,
}
impl<'a> StreamIter<'a> {
- pub fn new(streams: &'a Vec<Rc<NAStream>>) -> Self {
+ pub fn new(streams: &'a Vec<NAStreamRef>) -> Self {
StreamIter { streams: streams, pos: 0 }
}
}
impl<'a> Iterator for StreamIter<'a> {
- type Item = Rc<NAStream>;
+ type Item = NAStreamRef;
fn next(&mut self) -> Option<Self::Item> {
if self.pos >= self.streams.len() { return None; }
streams: str,
}
}
- pub fn get_stream(&self, idx: usize) -> Option<Rc<NAStream>> {
+ pub fn get_stream(&self, idx: usize) -> Option<NAStreamRef> {
self.streams.get_stream(idx)
}
- pub fn get_stream_by_id(&self, id: u32) -> Option<Rc<NAStream>> {
+ pub fn get_stream_by_id(&self, id: u32) -> Option<NAStreamRef> {
self.streams.get_stream_by_id(id)
}
pub fn get_num_streams(&self) -> usize {
tb_den: u32,
}
+pub type NAStreamRef = Arc<NAStream>;
+
pub fn reduce_timebase(tb_num: u32, tb_den: u32) -> (u32, u32) {
if tb_num == 0 { return (tb_num, tb_den); }
if (tb_den % tb_num) == 0 { return (1, tb_den / tb_num); }
self.tb_num = n;
self.tb_den = d;
}
+ pub fn into_ref(self) -> NAStreamRef { Arc::new(self) }
}
impl fmt::Display for NAStream {
#[allow(dead_code)]
pub struct NAPacket {
- stream: Rc<NAStream>,
+ stream: NAStreamRef,
ts: NATimeInfo,
buffer: NABufferRef<Vec<u8>>,
keyframe: bool,
}
impl NAPacket {
- pub fn new(str: Rc<NAStream>, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
+ pub fn new(str: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
// let mut vec: Vec<u8> = Vec::new();
// vec.resize(size, 0);
NAPacket { stream: str, ts: ts, keyframe: kf, buffer: NABufferRef::new(vec) }
}
- pub fn get_stream(&self) -> Rc<NAStream> { self.stream.clone() }
+ pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() }
pub fn get_time_information(&self) -> NATimeInfo { self.ts }
pub fn get_pts(&self) -> Option<u64> { self.ts.get_pts() }
pub fn get_dts(&self) -> Option<u64> { self.ts.get_dts() }
-use std::rc::Rc;
use nihav_core::demuxers::*;
macro_rules! validate {
}
RMAudioStream { deint: deint, iinfo: iinfo, buf: buf, sub_packet: 0 }
}
- fn read_apackets(&mut self, queued_packets: &mut Vec<NAPacket>, src: &mut ByteReader, stream: Rc<NAStream>, ts: u32, keyframe: bool, payload_size: usize) -> DemuxerResult<NAPacket> {
+ fn read_apackets(&mut self, queued_packets: &mut Vec<NAPacket>, src: &mut ByteReader, stream: NAStreamRef, ts: u32, keyframe: bool, payload_size: usize) -> DemuxerResult<NAPacket> {
let (tb_num, tb_den) = stream.get_timebase();
let ts = NATimeInfo::new(Some(ts as u64), None, None, tb_num, tb_den);
}
}
-fn read_video_buf(src: &mut ByteReader, stream: Rc<NAStream>, ts: u32, keyframe: bool, frame_size: usize) -> DemuxerResult<NAPacket> {
+fn read_video_buf(src: &mut ByteReader, stream: NAStreamRef, ts: u32, keyframe: bool, frame_size: usize) -> DemuxerResult<NAPacket> {
let size = (frame_size as usize) + 9;
let mut vec: Vec<u8> = Vec::with_capacity(size);
vec.resize(size, 0);
Ok(NAPacket::new(stream, ts, keyframe, vec))
}
-fn read_multiple_frame(src: &mut ByteReader, stream: Rc<NAStream>, keyframe: bool, skip_mtype: bool) -> DemuxerResult<NAPacket> {
+fn read_multiple_frame(src: &mut ByteReader, stream: NAStreamRef, keyframe: bool, skip_mtype: bool) -> DemuxerResult<NAPacket> {
if !skip_mtype {
let mtype = src.read_byte()?;
validate!(mtype == 0xC0);
Ok(())
}
#[allow(unused_variables)]
- fn parse_packet_payload(src: &mut ByteReader, rmstream: &mut RMStreamType, stream: Rc<NAStream>, slice_buf: &mut Vec<u8>, queued_pkts: &mut Vec<NAPacket>, keyframe: bool, ts: u32, payload_size: usize) -> DemuxerResult<NAPacket> {
+ fn parse_packet_payload(src: &mut ByteReader, rmstream: &mut RMStreamType, stream: NAStreamRef, slice_buf: &mut Vec<u8>, queued_pkts: &mut Vec<NAPacket>, keyframe: bool, ts: u32, payload_size: usize) -> DemuxerResult<NAPacket> {
match rmstream {
RMStreamType::Video(ref mut vstr) => {