v4l2: remove unused variables

Use the more specialized type for the bufferpool.
Use the size from the driver as the size of the image to read.
Don't configure the pool when created. This will be done in the setup_allocation
method later or by upstream for sinks.
Remove unused properties and variables. Bufferpool sizes are now configured in
the bufferpool by the elements in the pipeline. We might want to influence the
pool size later somehow.
This commit is contained in:
Wim Taymans 2011-07-27 16:46:46 +02:00
parent b638bb4735
commit 63fc64dd98
6 changed files with 29 additions and 82 deletions

View file

@ -849,7 +849,7 @@ gst_v4l2_buffer_pool_class_init (GstV4l2BufferPoolClass * klass)
*
* Returns: the new pool, use gst_object_unref() to free resources
*/
GstBufferPool *
GstV4l2BufferPool *
gst_v4l2_buffer_pool_new (GstV4l2Object * obj)
{
GstV4l2BufferPool *pool;
@ -863,7 +863,7 @@ gst_v4l2_buffer_pool_new (GstV4l2Object * obj)
pool->video_fd = fd;
pool->obj = obj;
return GST_BUFFER_POOL_CAST (pool);
return pool;
/* ERRORS */
dup_failed:
@ -880,11 +880,11 @@ gst_v4l2_do_read (GstV4l2BufferPool * pool, GstBuffer * buf)
GstV4l2Object *obj = pool->obj;
gint amount;
gpointer data;
gint buffersize;
gint toread;
buffersize = gst_buffer_get_size (buf);
toread = obj->sizeimage;
GST_LOG_OBJECT (pool, "reading %d bytes into buffer %p", buffersize, buf);
GST_LOG_OBJECT (pool, "reading %d bytes into buffer %p", toread, buf);
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
@ -892,9 +892,9 @@ gst_v4l2_do_read (GstV4l2BufferPool * pool, GstBuffer * buf)
if ((res = gst_v4l2_object_poll (obj)) != GST_FLOW_OK)
goto poll_error;
amount = v4l2_read (obj->video_fd, data, buffersize);
amount = v4l2_read (obj->video_fd, data, toread);
if (amount == buffersize) {
if (amount == toread) {
break;
} else if (amount == -1) {
if (errno == EAGAIN || errno == EINTR) {
@ -922,7 +922,7 @@ read_error:
{
GST_ELEMENT_ERROR (obj->element, RESOURCE, READ,
(_("Error reading %d bytes from device '%s'."),
buffersize, obj->videodev), GST_ERROR_SYSTEM);
toread, obj->videodev), GST_ERROR_SYSTEM);
res = GST_FLOW_ERROR;
goto cleanup;
}
@ -945,10 +945,10 @@ cleanup:
* Returns: %GST_FLOW_OK on success.
*/
GstFlowReturn
gst_v4l2_buffer_pool_process (GstBufferPool * bpool, GstBuffer * buf)
gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer * buf)
{
GstFlowReturn ret = GST_FLOW_OK;
GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
GstBufferPool *bpool = GST_BUFFER_POOL_CAST (pool);
GstV4l2Object *obj = pool->obj;
GST_DEBUG_OBJECT (pool, "process buffer %p", buf);

View file

@ -84,9 +84,9 @@ const GstMetaInfo * gst_meta_v4l2_get_info (void);
GType gst_v4l2_buffer_pool_get_type (void);
GstBufferPool * gst_v4l2_buffer_pool_new (GstV4l2Object *obj);
GstV4l2BufferPool * gst_v4l2_buffer_pool_new (GstV4l2Object *obj);
GstFlowReturn gst_v4l2_buffer_pool_process (GstBufferPool * bpool, GstBuffer * buf);
GstFlowReturn gst_v4l2_buffer_pool_process (GstV4l2BufferPool * bpool, GstBuffer * buf);
G_END_DECLS

View file

@ -2092,8 +2092,6 @@ gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
static gboolean
gst_v4l2_object_setup_pool (GstV4l2Object * v4l2object, GstCaps * caps)
{
guint num_buffers;
GstStructure *config;
GstV4l2IOMode mode;
GST_DEBUG_OBJECT (v4l2object->element, "initializing the capture system");
@ -2123,20 +2121,12 @@ gst_v4l2_object_setup_pool (GstV4l2Object * v4l2object, GstCaps * caps)
GST_INFO_OBJECT (v4l2object->element, "accessing buffers via mode %d", mode);
v4l2object->mode = mode;
/* keep track of current number of buffers */
num_buffers = v4l2object->num_buffers;
/* Map the buffers */
GST_LOG_OBJECT (v4l2object->element, "initiating buffer pool");
if (!(v4l2object->pool = gst_v4l2_buffer_pool_new (v4l2object)))
goto buffer_pool_new_failed;
config = gst_buffer_pool_get_config (v4l2object->pool);
gst_buffer_pool_config_set (config, caps, v4l2object->info.size,
num_buffers, num_buffers, 0, 0);
gst_buffer_pool_set_config (v4l2object->pool, config);
GST_V4L2_SET_ACTIVE (v4l2object);
return TRUE;
@ -2266,6 +2256,8 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps)
v4l2object->bytesperline = format.fmt.pix.bytesperline;
v4l2object->sizeimage = format.fmt.pix.sizeimage;
GST_DEBUG_OBJECT (v4l2object->element, "Got sizeimage %u",
v4l2object->sizeimage);
/* Is there a reason we require the caller to always specify a framerate? */
GST_DEBUG_OBJECT (v4l2object->element, "Desired framerate: %u/%u", fps_n,
@ -2434,7 +2426,7 @@ gst_v4l2_object_stop (GstV4l2Object * v4l2object)
if (v4l2object->pool) {
GST_DEBUG_OBJECT (v4l2object->element, "deactivating pool");
gst_buffer_pool_set_active (v4l2object->pool, FALSE);
gst_buffer_pool_set_active (GST_BUFFER_POOL_CAST (v4l2object->pool), FALSE);
gst_object_unref (v4l2object->pool);
v4l2object->pool = NULL;
}

View file

@ -125,10 +125,8 @@ struct _GstV4l2Object {
GstV4l2IOMode req_mode;
/* optional pool */
guint32 num_buffers;
guint32 min_queued_bufs;
gboolean always_copy;
GstBufferPool *pool;
GstV4l2BufferPool *pool;
/* the video device's capabilities */
struct v4l2_capability vcap;

View file

@ -70,16 +70,12 @@
GST_DEBUG_CATEGORY (v4l2sink_debug);
#define GST_CAT_DEFAULT v4l2sink_debug
#define PROP_DEF_QUEUE_SIZE 12
#define PROP_DEF_MIN_QUEUED_BUFS 1
#define DEFAULT_PROP_DEVICE "/dev/video1"
enum
{
PROP_0,
V4L2_STD_OBJECT_PROPS,
PROP_QUEUE_SIZE,
PROP_MIN_QUEUED_BUFS,
PROP_OVERLAY_TOP,
PROP_OVERLAY_LEFT,
PROP_OVERLAY_WIDTH,
@ -170,17 +166,7 @@ gst_v4l2sink_class_init (GstV4l2SinkClass * klass)
gst_v4l2_object_install_properties_helper (gobject_class,
DEFAULT_PROP_DEVICE);
g_object_class_install_property (gobject_class, PROP_QUEUE_SIZE,
g_param_spec_uint ("queue-size", "Queue size",
"Number of buffers to be enqueud in the driver in streaming mode",
GST_V4L2_MIN_BUFFERS, GST_V4L2_MAX_BUFFERS, PROP_DEF_QUEUE_SIZE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MIN_QUEUED_BUFS,
g_param_spec_uint ("min-queued-bufs", "Minimum queued bufs",
"Minimum number of queued bufs; v4l2sink won't dqbuf if the driver "
"doesn't have more than this number (which normally you shouldn't change)",
0, GST_V4L2_MAX_BUFFERS, PROP_DEF_MIN_QUEUED_BUFS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_OVERLAY_TOP,
g_param_spec_int ("overlay-top", "Overlay top",
"The topmost (y) coordinate of the video overlay; top left corner of screen is 0,0",
@ -249,10 +235,6 @@ gst_v4l2sink_init (GstV4l2Sink * v4l2sink)
*/
g_object_set (v4l2sink, "device", "/dev/video1", NULL);
/* number of buffers requested */
v4l2sink->v4l2object->num_buffers = PROP_DEF_QUEUE_SIZE;
v4l2sink->v4l2object->min_queued_bufs = PROP_DEF_MIN_QUEUED_BUFS;
v4l2sink->probed_caps = NULL;
v4l2sink->current_caps = NULL;
@ -397,12 +379,6 @@ gst_v4l2sink_set_property (GObject * object,
if (!gst_v4l2_object_set_property_helper (v4l2sink->v4l2object,
prop_id, value, pspec)) {
switch (prop_id) {
case PROP_QUEUE_SIZE:
v4l2sink->v4l2object->num_buffers = g_value_get_uint (value);
break;
case PROP_MIN_QUEUED_BUFS:
v4l2sink->v4l2object->min_queued_bufs = g_value_get_uint (value);
break;
case PROP_OVERLAY_TOP:
v4l2sink->overlay.top = g_value_get_int (value);
v4l2sink->overlay_fields_set |= RECT_TOP_SET;
@ -460,12 +436,6 @@ gst_v4l2sink_get_property (GObject * object,
if (!gst_v4l2_object_get_property_helper (v4l2sink->v4l2object,
prop_id, value, pspec)) {
switch (prop_id) {
case PROP_QUEUE_SIZE:
g_value_set_uint (value, v4l2sink->v4l2object->num_buffers);
break;
case PROP_MIN_QUEUED_BUFS:
g_value_set_uint (value, v4l2sink->v4l2object->min_queued_bufs);
break;
case PROP_OVERLAY_TOP:
g_value_set_int (value, v4l2sink->overlay.top);
break;
@ -682,7 +652,7 @@ gst_v4l2sink_setup_allocation (GstBaseSink * bsink, GstQuery * query)
if (caps == NULL)
goto no_caps;
if ((pool = obj->pool))
if ((pool = GST_BUFFER_POOL_CAST (obj->pool)))
gst_object_ref (pool);
if (pool != NULL) {
@ -699,7 +669,8 @@ gst_v4l2sink_setup_allocation (GstBaseSink * bsink, GstQuery * query)
goto different_caps;
}
}
gst_query_set_allocation_params (query, size, 0, 0, 0, 15, pool);
/* we need at least 2 buffers to operate */
gst_query_set_allocation_params (query, size, 2, 0, 0, 15, pool);
/* we also support various metadata */
gst_query_add_allocation_meta (query, GST_META_API_VIDEO);

View file

@ -66,7 +66,6 @@
GST_DEBUG_CATEGORY (v4l2src_debug);
#define GST_CAT_DEFAULT v4l2src_debug
#define PROP_DEF_QUEUE_SIZE 4
#define PROP_DEF_ALWAYS_COPY TRUE
#define PROP_DEF_DECIMATE 1
@ -76,7 +75,6 @@ enum
{
PROP_0,
V4L2_STD_OBJECT_PROPS,
PROP_QUEUE_SIZE,
PROP_ALWAYS_COPY,
PROP_DECIMATE
};
@ -156,11 +154,6 @@ gst_v4l2src_class_init (GstV4l2SrcClass * klass)
gst_v4l2_object_install_properties_helper (gobject_class,
DEFAULT_PROP_DEVICE);
g_object_class_install_property (gobject_class, PROP_QUEUE_SIZE,
g_param_spec_uint ("queue-size", "Queue size",
"Number of buffers to be enqueud in the driver in streaming mode",
GST_V4L2_MIN_BUFFERS, GST_V4L2_MAX_BUFFERS, PROP_DEF_QUEUE_SIZE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_ALWAYS_COPY,
g_param_spec_boolean ("always-copy", "Always Copy",
"If the buffer will or not be used directly from mmap",
@ -215,9 +208,6 @@ gst_v4l2src_init (GstV4l2Src * v4l2src)
V4L2_BUF_TYPE_VIDEO_CAPTURE, DEFAULT_PROP_DEVICE,
gst_v4l2_get_input, gst_v4l2_set_input, NULL);
/* number of buffers requested */
v4l2src->v4l2object->num_buffers = PROP_DEF_QUEUE_SIZE;
v4l2src->v4l2object->always_copy = PROP_DEF_ALWAYS_COPY;
v4l2src->decimate = PROP_DEF_DECIMATE;
@ -256,9 +246,6 @@ gst_v4l2src_set_property (GObject * object,
if (!gst_v4l2_object_set_property_helper (v4l2src->v4l2object,
prop_id, value, pspec)) {
switch (prop_id) {
case PROP_QUEUE_SIZE:
v4l2src->v4l2object->num_buffers = g_value_get_uint (value);
break;
case PROP_ALWAYS_COPY:
v4l2src->v4l2object->always_copy = g_value_get_boolean (value);
break;
@ -281,9 +268,6 @@ gst_v4l2src_get_property (GObject * object,
if (!gst_v4l2_object_get_property_helper (v4l2src->v4l2object,
prop_id, value, pspec)) {
switch (prop_id) {
case PROP_QUEUE_SIZE:
g_value_set_uint (value, v4l2src->v4l2object->num_buffers);
break;
case PROP_ALWAYS_COPY:
g_value_set_boolean (value, v4l2src->v4l2object->always_copy);
break;
@ -553,7 +537,7 @@ gst_v4l2src_setup_allocation (GstBaseSrc * bsrc, GstQuery * query)
* buffer extra to capture while the other two buffers are downstream */
min += 1;
} else {
min = obj->num_buffers;
min = 2;
}
/* select a pool */
@ -563,7 +547,7 @@ gst_v4l2src_setup_allocation (GstBaseSrc * bsrc, GstQuery * query)
/* no downstream pool, use our own then */
GST_DEBUG_OBJECT (src,
"read/write mode: no downstream pool, using our own");
pool = obj->pool;
pool = GST_BUFFER_POOL_CAST (obj->pool);
size = obj->sizeimage;
} else {
/* in READ/WRITE mode, prefer a downstream pool because our own pool
@ -578,7 +562,7 @@ gst_v4l2src_setup_allocation (GstBaseSrc * bsrc, GstQuery * query)
case GST_V4L2_IO_MMAP:
case GST_V4L2_IO_USERPTR:
/* in streaming mode, prefer our own pool */
pool = obj->pool;
pool = GST_BUFFER_POOL_CAST (obj->pool);
size = obj->sizeimage;
GST_DEBUG_OBJECT (src,
"streaming mode: using our own pool %" GST_PTR_FORMAT, pool);
@ -615,9 +599,11 @@ static gboolean
gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query)
{
GstV4l2Src *src;
GstV4l2Object *obj;
gboolean res = FALSE;
src = GST_V4L2SRC (bsrc);
obj = src->v4l2object;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_LATENCY:{
@ -625,14 +611,14 @@ gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query)
guint32 fps_n, fps_d;
/* device must be open */
if (!GST_V4L2_IS_OPEN (src->v4l2object)) {
if (!GST_V4L2_IS_OPEN (obj)) {
GST_WARNING_OBJECT (src,
"Can't give latency since device isn't open !");
goto done;
}
fps_n = GST_V4L2_FPS_N (src->v4l2object);
fps_d = GST_V4L2_FPS_D (src->v4l2object);
fps_n = GST_V4L2_FPS_N (obj);
fps_d = GST_V4L2_FPS_D (obj);
/* we must have a framerate */
if (fps_n <= 0 || fps_d <= 0) {
@ -645,7 +631,7 @@ gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query)
min_latency = gst_util_uint64_scale_int (GST_SECOND, fps_d, fps_n);
/* max latency is total duration of the frame buffer */
max_latency = src->v4l2object->num_buffers * min_latency;
max_latency = obj->pool->max_buffers * min_latency;
GST_DEBUG_OBJECT (bsrc,
"report latency min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT,