aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2021-11-18 14:11:27 +0100
committerKostya Shishkov <kostya.shishkov@gmail.com>2021-11-18 14:11:27 +0100
commit206dd66da4041e2c1aedd7a97840cbba2b44957c (patch)
tree96cbe789a5e691c3501f88ae0d9d0b1238469794
parent3e82df4aa941776da78eccc5d6c9fe875ea482cf (diff)
downloadnihav-encoder-206dd66da4041e2c1aedd7a97840cbba2b44957c.tar.gz
calculate PTS for raw stream if needed and possible
-rw-r--r--src/demux.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/demux.rs b/src/demux.rs
index 73ed14f..28f564d 100644
--- a/src/demux.rs
+++ b/src/demux.rs
@@ -41,13 +41,14 @@ pub struct RawStreamCtx<'a> {
sm: StreamManager,
packetiser: Box<dyn NAPacketiser + Send>,
br: &'a mut ByteReader<'a>,
+ pts: u64,
}
impl<'a> RawStreamCtx<'a> {
fn new(stream: NAStreamRef, packetiser: Box<dyn NAPacketiser + Send>, br: &'a mut ByteReader<'a>) -> Self {
let mut sm = StreamManager::new();
sm.add_stream_ref(stream.clone());
- Self { stream, sm, packetiser, br }
+ Self { stream, sm, packetiser, br, pts: 0 }
}
}
@@ -230,7 +231,13 @@ impl<'a> DemuxerObject<'a> {
let mut buf = [0; 65536];
loop {
match ctx.packetiser.get_packet(ctx.stream.clone()) {
- Ok(Some(packet)) => return Ok(packet),
+ Ok(Some(mut packet)) => {
+ if packet.get_pts().is_none() && packet.get_duration().is_some() {
+ packet.ts.pts = Some(ctx.pts);
+ }
+ ctx.pts += packet.get_duration().unwrap_or(0);
+ return Ok(packet);
+ },
Ok(None) => {},
Err(DecoderError::ShortData) => {},
_ => return Err(DemuxerError::InvalidData),
@@ -241,7 +248,13 @@ impl<'a> DemuxerObject<'a> {
},
Err(_) => {
match ctx.packetiser.get_packet(ctx.stream.clone()) {
- Ok(Some(packet)) => return Ok(packet),
+ Ok(Some(mut packet)) => {
+ if packet.get_pts().is_none() && packet.get_duration().is_some() {
+ packet.ts.pts = Some(ctx.pts);
+ }
+ ctx.pts += packet.get_duration().unwrap_or(0);
+ return Ok(packet);
+ },
Ok(None) | Err(DecoderError::ShortData) => return Err(DemuxerError::EOF),
_ => return Err(DemuxerError::InvalidData),
};