/** * 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); } }
/** * 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); } }
static void gst_v4l2_xoverlay_close (GstV4l2Object * v4l2object) { GstV4l2Xv *v4l2xv = v4l2object->xv; if (!v4l2object->xv) return; if (v4l2object->xwindow_id) { gst_v4l2_xoverlay_set_window_handle (v4l2object, 0); } XCloseDisplay (v4l2xv->dpy); g_mutex_free (v4l2xv->mutex); if (v4l2xv->idle_id) g_source_remove (v4l2xv->idle_id); if (v4l2xv->event_id) g_source_remove (v4l2xv->event_id); g_free (v4l2xv); v4l2object->xv = NULL; }
static void gst_v4l2_xoverlay_open (GstV4l2Object * v4l2object) { struct stat s; GstV4l2Xv *v4l2xv; const gchar *name = g_getenv ("DISPLAY"); unsigned int ver, rel, req, ev, err, anum; int i, id = 0, first_id = 0, min; XvAdaptorInfo *ai; Display *dpy; /* we need a display, obviously */ if (!name || !(dpy = XOpenDisplay (name))) { GST_WARNING_OBJECT (v4l2object->element, "No $DISPLAY set or failed to open - no overlay"); return; } /* First let's check that XVideo extension is available */ if (!XQueryExtension (dpy, "XVideo", &i, &i, &i)) { GST_WARNING_OBJECT (v4l2object->element, "Xv extension not available - no overlay"); XCloseDisplay (dpy); return; } /* find port that belongs to this device */ if (XvQueryExtension (dpy, &ver, &rel, &req, &ev, &err) != Success) { GST_WARNING_OBJECT (v4l2object->element, "Xv extension not supported - no overlay"); XCloseDisplay (dpy); return; } if (XvQueryAdaptors (dpy, DefaultRootWindow (dpy), &anum, &ai) != Success) { GST_WARNING_OBJECT (v4l2object->element, "Failed to query Xv adaptors"); XCloseDisplay (dpy); return; } if (fstat (v4l2object->video_fd, &s) < 0) { GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND, (_("Cannot identify device '%s'."), v4l2object->videodev), GST_ERROR_SYSTEM); XCloseDisplay (dpy); return; } min = s.st_rdev & 0xff; for (i = 0; i < anum; i++) { GST_DEBUG_OBJECT (v4l2object->element, "found adapter: %s", ai[i].name); if (!strcmp (ai[i].name, "video4linux2") || !strcmp (ai[i].name, "video4linux")) { if (first_id == 0) first_id = ai[i].base_id; GST_DEBUG_OBJECT (v4l2object->element, "first_id=%d, base_id=%lu, min=%d", first_id, ai[i].base_id, min); /* hmm... */ if (first_id != 0 && ai[i].base_id == first_id + min) id = ai[i].base_id; } } XvFreeAdaptorInfo (ai); if (id == 0) { GST_WARNING_OBJECT (v4l2object->element, "Did not find XvPortID for device - no overlay"); XCloseDisplay (dpy); return; } v4l2xv = g_new0 (GstV4l2Xv, 1); v4l2xv->dpy = dpy; v4l2xv->port = id; v4l2xv->mutex = g_mutex_new (); v4l2xv->idle_id = 0; v4l2xv->event_id = 0; v4l2object->xv = v4l2xv; if (v4l2object->xwindow_id) { gst_v4l2_xoverlay_set_window_handle (v4l2object, v4l2object->xwindow_id); } }