sys/v4l/: Probe less and cache it. Fixes #159187.

Original commit message from CVS:
* sys/v4l/gstv4lsrc.c:
* sys/v4l/gstv4lsrc.h:
* sys/v4l/v4lsrc_calls.c:
Probe less and cache it.  Fixes #159187.
This commit is contained in:
Thomas Vander Stichele 2004-11-23 12:42:21 +00:00
parent 4735c6ad5f
commit d680329e06
4 changed files with 51 additions and 23 deletions

View File

@ -1,3 +1,10 @@
2004-11-23 Thomas Vander Stichele <thomas at apestaart dot org>
* sys/v4l/gstv4lsrc.c:
* sys/v4l/gstv4lsrc.h:
* sys/v4l/v4lsrc_calls.c:
Probe less and cache it. Fixes #159187.
2004-11-23 Thomas Vander Stichele <thomas at apestaart dot org> 2004-11-23 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/videorate/gstvideorate.c: * gst/videorate/gstvideorate.c:

View File

@ -287,6 +287,8 @@ gst_v4lsrc_init (GstV4lSrc * v4lsrc)
v4lsrc->autoprobe_fps = TRUE; v4lsrc->autoprobe_fps = TRUE;
v4lsrc->latency_offset = 0; v4lsrc->latency_offset = 0;
v4lsrc->fps_list = NULL;
} }
static void static void
@ -634,6 +636,7 @@ gst_v4lsrc_src_link (GstPad * pad, const GstCaps * vscapslist)
return GST_PAD_LINK_DELAYED; return GST_PAD_LINK_DELAYED;
} }
/* FIXME: setting the first one is just stupid. We should loop */
structure = gst_caps_get_structure (vscapslist, 0); structure = gst_caps_get_structure (vscapslist, 0);
if (!strcmp (gst_structure_get_name (structure), "video/x-raw-yuv")) if (!strcmp (gst_structure_get_name (structure), "video/x-raw-yuv"))
@ -644,6 +647,7 @@ gst_v4lsrc_src_link (GstPad * pad, const GstCaps * vscapslist)
gst_structure_get_int (structure, "width", &w); gst_structure_get_int (structure, "width", &w);
gst_structure_get_int (structure, "height", &h); gst_structure_get_int (structure, "height", &h);
gst_structure_get_double (structure, "framerate", &fps); gst_structure_get_double (structure, "framerate", &fps);
GST_DEBUG_OBJECT (v4lsrc, "linking with %dx%d at %f fps", w, h, fps);
/* set framerate if it's not already correct */ /* set framerate if it's not already correct */
if (fps != gst_v4lsrc_get_fps (v4lsrc)) { if (fps != gst_v4lsrc_get_fps (v4lsrc)) {
@ -812,7 +816,6 @@ gst_v4lsrc_getcaps (GstPad * pad)
struct video_capability *vcap = &GST_V4LELEMENT (v4lsrc)->vcap; struct video_capability *vcap = &GST_V4LELEMENT (v4lsrc)->vcap;
gfloat fps = 0.0; gfloat fps = 0.0;
GList *item; GList *item;
GValue *fps_list = NULL;
if (!GST_V4L_IS_OPEN (GST_V4LELEMENT (v4lsrc))) { if (!GST_V4L_IS_OPEN (GST_V4LELEMENT (v4lsrc))) {
return gst_caps_new_any (); return gst_caps_new_any ();
@ -822,12 +825,12 @@ gst_v4lsrc_getcaps (GstPad * pad)
return gst_caps_new_any (); return gst_caps_new_any ();
} }
/* FIXME: cache this on gst_v4l_open() */ /*
if (v4lsrc->autoprobe_fps) { FIXME: if we choose a fixed one because we didn't probe, fixated caps don't
fps_list = gst_v4lsrc_get_fps_list (v4lsrc); work. So comment this out for now.
} if (!v4lsrc->fps_list)
if (!fps_list)
fps = gst_v4lsrc_get_fps (v4lsrc); fps = gst_v4lsrc_get_fps (v4lsrc);
*/
list = gst_caps_new_empty (); list = gst_caps_new_empty ();
for (item = v4lsrc->colourspaces; item != NULL; item = item->next) { for (item = v4lsrc->colourspaces; item != NULL; item = item->next) {
@ -855,15 +858,18 @@ gst_v4lsrc_getcaps (GstPad * pad)
gst_caps_set_simple (one, "height", G_TYPE_INT, vcap->minheight, NULL); gst_caps_set_simple (one, "height", G_TYPE_INT, vcap->minheight, NULL);
} }
if (fps_list) { if (v4lsrc->fps_list) {
GstStructure *structure = gst_caps_get_structure (one, 0); GstStructure *structure = gst_caps_get_structure (one, 0);
gst_structure_set_value (structure, "framerate", fps_list); gst_structure_set_value (structure, "framerate", v4lsrc->fps_list);
} else { }
/* see higher up why we comment this
else {
GstStructure *structure = gst_caps_get_structure (one, 0); GstStructure *structure = gst_caps_get_structure (one, 0);
gst_structure_set (structure, "framerate", G_TYPE_DOUBLE, fps, NULL); gst_structure_set (structure, "framerate", G_TYPE_DOUBLE, fps, NULL);
} }
*/
GST_DEBUG_OBJECT (v4lsrc, "caps: %" GST_PTR_FORMAT, one); GST_DEBUG_OBJECT (v4lsrc, "caps: %" GST_PTR_FORMAT, one);
gst_caps_append (list, one); gst_caps_append (list, one);
} }
@ -1163,14 +1169,14 @@ gst_v4lsrc_change_state (GstElement * element)
GstV4lSrc *v4lsrc; GstV4lSrc *v4lsrc;
GTimeVal time; GTimeVal time;
gint transition = GST_STATE_TRANSITION (element); gint transition = GST_STATE_TRANSITION (element);
GstElementStateReturn parent_ret = GST_STATE_SUCCESS;
g_return_val_if_fail (GST_IS_V4LSRC (element), GST_STATE_FAILURE); g_return_val_if_fail (GST_IS_V4LSRC (element), GST_STATE_FAILURE);
v4lsrc = GST_V4LSRC (element); v4lsrc = GST_V4LSRC (element);
/* pre-parent state change */
switch (transition) { switch (transition) {
case GST_STATE_NULL_TO_READY:
break;
case GST_STATE_READY_TO_PAUSED: case GST_STATE_READY_TO_PAUSED:
v4lsrc->handled = 0; v4lsrc->handled = 0;
v4lsrc->need_discont = TRUE; v4lsrc->need_discont = TRUE;
@ -1210,9 +1216,22 @@ gst_v4lsrc_change_state (GstElement * element)
} }
if (GST_ELEMENT_CLASS (parent_class)->change_state) if (GST_ELEMENT_CLASS (parent_class)->change_state)
return GST_ELEMENT_CLASS (parent_class)->change_state (element); parent_ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
return GST_STATE_SUCCESS; /* post-parent change_state */
switch (transition) {
case GST_STATE_NULL_TO_READY:
GST_DEBUG_OBJECT (v4lsrc,
"Doing post-parent NULL_TO_READY, checking probes");
if (v4lsrc->autoprobe_fps) {
GST_DEBUG_OBJECT (v4lsrc, "autoprobing framerates");
v4lsrc->fps_list = gst_v4lsrc_get_fps_list (v4lsrc);
}
default:
break;
}
return parent_ret;
} }

View File

@ -106,6 +106,8 @@ struct _GstV4lSrc
gboolean copy_mode; gboolean copy_mode;
gboolean autoprobe; /* probe features on startup ? */ gboolean autoprobe; /* probe features on startup ? */
gboolean autoprobe_fps; /* probe fps on startup ? */ gboolean autoprobe_fps; /* probe fps on startup ? */
GValue *fps_list; /* list of fps probed */
}; };
struct _GstV4lSrcClass struct _GstV4lSrcClass

View File

@ -272,7 +272,7 @@ gst_v4lsrc_capture_start (GstV4lSrc * v4lsrc)
gboolean gboolean
gst_v4lsrc_grab_frame (GstV4lSrc * v4lsrc, gint * num) gst_v4lsrc_grab_frame (GstV4lSrc * v4lsrc, gint * num)
{ {
GST_LOG_OBJECT (v4lsrc, "grabbing frame %d", num); GST_LOG_OBJECT (v4lsrc, "grabbing frame %d", *num);
GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lsrc)); GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lsrc));
GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lsrc)); GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lsrc));
@ -285,7 +285,7 @@ gst_v4lsrc_grab_frame (GstV4lSrc * v4lsrc, gint * num)
while (v4lsrc->frame_queue_state[v4lsrc->queue_frame] != while (v4lsrc->frame_queue_state[v4lsrc->queue_frame] !=
QUEUE_STATE_READY_FOR_QUEUE && !v4lsrc->quit) { QUEUE_STATE_READY_FOR_QUEUE && !v4lsrc->quit) {
GST_DEBUG_OBJECT (v4lsrc, GST_DEBUG_OBJECT (v4lsrc,
"Waiting for frames to become available (%d < %d)", "Waiting for frames to become available (queued %d < minimum %d)",
v4lsrc->num_queued, MIN_BUFFERS_QUEUED); v4lsrc->num_queued, MIN_BUFFERS_QUEUED);
g_cond_wait (v4lsrc->cond_queue_state, v4lsrc->mutex_queue_state); g_cond_wait (v4lsrc->cond_queue_state, v4lsrc->mutex_queue_state);
} }