bool MediaPlayerPrivateGStreamerBase::ensureGstGLContext() { if (m_glContext) return true; if (!m_glDisplay) { const auto& sharedDisplay = PlatformDisplay::sharedDisplay(); #if PLATFORM(X11) m_glDisplay = GST_GL_DISPLAY(gst_gl_display_x11_new_with_display(downcast<PlatformDisplayX11>(sharedDisplay).native())); #elif PLATFORM(WAYLAND) m_glDisplay = GST_GL_DISPLAY(gst_gl_display_egl_new_with_egl_display(downcast<PlatformDisplayWayland>(sharedDisplay).native())); #endif } GLContext* webkitContext = GLContext::sharingContext(); // EGL and GLX are mutually exclusive, no need for ifdefs here. GstGLPlatform glPlatform = webkitContext->isEGLContext() ? GST_GL_PLATFORM_EGL : GST_GL_PLATFORM_GLX; #if USE(OPENGL_ES_2) GstGLAPI glAPI = GST_GL_API_GLES2; #elif USE(OPENGL) GstGLAPI glAPI = GST_GL_API_OPENGL; #else ASSERT_NOT_REACHED(); #endif PlatformGraphicsContext3D contextHandle = webkitContext->platformContext(); if (!contextHandle) return false; m_glContext = gst_gl_context_new_wrapped(m_glDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI); return true; }
static void open_ogl (void) { TRACE_VC_MEMORY ("state 0"); #if defined (USE_OMX_TARGET_RPI) bcm_host_init (); TRACE_VC_MEMORY ("after bcm_host_init"); #endif /* Create surface and gl context */ init_ogl (state); TRACE_VC_MEMORY ("after init_ogl"); /* Wrap the EGLDisplay to GstGLDisplayEGL */ state->gst_display = gst_gl_display_egl_new_with_egl_display (state->display); }
bool ofGstVideoUtils::setPipeline(string pipeline, ofPixelFormat pixelFormat, bool isStream, int w, int h){ internalPixelFormat = pixelFormat; #ifndef OF_USE_GST_GL string caps; #if GST_VERSION_MAJOR==0 switch(pixelFormat){ case OF_PIXELS_MONO: caps="video/x-raw-gray, depth=8, bpp=8"; break; case OF_PIXELS_RGBA: caps="video/x-raw-rgb, depth=24, bpp=32, endianness=4321, red_mask=0xff0000, green_mask=0x00ff00, blue_mask=0x0000ff, alpha_mask=0x000000ff"; break; case OF_PIXELS_BGRA: caps="video/x-raw-rgb, depth=24, bpp=32, endianness=4321, red_mask=0x0000ff, green_mask=0x00ff00, blue_mask=0xff0000, alpha_mask=0x000000ff"; break; case OF_PIXELS_RGB: default: caps="video/x-raw-rgb, depth=24, bpp=24, endianness=4321, red_mask=0xff0000, green_mask=0x00ff00, blue_mask=0x0000ff, alpha_mask=0x000000ff"; break; } #else if(pixelFormat!=OF_PIXELS_NATIVE){ caps="video/x-raw, format="+getGstFormatName(pixelFormat); }else{ caps = "video/x-raw,format={RGBA,BGRA,RGB,BGR,RGB16,GRAY8,YV12,I420,NV12,NV21,YUY2}"; } #endif if(w!=-1 && h!=-1){ caps+=", width=" + ofToString(w) + ", height=" + ofToString(h); } string pipeline_string = pipeline + " ! appsink name=ofappsink enable-last-sample=0 caps=\"" + caps + "\""; if((w==-1 || h==-1) || pixelFormat==OF_PIXELS_NATIVE || allocate(w,h,pixelFormat)){ return setPipelineWithSink(pipeline_string,"ofappsink",isStream); }else{ return false; } #else string pipeline_string = pipeline + " ! glcolorscale name=gl_filter ! appsink name=ofappsink enable-last-sample=0 caps=\"video/x-raw,format=RGBA\""; bool ret; if((w==-1 || h==-1) || pixelFormat==OF_PIXELS_NATIVE || allocate(w,h,pixelFormat)){ ret = setPipelineWithSink(pipeline_string,"ofappsink",isStream); }else{ ret = false; } auto glfilter = gst_bin_get_by_name(GST_BIN(getPipeline()),"gl_filter"); #if defined(TARGET_LINUX) && !defined(TARGET_OPENGLES) glXMakeCurrent (ofGetX11Display(), None, 0); glDisplay = (GstGLDisplay *)gst_gl_display_x11_new_with_display(ofGetX11Display()); glContext = gst_gl_context_new_wrapped (glDisplay, (guintptr) ofGetGLXContext(), GST_GL_PLATFORM_GLX, GST_GL_API_OPENGL); g_object_set (G_OBJECT (glfilter), "other-context", glContext, NULL); // FIXME: this seems to be the way to add the context in 1.4.5 // // GstBus * bus = gst_pipeline_get_bus (GST_PIPELINE(gstPipeline)); // gst_bus_enable_sync_message_emission (bus); // g_signal_connect (bus, "sync-message", G_CALLBACK (sync_bus_call), this); // gst_object_unref(bus); glXMakeCurrent (ofGetX11Display(), ofGetX11Window(), ofGetGLXContext()); #elif defined(TARGET_OPENGLES) cout << "current display " << ofGetEGLDisplay() << endl; eglMakeCurrent (eglGetDisplay(EGL_DEFAULT_DISPLAY), 0,0, 0); glDisplay = (GstGLDisplay *)gst_gl_display_egl_new_with_egl_display(eglGetDisplay(EGL_DEFAULT_DISPLAY)); glContext = gst_gl_context_new_wrapped (glDisplay, (guintptr) ofGetEGLContext(), GST_GL_PLATFORM_GLX, GST_GL_API_OPENGL); g_object_set (G_OBJECT (glfilter), "other-context", glContext, NULL); // FIXME: this seems to be the way to add the context in 1.4.5 // // GstBus * bus = gst_pipeline_get_bus (GST_PIPELINE(gstPipeline)); // gst_bus_enable_sync_message_emission (bus); // g_signal_connect (bus, "sync-message", G_CALLBACK (sync_bus_call), this); // gst_object_unref(bus); eglMakeCurrent (ofGetEGLDisplay(), ofGetEGLSurface(), ofGetEGLSurface(), ofGetEGLContext()); #endif return ret; #endif }