def on_pad_added()

in awstreamer/gst_pipeline/stream_pipeline.py [0:0]


    def on_pad_added(self, src, new_pad, target):
        '''
        Callback function called on new pad added
        '''
        # Get new pad info
        new_pad_name = new_pad.get_name()
        new_pad_caps = new_pad.get_current_caps()
        new_pad_struct = new_pad_caps.get_structure(0)
        new_pad_type = new_pad_struct.get_name()

        logger.info("Received new pad '{0:s}' from '{1:s}'".format(
                new_pad_name,
                src.get_name()))
        logger.info(new_pad_caps.to_string())

        # Check payload type and set the blocking probe on audio
        add_block_probe = False
        if new_pad_type == "application/x-rtp" and new_pad_struct.has_field("media"):
            media_type = new_pad_struct.get_string("media")
            logger.info("Media type: %s" % media_type)
            if media_type != "video":
                add_block_probe = True
        elif new_pad_type.startswith("audio"):
            add_block_probe = True

        # Add blocking probe
        if add_block_probe:
            logger.info("Adding blocking probe to the pad: %s" % new_pad_name)
            new_pad.add_probe(Gst.PadProbeType.BLOCK, lambda x,y : Gst.PadProbeReturn.OK)
            return

        # Find target sink pad
        sink_pad = target.get_static_pad("sink")
        if not sink_pad:
            logger.info("Static sink pad not found for element '%s'. Searching by indices..." % target.name)
            for i in range(10):
                sink_pad = target.get_static_pad("sink_" + str(i))
                if sink_pad:
                    logger.info("Found static sink pad for element '%s': sink_%d" % (target.name, i))
                    break
        if not sink_pad:
            logger.error("Failed to find sink pad for element: %s" % target.name)

        if sink_pad.is_linked():
            logger.info("We are already linked. Ignoring.")
            return

        # Attempt the link
        ret = new_pad.link(sink_pad)
        if not ret == Gst.PadLinkReturn.OK:
            logger.info("Type is '{0:s}}' but link failed".format(new_pad_type))
        else:
            logger.info("Link succeeded (type '{0:s}')".format(new_pad_type))