changeset 24904:75e930e20f48

repeat the PSM once every second (in terms of delta_scr) otherwise playing the file from the middle would miss the first instance
author nicodvb
date Fri, 02 Nov 2007 17:48:27 +0000
parents b4cdc74f4496
children 170dcb44069a
files libmpdemux/muxer_mpeg.c
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/muxer_mpeg.c	Fri Nov 02 17:43:39 2007 +0000
+++ b/libmpdemux/muxer_mpeg.c	Fri Nov 02 17:48:27 2007 +0000
@@ -142,6 +142,7 @@
 	off_t headers_size, data_size;
 	uint64_t scr;
 	uint64_t delta_scr;
+	uint64_t last_psm_scr;
 	uint32_t muxrate;
 	uint8_t *buff;
 	uint32_t headers_cnt;
@@ -663,6 +664,11 @@
 	return len;
 }
 
+static int psm_is_late(muxer_priv_t *priv)
+{
+	return (priv->scr >= priv->last_psm_scr + 27000000ULL);
+}
+
 static int write_mpeg_pes_header(muxer_headers_t *h, uint8_t *pes_id, uint8_t *buff, uint16_t plen, int stuffing_len, int mux_type)
 {
 	int len;
@@ -797,6 +803,11 @@
 	return len;
 }
 
+static unsigned int calc_psm_len(muxer_priv_t *priv)
+{
+	return 16 + 4*(priv->psm_info.cnt);
+}
+
 static uint32_t calc_pes_hlen(int format, muxer_headers_t *h, muxer_priv_t *priv)
 {
 	uint32_t len;
@@ -1042,6 +1053,8 @@
 		pack_hlen = 12;
 	else
 		pack_hlen = 14;
+	if(priv->use_psm && psm_is_late(priv))
+		pack_hlen += calc_psm_len(priv);
 
 	if(find_packet_timestamps(priv, s, pack_hlen, &dts, &pts))
 	{
@@ -1122,6 +1135,7 @@
 	muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
 	muxer_headers_t *spriv = (muxer_headers_t *) s->priv;
 	int len, m, n, dvd_pack = 0;
+	int write_psm = 0;
 	mpeg_frame_t *frm;
 	pack_stats_t p;
 
@@ -1144,6 +1158,13 @@
 			spriv->pack_offset += write_mpeg_system_header(muxer, &spriv->pack[spriv->pack_offset]);
 			priv->update_system_header = 0;
 		}
+
+		if(priv->use_psm && psm_is_late(priv))
+		{
+			spriv->pack_offset += write_mpeg_psm(muxer, &spriv->pack[spriv->pack_offset]);
+			write_psm = 1;
+		}
+
 		spriv->pes_set = 0;
 		spriv->pes_offset = spriv->pack_offset;
 		spriv->payload_offset = 0;
@@ -1273,6 +1294,8 @@
 	spriv->pack_offset = 0;
 	spriv->pes_set = 0;
 	spriv->frames = 0;
+	if(write_psm)
+		priv->last_psm_scr = priv->scr;
 	
 	return len;
 }