Experiments with VLC based video player, help needed

#1

hi friends,
latest version of libvlc is implementing a nice feature, it allows the transfer of textures with decoded frame pictures via GL context sharing (instead of pixels array that had to be copied via the cpu in previous versions of the library). This of course leads to a much faster playback. The feature is still only in the development branch of libvlc, but this is not a reason to avoid experimenting with it :slight_smile: My idea is to write a simple addon to implement a video (and audio) player with libvlc, at the moment for Linux but it should not be too difficult to extend it to other platforms too.

At the moment I managed to install the library and successfully compile a simple example they provide (based on SDL2). The skeleton of an OF compatible class is there too, but I need some help with openGL stuff I am not familiar with.

The example code from videolan repository can be found here. The parts that I couldn’t yet port to openFrameworks are these:

In initialization (class constructor)

//VLC opengl context needs to be shared with SDL context
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
m_ctx = SDL_GL_CreateContext(window);

I found some hints about sharing GL context among different OF windows but this is a different case, it looks like the app should share context with whatever is the current one at any given time.

Then a couple of callbacks

    // This callback is called to set the OpenGL context
    static bool make_current(void* data, bool current)
    {
        VLCVideo* that = static_cast<VLCVideo*>(data);
        if (current)
            return SDL_GL_MakeCurrent(that->m_win, that->m_ctx) == 0;
        else
            return SDL_GL_MakeCurrent(that->m_win, 0) == 0;
    }

What would be the OF equivalent for the “MakeCurrent” calls? There is a “glXMakeCurrent” that looks like a good candidate, but it is not clear to me what its parameters should be in an OF app.

    // This callback is called by VLC to get OpenGL functions.
    static void* get_proc_address(void* /*data*/, const char* current)
    {
        return SDL_GL_GetProcAddress(current);
    }

As a replacement for the SDL_GL_getProcAddress call I put glXGetProcAddress((const GLubyte*)current) adding a #include <GL/glx.h> at the top, but I couldn’t test if it works.

So at the moment I could really use some help! That would be a good opportunity for me to learn something new and besides that a fast vlc based player may be useful to others as well.

thanks for helping
Davide