<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    So, I think you almost have the correct sequence.<br>
    <br>
    Response inline.<br>
    <br>
    <div class="moz-cite-prefix">On 5/8/21 1:04 am, Lusine Hayrapetyan
      via gstreamer-devel wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAO4TkMixB6RCqfWi078mExUx5S4BEObuzDZDV2vVd59Qa_X=GA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Hi Folks,
        <div>I'm struggling with the following issue and can't
          understand what I'm doing wrong.</div>
        <div>I need to pass opengl texture to the gstreamer pipeline.</div>
        <div>I have a rendering thread where I create opengl texture,
          the following objects created in this thread:</div>
        <div><i>EGLDisplay display;</i></div>
        <div><i>EGLContext context;</i><br>
        </div>
        <div><i><br>
          </i></div>
        <div>I create gstreamer pipeline in the main thread and as
          described in the following article sharing an X11 display and
          GstGLContext with the bus callback.</div>
        <div><a
href="http://ystreet00.blogspot.com/2015/09/gstreamer-16-and-opengl-contexts.html"
            moz-do-not-send="true">http://ystreet00.blogspot.com/2015/09/gstreamer-16-and-opengl-contexts.html</a><br>
        </div>
        <div><br>
        </div>
        <div>GstGLDisplayEGL and GstGLContext are created in this way:</div>
        <div><i>GstGLDisplayEGL* gst_display =
            gst_gl_display_egl_new_with_egl_display (display);<br>
          </i></div>
        <div><i>GstGLContext *gl_context =<br>
                  gst_gl_context_new_wrapped (GST_GL_DISPLAY
            (gst_display),<br>
                  (guintptr) context, GST_GL_PLATFORM_EGL,
            GST_GL_API_GLES2);</i><br>
        </div>
        <div><br>
        </div>
        <div>The first element of my pipeline is appsrc:</div>
        <div><i>appsrc stream-type=0 emit-signals=1 format=3 
            caps=video/x-raw(memory:GLMemory),  width=300, height=300,
            framerate=(fraction)20/1, format=(string)RGBA ! gldownload !
            ...</i><br>
        </div>
        <div><br>
        </div>
        <div>I use need-data callback to create a buffer from texture_id
          and and push it in the appsrc:</div>
        <div><i>g_signal_connect (state->appsrc, "need-data",
            G_CALLBACK (</i>
          pushFrame <i>), state);</i></div>
        <div><i><br>
          </i></div>
        <div><i>bool pushFrame()</i><br>
        </div>
        <div><i>{<br>
                 // Wrap the texture into GstGLMemory<br>
                GstVideoInfo vinfo;<br>
                gst_video_info_set_format(&vinfo,
            GST_VIDEO_FORMAT_RGBA, 300, 300);<br>
            <br>
                GstAllocator* allocator =
            GST_ALLOCATOR(gst_gl_memory_allocator_get_default(gl_context));<br>
            <br>
                GstGLVideoAllocationParams* params =
            gst_gl_video_allocation_params_new_wrapped_texture(<br>
                   state->gl_context, NULL, &vinfo, 0, NULL,
            GST_GL_TEXTURE_TARGET_2D, GST_GL_RGBA, </i>
          texture_id  <i>,<br>
                  NULL, 0);<br>
          </i></div>
      </div>
    </blockquote>
    <br>
    The use of state->gl_context is probably your OpenGL context that
    has been wrapped from the application.  This 'wrapped' OpenGL
    context has some limitations, one being that GStreamer cannot
    actually do a complete gst_gl_context_thread_add where the request
    is marshalled to an OpenGL-specific thread.  This is what that
    critical is complaining about effectively.<br>
    <br>
    To do this properly, you would need to do one of two things:<br>
    1. Retrieve the OpenGL context from the downstream gldownload
    element using either the 'context' property or using an appropriate
    GST_CONTEXT QUERY or the helper gst_gl_query_local_gl_context().<br>
    2. Create your own GStreamer OpenGL context and add it to the
    GstGLDisplay using something like: <a moz-do-not-send="true"
href="https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/blob/master/gst-libs/gst/gl/gstglbasefilter.c#L550-565">https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/blob/master/gst-libs/gst/gl/gstglbasefilter.c#L550-565</a>.<br>
    <br>
    Cheers<br>
    -Matt<br>
    <br>
    <blockquote type="cite"
cite="mid:CAO4TkMixB6RCqfWi078mExUx5S4BEObuzDZDV2vVd59Qa_X=GA@mail.gmail.com">
      <div dir="ltr">
        <div><i><br>
                // The following line produces an error!!!<br>
                GstGLMemory* glMemory =
            GST_GL_MEMORY_CAST(gst_gl_base_memory_alloc(<br>
                  GST_GL_BASE_MEMORY_ALLOCATOR_CAST(allocator),
            (GstGLAllocationParams*) params));<br>
            <br>
                gst_gl_allocation_params_free((GstGLAllocationParams
            *)params);<br>
                gst_object_unref(allocator);<br>
            <br>
                // Attach GstGLMemory object into buffer, timestamp the
            buffer and push it downstream<br>
                GstBuffer* buffer = gst_buffer_new();<br>
                gst_buffer_append_memory(buffer,
            GST_MEMORY_CAST(glMemory));<br>
            <br>
                // Put timestamps into buffer<br>
                GST_BUFFER_PTS (buffer) = timestamp;<br>
                GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int
            (1, GST_SECOND, 2);<br>
            <br>
                timestamp += GST_BUFFER_DURATION (buffer);<br>
                GstFlowReturn ret;<br>
                g_signal_emit_by_name(state->appsrc, "push-buffer",
            buffer, &ret);<br>
            <br>
                if (ret != GST_FLOW_OK)<br>
                {<br>
                    // Something wrong, stop pushing.<br>
                    g_printerr("Something went wrong: Pushing buffer
            into appsrc is stopped.\n");<br>
                    return false;<br>
                }<br>
            <br>
                return true;<br>
            }<br>
          </i></div>
        <div><br>
        </div>
        <div>pushFrame produces the following error:</div>
        <div><font color="#ff0000">gst_gl_context_thread_add: assertion
            'context->priv->active_thread == g_thread_self ()'
            failIed<br>
          </font></div>
        <div><font color="#ff0000"><br>
          </font></div>
        <div><font color="#000000">What am I doing wrong or how can push
            gpu texture to gstreamer?</font></div>
        <div><font color="#000000"><br>
          </font></div>
        <div><font color="#000000">Thanks,</font></div>
        <div><font color="#000000">Lusine</font></div>
        <div><font color="#000000"><br>
          </font></div>
      </div>
    </blockquote>
    <br>
  </body>
</html>