diff --git a/sys/v4l2/gstv4l2src.c b/sys/v4l2/gstv4l2src.c index 783a6bd108..1178f5a811 100644 --- a/sys/v4l2/gstv4l2src.c +++ b/sys/v4l2/gstv4l2src.c @@ -202,6 +202,12 @@ static void gst_v4l2src_set_property (GObject * object, guint prop_id, static void gst_v4l2src_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +/* get_frame io methods */ +static GstFlowReturn +gst_v4l2src_get_read (GstV4l2Src * v4l2src, GstBuffer ** buf); +static GstFlowReturn +gst_v4l2src_get_mmap (GstV4l2Src * v4l2src, GstBuffer ** buf); + static void gst_v4l2src_base_init (gpointer g_class) { @@ -616,6 +622,12 @@ gst_v4l2src_set_caps (GstBaseSrc * src, GstCaps * caps) if (!gst_v4l2src_capture_init (v4l2src, caps)) return FALSE; + if (v4l2src->use_mmap) { + v4l2src->get_frame = gst_v4l2src_get_mmap; + } else { + v4l2src->get_frame = gst_v4l2src_get_read; + } + if (!gst_v4l2src_capture_start (v4l2src)) return FALSE; @@ -850,7 +862,7 @@ gst_v4l2src_get_mmap (GstV4l2Src * v4l2src, GstBuffer ** buf) again: ret = gst_v4l2src_grab_frame (v4l2src, &temp); - if (ret != GST_FLOW_OK) + if (G_UNLIKELY (ret != GST_FLOW_OK)) goto done; if (v4l2src->frame_byte_size > 0) { @@ -889,13 +901,9 @@ gst_v4l2src_create (GstPushSrc * src, GstBuffer ** buf) GstV4l2Src *v4l2src = GST_V4L2SRC (src); GstFlowReturn ret; - if (v4l2src->use_mmap) { - ret = gst_v4l2src_get_mmap (v4l2src, buf); - } else { - ret = gst_v4l2src_get_read (v4l2src, buf); - } + ret = v4l2src->get_frame (v4l2src, buf); /* set buffer metadata */ - if (ret == GST_FLOW_OK && *buf) { + if (G_LIKELY (ret == GST_FLOW_OK && *buf)) { GstClock *clock; GstClockTime timestamp; diff --git a/sys/v4l2/gstv4l2src.h b/sys/v4l2/gstv4l2src.h index fef3f108c3..68f45d97d6 100644 --- a/sys/v4l2/gstv4l2src.h +++ b/sys/v4l2/gstv4l2src.h @@ -45,7 +45,7 @@ G_BEGIN_DECLS typedef struct _GstV4l2Src GstV4l2Src; typedef struct _GstV4l2SrcClass GstV4l2SrcClass; - +typedef GstFlowReturn (*GstV4l2SrcGetFunc)(GstV4l2Src * v4l2src, GstBuffer ** buf); /** * GstV4l2Src: @@ -80,6 +80,8 @@ struct _GstV4l2Src guint64 offset; gint fps_d, fps_n; /* framerate if device is open */ + + GstV4l2SrcGetFunc get_frame; }; struct _GstV4l2SrcClass