<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Hi Lasse and Matt,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I'm on a very similar path - OpenGL Gst elements sharing a context and textures with Cinder - and I seem to have arrived at a very similar place.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">The hastebin links below are broken, is this code anywhere? Or better yet, did you get a full working integration with Cinder?<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></a></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">- Gordon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext"> gstreamer-devel [mailto:gstreamer-devel-bounces@lists.freedesktop.org]
<b>On Behalf Of </b>Lasse Laursen<br>
<b>Sent:</b> Saturday, January 17, 2015 10:46 AM<br>
<b>To:</b> Discussion of the development of and with GStreamer <gstreamer-devel@lists.freedesktop.org><br>
<b>Subject:</b> Re: OpenGL Texture via GstGLUpload - So close! - Proper Post<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hey,<br>
<br>
Here's an update on the situation:<br>
<br>
1) wglGetCurrentContext() returns a non-NULL object, so that seems ok.<br>
2) The wglMakeCurrent call was an overlooked left over from the sdlshare code. It has been commented out.<br>
3) GST_GL_API_OPENGL3 changed to GST_GL_API_OPENGL<br>
4) glshader replaced by glcolorscale<br>
5) Done!<br>
6) Since I don't unref any of the samples/buffers/frames, I'm fairly confident the lack of a mutex lock, should still let textures/data propagate through the system. So for the sake of simplicity, I've not yet implemented this.<br>
<br>
I've resorted to using gst_caps_new_simple() just to make sure I'm not messing anything up there. For posterity, here are the current versions of videoTester4.<br>
<br>
.H File: <a href="http://hastebin.com/ozemufibit.coffee">http://hastebin.com/ozemufibit.coffee</a><br>
.CPP File: <a href="http://hastebin.com/heyajuwigo.cpp">http://hastebin.com/heyajuwigo.cpp</a><br>
<br>
I may - however - need your help in trying to decode the output that the gstreamer debugger gives me.<br>
<br>
For ease of reading, here is the log file at 4 key events.<br>
<br>
1) Right after gst_parse_launch() returns: <a href="http://hastebin.com/gebunetixa.css">
http://hastebin.com/gebunetixa.css</a><br>
2) Right after changing the state of the pipeline to 5 secs into playback: <a href="http://hastebin.com/buxadozudu.md">
http://hastebin.com/buxadozudu.md</a><br>
3) Right at the end of the first call to newVideoSinkSampleCallback(): <a href="http://hastebin.com/catafodape.md">
http://hastebin.com/catafodape.md</a><br>
4) Right before the texture is about to be inspected by me: <a href="http://hastebin.com/lufacoxoco.md">
http://hastebin.com/lufacoxoco.md</a><br>
<br>
The first thing I looked at is that the Texture ID seems to match fine. As you can see, at the end of the call to newVideoSinkSampleCallback(), a texture with ID 6 is made available (I think?), which is also the texture ID I get from the frame object (and try
 to render with/inspect). Which leaves me to ponder about the context. It seems as though the gstreamer log is saying that it is creating its own context - which I really shouldn't? Or is it perhaps just misleading debug output?<br>
<br>
I'm also a bit curious about the half-sized textures being generated (160x100). I'm also a bit unsure of the Texture Target still. The sdlshare example uses GL_TEXTURE_2D - but even their textures are not sized to the power of 2 - which confuses me a bit to
 be honest.<br>
<br>
I'm keen to hear what you make of the logs?<br>
<br>
Regards,<br>
Lasse<o:p></o:p></p>
<div>
<p class="MsoNormal">On 17-01-2015 13:15, Matthew Waters wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">On 17/01/15 22:47, Lasse Laursen wrote:<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hey again,<br>
<br>
I can almost taste success. I imagine it being sweet, like sugar. Entirely unlike the bitter lemony sourness of 'not quite there' I have in my mouth now. Help me see the error of my ways!<br>
<br>
Inspired by the code Matthew sent my way, I've cobbled together the following object in C++ that is supposed to create a pipeline, share the current OpenGL context with it, grab samples arriving at the appsink and provide the texture ID's to the main thread
 for usage.<br>
<br>
videoTester.h<br>
<a href="http://hastebin.com/sutoyuxoci.coffee">http://hastebin.com/sutoyuxoci.coffee</a><br>
<br>
videoTester.cpp<br>
<a href="http://hastebin.com/gohofababi.cpp">http://hastebin.com/gohofababi.cpp</a><br>
<br>
In the main application, the following happens:<br>
<br>
Cinder sets up all the win32 app stuff, including an OpenGL context.<br>
VideoTester4 is instantiated with paths pointing to a webm video and a passthrough fragment shader (no parameters).<br>
prepPipeline() is called.<br>
launchPipeline() is called.<br>
The generated Texture ID is inspected via imdebug (an awesome texture debugging tool) via this call:<br>
imdebugTexImage( GL_TEXTURE_2D, mVidTester4->getTexId(), GL_RGBA );<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
This looks like a solid approach.<br>
<br>
A couple of things to try/check.<br>
<br>
1. See what the value of gl_context = wglGetCurrentContext() returns.  make sure it is not NULL.  If it is, make sure you're calling that in the main thread (or wherever your gl context is current).<br>
2. if you call wglMakeCurrent (0, 0) make sure you reactivate it after you're done as cinder might assume it controls the gl context and might not reactivate it by itself.<br>
3. The use of GST_GL_API_OPENGL3 might not match cinder's API usage.  Also, the wgl backend does not currently create GL3 contexts yet or contain gl debugging support from the library like the glx backend.<br>
4. In order to remove shader issues, replace glshader by glcolorscale for testing.<br>
5. enable all the gl debugging with GST_DEBUG=gl*:7 and see if the texture handles you get from the callback match up with the textures printed out.  It might also mention some things about the context setup in the beginning that might be useful.<br>
6. the lack of locking on mTextureId :)<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Note that I intentionally do *not* unref any of the associated frame/sample/buffer objects, just to keep things simple. However, all I seem to get when I use imdebug to inspect the textures, are empty 0,0 sized textures that (not surprisingly)
 contain nothing at all. I wondered if GL_TEXTURE_2D might be the wrong texture target and have also tried GL_TEXTURE_RECTANGLE without any luck. Is there any place I can read the texture target from?<br>
<br>
Anyway, the pipeline does not report any errors along the way, and the gstreamer log only contains a few (harmless?) warnings:<br>
<br>
0:00:00.683792474  1836   0CFBEE60 WARN               gldisplay gstgldisplay.c:169:gst_gl_display_new: Could not create display. user specified (NULL) (platform: (NULL)), creating dummy<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
That's normal for win32.<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">0:00:00.686256033  1836   0CFBEE60 WARN                 basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<source> pad not activated yet<br>
0:00:00.686752850  1836   0CFBEE60 WARN                 basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<source> pad not activated yet<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
These may also be normal.<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">The texture ID increases as the program continues execution (which is to be expected), and inspecting the Textures in the actual callback thread with imdebug crashes the program. This has to be due to the fact that the callback function
 executes in a separate thread as Matthew told me last we spoke.<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
My guess based on this and the above is something simple based on the setup of the gl contexts is off.<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-bottom:12.0pt">I've poked a bit around with the various Gst objects without any luck so far. Any ideas/clues as to what I'm missing or how to narrow down what the problem might be?<br>
<br>
Regards,<br>
Lasse<o:p></o:p></p>
<div>
<p class="MsoNormal">On 16-01-2015 22:21, Matthew Waters wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 17/01/15 06:42, Lasse Laursen wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hey Matthew,<br>
<br>
Thanks for the reply and especially the example. I'm working on getting it function with the cinder framework. At first it seemed quite odd to hand over the context as a result of a bus message, but I can see the logic in not needing to create a secondary OpenGL
 context for gstreamer to make textures in, if one already exists. I do have one question though:<br>
<br>
Is it vital to turn off the OpenGL context when sharing it with Gstreamer? I've done a little context sharing before and I don't recall having to actively turn any contexts 'off'.<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
No it is not required to turn off the context.<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-bottom:12.0pt">Regards,<br>
Lasse<o:p></o:p></p>
<div>
<p class="MsoNormal">On 16-01-2015 00:27, Matthew Waters wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-bottom:12.0pt">A couple of points added inline.<o:p></o:p></p>
<div>
<p class="MsoNormal">On 16/01/15 03:14, Lasse Laursen wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hello!<br>
<br>
Apologies for the double post, but my inept handling of Thunderbird caused my last post to be appended to an unrelated thread. Sorry about that Luis dArquer.<br>
<br>
For the sake of posterity, here's is the original question:<br>
<br>
I feel like I am so close to finally getting through to the other side with this problem, so I'm hoping someone can give me a few clues as to what pieces of the puzzle are missing. I used to use gStreamer as a pure 'decoding' library using this simple pipeline:
<br>
<br>
uridecodebin uri=" + mPathToVideoFile +    " ! videoconvert ! appsink name=sink caps="video/x-raw,format=RGB,pixel-aspect-ratio=1/1";
<br>
<br>
With this pipeline, I could quite easily grab the frames arriving at the sink and use them however I pleased. Mostly just throwing them on a texture in OpenGL and displaying them various places. This approach is - of course - quite horrible. I'm not making
 use of gstreamer as a fully-fledged media pipeline. So to rectify that - and because I'd like to run some simple shaders on the video data - I am now using this (almost as) simple pipeline:
<br>
<br>
uridecodebin uri=" + mPathToVideoFile + " ! glshader name=shader location=" + pathToShader + " vars=\"float silver = float( 0.8 ); \" ! appsink name=sink caps=\"video/x-raw,format=RGB,pixel-aspect-ratio=1/1\"";
<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
1. You should set the appsink caps to contain the memory:GstGLMemory caps features. e.g. video/x-raw(memory:GstGLMemory),format=RGBA... see gst-inspect-1.0 glshader for the supported formats and features.  Otherwise, glshader (and any GL element) will download
 the texture upon seeing the system memory caps.<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">I make sure to share my current OpenGL context with the glshader element thusly:
<br>
<br>
mPipeline_ShaderPre = gst_bin_get_by_name( GST_BIN( mGstPipeline ), "shader" ); <br>
HGLRC mainContext = ::wglGetCurrentContext(); <br>
g_object_set( mPipeline_ShaderPre, "other-context", mainContext, NULL ); <o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
2. The "other-context" property expects a GstGLContext rather than a platform specific handle.  You can wrap a context handle using gst_gl_context_new_wrapped().  However, in master there is no "other-context" property anymore so the sharing of GL context happens
 using GstContext.  See for example <a href="http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/tests/examples/gl/sdl/sdlshare.c#n232">
http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/tests/examples/gl/sdl/sdlshare.c#n232</a> and the GstContext documentation.<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Not sure if this is correct to be honest, but I didn't see any errors in gstreamers logs. Anyway - fast forward to my callback function that fires whenever a sample is ready at the sink I proceed to grab a Sample, from which I grab a Buffer,
 from which I grab a Frame, from which I grab a Texture ID, thusly: <br>
<br>
GstSample* gstVideoSinkSample = gst_app_sink_pull_sample( GST_APP_SINK( appsink ) );
<br>
GstBuffer* gstBuffer = gst_sample_get_buffer( gstVideoSinkSample ); <br>
if ( !gst_video_frame_map( &gstFrame, &gstInfo, gstBuffer, static_cast<GstMapFlags>( GST_MAP_READ | ( GST_MAP_FLAG_LAST << 1 ) ) ) )
<br>
    { <br>
        errorToConsole( true, "Failed to map video frame" ); <br>
    } <br>
GLuint textureId = *(guint *) gstFrame.data[0]; <br>
<br>
The result is the number 6. Which I felt was a plausible Texture ID handle. But when I then use a lovely tool named imdebug, and presume that the target for the texture is GL_TEXTURE_2D (which might be wrong), it throws a fit, because it attempts to determine
 the width and height of said texture via these calls: <br>
<br>
glBindTexture(target, texture); <br>
  glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &w); <br>
  glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &h); <br>
<br>
So clearly something is wrong. Some place along this winding road, I've misunderstood something or overlooked something. I'd much appreciate any suggestions/clues!
<br>
<br>
I myself am wondering if a callback at the sink is the right place to grab the texture ID, but I'm not sure how to get at it any earlier, and if that's wise. I am also unsure of how long this texture Id is valid if I want to render it on to a quad. I hope someone
 can shed a bit of light! <o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
It will be valid for as long as it's not overwritten/reused by the producing element which generally means while you keep a ref to the buffer or have the video frame mapped.<br>
<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-bottom:12.0pt">Regards, <br>
Lasse <o:p></o:p></p>
<div>
<p class="MsoNormal">-- <br>
Lasse Farnung Laursen<br>
Researcher at the University of Tokyo<br>
<a href="http://www.lasselaursen.com">www.lasselaursen.com</a><br>
Twitter: <a href="https://twitter.com/PMP_J">@PMP_J</a><o:p></o:p></p>
</div>
</blockquote>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>gstreamer-devel mailing list<o:p></o:p></pre>
<pre><a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><o:p></o:p></pre>
<pre><a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><o:p></o:p></pre>
</blockquote>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">-- <br>
Lasse Farnung Laursen<br>
Researcher at the University of Tokyo<br>
<a href="http://www.lasselaursen.com">www.lasselaursen.com</a><br>
Twitter: <a href="https://twitter.com/PMP_J">@PMP_J</a><o:p></o:p></p>
</div>
</blockquote>
<p class="MsoNormal"><br>
<br>
<br>
<br>
<o:p></o:p></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>gstreamer-devel mailing list<o:p></o:p></pre>
<pre><a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><o:p></o:p></pre>
<pre><a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><o:p></o:p></pre>
</blockquote>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">-- <br>
Lasse Farnung Laursen<br>
Researcher at the University of Tokyo<br>
<a href="http://www.lasselaursen.com">www.lasselaursen.com</a><br>
Twitter: <a href="https://twitter.com/PMP_J">@PMP_J</a><o:p></o:p></p>
</div>
</blockquote>
<p class="MsoNormal"><br>
<br>
<br>
<br>
<o:p></o:p></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>gstreamer-devel mailing list<o:p></o:p></pre>
<pre><a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><o:p></o:p></pre>
<pre><a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><o:p></o:p></pre>
</blockquote>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">-- <br>
Lasse Farnung Laursen<br>
Researcher at the University of Tokyo<br>
<a href="http://www.lasselaursen.com">www.lasselaursen.com</a><br>
Twitter: <a href="https://twitter.com/PMP_J">@PMP_J</a><o:p></o:p></p>
</div>
</div>
</body>
</html>