kayasrc: 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
1611f54672
commit
75aaec26b6
@ -112,6 +112,11 @@ static GstStaticPadTemplate gst_kayasrc_src_template =
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
#if GST_CHECK_VERSION(1,14,0)
|
||||||
|
static GstStaticCaps unix_reference = GST_STATIC_CAPS ("timestamp/x-unix");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* class initialization */
|
/* class initialization */
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstKayaSrc, gst_kayasrc, GST_TYPE_PUSH_SRC);
|
G_DEFINE_TYPE (GstKayaSrc, gst_kayasrc, GST_TYPE_PUSH_SRC);
|
||||||
@ -201,6 +206,7 @@ gst_kayasrc_cleanup (GstKayaSrc * src)
|
|||||||
src->dropped_frames = 0;
|
src->dropped_frames = 0;
|
||||||
src->stop_requested = FALSE;
|
src->stop_requested = FALSE;
|
||||||
src->acquisition_started = FALSE;
|
src->acquisition_started = FALSE;
|
||||||
|
src->kaya_base = GST_CLOCK_TIME_NONE;
|
||||||
|
|
||||||
if (src->caps) {
|
if (src->caps) {
|
||||||
gst_caps_unref (src->caps);
|
gst_caps_unref (src->caps);
|
||||||
@ -254,6 +260,8 @@ gst_kayasrc_init (GstKayaSrc * src)
|
|||||||
src->cam_handle = INVALID_CAMHANDLE;
|
src->cam_handle = INVALID_CAMHANDLE;
|
||||||
src->stream_handle = INVALID_STREAMHANDLE;
|
src->stream_handle = INVALID_STREAMHANDLE;
|
||||||
src->buffer_handles = NULL;
|
src->buffer_handles = NULL;
|
||||||
|
|
||||||
|
src->kaya_base = GST_CLOCK_TIME_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -702,12 +710,14 @@ gst_kayasrc_stream_buffer_callback (STREAM_BUFFER_HANDLE buffer_handle,
|
|||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
guint32 buf_id;
|
guint32 buf_id;
|
||||||
static guint64 buffers_processed = 0;
|
static guint64 buffers_processed = 0;
|
||||||
|
GstClockTime timestamp;
|
||||||
VideoFrame *vf;
|
VideoFrame *vf;
|
||||||
GstClock *clock;
|
GstClock *clock;
|
||||||
|
|
||||||
|
KYFG_BufferGetInfo (buffer_handle, KY_STREAM_BUFFER_INFO_TIMESTAMP,
|
||||||
|
×tamp, NULL, NULL);
|
||||||
KYFG_BufferGetInfo (buffer_handle, KY_STREAM_BUFFER_INFO_BASE, &data, NULL,
|
KYFG_BufferGetInfo (buffer_handle, KY_STREAM_BUFFER_INFO_BASE, &data, NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
KYFG_BufferGetInfo (buffer_handle, KY_STREAM_BUFFER_INFO_ID, &buf_id, NULL,
|
KYFG_BufferGetInfo (buffer_handle, KY_STREAM_BUFFER_INFO_ID, &buf_id, NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
@ -723,6 +733,29 @@ gst_kayasrc_stream_buffer_callback (STREAM_BUFFER_HANDLE buffer_handle,
|
|||||||
(gpointer) data, src->frame_size, 0, src->frame_size, vf,
|
(gpointer) data, src->frame_size, 0, src->frame_size, vf,
|
||||||
(GDestroyNotify) buffer_release);
|
(GDestroyNotify) buffer_release);
|
||||||
|
|
||||||
|
if (src->kaya_base == GST_CLOCK_TIME_NONE) {
|
||||||
|
/* assume delay between these two calls is negligible */
|
||||||
|
src->kaya_base = KYFG_GetGrabberValueInt (src->cam_handle, "Timestamp");
|
||||||
|
src->unix_base = g_get_real_time () * 1000;
|
||||||
|
}
|
||||||
|
#if GST_CHECK_VERSION(1,14,0)
|
||||||
|
{
|
||||||
|
GstClockTime unix_ts = src->unix_base + (timestamp - src->kaya_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
|
||||||
|
|
||||||
clock = gst_element_get_clock (GST_ELEMENT (src));
|
clock = gst_element_get_clock (GST_ELEMENT (src));
|
||||||
GST_BUFFER_TIMESTAMP (buf) =
|
GST_BUFFER_TIMESTAMP (buf) =
|
||||||
GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)),
|
GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)),
|
||||||
|
|||||||
@ -63,6 +63,9 @@ struct _GstKayaSrc
|
|||||||
|
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GAsyncQueue *queue;
|
GAsyncQueue *queue;
|
||||||
|
|
||||||
|
GstClockTime unix_base;
|
||||||
|
GstClockTime kaya_base;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstKayaSrcClass
|
struct _GstKayaSrcClass
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user