static void get_device_data (ofGstDevice &webcam_device, int desired_framerate) { string pipeline_desc = webcam_device.gstreamer_src + " name=source device=" + webcam_device.video_device + " ! fakesink"; GError * err = NULL; GstElement * pipeline = gst_parse_launch (pipeline_desc.c_str(), &err); if ((pipeline == NULL) || (err != NULL)){ if (err){ ofLog(OF_LOG_ERROR, "ofGstUtils: error getting device data: %s", err->message); g_error_free (err); }else{ ofLog(OF_LOG_ERROR, "ofGstUtils: error getting device data, cannot get pipeline"); } if(pipeline) gst_object_unref (pipeline); return; } // TODO: try to lower seconds, // Start the pipeline and wait for max. 10 seconds for it to start up gst_element_set_state (pipeline, GST_STATE_PLAYING); GstStateChangeReturn ret = gst_element_get_state (pipeline, NULL, NULL, 10 * GST_SECOND); // Check if any error messages were posted on the bus GstBus * bus = gst_element_get_bus (pipeline); GstMessage * msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0); gst_object_unref (bus); if ((msg == NULL) && (ret == GST_STATE_CHANGE_SUCCESS)){ gst_element_set_state (pipeline, GST_STATE_PAUSED); GstElement *src = gst_bin_get_by_name (GST_BIN (pipeline), "source"); char *name; g_object_get (G_OBJECT (src), "device-name", &name, (void*)NULL); ofLog(OF_LOG_VERBOSE, "Device: %s (%s)\n", name==NULL?"":name, webcam_device.video_device.c_str()); GstPad *pad = gst_element_get_pad (src, "src"); GstCaps *caps = gst_pad_get_caps (pad); gst_object_unref (pad); get_supported_video_formats (webcam_device, *caps, desired_framerate); gst_caps_unref (caps); }else if(msg){ gchar *debug; gst_message_parse_error(msg, &err, &debug); ofLog(OF_LOG_ERROR, "ofGstUtils: error getting device data; module %s reported: %s", gst_element_get_name(GST_MESSAGE_SRC (msg)), err->message); g_error_free(err); g_free(debug); } gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); }
static void get_device_data (ofGstDevice &webcam_device) { char *pipeline_desc; GstElement *pipeline; GError *err; GstStateChangeReturn ret; GstMessage *msg; GstBus *bus; { pipeline_desc = g_strdup_printf ("%s name=source device=%s ! fakesink", webcam_device.gstreamer_src, webcam_device.video_device); err = NULL; pipeline = gst_parse_launch (pipeline_desc, &err); if ((pipeline != NULL) && (err == NULL)) { /* Start the pipeline and wait for max. 10 seconds for it to start up */ gst_element_set_state (pipeline, GST_STATE_PLAYING); ret = gst_element_get_state (pipeline, NULL, NULL, 10 * GST_SECOND); /* Check if any error messages were posted on the bus */ bus = gst_element_get_bus (pipeline); msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0); gst_object_unref (bus); if ((msg == NULL) && (ret == GST_STATE_CHANGE_SUCCESS)) { GstElement *src; GstPad *pad; char *name; GstCaps *caps; gst_element_set_state (pipeline, GST_STATE_PAUSED); src = gst_bin_get_by_name (GST_BIN (pipeline), "source"); g_object_get (G_OBJECT (src), "device-name", &name, (void*)NULL); if (name == NULL) name = "Unknown"; // ofLog(OF_LOG_VERBOSE,"Device: %s (%s)\n", name, webcam_device.video_device); pad = gst_element_get_pad (src, "src"); caps = gst_pad_get_caps (pad); gst_object_unref (pad); get_supported_video_formats (webcam_device, *caps); gst_caps_unref (caps); } gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); } if (err) g_error_free (err); g_free (pipeline_desc); } }