'''
Created on Oct 20, 2015

'''

from gi.repository import Gst, GLib

if __name__ == '__main__':
    Gst.init(None)
    
    #h264 - the error occurs
    pipe = Gst.parse_launch("videotestsrc ! x264enc tune=zerolatency ! rtph264pay ! queue name=paybuffer ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink")
    #theora - never encountered a buffer list
    #pipe = Gst.parse_launch("videotestsrc ! theoraenc ! rtptheorapay ! queue name=paybuffer ! rtptheoradepay ! theoradec ! videoconvert ! autovideosink")
    #mpeg4 - also encountered the problem with bufferlists
    #pipe = Gst.parse_launch("videotestsrc ! avenc_mpeg4 ! rtpmp4vpay ! queue name=paybuffer ! rtpmp4vdepay ! avdec_mpeg4 ! videoconvert ! autovideosink")
    
    paybuffer = pipe.get_by_name("paybuffer")
    
    def buffer_probe_callback(pad, padprobeinfo):
        if (padprobeinfo.type & Gst.PadProbeType.BUFFER) == Gst.PadProbeType.BUFFER:
            print("it claims to have a buffer")
            buf = padprobeinfo.get_buffer()
            print(" .... here is the buffer %s"%buf)
        if (padprobeinfo.type & Gst.PadProbeType.BUFFER_LIST) == Gst.PadProbeType.BUFFER_LIST:
            print("it claims to have a buffer list")
            buflist = padprobeinfo.get_buffer_list()
            print(" .... here is the buffer list %s"%buflist)
            #now there should be GStreamer-CRITICAL messages with  assertion 'GST_IS_BUFFER_LIST (list)' failed 
            
        return Gst.PadProbeReturn.OK
        
    
    paybuffer.get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER | Gst.PadProbeType.BUFFER_LIST, buffer_probe_callback)
    
    pipe.set_state(Gst.State.PLAYING)
    
    mainloop = GLib.MainLoop()
    mainloop.run()