Skip to content

Instantly share code, notes, and snippets.

@Alfro
Last active June 1, 2020 22:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alfro/d94deab6b5b5314f2cee8167019c7239 to your computer and use it in GitHub Desktop.
Save Alfro/d94deab6b5b5314f2cee8167019c7239 to your computer and use it in GitHub Desktop.
Webcam bug - Resource busy when recording several times in a row

SUM UP:

When executing a .c script with this pipeline:

v4l2src name=gc-v4l2-src device="DEVICE" ! video/x-raw,framerate=24/1,width=640,height=480 !  xvimagesink

after a number of attempts, gstreamer seems to fail freeing the device:

0:00:26.941414390 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
0:00:27.492185197 11963      0x25bc830 ERROR          v4l2allocator gstv4l2allocator.c:1245:gst_v4l2_allocator_qbuf:<gc-v4l2-src:pool:src:allocator> failed queueing buffer 1: Invalid argument
0:00:27.492207147 11963      0x25bc830 ERROR         v4l2bufferpool gstv4l2bufferpool.c:1127:gst_v4l2_buffer_pool_qbuf:<gc-v4l2-src:pool:src> could not queue a buffer 1
0:00:27.534435394 11963      0x25bc830 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
0:00:27.534448591 11963      0x25bc830 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
0:00:27.676909420 11963      0x25bc830 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
0:00:27.676927405 11963      0x25bc830 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
0:00:27.676932431 11963      0x25bc830 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
0:00:27.676935481 11963      0x25bc830 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed

and the next pipeline fails:

libv4l2: error setting pixformat: Device or resource busy
0:00:30.144302919 11963      0x24fc720 WARN                 default v4l2-utils.c:188:gst_v4l2_error:<gc-v4l2-src> error: Device '/dev/video0' is busy
0:00:30.144333322 11963      0x24fc720 WARN                 default v4l2-utils.c:191:gst_v4l2_error:<gc-v4l2-src> error: Call to S_FMT failed for YV12 @ 640x480: Device or resource busy
0:00:30.144411621 11963      0x24fc720 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: Internal data flow error.
0:00:30.144424870 11963      0x24fc720 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: streaming task paused, reason not-negotiated (-4)

Tested with the following script: https://gist.github.com/Alfro/d94deab6b5b5314f2cee8167019c7239#file-ko-c

SO VERSION:

Ubuntu 16.04.1 LTS Linux 4.4.0-38-generic x86_64

GST VERSION:

gst-launch-1.0 version 1.8.2 GStreamer 1.8.2

UVCVIDEO KERNEL MODULE VERSION:

filename:       /lib/modules/4.4.0-38-generic/kernel/drivers/media/usb/uvc/uvcvideo.ko
version:        1.1.1
license:        GPL
description:    USB Video Class driver
author:         Laurent Pinchart <laurent.pinchart@ideasonboard.com>
srcversion:     BD755E7585400C05C5AE594
depends:        videodev,videobuf2-core,videobuf2-v4l2,media,videobuf2-vmalloc
intree:         Y
vermagic:       4.4.0-38-generic SMP mod_unload modversions

TEST CAMERA 1:

CAMERA HW:

UVC Camera (046d:0821)
    Logitech, Inc. HD Webcam C910

CAMERA DRIVER INFO:

Driver Info (not using libv4l2):
       Driver name   : uvcvideo
       Card type     : UVC Camera (046d:0821)
       Bus info      : usb-0000:00:14.0-1
       Driver version: 4.4.19
       Capabilities  : 0x84200001
              Video Capture
              Streaming
              Extended Pix Format
              Device Capabilities
       Device Caps   : 0x04200001
              Video Capture
              Streaming
              Extended Pix Format

TEST 1:

     $ GST_DEBUG=3 ./ko 3
     Test interval: 3
     v4l2src name=gc-v4l2-src device=/dev/video0 ! video/x-raw,framerate=24/1,width=640,height=480 !  xvimagesink ---> 0
     0:00:02.348111922 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 1
     0:00:05.527909895 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 2
     0:00:08.595750788 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 3
     0:00:11.656613580 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 4
     0:00:14.664742196 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 5
     0:00:17.735566049 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 6
     0:00:20.777213382 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 7
     0:00:23.858733706 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 8
     0:00:26.941414390 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     0:00:27.492185197 11963      0x25bc830 ERROR          v4l2allocator gstv4l2allocator.c:1245:gst_v4l2_allocator_qbuf:<gc-v4l2-src:pool:src:allocator> failed queueing buffer 1: Invalid argument
     0:00:27.492207147 11963      0x25bc830 ERROR         v4l2bufferpool gstv4l2bufferpool.c:1127:gst_v4l2_buffer_pool_qbuf:<gc-v4l2-src:pool:src> could not queue a buffer 1
     0:00:27.534435394 11963      0x25bc830 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:27.534448591 11963      0x25bc830 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     0:00:27.676909420 11963      0x25bc830 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:27.676927405 11963      0x25bc830 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     0:00:27.676932431 11963      0x25bc830 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:27.676935481 11963      0x25bc830 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     ---> 9
     libv4l2: error setting pixformat: Device or resource busy
     0:00:30.144302919 11963      0x24fc720 WARN                 default v4l2-utils.c:188:gst_v4l2_error:<gc-v4l2-src> error: Device '/dev/video0' is busy
     0:00:30.144333322 11963      0x24fc720 WARN                 default v4l2-utils.c:191:gst_v4l2_error:<gc-v4l2-src> error: Call to S_FMT failed for YV12 @ 640x480: Device or resource busy
     0:00:30.144411621 11963      0x24fc720 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: Internal data flow error.
     0:00:30.144424870 11963      0x24fc720 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: streaming task paused, reason not-negotiated (-4)
     Error waiting 1 sec

TEST 2:

      $ GST_DEBUG=3 ./ko 3
      Test interval: 3
      v4l2src name=gc-v4l2-src device=/dev/video0 ! video/x-raw,framerate=24/1,width=640,height=480 !  xvimagesink ---> 0
      0:00:02.348111922 11963      0x24fc720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
      ---> 1
      ...
      (same output from 1 to 70)
      ...
      ---> 71
      0:03:41.995749603 12747       0xf6f720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
      ---> 72
      0:03:45.052403514 12747       0xf6f720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
      0:03:45.576141112 12747       0xf6f720 ERROR          v4l2allocator gstv4l2allocator.c:1245:gst_v4l2_allocator_qbuf:<gc-v4l2-src:pool:src:allocator> failed queueing buffer 0: Invalid argument
      0:03:45.576166755 12747       0xf6f720 ERROR         v4l2bufferpool gstv4l2bufferpool.c:1127:gst_v4l2_buffer_pool_qbuf:<gc-v4l2-src:pool:src> could not queue a buffer 0
      0:03:45.603033994 12747      0x1140ed0 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
      0:03:45.603053445 12747      0x1140ed0 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
      0:03:45.746719579 12747      0x1140ed0 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
      0:03:45.746736880 12747      0x1140ed0 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
      0:03:45.746751924 12747      0x1140ed0 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
      0:03:45.746756933 12747      0x1140ed0 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
      ---> 73
      libv4l2: error setting pixformat: Device or resource busy
      0:03:48.208790087 12747       0xf6f720 WARN                 default v4l2-utils.c:188:gst_v4l2_error:<gc-v4l2-src> error: Device '/dev/video0' is busy
      0:03:48.208809020 12747       0xf6f720 WARN                 default v4l2-utils.c:191:gst_v4l2_error:<gc-v4l2-src> error: Call to S_FMT failed for YV12 @ 640x480: Device or resource busy
      0:03:48.208864327 12747       0xf6f720 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: Internal data flow error.
      0:03:48.208869270 12747       0xf6f720 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: streaming task paused, reason not-negotiated (-4)
      Error waiting 1 sec

TEST CAMERA 2:

CAMERA HW:

   Logitech, Inc. HD Pro Webcam C920

CAMERA DRIVER INFO:

   Driver name   : uvcvideo
   Card type     : HD Pro Webcam C920
   Bus info      : usb-0000:00:14.0-13
   Driver version: 4.4.19
   Capabilities  : 0x84200001
          Video Capture
          Streaming
          Extended Pix Format
          Device Capabilities
   Device Caps   : 0x04200001
          Video Capture
          Streaming
          Extended Pix Format

TEST 1:

     $ GST_DEBUG=3 ./ko 3
     Test interval: 3
     v4l2src name=gc-v4l2-src device=/dev/video0 ! video/x-raw,framerate=24/1,width=640,height=480 !  xvimagesink ---> 0
     0:00:00.068631649 15615      0x23c5720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 1
     0:00:03.345801583 15615      0x23c5720 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     0:00:06.502962147 15615      0x23c5720 ERROR          v4l2allocator gstv4l2allocator.c:1245:gst_v4l2_allocator_qbuf:<gc-v4l2-src:pool:src:allocator> failed queueing buffer 2: Invalid argument
     0:00:06.502992190 15615      0x23c5720 ERROR         v4l2bufferpool gstv4l2bufferpool.c:1127:gst_v4l2_buffer_pool_qbuf:<gc-v4l2-src:pool:src> could not queue a buffer 2
     0:00:06.556493384 15615      0x2596e40 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:06.556519816 15615      0x2596e40 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     0:00:06.747836018 15615      0x2596e40 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:06.747856167 15615      0x2596e40 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     0:00:06.747864227 15615      0x2596e40 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:06.747867607 15615      0x2596e40 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     ---> 2
     libv4l2: error setting pixformat: Device or resource busy
     0:00:06.819458926 15615      0x23c5720 WARN                 default v4l2-utils.c:188:gst_v4l2_error:<gc-v4l2-src> error: Device '/dev/video0' is busy
     0:00:06.819467204 15615      0x23c5720 WARN                 default v4l2-utils.c:191:gst_v4l2_error:<gc-v4l2-src> error: Call to S_FMT failed for YV12 @ 640x480: Device or resource busy
     Error waiting 1 sec
     0:00:06.819501079 15615      0x23c5720 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: Internal data flow error.
     0:00:06.819513615 15615      0x23c5720 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: streaming task paused, reason not-negotiated (-4)

TEST 2:

     $ GST_DEBUG=3 ./ko 3
     Test interval: 3
     v4l2src name=gc-v4l2-src device=/dev/video0 ! video/x-raw,framerate=24/1,width=640,height=480 !  xvimagesink ---> 0
     0:00:00.069775964 16098       0xa3cf20 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 1
     0:00:03.345500340 16098       0xa3cf20 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     ---> 2
     0:00:06.605737914 16098       0xa3cf20 WARN          v4l2bufferpool gstv4l2bufferpool.c:540:gst_v4l2_buffer_pool_set_config:<gc-v4l2-src:pool:src> libv4l2 converter detected, disabling CREATE_BUFS
     0:00:09.771795108 16098       0xa3cf20 ERROR          v4l2allocator gstv4l2allocator.c:1245:gst_v4l2_allocator_qbuf:<gc-v4l2-src:pool:src:allocator> failed queueing buffer 2: Invalid argument
     0:00:09.771818195 16098       0xa3cf20 ERROR         v4l2bufferpool gstv4l2bufferpool.c:1127:gst_v4l2_buffer_pool_qbuf:<gc-v4l2-src:pool:src> could not queue a buffer 2
     0:00:09.866366485 16098       0xc07240 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:09.866386382 16098       0xc07240 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     0:00:10.091141180 16098       0xc07240 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:10.091161449 16098       0xc07240 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     0:00:10.091168825 16098       0xc07240 WARN          v4l2bufferpool gstv4l2bufferpool.c:912:gst_v4l2_buffer_pool_stop:<gc-v4l2-src:pool:src> some buffers are still outstanding
     0:00:10.091172380 16098       0xc07240 WARN              bufferpool gstbufferpool.c:537:gst_buffer_pool_set_active:<gc-v4l2-src:pool:src> stop failed
     ---> 3
     libv4l2: error setting pixformat: Device or resource busy
     0:00:10.163473451 16098       0xa3cf20 WARN                 default v4l2-utils.c:188:gst_v4l2_error:<gc-v4l2-src> error: Device '/dev/video0' is busy
     0:00:10.163481384 16098       0xa3cf20 WARN                 default v4l2-utils.c:191:gst_v4l2_error:<gc-v4l2-src> error: Call to S_FMT failed for YV12 @ 640x480: Device or resource busy
     0:00:10.163534384 16098       0xa3cf20 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: Internal data flow error.
     Error waiting 1 sec
     0:00:10.163539715 16098       0xa3cf20 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<gc-v4l2-src> error: streaming task paused, reason not-negotiated (-4)
/*
* gcc ko.c -o ko `pkg-config --cflags --libs gstreamer-1.0`
*/
#include <gst/gst.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define DEVICE "/dev/video0"
int main(int argc, char *argv[]) {
GstElement *pipeline;
GstState state, pending;
GstBus *bus;
GstMessage *msg;
int i = 0;
int gstPipInterval = 1;
char *pipelinestr;
/* Initialize GStreamer */
gst_init (&argc, &argv);
if(argc == 2){
gstPipInterval = atoi(argv[1]);
printf("Test interval: %d\n", gstPipInterval);
}
else {
printf("Insert test interval: ");
scanf("%d", &gstPipInterval);
}
pipelinestr = "v4l2src name=gc-v4l2-src device="DEVICE" ! video/x-raw,framerate=24/1,width=640,height=480 ! xvimagesink";
printf("%s", pipelinestr);
while(1) {
printf(" ---> %d\n", i++);
/* Build the pipeline */
pipeline = gst_parse_launch (pipelinestr, NULL);
if (pipeline == NULL) {
printf("Error gen pipeline\n");
return -1;
}
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg = gst_bus_timed_pop_filtered (bus, gstPipInterval * GST_SECOND, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
if (msg != NULL) {
printf("Error waiting 1 sec\n");
return -1;
}
gst_element_send_event (pipeline, gst_event_new_eos ());
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Free resources */
if (msg != NULL)
gst_message_unref (msg);
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE);
gst_object_unref (pipeline);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment