This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Gstreamer v4l2src element giving segfault when "always-copy=false" parameter is used

Hello,

we are using gstreamer to access omx camera nad stream video over RTP. The pipeline works, but it consumes lot of CPU. Threfore I was doing some profiling and found out that most of the time (almost 70%) is spent in memcpy(). Further googling revealed that the v4l2 element might be responsible for it as it copies each frame. There is a parameter called always-copy which prevents the memory copiing when set to false.

Unfortunately when applying this parameter the pipeline fails with segfault. I tested the parameter with very simple pipelines and it seems that when anything other than fakesink is used as sink in the pipeline it crashes.

Can we somehow fix this?

The output of the pipeline is below. The other errors can be probably ignored as the pipe starts with them just fine (...and it is not possible to get rid of them).

libdce-x11.c:64:        dce_auth_x11    info: attempting to open X11 connection
Setting pipeline to PAUSED ...
libv4l2: error getting pixformat: Invalid argument
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
src/omx_proxy_camera.c:239      Camera_SendCommand()    ERROR:  Error in DCC Init
Setting pipeline to PAUSED ...
libv4l2: error getting pixformat: Invalid argument
libv4l2: error getting pixformat: Invalid argument
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Caught SIGSEGV accessing address 0x2c
./camera_rtp_start.sh: line 23: 29654 Segmentation fault      DISPLAY=:0 gst-launch -e v4l2src always-copy=false device=/dev/video0 ! tee name=t ! queue ! v4l2sink device=/dev/video1 t. ! queue ! v4l2sink device=/dev/video2
Setting pipeline to PAUSED ...
libv4l2: error getting pixformat: Invalid argument
libdce-x11.c:64:        dce_auth_x11    info: attempting to open X11 connection
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Could not negotiate format
Additional debug info:
gstbasesrc.c(2830): gst_base_src_start (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Check your filtered caps, if any
Setting pipeline to NULL ...
Freeing pipeline ...
Setting pipeline to PAUSED ...
libv4l2: error getting pixformat: Invalid argument
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Could not negotiate format
Additional debug info:
gstbasesrc.c(2830): gst_base_src_start (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Check your filtered caps, if any
Setting pipeline to NULL ...
Freeing pipeline ...

Pipeline itself is here:

function startStreamingWithPhoto() {
    local STREAM_IMAGE="/opt/km/sg-server/media/stream.jpg"
    if [[ ${USE_RAMDISK} == true ]]; then
        STREAM_IMAGE=$(createVirtualMediaFolder)"/stream.jpg"
    fi

    DISPLAY=:0 gst-launch -e \
     omx_camera mode=1 device=0 focus=2 output-buffers=8 video-output-buffers=8 allocate-buffers=true \
      do-timestamp=true mtis=true scene-mode=6 flicker-mode=3 flicker=1 nsf=2 gbce=2 lbce=2 name=cam cam.src \
      ! "video/x-raw-yuv,width=(int)${WIDTH},height=(int)${HEIGHT},framerate=(fraction)${FPS}/1" \
      ! v4l2sink enable-last-buffer=false device=/dev/video0 &
    sleep 2
    #echo "------CAM DONE-----"
    DISPLAY=:0 gst-launch -e  \
     v4l2src always-copy=false device=/dev/video0 \
      ! tee name=t \
      ! queue \
      ! v4l2sink device=/dev/video1 t. \
      ! queue \
      ! v4l2sink device=/dev/video2 &
    sleep 1
    #echo "------SPLIT DONE-----"
    DISPLAY=:0 gst-launch -e \
     gstrtpbin name=r sdes="application/x-rtp-source-sdes,cname=(string)\"airelens\@konicaminolta.eu\"" \
      v4l2src do-timestamp=true device=/dev/video1 \
      ! videorate drop-only=true \
      ! "video/x-raw-yuv,framerate=(fraction)${FPS}/1" \
      ! autovideoconvert \
      ! ducatih264enc rate-preset=low-delay hrd-buffer-size=8192 slice-mode=1 inter-interval=16 entropy-coding-mode=1 bitrate=${BITRATE} \
      ! rtph264pay mtu=1200 \
      ! "application/x-rtp,payload=(int)103,clock-rate=(int)90000,ssrc=(uint)${SELF_VSSRC}" \
      ! r.send_rtp_sink_1 r.send_rtp_src_1 \
      ! udpsink host=${PEER_IP} port=${PEER_V} async=false  &
    sleep 1
    #echo "------RTP DONE-----"
    DISPLAY=:0 gst-launch -e \
     v4l2src device=/dev/video2 \
      ! videorate drop-only=true \
      ! "video/x-raw-yuv,framerate=1/1" \
      ! jpegenc quality=${STREAMING_QUALITY} \
      ! multifilesink location="${STREAM_IMAGE}" &
    sleep 1
    #echo "---- IMAGE DONE ----"
}