copenglgstreamer-1.0

OpenGL functions cause Segmentation Fault when using with GStreamer


I tried to create GStreamer Element that will produce triangle (for example) on screen. But I encountered SegFault problem... I tried to troubleshoot what is cousing it, and find out every OpenGL function does. In the code bellow I present my _chain() function:

static GstFlowReturn
gst_markersrc_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
{
  Gstmarkersrc *filter;

  filter = GST_MARKERSRC (parent);

  if (filter->silent == FALSE)
  {
    GstGLContext* context;
    GstGLFuncs *gl = context->gl_vtable;
    gl->ClearColor(1.0f,0.0f,0.0f,1.0f); // <- SegFault
  }
  
  /* just push out the incoming buffer without touching it */
  return gst_pad_push (filter->srcpad, buf);
}

As you can see It just pushes buffer received from sinkpad to srcpad, but when I try to add any OpenGL function it breaks here (Here it is on line with ClearColor).


Solution

  • I solved it for now by including GLFW for context handling. I now have something like this:

    glfwInit();
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    window = glfwCreateWindow(320, 240, "", NULL, NULL);
    glfwMakeContextCurrent(window);
    context = gst_gl_context_new_wrapped (gst_gl_display_new (), (guintptr) glfwGetProcAddress("glXGetCurrentContex"), GST_GL_PLATFORM_GLX, GST_GL_API_OPENGL);
    glClearColor(0.5f ,1.0f , 0.2f, 0.1f);
    

    And also need to call glfwMakeContextCurrent(window); in _chain() function.

    I would like to get an idea for better solution, so I will not mark this question as answered for now.