/* * 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); }
ElementPtr Bin::getElementByName(const char *name, RecursionType r) const { GstElement *e = NULL; switch(r) { case RecurseDown: e = gst_bin_get_by_name(object<GstBin>(), name); break; case RecurseUp: e = gst_bin_get_by_name_recurse_up(object<GstBin>(), name); break; default: Q_ASSERT_X(false, "QGst::Bin::getElementByName", "Invalid RecursionType"); } return ElementPtr::wrap(e, false); }
static int act_gstreamer_render (VisPluginData *plugin, VisVideo *video, VisAudio *audio) { GstreamerPrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin)); static int playing = 0; if (playing == 0) { char pipe[1024]; gst_init (NULL, NULL); /* snprintf(pipe, 1024, "filesrc location=%s ! decodebin ! ffmpegcolorspace ! " "videoscale ! video/x-raw-rgb,bpp=32,depth=32,width=%d,height=%d," "red_mask=0xff000000,green_mask=0x00ff0000,blue_mask=0x0000ff00 !" "fakesink name=sink sync=true", "test.mpg", video->width, video->height); */ snprintf(pipe, 1024, "filesrc location=%s ! decodebin ! ffmpegcolorspace ! " "video/x-raw-rgb,bpp=24,depth=24 ! " "fakesink name=sink signal-handoffs=true", "test.mpg"); GError *err = NULL; priv->pipe = GST_PIPELINE_CAST(gst_parse_launch (pipe, &err)); if (err) { visual_log (VISUAL_LOG_ERROR, "Failed to create pipeline", err->message); return; } gst_element_set_state (GST_ELEMENT (priv->pipe), GST_STATE_PLAYING); g_signal_connect (gst_bin_get_by_name_recurse_up (GST_BIN (priv->pipe), "sink"), "handoff", G_CALLBACK (have_data), video); playing = 1; } // g_signal_handlers_disconnect_by_func (gst_bin_get_by_name_recurse_up (GST_BIN (priv->pipe), "sink"), // G_CALLBACK (have_data), priv->old_video); gst_bin_iterate (GST_BIN (priv->pipe)); priv->old_video = video; return 0; }
/* called when a new media pipeline is constructed. We can query the * pipeline and configure our appsrc */ void ReStream::media_configure_feature (GstRTSPMediaFactory * factory, GstRTSPMedia * media, gpointer user_data) { try{ GstElement *element, *appsrc; struct MyContext *ctx = (struct MyContext *)user_data; element = gst_rtsp_media_get_element (media); appsrc = gst_bin_get_by_name_recurse_up (GST_BIN (element), "mysrc"); gst_util_set_object_arg (G_OBJECT (appsrc), "format", "time"); g_object_set (G_OBJECT (appsrc), "caps", gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, "BGR", "width", G_TYPE_INT, ctx->width, "height", G_TYPE_INT,ctx->height, "framerate", GST_TYPE_FRACTION, FPS, 1, NULL),NULL ); //ctx->white = FALSE; ctx->timestamp = 0; ctx->buffer = gst_buffer_new_allocate (NULL, ctx->height * ctx->width*3 , NULL); gst_buffer_map (ctx->buffer, &ctx->map, GST_MAP_WRITE); /* make sure ther datais freed when the media is gone */ //g_object_set_data_full (G_OBJECT (media), "my-extra-data", ctx, (GDestroyNotify) g_free); g_signal_connect (appsrc, "need-data", (GCallback)need_data_feature, ctx); g_signal_connect (media, "unprepared", (GCallback)unprepared_feature, ctx); if ( ISDEBUG ) cout<<"media prepared_feature\n"; gst_object_unref (appsrc); gst_object_unref (element); } catch(Exception &e){ CommonClass localcommclass; localcommclass.PrintException("ReStream","CV::media_configure_feature",e); } catch(exception &e){ CommonClass localcommclass; localcommclass.PrintException("ReStream","STD::media_configure_feature",e); } }
/* called when a new media pipeline is constructed. We can query the * pipeline and configure our appsrc */ static void media_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media, gpointer user_data) { GstElement *element, *appsrc; MyContext *ctx; /* get the element used for providing the streams of the media */ element = gst_rtsp_media_get_element (media); //gst_element_set_base_time(GST_ELEMENT(element), 0); /* get our appsrc, we named it 'mysrc' with the name property */ appsrc = gst_bin_get_by_name_recurse_up (GST_BIN (element), "mysrc"); /* this instructs appsrc that we will be dealing with timed buffer */ gst_util_set_object_arg (G_OBJECT (appsrc), "format", "time"); /* configure the caps of the video */ g_object_set (G_OBJECT (appsrc), "caps", gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, "RGB16", "width", G_TYPE_INT, 384, "height", G_TYPE_INT, 288, "framerate", GST_TYPE_FRACTION, 0, 1, NULL), NULL); ctx = g_new0 (MyContext, 1); ctx->white = FALSE; ctx->timestamp = 0; /* make sure ther datais freed when the media is gone */ g_object_set_data_full (G_OBJECT (media), "my-extra-data", ctx, (GDestroyNotify) g_free); /* install the callback that will be called when a buffer is needed */ g_signal_connect (appsrc, "need-data", (GCallback) need_data, ctx); gst_object_unref (appsrc); gst_object_unref (element); }