Example #1
0
def gst_buffer_with_pad_to_ndarray(buffer: Gst.Buffer,
                                   pad: Gst.Pad,
                                   do_copy: bool = False) -> np.ndarray:
    """Converts Gst.Buffer with Gst.Pad (stores Gst.Caps) to np.ndarray """
    return gst_buffer_with_caps_to_ndarray(buffer,
                                           pad.get_current_caps(),
                                           do_copy=do_copy)
Example #2
0
def _link_pads(a: Gst.Pad, b: Gst.Pad):
    """
    link two Gst.Pad by doing a.link(b) but with extra logging.

    :arg a: src pad to link from
    :arg b: sink pad to link to

    :raises: LinkError if link fails
    """
    # check pads are not none
    if a is None or b is None:
        raise LinkError(f'cannot link {a} to {b} because one is None (null)')
    # try to link pads
    ret = a.link(b)
    if ret == Gst.PadLinkReturn.OK:
        logger.debug(f'pad link between {a.parent.name}:{a.name} and '
                     f'{b.parent.name}{b.name} OK')
        return
    elif ret == Gst.PadLinkReturn.WRONG_HIERARCHY:
        # todo: handle this automatically (really, gstreamer itself should)
        #  but at least this saves some googling
        raise LinkError(
            f"could not link {a.name} to {b.name} because you need to create"
            f"ghost pads from the elements inside the bin to the bin itself."
            f"You may need to request a pad if it's not a static pad.")
    elif ret == Gst.PadLinkReturn.WAS_LINKED:
        for pad in (a, b):  # type: Gst.Pad
            if pad.is_linked():
                peer = pad.get_peer()  # type: Gst.Pad
                raise LinkError(
                    f"{pad.name} of {pad.get_parent_element().name} is already "
                    f"linked to {peer.name} of {peer.get_parent_element().name}"
                )
    elif ret == Gst.PadLinkReturn.NOFORMAT:
        a_caps = a.get_current_caps()
        b_caps = b.get_current_caps()
        raise LinkError(
            f"could not link pads {a.name} and {b.name} because caps are "
            f"incompatible:\n"
            f"{a.name}: {a_caps.to_string() if a_caps is not None else a_caps}\n"
            f"{b.name}: {b_caps.to_string() if b_caps is not None else b_caps}"
        )
    else:
        raise LinkError(
            f"could not link {a.name} on {a.get_parent_element().name} "
            f"to {b.name} on {b.get_parent_element().name} because "
            f"pad return: {ret.value_name}")
Example #3
0
def gst_buffer_with_pad_for_ndarray(buffer: Gst.Buffer, pad: Gst.Pad) -> np.ndarray:
    """Converts Gst.Buffer with Gst.Pad (stores Gst.Caps) to np.ndarray
    Returns: 
        np.ndarray(c, w, h)
    """
    return gst_buffer_with_caps_for_ndarray(buffer, pad.get_current_caps())
Example #4
0
def gst_buffer_with_pad_for_tensor(buffer: Gst.Buffer,
                                   pad: Gst.Pad) -> np.ndarray:
    """Converts Gst.Buffer with Gst.Pad (stores Gst.Caps) to np.ndarray """
    return gst_buffer_with_caps_to_tensor(buffer, pad.get_current_caps())