From 4c47870c00de974a0e3c7da2f267fd6cf720ff84 Mon Sep 17 00:00:00 2001 From: "Joshua M. Doe" Date: Wed, 18 Jul 2018 08:51:13 -0400 Subject: [PATCH] kayasrc: report dropped frames with warning and bus message --- sys/kaya/gstkayasrc.c | 32 +++++++++++++++++++++++++++++--- sys/kaya/gstkayasrc.h | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/sys/kaya/gstkayasrc.c b/sys/kaya/gstkayasrc.c index eced01d..ab3ebbd 100644 --- a/sys/kaya/gstkayasrc.c +++ b/sys/kaya/gstkayasrc.c @@ -189,6 +189,8 @@ gst_kayasrc_class_init (GstKayaSrcClass * klass) static void gst_kayasrc_cleanup (GstKayaSrc * src) { + src->frame_size = 0; + src->dropped_frames = 0; src->stop_requested = FALSE; src->acquisition_started = FALSE; @@ -241,8 +243,8 @@ gst_kayasrc_init (GstKayaSrc * src) src->fg_handle = INVALID_FGHANDLE; src->cam_handle = INVALID_CAMHANDLE; - - gst_kayasrc_cleanup (src); + src->stream_handle = INVALID_STREAMHANDLE; + src->buffer_handles = NULL; } static void @@ -386,6 +388,8 @@ gst_kayasrc_start (GstBaseSrc * bsrc) GST_DEBUG_OBJECT (src, "start"); + gst_kayasrc_cleanup (src); + /* find and list all KAYA interfaces */ num_ifaces = KYFG_Scan (NULL, 0); if (num_ifaces == 0) { @@ -541,6 +545,9 @@ gst_kayasrc_start (GstBaseSrc * bsrc) return FALSE; } + src->stop_requested = FALSE; + src->dropped_frames = 0; + return TRUE; error: @@ -700,7 +707,7 @@ static GstFlowReturn gst_kayasrc_create (GstPushSrc * psrc, GstBuffer ** buf) { GstKayaSrc *src = GST_KAYA_SRC (psrc); - guint32 dropped_frames = 0; + gint64 dropped_frames = 0; GST_LOG_OBJECT (src, "create"); @@ -724,6 +731,25 @@ gst_kayasrc_create (GstPushSrc * psrc, GstBuffer ** buf) goto error; } + dropped_frames = + KYFG_GetGrabberValueInt (src->cam_handle, "DropFrameCounter"); + if (dropped_frames > src->dropped_frames) { + GstStructure *info_msg; + gint64 just_dropped = dropped_frames - src->dropped_frames; + src->dropped_frames = dropped_frames; + + GST_WARNING_OBJECT (src, "Just dropped %d frames (%d total)", just_dropped, + src->dropped_frames); + + info_msg = gst_structure_new ("dropped-frame-info", + "num-dropped-frames", G_TYPE_INT, just_dropped, + "total-dropped-frames", G_TYPE_INT, src->dropped_frames, + "timestamp", GST_TYPE_CLOCK_TIME, GST_BUFFER_TIMESTAMP (buf), NULL); + gst_element_post_message (GST_ELEMENT (src), + gst_message_new_element (GST_OBJECT (src), info_msg)); + src->dropped_frames = dropped_frames; + } + if (src->stop_requested) { if (*buf != NULL) { gst_buffer_unref (*buf); diff --git a/sys/kaya/gstkayasrc.h b/sys/kaya/gstkayasrc.h index 8ef8ed2..2a57dc2 100644 --- a/sys/kaya/gstkayasrc.h +++ b/sys/kaya/gstkayasrc.h @@ -58,6 +58,7 @@ struct _GstKayaSrc gboolean acquisition_started; gboolean stop_requested; + gint64 dropped_frames; GstCaps *caps; GAsyncQueue *queue;