mpegtspacketizer: clock fix and minor addition
authorEdward Hervey <edward.hervey@collabora.co.uk>
Thu, 1 Mar 2012 16:53:41 +0000 (17:53 +0100)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Thu, 1 Mar 2012 17:15:51 +0000 (18:15 +0100)
* Don't take into account packets that arrived at the same time as
  previous ones for clock skew estimation
* Add convenience method for processing the next ts packet

gst/mpegtsdemux/mpegtspacketizer.c
gst/mpegtsdemux/mpegtspacketizer.h

index 1bc93564069f15deecdf9f79b33dc801dec7d64e..dc1192220184f07af0a8a4f0b5df4d72bf635a1e 100644 (file)
@@ -212,7 +212,7 @@ mpegts_packetizer_finalize (GObject * object)
     G_OBJECT_CLASS (mpegts_packetizer_parent_class)->finalize (object);
 }
 
-guint64
+static inline guint64
 mpegts_packetizer_compute_pcr (const guint8 * data)
 {
   guint32 pcr1;
@@ -2318,6 +2318,14 @@ done:
   return PACKET_NEED_MORE;
 }
 
+MpegTSPacketizerPacketReturn
+mpegts_packetizer_process_next_packet (MpegTSPacketizer2 * packetizer)
+{
+  MpegTSPacketizerPacket packet;
+
+  return mpegts_packetizer_next_packet (packetizer, &packet);
+}
+
 void
 mpegts_packetizer_clear_packet (MpegTSPacketizer2 * packetizer,
     MpegTSPacketizerPacket * packet)
@@ -2927,6 +2935,11 @@ calculate_skew (MpegTSPacketizer2 * packetizer, guint64 pcrtime,
   /* elapsed time at receiver, includes the jitter */
   recv_diff = time - packetizer->base_time;
 
+  /* Ignore packets received at 100% the same time (i.e. from the same input buffer) */
+  if (G_UNLIKELY (time == packetizer->prev_in_time
+          && GST_CLOCK_TIME_IS_VALID (packetizer->prev_in_time)))
+    goto no_skew;
+
   /* measure the diff */
   delta = ((gint64) recv_diff) - ((gint64) send_diff);
 
@@ -3061,6 +3074,7 @@ no_skew:
   }
 
   packetizer->prev_out_time = out_time;
+  packetizer->prev_in_time = time;
   packetizer->prev_send_diff = send_diff;
 
   GST_DEBUG ("skew %" G_GINT64_FORMAT ", out %" GST_TIME_FORMAT,
index 3b18535e49637da5e299d738100fcaf947be5446..845541afed35471ee2999d285010a316e24a7ac1 100644 (file)
@@ -86,9 +86,14 @@ struct _MpegTSPacketizer2 {
 
   /* clock skew calculation */
   gboolean       calculate_skew;
+
+  /* Following variables are only active/used when
+   * calculate_skew is TRUE */
+  /* FIXME : These variables should be *per* PCR PID */
   GstClockTime   base_time;
   GstClockTime   base_pcrtime;
   GstClockTime   prev_out_time;
+  GstClockTime   prev_in_time;
   GstClockTime   last_pcrtime;
   gint64         window[MAX_WINDOW];
   guint          window_pos;
@@ -161,6 +166,8 @@ void mpegts_packetizer_push (MpegTSPacketizer2 *packetizer, GstBuffer *buffer);
 gboolean mpegts_packetizer_has_packets (MpegTSPacketizer2 *packetizer);
 MpegTSPacketizerPacketReturn mpegts_packetizer_next_packet (MpegTSPacketizer2 *packetizer,
   MpegTSPacketizerPacket *packet);
+MpegTSPacketizerPacketReturn
+mpegts_packetizer_process_next_packet(MpegTSPacketizer2 * packetizer);
 void mpegts_packetizer_clear_packet (MpegTSPacketizer2 *packetizer,
   MpegTSPacketizerPacket *packet);
 void mpegts_packetizer_remove_stream(MpegTSPacketizer2 *packetizer,