qtmobility/plugins/multimedia/directshow/player/directshoweventloop.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    63     QEvent *event;
    63     QEvent *event;
    64     DirectShowPostedEvent *next;
    64     DirectShowPostedEvent *next;
    65 };
    65 };
    66 
    66 
    67 DirectShowEventLoop::DirectShowEventLoop(QObject *parent)
    67 DirectShowEventLoop::DirectShowEventLoop(QObject *parent)
    68     : QWinEventNotifier(parent)
    68     : QObject(parent)
    69     , m_postsHead(0)
    69     , m_postsHead(0)
    70     , m_postsTail(0)
    70     , m_postsTail(0)
    71     , m_eventHandle(::CreateEvent(0, 0, 0, 0))
    71     , m_eventHandle(::CreateEvent(0, 0, 0, 0))
    72     , m_waitHandle(::CreateEvent(0, 0, 0, 0))
    72     , m_waitHandle(::CreateEvent(0, 0, 0, 0))
    73 {
    73 {
    74     setHandle(m_eventHandle);
       
    75     setEnabled(true);
       
    76 }
    74 }
    77 
    75 
    78 DirectShowEventLoop::~DirectShowEventLoop()
    76 DirectShowEventLoop::~DirectShowEventLoop()
    79 {
    77 {
    80     setEnabled(false);
       
    81 
       
    82     ::CloseHandle(m_eventHandle);
    78     ::CloseHandle(m_eventHandle);
    83     ::CloseHandle(m_waitHandle);
    79     ::CloseHandle(m_waitHandle);
    84 
    80 
    85     for (DirectShowPostedEvent *post = m_postsHead; post; post = m_postsHead) {
    81     for (DirectShowPostedEvent *post = m_postsHead; post; post = m_postsHead) {
    86         m_postsHead = m_postsHead->next;
    82         m_postsHead = m_postsHead->next;
   118     else
   114     else
   119         m_postsHead = post;
   115         m_postsHead = post;
   120 
   116 
   121     m_postsTail = post;
   117     m_postsTail = post;
   122 
   118 
       
   119     QCoreApplication::postEvent(this, new QEvent(QEvent::User));
   123     ::SetEvent(m_eventHandle);
   120     ::SetEvent(m_eventHandle);
   124 }
   121 }
   125 
   122 
   126 bool DirectShowEventLoop::event(QEvent *event)
   123 void DirectShowEventLoop::customEvent(QEvent *event)
   127 {
   124 {
   128     if (event->type() == QEvent::WinEventAct) {
   125     if (event->type() == QEvent::User) {
   129         processEvents();
   126         processEvents();
   130 
       
   131         return true;
       
   132     } else {
   127     } else {
   133         return QWinEventNotifier::event(event);
   128         QObject::customEvent(event);
   134     }
   129     }
   135 }
   130 }
   136 
   131 
   137 void DirectShowEventLoop::processEvents()
   132 void DirectShowEventLoop::processEvents()
   138 {
   133 {
   139     QMutexLocker locker(&m_mutex);
   134     QMutexLocker locker(&m_mutex);
   140 
   135 
       
   136     ::ResetEvent(m_eventHandle);
       
   137 
   141     while(m_postsHead) {
   138     while(m_postsHead) {
   142         ::ResetEvent(m_eventHandle);
       
   143 
       
   144         DirectShowPostedEvent *post = m_postsHead;
   139         DirectShowPostedEvent *post = m_postsHead;
   145         m_postsHead = m_postsHead->next;
   140         m_postsHead = m_postsHead->next;
       
   141 
       
   142         if (!m_postsHead)
       
   143             m_postsTail = 0;
   146 
   144 
   147         locker.unlock();
   145         locker.unlock();
   148         QCoreApplication::sendEvent(post->receiver, post->event);
   146         QCoreApplication::sendEvent(post->receiver, post->event);
   149         delete post;
   147         delete post;
   150         locker.relock();
   148         locker.relock();
   151     }
   149     }
   152 
       
   153     m_postsTail = 0;
       
   154 }
   150 }