basertpaudiopayload: Add extra frame for non-complete frame lengths
authorOlivier CrĂȘte <olivier.crete@collabora.co.uk>
Mon, 10 May 2010 23:09:28 +0000 (19:09 -0400)
committerWim Taymans <wim.taymans@collabora.co.uk>
Thu, 13 May 2010 09:03:12 +0000 (11:03 +0200)
Some payloaders like rtpg729pay can add a shorter frame at the end of a
RTP packet. We need to count it like a full frame for timestamps.

https://bugzilla.gnome.org/show_bug.cgi?id=618324

gst-libs/gst/rtp/gstbasertpaudiopayload.c

index 1596962..512455a 100644 (file)
@@ -722,16 +722,27 @@ static GstClockTime
 gst_base_rtp_audio_payload_frame_bytes_to_time (GstBaseRTPAudioPayload *
     payload, guint64 bytes)
 {
-  return (bytes / payload->frame_size) * (payload->priv->frame_duration_ns);
+  guint64 framecount;
+
+  framecount = bytes / payload->frame_size;
+  if (G_UNLIKELY (bytes % payload->frame_size))
+    framecount++;
+
+  return framecount * payload->priv->frame_duration_ns;
 }
 
 static guint32
 gst_base_rtp_audio_payload_frame_bytes_to_rtptime (GstBaseRTPAudioPayload *
     payload, guint64 bytes)
 {
+  guint64 framecount;
   guint64 time;
 
-  time = (bytes / payload->frame_size) * (payload->priv->frame_duration_ns);
+  framecount = bytes / payload->frame_size;
+  if (G_UNLIKELY (bytes % payload->frame_size))
+    framecount++;
+
+  time = framecount * payload->priv->frame_duration_ns;
 
   return gst_util_uint64_scale_int (time,
       GST_BASE_RTP_PAYLOAD (payload)->clock_rate, GST_SECOND);