let out_info = NAVideoInfo::new(vinfo.width, vinfo.height, false, vinfo.format);
let info = NACodecInfo::new("cinepak", NACodecTypeInfo::Video(out_info), None);
- let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den);
+ let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0);
stream.set_num(stream_id as usize);
let stream = stream.into_ref();
NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Audio(_) => {
let info = NACodecInfo::new("pcm", encinfo.format, None);
- let mut stream = NAStream::new(StreamType::Audio, stream_id, info, encinfo.tb_num, encinfo.tb_den);
+ let mut stream = NAStream::new(StreamType::Audio, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0);
stream.set_num(stream_id as usize);
let stream = stream.into_ref();
self.stream = Some(stream.clone());
sstate: StreamState,
tb_num: u32,
tb_den: u32,
+ strm_duration: u32,
key_offs: Vec<u64>,
pal: Vec<PalInfo>,
}
Ok(())
}
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for AVIDemuxer<'a> {
sstate: StreamState::new(),
tb_num: 0,
tb_den: 0,
+ strm_duration: 0,
key_offs: Vec::new(),
pal: Vec::new(),
}
dmx.tb_num = dmx.src.read_u32le()?; //scale
dmx.tb_den = dmx.src.read_u32le()?; //rate
dmx.src.read_skip(4)?; //start
- dmx.src.read_skip(4)?; //length
+ dmx.strm_duration = dmx.src.read_u32le()?;
dmx.src.read_skip(4)?; //buf size
dmx.src.read_skip(4)?; //quality
dmx.src.read_skip(4)?; //sample size
Some(name) => name,
};
let vinfo = NACodecInfo::new(cname, vci, edata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Video, u32::from(dmx.sstate.strm_no), vinfo, dmx.tb_num, dmx.tb_den));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Video, u32::from(dmx.sstate.strm_no), vinfo, dmx.tb_num, dmx.tb_den, u64::from(dmx.strm_duration)));
if res.is_none() { return Err(MemoryError); }
dmx.sstate.reset();
Ok(size)
Some(name) => name,
};
let ainfo = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), edata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, u32::from(dmx.sstate.strm_no), ainfo, dmx.tb_num, dmx.tb_den));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, u32::from(dmx.sstate.strm_no), ainfo, dmx.tb_num, dmx.tb_den, u64::from(dmx.strm_duration)));
if res.is_none() { return Err(MemoryError); }
dmx.sstate.reset();
Ok(size)
fn parse_strf_xxxx(dmx: &mut AVIDemuxer, strmgr: &mut StreamManager, size: usize) -> DemuxerResult<usize> {
let edata = dmx.read_extradata(size)?;
let info = NACodecInfo::new("unknown", NACodecTypeInfo::None, edata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Data, u32::from(dmx.sstate.strm_no), info, dmx.tb_num, dmx.tb_den));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Data, u32::from(dmx.sstate.strm_no), info, dmx.tb_num, dmx.tb_den, u64::from(dmx.strm_duration)));
if res.is_none() { return Err(MemoryError); }
dmx.sstate.reset();
Ok(size)
let _mtime = br.read_u32be()?;
let track_id = br.read_u32be()?;
br.read_skip(4)?;
- let _duration = br.read_u32be()?;
+ let duration = br.read_u32be()?;
br.read_skip(8)?;
let _layer = br.read_u16be()?;
let _alt_group = br.read_u16be()?;
track.width = width >> 16;
track.height = height >> 16;
track.track_id = track_id;
+ track.duration = duration;
track.tkhd_found = true;
Ok(KNOWN_TKHD_SIZE)
};
let read_size = br.tell() - start_pos;
validate!(read_size <= size);
- track.stream = Some(NAStream::new(track.stream_type, track.track_no, codec_info, 1, track.tb_den));
+ track.stream = Some(NAStream::new(track.stream_type, track.track_no, codec_info, 1, track.tb_den, u64::from(track.duration)));
track.stsd_found = true;
Ok(read_size)
}
track_str_id: usize,
track_no: u32,
tb_den: u32,
+ duration: u32,
depth: u8,
tkhd_found: bool,
stsd_found: bool,
track_str_id: 0,
track_no,
tb_den,
+ duration: 0,
stream_type: StreamType::None,
width: 0,
height: 0,
}
Ok(())
}
+ fn get_duration(&self) -> u64 {
+ if self.tb_den != 0 {
+ u64::from(self.duration) * 1000 / u64::from(self.tb_den)
+ } else {
+ 0
+ }
+ }
}
impl<'a> NAOptionHandler for MOVDemuxer<'a> {
block_size: usize,
is_pcm: bool,
avg_bytes: u32,
+ duration: u64,
}
impl<'a> DemuxCore<'a> for WAVDemuxer<'a> {
seek_index.mode = SeekIndexMode::Automatic;
let mut fmt_parsed = false;
- let mut _duration = 0;
+ let mut duration = 0;
while self.src.tell() < riff_end {
let ctype = self.src.read_tag()?;
let csize = self.src.read_u32le()? as usize;
},
b"fact" => {
validate!(csize == 4);
- _duration = self.src.read_u32le()? as usize;
+ duration = self.src.read_u32le()? as usize;
},
b"data" => {
validate!(fmt_parsed);
self.data_pos = self.src.tell();
self.data_end = self.data_pos + (csize as u64);
+
+ if duration != 0 {
+ self.duration = (duration as u64) * 1000 / u64::from(self.srate);
+ } else if self.avg_bytes > 0 {
+ self.duration = (self.data_end - self.data_pos) * 1000 / u64::from(self.avg_bytes);
+ } else {
+ self.duration = 0;
+ }
+
return Ok(());
},
_ => {
Err(DemuxerError::NotImplemented)
}
}
+
+ fn get_duration(&self) -> u64 { self.duration }
}
impl<'a> NAOptionHandler for WAVDemuxer<'a> {
block_size: 0,
is_pcm: false,
avg_bytes: 0,
+ duration: 0,
}
}
fn parse_fmt(&mut self, strmgr: &mut StreamManager, csize: usize) -> DemuxerResult<()> {
};
let ahdr = NAAudioInfo::new(samples_per_sec, channels as u8, soniton, block_align);
let ainfo = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), edata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, 1, samples_per_sec));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, 1, samples_per_sec, 0));
if res.is_none() { return Err(MemoryError); }
self.srate = samples_per_sec;
self.block_size = block_align;
self.avg_bytes = avg_bytes_per_sec;
self.is_pcm = cname == "pcm";
+ if self.is_pcm && self.avg_bytes == 0 {
+ self.avg_bytes = self.block_size as u32 * self.srate;
+ }
Ok(())
}
fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<NAPacket>;
/// Seeks to the requested time.
fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()>;
+ /// Returns container duration in milliseconds (zero if not available).
+ fn get_duration(&self) -> u64;
}
/// An auxiliary trait to make bytestream reader read packet data.
pub fn get_seek_index(&self) -> &SeekIndex {
&self.seek_idx
}
+ /// Returns media duration reported by container or its streams.
+ ///
+ /// Duration is in milliseconds and set to zero when it is not available.
+ pub fn get_duration(&self) -> u64 {
+ let duration = self.dmx.get_duration();
+ if duration != 0 {
+ return duration;
+ }
+ let mut duration = 0;
+ for stream in self.streams.iter() {
+ if stream.duration > 0 {
+ let dur = NATimeInfo::ts_to_time(stream.duration, 1000, stream.tb_num, stream.tb_den);
+ if duration < dur {
+ duration = dur;
+ }
+ }
+ }
+ duration
+ }
}
impl<'a> NAOptionHandler for Demuxer<'a> {
pub tb_num: u32,
/// Timebase denominator.
pub tb_den: u32,
+ /// Duration in timebase units (zero if not available).
+ pub duration: u64,
}
/// A specialised reference-counted `NAStream` type.
impl NAStream {
/// Constructs a new `NAStream` instance.
- pub fn new(mt: StreamType, id: u32, info: NACodecInfo, tb_num: u32, tb_den: u32) -> Self {
+ pub fn new(mt: StreamType, id: u32, info: NACodecInfo, tb_num: u32, tb_den: u32, duration: u64) -> Self {
let (n, d) = reduce_timebase(tb_num, tb_den);
- NAStream { media_type: mt, id, num: 0, info: info.into_ref(), tb_num: n, tb_den: d }
+ NAStream { media_type: mt, id, num: 0, info: info.into_ref(), tb_num: n, tb_den: d, duration }
}
/// Returns stream id.
pub fn get_id(&self) -> u32 { self.id }
self.tb_num = n;
self.tb_den = d;
}
+ /// Returns stream duration.
+ pub fn get_duration(&self) -> usize { self.num }
/// Converts current instance into a reference-counted one.
pub fn into_ref(self) -> NAStreamRef { Arc::new(self) }
}
let vhdr = NAVideoInfo::new(640, 429, false, PAL8_FORMAT);
let vci = NACodecTypeInfo::Video(vhdr);
let vinfo = NACodecInfo::new("bmv-video", vci, None);
- self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 12)).unwrap();
+ self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 12, 0)).unwrap();
let ahdr = NAAudioInfo::new(22050, 2, SND_S16_FORMAT, 1);
let ainfo = NACodecInfo::new("bmv-audio", NACodecTypeInfo::Audio(ahdr), None);
- self.aud_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, 22050)).unwrap();
+ self.aud_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, 22050, 0)).unwrap();
self.vpos = 0;
self.apos = 0;
fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for BMVDemuxer<'a> {
let vhdr = NAVideoInfo::new(width, height, false, RGB565_FORMAT);
let vci = NACodecTypeInfo::Video(vhdr);
let vinfo = NACodecInfo::new("bmv3-video", vci, None);
- self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 256, fps)).unwrap();
+ self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 256, fps, nframes as u64)).unwrap();
let ahdr = NAAudioInfo::new(22050, 2, SND_S16_FORMAT, audio_blob_size);
let ainfo = NACodecInfo::new("bmv3-audio", NACodecTypeInfo::Audio(ahdr), None);
- self.aud_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, 22050)).unwrap();
+ self.aud_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, 22050, 0)).unwrap();
self.vpos = 0;
self.apos = 0;
fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for BMV3Demuxer<'a> {
let vhdr = NAVideoInfo::new(width as usize, height as usize, false, PAL8_FORMAT);
let vci = NACodecTypeInfo::Video(vhdr);
let vinfo = NACodecInfo::new("gdv-video", vci, if edata.is_empty() { None } else { Some(edata) });
- self.v_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, u32::from(fps)));
+ self.v_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, u32::from(fps), u64::from(frames)));
}
if (aflags & 1) != 0 {
let channels = if (aflags & 2) != 0 { 2 } else { 1 };
let ahdr = NAAudioInfo::new(u32::from(rate), channels as u8, if depth == 16 { SND_S16_FORMAT } else { SND_U8_FORMAT }, 2);
let ainfo = NACodecInfo::new(if packed != 0 { "gdv-audio" } else { "pcm" },
NACodecTypeInfo::Audio(ahdr), None);
- self.a_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, u32::from(rate)));
+ self.a_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, u32::from(rate), 0));
self.asize = (((rate / fps) * channels * (depth / 8)) >> packed) as usize;
self.apacked = (aflags & 8) != 0;
fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for GremlinVideoDemuxer<'a> {
fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
let vhdr = NAVideoInfo::new(width, height, false, PAL8_FORMAT);
let vci = NACodecTypeInfo::Video(vhdr);
let vinfo = NACodecInfo::new(if !self.is_indeo { "vmd-video" } else { "indeo3" }, vci, Some(edata));
- self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 12)).unwrap();
+ self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 12, nframes as u64)).unwrap();
let is_ext_audio = (hdr_size & 0xF) == 4;
let ext_audio_id = if is_ext_audio {
}
};
let ainfo = NACodecInfo::new(ac_name, NACodecTypeInfo::Audio(ahdr), Some(aedata));
- self.aud_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, srate)).unwrap();
+ self.aud_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, srate, 0)).unwrap();
} else {
block_size = 0;
}
fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
+
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for VMDDemuxer<'a> {
let vci = NACodecTypeInfo::Video(vhdr);
let edata = [fps as u8].to_vec();
let vinfo = NACodecInfo::new("vxvideo", vci, Some(edata));
- self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, fps)).unwrap();
+ self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, fps, nframes as u64)).unwrap();
if num_audio_tracks != 0 {
validate!(audio_off + ((num_audio_tracks * AUDIO_EXTRADATA_LEN) as u64) == vinfo_off);
src.read_buf(edata.as_mut_slice())?;
let ahdr = NAAudioInfo::new(srate, 1, SND_S16P_FORMAT, 1);
let ainfo = NACodecInfo::new("vxaudio", NACodecTypeInfo::Audio(ahdr), Some(edata));
- self.aud_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, srate)).unwrap();
+ self.aud_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, srate, 0)).unwrap();
self.num_afrm = nframes as u64;
self.ano = 0;
self.num_aud = num_audio_tracks;
fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
+
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for VXDemuxer<'a> {
let ahdr = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, 1);
let ainfo = NACodecInfo::new("ape", NACodecTypeInfo::Audio(ahdr), Some(hdr));
- strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, blocksperframe, srate)).unwrap();
+ strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, blocksperframe, srate, nframes as u64)).unwrap();
self.cur_frame = 0;
Ok(())
}
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for APEDemuxer<'a> {
let base = if self.blk_samples != 0 { u32::from(self.blk_samples) } else { 1 };
let ahdr = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, base as usize);
let ainfo = NACodecInfo::new("flac", NACodecTypeInfo::Audio(ahdr), Some(streaminfo));
- strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, base, srate)).unwrap();
+ strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, base, srate, 0)).unwrap();
Ok(())
}
Err(DemuxerError::NotPossible)
}
}
+ fn get_duration(&self) -> u64 { self.tot_samples * 1000 / u64::from(self.srate) }
}
impl<'a> NAOptionHandler for FLACDemuxer<'a> {
let ahdr = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, 1);
let ainfo = NACodecInfo::new("tta", NACodecTypeInfo::Audio(ahdr), Some(hdr));
- strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, self.framelen, srate)).unwrap();
+ strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, self.framelen, srate, u64::from(self.nframes))).unwrap();
self.cur_frame = 0;
Ok(())
}
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for TTADemuxer<'a> {
let ahdr = NAAudioInfo::new(srate, channels, SND_S16P_FORMAT, 1);
let ainfo = NACodecInfo::new("wavpack", NACodecTypeInfo::Audio(ahdr), Some(buf.clone()));
- strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, 1, srate)).unwrap();
+ strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, 1, srate, hdr.tot_samples)).unwrap();
seek_index.mode = SeekIndexMode::Automatic;
self.srate = srate;
self.known_frames = Vec::with_capacity(((self.nsamples + u64::from(srate) - 1) / u64::from(srate)) as usize);
Err(DemuxerError::NotPossible)
}
}
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for WavPackDemuxer<'a> {
let soniton = NASoniton::new(4, 0);
let out_ainfo = NAAudioInfo::new(ainfo.sample_rate, ainfo.channels, soniton, Self::calc_block_size(self.block_len, self.channels));
let info = NACodecInfo::new("ms-adpcm", NACodecTypeInfo::Audio(out_ainfo), None);
- let mut stream = NAStream::new(StreamType::Audio, stream_id, info.clone(), self.block_len as u32, ainfo.sample_rate);
+ let mut stream = NAStream::new(StreamType::Audio, stream_id, info.clone(), self.block_len as u32, ainfo.sample_rate, 0);
stream.set_num(stream_id as usize);
let stream = stream.into_ref();
let out_info = NAVideoInfo::new(vinfo.width, vinfo.height, true, RGB555_FORMAT);
let info = NACodecInfo::new("msvideo1", NACodecTypeInfo::Video(out_info), None);
- let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den);
+ let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0);
stream.set_num(stream_id as usize);
let stream = stream.into_ref();
if self.pool.prealloc_video(out_info, 2).is_err() {
let mut edata: Vec<u8> = Vec::with_capacity(4);
edata.extend_from_slice(&magic);
let ainfo = NACodecInfo::new(codecname, NACodecTypeInfo::Audio(ahdr), Some(edata));
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, (str_id + 1) as u32, ainfo, 1, srate));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, (str_id + 1) as u32, ainfo, 1, srate, 0));
validate!(res.is_some());
let id = res.unwrap();
Ok(Self{ id })
let vhdr = NAVideoInfo::new(width, height, false, YUV420_FORMAT);
let codec = if magic[0] == b'K' && magic[1] == b'B' && magic[2] == b'2' { "bink2-video" } else { "bink-video" };
let vinfo = NACodecInfo::new(codec, NACodecTypeInfo::Video(vhdr), Some(edata));
- let res = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, self.tb_num, self.tb_den));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, self.tb_num, self.tb_den, self.frames as u64));
validate!(res.is_some());
self.video_id = res.unwrap();
self.cur_frame = seek_info.pts as usize;
Ok(())
}
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for BinkDemuxer<'a> {
let soniton = if (self.flags & SMK_AUD_FLAG_16BIT) != 0 { SND_S16_FORMAT } else { SND_U8_FORMAT };
let ahdr = NAAudioInfo::new(self.srate, channels, soniton, 1);
let ainfo = NACodecInfo::new(codecname, NACodecTypeInfo::Audio(ahdr), None);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, (str_id + 1) as u32, ainfo, 1, self.srate));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, (str_id + 1) as u32, ainfo, 1, self.srate, 0));
validate!(res.is_some());
self.id = res.unwrap();
let vhdr = NAVideoInfo::new(width, height, false, PAL8_FORMAT);
let vinfo = NACodecInfo::new("smacker-video", NACodecTypeInfo::Video(vhdr), Some(treedata));
- let res = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 100000));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 100000, 0));
validate!(res.is_some());
self.video_id = res.unwrap();
}
Err(DemuxerError::NotImplemented)
}
+ fn get_duration(&self) -> u64 { self.frames as u64 * self.pts_inc / 100 }
}
impl<'a> NAOptionHandler for SmackerVideoDemuxer<'a> {
struct RMDemuxCommon {}
impl RMDemuxCommon {
- fn parse_stream_info(str_data: &mut CommonStreamData, strmgr: &mut StreamManager, stream_no: u32, edata: &[u8]) -> DemuxerResult<bool> {
+ fn parse_stream_info(str_data: &mut CommonStreamData, strmgr: &mut StreamManager, stream_no: u32, edata: &[u8], duration: u32) -> DemuxerResult<bool> {
let mut is_mlti = false;
let mut mr = MemoryReader::new_read(edata);
let mut src = ByteReader::new(&mut mr);
let tag2 = src.peek_u32be()?;
//println!("tag1 {:X} tag2 {:X}", tag, tag2);
if tag == mktag!('.', 'r', 'a', 0xFD) {
- Self::parse_audio_stream(strmgr, &mut str_data.streams, stream_no, &mut src, edata)?;
+ Self::parse_audio_stream(strmgr, &mut str_data.streams, stream_no, &mut src, edata, duration)?;
} else if ((tag2 == mktag!('V', 'I', 'D', 'O')) || (tag2 == mktag!('I', 'M', 'A', 'G'))) && ((tag as usize) <= edata.len()) {
- Self::parse_video_stream(strmgr, &mut str_data.streams, stream_no, &mut src, edata, tag2)?;
+ Self::parse_video_stream(strmgr, &mut str_data.streams, stream_no, &mut src, edata, tag2, duration)?;
} else if tag == mktag!(b"LSD:") {
let extradata = Some(edata.to_owned());
let soniton = NASoniton::new(samp_size as u8, SONITON_FLAG_SIGNED);
let ahdr = NAAudioInfo::new(sample_rate, channels as u8, soniton, 1);
let nainfo = NACodecInfo::new("ralf", NACodecTypeInfo::Audio(ahdr), extradata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, nainfo, 1, 1000));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, nainfo, 1, 1000, u64::from(duration)));
if res.is_none() { return Err(MemoryError); }
let astr = RMAudioStream::new(None);
str_data.streams.push(RMStreamType::Audio(astr));
let stream_no = str_data.mlti_mapper.get_substream_no();
//todo check that all substreams are of the same type");
if tag == mktag!('.', 'r', 'a', 0xFD) {
- Self::parse_audio_stream(strmgr, &mut str_data.streams, stream_no, &mut hsrc, hdrsrc)?;
+ Self::parse_audio_stream(strmgr, &mut str_data.streams, stream_no, &mut hsrc, hdrsrc, duration)?;
} else if (tag2 == mktag!('V', 'I', 'D', 'O')) && ((tag as usize) <= hdr_size) {
- Self::parse_video_stream(strmgr, &mut str_data.streams, stream_no, &mut hsrc, hdrsrc, tag2)?;
+ Self::parse_video_stream(strmgr, &mut str_data.streams, stream_no, &mut hsrc, hdrsrc, tag2, duration)?;
} else {
println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2);
return Err(DemuxerError::InvalidData);
}
Ok(is_mlti)
}
- fn parse_audio_stream(strmgr: &mut StreamManager, streams: &mut Vec<RMStreamType>, stream_no: u32, src: &mut ByteReader, edata_: &[u8]) -> DemuxerResult<()> {
+ fn parse_audio_stream(strmgr: &mut StreamManager, streams: &mut Vec<RMStreamType>, stream_no: u32, src: &mut ByteReader, edata_: &[u8], duration: u32) -> DemuxerResult<()> {
let ver = src.read_u16be()?;
let ainfo = match ver {
3 => {
let eslice = &edata_[(src.tell() as usize)..];
Some(eslice.to_vec())
};
+ let duration = if duration == 0 { ainfo.get_duration(1000) } else { u64::from(duration) };
let nainfo = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), extradata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, nainfo, 1, 1000));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, nainfo, 1, 1000, duration));
if res.is_none() { return Err(MemoryError); }
let astr = RMAudioStream::new(ainfo.ileave_info);
Ok(())
}
#[allow(unused_variables)]
- fn parse_video_stream(strmgr: &mut StreamManager, streams: &mut Vec<RMStreamType>, stream_no: u32, src: &mut ByteReader, edata_: &[u8], tag2: u32) -> DemuxerResult<()> {
+ fn parse_video_stream(strmgr: &mut StreamManager, streams: &mut Vec<RMStreamType>, stream_no: u32, src: &mut ByteReader, edata_: &[u8], tag2: u32, duration: u32) -> DemuxerResult<()> {
src.read_skip(4)?;
let fcc = src.read_u32be()?;
let width = src.read_u16be()? as usize;
let vhdr = NAVideoInfo::new(width, height, false, RGB24_FORMAT);
let vinfo = NACodecInfo::new(cname, NACodecTypeInfo::Video(vhdr), extradata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Video, stream_no as u32, vinfo, 1, 1000));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Video, stream_no as u32, vinfo, 1, 1000, u64::from(duration)));
if res.is_none() { return Err(DemuxerError::MemoryError); }
let vstr = RMVideoStream::new();
}
Err(DemuxerError::SeekError)
}
+
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for RealMediaDemuxer<'a> {
ileave_info: Option<InterleaveInfo>
}
+impl RealAudioInfo {
+ fn get_duration(&self, base: u32) -> u64 {
+ if self.bytes_per_minute != 0 {
+ u64::from(self.total_bytes) * 60 * u64::from(base) / u64::from(self.bytes_per_minute)
+ } else {
+ 0
+ }
+ }
+}
+
fn skip_ra_metadata(src: &mut ByteReader) -> DemuxerResult<()> {
let title_len = src.read_byte()? as usize;
src.read_skip(title_len)?;
let mut is_mlti = false;
if edata_size > 8 {
if let Some(edata_) = edata {
- is_mlti = RMDemuxCommon::parse_stream_info(&mut self.str_data, strmgr, stream_no, &edata_)?;
+ is_mlti = RMDemuxCommon::parse_stream_info(&mut self.str_data, strmgr, stream_no, &edata_, duration)?;
}
} else {
self.str_data.streams.push(RMStreamType::Unknown);
Some(dta)
};
let nainfo = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), extradata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, 0, nainfo, 1, srate));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, 0, nainfo, 1, srate, ainfo.get_duration(ainfo.sample_rate)));
if res.is_none() { return Err(MemoryError); }
let astr = RMAudioStream::new(ainfo.ileave_info);
fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
Err(NotImplemented)
}
+
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for RealAudioDemuxer<'a> {
cur_str_no += 1;
let mut parsed = false;
let mut real_stream_no = 0;
+ let mut duration = 0;
for _ in 0..num {
let rec = IVRRecord::read(src)?;
//println!(" strm property {}", rec);
if name == b"StreamNumber\0" {
real_stream_no = val;
}
+ if name == b"Duration\0" {
+ duration = val;
+ }
},
IVRRecord::BinaryData(ref name, ref val) => {
if name == b"OpaqueData\0" {
validate!(!parsed);
- let is_mlti = RMDemuxCommon::parse_stream_info(str_data, strmgr, stream_no, val)?;
+ let is_mlti = RMDemuxCommon::parse_stream_info(str_data, strmgr, stream_no, val, duration)?;
if !is_mlti {
str_data.str_ids.push(stream_no);
}
fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
Err(NotImplemented)
}
+
+ fn get_duration(&self) -> u64 { 0 }
}
impl<'a> NAOptionHandler for RealIVRDemuxer<'a> {
fps: f32,
width: usize,
height: usize,
+ duration: u64,
vname: &'static str,
aname: &'static str,
}
let vhdr = NAVideoInfo::new(self.width, self.height, false, YUV420_FORMAT);
let vinfo = NACodecInfo::new(self.vname, NACodecTypeInfo::Video(vhdr), None);
- let res = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, self.v_num, self.v_den));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, self.v_num, self.v_den, 0));
validate!(res.is_some());
self.video_id = res.unwrap();
if self.aname != "none" {
let ahdr = NAAudioInfo::new(self.a_den, 1, SND_S16_FORMAT, self.a_num as usize);
let ainfo = NACodecInfo::new(self.aname, NACodecTypeInfo::Audio(ahdr), None);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, self.a_num, self.a_den));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, self.a_num, self.a_den, 0));
validate!(res.is_some());
self.audio_id = res.unwrap();
}
fn seek(&mut self, _time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
+ fn get_duration(&self) -> u64 { self.duration }
}
impl<'a> NAOptionHandler for VivoDemuxer<'a> {
width: 0,
height: 0,
fps: 0.0,
+ duration: 0,
vname: "none",
aname: "none",
}
return Err(DemuxerError::InvalidData);
};
},
+ b"Duration" => {
+ self.duration = if let Ok(val) = valstr.parse() {
+ val
+ } else { 0 };
+ },
/* b"TimeUnitNumerator" => {
self.v_num = if let Ok(val) = valstr.parse() {
val