GNOME Bugzilla – Bug 767086
v4l2src: pushes incomplete raw video buffers
Last modified: 2016-06-07 21:23:32 UTC
With Inogeni 4K2USB3 (uvc device) sometime we push few raw video buffers that smaller than expected at the beginning of the stream. This leads to downstream elements to fail mapping the buffer. GST_DEBUG=v4l2src:6,v4l2bufferpool:6,v4l2allocator:6 gst-launch-1.0 -q --gst-debug-no-color v4l2src ! video/x-raw, format=NV12, width=1920, height=1080, framerate=\(GstFraction\)60/1 ! queue ! vaapih264enc ! fakesink 2> ~/gst.log ``` 0:00:01.022924707 3537 0x2571ad0 DEBUG v4l2bufferpool gstv4l2bufferpool.c:945:gst_v4l2_buffer_pool_flush_stop:<v4l2src0:pool:src> stop flushing 0:00:01.023306617 3537 0x2571ad0 DEBUG v4l2bufferpool gstv4l2bufferpool.c:623:gst_v4l2_buffer_pool_streamon:<v4l2src0:pool:src> Started streaming 0:00:01.023517695 3537 0x2571ad0 DEBUG v4l2bufferpool gstv4l2bufferpool.c:1300:gst_v4l2_buffer_pool_acquire_buffer:<v4l2src0:pool:src> acquire 0:00:01.023577922 3537 0x2571ad0 LOG v4l2bufferpool gstv4l2bufferpool.c:1017:gst_v4l2_buffer_pool_poll:<v4l2src0:pool:src> polling device 0:00:01.023637313 3537 0x2571ad0 LOG v4l2bufferpool gstv4l2bufferpool.c:1149:gst_v4l2_buffer_pool_dqbuf:<v4l2src0:pool:src> dequeueing a buffer 0:00:01.023705512 3537 0x2571ad0 LOG v4l2allocator gstv4l2allocator.c:1306:gst_v4l2_allocator_dqbuf:<v4l2src0:pool:src:allocator> dequeued buffer 0 (flags 0x12005) 0:00:01.023755785 3537 0x2571ad0 DEBUG v4l2allocator gstv4l2allocator.c:1310:gst_v4l2_allocator_dqbuf:<v4l2src0:pool:src:allocator> driver pretends buffer is queued even if dequeue succeeded 0:00:01.023792180 3537 0x2571ad0 LOG v4l2bufferpool gstv4l2bufferpool.c:1181:gst_v4l2_buffer_pool_dqbuf:<v4l2src0:pool:src> dequeued buffer 0x7f3c10024020 seq:0 (ix=0), mem 0x256bd80 used 16092, plane=0, flags 00012001, ts 0:13:49.994804000, pool-queued=1, buffer=0x7f3c10024020 0:00:01.023878313 3537 0x2571ad0 DEBUG v4l2bufferpool gstv4l2bufferpool.c:1704:gst_v4l2_buffer_pool_process:<v4l2src0:pool:src> process buffer 0x7f3c1fffed08 0:00:01.023942762 3537 0x2571ad0 DEBUG v4l2src gstv4l2src.c:774:gst_v4l2src_create:<v4l2src0> ts: 0:13:49.994804000 now 0:13:49.995415403 delay 0:00:00.000611403 0:00:01.024030202 3537 0x2571ad0 INFO v4l2src gstv4l2src.c:810:gst_v4l2src_create:<v4l2src0> sync to 0:00:00.016666666 out ts 0:00:00.746377358 0:00:01.024271077 3537 0x2571ad0 DEBUG v4l2bufferpool gstv4l2bufferpool.c:1300:gst_v4l2_buffer_pool_acquire_buffer:<v4l2src0:pool:src> acquire 0:00:01.024349631 3537 0x2571ad0 LOG v4l2bufferpool gstv4l2bufferpool.c:1017:gst_v4l2_buffer_pool_poll:<v4l2src0:pool:src> polling device 0:00:01.024337878 3537 0x2571a30 ERROR default video-frame.c:161:gst_video_frame_map_id: failed to map video frame plane 1 0:00:01.031779897 3537 0x2571ad0 LOG v4l2bufferpool gstv4l2bufferpool.c:1149:gst_v4l2_buffer_pool_dqbuf:<v4l2src0:pool:src> dequeueing a buffer 0:00:01.031839315 3537 0x2571ad0 LOG v4l2allocator gstv4l2allocator.c:1306:gst_v4l2_allocator_dqbuf:<v4l2src0:pool:src:allocator> dequeued buffer 1 (flags 0x12005) 0:00:01.031879412 3537 0x2571ad0 DEBUG v4l2allocator gstv4l2allocator.c:1310:gst_v4l2_allocator_dqbuf:<v4l2src0:pool:src:allocator> driver pretends buffer is queued even if dequeue succeeded 0:00:01.031909941 3537 0x2571ad0 LOG v4l2bufferpool gstv4l2bufferpool.c:1181:gst_v4l2_buffer_pool_dqbuf:<v4l2src0:pool:src> dequeued buffer 0x7f3c10024130 seq:1 (ix=1), mem 0x256bea0 used 3110400, plane=0, flags 00012001, ts 0:13:49.994840000, pool-queued=0, buffer=0x7f3c10024130 0:00:01.031970462 3537 0x2571ad0 DEBUG v4l2bufferpool gstv4l2bufferpool.c:1704:gst_v4l2_buffer_pool_process:<v4l2src0:pool:src> process buffer 0x7f3c1fffed08 0:00:01.032002386 3537 0x2571ad0 DEBUG v4l2bufferpool gstv4l2bufferpool.c:675:gst_v4l2_buffer_pool_resurect_buffer:<v4l2src0:pool:src> A buffer was lost, reallocating it 0:00:01.032032683 3537 0x2571ad0 DEBUG v4l2bufferpool gstv4l2bufferpool.c:1300:gst_v4l2_buffer_pool_acquire_buffer:<v4l2src0:pool:src> acquire ```
Created attachment 328843 [details] [review] v4l2src: check for valid size on raw video buffers Proposed fix.
Review of attachment 328843 [details] [review]: ::: sys/v4l2/gstv4l2bufferpool.c @@ +1738,3 @@ + if (GST_VIDEO_INFO_FORMAT (&obj->info) != GST_VIDEO_FORMAT_ENCODED + && size < GST_VIDEO_INFO_SIZE (&obj->info)) { + goto buffer_corrupted; Sounds safe, we should warn about the fact that this is a driver bug also. Want to add that ? I'm fine with merging as-is too.
(In reply to Nicolas Dufresne (stormer) from comment #2) > Sounds safe, we should warn about the fact that this is a driver bug also. > Want to add that ? I'm fine with merging as-is too. Tomorrow I'll add a GST_WARNING message and I'll push it then.
commit b7866315a6c9004c5e0c201e55107ecd81951cdc Author: Josep Torra <adn770@gmail.com> Date: Tue May 31 21:34:04 2016 +0200 v4l2src: check for valid size on raw video buffers Discard buffers that doesn't contain enough data when dealing with raw video inputs. https://bugzilla.gnome.org/show_bug.cgi?id=767086
I'd like to backport this one into 1.8, let me know if you have any concerns.
Branch: 1.8 Commit: c26f5b6222c4b5d2d5d95555b24d9f058454ebbe