Search code examples
gstreamerv4l2python-gstreamer

Gstreamer : 'src' element task going to PAUSE state when one of the elements in pipeline is added dynamically


I have the following pipeline :

v4l2src -> queue -> h264parse -> avdec_h264 -> identity ->
imagefreeze(added/removed dynamically) -> glupload -> glcolorconvert ->
gltransformation -> glimagesink
  1. I have a added a probe on the element identity srcpad.
  2. Based, on the user-input I add or remove dynamically the element imagefreeze

Here is the pseudo code :

#show live video on rendering window till no user input
#if user_input == 1:
  insert_imagefreeze  #analogous to image being displayed on rendering window
#if user_input == 2:
  delete_imagefreeze  #resume back showing live video as before
  1. Inserting imagefreeze is no problem, it works fine. I can observe the results that I would want to with a imagefreeze
  2. However, after the element imagefreeze is added, the element v4l2src task goes to a paused state. Here is the info log :

    0:03:39.608226968 [333m29510[00m      0x1561c00 [36mINFO   [00m [00m             v4l2src gstv4l2src.c:949:gst_v4l2src_create:<source>[00m sync to 0:03:39.066664476 out ts 0:03:39.375180156
    0:03:39.608449406 [333m29510[00m      0x1561c00 [36mINFO   [00m [00m             basesrc gstbasesrc.c:2965:gst_base_src_loop:<source>[00m pausing after gst_pad_push() = eos
    0:03:39.608561724 [333m29510[00m      0x1561c00 [36mINFO   [00m [00m                task gsttask.c:316:gst_task_func:<source:src>[00m Task going to paused.
    

Can anyone explain, why the source element of pipeline goes to a paused state once a new element is added to the pipeline.

And snippets from actual code :

def add_delete(self):
   if ui_input_cnt = 1  #updated based on user input
        self.idsrcpad = self.identity.get_static_pad("src")
        self.in_idle_probe = False
        self.probeID = self.idsrcpad.add_probe(Gst.PadProbeType.IDLE,self.lengthen_pipeline)

   if ui_input_cnt = 2        
        self.probeID2 = self.idsrcpad.add_probe(Gst.PadProbeType.IDLE,self.shorten_pipeline)

def lengthen_pipeline(self,pad,info):
    print("entered callback")
    global pipeline

    #restrict only 1 call to this callback 
    if self.in_idle_probe == True:
        print("callback for now restricted to one call per thread")
        return Gst.PadProbeReturn.OK

    if  self.in_idle_probe == False:
        self.in_idle_probe == True

    #create image freze element
    self.ifreeze = Gst.ElementFactory.make("imagefreeze","ifreeze")
    # increment reference
    self.ifreeze.ref()
    #add imagefreze to pipeline
    pipeline.add(self.ifreeze)
    #sync image freeze state to main pipeline
    self.ifreeze.sync_state_with_parent()

    #unlink identity and upload

    #1.get sink pad of upload and srcpad of identity
    sinkpad = self.upload.get_static_pad("sink")
    srcpad = self.identity.get_static_pad("src")
    print("unlinking identit srcpad - uplaod sinkpad")
    if self.check_and_unlink(srcpad,sinkpad):
        #2.get sink pad of imagefreeze
        sinkpad = self.ifreeze.get_static_pad("sink")

        #3. link identity src pad to image freeze sinkpad
        print("linking identity srcpad - ifreeze sinkpad")
        self.check_and_link(srcpad,sinkpad)

        #4. link imagefreeze src pad to upload sink pad
        #get image freeze srcpad and sinkpad of upload
        srcpad = self.ifreeze.get_static_pad("src")
        sinkpad = self.upload.get_static_pad("sink")
        print("linking ifreeze srcpad - upload sinkpad")
        if self.check_and_link(srcpad,sinkpad):
            return Gst.PadProbeReturn.REMOVE
    else:
        print("ERORR : unlinking")
    return -1

The functions check_and_link(srcpad,sinkpad) and check_and_unlink(srcpad,sinkpad), does no more than checking the src and sink pads, and then linking and unlinking accordingly.


Solution

  • The sink sends a EOS event, when the imagefreeze is added dynamically. This makes the pipeline go into a PAUSED state. However, why the sink receives a EOS event is still unclear, and needs further investigation. More information of the observations are provided here.