summaryrefslogtreecommitdiffstats
path: root/sys/v4l2
diff options
context:
space:
mode:
authorStefan Kost <ensonic@users.sf.net>2009-09-11 22:24:47 +0300
committerStefan Kost <ensonic@users.sf.net>2009-09-11 22:24:47 +0300
commit00ffa9c2dde5361017f7d523970921cfb1937199 (patch)
treee1415c0782719e758384ef8027c4dbdddbf08921 /sys/v4l2
parent1a945a32ccae14b2828cacdd5d11560039df5d74 (diff)
v4l2src: add a function pointer for get_frame function and optimize a bit
Use a function-pointer for mmap/read, as this can't change during capture. Also sprinkle a few G_LIKELY/UNLIKELY to improve the error-less code path.
Diffstat (limited to 'sys/v4l2')
-rw-r--r--sys/v4l2/gstv4l2src.c22
-rw-r--r--sys/v4l2/gstv4l2src.h4
2 files changed, 18 insertions, 8 deletions
diff --git a/sys/v4l2/gstv4l2src.c b/sys/v4l2/gstv4l2src.c
index 783a6bd1..1178f5a8 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 fef3f108..68f45d97 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