Beispiel #1
0
/*
 * Method: get_child(index)
 * Method: get_child(name, recurse=false)
 * Method: get_child(interface)
 * index: an index.
 * name: a name.
 * recurse: search recursively.
 * interface: an interface (Ruby class).
 *
 * 1st: Gets the index-th element.
 *
 * 2nd: Gets the element with the given name from the
 * bin, as a reference to a Gst::Element object. If the
 * element is not found and recurse is true, a recursion is
 * performed on the parent bin.
 *
 * 3nd: Looks for the first element inside the bin that implements the
 * given interface. If such an element is found, it returns the element.
 * If you want all elements that implement the interface, use
 * Gst::Bin#get_all_by_interface. The method recurses bins inside bins.
 *
 * Returns: a Gst::Element reference, or nil if the bin does not contain
 * an element with the given name nor implementing the interface.
 */
static VALUE
rb_gst_bin_get(int argc, VALUE *argv, VALUE self)
{
    VALUE index_or_name_or_interface, recurse;
    GstElement *element = NULL;

    rb_scan_args(argc, argv, "11", &index_or_name_or_interface, &recurse);

    if (RVAL2CBOOL(rb_obj_is_kind_of(index_or_name_or_interface, rb_cInteger))) {
        int index;
        GList *node;
        index = NUM2INT(index_or_name_or_interface);
        node = g_list_nth(GST_BIN_CHILDREN(SELF(self)), index);
        if (node)
            element = node->data;
    } else if (RVAL2CBOOL(rb_obj_is_kind_of(index_or_name_or_interface,
                                            rb_cString))) {
        char *name;
        name = RVAL2CSTR(index_or_name_or_interface);

        if (RVAL2CBOOL(recurse)) {
            element = gst_bin_get_by_name_recurse_up(SELF(self), name);
        } else {
            element = gst_bin_get_by_name(SELF(self), name);
        }
    } else {
        GType iface;
        iface = CLASS2GTYPE(index_or_name_or_interface);
        element = gst_bin_get_by_interface(SELF(self), iface);
    }

    return GST_ELEMENT2RVAL(element);
}
Beispiel #2
0
VALUE
_rbgst_collect_elements(GstIterator *iter)
{
    VALUE elements;
    gboolean done = FALSE;

    elements = rb_ary_new();
    while (!done) {
        gpointer element;
        switch (gst_iterator_next(iter, &element)) {
          case GST_ITERATOR_OK:
            rb_ary_push(elements, GST_ELEMENT2RVAL(element));
            gst_object_unref(element);
            break;
          case GST_ITERATOR_RESYNC:
            gst_iterator_resync(iter);
            break;
          case GST_ITERATOR_ERROR:
            done = TRUE;
            break;
          case GST_ITERATOR_DONE:
            done = TRUE;
            break;
        }
    }
    gst_iterator_free(iter);

    return elements;
}
Beispiel #3
0
/*
 * Method: children(interface=nil)
 * interface: an interface (Ruby class).
 *
 * Returns: If interface is nil, an array of all
 * Gst::Element objects in the container. Otherwise, an
 * array of Gst::Element objects in the container that
 * implements the interface.
 */
static VALUE
rb_gst_bin_get_children(int argc, VALUE *argv, VALUE self)
{
    VALUE children, iface;

    rb_scan_args(argc, argv, "01", &iface);

    if (NIL_P(iface)) {
        const GList *node;
        children = rb_ary_new();
        for (node = GST_BIN_CHILDREN(SELF(self));
                node;
                node = g_list_next(node)) {
            rb_ary_push(children, GST_ELEMENT2RVAL(node->data));
        }
    } else {
        GstIterator *iter;
        iter = gst_bin_iterate_all_by_interface(SELF(self),
                                                CLASS2GTYPE(iface));
        children = _rbgst_collect_elements(iter);
    }

    return children;
}
Beispiel #4
0
static VALUE
rb_gst_bin_get_clock_provider(VALUE self)
{
    return GST_ELEMENT2RVAL(SELF(self)->clock_provider);
}