After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 732288 - x264enc: Does not request enough buffers in allocation query
x264enc: Does not request enough buffers in allocation query
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-ugly
git master
Other Linux
: Normal normal
: 1.5.1
Assigned To: Nicolas Dufresne (ndufresne)
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-06-26 16:49 UTC by sazzad
Modified: 2014-07-25 18:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
stdout and stderr output (315.85 KB, text/plain)
2014-06-26 16:49 UTC, sazzad
  Details
[PATCH] videoencoder: Don't delay set_format (1.82 KB, patch)
2014-07-08 21:00 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
[PATCH] x264enc: Request buffers in allocation query (1.18 KB, patch)
2014-07-08 21:02 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
[PATCH] v4l2object: Don't skip configuration if active (1.35 KB, patch)
2014-07-08 21:03 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
[PATCH] v4l2object: Don't share own pool if min exceed V4L2 capacity (2.12 KB, patch)
2014-07-08 21:03 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
[PATCH] v4l2bufferpool: Workaround elements not requesting any buffers (1.13 KB, patch)
2014-07-08 21:51 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review

Description sazzad 2014-06-26 16:49:02 UTC
Created attachment 279330 [details]
stdout and stderr output

I have successfully compiled gstreamer1.0 from git source june 23,2014 (gstreamer, base, good, bad, ugly, libav) in Ubuntu 12.. However, gst-launch-1.0 fails with v4l2src saying failed to allocate buffer. On the other hand, gst-launc-0.1 (came with Ubuntu release) runs fine and does not fail with such error.

I found the same issue with 1.3 source tree.

------------------log-----------------

#gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw, width=640, height=480, framerate=15/1' ! queue ! videoconvert ! x264enc ! rtph264pay pt=96 ! udpsink host=127.0.0.1 port=5000
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Redistribute latency...
0:00:04.152979362 30179       0x8a5770 ERROR          v4l2allocator gstv4l2allocator.c:1326:gst_v4l2_allocator_dqbuf:<v4l2src0:pool:src:allocator> failed dequeuing a mmap buffer: Invalid argument
0:00:04.153024426 30179       0x8a5770 ERROR          v4l2allocator gstv4l2allocator.c:1338:gst_v4l2_allocator_dqbuf:<v4l2src0:pool:src:allocator> The buffer type is not supported, or the index is out of bounds, or no buffers have been allocated yet, or the userptr or length are invalid.
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Failed to allocate a buffer
Additional debug info:
gstv4l2src.c(736): gst_v4l2src_create (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0
Execution ended after 0:00:04.073653279
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
-----------------------------
/dev/video0 is a USB webcam, vlc can open it either with v4l2. 
Attached file contains the stdout and stderr output with  GST_DEBUG=v4l*:6
Comment 1 Gwenole Beauchesne 2014-06-26 17:04:53 UTC
0:00:04.120210834 [333m  458[00m      0x1471f70 [31;01mERROR  [00m [00m       v4l2allocator gstv4l2allocator.c:1326:gst_v4l2_allocator_dqbuf:<v4l2src0:pool:src:allocator>[00m failed dequeuing a mmap buffer: Invalid argument
0:00:04.120215825 [333m  458[00m      0x1471f70 [31;01mERROR  [00m [00m       v4l2allocator gstv4l2allocator.c:1338:gst_v4l2_allocator_dqbuf:<v4l2src0:pool:src:allocator>[00m The buffer type is not supported, or the index is out of bounds, or no buffers have been allocated yet, or the userptr or length are invalid.
0:00:04.120220062 [333m  458[00m      0x1471f70 [33;01mWARN   [00m [00m             v4l2src gstv4l2src.c:736:gst_v4l2src_create:<v4l2src0>[00m error: Failed to allocate a buffer
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Failed to allocate a buffer

PS: if you want to dump logs to a file, please use GST_DEBUG_NO_COLOR=1 :)
Comment 2 Nicolas Dufresne (ndufresne) 2014-06-28 16:38:51 UTC
It seems to run for a while, and then suddenly fail. It most likely fail in the driver. Also, a driver bugs is exposed, as it does not update flags correctly.

To go forward, and find a solution, we would need to get some kernel traces, as "invalid argument" is used nearly everywhere in the kernel. Also, providing kernel version and which drivers (most of the time it's UVC for USB webcams, but there is couple non-UVC drivers too). Also, please compare results with and without libv4l2, and specify version of libv4l2 being used, as the rework of v4l2 framework have rendered visible few bugs in that library.
Comment 3 Songwater 2014-06-30 06:15:07 UTC
With version 1.3.3 ,My x264enc works fine, but x265enc have the same problem. When this happened , the x265 encoder would have many frames to input without encoded result to output. So this error may be caused by v4l2src buffer occupied by x265encoder. I found that only 2 buffers allocated by default  in v4l2src , if the encoder don't release the buffer , the v4l2src will has no buffer to capture picture, the line in /gst-plugins-good-1.3.3/sys/v4l2/gstv4l2allocator.c
 if (v4l2_ioctl (allocator->video_fd, VIDIOC_DQBUF, &buffer) < 0)
    goto error;
will report this error.
In gst-plugins-good-1.3.3/sys/v4l2/gstv4l2object.h, I change GST_V4L2_MIN_BUFFERS from 2 to 32,my x265enc works fine with out that error, but this change sounds so ugly . How to change the buffer numbers of the v4l2src plug-in?
Comment 4 Nicolas Dufresne (ndufresne) 2014-06-30 15:11:23 UTC
It should have stalled rather then failed, but this is another issue. The problem here is that you need to expose how many buffers you'll need in the allocation query (see propose_allocation() virtual method of the encoder base class). This will let v4l2 know how many buffers to allocate.
Comment 5 Nicolas Dufresne (ndufresne) 2014-07-08 01:25:12 UTC
As the other bug is fixed now, it properly stalls. Not we need to fix x264enc to request enough buffers.
Comment 6 Nicolas Dufresne (ndufresne) 2014-07-08 21:00:08 UTC
Created attachment 280186 [details] [review]
[PATCH] videoencoder: Don't delay set_format


This prevent implementing allocation query, as the format need to be
known in order to determin the size and number of buffers needed.

https://bugzilla.gnome.org/show_bug.cgi?id=73228
---
 gst-libs/gst/video/gstvideoencoder.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
Comment 7 Nicolas Dufresne (ndufresne) 2014-07-08 21:02:20 UTC
Created attachment 280187 [details] [review]
[PATCH] x264enc: Request buffers in allocation query


https://bugzilla.gnome.org/show_bug.cgi?id=73228
---
 ext/x264/gstx264enc.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Comment 8 Nicolas Dufresne (ndufresne) 2014-07-08 21:03:13 UTC
Created attachment 280188 [details] [review]
[PATCH] v4l2object: Don't skip configuration if active


Bug 728268 has been fix. If the configuration is different, pool will now
try to deactivate the pool in order to update the config
---
 sys/v4l2/gstv4l2object.c | 9 ---------
 1 file changed, 9 deletions(-)
Comment 9 Nicolas Dufresne (ndufresne) 2014-07-08 21:03:18 UTC
Created attachment 280189 [details] [review]
[PATCH] v4l2object: Don't share own pool if min exceed V4L2 capacity


If the minimum required buffer exceed V4L2 capacity, don't share down
pool. This allow support very high latency, like with x264enc default
encoding settings.

https://bugzilla.gnome.org/show_bug.cgi?id=73228
---
 sys/v4l2/gstv4l2object.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
Comment 10 Nicolas Dufresne (ndufresne) 2014-07-08 21:04:30 UTC
So these are for after the freeze. As some more decoder will need to be revisited, I'll try to come up with a workaround (similar to what happened in 1.2 for the upcoming 1.4 release.
Comment 11 Nicolas Dufresne (ndufresne) 2014-07-08 21:51:24 UTC
Created attachment 280193 [details] [review]
[PATCH] v4l2bufferpool: Workaround elements not requesting any buffers


This is a workaround for element that don't request buffers when
they should.

https://bugzilla.gnome.org/show_bug.cgi?id=73228
---
 sys/v4l2/gstv4l2bufferpool.c | 6 ++++++
 1 file changed, 6 insertions(+)
Comment 12 Nicolas Dufresne (ndufresne) 2014-07-08 21:52:18 UTC
This last one is a workaround, which would be similar to what 1.2 was doing.
Comment 13 Sebastian Dröge (slomo) 2014-07-09 07:31:02 UTC
Comment on attachment 280187 [details] [review]
[PATCH] x264enc: Request buffers in allocation query

That seems safe for 1.4 too
Comment 14 Sebastian Dröge (slomo) 2014-07-09 07:32:52 UTC
Comment on attachment 280186 [details] [review]
[PATCH] videoencoder: Don't delay set_format

Seems fine to me for 1.6... but why did we do this complicated delaying at all? Can you investigate? Maybe there was a reason we need to consider :)

Also you probably want to get rid of the do_caps boolean now
Comment 15 Nicolas Dufresne (ndufresne) 2014-07-09 12:14:51 UTC
(In reply to comment #14)
> (From update of attachment 280186 [details] [review])
> Seems fine to me for 1.6... but why did we do this complicated delaying at all?
> Can you investigate? Maybe there was a reason we need to consider :)
> 

Should have added the reference in the commit log I guess, see:
https://bugzilla.gnome.org/show_bug.cgi?id=680614

> Also you probably want to get rid of the do_caps boolean now

Ok, I thought it was removed, will fix.
Comment 16 Nicolas Dufresne (ndufresne) 2014-07-09 13:23:04 UTC
(In reply to comment #13)
> (From update of attachment 280187 [details] [review])
> That seems safe for 1.4 too

This patch has no effect without the base class fix, input_state is always NULL right now, hence the allocation query will always fail. I would try and make sure if input_state is missing that we endup doing that same as before. At least, we would ensure the a pool is provided, and that no copy due to stride is done ?
Comment 17 Nicolas Dufresne (ndufresne) 2014-07-10 22:22:58 UTC
Ready for 1.4.

commit d03bcba3db15d06dbdea6b776a6f28ed2f03272a
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Tue Jul 8 17:50:47 2014 -0400

    v4l2bufferpool: Workaround elements not requesting any buffers
    
    This is a workaround for element that don't request buffers when
    they should.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732288
Comment 18 Nicolas Dufresne (ndufresne) 2014-07-25 18:19:51 UTC
Comment on attachment 280186 [details] [review]
[PATCH] videoencoder: Don't delay set_format

commit ce50fc221e8a795d7cfedf471d239d4a9d3bf824
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Tue Jul 8 16:59:37 2014 -0400

    videoencoder: Don't delay set_format
    
    This prevent implementing allocation query, as the format need to be
    known in order to determin the size and number of buffers needed.
    
    Note: This may lead to few regressions that will need fixing
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732288
Comment 19 Nicolas Dufresne (ndufresne) 2014-07-25 18:25:16 UTC
Comment on attachment 280188 [details] [review]
[PATCH] v4l2object: Don't skip configuration if active

commit e196906b993285f3405690f6240f5dcd491ae9ea
Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Date:   Sat May 24 19:02:59 2014 -0400

    v4l2object: Remove is_active checks
    
    These checks are no longer required with recent change to the bufferpool. This
    should allow changing the configuartion, hence the way forward renegotiation
    support.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728268
Comment 20 Nicolas Dufresne (ndufresne) 2014-07-25 18:25:37 UTC
(In reply to comment #19)
> (From update of attachment 280188 [details] [review])
> commit e196906b993285f3405690f6240f5dcd491ae9ea
> Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
> Date:   Sat May 24 19:02:59 2014 -0400
> 
>     v4l2object: Remove is_active checks
> 
>     These checks are no longer required with recent change to the bufferpool.
> This
>     should allow changing the configuartion, hence the way forward
> renegotiation
>     support.
> 
>     https://bugzilla.gnome.org/show_bug.cgi?id=728268

Sorry, wrong one.
Comment 21 Nicolas Dufresne (ndufresne) 2014-07-25 18:26:46 UTC
Comment on attachment 280188 [details] [review]
[PATCH] v4l2object: Don't skip configuration if active

was don differently elswhere, so just marking obsolte.
Comment 22 Nicolas Dufresne (ndufresne) 2014-07-25 18:27:35 UTC
Comment on attachment 280189 [details] [review]
[PATCH] v4l2object: Don't share own pool if min exceed V4L2 capacity

commit 3df949c7454b39d0394c4d9c6583393972edeff0
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Tue Jul 8 14:31:59 2014 -0400

    v4l2object: Don't share own pool if min exceed V4L2 capacity
    
    If the minimum required buffer exceed V4L2 capacity, don't share down
    pool. This allow support very high latency, like with x264enc default
    encoding settings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732288
Comment 23 Nicolas Dufresne (ndufresne) 2014-07-25 18:30:00 UTC
Comment on attachment 280187 [details] [review]
[PATCH] x264enc: Request buffers in allocation query

commit 8aea88d2616c3be8dd30a883534031d832872c9c
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Tue Jul 8 16:45:45 2014 -0400

    x264enc: Request buffers in allocation query
    
    https://bugzilla.gnome.org/show_bug.cgi?id=73228
Comment 24 Nicolas Dufresne (ndufresne) 2014-07-25 18:41:19 UTC
commit 287517d6a9803445b0e9afcfc144afa713b7b1b0
Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Date:   Fri Jul 25 14:30:33 2014 -0400

    Revert "v4l2bufferpool: Workaround elements not requesting any buffers"
    
    This was a tempory workaround, we should fix the encoders that do not
    negotatiate the amount of buffers they need.
    
    This reverts commit d03bcba3db15d06dbdea6b776a6f28ed2f03272a.

That's it, time to fix decoders if you see one being broken.