Commit graph

103 commits

Author SHA1 Message Date
Julien Isorce
3c70741e45 v4l2bufferpool: add support for multi-planar V4l2 API in DMABUF mode
Fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=712754
2013-12-04 09:28:25 +00:00
Julien Isorce
303cec48db v4l2: refactor by emulating one v4l2_plane in non-MPLANE mode
so that the buffer informations can be retrieved the same way
in both MPLANE and non-MPLANE mode.

Here "emulating" means "manually fill in the plane".

Fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=712754
2013-12-04 09:28:08 +00:00
Julien Isorce
61ae84b50d v4l2: add support for multi-planar V4L2 API
This api is in linux kernel since version 2.6.39,
and present in all version 3.

The commit that adds the API in master branch of the
linux kernel source is:
f8f3914cf9

v4l2 doc: "Some devices require data for each input
or output video frame to be placed in discontiguous
memory buffers"

There are newer structures 'struct v4l2_pix_format_mplane'
and 'struct v4l2_plane'.
So the pixel format is not setup with the same API when using
multi-planar.

Also for gst-v4l2, one of the difference is that in GstV4l2Meta
there are now one mem pointer for each maped plane.

When not using multi-planar, this commit takes care of keeping
the same code path than previously. So that the 2 cases are
in two different blocks triggered from V4L2_TYPE_IS_MULTIPLANAR.

Fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=712754
2013-12-04 09:27:20 +00:00
Marc Leeman
bc87f39a90 v4l2: init v4l2_buffer to 0x0 before ioctl
https://bugzilla.gnome.org/show_bug.cgi?id=712137
2013-11-12 13:08:33 -05:00
Peter Korsgaard
94f3d6fc07 v4l2bufferpool: O_CLOEXEC needs _GNU_SOURCE
On some systems (E.G. uClibc and older Glibc versions), O_CLOEXEC is only
defined when _GNU_SOURCE is specified, so do so.

_GNU_SOURCE needs to be defined before any system headers are included,
so move the fcntl.h section up.

https://bugzilla.gnome.org/show_bug.cgi?id=709423
2013-10-04 14:33:43 +02:00
Robert Krakora
141a1fc296 v4l2bufferpool: Restore original GstMemory in buffer if it has been changed
https://bugzilla.gnome.org/show_bug.cgi?id=706083
2013-09-23 11:58:39 -04:00
Olivier Crête
d1e16f7b0c v4l2bufferpool: dmabuf is not a singleton anymore
https://bugzilla.gnome.org/show_bug.cgi?id=707793
2013-09-18 15:13:59 -04:00
Mathieu Duponchelle
374a97a3e9 v4l2: Use newly #defined metadata names. 2013-09-09 15:39:17 +02:00
Sebastian Dröge
478f0dcfe7 v4l2bufferpool: Fix missing condition in previous commit 2013-09-09 14:46:42 +02:00
Sebastian Dröge
1e7c3e4520 v4l2bufferpool: Also fix strides for other semi-planar video formats 2013-09-09 14:45:55 +02:00
Andreea Fulger
78adf28a61 v4l2bufferpool: Fix stride for NV12/NV21
https://bugzilla.gnome.org/show_bug.cgi?id=707758
2013-09-09 14:45:55 +02:00
Michael Olbrich
07e4dd3424 v4l2: bufferpool: don't forget to release buffer on error
If the pool is stopped while gst_v4l2_buffer_pool_dqbuf() waits for a
buffer then the return value is GST_FLOW_FLUSHING. In this case the buffer
to queue must also be released. Otherwise is will never be deleted or
returned to its pool.

https://bugzilla.gnome.org/show_bug.cgi?id=703764
2013-07-08 16:27:19 +02:00
Michael Olbrich
a1c34b5407 v4l2: make sure the element is not deleted before the pool
The pool accesses data from the v4l2object so it must exist at least
as long as the pool. Refcount the element which controls the object
live-time.

https://bugzilla.gnome.org/show_bug.cgi?id=701650
2013-06-07 20:07:42 +02:00
Michael Olbrich
3417a791ac v4l2: call VIDIOC_REQBUFS with count = 0 in pool_finalize
Without this the following sequence fails:

- set_caps()
  - object_stop() (does nothing)
  - set_format() -> VIDIOC_S_FMT
- set_config() -> VIDIOC_REQBUFS with count = N
- set_caps()
  - object_stop()
    - pool_finalize()
  - set_format() -> VIDIOC_S_FMT => EBUSY

Usually the pool is started after set_config(), in which case object_stop()
will result in a pool_stop and therefore VIDIOC_REQBUFS with count = 0 but
that is not guaranteed.
Also calling VIDIOC_REQBUFS with count = 0 in pool_finalize() if necessary
fixes this problem.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=701543
2013-06-04 10:45:06 +02:00
Michael Olbrich
496995a7d5 v4l2: rework sink buffer refcounting
This is a followup patch for #700781, which is not quite correct.
The buffer handling is quite complicated here.
The original code intended to the the following:

- gst_v4l2_buffer_pool_process() calls QBUF and adds the buffer to the
  local list.
- The sink calls gst_buffer_unref() which returns the buffer to the pool
  but not the 'free list'.
- Some time later DQBUF returns the buffer and
  gst_v4l2_buffer_pool_release_buffer() puts in on the 'free list'.

If the buffer must be copied then (parent_class)->acquire_buffer() is
called directly to keep the buffer in the pool.

This has two problems:
1. If gst_v4l2_buffer_pool_release_buffer() is called before the buffer is
   returned to the pool, then the buffer is put on the 'free list' twice.
   This can happen if a reference to the buffer is kept outside the sink,
   of if DQBUF returns the buffer, that was just queued with QBUF.
2. If buffers are copied, then all buffers are in the pool at all times. As
   a result gst_v4l2_buffer_pool_stop() and gst_v4l2_buffer_pool_dqbuf()
   can access pool->buffers at the same time, which can lead to memory
   corruption.

The patch for #700781 fixes those problems, but with the side effect that
there are always buffers outside the pool (because they are queued) and
the pool is never stopped.
This patch fixes this by releasing the reference to the buffer after
handling it (to avoid problem 2.) so it can be returned to the pool.
gst_v4l2_buffer_pool_release_buffer() is only called if the buffer is
already in the pool (to avoid problem 1.).

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=701375
2013-06-03 11:55:48 +02:00
Michael Olbrich
f9cc655adf v4l2: keep a reference to all queued buffers
Without this, a queued buffer may be required, filled and queued before it
is dequeued.
Calling gst_buffer_pool_acquire_buffer() ensures that the buffer is set up
correctly and gst_buffer_unref() calls buffer_release().

https://bugzilla.gnome.org/show_bug.cgi?id=700781
2013-05-21 16:44:58 +02:00
Michael Olbrich
113b60935a v4l2: request 0 buffers when stopping
Without this stopping the pool in *_set_caps() is useless.
S_FMT will still fail with EBUSY.

https://bugzilla.gnome.org/show_bug.cgi?id=699835
2013-05-07 16:39:41 +02:00
Philipp Zabel
59d7d5c6bb v4l2: fill out v4l2_buffer.bytesused field for v4l2sink
When queuing a buffer for a sink, bytesused must contain the actual
amount of data.

For a source, the driver must overwrite this, so it doesn't matter
what is set here.

https://bugzilla.gnome.org/show_bug.cgi?id=699598
2013-05-04 11:19:14 +01:00
Michael Olbrich
1e777ede92 v4l2: try to allocate new buffers with VIDIOC_CREATE_BUFS if needed
If max_buffers is 0 then an arbitrary number of buffers (currently 4) is
allocated. If this is not enough v4l2src starts copying buffers.
With this patch VIDIOC_CREATE_BUFS is used to allocate a new buffer. If
this fails v4l2src falls back to copying buffers.

https://bugzilla.gnome.org/show_bug.cgi?id=699447
2013-05-03 11:18:04 +02:00
Michael Olbrich
eebe5fc70d v4l2: fix and cleanup VIDIOC_EXPBUF handling
clear the struct, and provide a correct error message

https://bugzilla.gnome.org/show_bug.cgi?id=699337
2013-05-01 15:40:55 +02:00
Michael Olbrich
d4126ff986 v4l2: also poll for output devices
Note that the V4L2 API defines that for output devices POLLOUT
indicates that a buffer is ready to be dequeued.

https://bugzilla.gnome.org/show_bug.cgi?id=698992
2013-04-27 09:31:29 +01:00
Michael Olbrich
2e80c0d2c0 v4l2: bufferpool: reset buffer size in release_buffer
The buffer might still be in use elsewhere when dequeuing buffers for
outputs.

https://bugzilla.gnome.org/show_bug.cgi?id=698822
2013-04-25 12:34:24 +02:00
Michael Olbrich
8f9cc96a69 v4l2: bufferpool: remove unused includes
The hacks that needed these are long gone.

https://bugzilla.gnome.org/show_bug.cgi?id=698821
2013-04-25 11:30:48 +01:00
Wim Taymans
14300e5805 v4l2: free all queued buffers
Don't just loop over the first num_queued buffers but loop over
all the buffers and check if they need to be freed. It is possible that
not all buffers are queued and then the entry in our array will be NULL.
Those buffers that are not queued were freed in stop().

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=696651
2013-04-03 11:14:41 +02:00
Wim Taymans
0dfc88d893 v4l2: improve debug 2013-04-03 11:14:41 +02:00
Benjamin Gaignard
e29ab42922 v4l2: Add support of dmabuf
v4l has add a new IOCTL to export a buffer by using dmabuf.
This patch allow to use this new IOTCL if it has been defined in videodev2.h
I introduce a new IO mode (GST_V4L2_IO_DMABUF) to enable this way of working.

https://bugzilla.gnome.org/show_bug.cgi?id=693826
2013-02-19 12:57:07 +01:00
Benjamin Gaignard
59e583b59f v4l2: don't check stride for encoded formats
Don't try to check the stride for encoded formats. Some drivers output
something != 0 and then we don't want to fail on that.
2013-02-15 16:23:23 +01:00
Tim-Philipp Müller
230cf41cc9 Fix FSF address
https://bugzilla.gnome.org/show_bug.cgi?id=687520
2012-11-04 00:07:18 +00:00
Michael Smith
b04b1b5089 meta info: threadsafe registration using g_once 2012-10-03 10:51:45 -07:00
Matthias Clasen
9f2aa8d47f v4l2: fix build with recent kernels, the v4l2_buffer input field was removed
This was unused apparently and removed in the kernel in commit:

 From 2b719d7baf490e24ce7d817c6337b7c87fda84c1 Mon Sep 17 00:00:00 2001
 From: Sakari Ailus <sakari.ailus@iki.fi>
 Date: Wed, 2 May 2012 09:40:03 -0300
 Subject: [PATCH] [media] v4l: drop v4l2_buffer.input and V4L2_BUF_FLAG_INPUT

 Remove input field in struct v4l2_buffer and flag V4L2_BUF_FLAG_INPUT which
 tells the former is valid. The flag is used by no driver currently.

https://bugzilla.gnome.org/show_bug.cgi?id=681491

Conflicts:
	sys/v4l2/gstv4l2bufferpool.c
2012-08-09 08:40:33 +01:00
Tim-Philipp Müller
787c314ec3 Silence some 'variable may be used uninitialized' compiler warnings
When compiling with -DG_DISABLE_ASSERT
2012-08-08 11:31:59 +01:00
Wim Taymans
2052cabdc4 fix for allocator API changes 2012-07-09 16:28:41 +02:00
Wim Taymans
56690cf021 v4l2: improve debug 2012-06-26 13:19:02 +02:00
Wim Taymans
77f33e591f Revert "v4l2: free kernel buffers before allocating new ones"
This reverts commit 1b09bc609a.

Seems to make libv4l2 complain, maybe because we call REQBUFS with 0 buffers
before we allocated buffers.
2012-06-26 13:02:13 +02:00
Wim Taymans
1b09bc609a v4l2: free kernel buffers before allocating new ones
See https://bugzilla.gnome.org/show_bug.cgi?id=670257
2012-06-26 12:07:47 +02:00
Wim Taymans
f4e3ae65ab v4l2: setup strides and offsets for all planes 2012-06-26 11:14:59 +02:00
Wim Taymans
46045316ce v4l2: use driver timestamps
Use the drive timestamps for timestamping outgoing buffers.
2012-04-24 12:37:33 +02:00
Wim Taymans
eecb9a96a6 v4l2: Improve buffer management
Query the amount of available buffers when doing set_config(). This allows us to
configure the parent bufferpool with the number of buffers to preallocate.
Keep track of the provided allocator and use it when we need to allocate a
buffer in RW mode.
When we are can not allocate the requested max_buffers amount of buffers, make
sure we keep 2 buffers around in the pool and copy them into an output buffer.
This makes sure that we always have a buffer to capture into. We also need to
detect those copied buffers and unref them when they return to the pool.
2012-04-23 18:10:33 +02:00
Wim Taymans
713ddbf541 v4l2: free the queued buffers
Only free the queued buffers that we keep track of in our buffer array. for rw
io-mode, we do allocate buffers but we don't keep track of them in the buffer
array.
2012-04-23 18:10:33 +02:00
Wim Taymans
5d7d4e0d9b v4l2: mark memory as no-share
We don't support sharing our mmapped memory so mark it as NO_SHARE.
2012-04-23 18:10:33 +02:00
Wim Taymans
f08bab4e86 v4l2: update for video api change 2012-04-19 14:16:01 +02:00
Sebastian Dröge
04b70571e5 video: Update for libgstvideo API changes 2012-04-19 12:20:59 +02:00
Wim Taymans
3d61d12e03 update for buffer api change 2012-03-30 18:15:34 +02:00
Wim Taymans
098d8ceae7 v4l2: update for get_param
Remove const from the GstCaps.
Plug some GstStructure leaks
2012-03-27 12:44:46 +02:00
Wim Taymans
fa436c0799 v4l2: called base class start
Chain up to the base class start method so that metadata is properly tagged.
Remove an unused variable.

fixes: https://bugzilla.gnome.org/show_bug.cgi?id=672813
2012-03-26 15:33:59 +02:00
Wim Taymans
ced47580b7 update for bufferpool changes 2012-03-15 22:11:17 +01:00
Wim Taymans
6ed3bc109b update for bufferpool api change 2012-03-15 14:06:40 +01:00
Wim Taymans
ecaea36c3d update for memory api changes 2012-03-15 13:36:17 +01:00
Wim Taymans
751fcf035b take padding into account 2012-03-14 19:56:56 +01:00
Wim Taymans
9c789aa434 update for metadata API changes 2012-02-29 17:26:01 +01:00