void gst_v4l2_xoverlay_start (GstV4l2Object * v4l2object) { if (v4l2object->xwindow_id) { gst_v4l2_xoverlay_open (v4l2object); } }
/** * gst_v4l2_xoverlay_prepare_xwindow_id: * @v4l2object: the v4l2object * @required: %TRUE if display is required (ie. TRUE for v4l2sink, but * FALSE for any other element with optional overlay capabilities) * * Helper function to create a windo if none is set from the application. */ void gst_v4l2_xoverlay_prepare_xwindow_id (GstV4l2Object * v4l2object, gboolean required) { if (!GST_V4L2_IS_OVERLAY (v4l2object)) return; gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (v4l2object->element)); if (required && !v4l2object->xwindow_id) { GstV4l2Xv *v4l2xv; Window win; int width, height; long event_mask; if (!v4l2object->xv && GST_V4L2_IS_OPEN (v4l2object)) gst_v4l2_xoverlay_open (v4l2object); v4l2xv = v4l2object->xv; /* if xoverlay is not supported, just bail */ if (!v4l2xv) return; /* xoverlay is supported, but we don't have a window.. so create one */ GST_DEBUG_OBJECT (v4l2object->element, "creating window"); g_mutex_lock (v4l2xv->mutex); width = XDisplayWidth (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy)); height = XDisplayHeight (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy)); GST_DEBUG_OBJECT (v4l2object->element, "dpy=%p", v4l2xv->dpy); win = XCreateSimpleWindow (v4l2xv->dpy, DefaultRootWindow (v4l2xv->dpy), 0, 0, width, height, 0, 0, XBlackPixel (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy))); GST_DEBUG_OBJECT (v4l2object->element, "win=%lu", win); event_mask = ExposureMask | StructureNotifyMask; if (GST_IS_NAVIGATION (v4l2object->element)) { event_mask |= PointerMotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask; } XSelectInput (v4l2xv->dpy, win, event_mask); v4l2xv->event_id = g_timeout_add (45, event_refresh, v4l2object); XMapRaised (v4l2xv->dpy, win); XSync (v4l2xv->dpy, FALSE); g_mutex_unlock (v4l2xv->mutex); GST_DEBUG_OBJECT (v4l2object->element, "got window"); gst_v4l2_xoverlay_set_window_handle (v4l2object, win); } }
void gst_v4l2_xoverlay_set_xwindow_id (GstV4l2Object * v4l2object, XID xwindow_id) { GstV4l2Xv *v4l2xv; XWindowAttributes attr; gboolean change = (v4l2object->xwindow_id != xwindow_id); GST_LOG_OBJECT (v4l2object->element, "Setting XID to %lx", (gulong) xwindow_id); if (!v4l2object->xv && GST_V4L2_IS_OPEN (v4l2object)) gst_v4l2_xoverlay_open (v4l2object); v4l2xv = v4l2object->xv; if (v4l2xv) g_mutex_lock (v4l2xv->mutex); if (change) { if (v4l2object->xwindow_id && v4l2xv) { GST_DEBUG_OBJECT (v4l2object->element, "Deactivating old port %lx", v4l2object->xwindow_id); XvSelectPortNotify (v4l2xv->dpy, v4l2xv->port, 0); XvSelectVideoNotify (v4l2xv->dpy, v4l2object->xwindow_id, 0); XvStopVideo (v4l2xv->dpy, v4l2xv->port, v4l2object->xwindow_id); } v4l2object->xwindow_id = xwindow_id; } if (!v4l2xv || xwindow_id == 0) { if (v4l2xv) g_mutex_unlock (v4l2xv->mutex); return; } if (change) { GST_DEBUG_OBJECT (v4l2object->element, "Activating new port %lx", xwindow_id); /* draw */ XvSelectPortNotify (v4l2xv->dpy, v4l2xv->port, 1); XvSelectVideoNotify (v4l2xv->dpy, v4l2object->xwindow_id, 1); } XGetWindowAttributes (v4l2xv->dpy, v4l2object->xwindow_id, &attr); XvPutVideo (v4l2xv->dpy, v4l2xv->port, v4l2object->xwindow_id, DefaultGC (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy)), 0, 0, attr.width, attr.height, 0, 0, attr.width, attr.height); if (v4l2xv->idle_id) g_source_remove (v4l2xv->idle_id); v4l2xv->idle_id = g_idle_add (idle_refresh, v4l2object); g_mutex_unlock (v4l2xv->mutex); }
void gst_v4l2_xoverlay_set_window_handle (GstV4l2Object * v4l2object, guintptr id) { GstV4l2Xv *v4l2xv; XID xwindow_id = id; gboolean change = (v4l2object->xwindow_id != xwindow_id); GST_LOG_OBJECT (v4l2object->element, "Setting XID to %lx", (gulong) xwindow_id); if (!v4l2object->xv && GST_V4L2_IS_OPEN (v4l2object)) gst_v4l2_xoverlay_open (v4l2object); v4l2xv = v4l2object->xv; if (v4l2xv) g_mutex_lock (v4l2xv->mutex); if (change) { if (v4l2object->xwindow_id && v4l2xv) { GST_DEBUG_OBJECT (v4l2object->element, "Deactivating old port %lx", v4l2object->xwindow_id); XvSelectPortNotify (v4l2xv->dpy, v4l2xv->port, 0); XvSelectVideoNotify (v4l2xv->dpy, v4l2object->xwindow_id, 0); XvStopVideo (v4l2xv->dpy, v4l2xv->port, v4l2object->xwindow_id); } v4l2object->xwindow_id = xwindow_id; } if (!v4l2xv || xwindow_id == 0) { if (v4l2xv) g_mutex_unlock (v4l2xv->mutex); return; } if (change) { GST_DEBUG_OBJECT (v4l2object->element, "Activating new port %lx", xwindow_id); /* draw */ XvSelectPortNotify (v4l2xv->dpy, v4l2xv->port, 1); XvSelectVideoNotify (v4l2xv->dpy, v4l2object->xwindow_id, 1); } update_geometry (v4l2object); if (v4l2xv->idle_id) g_source_remove (v4l2xv->idle_id); v4l2xv->idle_id = g_idle_add (idle_refresh, v4l2object); g_mutex_unlock (v4l2xv->mutex); }
/** * gst_v4l2_xoverlay_prepare_xwindow_id: * @v4l2object: the v4l2object * @required: %TRUE if display is required (ie. TRUE for v4l2sink, but * FALSE for any other element with optional overlay capabilities) * * Helper function to create a windo if none is set from the application. */ void gst_v4l2_xoverlay_prepare_xwindow_id (GstV4l2Object * v4l2object, gboolean required) { if (!GST_V4L2_IS_OVERLAY (v4l2object)) return; gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (v4l2object->element)); if (required && !v4l2object->xwindow_id) { GstV4l2Xv *v4l2xv; Window win; int width, height; if (!v4l2object->xv && GST_V4L2_IS_OPEN (v4l2object)) gst_v4l2_xoverlay_open (v4l2object); v4l2xv = v4l2object->xv; /* if xoverlay is not supported, just bail */ if (!v4l2xv) return; /* xoverlay is supported, but we don't have a window.. so create one */ GST_DEBUG_OBJECT (v4l2object->element, "creating window"); g_mutex_lock (v4l2xv->mutex); width = XDisplayWidth (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy)); height = XDisplayHeight (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy)); GST_DEBUG_OBJECT (v4l2object->element, "dpy=%p", v4l2xv->dpy); win = XCreateSimpleWindow (v4l2xv->dpy, DefaultRootWindow (v4l2xv->dpy), 0, 0, width, height, 0, 0, XBlackPixel (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy))); GST_DEBUG_OBJECT (v4l2object->element, "win=%lu", win); XMapRaised (v4l2xv->dpy, win); XSync (v4l2xv->dpy, FALSE); v4l2xv->internal_window = TRUE; g_mutex_unlock (v4l2xv->mutex); GST_DEBUG_OBJECT (v4l2object->element, "got window"); gst_v4l2_xoverlay_set_window_handle (v4l2object, win); } }
void gst_v4l2_xoverlay_set_window_handle (GstV4l2Object * v4l2object, guintptr id) { GstV4l2Xv *v4l2xv; XID xwindow_id = id; gboolean change = (v4l2object->xwindow_id != xwindow_id); GST_LOG_OBJECT (v4l2object->element, "Setting XID to %lx", (gulong) xwindow_id); if (!v4l2object->xv && GST_V4L2_IS_OPEN (v4l2object)) gst_v4l2_xoverlay_open (v4l2object); v4l2xv = v4l2object->xv; if (v4l2xv) g_mutex_lock (v4l2xv->mutex); if (change) { if (v4l2object->xwindow_id && v4l2xv) { GST_DEBUG_OBJECT (v4l2object->element, "Deactivating old port %lx", v4l2object->xwindow_id); XvSelectPortNotify (v4l2xv->dpy, v4l2xv->port, 0); XvSelectVideoNotify (v4l2xv->dpy, v4l2object->xwindow_id, 0); XvStopVideo (v4l2xv->dpy, v4l2xv->port, v4l2object->xwindow_id); } v4l2object->xwindow_id = xwindow_id; if (v4l2object->xwindow_id && v4l2xv) { long event_mask; GST_DEBUG_OBJECT (v4l2object->element, "Setting up event mask"); event_mask = ExposureMask | StructureNotifyMask; if (GST_IS_NAVIGATION (v4l2object->element)) { event_mask |= PointerMotionMask | KeyPressMask | KeyReleaseMask; if (v4l2xv->internal_window) event_mask |= ButtonPressMask | ButtonReleaseMask; } XSelectInput (v4l2xv->dpy, v4l2object->xwindow_id, event_mask); if (v4l2xv->event_id) g_source_remove (v4l2xv->event_id); v4l2xv->event_id = g_timeout_add (45, event_refresh, v4l2object); } } if (!v4l2xv || xwindow_id == 0) { if (v4l2xv) g_mutex_unlock (v4l2xv->mutex); return; } if (change) { GST_DEBUG_OBJECT (v4l2object->element, "Activating new port %lx", xwindow_id); /* draw */ XvSelectPortNotify (v4l2xv->dpy, v4l2xv->port, 1); XvSelectVideoNotify (v4l2xv->dpy, v4l2object->xwindow_id, 1); } update_geometry (v4l2object); if (v4l2xv->idle_id) g_source_remove (v4l2xv->idle_id); v4l2xv->idle_id = g_idle_add (idle_refresh, v4l2object); g_mutex_unlock (v4l2xv->mutex); }