static void empathy_video_src_init (EmpathyGstVideoSrc *obj) { EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (obj); GstElement *scale, *colorspace, *capsfilter; GstPad *ghost, *src; GstCaps *caps; /* allocate any data required by the object here */ scale = gst_element_factory_make ("videoscale", NULL); colorspace = gst_element_factory_make ("ffmpegcolorspace", NULL); capsfilter = gst_element_factory_make ("capsfilter", NULL); caps = gst_caps_new_simple ("video/x-raw-yuv", "width", G_TYPE_INT, 320, "height", G_TYPE_INT, 240, NULL); g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL); priv->src = gst_element_factory_make ("gconfvideosrc", NULL); gst_bin_add_many (GST_BIN (obj), priv->src, scale, colorspace, capsfilter, NULL); gst_element_link_many (priv->src, scale, colorspace, capsfilter, NULL); src = gst_element_get_static_pad (capsfilter, "src"); ghost = gst_ghost_pad_new ("src", src); gst_element_add_pad (GST_ELEMENT (obj), ghost); gst_object_unref (G_OBJECT (src)); }
gchar * empathy_video_src_dup_device (EmpathyGstVideoSrc *self) { EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (self); gchar *device; g_object_get (priv->src, "device", &device, NULL); return device; }
void empathy_video_src_set_framerate (GstElement *src, guint framerate) { EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (src); if (priv->videorate) { g_object_set (G_OBJECT (priv->videorate), "max-rate", framerate, NULL); } }
void empathy_video_src_change_device (EmpathyGstVideoSrc *self, const gchar *device) { EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (self); GstState state; gst_element_get_state (priv->src, &state, NULL, 0); g_return_if_fail (state == GST_STATE_NULL); g_object_set (priv->src, "device", device, NULL); }
void empathy_video_src_dispose (GObject *object) { EmpathyGstVideoSrc *self = EMPATHY_GST_VIDEO_SRC (object); EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (self); if (priv->dispose_has_run) return; priv->dispose_has_run = TRUE; /* release any references held by the object here */ if (G_OBJECT_CLASS (empathy_video_src_parent_class)->dispose) G_OBJECT_CLASS (empathy_video_src_parent_class)->dispose (object); }
void empathy_video_src_set_resolution (GstElement *src, guint width, guint height) { EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (src); GstCaps *caps; GstPad *srcpad, *peer; g_return_if_fail (priv->capsfilter != NULL); gst_element_set_locked_state (priv->src, TRUE); gst_element_set_state (priv->src, GST_STATE_NULL); srcpad = gst_element_get_static_pad (priv->src, "src"); peer = gst_pad_get_peer (srcpad); /* Keep a ref as removing it from the bin will loose our reference */ gst_object_ref (priv->src); gst_bin_remove (GST_BIN (src), priv->src); g_object_get (priv->capsfilter, "caps", &caps, NULL); caps = gst_caps_make_writable (caps); gst_caps_set_simple (caps, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL); g_object_set (priv->capsfilter, "caps", caps, NULL); gst_caps_unref (caps); gst_bin_add (GST_BIN (src), priv->src); /* We as the bin own the source again, so drop the temporary ref */ gst_object_unref (priv->src); gst_pad_link (srcpad, peer); gst_element_set_locked_state (priv->src, FALSE); gst_element_sync_state_with_parent (priv->src); gst_object_unref (srcpad); gst_object_unref (peer); }
static void empathy_video_src_init (EmpathyGstVideoSrc *obj) { EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (obj); GstElement *element, *element_back; GstPad *ghost, *src; GstCaps *caps; gchar *str; /* allocate caps here, so we can update it by optional elements */ caps = gst_caps_new_simple ("video/x-raw", "width", G_TYPE_INT, 320, "height", G_TYPE_INT, 240, NULL); /* allocate any data required by the object here */ if ((element = empathy_gst_add_to_bin (GST_BIN (obj), NULL, "v4l2src")) == NULL) g_error ("Couldn't add \"v4l2src\" (gst-plugins-good missing?)"); /* we need to save our source to priv->src */ priv->src = element; /* Drop EOS events, so that our sinks don't get confused when we restart the * source (triggering an EOS) */ src = gst_element_get_static_pad (element, "src"); gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, empathy_video_src_drop_eos, NULL, NULL); gst_object_unref (src); /* videorate with the required properties optional as it needs a currently * unreleased gst-plugins-base 0.10.36 */ element_back = element; element = empathy_gst_add_to_bin (GST_BIN (obj), element, "videorate"); if (element != NULL && g_object_class_find_property ( G_OBJECT_GET_CLASS (element), "max-rate") != NULL) { priv->videorate = element; g_object_set (G_OBJECT (element), "drop-only", TRUE, "average-period", GST_SECOND/2, NULL); } else { g_message ("videorate missing or doesn't have max-rate property, not" "doing dynamic framerate changes (Needs gst-plugins-base >= 0.10.36)"); /* Refcount owned by the bin */ gst_bin_remove (GST_BIN (obj), element); element = element_back; } gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION_RANGE, 1, 1, 30, 1, NULL); str = gst_caps_to_string (caps); DEBUG ("Current video src caps are : %s", str); g_free (str); if ((element = empathy_gst_add_to_bin (GST_BIN (obj), element, "videoconvert")) == NULL) g_error ("Failed to add \"videoconvert\" (gst-plugins-base missing?)"); if ((element = empathy_gst_add_to_bin (GST_BIN (obj), element, "videoscale")) == NULL) g_error ("Failed to add \"videoscale\", (gst-plugins-base missing?)"); if ((element = empathy_gst_add_to_bin (GST_BIN (obj), element, "capsfilter")) == NULL) g_error ( "Failed to add \"capsfilter\" (gstreamer core elements missing?)"); priv->capsfilter = element; g_object_set (G_OBJECT (element), "caps", caps, NULL); /* optionally add postproc_tmpnoise to improve the performance of encoders */ element_back = element; if ((element = empathy_gst_add_to_bin (GST_BIN (obj), element, "postproc_tmpnoise")) == NULL) { g_message ("Failed to add \"postproc_tmpnoise\" (gst-ffmpeg missing?)"); element = element_back; } src = gst_element_get_static_pad (element, "src"); g_assert (src != NULL); ghost = gst_ghost_pad_new ("src", src); if (ghost == NULL) g_error ("Unable to create ghost pad for the videosrc"); if (!gst_element_add_pad (GST_ELEMENT (obj), ghost)) g_error ("pad with the same name already existed or " "the pad already had another parent."); gst_object_unref (G_OBJECT (src)); }