changeset 26038:4f9a30caadff

read the PCR of the currently playing program (if available) in demuxer->reference_clock
author nicodvb
date Sat, 23 Feb 2008 10:38:24 +0000
parents bee99864f397
children aa0784c046d1
files libmpdemux/demux_ts.c
diffstat 1 files changed, 45 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_ts.c	Sat Feb 23 10:31:44 2008 +0000
+++ b/libmpdemux/demux_ts.c	Sat Feb 23 10:38:24 2008 +0000
@@ -502,6 +502,20 @@
 	return -1;
 }
 
+static inline int32_t prog_pcr_pid(ts_priv_t *priv, int progid)
+{
+	int i;
+
+	if(priv->pmt == NULL)
+		return -1;
+	for(i=0; i < priv->pmt_cnt; i++)
+	{
+		if(priv->pmt[i].progid == progid)
+			return priv->pmt[i].PCR_PID;
+	}
+	return -1;
+}
+
 
 static inline int pid_match_lang(ts_priv_t *priv, uint16_t pid, char *lang)
 {
@@ -1036,6 +1050,7 @@
 
 	start_pos = (start_pos <= priv->ts.packet_size ? 0 : start_pos - priv->ts.packet_size);
 	demuxer->movi_start = start_pos;
+	demuxer->reference_clock = MP_NOPTS_VALUE;
 	stream_reset(demuxer->stream);
 	stream_seek(demuxer->stream, start_pos);	//IF IT'S FROM A PIPE IT WILL FAIL, BUT WHO CARES?
 
@@ -2726,11 +2741,38 @@
 			//c==0 is allowed!
 			if(c > 0)
 			{
-				rap_flag = (stream_read_char(stream) & 0x40) >> 6;
+				uint8_t pcrbuf[188];
+				int flags = stream_read_char(stream);
+				int has_pcr;
+				rap_flag = (flags & 0x40) >> 6;
+				has_pcr = flags & 0x10;
+				
 				buf_size--;
+				c--;
+				stream_read(stream, pcrbuf, c);
+
+				if(has_pcr)
+				{
+					int pcr_pid = prog_pcr_pid(priv, priv->prog);
+					if(pcr_pid == pid)
+					{
+						uint64_t pcr, pcr_ext;
 	
-				c--;
-				stream_skip(stream, c);
+						pcr  = (int64_t)(pcrbuf[0]) << 25;
+						pcr |=  pcrbuf[1]         << 17 ;
+						pcr |= (pcrbuf[2]) << 9;
+						pcr |=  pcrbuf[3]  <<  1 ;
+						pcr |= (pcrbuf[4] & 0x80) >>  7;
+	
+						pcr_ext = (pcrbuf[4] & 0x01) << 8;
+						pcr_ext |= pcrbuf[5];
+	
+						pcr = pcr * 300 + pcr_ext;
+						
+						demuxer->reference_clock = (double)pcr/(double)27000000.0;
+					}
+				}
+				
 				buf_size -= c;
 				if(buf_size == 0)
 					continue;