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
|
||||
gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
||||
static gboolean
|
||||
gst_niimaqsrc_start_acquisition (GstNiImaqSrc * niimaqsrc)
|
||||
{
|
||||
GstNiImaqSrc *niimaqsrc = GST_NIIMAQSRC (psrc);
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
guint i;
|
||||
GstNiImaqSrcFrameTime *frametime;
|
||||
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;
|
||||
int i;
|
||||
gint32 rval;
|
||||
|
||||
g_assert (!niimaqsrc->session_started);
|
||||
|
||||
/* start the IMAQ acquisition session if we haven't done so yet */
|
||||
if (!niimaqsrc->session_started) {
|
||||
GST_DEBUG_OBJECT (niimaqsrc, "Starting acquisition");
|
||||
|
||||
/* try to open the camera five times */
|
||||
for (i = 0; i < 5; i++) {
|
||||
rval = imgSessionStartAcquisition (niimaqsrc->sid);
|
||||
if (rval == 0) {
|
||||
break;
|
||||
if (rval == IMG_ERR_GOOD) {
|
||||
return niimaqsrc->session_started = TRUE;
|
||||
} else {
|
||||
gst_niimaqsrc_report_imaq_error (rval);
|
||||
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 */
|
||||
if (i >= 5) {
|
||||
GST_ELEMENT_ERROR (niimaqsrc, RESOURCE, FAILED,
|
||||
("Camera doesn't seem to want to turn on!"),
|
||||
("Camera doesn't seem to want to turn on!"));
|
||||
|
||||
gst_niimaqsrc_close_interface (niimaqsrc);
|
||||
|
||||
return GST_FLOW_ERROR;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
niimaqsrc->session_started = TRUE;
|
||||
|
||||
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 =
|
||||
@ -750,52 +791,14 @@ gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
||||
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");
|
||||
|
||||
/* 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 */
|
||||
timestamp =
|
||||
gst_niimaqsrc_get_timestamp_from_buffer_number (niimaqsrc, copied_number);
|
||||
if (timestamp == GST_CLOCK_TIME_NONE) {
|
||||
GST_WARNING_OBJECT (niimaqsrc, "No timestamp found; callback failed?");
|
||||
/* 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 {
|
||||
timestamp =
|
||||
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;
|
||||
}
|
||||
|
||||
/* TODO, DEBUG: set duration to see what the difference is between callback and create */
|
||||
/*duration = GST_CLOCK_DIFF (timestamp, timestamp2); */
|
||||
|
||||
|
||||
GST_BUFFER_OFFSET (*buffer) = copied_number;
|
||||
GST_BUFFER_OFFSET_END (*buffer) = copied_number + 1;
|
||||
GST_BUFFER_TIMESTAMP (*buffer) = timestamp;
|
||||
GST_BUFFER_DURATION (*buffer) = duration;
|
||||
|
||||
/* 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_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;
|
||||
if (dropped > 0) {
|
||||
niimaqsrc->n_dropped_frames += dropped;
|
||||
GST_WARNING_OBJECT (niimaqsrc, "Asked to copy buffer %d but was given %d",
|
||||
niimaqsrc->cumbufnum, copied_number);
|
||||
GST_WARNING_OBJECT (niimaqsrc, "Dropped %d frames (%d total)", dropped,
|
||||
GST_WARNING_OBJECT (niimaqsrc,
|
||||
"Asked to copy buffer #%d but was given #%d; just dropped %d frames (%d total)",
|
||||
niimaqsrc->cumbufnum, copied_number, dropped,
|
||||
niimaqsrc->n_dropped_frames);
|
||||
}
|
||||
|
||||
@ -838,11 +833,6 @@ gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
||||
niimaqsrc->cumbufnum = copied_number + 1;
|
||||
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)) {
|
||||
GstTagList *tl =
|
||||
gst_tag_list_new_full (GST_TAG_DATE_TIME, niimaqsrc->start_time, NULL);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user