Ticket #2383: mythtv-0.20-vsync.patch

File mythtv-0.20-vsync.patch, 4.6 KB (added by cardoe@…, 18 years ago)

The patch here did not compile for me. Here's a refactored version that doesn't use templates

  • libs/libmythtv/vsync.cpp

     
    3535#include "util-x11.h"    // for OpenGL VSync
    3636
    3737#ifdef USING_OPENGL_VSYNC
    38 #define GLX_GLXEXT_PROTOTYPES
    3938#define XMD_H 1
     39#define GLX_GLXEXT_PROTOTYPES
    4040#include <GL/glx.h>
    4141#include <GL/gl.h>
    4242#undef GLX_ARB_get_proc_address
     
    437437    UpdateNexttrigger();
    438438}
    439439
     440#ifdef USING_OPENGL_VSYNC
     441class OpenGLVideoSyncPrivate
     442{
     443  public:
     444    OpenGLVideoSyncPrivate()
     445    {
     446        m_glXGetVideoSyncSGI = (PFNGLXGETVIDEOSYNCSGIPROC) glXGetProcAddress("glXGetVideoSyncSGI");
     447        m_glXWaitVideoSyncSGI = (PFNGLXWAITVIDEOSYNCSGIPROC) glXGetProcAddress("glXWaitVideoSyncSGI");
     448    }
     449
     450    bool funcsLoaded()
     451    {
     452        return m_glXGetVideoSyncSGI && m_glXWaitVideoSyncSGI;
     453    }
     454
     455  public:
     456    int glXGetVideoSyncSGI(unsigned int *count)
     457    {
     458        return m_glXGetVideoSyncSGI(count);
     459    }
     460
     461    int glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
     462    {
     463        return m_glXWaitVideoSyncSGI(divisor, remainder, count);
     464    }
     465
     466    __GLXextFuncPtr glXGetProcAddress(const char * const procName)
     467    {
     468        __GLXextFuncPtr ret = glXGetProcAddressARB((const GLubyte *) procName);
     469        if (!ret)
     470        {
     471            VERBOSE(VB_PLAYBACK,
     472                    QString("Error: glXGetProcAddressARB unable to find %1")
     473                    .arg(procName));
     474        }
     475        return ret;
     476    }
     477
     478  private:
     479    PFNGLXGETVIDEOSYNCSGIPROC m_glXGetVideoSyncSGI;
     480    PFNGLXWAITVIDEOSYNCSGIPROC m_glXWaitVideoSyncSGI;
     481};
     482#endif // USING_OPENGL_VSYNC
     483
    440484OpenGLVideoSync::OpenGLVideoSync(VideoOutput *video_output,
    441485                                 int frame_interval, int refresh_interval,
    442486                                 bool interlaced)
    443487    : VideoSync(video_output, frame_interval, refresh_interval, interlaced),
    444       m_drawable(0), m_context(0)
     488      m_drawable(0), m_context(0), m_imp(0)
    445489{
     490#ifdef USING_OPENGL_VSYNC
     491    m_imp = new OpenGLVideoSyncPrivate;
     492#endif // USING_OPENGL_VSYNC
    446493}
    447494
    448495OpenGLVideoSync::~OpenGLVideoSync()
     
    457504        if (m_drawable)
    458505            X11S(XDestroyWindow(vo->XJ_disp, m_drawable));
    459506    }
     507    delete m_imp;
    460508#endif /* USING_OPENGL_VSYNC */
    461509}
    462510
     
    503551        return false;
    504552    }
    505553
     554    if (!m_imp->funcsLoaded())
     555    {
     556       VERBOSE(VB_PLAYBACK, QString("GL sync functions not found"));
     557       return false;
     558    }
     559
    506560    int attribList[] = {GLX_RGBA,
    507561                        GLX_RED_SIZE, 1,
    508562                        GLX_GREEN_SIZE, 1,
     
    552606    if (ret != False)
    553607    {
    554608        unsigned int count;
    555         X11S(ret = glXGetVideoSyncSGI(&count));
     609        X11S(ret = m_imp->glXGetVideoSyncSGI(&count));
    556610        if (ret == 0)
    557611        {
    558612            VERBOSE(VB_PLAYBACK, "Using OpenGLVideoSync");
     
    631685
    632686    // Wait for a refresh so we start out synched
    633687    unsigned int count;
    634     err = glXGetVideoSyncSGI(&count);
     688    err = m_imp->glXGetVideoSyncSGI(&count);
    635689    checkGLSyncError("OpenGLVideoSync::Start(): Frame Number Query", err);
    636     err = glXWaitVideoSyncSGI(2, (count+1)%2 ,&count);
     690    err = m_imp->glXWaitVideoSyncSGI(2, (count+1)%2 ,&count);
    637691    checkGLSyncError("OpenGLVideoSync::Start(): A/V Sync", err);
    638692
    639693    // Initialize next trigger
     
    649703    OffsetTimeval(m_nexttrigger, sync_delay);
    650704
    651705    unsigned int frameNum = 0;
    652     int err = glXGetVideoSyncSGI(&frameNum);
     706    int err = m_imp->glXGetVideoSyncSGI(&frameNum);
    653707    checkGLSyncError("Frame Number Query", err);
    654708
    655709    // Always sync to the next retrace execpt when we are very late.
    656710    if ((m_delay = CalcDelay()) > -(m_refresh_interval/2))
    657711    {
    658         err = glXWaitVideoSyncSGI(2, (frameNum+1)%2 ,&frameNum);
     712        err = m_imp->glXWaitVideoSyncSGI(2, (frameNum+1)%2 ,&frameNum);
    659713        checkGLSyncError(msg1, err);
    660714        m_delay = CalcDelay();
    661715    }
     
    664718    if (m_delay > 0)
    665719    {
    666720        uint n = m_delay / m_refresh_interval + 1;
    667         err = glXWaitVideoSyncSGI((n+1), (frameNum+n)%(n+1), &frameNum);
     721        err = m_imp->glXWaitVideoSyncSGI((n+1), (frameNum+n)%(n+1), &frameNum);
    668722        checkGLSyncError(msg2, err);
    669723        m_delay = CalcDelay();
    670724    }
  • libs/libmythtv/vsync.h

     
    214214  private:
    215215    GLXDrawable m_drawable;
    216216    GLXContext  m_context;
     217    class OpenGLVideoSyncPrivate *m_imp;
    217218};
    218219
    219220#ifdef __linux__