Ravi Modha
Ravi Modha

Reputation: 51

GstBus not getting EOS Event

I am new to GStreamer and i have created a small example where I am recording the webcam and used appsink to get the sample but when i try to stop the pipeline by setting its state to null and sending EOS event, my bus callback function never gets called for the EOS.

Guys, Please help me

class Main: shutdown = False

def __init__(self):
    signal.signal(signal.SIGINT, self.keyboardInterruptHandler)

    self._pipeline = Gst.parse_launch("avfvideosrc name=avfvideosrc ! x264enc name=x264enc ! appsink name=appsink max-buffers=1 drop=false sync=false emit-signals=true wait-on-eos=false")
    bus = self._pipeline.get_bus()
    bus.add_signal_watch()
    bus.connect("message::eos", self._on_eos_from_sink_pipeline)
    bus.connect("message", self.on_status_changed)
    appsink = self._pipeline.get_by_name('appsink')
    appsink.connect('new-sample', self.on_new_sample)
    appsink.connect('eos', self.eos)

    #bus.connect('message', self.on_status_changed)
    self._pipeline.set_state(Gst.State.PLAYING)

def on_new_sample(self, appsink):
    return Gst.FlowReturn.OK

def _on_eos_from_sink_pipeline(self, _bus, _message):
    print("Got EOS from sink pipeline")
    exit()

def eos(self, sink):
    print("SINK EOS")
    return True

def on_status_changed(self, bus, message):
    print('Status: ', message.type)
    print('Object: ', message.src)
    print('Parsed Message: ', message.parse_state_changed())

def keyboardInterruptHandler(self,signal, frame):
    print("KeyboardInterrupt (ID: {}) has been caught. Cleaning up...".format(signal))
    self.shutdown = True
    self.stopFetching()

def stopFetching(self):
    print("AT THE START OF STOP FETCHING")       
    self._pipeline.set_state(Gst.State.NULL)
    self._pipeline.send_event(Gst.Event.new_eos())
    print("AT THE END OF STOP FETCHING")

start = Main() Gtk.main()

Upvotes: 0

Views: 1312

Answers (1)

thiagoss
thiagoss

Reputation: 2094

You need to send EOS and wait for it to reach your handler. Once that happens, you can set the pipeline to NULL to shut down the pipeline completely.

In your current code, when you set it to NULL and then send an event, the pipeline is already down (setting to NULL happens synchronously) and the event won't be sent.

Upvotes: 1

Related Questions