niimaqdxsrc: add UNIX epoch reference timestamp for absolute timestamping
Requires GStreamer 1.14 and a downstream element that can use it.
This commit is contained in:
parent
11bb336ee4
commit
8fd7c91da6
@ -123,8 +123,7 @@ gst_niimaqdxsrc_frame_done_callback (IMAQdxSession session, uInt32 bufferNumber,
|
|||||||
time_entry = g_new (GstNiImaqDxSrcTimeEntry, 1);
|
time_entry = g_new (GstNiImaqDxSrcTimeEntry, 1);
|
||||||
|
|
||||||
/* get clock time */
|
/* get clock time */
|
||||||
time_entry->clock_time =
|
time_entry->clock_time = gst_clock_get_time (src->clock);
|
||||||
gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src)));
|
|
||||||
time_entry->frame_index = bufferNumber;
|
time_entry->frame_index = bufferNumber;
|
||||||
|
|
||||||
g_async_queue_push (src->time_queue, time_entry);
|
g_async_queue_push (src->time_queue, time_entry);
|
||||||
@ -133,6 +132,10 @@ gst_niimaqdxsrc_frame_done_callback (IMAQdxSession session, uInt32 bufferNumber,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GST_CHECK_VERSION(1,14,0)
|
||||||
|
static GstStaticCaps unix_reference = GST_STATIC_CAPS ("timestamp/x-unix");
|
||||||
|
#endif
|
||||||
|
|
||||||
#define VIDEO_CAPS_MAKE_BAYER8(format) \
|
#define VIDEO_CAPS_MAKE_BAYER8(format) \
|
||||||
"video/x-bayer, " \
|
"video/x-bayer, " \
|
||||||
"format = (string) { " format " }, " \
|
"format = (string) { " format " }, " \
|
||||||
@ -515,6 +518,7 @@ gst_niimaqdxsrc_init (GstNiImaqDxSrc * src)
|
|||||||
/* initialize pointers, then call reset to initialize the rest */
|
/* initialize pointers, then call reset to initialize the rest */
|
||||||
src->temp_buffer = NULL;
|
src->temp_buffer = NULL;
|
||||||
src->time_queue = NULL;
|
src->time_queue = NULL;
|
||||||
|
src->clock = NULL;
|
||||||
gst_niimaqdxsrc_reset (src);
|
gst_niimaqdxsrc_reset (src);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,6 +631,11 @@ gst_niimaqdxsrc_reset (GstNiImaqDxSrc * src)
|
|||||||
g_async_queue_unref (src->time_queue);
|
g_async_queue_unref (src->time_queue);
|
||||||
}
|
}
|
||||||
src->time_queue = g_async_queue_new ();
|
src->time_queue = g_async_queue_new ();
|
||||||
|
|
||||||
|
if (src->clock) {
|
||||||
|
gst_object_unref (src->clock);
|
||||||
|
src->clock = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -674,11 +683,17 @@ gst_niimaqdxsrc_fill (GstPushSrc * psrc, GstBuffer * buf)
|
|||||||
|
|
||||||
/* start the IMAQ acquisition session if we haven't done so yet */
|
/* start the IMAQ acquisition session if we haven't done so yet */
|
||||||
if (!src->session_started) {
|
if (!src->session_started) {
|
||||||
|
src->clock = gst_element_get_clock (GST_ELEMENT (src));
|
||||||
|
|
||||||
if (!gst_niimaqdxsrc_start_acquisition (src)) {
|
if (!gst_niimaqdxsrc_start_acquisition (src)) {
|
||||||
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
||||||
("Unable to start acquisition."), (NULL));
|
("Unable to start acquisition."), (NULL));
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* assume delay between these two calls is negligible */
|
||||||
|
src->unix_base = g_get_real_time () * 1000;
|
||||||
|
src->stream_base = gst_clock_get_time (src->clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* will change attributes if provided */
|
/* will change attributes if provided */
|
||||||
@ -719,7 +734,7 @@ gst_niimaqdxsrc_fill (GstPushSrc * psrc, GstBuffer * buf)
|
|||||||
|
|
||||||
if (src->is_jpeg) {
|
if (src->is_jpeg) {
|
||||||
/* JPEG sources don't seem to give reliable callbacks, just pull clock */
|
/* JPEG sources don't seem to give reliable callbacks, just pull clock */
|
||||||
timestamp = gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src)));
|
timestamp = gst_clock_get_time (src->clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (timestamp == GST_CLOCK_TIME_NONE) {
|
while (timestamp == GST_CLOCK_TIME_NONE) {
|
||||||
@ -780,6 +795,23 @@ gst_niimaqdxsrc_fill (GstPushSrc * psrc, GstBuffer * buf)
|
|||||||
timestamp - gst_element_get_base_time (GST_ELEMENT (src));
|
timestamp - gst_element_get_base_time (GST_ELEMENT (src));
|
||||||
// TODO: fix duration
|
// TODO: fix duration
|
||||||
//GST_BUFFER_DURATION (buf) = duration;
|
//GST_BUFFER_DURATION (buf) = duration;
|
||||||
|
#if GST_CHECK_VERSION(1,14,0)
|
||||||
|
{
|
||||||
|
GstClockTime unix_ts = src->unix_base + (timestamp - src->stream_base);
|
||||||
|
gst_buffer_add_reference_timestamp_meta (buf,
|
||||||
|
gst_static_caps_get (&unix_reference), unix_ts, GST_CLOCK_TIME_NONE);
|
||||||
|
GST_LOG_OBJECT (src, "Buffer #%d, adding unix timestamp: %llu",
|
||||||
|
GST_BUFFER_OFFSET (buf), unix_ts);
|
||||||
|
/*{
|
||||||
|
GDateTime *frame_time, *tmpdt;
|
||||||
|
tmpdt = g_date_time_new_from_unix_utc (0);
|
||||||
|
frame_time = g_date_time_add_seconds(tmpdt, (gdouble)unix_ts / GST_SECOND);
|
||||||
|
g_date_time_unref (tmpdt);
|
||||||
|
GST_LOG ("Unix timestamp added is: %s.%d", g_date_time_format (frame_time, "%Y-%m-%d %H:%M:%S"), g_date_time_get_microsecond(frame_time));
|
||||||
|
g_date_time_unref (frame_time);
|
||||||
|
} */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
dropped = copied_number - src->cumbufnum;
|
dropped = copied_number - src->cumbufnum;
|
||||||
if (dropped > 0) {
|
if (dropped > 0) {
|
||||||
|
|||||||
@ -86,6 +86,10 @@ struct _GstNiImaqDxSrc {
|
|||||||
gboolean session_started;
|
gboolean session_started;
|
||||||
|
|
||||||
GAsyncQueue *time_queue;
|
GAsyncQueue *time_queue;
|
||||||
|
|
||||||
|
GstClock *clock;
|
||||||
|
GstClockTime stream_base;
|
||||||
|
GstClockTime unix_base;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstNiImaqDxSrcClass {
|
struct _GstNiImaqDxSrcClass {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user