]> git.vomp.tv Git - vompclient.git/commitdiff
Roll OsdOpenVG::haveOpenVGResponse into putOpenVGCommand
authorChris Tallon <chris@vomp.tv>
Sat, 16 May 2020 13:59:58 +0000 (14:59 +0100)
committerChris Tallon <chris@vomp.tv>
Sat, 16 May 2020 13:59:58 +0000 (14:59 +0100)
osdopenvg.cc
osdopenvg.h

index 372e898736ec13745f066281b4b674f94e19ae65..f1fa05655f2748f3ce01dafc052b64d1fac0496c 100644 (file)
@@ -1367,7 +1367,7 @@ unsigned int OsdOpenVG::handleTask(OpenVGCommand& command)
         m->tag = info->lindex >> 32LL;
       }
 
-      MessageQueue::getInstance()->postMessage(m); // inform command about new picture
+      MessageQueue::getInstance()->postMessage(m); // inform control about new picture
 
       delete info;
       break;
@@ -1382,15 +1382,11 @@ unsigned int OsdOpenVG::handleTask(OpenVGCommand& command)
 
       info->handle = handle;
       info->reference =  eglCreateImageKHR(egl_display, egl_context, EGL_VG_PARENT_IMAGE_KHR, reinterpret_cast<EGLClientBuffer>(handle), NULL);
-
       if (info->reference) return true;
-      else
-      {
-        Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateEGLImage %d %d %x Fail!", info->width, info->height, handle);
-        if (handle) vgDestroyImage(handle);
-        return false;
-      }
-      break;
+
+      Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateEGLImage %d %d %x Fail!", info->width, info->height, handle);
+      if (handle) vgDestroyImage(handle);
+      return false;
     }
     case OVGreadyEGLImage:
     {
@@ -1538,84 +1534,42 @@ bool OsdOpenVG::processTasks()
   return worked;
 }
 
-bool OsdOpenVG::haveOpenVGResponse(unsigned int id, unsigned int* resp)
-{
-  taskmutex.lock();
-
-  if (vgresponses.size() > 0)
-  {
-    std::deque<OpenVGResponse>::iterator itty = vgresponses.begin();
-
-    while (itty != vgresponses.end())
-    {
-      if ((*itty).id == id)
-      {
-        *resp = (*itty).result;
-        taskmutex.unlock();
-        return true;
-      }
-
-      itty++;
-    }
-  }
-
-  taskmutex.unlock();
-  return false;
-}
-
 unsigned int OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm, bool wait)
 {
   taskmutex.lock();
 
   if (wait)
-  {
-    comm.id = wait_id;
-    wait_id++;
-  }
+    comm.id = wait_id++;
   else
-  {
     comm.id = 0; // we are not waiting
-  }
 
   vgcommands.push_back(comm);
   taskmutex.unlock();
+
   threadSignal();
 
-  while (wait)
-  {
-    unsigned int resp;
+  if (!wait) return 0;
 
-    if (!haveOpenVGResponse(comm.id, &resp))
+  while(1)
+  {
+    // Is there a response now?
+    taskmutex.lock();
+    for (auto& vgresponse : vgresponses)
     {
-
-      //          Log::getInstance()->log("OsdOpenVG", Log::DEBUG, "putOpenVGCommand wait_for");
-      std::unique_lock<std::mutex> ul(vgTaskSignalMutex);
-      /*auto a = */ vgTaskSignal.wait_for(ul, std::chrono::milliseconds(100));
-      ul.unlock();
-      /*
-                  if (a == std::cv_status::timeout)
-                    Log::getInstance()->log("OsdOpenVG", Log::DEBUG, "putOpenVGCommand timeout");
-                  else
-                    Log::getInstance()->log("OsdOpenVG", Log::DEBUG, "putOpenVGCommand no timeout");
-      */
-      /*
-      struct timespec target_time;
-      clock_gettime(CLOCK_REALTIME,&target_time);
-      target_time.tv_nsec+=1000000LL*100;
-      if (target_time.tv_nsec>999999999) {
-      target_time.tv_nsec-=1000000000L;
-      target_time.tv_sec+=1;
+      if (vgresponse.id == comm.id)
+      {
+        UINT resp = vgresponse.result;
+        taskmutex.unlock();
+        return resp;
       }
-      vgtaskSignal.waitForSignalTimed(&target_time);
-        */
     }
-    else
-    {
-      return resp;
-    }
-  }
+    // No.
+    taskmutex.unlock();
 
-  return 0;
+    std::unique_lock<std::mutex> ul(vgTaskSignalMutex);
+    vgTaskSignal.wait_for(ul, std::chrono::milliseconds(100));
+    ul.unlock();
+  }
 }
 
 void OsdOpenVG::destroyImageRef(ImageIndex index)
index 194dec1b656d3a0906a90ac2f2b362d77c409669..c66469cd3a6a6f0d99d913bc6780c23807ad5ae6 100644 (file)
@@ -23,6 +23,7 @@
 #include <vector>
 #include <deque>
 #include <mutex>
+#include <thread>
 #include <condition_variable>
 
 #include <EGL/egl.h>
@@ -131,7 +132,6 @@ class OsdOpenVG : public OsdVector, public Thread_TYPE
     std::deque<OpenVGCommand> vgcommands;
     std::deque<OpenVGResponse> vgresponses;
     bool processTasks();
-    bool haveOpenVGResponse(unsigned int id, unsigned int* resp);
     unsigned int putOpenVGCommand(OpenVGCommand& comm, bool wait);
     unsigned int handleTask(OpenVGCommand& command);
     //void purgeAllReferences();
@@ -182,6 +182,10 @@ class OsdOpenVG : public OsdVector, public Thread_TYPE
     ImageOMX* imageomx;
 #endif
 
+    // future
+    //std::thread renderThread;
+    //std::mutex threadStartProtect;
+
 };
 
 #endif