From 3607f30fffcb24c9e75216c6c96d19ed00df7c59 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Thu, 26 Nov 2015 17:08:12 -0300 Subject: [PATCH] media-descriptor-writer: track running time of buffers PTS and DTS can be deceiving as a change in segment can dramatically change playback synchronization. Track the running-time as well to properly get any change in synchronization --- validate/gst/validate/media-descriptor-parser.c | 2 ++ validate/gst/validate/media-descriptor-writer.c | 42 +++++++++++++++++++++---- validate/gst/validate/media-descriptor.c | 1 + validate/gst/validate/media-descriptor.h | 2 ++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/validate/gst/validate/media-descriptor-parser.c b/validate/gst/validate/media-descriptor-parser.c index 9d19696..8cde648 100644 --- a/validate/gst/validate/media-descriptor-parser.c +++ b/validate/gst/validate/media-descriptor-parser.c @@ -135,6 +135,8 @@ deserialize_framenode (const gchar ** names, const gchar ** values) framenode->pts = g_ascii_strtoull (values[i], NULL, 0); else if (g_strcmp0 (names[i], "dts") == 0) framenode->dts = g_ascii_strtoull (values[i], NULL, 0); + else if (g_strcmp0 (names[i], "running-time") == 0) + framenode->running_time = g_ascii_strtoull (values[i], NULL, 0); else if (g_strcmp0 (names[i], "checksum") == 0) framenode->checksum = g_strdup (values[i]); else if (g_strcmp0 (names[i], "is-keyframe") == 0) { diff --git a/validate/gst/validate/media-descriptor-writer.c b/validate/gst/validate/media-descriptor-writer.c index 9e79cb2..d97f49e 100644 --- a/validate/gst/validate/media-descriptor-writer.c +++ b/validate/gst/validate/media-descriptor-writer.c @@ -293,7 +293,31 @@ static GstPadProbeReturn _uridecodebin_probe (GstPad * pad, GstPadProbeInfo * info, GstMediaDescriptorWriter * writer) { - gst_media_descriptor_writer_add_frame (writer, pad, info->data); + if (GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_BUFFER) { + gst_media_descriptor_writer_add_frame (writer, pad, info->data); + } else if (GST_PAD_PROBE_INFO_TYPE (info) & + GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) { + GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info); + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_SEGMENT:{ + const GstSegment *segment; + StreamNode *streamnode; + + streamnode = + gst_media_descriptor_find_stream_node_by_pad ((GstMediaDescriptor *) + writer, pad); + if (streamnode) { + gst_event_parse_segment (event, &segment); + gst_segment_copy_into (segment, &streamnode->segment); + } + break; + } + default: + break; + } + } else { + g_assert_not_reached (); + } return GST_PAD_PROBE_OK; } @@ -409,7 +433,8 @@ pad_added_cb (GstElement * decodebin, GstPad * pad, } } - gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_BUFFER, + gst_pad_add_probe (srcpad, + GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, (GstPadProbeCallback) _uridecodebin_probe, writer, NULL); } @@ -817,16 +842,21 @@ gst_media_descriptor_writer_add_frame (GstMediaDescriptorWriter fnode->duration = GST_BUFFER_DURATION (buf); fnode->pts = GST_BUFFER_PTS (buf); fnode->dts = GST_BUFFER_DTS (buf); - fnode->is_keyframe = (GST_BUFFER_FLAG_IS_SET (buf, - GST_BUFFER_FLAG_DELTA_UNIT) == FALSE); + fnode->running_time = + gst_segment_to_running_time (&streamnode->segment, GST_FORMAT_TIME, + GST_BUFFER_PTS (buf)); + fnode->is_keyframe = + (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT) == FALSE); fnode->str_open = g_markup_printf_escaped (" ", + "\" dts=\"%" G_GUINT64_FORMAT "\" running-time=\"%" G_GUINT64_FORMAT + "\" checksum=\"%s\"/>", fnode->duration, id, fnode->is_keyframe ? "true" : "false", - fnode->offset, fnode->offset_end, fnode->pts, fnode->dts, checksum); + fnode->offset, fnode->offset_end, fnode->pts, fnode->dts, + fnode->running_time, checksum); fnode->str_close = NULL; diff --git a/validate/gst/validate/media-descriptor.c b/validate/gst/validate/media-descriptor.c index 7313594..a2e6216 100644 --- a/validate/gst/validate/media-descriptor.c +++ b/validate/gst/validate/media-descriptor.c @@ -359,6 +359,7 @@ compare_frames (GstMediaDescriptor * ref, StreamNode * rstream, CHECK_FRAME_FIELD (pts, "%" G_GUINT64_FORMAT); CHECK_FRAME_FIELD (dts, "%" G_GUINT64_FORMAT); CHECK_FRAME_FIELD (duration, "%" G_GUINT64_FORMAT); + CHECK_FRAME_FIELD (running_time, "%" G_GUINT64_FORMAT); CHECK_FRAME_FIELD (offset, "%" G_GUINT64_FORMAT); CHECK_FRAME_FIELD (offset_end, "%" G_GUINT64_FORMAT); CHECK_FRAME_FIELD (is_keyframe, "%d"); diff --git a/validate/gst/validate/media-descriptor.h b/validate/gst/validate/media-descriptor.h index 30afebc..e2d486d 100644 --- a/validate/gst/validate/media-descriptor.h +++ b/validate/gst/validate/media-descriptor.h @@ -85,6 +85,7 @@ typedef struct /* Attributes */ GstCaps *caps; + GstSegment segment; gchar *id; gchar *padname; @@ -104,6 +105,7 @@ typedef struct guint64 offset_end; GstClockTime duration; GstClockTime pts, dts; + GstClockTime running_time; gboolean is_keyframe; GstBuffer *buf; -- 2.7.4