niimaq: organize and cleanup
This commit is contained in:
parent
07fe523680
commit
1b6b14d225
@ -672,31 +672,21 @@ gst_niimaqsrc_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static gboolean
|
||||||
gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
gst_niimaqsrc_start_acquisition (GstNiImaqSrc * niimaqsrc)
|
||||||
{
|
{
|
||||||
GstNiImaqSrc *niimaqsrc = GST_NIIMAQSRC (psrc);
|
int i;
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
gint32 rval;
|
||||||
guint i;
|
|
||||||
GstNiImaqSrcFrameTime *frametime;
|
g_assert (!niimaqsrc->session_started);
|
||||||
GstClockTime timestamp = GST_CLOCK_TIME_NONE;
|
|
||||||
GstClockTime timestamp2 = GST_CLOCK_TIME_NONE;
|
|
||||||
GstClockTime duration = GST_CLOCK_TIME_NONE;
|
|
||||||
guint8 *data;
|
|
||||||
uInt32 copied_number;
|
|
||||||
uInt32 copied_index;
|
|
||||||
Int32 rval;
|
|
||||||
uInt32 dropped;
|
|
||||||
|
|
||||||
/* start the IMAQ acquisition session if we haven't done so yet */
|
|
||||||
if (!niimaqsrc->session_started) {
|
|
||||||
GST_DEBUG_OBJECT (niimaqsrc, "Starting acquisition");
|
GST_DEBUG_OBJECT (niimaqsrc, "Starting acquisition");
|
||||||
|
|
||||||
/* try to open the camera five times */
|
/* try to open the camera five times */
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
rval = imgSessionStartAcquisition (niimaqsrc->sid);
|
rval = imgSessionStartAcquisition (niimaqsrc->sid);
|
||||||
if (rval == 0) {
|
if (rval == IMG_ERR_GOOD) {
|
||||||
break;
|
return niimaqsrc->session_started = TRUE;
|
||||||
} else {
|
} else {
|
||||||
gst_niimaqsrc_report_imaq_error (rval);
|
gst_niimaqsrc_report_imaq_error (rval);
|
||||||
GST_LOG_OBJECT (niimaqsrc, "camera is still off , wait 50ms and retry");
|
GST_LOG_OBJECT (niimaqsrc, "camera is still off , wait 50ms and retry");
|
||||||
@ -705,16 +695,67 @@ gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* we tried five times and failed, so we error */
|
/* we tried five times and failed, so we error */
|
||||||
if (i >= 5) {
|
|
||||||
GST_ELEMENT_ERROR (niimaqsrc, RESOURCE, FAILED,
|
GST_ELEMENT_ERROR (niimaqsrc, RESOURCE, FAILED,
|
||||||
("Camera doesn't seem to want to turn on!"),
|
("Camera doesn't seem to want to turn on!"),
|
||||||
("Camera doesn't seem to want to turn on!"));
|
("Camera doesn't seem to want to turn on!"));
|
||||||
|
|
||||||
gst_niimaqsrc_close_interface (niimaqsrc);
|
gst_niimaqsrc_close_interface (niimaqsrc);
|
||||||
|
|
||||||
return GST_FLOW_ERROR;
|
return FALSE;
|
||||||
}
|
}
|
||||||
niimaqsrc->session_started = TRUE;
|
|
||||||
|
static GstClockTime
|
||||||
|
gst_niimaqsrc_get_timestamp_from_buffer_number (GstNiImaqSrc * niimaqsrc,
|
||||||
|
guint32 buffer_number)
|
||||||
|
{
|
||||||
|
GstClockTime timestamp = GST_CLOCK_TIME_NONE;
|
||||||
|
GstNiImaqSrcFrameTime *frametime;
|
||||||
|
|
||||||
|
/* search linked list for frame time */
|
||||||
|
g_mutex_lock (niimaqsrc->frametime_mutex);
|
||||||
|
if (G_LIKELY (niimaqsrc->timelist)
|
||||||
|
&& g_slist_length (niimaqsrc->timelist) > 0) {
|
||||||
|
/* remove all old frametimes from the list */
|
||||||
|
frametime = (GstNiImaqSrcFrameTime *) niimaqsrc->timelist->data;
|
||||||
|
while (frametime->number < buffer_number) {
|
||||||
|
niimaqsrc->timelist =
|
||||||
|
g_slist_delete_link (niimaqsrc->timelist, niimaqsrc->timelist);
|
||||||
|
frametime = (GstNiImaqSrcFrameTime *) niimaqsrc->timelist->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frametime->number == buffer_number) {
|
||||||
|
timestamp = frametime->time;
|
||||||
|
|
||||||
|
/* remove frame time as we no longer need it */
|
||||||
|
niimaqsrc->timelist =
|
||||||
|
g_slist_delete_link (niimaqsrc->timelist, niimaqsrc->timelist);
|
||||||
|
} else {
|
||||||
|
GST_WARNING_OBJECT (niimaqsrc,
|
||||||
|
"Did NOT find buffer date-timestamp in list generated by callback");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_mutex_unlock (niimaqsrc->frametime_mutex);
|
||||||
|
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
||||||
|
{
|
||||||
|
GstNiImaqSrc *niimaqsrc = GST_NIIMAQSRC (psrc);
|
||||||
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
|
GstClockTime timestamp;
|
||||||
|
GstClockTime duration;
|
||||||
|
guint8 *data;
|
||||||
|
uInt32 copied_number;
|
||||||
|
uInt32 copied_index;
|
||||||
|
Int32 rval;
|
||||||
|
uInt32 dropped;
|
||||||
|
|
||||||
|
/* start the IMAQ acquisition session if we haven't done so yet */
|
||||||
|
if (!niimaqsrc->session_started) {
|
||||||
|
gst_niimaqsrc_start_acquisition (niimaqsrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret =
|
ret =
|
||||||
@ -750,52 +791,14 @@ gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO, DEBUG: get running time now to compare to what the callback gives us */
|
|
||||||
/*clock = gst_element_get_clock (GST_ELEMENT (niimaqsrc));
|
|
||||||
timestamp2 =
|
|
||||||
GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (niimaqsrc)), gst_clock_get_time (clock));
|
|
||||||
gst_object_unref (clock); */
|
|
||||||
|
|
||||||
GST_BUFFER_OFFSET (*buffer) = copied_number;
|
|
||||||
GST_BUFFER_OFFSET_END (*buffer) = copied_number + 1;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (niimaqsrc, "Associating time with buffer");
|
GST_DEBUG_OBJECT (niimaqsrc, "Associating time with buffer");
|
||||||
|
|
||||||
/* search linked list for frame time */
|
|
||||||
g_mutex_lock (niimaqsrc->frametime_mutex);
|
|
||||||
if (G_LIKELY (niimaqsrc->timelist)
|
|
||||||
&& g_slist_length (niimaqsrc->timelist) > 0) {
|
|
||||||
/* remove all old frametimes from the list */
|
|
||||||
frametime = niimaqsrc->timelist->data;
|
|
||||||
while (frametime->number < copied_number) {
|
|
||||||
niimaqsrc->timelist =
|
|
||||||
g_slist_delete_link (niimaqsrc->timelist, niimaqsrc->timelist);
|
|
||||||
frametime = niimaqsrc->timelist->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frametime->number == copied_number) {
|
|
||||||
GST_DEBUG_OBJECT (niimaqsrc,
|
|
||||||
"Found buffer date-timestamp in list generated by callback");
|
|
||||||
timestamp = frametime->time;
|
|
||||||
|
|
||||||
/* remove frame time as we no longer need it */
|
|
||||||
niimaqsrc->timelist =
|
|
||||||
g_slist_delete_link (niimaqsrc->timelist, niimaqsrc->timelist);
|
|
||||||
} else {
|
|
||||||
GST_WARNING_OBJECT (niimaqsrc,
|
|
||||||
"Did NOT find buffer date-timestamp in list generated by callback");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_mutex_unlock (niimaqsrc->frametime_mutex);
|
|
||||||
|
|
||||||
/* set timestamp */
|
/* set timestamp */
|
||||||
|
timestamp =
|
||||||
|
gst_niimaqsrc_get_timestamp_from_buffer_number (niimaqsrc, copied_number);
|
||||||
if (timestamp == GST_CLOCK_TIME_NONE) {
|
if (timestamp == GST_CLOCK_TIME_NONE) {
|
||||||
GST_WARNING_OBJECT (niimaqsrc, "No timestamp found; callback failed?");
|
GST_WARNING_OBJECT (niimaqsrc, "No timestamp found; callback failed?");
|
||||||
/* FIXME: the clock isn't valid before the first FVAL callback? */
|
/* FIXME: the clock isn't valid before the first FVAL callback? */
|
||||||
/*clock = gst_element_get_clock (GST_ELEMENT (niimaqsrc));
|
|
||||||
GST_BUFFER_TIMESTAMP (*buffer) =
|
|
||||||
GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (niimaqsrc)), gst_clock_get_time (clock));
|
|
||||||
gst_object_unref (clock); */
|
|
||||||
} else {
|
} else {
|
||||||
timestamp =
|
timestamp =
|
||||||
GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (niimaqsrc)),
|
GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (niimaqsrc)),
|
||||||
@ -809,28 +812,20 @@ gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
|||||||
duration = 33 * GST_MSECOND;
|
duration = 33 * GST_MSECOND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO, DEBUG: set duration to see what the difference is between callback and create */
|
GST_BUFFER_OFFSET (*buffer) = copied_number;
|
||||||
/*duration = GST_CLOCK_DIFF (timestamp, timestamp2); */
|
GST_BUFFER_OFFSET_END (*buffer) = copied_number + 1;
|
||||||
|
|
||||||
|
|
||||||
GST_BUFFER_TIMESTAMP (*buffer) = timestamp;
|
GST_BUFFER_TIMESTAMP (*buffer) = timestamp;
|
||||||
GST_BUFFER_DURATION (*buffer) = duration;
|
GST_BUFFER_DURATION (*buffer) = duration;
|
||||||
|
|
||||||
/* the negotiate() method already set caps on the source pad */
|
/* the negotiate() method already set caps on the source pad */
|
||||||
gst_buffer_set_caps (*buffer, GST_PAD_CAPS (GST_BASE_SRC_PAD (niimaqsrc)));
|
gst_buffer_set_caps (*buffer, GST_PAD_CAPS (GST_BASE_SRC_PAD (niimaqsrc)));
|
||||||
|
|
||||||
/*GST_BUFFER_TIMESTAMP (outbuf) = src->timestamp_offset + src->running_time;
|
|
||||||
if (src->rate_numerator != 0) {
|
|
||||||
GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale_int (GST_SECOND,
|
|
||||||
src->rate_denominator, src->rate_numerator);
|
|
||||||
} */
|
|
||||||
|
|
||||||
dropped = copied_number - niimaqsrc->cumbufnum;
|
dropped = copied_number - niimaqsrc->cumbufnum;
|
||||||
if (dropped > 0) {
|
if (dropped > 0) {
|
||||||
niimaqsrc->n_dropped_frames += dropped;
|
niimaqsrc->n_dropped_frames += dropped;
|
||||||
GST_WARNING_OBJECT (niimaqsrc, "Asked to copy buffer %d but was given %d",
|
GST_WARNING_OBJECT (niimaqsrc,
|
||||||
niimaqsrc->cumbufnum, copied_number);
|
"Asked to copy buffer #%d but was given #%d; just dropped %d frames (%d total)",
|
||||||
GST_WARNING_OBJECT (niimaqsrc, "Dropped %d frames (%d total)", dropped,
|
niimaqsrc->cumbufnum, copied_number, dropped,
|
||||||
niimaqsrc->n_dropped_frames);
|
niimaqsrc->n_dropped_frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -838,11 +833,6 @@ gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
|||||||
niimaqsrc->cumbufnum = copied_number + 1;
|
niimaqsrc->cumbufnum = copied_number + 1;
|
||||||
niimaqsrc->n_frames++;
|
niimaqsrc->n_frames++;
|
||||||
|
|
||||||
/*if (src->rate_numerator != 0) {
|
|
||||||
src->running_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
|
|
||||||
src->rate_denominator, src->rate_numerator);
|
|
||||||
} */
|
|
||||||
|
|
||||||
if (G_UNLIKELY (niimaqsrc->start_time && !niimaqsrc->start_time_sent)) {
|
if (G_UNLIKELY (niimaqsrc->start_time && !niimaqsrc->start_time_sent)) {
|
||||||
GstTagList *tl =
|
GstTagList *tl =
|
||||||
gst_tag_list_new_full (GST_TAG_DATE_TIME, niimaqsrc->start_time, NULL);
|
gst_tag_list_new_full (GST_TAG_DATE_TIME, niimaqsrc->start_time, NULL);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user