/** * 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 gboolean gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps) { GstGLImageSink *glimage_sink; gint width; gint height; gboolean ok; gint fps_n, fps_d; gint par_n, par_d; GstVideoFormat format; GstStructure *structure; gboolean is_gl; GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps); glimage_sink = GST_GLIMAGE_SINK (bsink); structure = gst_caps_get_structure (caps, 0); if (gst_structure_has_name (structure, "video/x-raw-gl")) { is_gl = TRUE; format = GST_VIDEO_FORMAT_UNKNOWN; ok = gst_structure_get_int (structure, "width", &width); ok &= gst_structure_get_int (structure, "height", &height); } else { is_gl = FALSE; ok = gst_video_format_parse_caps (caps, &format, &width, &height); } ok &= gst_video_parse_caps_framerate (caps, &fps_n, &fps_d); ok &= gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d); if (!ok) return FALSE; GST_VIDEO_SINK_WIDTH (glimage_sink) = width; GST_VIDEO_SINK_HEIGHT (glimage_sink) = height; glimage_sink->is_gl = is_gl; glimage_sink->format = format; glimage_sink->width = width; glimage_sink->height = height; glimage_sink->fps_n = fps_n; glimage_sink->fps_d = fps_d; glimage_sink->par_n = par_n; glimage_sink->par_d = par_d; if (!glimage_sink->window_id && !glimage_sink->new_window_id) gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (glimage_sink)); return TRUE; }
static gboolean gst_eglglessink_start (GstEglGlesSink * eglglessink) { GError *error = NULL; GST_DEBUG_OBJECT (eglglessink, "Starting"); if (!eglglessink->egl_started) { GST_ERROR_OBJECT (eglglessink, "EGL uninitialized. Bailing out"); goto HANDLE_ERROR; } /* Ask for a window to render to */ if (!eglglessink->have_window) gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (eglglessink)); if (!eglglessink->have_window && !eglglessink->create_window) { GST_ERROR_OBJECT (eglglessink, "Window handle unavailable and we " "were instructed not to create an internal one. Bailing out."); goto HANDLE_ERROR; } eglglessink->last_flow = GST_FLOW_OK; eglglessink->display_region.w = 0; eglglessink->display_region.h = 0; gst_data_queue_set_flushing (eglglessink->queue, FALSE); #if !GLIB_CHECK_VERSION (2, 31, 0) eglglessink->thread = g_thread_create ((GThreadFunc) render_thread_func, eglglessink, TRUE, &error); #else eglglessink->thread = g_thread_try_new ("eglglessink-render", (GThreadFunc) render_thread_func, eglglessink, &error); #endif if (!eglglessink->thread || error != NULL) goto HANDLE_ERROR; GST_DEBUG_OBJECT (eglglessink, "Started"); return TRUE; HANDLE_ERROR: GST_ERROR_OBJECT (eglglessink, "Couldn't start"); g_clear_error (&error); return FALSE; }
/* Must be called with the SDL lock held */ static gboolean gst_sdlvideosink_initsdl (GstSDLVideoSink * sdlvideosink) { gst_sdlvideosink_deinitsdl (sdlvideosink); if (sdlvideosink->is_xwindows && !sdlvideosink->xwindow_id) { g_mutex_unlock (sdlvideosink->lock); gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (sdlvideosink)); g_mutex_lock (sdlvideosink->lock); } if (!sdlvideosink->xwindow_id) { g_unsetenv ("SDL_WINDOWID"); } else { char SDL_hack[32]; sprintf (SDL_hack, "%lu", sdlvideosink->xwindow_id); g_setenv ("SDL_WINDOWID", SDL_hack, 1); } /* Initialize the SDL library */ if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) goto init_failed; sdlvideosink->init = TRUE; sdlvideosink->running = TRUE; sdlvideosink->event_thread = g_thread_create ((GThreadFunc) gst_sdlvideosink_event_thread, sdlvideosink, TRUE, NULL); return TRUE; /* ERRORS */ init_failed: { GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, INIT, (NULL), ("Couldn't initialize SDL: %s", SDL_GetError ())); return FALSE; } }
/* Must be called with the sdl lock held */ static gboolean gst_sdlvideosink_create (GstSDLVideoSink * sdlvideosink) { if (GST_VIDEO_SINK_HEIGHT (sdlvideosink) <= 0) GST_VIDEO_SINK_HEIGHT (sdlvideosink) = sdlvideosink->height; if (GST_VIDEO_SINK_WIDTH (sdlvideosink) <= 0) GST_VIDEO_SINK_WIDTH (sdlvideosink) = sdlvideosink->width; gst_sdlvideosink_destroy (sdlvideosink); if (sdlvideosink->is_xwindows && !sdlvideosink->xwindow_id) { g_mutex_unlock (sdlvideosink->lock); gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (sdlvideosink)); g_mutex_lock (sdlvideosink->lock); } /* create a SDL window of the size requested by the user */ if (sdlvideosink->full_screen) { sdlvideosink->screen = SDL_SetVideoMode (GST_VIDEO_SINK_WIDTH (sdlvideosink), GST_VIDEO_SINK_HEIGHT (sdlvideosink), 0, SDL_SWSURFACE | SDL_FULLSCREEN); } else { sdlvideosink->screen = SDL_SetVideoMode (GST_VIDEO_SINK_WIDTH (sdlvideosink), GST_VIDEO_SINK_HEIGHT (sdlvideosink), 0, SDL_HWSURFACE | SDL_RESIZABLE); } if (sdlvideosink->screen == NULL) goto no_screen; /* create a new YUV overlay */ sdlvideosink->overlay = SDL_CreateYUVOverlay (sdlvideosink->width, sdlvideosink->height, sdlvideosink->format, sdlvideosink->screen); if (sdlvideosink->overlay == NULL) goto no_overlay; GST_DEBUG ("Using a %dx%d %dbpp SDL screen with a %dx%d \'%" GST_FOURCC_FORMAT "\' YUV overlay", GST_VIDEO_SINK_WIDTH (sdlvideosink), GST_VIDEO_SINK_HEIGHT (sdlvideosink), sdlvideosink->screen->format->BitsPerPixel, sdlvideosink->width, sdlvideosink->height, GST_FOURCC_ARGS (sdlvideosink->format)); sdlvideosink->rect.x = 0; sdlvideosink->rect.y = 0; sdlvideosink->rect.w = GST_VIDEO_SINK_WIDTH (sdlvideosink); sdlvideosink->rect.h = GST_VIDEO_SINK_HEIGHT (sdlvideosink); /*SDL_DisplayYUVOverlay (sdlvideosink->overlay, &(sdlvideosink->rect)); */ GST_DEBUG ("sdlvideosink: setting %08x (%" GST_FOURCC_FORMAT ")", sdlvideosink->format, GST_FOURCC_ARGS (sdlvideosink->format)); return TRUE; /* ERRORS */ no_screen: { GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL), ("SDL: Couldn't set %dx%d: %s", GST_VIDEO_SINK_WIDTH (sdlvideosink), GST_VIDEO_SINK_HEIGHT (sdlvideosink), SDL_GetError ())); return FALSE; } no_overlay: { GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL), ("SDL: Couldn't create SDL YUV overlay (%dx%d \'%" GST_FOURCC_FORMAT "\'): %s", sdlvideosink->width, sdlvideosink->height, GST_FOURCC_ARGS (sdlvideosink->format), SDL_GetError ())); return FALSE; } }
static gboolean gst_vdp_sink_setcaps (GstBaseSink * bsink, GstCaps * caps) { VdpSink *vdp_sink; GstCaps *allowed_caps; gboolean ret = TRUE; GstStructure *structure; GstCaps *intersection; gint new_width, new_height; const GValue *fps; vdp_sink = GST_VDP_SINK (bsink); GST_OBJECT_LOCK (vdp_sink); if (!vdp_sink->device) return FALSE; GST_OBJECT_UNLOCK (vdp_sink); allowed_caps = gst_pad_get_caps (GST_BASE_SINK_PAD (bsink)); GST_DEBUG_OBJECT (vdp_sink, "sinkconnect possible caps %" GST_PTR_FORMAT " with given caps %" GST_PTR_FORMAT, allowed_caps, caps); /* We intersect those caps with our template to make sure they are correct */ intersection = gst_caps_intersect (allowed_caps, caps); gst_caps_unref (allowed_caps); GST_DEBUG_OBJECT (vdp_sink, "intersection returned %" GST_PTR_FORMAT, intersection); if (gst_caps_is_empty (intersection)) { gst_caps_unref (intersection); return FALSE; } gst_caps_unref (intersection); structure = gst_caps_get_structure (caps, 0); ret &= gst_structure_get_int (structure, "width", &new_width); ret &= gst_structure_get_int (structure, "height", &new_height); fps = gst_structure_get_value (structure, "framerate"); ret &= (fps != NULL); if (!ret) return FALSE; GST_VIDEO_SINK_WIDTH (vdp_sink) = new_width; GST_VIDEO_SINK_HEIGHT (vdp_sink) = new_height; vdp_sink->fps_n = gst_value_get_fraction_numerator (fps); vdp_sink->fps_d = gst_value_get_fraction_denominator (fps); gst_vdp_buffer_pool_set_caps (vdp_sink->bpool, caps); /* Notify application to set xwindow id now */ g_mutex_lock (vdp_sink->flow_lock); if (!vdp_sink->window) { g_mutex_unlock (vdp_sink->flow_lock); gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (vdp_sink)); } else { g_mutex_unlock (vdp_sink->flow_lock); } /* Creating our window and our image */ if (GST_VIDEO_SINK_WIDTH (vdp_sink) <= 0 || GST_VIDEO_SINK_HEIGHT (vdp_sink) <= 0) { GST_ELEMENT_ERROR (vdp_sink, CORE, NEGOTIATION, (NULL), ("Invalid image size.")); return FALSE; } g_mutex_lock (vdp_sink->flow_lock); if (!vdp_sink->window) { vdp_sink->window = gst_vdp_sink_window_new (vdp_sink, GST_VIDEO_SINK_WIDTH (vdp_sink), GST_VIDEO_SINK_HEIGHT (vdp_sink)); } g_mutex_unlock (vdp_sink->flow_lock); return TRUE; }
static gboolean gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps) { GstGLImageSink *glimage_sink; gint width; gint height; gboolean ok; gint fps_n, fps_d; gint par_n, par_d; gint display_par_n, display_par_d; guint display_ratio_num, display_ratio_den; GstVideoFormat format; GstStructure *structure; gboolean is_gl; GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps); glimage_sink = GST_GLIMAGE_SINK (bsink); structure = gst_caps_get_structure (caps, 0); if (gst_structure_has_name (structure, "video/x-raw-gl")) { is_gl = TRUE; format = GST_VIDEO_FORMAT_UNKNOWN; ok = gst_structure_get_int (structure, "width", &width); ok &= gst_structure_get_int (structure, "height", &height); } else { is_gl = FALSE; ok = gst_video_format_parse_caps (caps, &format, &width, &height); if (!ok) return FALSE; /* init colorspace conversion if needed */ ok = gst_gl_display_init_upload (glimage_sink->display, format, width, height, width, height); if (!ok) { GST_ELEMENT_ERROR (glimage_sink, RESOURCE, NOT_FOUND, GST_GL_DISPLAY_ERR_MSG (glimage_sink->display), (NULL)); return FALSE; } } gst_gl_display_set_client_reshape_callback (glimage_sink->display, glimage_sink->clientReshapeCallback); gst_gl_display_set_client_draw_callback (glimage_sink->display, glimage_sink->clientDrawCallback); gst_gl_display_set_client_data (glimage_sink->display, glimage_sink->client_data); ok &= gst_video_parse_caps_framerate (caps, &fps_n, &fps_d); ok &= gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d); if (!ok) return FALSE; /* get display's PAR */ if (glimage_sink->par) { display_par_n = gst_value_get_fraction_numerator (glimage_sink->par); display_par_d = gst_value_get_fraction_denominator (glimage_sink->par); } else { display_par_n = 1; display_par_d = 1; } ok = gst_video_calculate_display_ratio (&display_ratio_num, &display_ratio_den, width, height, par_n, par_d, display_par_n, display_par_d); if (!ok) return FALSE; if (height % display_ratio_den == 0) { GST_DEBUG ("keeping video height"); glimage_sink->window_width = (guint) gst_util_uint64_scale_int (height, display_ratio_num, display_ratio_den); glimage_sink->window_height = height; } else if (width % display_ratio_num == 0) { GST_DEBUG ("keeping video width"); glimage_sink->window_width = width; glimage_sink->window_height = (guint) gst_util_uint64_scale_int (width, display_ratio_den, display_ratio_num); } else { GST_DEBUG ("approximating while keeping video height"); glimage_sink->window_width = (guint) gst_util_uint64_scale_int (height, display_ratio_num, display_ratio_den); glimage_sink->window_height = height; } GST_DEBUG ("scaling to %dx%d", glimage_sink->window_width, glimage_sink->window_height); GST_VIDEO_SINK_WIDTH (glimage_sink) = width; GST_VIDEO_SINK_HEIGHT (glimage_sink) = height; glimage_sink->is_gl = is_gl; glimage_sink->width = width; glimage_sink->height = height; glimage_sink->fps_n = fps_n; glimage_sink->fps_d = fps_d; glimage_sink->par_n = par_n; glimage_sink->par_d = par_d; if (!glimage_sink->window_id && !glimage_sink->new_window_id) gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (glimage_sink)); return TRUE; }
static gboolean gst_egl_sink_set_caps (GstBaseSink * bsink, GstCaps * caps) { GstEGLSink *egl_sink; gint width; gint height; gint bufcount; gboolean ok; gint fps_n, fps_d; gint par_n, par_d; gint display_par_n, display_par_d; guint display_ratio_num, display_ratio_den; GstVideoFormat format; GstStructure *s; GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps); egl_sink = GST_EGL_SINK (bsink); if(egl_sink->set_caps_callback) return egl_sink->set_caps_callback(caps, egl_sink->client_data); s = gst_caps_get_structure (caps, 0); if(gst_structure_get_int (s, "num-buffers-required", &bufcount) && bufcount > GST_GL_DISPLAY_MAX_BUFFER_COUNT) { GST_WARNING("num-buffers-required %d exceed max eglsink buffer count %d", bufcount, GST_GL_DISPLAY_MAX_BUFFER_COUNT); return FALSE; } ok = gst_video_format_parse_caps (caps, &format, &width, &height); if (!ok) return FALSE; ok &= gst_video_parse_caps_framerate (caps, &fps_n, &fps_d); ok &= gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d); if (!ok) return FALSE; /* get display's PAR */ if (egl_sink->par) { display_par_n = gst_value_get_fraction_numerator (egl_sink->par); display_par_d = gst_value_get_fraction_denominator (egl_sink->par); } else { display_par_n = 1; display_par_d = 1; } ok = gst_video_calculate_display_ratio (&display_ratio_num, &display_ratio_den, width, height, par_n, par_d, display_par_n, display_par_d); if (!ok) return FALSE; if (height % display_ratio_den == 0) { GST_DEBUG ("keeping video height"); egl_sink->window_width = (guint) gst_util_uint64_scale_int (height, display_ratio_num, display_ratio_den); egl_sink->window_height = height; } else if (width % display_ratio_num == 0) { GST_DEBUG ("keeping video width"); egl_sink->window_width = width; egl_sink->window_height = (guint) gst_util_uint64_scale_int (width, display_ratio_den, display_ratio_num); } else { GST_DEBUG ("approximating while keeping video height"); egl_sink->window_width = (guint) gst_util_uint64_scale_int (height, display_ratio_num, display_ratio_den); egl_sink->window_height = height; } GST_DEBUG ("scaling to %dx%d", egl_sink->window_width, egl_sink->window_height); GST_VIDEO_SINK_WIDTH (egl_sink) = width; GST_VIDEO_SINK_HEIGHT (egl_sink) = height; egl_sink->fps_n = fps_n; egl_sink->fps_d = fps_d; egl_sink->par_n = par_n; egl_sink->par_d = par_d; if (!egl_sink->window_id && !egl_sink->new_window_id) gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (egl_sink)); return TRUE; }