mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 19:20:35 +00:00
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.
This commit is contained in:
parent
1a945a32cc
commit
00ffa9c2dd
2 changed files with 18 additions and 8 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue