mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-30 13:41:48 +00:00
sys/v4l2/: add norm, channel and frequency properties.
Original commit message from CVS: 2004-01-12 Benjamin Otte <in7y118@public.uni-hamburg.de> * sys/v4l2/gstv4l2element.c: (gst_v4l2element_class_init), (gst_v4l2element_dispose), (gst_v4l2element_set_property), (gst_v4l2element_get_property): * sys/v4l2/v4l2_calls.c: (gst_v4l2_set_defaults), (gst_v4l2_open): add norm, channel and frequency properties. * sys/v4l2/gstv4l2tuner.c: fixes for tuner interface changes * sys/v4l2/gstv4l2element.h: * sys/v4l2/gstv4l2src.c: * sys/v4l2/gstv4l2src.h: * sys/v4l2/v4l2src_calls.c: * sys/v4l2/v4l2src_calls.h: rework v4l2src to work with saa1734 cards and allow mmaped buffers.
This commit is contained in:
parent
efeab14a4e
commit
409384e0d8
9 changed files with 1077 additions and 1060 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2004-01-12 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
||||
|
||||
* sys/v4l2/gstv4l2element.c: (gst_v4l2element_class_init),
|
||||
(gst_v4l2element_dispose), (gst_v4l2element_set_property),
|
||||
(gst_v4l2element_get_property):
|
||||
* sys/v4l2/v4l2_calls.c: (gst_v4l2_set_defaults), (gst_v4l2_open):
|
||||
add norm, channel and frequency properties.
|
||||
* sys/v4l2/gstv4l2tuner.c:
|
||||
fixes for tuner interface changes
|
||||
* sys/v4l2/gstv4l2element.h:
|
||||
* sys/v4l2/gstv4l2src.c:
|
||||
* sys/v4l2/gstv4l2src.h:
|
||||
* sys/v4l2/v4l2src_calls.c:
|
||||
* sys/v4l2/v4l2src_calls.h:
|
||||
rework v4l2src to work with saa1734 cards and allow mmaped buffers.
|
||||
|
||||
2004-01-12 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
||||
|
||||
* gst-libs/gst/tuner/tuner.c: (gst_tuner_class_init),
|
||||
|
|
|
@ -43,17 +43,20 @@ static GstElementDetails gst_v4l2element_details = {
|
|||
|
||||
/* V4l2Element signals and args */
|
||||
enum {
|
||||
/* FILL ME */
|
||||
SIGNAL_OPEN,
|
||||
SIGNAL_CLOSE,
|
||||
LAST_SIGNAL
|
||||
/* FILL ME */
|
||||
SIGNAL_OPEN,
|
||||
SIGNAL_CLOSE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum {
|
||||
ARG_0,
|
||||
ARG_DEVICE,
|
||||
ARG_DEVICE_NAME,
|
||||
ARG_FLAGS
|
||||
ARG_0,
|
||||
ARG_DEVICE,
|
||||
ARG_DEVICE_NAME,
|
||||
ARG_NORM,
|
||||
ARG_CHANNEL,
|
||||
ARG_FREQUENCY,
|
||||
ARG_FLAGS
|
||||
};
|
||||
|
||||
|
||||
|
@ -378,41 +381,47 @@ gst_v4l2element_base_init (GstV4l2ElementClass *klass)
|
|||
static void
|
||||
gst_v4l2element_class_init (GstV4l2ElementClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
||||
|
||||
gobject_class = (GObjectClass*)klass;
|
||||
gstelement_class = (GstElementClass*)klass;
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
||||
g_object_class_install_property(gobject_class, ARG_DEVICE,
|
||||
g_param_spec_string("device", "Device", "Device location",
|
||||
NULL, G_PARAM_READWRITE));
|
||||
g_object_class_install_property(gobject_class, ARG_DEVICE_NAME,
|
||||
g_param_spec_string("device_name", "Device name",
|
||||
"Name of the device", NULL, G_PARAM_READABLE));
|
||||
g_object_class_install_property(gobject_class, ARG_FLAGS,
|
||||
g_param_spec_flags("flags", "Flags", "Device type flags",
|
||||
GST_TYPE_V4L2_DEVICE_FLAGS, 0, G_PARAM_READABLE));
|
||||
g_object_class_install_property(gobject_class, ARG_NORM,
|
||||
g_param_spec_string("norm", "norm",
|
||||
"Norm to use", NULL, G_PARAM_READWRITE));
|
||||
g_object_class_install_property(gobject_class, ARG_CHANNEL,
|
||||
g_param_spec_string("channel", "channel",
|
||||
"input/output to switch to", NULL, G_PARAM_READWRITE));
|
||||
g_object_class_install_property(gobject_class, ARG_FREQUENCY,
|
||||
g_param_spec_ulong ("frequency", "frequency",
|
||||
"frequency to tune to", 0, G_MAXULONG, 0, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE,
|
||||
g_param_spec_string("device", "Device", "Device location",
|
||||
NULL, G_PARAM_READWRITE));
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE_NAME,
|
||||
g_param_spec_string("device_name", "Device name",
|
||||
"Name of the device", NULL, G_PARAM_READABLE));
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FLAGS,
|
||||
g_param_spec_flags("flags", "Flags", "Device type flags",
|
||||
GST_TYPE_V4L2_DEVICE_FLAGS, 0, G_PARAM_READABLE));
|
||||
/* signals */
|
||||
gst_v4l2element_signals[SIGNAL_OPEN] =
|
||||
g_signal_new("open", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET(GstV4l2ElementClass, open),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
gst_v4l2element_signals[SIGNAL_CLOSE] =
|
||||
g_signal_new("close", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET(GstV4l2ElementClass, close),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
|
||||
/* signals */
|
||||
gst_v4l2element_signals[SIGNAL_OPEN] =
|
||||
g_signal_new("open", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET(GstV4l2ElementClass, open),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
gst_v4l2element_signals[SIGNAL_CLOSE] =
|
||||
g_signal_new("close", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET(GstV4l2ElementClass, close),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
gobject_class->set_property = gst_v4l2element_set_property;
|
||||
gobject_class->get_property = gst_v4l2element_get_property;
|
||||
gobject_class->dispose = gst_v4l2element_dispose;
|
||||
|
||||
gobject_class->set_property = gst_v4l2element_set_property;
|
||||
gobject_class->get_property = gst_v4l2element_get_property;
|
||||
gobject_class->dispose = gst_v4l2element_dispose;
|
||||
|
||||
gstelement_class->change_state = gst_v4l2element_change_state;
|
||||
gstelement_class->change_state = gst_v4l2element_change_state;
|
||||
}
|
||||
|
||||
|
||||
|
@ -446,10 +455,13 @@ gst_v4l2element_dispose (GObject *object)
|
|||
g_free (v4l2element->display);
|
||||
}
|
||||
|
||||
if (v4l2element->device) {
|
||||
g_free (v4l2element->device);
|
||||
}
|
||||
|
||||
g_free (v4l2element->device);
|
||||
v4l2element->device = NULL;
|
||||
g_free (v4l2element->norm);
|
||||
v4l2element->norm = NULL;
|
||||
g_free (v4l2element->channel);
|
||||
v4l2element->channel = NULL;
|
||||
|
||||
if (((GObjectClass *) parent_class)->dispose)
|
||||
((GObjectClass *) parent_class)->dispose(object);
|
||||
}
|
||||
|
@ -460,24 +472,63 @@ gst_v4l2element_set_property (GObject *object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GstV4l2Element *v4l2element;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail(GST_IS_V4L2ELEMENT(object));
|
||||
v4l2element = GST_V4L2ELEMENT(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_DEVICE:
|
||||
if (!GST_V4L2_IS_OPEN(v4l2element)) {
|
||||
if (v4l2element->device)
|
||||
g_free(v4l2element->device);
|
||||
v4l2element->device = g_strdup(g_value_get_string(value));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
GstV4l2Element *v4l2element;
|
||||
GstTuner *tuner;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail (GST_IS_V4L2ELEMENT (object));
|
||||
v4l2element = GST_V4L2ELEMENT (object);
|
||||
/* stupid GstInterface */
|
||||
tuner = (GstTuner *) object;
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_DEVICE:
|
||||
if (!GST_V4L2_IS_OPEN(v4l2element)) {
|
||||
if (v4l2element->device)
|
||||
g_free(v4l2element->device);
|
||||
v4l2element->device = g_value_dup_string(value);
|
||||
}
|
||||
break;
|
||||
case ARG_NORM:
|
||||
if (GST_V4L2_IS_OPEN(v4l2element)) {
|
||||
GstTunerNorm *norm = gst_tuner_get_norm (tuner);
|
||||
if (norm) {
|
||||
gst_tuner_set_norm (tuner, norm);
|
||||
}
|
||||
} else {
|
||||
g_free (v4l2element->norm);
|
||||
v4l2element->norm = g_value_dup_string (value);
|
||||
g_object_notify (object, "norm");
|
||||
}
|
||||
break;
|
||||
case ARG_CHANNEL:
|
||||
if (GST_V4L2_IS_OPEN(v4l2element)) {
|
||||
GstTunerChannel *channel = gst_tuner_get_channel (tuner);
|
||||
if (channel) {
|
||||
gst_tuner_set_channel (tuner, channel);
|
||||
}
|
||||
} else {
|
||||
g_free (v4l2element->channel);
|
||||
v4l2element->channel = g_value_dup_string (value);
|
||||
g_object_notify (object, "channel");
|
||||
}
|
||||
break;
|
||||
case ARG_FREQUENCY:
|
||||
if (GST_V4L2_IS_OPEN(v4l2element)) {
|
||||
GstTunerChannel *channel;
|
||||
if (!v4l2element->channel) return;
|
||||
channel = gst_tuner_get_channel (tuner);
|
||||
g_assert (channel);
|
||||
gst_tuner_set_frequency (tuner, channel, g_value_get_ulong (value));
|
||||
} else {
|
||||
v4l2element->frequency = g_value_get_ulong (value);
|
||||
g_object_notify (object, "frequency");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -513,6 +564,15 @@ gst_v4l2element_get_property (GObject *object,
|
|||
g_value_set_flags(value, flags);
|
||||
break;
|
||||
}
|
||||
case ARG_NORM:
|
||||
g_value_set_string (value, v4l2element->norm);
|
||||
break;
|
||||
case ARG_CHANNEL:
|
||||
g_value_set_string (value, v4l2element->channel);
|
||||
break;
|
||||
case ARG_FREQUENCY:
|
||||
g_value_set_ulong (value, v4l2element->frequency);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
|
|
|
@ -82,6 +82,11 @@ struct _GstV4l2Element {
|
|||
GstXWindowListener *overlay;
|
||||
XID xwindow_id;
|
||||
|
||||
/* properties */
|
||||
gchar *norm;
|
||||
gchar *channel;
|
||||
gulong frequency;
|
||||
|
||||
/* caching values */
|
||||
gchar *display;
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,6 +22,10 @@
|
|||
|
||||
#include <gstv4l2element.h>
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (v4l2src_debug);
|
||||
|
||||
#define GST_V4L2_MAX_BUFFERS 16
|
||||
#define GST_V4L2_MIN_BUFFERS 2
|
||||
|
||||
#define GST_TYPE_V4L2SRC \
|
||||
(gst_v4l2src_get_type())
|
||||
|
@ -34,9 +38,26 @@
|
|||
#define GST_IS_V4L2SRC_CLASS(obj) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_V4L2SRC))
|
||||
|
||||
typedef struct _GstV4l2BufferPool GstV4l2BufferPool;
|
||||
typedef struct _GstV4l2Buffer GstV4l2Buffer;
|
||||
typedef struct _GstV4l2Src GstV4l2Src;
|
||||
typedef struct _GstV4l2SrcClass GstV4l2SrcClass;
|
||||
|
||||
typedef struct _GstV4l2Src GstV4l2Src;
|
||||
typedef struct _GstV4l2SrcClass GstV4l2SrcClass;
|
||||
/* global info */
|
||||
struct _GstV4l2BufferPool {
|
||||
GstAtomicInt refcount; /* number of users: 1 for every buffer, 1 for element */
|
||||
gint video_fd;
|
||||
guint buffer_count;
|
||||
GstV4l2Buffer * buffers;
|
||||
};
|
||||
|
||||
struct _GstV4l2Buffer {
|
||||
struct v4l2_buffer buffer;
|
||||
guint8 * start;
|
||||
guint length;
|
||||
GstAtomicInt refcount; /* add 1 if in use by element, add 1 if in use by GstBuffer */
|
||||
GstV4l2BufferPool * pool;
|
||||
};
|
||||
|
||||
struct _GstV4l2Src {
|
||||
GstV4l2Element v4l2element;
|
||||
|
@ -45,28 +66,21 @@ struct _GstV4l2Src {
|
|||
GstPad *srcpad;
|
||||
|
||||
/* internal lists */
|
||||
GList /*v4l2_fmtdesc*/ *formats, *format_list; /* list of available capture formats */
|
||||
GSList *formats; /* list of available capture formats */
|
||||
|
||||
/* buffers */
|
||||
GstV4l2BufferPool *pool;
|
||||
|
||||
/* buffer properties */
|
||||
struct v4l2_buffer bufsettings;
|
||||
struct v4l2_requestbuffers breq;
|
||||
struct v4l2_format format;
|
||||
|
||||
/* num of queued frames and some GThread stuff
|
||||
* to wait if there's not enough */
|
||||
gint8 *frame_queue_state;
|
||||
GMutex *mutex_queue_state;
|
||||
GCond *cond_queue_state;
|
||||
gint num_queued;
|
||||
gint queue_frame;
|
||||
|
||||
/* True if we want to stop */
|
||||
gboolean quit;
|
||||
|
||||
/* A/V sync... frame counter and internal cache */
|
||||
gulong handled;
|
||||
gint last_frame;
|
||||
gint need_writes;
|
||||
GstBuffer *cached_buffer;
|
||||
gulong last_seq;
|
||||
|
||||
/* clock */
|
||||
|
@ -75,9 +89,6 @@ struct _GstV4l2Src {
|
|||
/* time to substract from clock time to get back to timestamp */
|
||||
GstClockTime substract_time;
|
||||
|
||||
/* how often are we going to use each frame? */
|
||||
gint *use_num_times;
|
||||
|
||||
/* how are we going to push buffers? */
|
||||
gboolean use_fixed_fps;
|
||||
};
|
||||
|
|
|
@ -40,14 +40,14 @@ static const GList *
|
|||
gst_v4l2_tuner_list_channels (GstTuner *mixer);
|
||||
static void gst_v4l2_tuner_set_channel (GstTuner *mixer,
|
||||
GstTunerChannel *channel);
|
||||
static const GstTunerChannel *
|
||||
static GstTunerChannel *
|
||||
gst_v4l2_tuner_get_channel (GstTuner *mixer);
|
||||
|
||||
static const GList *
|
||||
gst_v4l2_tuner_list_norms (GstTuner *mixer);
|
||||
static void gst_v4l2_tuner_set_norm (GstTuner *mixer,
|
||||
GstTunerNorm *norm);
|
||||
static const GstTunerNorm *
|
||||
static GstTunerNorm *
|
||||
gst_v4l2_tuner_get_norm (GstTuner *mixer);
|
||||
|
||||
static void gst_v4l2_tuner_set_frequency (GstTuner *mixer,
|
||||
|
@ -205,13 +205,15 @@ gst_v4l2_tuner_set_channel (GstTuner *mixer,
|
|||
g_return_if_fail (gst_v4l2_tuner_contains_channel (v4l2element, v4l2channel));
|
||||
|
||||
/* ... or output, if we're a sink... */
|
||||
if (gst_v4l2_tuner_is_sink (v4l2element))
|
||||
gst_v4l2_set_output (v4l2element, v4l2channel->index);
|
||||
else
|
||||
gst_v4l2_set_input (v4l2element, v4l2channel->index);
|
||||
if (gst_v4l2_tuner_is_sink (v4l2element) ?
|
||||
gst_v4l2_set_output (v4l2element, v4l2channel->index) :
|
||||
gst_v4l2_set_input (v4l2element, v4l2channel->index)) {
|
||||
gst_tuner_channel_changed (mixer, channel);
|
||||
g_object_notify (G_OBJECT (v4l2element), "channel");
|
||||
}
|
||||
}
|
||||
|
||||
static const GstTunerChannel *
|
||||
static GstTunerChannel *
|
||||
gst_v4l2_tuner_get_channel (GstTuner *mixer)
|
||||
{
|
||||
GstV4l2Element *v4l2element = GST_V4L2ELEMENT (mixer);
|
||||
|
@ -229,7 +231,7 @@ gst_v4l2_tuner_get_channel (GstTuner *mixer)
|
|||
|
||||
for (item = v4l2element->channels; item != NULL; item = item->next) {
|
||||
if (channel == GST_V4L2_TUNER_CHANNEL (item->data)->index)
|
||||
return (const GstTunerChannel *) item->data;
|
||||
return (GstTunerChannel *) item->data;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -265,10 +267,13 @@ gst_v4l2_tuner_set_norm (GstTuner *mixer,
|
|||
g_return_if_fail (GST_V4L2_IS_OPEN (v4l2element));
|
||||
g_return_if_fail (gst_v4l2_tuner_contains_norm (v4l2element, v4l2norm));
|
||||
|
||||
gst_v4l2_set_norm (v4l2element, v4l2norm->index);
|
||||
if (gst_v4l2_set_norm (v4l2element, v4l2norm->index)) {
|
||||
gst_tuner_norm_changed (mixer, norm);
|
||||
g_object_notify (G_OBJECT (v4l2element), "norm");
|
||||
}
|
||||
}
|
||||
|
||||
static const GstTunerNorm *
|
||||
static GstTunerNorm *
|
||||
gst_v4l2_tuner_get_norm (GstTuner *mixer)
|
||||
{
|
||||
GstV4l2Element *v4l2element = GST_V4L2ELEMENT (mixer);
|
||||
|
@ -282,7 +287,7 @@ gst_v4l2_tuner_get_norm (GstTuner *mixer)
|
|||
|
||||
for (item = v4l2element->norms; item != NULL; item = item->next) {
|
||||
if (norm == GST_V4L2_TUNER_NORM (item->data)->index)
|
||||
return (const GstTunerNorm *) item->data;
|
||||
return (GstTunerNorm *) item->data;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -306,7 +311,10 @@ gst_v4l2_tuner_set_frequency (GstTuner *mixer,
|
|||
gst_v4l2_get_input (v4l2element, &chan);
|
||||
if (chan == GST_V4L2_TUNER_CHANNEL (channel)->index &&
|
||||
GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
|
||||
gst_v4l2_set_frequency (v4l2element, v4l2channel->tuner, frequency);
|
||||
if (gst_v4l2_set_frequency (v4l2element, v4l2channel->tuner, frequency)) {
|
||||
gst_tuner_frequency_changed (mixer, channel, frequency);
|
||||
g_object_notify (G_OBJECT (v4l2element), "frequency");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -342,6 +342,49 @@ gst_v4l2_empty_lists (GstV4l2Element *v4l2element)
|
|||
v4l2element->colors = NULL;
|
||||
}
|
||||
|
||||
/* FIXME: move this stuff to gstv4l2tuner.c? */
|
||||
|
||||
static void
|
||||
gst_v4l2_set_defaults (GstV4l2Element *v4l2element)
|
||||
{
|
||||
GstTunerNorm *norm = NULL;
|
||||
GstTunerChannel *channel = NULL;
|
||||
GstTuner *tuner = GST_TUNER (v4l2element);
|
||||
|
||||
if (v4l2element->norm)
|
||||
norm = gst_tuner_find_norm_by_name (tuner, v4l2element->norm);
|
||||
if (norm) {
|
||||
gst_tuner_set_norm (tuner, norm);
|
||||
} else {
|
||||
norm = GST_TUNER_NORM (gst_tuner_get_norm (GST_TUNER (v4l2element)));
|
||||
v4l2element->norm = g_strdup (norm->label);
|
||||
gst_tuner_norm_changed (tuner, norm);
|
||||
g_object_notify (G_OBJECT (v4l2element), "norm");
|
||||
}
|
||||
|
||||
if (v4l2element->channel)
|
||||
channel = gst_tuner_find_channel_by_name (tuner, v4l2element->channel);
|
||||
if (channel) {
|
||||
gst_tuner_set_channel (tuner, channel);
|
||||
} else {
|
||||
channel = GST_TUNER_CHANNEL (gst_tuner_get_channel (GST_TUNER (v4l2element)));
|
||||
v4l2element->channel = g_strdup (channel->label);
|
||||
gst_tuner_channel_changed (tuner, channel);
|
||||
g_object_notify (G_OBJECT (v4l2element), "channel");
|
||||
}
|
||||
if (v4l2element->frequency != 0) {
|
||||
gst_tuner_set_frequency (tuner, channel, v4l2element->frequency);
|
||||
} else {
|
||||
v4l2element->frequency = gst_tuner_get_frequency (tuner, channel);
|
||||
if (v4l2element->frequency == 0) {
|
||||
/* guess */
|
||||
gst_tuner_set_frequency (tuner, channel, 1000);
|
||||
} else {
|
||||
g_object_notify (G_OBJECT (v4l2element), "frequency");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************
|
||||
* gst_v4l2_open():
|
||||
|
@ -387,7 +430,10 @@ gst_v4l2_open (GstV4l2Element *v4l2element)
|
|||
if (!gst_v4l2_fill_lists(v4l2element))
|
||||
goto error;
|
||||
|
||||
gst_info("Opened device '%s' (%s) successfully\n",
|
||||
/* set defaults */
|
||||
gst_v4l2_set_defaults (v4l2element);
|
||||
|
||||
GST_INFO_OBJECT (v4l2element, "Opened device '%s' (%s) successfully\n",
|
||||
v4l2element->vcap.card, v4l2element->device);
|
||||
|
||||
return TRUE;
|
||||
|
|
|
@ -31,26 +31,24 @@
|
|||
#include <errno.h>
|
||||
#include "v4l2src_calls.h"
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define GST_CAT_DEFAULT v4l2src_debug
|
||||
|
||||
/* lalala... */
|
||||
#define GST_V4L2_SET_ACTIVE(element) (element)->buffer = GINT_TO_POINTER (-1)
|
||||
#define GST_V4L2_SET_INACTIVE(element) (element)->buffer = NULL
|
||||
|
||||
#define DEBUG(format, args...) \
|
||||
GST_DEBUG_OBJECT (\
|
||||
GST_ELEMENT(v4l2src), \
|
||||
GST_CAT_DEBUG_OBJECT (\
|
||||
v4l2src_debug, v4l2src, \
|
||||
"V4L2SRC: " format, ##args)
|
||||
|
||||
#define MIN_BUFFERS_QUEUED 2
|
||||
|
||||
/* On some systems MAP_FAILED seems to be missing */
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED ( (caddr_t) -1 )
|
||||
#endif
|
||||
|
||||
enum {
|
||||
QUEUE_STATE_ERROR = -1,
|
||||
QUEUE_STATE_READY_FOR_QUEUE,
|
||||
QUEUE_STATE_QUEUED,
|
||||
QUEUE_STATE_SYNCED,
|
||||
};
|
||||
|
||||
/******************************************************
|
||||
* gst_v4l2src_fill_format_list():
|
||||
* create list of supported capture formats
|
||||
|
@ -60,54 +58,49 @@ enum {
|
|||
gboolean
|
||||
gst_v4l2src_fill_format_list (GstV4l2Src *v4l2src)
|
||||
{
|
||||
gint n;
|
||||
gint n;
|
||||
struct v4l2_fmtdesc *format;
|
||||
|
||||
DEBUG("getting src format enumerations");
|
||||
GST_DEBUG_OBJECT (v4l2src, "getting src format enumerations");
|
||||
|
||||
/* format enumeration */
|
||||
for (n=0;;n++) {
|
||||
struct v4l2_fmtdesc format, *fmtptr;
|
||||
format.index = n;
|
||||
format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_ENUM_FMT, &format) < 0) {
|
||||
if (errno == EINVAL)
|
||||
break; /* end of enumeration */
|
||||
else {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Failed to get no. %d in pixelformat enumeration for %s: %s",
|
||||
n, GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
fmtptr = g_malloc(sizeof(format));
|
||||
memcpy(fmtptr, &format, sizeof(format));
|
||||
v4l2src->formats = g_list_append(v4l2src->formats, fmtptr);
|
||||
/* format enumeration */
|
||||
for (n=0;;n++) {
|
||||
format = g_new (struct v4l2_fmtdesc, 1);
|
||||
format->index = n;
|
||||
format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_ENUM_FMT, format) < 0) {
|
||||
if (errno == EINVAL) {
|
||||
break; /* end of enumeration */
|
||||
} else {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Failed to get no. %d in pixelformat enumeration for %s: %s",
|
||||
n, GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
g_free (format);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
GST_LOG_OBJECT (v4l2src, "got format"GST_FOURCC_FORMAT,
|
||||
GST_FOURCC_ARGS (format->pixelformat));
|
||||
v4l2src->formats = g_slist_prepend (v4l2src->formats, format);
|
||||
}
|
||||
|
||||
v4l2src->format_list = g_list_append(v4l2src->format_list, fmtptr->description);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************
|
||||
* gst_v4l2src_empty_format_list():
|
||||
* gst_v4l2src_clear_format_list():
|
||||
* free list of supported capture formats
|
||||
* return value: TRUE on success, FALSE on error
|
||||
******************************************************/
|
||||
|
||||
gboolean
|
||||
gst_v4l2src_empty_format_list (GstV4l2Src *v4l2src)
|
||||
gst_v4l2src_clear_format_list (GstV4l2Src *v4l2src)
|
||||
{
|
||||
while (g_list_length(v4l2src->formats) > 0) {
|
||||
gpointer data = g_list_nth_data(v4l2src->formats, 0);
|
||||
v4l2src->formats = g_list_remove(v4l2src->formats, data);
|
||||
g_free(data);
|
||||
}
|
||||
g_list_free(v4l2src->format_list);
|
||||
v4l2src->format_list = NULL;
|
||||
g_slist_foreach (v4l2src->formats, (GFunc) g_free, NULL);
|
||||
g_slist_free (v4l2src->formats);
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -117,65 +110,47 @@ gst_v4l2src_empty_format_list (GstV4l2Src *v4l2src)
|
|||
* return value: TRUE on success, FALSE on error
|
||||
******************************************************/
|
||||
|
||||
static gboolean
|
||||
gboolean
|
||||
gst_v4l2src_queue_frame (GstV4l2Src *v4l2src,
|
||||
gint num)
|
||||
guint i)
|
||||
{
|
||||
DEBUG("queueing frame %d", num);
|
||||
GST_LOG_OBJECT (v4l2src, "queueing frame %u", i);
|
||||
|
||||
if (v4l2src->frame_queue_state[num] != QUEUE_STATE_READY_FOR_QUEUE) {
|
||||
return FALSE;
|
||||
}
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_QBUF, &v4l2src->pool->buffers[i].buffer) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src), "Error queueing buffer %u on device %s: %s",
|
||||
i, GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
v4l2src->bufsettings.index = num;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd,
|
||||
VIDIOC_QBUF, &v4l2src->bufsettings) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Error queueing buffer %d on device %s: %s",
|
||||
num, GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
v4l2src->frame_queue_state[num] = QUEUE_STATE_QUEUED;
|
||||
v4l2src->num_queued++;
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************
|
||||
* gst_v4l2src_sync_next_frame():
|
||||
* sync on a frame for capturing
|
||||
* gst_v4l2src_grab_frame ():
|
||||
* grab a frame for capturing
|
||||
* return value: TRUE on success, FALSE on error
|
||||
******************************************************/
|
||||
|
||||
static gboolean
|
||||
gst_v4l2src_sync_next_frame (GstV4l2Src *v4l2src,
|
||||
gint *num)
|
||||
gint
|
||||
gst_v4l2src_grab_frame (GstV4l2Src *v4l2src)
|
||||
{
|
||||
if (v4l2src->num_queued <= 0) {
|
||||
return FALSE;
|
||||
}
|
||||
struct v4l2_buffer buffer;
|
||||
|
||||
buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
while (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_DQBUF, &buffer) < 0) {
|
||||
/* if the sync() got interrupted, we can retry */
|
||||
if (errno != EINTR) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src), "Error syncing on a buffer on device %s: %s",
|
||||
GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
GST_DEBUG_OBJECT (v4l2src, "grab got interrupted");
|
||||
}
|
||||
|
||||
while (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd,
|
||||
VIDIOC_DQBUF, &v4l2src->bufsettings) < 0) {
|
||||
/* if the sync() got interrupted, we can retry */
|
||||
if (errno != EINTR) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Error syncing on a buffer on device %s: %s",
|
||||
GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
DEBUG("Sync got interrupted");
|
||||
}
|
||||
GST_LOG_OBJECT (v4l2src, "grabbed frame %d", buffer.index);
|
||||
|
||||
DEBUG("synced on frame %d", v4l2src->bufsettings.index);
|
||||
*num = v4l2src->bufsettings.index;
|
||||
|
||||
v4l2src->frame_queue_state[*num] = QUEUE_STATE_SYNCED;
|
||||
v4l2src->num_queued--;
|
||||
|
||||
return TRUE;
|
||||
return buffer.index;
|
||||
}
|
||||
|
||||
|
||||
|
@ -226,6 +201,7 @@ gst_v4l2src_set_capture (GstV4l2Src *v4l2src,
|
|||
v4l2src->format.fmt.pix.width = width;
|
||||
v4l2src->format.fmt.pix.height = height;
|
||||
v4l2src->format.fmt.pix.pixelformat = fmt->pixelformat;
|
||||
v4l2src->format.fmt.pix.field = V4L2_FIELD_INTERLACED;
|
||||
v4l2src->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_S_FMT, &v4l2src->format) < 0) {
|
||||
|
@ -250,88 +226,81 @@ gst_v4l2src_set_capture (GstV4l2Src *v4l2src,
|
|||
gboolean
|
||||
gst_v4l2src_capture_init (GstV4l2Src *v4l2src)
|
||||
{
|
||||
gint n;
|
||||
gchar *desc = NULL;
|
||||
struct v4l2_buffer buf;
|
||||
gint n;
|
||||
guint buffers;
|
||||
|
||||
DEBUG("initting the capture system");
|
||||
GST_DEBUG_OBJECT (v4l2src, "initting the capture system");
|
||||
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_NOT_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_NOT_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
|
||||
/* request buffer info */
|
||||
if (v4l2src->breq.count < MIN_BUFFERS_QUEUED) {
|
||||
v4l2src->breq.count = MIN_BUFFERS_QUEUED;
|
||||
}
|
||||
v4l2src->breq.type = v4l2src->format.type;
|
||||
v4l2src->breq.memory = V4L2_MEMORY_MMAP;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd,
|
||||
VIDIOC_REQBUFS, &v4l2src->breq) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Error requesting buffers (%d) for %s: %s",
|
||||
v4l2src->breq.count, GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
/* request buffer info */
|
||||
buffers = v4l2src->breq.count;
|
||||
if (v4l2src->breq.count > GST_V4L2_MAX_BUFFERS) {
|
||||
v4l2src->breq.count = GST_V4L2_MAX_BUFFERS;
|
||||
}
|
||||
if (v4l2src->breq.count < GST_V4L2_MIN_BUFFERS) {
|
||||
v4l2src->breq.count = GST_V4L2_MIN_BUFFERS;
|
||||
}
|
||||
v4l2src->breq.type = v4l2src->format.type;
|
||||
v4l2src->breq.memory = V4L2_MEMORY_MMAP;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_REQBUFS, &v4l2src->breq) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src), "Error requesting buffers (%d) for %s: %s",
|
||||
v4l2src->breq.count, GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (v4l2src->breq.count < MIN_BUFFERS_QUEUED) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Too little buffers. We got %d, we want at least %d",
|
||||
v4l2src->breq.count, MIN_BUFFERS_QUEUED);
|
||||
return FALSE;
|
||||
}
|
||||
v4l2src->bufsettings.type = v4l2src->format.type;
|
||||
if (v4l2src->breq.count < GST_V4L2_MIN_BUFFERS) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src), "Too little buffers. We got %d, we want at least %d",
|
||||
v4l2src->breq.count, GST_V4L2_MIN_BUFFERS);
|
||||
v4l2src->breq.count = buffers;
|
||||
return FALSE;
|
||||
}
|
||||
if (v4l2src->breq.count != buffers)
|
||||
g_object_notify (G_OBJECT (v4l2src), "num_buffers");
|
||||
|
||||
for (n=0;n<g_list_length(v4l2src->formats);n++) {
|
||||
struct v4l2_fmtdesc *fmt = (struct v4l2_fmtdesc *) g_list_nth_data(v4l2src->formats, n);
|
||||
if (v4l2src->format.fmt.pix.pixelformat == fmt->pixelformat) {
|
||||
desc = fmt->description;
|
||||
break;
|
||||
}
|
||||
}
|
||||
gst_info("Got %d buffers (%s) of size %d KB\n",
|
||||
v4l2src->breq.count, desc, v4l2src->format.fmt.pix.sizeimage/1024);
|
||||
GST_INFO_OBJECT (v4l2src, "Got %d buffers ("GST_FOURCC_FORMAT") of size %d KB\n",
|
||||
v4l2src->breq.count, GST_FOURCC_ARGS (v4l2src->format.fmt.pix.pixelformat),
|
||||
v4l2src->format.fmt.pix.sizeimage / 1024);
|
||||
|
||||
/* keep track of queued buffers */
|
||||
v4l2src->frame_queue_state = (gint8 *)
|
||||
g_malloc(sizeof(gint8) * v4l2src->breq.count);
|
||||
/* Map the buffers */
|
||||
v4l2src->pool = g_new (GstV4l2BufferPool, 1);
|
||||
gst_atomic_int_init (&v4l2src->pool->refcount, 1);
|
||||
v4l2src->pool->video_fd = GST_V4L2ELEMENT (v4l2src)->video_fd;
|
||||
v4l2src->pool->buffer_count = v4l2src->breq.count;
|
||||
v4l2src->pool->buffers = g_new0 (GstV4l2Buffer, v4l2src->breq.count);
|
||||
|
||||
/* track how often to use each frame */
|
||||
v4l2src->use_num_times = (gint *)
|
||||
g_malloc(sizeof(gint) * v4l2src->breq.count);
|
||||
for (n = 0; n < v4l2src->breq.count; n++) {
|
||||
GstV4l2Buffer *buffer = &v4l2src->pool->buffers[n];
|
||||
|
||||
/* lock for the frame_state */
|
||||
v4l2src->mutex_queue_state = g_mutex_new();
|
||||
v4l2src->cond_queue_state = g_cond_new();
|
||||
gst_atomic_int_init (&buffer->refcount, 1);
|
||||
buffer->pool = v4l2src->pool;
|
||||
buffer->buffer.index = n;
|
||||
buffer->buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_QUERYBUF, &buffer->buffer) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src), "Failed to get buffer (%d) properties: %s",
|
||||
n, g_strerror(errno));
|
||||
gst_v4l2src_capture_deinit(v4l2src);
|
||||
return FALSE;
|
||||
}
|
||||
buffer->start = mmap (0, buffer->buffer.length, PROT_READ|PROT_WRITE, MAP_SHARED,
|
||||
GST_V4L2ELEMENT(v4l2src)->video_fd, buffer->buffer.m.offset);
|
||||
if (buffer->start == MAP_FAILED) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src), "Error mapping video buffer (%d) on device %s: %s",
|
||||
n, GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
buffer->start = 0;
|
||||
gst_v4l2src_capture_deinit (v4l2src);
|
||||
return FALSE;
|
||||
}
|
||||
buffer->length = buffer->buffer.length;
|
||||
if (!gst_v4l2src_queue_frame(v4l2src, n)) {
|
||||
gst_v4l2src_capture_deinit (v4l2src);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Map the buffers */
|
||||
GST_V4L2ELEMENT(v4l2src)->buffer = (guint8 **)
|
||||
g_malloc(sizeof(guint8 *) * v4l2src->breq.count);
|
||||
for (n=0;n<v4l2src->breq.count;n++) {
|
||||
buf.index = n;
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd,
|
||||
VIDIOC_QUERYBUF, &buf) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Failed to get buffer (%d) properties: %s",
|
||||
n, g_strerror(errno));
|
||||
gst_v4l2src_capture_deinit(v4l2src);
|
||||
return FALSE;
|
||||
}
|
||||
GST_V4L2ELEMENT(v4l2src)->buffer[n] = mmap(0,
|
||||
buf.length, PROT_READ|PROT_WRITE, MAP_SHARED,
|
||||
GST_V4L2ELEMENT(v4l2src)->video_fd, buf.m.offset);
|
||||
if (GST_V4L2ELEMENT(v4l2src)->buffer[n] == MAP_FAILED) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Error mapping video buffer (%d) on device %s: %s",
|
||||
n, GST_V4L2ELEMENT(v4l2src)->device,
|
||||
g_strerror(errno));
|
||||
GST_V4L2ELEMENT(v4l2src)->buffer[n] = NULL;
|
||||
gst_v4l2src_capture_deinit(v4l2src);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
GST_V4L2_SET_ACTIVE(GST_V4L2ELEMENT (v4l2src));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -344,147 +313,25 @@ gst_v4l2src_capture_init (GstV4l2Src *v4l2src)
|
|||
gboolean
|
||||
gst_v4l2src_capture_start (GstV4l2Src *v4l2src)
|
||||
{
|
||||
gint n;
|
||||
gint type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
||||
DEBUG("starting the capturing");
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_DEBUG_OBJECT (v4l2src, "starting the capturing");
|
||||
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
if (!GST_V4L2_IS_ACTIVE (GST_V4L2ELEMENT(v4l2src))) {
|
||||
gst_pad_renegotiate (v4l2src->srcpad);
|
||||
}
|
||||
GST_V4L2_CHECK_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
|
||||
g_mutex_lock(v4l2src->mutex_queue_state);
|
||||
v4l2src->quit = FALSE;
|
||||
|
||||
v4l2src->quit = FALSE;
|
||||
v4l2src->num_queued = 0;
|
||||
v4l2src->queue_frame = 0;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_STREAMON, &type) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src), "Error starting streaming capture for %s: %s",
|
||||
GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set all buffers ready to queue , this starts streaming capture */
|
||||
for (n=0;n<v4l2src->breq.count;n++) {
|
||||
v4l2src->frame_queue_state[n] = QUEUE_STATE_READY_FOR_QUEUE;
|
||||
if (!gst_v4l2src_queue_frame(v4l2src, n)) {
|
||||
g_mutex_unlock(v4l2src->mutex_queue_state);
|
||||
gst_v4l2src_capture_stop(v4l2src);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
n = 1;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_STREAMON, &n) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Error starting streaming capture for %s: %s",
|
||||
GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_mutex_unlock(v4l2src->mutex_queue_state);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************
|
||||
* gst_v4l2src_grab_frame():
|
||||
* capture one frame during streaming capture
|
||||
* return value: TRUE on success, FALSE on error
|
||||
******************************************************/
|
||||
|
||||
gboolean
|
||||
gst_v4l2src_grab_frame (GstV4l2Src *v4l2src,
|
||||
gint *num)
|
||||
{
|
||||
DEBUG("syncing on the next frame");
|
||||
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
|
||||
g_mutex_lock(v4l2src->mutex_queue_state);
|
||||
|
||||
/* do we have enough frames? */
|
||||
while (v4l2src->num_queued < MIN_BUFFERS_QUEUED ||
|
||||
v4l2src->frame_queue_state[v4l2src->queue_frame] ==
|
||||
QUEUE_STATE_READY_FOR_QUEUE) {
|
||||
while (v4l2src->frame_queue_state[v4l2src->queue_frame] !=
|
||||
QUEUE_STATE_READY_FOR_QUEUE &&
|
||||
!v4l2src->quit) {
|
||||
GST_DEBUG (
|
||||
"Waiting for frames to become available (%d < %d)",
|
||||
v4l2src->num_queued, MIN_BUFFERS_QUEUED);
|
||||
g_cond_wait(v4l2src->cond_queue_state,
|
||||
v4l2src->mutex_queue_state);
|
||||
}
|
||||
if (v4l2src->quit) {
|
||||
g_mutex_unlock(v4l2src->mutex_queue_state);
|
||||
return TRUE; /* it won't get through anyway */
|
||||
}
|
||||
if (!gst_v4l2src_queue_frame(v4l2src, v4l2src->queue_frame)) {
|
||||
g_mutex_unlock(v4l2src->mutex_queue_state);
|
||||
return FALSE;
|
||||
}
|
||||
v4l2src->queue_frame = (v4l2src->queue_frame + 1) % v4l2src->breq.count;
|
||||
}
|
||||
|
||||
/* syncing on the buffer grabs it */
|
||||
if (!gst_v4l2src_sync_next_frame(v4l2src, num)) {
|
||||
g_mutex_unlock(v4l2src->mutex_queue_state);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_mutex_unlock(v4l2src->mutex_queue_state);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************
|
||||
*
|
||||
******************************************************/
|
||||
|
||||
guint8 *
|
||||
gst_v4l2src_get_buffer (GstV4l2Src *v4l2src,
|
||||
gint num)
|
||||
{
|
||||
if (!GST_V4L2_IS_ACTIVE(GST_V4L2ELEMENT(v4l2src)) ||
|
||||
!GST_V4L2_IS_OPEN(GST_V4L2ELEMENT(v4l2src)))
|
||||
return NULL;
|
||||
|
||||
if (num < 0 || num >= v4l2src->breq.count)
|
||||
return NULL;
|
||||
|
||||
return GST_V4L2ELEMENT(v4l2src)->buffer[num];
|
||||
}
|
||||
|
||||
|
||||
/******************************************************
|
||||
* gst_v4l2src_requeue_frame():
|
||||
* re-queue a frame after we're done with the buffer
|
||||
* return value: TRUE on success, FALSE on error
|
||||
******************************************************/
|
||||
|
||||
gboolean
|
||||
gst_v4l2src_requeue_frame (GstV4l2Src *v4l2src,
|
||||
gint num)
|
||||
{
|
||||
DEBUG("requeueing frame %d", num);
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
|
||||
/* mark frame as 'ready to requeue' */
|
||||
g_mutex_lock(v4l2src->mutex_queue_state);
|
||||
|
||||
if (v4l2src->frame_queue_state[num] != QUEUE_STATE_SYNCED) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Invalid state %d (expected %d), can't requeue",
|
||||
v4l2src->frame_queue_state[num],
|
||||
QUEUE_STATE_SYNCED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
v4l2src->frame_queue_state[num] = QUEUE_STATE_READY_FOR_QUEUE;
|
||||
|
||||
/* let an optional wait know */
|
||||
g_cond_broadcast(v4l2src->cond_queue_state);
|
||||
|
||||
g_mutex_unlock(v4l2src->mutex_queue_state);
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -497,37 +344,60 @@ gst_v4l2src_requeue_frame (GstV4l2Src *v4l2src,
|
|||
gboolean
|
||||
gst_v4l2src_capture_stop (GstV4l2Src *v4l2src)
|
||||
{
|
||||
gint n = 0;
|
||||
gint type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
||||
DEBUG("stopping capturing");
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_DEBUG_OBJECT (v4l2src, "stopping capturing");
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
|
||||
g_mutex_lock(v4l2src->mutex_queue_state);
|
||||
/* we actually need to sync on all queued buffers but not
|
||||
* on the non-queued ones */
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_STREAMOFF, &type) < 0) {
|
||||
gst_element_error (GST_ELEMENT(v4l2src), "Error stopping streaming capture for %s: %s",
|
||||
GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* we actually need to sync on all queued buffers but not
|
||||
* on the non-queued ones */
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_STREAMOFF, &n) < 0) {
|
||||
gst_element_error(GST_ELEMENT(v4l2src),
|
||||
"Error stopping streaming capture for %s: %s",
|
||||
GST_V4L2ELEMENT(v4l2src)->device, g_strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* make an optional pending wait stop */
|
||||
v4l2src->quit = TRUE;
|
||||
g_cond_broadcast(v4l2src->cond_queue_state);
|
||||
/* make an optional pending wait stop */
|
||||
v4l2src->quit = TRUE;
|
||||
|
||||
/* sync on remaining frames */
|
||||
while (v4l2src->num_queued > 0) {
|
||||
gst_v4l2src_sync_next_frame(v4l2src, &n);
|
||||
}
|
||||
|
||||
g_mutex_unlock(v4l2src->mutex_queue_state);
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_v4l2src_buffer_pool_free (GstV4l2BufferPool *pool, gboolean do_close)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < pool->buffer_count; i++) {
|
||||
gst_atomic_int_destroy (&pool->buffers[i].refcount);
|
||||
munmap (pool->buffers[i].start, pool->buffers[i].length);
|
||||
}
|
||||
g_free (pool->buffers);
|
||||
gst_atomic_int_destroy (&pool->refcount);
|
||||
if (do_close)
|
||||
close (pool->video_fd);
|
||||
g_free (pool);
|
||||
}
|
||||
|
||||
void
|
||||
gst_v4l2src_free_buffer (GstBuffer *buffer)
|
||||
{
|
||||
GstV4l2Buffer *buf = (GstV4l2Buffer *) GST_BUFFER_PRIVATE (buffer);
|
||||
|
||||
GST_LOG ("freeing buffer %p (nr. %d)", buffer, buf->buffer.index);
|
||||
|
||||
if (!gst_atomic_int_dec_and_test (&buf->refcount)) {
|
||||
/* we're still in use, add to queue again
|
||||
note: this might fail because the device is already stopped (race) */
|
||||
if (ioctl(buf->pool->video_fd, VIDIOC_QBUF, &buf->buffer) < 0)
|
||||
GST_INFO ("readding to queue failed, assuming video device is stopped");
|
||||
}
|
||||
if (gst_atomic_int_dec_and_test (&buf->pool->refcount)) {
|
||||
/* we're last thing that used all this */
|
||||
gst_v4l2src_buffer_pool_free (buf->pool, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* gst_v4l2src_capture_deinit():
|
||||
|
@ -538,31 +408,32 @@ gst_v4l2src_capture_stop (GstV4l2Src *v4l2src)
|
|||
gboolean
|
||||
gst_v4l2src_capture_deinit (GstV4l2Src *v4l2src)
|
||||
{
|
||||
int n;
|
||||
|
||||
DEBUG("deinitting capture system");
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
gint i, dequeue = 0;
|
||||
|
||||
GST_DEBUG_OBJECT (v4l2src, "deinitting capture system");
|
||||
|
||||
GST_V4L2_CHECK_OPEN(GST_V4L2ELEMENT(v4l2src));
|
||||
GST_V4L2_CHECK_ACTIVE(GST_V4L2ELEMENT(v4l2src));
|
||||
|
||||
/* unmap the buffer */
|
||||
for (n=0;n<v4l2src->breq.count;n++) {
|
||||
if (!GST_V4L2ELEMENT(v4l2src)->buffer[n]) {
|
||||
break;
|
||||
}
|
||||
munmap(GST_V4L2ELEMENT(v4l2src)->buffer[n],
|
||||
v4l2src->format.fmt.pix.sizeimage);
|
||||
GST_V4L2ELEMENT(v4l2src)->buffer[n] = NULL;
|
||||
}
|
||||
|
||||
/* free buffer tracker */
|
||||
g_free(GST_V4L2ELEMENT(v4l2src)->buffer);
|
||||
GST_V4L2ELEMENT(v4l2src)->buffer = NULL;
|
||||
g_mutex_free(v4l2src->mutex_queue_state);
|
||||
g_cond_free(v4l2src->cond_queue_state);
|
||||
g_free(v4l2src->frame_queue_state);
|
||||
g_free(v4l2src->use_num_times);
|
||||
|
||||
return TRUE;
|
||||
/* free the buffers */
|
||||
for (i = 0; i < v4l2src->breq.count; i++) {
|
||||
if (gst_atomic_int_dec_and_test (&v4l2src->pool->buffers[i].refcount))
|
||||
dequeue++;
|
||||
}
|
||||
for (i = 0; i < dequeue; i++) {
|
||||
struct v4l2_buffer buffer;
|
||||
buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd, VIDIOC_DQBUF, &buffer) < 0)
|
||||
GST_WARNING_OBJECT (v4l2src, "Could not dequeue buffer on uninitialization");
|
||||
}
|
||||
if (gst_atomic_int_dec_and_test (&v4l2src->pool->refcount)) {
|
||||
/* we're last thing that used all this */
|
||||
gst_v4l2src_buffer_pool_free (v4l2src->pool, FALSE);
|
||||
}
|
||||
v4l2src->pool = NULL;
|
||||
|
||||
GST_V4L2_SET_INACTIVE (GST_V4L2ELEMENT (v4l2src));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -578,13 +449,16 @@ gst_v4l2src_get_size_limits (GstV4l2Src *v4l2src,
|
|||
{
|
||||
struct v4l2_format fmt;
|
||||
|
||||
GST_LOG_OBJECT (v4l2src, "getting size limits with format " GST_FOURCC_FORMAT,
|
||||
GST_FOURCC_ARGS (format->pixelformat));
|
||||
|
||||
/* get size delimiters */
|
||||
memset(&fmt, 0, sizeof(fmt));
|
||||
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
fmt.fmt.pix.width = 0;
|
||||
fmt.fmt.pix.height = 0;
|
||||
fmt.fmt.pix.pixelformat = format->pixelformat;
|
||||
fmt.fmt.pix.field = V4L2_FIELD_ANY;
|
||||
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd,
|
||||
VIDIOC_TRY_FMT, &fmt) < 0) {
|
||||
return FALSE;
|
||||
|
@ -594,9 +468,10 @@ gst_v4l2src_get_size_limits (GstV4l2Src *v4l2src,
|
|||
*min_w = fmt.fmt.pix.width;
|
||||
if (min_h)
|
||||
*min_h = fmt.fmt.pix.height;
|
||||
GST_LOG_OBJECT (v4l2src, "got min size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
|
||||
|
||||
fmt.fmt.pix.width = G_MAXINT;
|
||||
fmt.fmt.pix.height = G_MAXINT;
|
||||
fmt.fmt.pix.height = 576;
|
||||
if (ioctl(GST_V4L2ELEMENT(v4l2src)->video_fd,
|
||||
VIDIOC_TRY_FMT, &fmt) < 0) {
|
||||
return FALSE;
|
||||
|
@ -606,6 +481,7 @@ gst_v4l2src_get_size_limits (GstV4l2Src *v4l2src,
|
|||
*max_w = fmt.fmt.pix.width;
|
||||
if (max_h)
|
||||
*max_h = fmt.fmt.pix.height;
|
||||
GST_LOG_OBJECT (v4l2src, "got max size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __V4L2_SRC_CALLS_H__
|
||||
#define __V4L2_SRC_CALLS_H__
|
||||
#ifndef __V4L2SRC_CALLS_H__
|
||||
#define __V4L2SRC_CALLS_H__
|
||||
|
||||
#include "gstv4l2src.h"
|
||||
#include "v4l2_calls.h"
|
||||
|
@ -31,17 +31,16 @@ gboolean gst_v4l2src_set_capture (GstV4l2Src *v4l2src,
|
|||
gint height);
|
||||
gboolean gst_v4l2src_capture_init (GstV4l2Src *v4l2src);
|
||||
gboolean gst_v4l2src_capture_start (GstV4l2Src *v4l2src);
|
||||
gboolean gst_v4l2src_grab_frame (GstV4l2Src *v4l2src,
|
||||
gint *num);
|
||||
gint gst_v4l2src_grab_frame (GstV4l2Src *v4l2src);
|
||||
guint8 * gst_v4l2src_get_buffer (GstV4l2Src *v4l2src,
|
||||
gint num);
|
||||
gboolean gst_v4l2src_requeue_frame (GstV4l2Src *v4l2src,
|
||||
gint num);
|
||||
gboolean gst_v4l2src_queue_frame (GstV4l2Src *v4l2src,
|
||||
guint i);
|
||||
gboolean gst_v4l2src_capture_stop (GstV4l2Src *v4l2src);
|
||||
gboolean gst_v4l2src_capture_deinit (GstV4l2Src *v4l2src);
|
||||
|
||||
gboolean gst_v4l2src_fill_format_list (GstV4l2Src *v4l2src);
|
||||
gboolean gst_v4l2src_empty_format_list (GstV4l2Src *v4l2src);
|
||||
gboolean gst_v4l2src_clear_format_list (GstV4l2Src *v4l2src);
|
||||
|
||||
/* hacky */
|
||||
gboolean gst_v4l2src_get_size_limits (GstV4l2Src *v4l2src,
|
||||
|
@ -49,4 +48,6 @@ gboolean gst_v4l2src_get_size_limits (GstV4l2Src *v4l2src,
|
|||
gint *min_w, gint *max_w,
|
||||
gint *min_h, gint *max_h);
|
||||
|
||||
#endif /* __V4L2_SRC_CALLS_H__ */
|
||||
void gst_v4l2src_free_buffer (GstBuffer *buffer);
|
||||
|
||||
#endif /* __V4L2SRC_CALLS_H__ */
|
||||
|
|
Loading…
Reference in a new issue