rtpbasepayload: Do cosmetic changes to rtptime calculations
* Change running time type to guint64 * Use GST_CLOCK_TIME_NONE() to check for invalid timestamps * Name variables so ns-based and hz-based timestamps are evident Fixes https://bugzilla.gnome.org/show_bug.cgi?id=719383
This commit is contained in:
parent
0142cd5e35
commit
125b9c19c0
@ -46,6 +46,7 @@ struct _GstRTPBasePayloadPrivate
|
|||||||
|
|
||||||
guint64 base_offset;
|
guint64 base_offset;
|
||||||
gint64 base_rtime;
|
gint64 base_rtime;
|
||||||
|
guint64 base_rtime_hz;
|
||||||
guint64 running_time;
|
guint64 running_time;
|
||||||
|
|
||||||
gint64 prop_max_ptime;
|
gint64 prop_max_ptime;
|
||||||
@ -350,7 +351,7 @@ gst_rtp_base_payload_init (GstRTPBasePayload * rtpbasepayload, gpointer g_class)
|
|||||||
rtpbasepayload->priv->perfect_rtptime = DEFAULT_PERFECT_RTPTIME;
|
rtpbasepayload->priv->perfect_rtptime = DEFAULT_PERFECT_RTPTIME;
|
||||||
rtpbasepayload->ptime_multiple = DEFAULT_PTIME_MULTIPLE;
|
rtpbasepayload->ptime_multiple = DEFAULT_PTIME_MULTIPLE;
|
||||||
rtpbasepayload->priv->base_offset = GST_BUFFER_OFFSET_NONE;
|
rtpbasepayload->priv->base_offset = GST_BUFFER_OFFSET_NONE;
|
||||||
rtpbasepayload->priv->base_rtime = GST_BUFFER_OFFSET_NONE;
|
rtpbasepayload->priv->base_rtime_hz = GST_BUFFER_OFFSET_NONE;
|
||||||
|
|
||||||
rtpbasepayload->media = NULL;
|
rtpbasepayload->media = NULL;
|
||||||
rtpbasepayload->encoding_name = NULL;
|
rtpbasepayload->encoding_name = NULL;
|
||||||
@ -969,9 +970,12 @@ gst_rtp_base_payload_prepare_push (GstRTPBasePayload * payload,
|
|||||||
/* convert to RTP time */
|
/* convert to RTP time */
|
||||||
if (priv->perfect_rtptime && data.offset != GST_BUFFER_OFFSET_NONE &&
|
if (priv->perfect_rtptime && data.offset != GST_BUFFER_OFFSET_NONE &&
|
||||||
priv->base_offset != GST_BUFFER_OFFSET_NONE) {
|
priv->base_offset != GST_BUFFER_OFFSET_NONE) {
|
||||||
/* if we have an offset, use that for making an RTP timestamp */
|
/* generate perfect RTP time by adding together the base timestamp, the
|
||||||
data.rtptime = payload->ts_base + priv->base_rtime +
|
* running time of the first buffer and difference between the offset of the
|
||||||
data.offset - priv->base_offset;
|
* first buffer and the offset of the current buffer. */
|
||||||
|
guint64 offset = data.offset - priv->base_offset;
|
||||||
|
data.rtptime = payload->ts_base + priv->base_rtime_hz + offset;
|
||||||
|
|
||||||
GST_LOG_OBJECT (payload,
|
GST_LOG_OBJECT (payload,
|
||||||
"Using offset %" G_GUINT64_FORMAT " for RTP timestamp", data.offset);
|
"Using offset %" G_GUINT64_FORMAT " for RTP timestamp", data.offset);
|
||||||
|
|
||||||
@ -981,31 +985,39 @@ gst_rtp_base_payload_prepare_push (GstRTPBasePayload * payload,
|
|||||||
data.offset - priv->base_offset);
|
data.offset - priv->base_offset);
|
||||||
priv->running_time = priv->base_rtime + data.offset - priv->base_offset;
|
priv->running_time = priv->base_rtime + data.offset - priv->base_offset;
|
||||||
} else if (GST_CLOCK_TIME_IS_VALID (data.pts)) {
|
} else if (GST_CLOCK_TIME_IS_VALID (data.pts)) {
|
||||||
gint64 rtime;
|
guint64 rtime_ns;
|
||||||
|
guint64 rtime_hz;
|
||||||
|
|
||||||
/* no offset, use the gstreamer pts */
|
/* no offset, use the gstreamer pts */
|
||||||
rtime = gst_segment_to_running_time (&payload->segment, GST_FORMAT_TIME,
|
rtime_ns = gst_segment_to_running_time (&payload->segment, GST_FORMAT_TIME,
|
||||||
data.pts);
|
data.pts);
|
||||||
|
|
||||||
if (rtime == -1) {
|
if (!GST_CLOCK_TIME_IS_VALID (rtime_ns)) {
|
||||||
GST_LOG_OBJECT (payload, "Clipped pts, using base RTP timestamp");
|
GST_LOG_OBJECT (payload, "Clipped pts, using base RTP timestamp");
|
||||||
rtime = 0;
|
rtime_hz = 0;
|
||||||
} else {
|
} else {
|
||||||
GST_LOG_OBJECT (payload,
|
GST_LOG_OBJECT (payload,
|
||||||
"Using running_time %" GST_TIME_FORMAT " for RTP timestamp",
|
"Using running_time %" GST_TIME_FORMAT " for RTP timestamp",
|
||||||
GST_TIME_ARGS (rtime));
|
GST_TIME_ARGS (rtime_ns));
|
||||||
rtime =
|
rtime_hz =
|
||||||
gst_util_uint64_scale_int (rtime, payload->clock_rate, GST_SECOND);
|
gst_util_uint64_scale_int (rtime_ns, payload->clock_rate, GST_SECOND);
|
||||||
priv->base_offset = data.offset;
|
priv->base_offset = data.offset;
|
||||||
priv->base_rtime = rtime;
|
priv->base_rtime_hz = rtime_hz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add running_time in clock-rate units to the base timestamp */
|
/* add running_time in clock-rate units to the base timestamp */
|
||||||
data.rtptime = payload->ts_base + rtime;
|
data.rtptime = payload->ts_base + rtime_hz;
|
||||||
|
|
||||||
/* store buffer's running time */
|
/* store buffer's running time */
|
||||||
|
if (priv->perfect_rtptime) {
|
||||||
GST_LOG_OBJECT (payload,
|
GST_LOG_OBJECT (payload,
|
||||||
"setting running-time to %" G_GUINT64_FORMAT, rtime);
|
"setting running-time to %" G_GUINT64_FORMAT, rtime_hz);
|
||||||
priv->running_time = rtime;
|
priv->running_time = rtime_hz;
|
||||||
|
} else {
|
||||||
|
GST_LOG_OBJECT (payload,
|
||||||
|
"setting running-time to %" GST_TIME_FORMAT, GST_TIME_ARGS (rtime_ns));
|
||||||
|
priv->running_time = rtime_ns;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
GST_LOG_OBJECT (payload,
|
GST_LOG_OBJECT (payload,
|
||||||
"Using previous RTP timestamp %" G_GUINT32_FORMAT, payload->timestamp);
|
"Using previous RTP timestamp %" G_GUINT32_FORMAT, payload->timestamp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user