Problems when creating pipeline outside main thread

Daniel Spiessberger via gstreamer-devel <[email protected]> Mon, 23 Dec 2024 10:38:16 +0100
Newsgroups gmane.comp.video.gstreamer.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------TKKW4FA01QH0BkRNKW02zL61
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi everyone,

I’m working on a QtQuick application that uses GStreamer to display 
video streams. On my target hardware, creating the video decoder element 
(v4l2h264dec) takes some time, which blocks the main thread and freezes 
the GUI.

To avoid this, I’ve moved the pipeline creation, starting, and stopping 
to a |QThread|. However, I’m encountering an occasional problem (~1 in 
100 runs): the |v4l2h264dec| element gradually accumulates latency, 
leading to delays of up to ~20 seconds. Strangely, this issue doesn’t 
occur when the same pipeline is initialized and run from the main thread.

Here’s the pipeline: udpsrc port=5000 ! application/x-rtp, payload=96, 
encoding-name=H264 ! queue max-size-buffers=0 ! rtph264depay ! h264parse 
! v4l2h264dec ! imxvideoconvert_g2d ! qtvideosink sync=false
I’ve tried repositioning the |queue| element, but it doesn’t affect the 
outcome.

My questions are:

 1. What is the recommended approach for creating and managing GStreamer
    elements outside the main thread?
 2. Are there any specific considerations for synchronization or thread
    safety when using |QThread| for this purpose?

Any advice or insights would be greatly appreciated!

Thank you,
Daniel Spießberger

--------------TKKW4FA01QH0BkRNKW02zL61
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi everyone,</p>
    <p>I’m working on a QtQuick application that uses GStreamer to
      display video streams. On my target hardware, creating the video
      decoder element (v4l2h264dec) takes some time, which blocks the
      main thread and freezes the GUI.</p>
    <p>To avoid this, I’ve moved the pipeline creation, starting, and
      stopping to a <code>QThread</code>. However, I’m encountering an
      occasional problem (~1 in 100 runs): the <code>v4l2h264dec</code>
      element gradually accumulates latency, leading to delays of up to
      ~20 seconds. Strangely, this issue doesn’t occur when the same
      pipeline is initialized and run from the main thread.</p>
    <p>Here’s the pipeline: udpsrc port=5000 ! application/x-rtp,
      payload=96, encoding-name=H264 ! queue max-size-buffers=0 !
      rtph264depay ! h264parse ! v4l2h264dec ! imxvideoconvert_g2d !
      qtvideosink sync=false<br>
      I’ve tried repositioning the <code>queue</code> element, but it
      doesn’t affect the outcome.</p>
    <p>My questions are:</p>
    <ol>
      <li>What is the recommended approach for creating and managing
        GStreamer elements outside the main thread?</li>
      <li>Are there any specific considerations for synchronization or
        thread safety when using <code>QThread</code> for this purpose?</li>
    </ol>
    <p>Any advice or insights would be greatly appreciated!</p>
    <p>Thank you,<br>
      Daniel Spießberger<br>
    </p>
    <p></p>
  </body>
</html>

--------------TKKW4FA01QH0BkRNKW02zL61--