Thread::Thread()
    : m_pFn(NULL),
      m_nPriority(0),
      m_pThread(NULL),
      m_pThreadArgs(NULL)
 {
    VENC_TEST_MSG_LOW("constructor", 0, 0, 0);
 }
 FileSink::FileSink()
   : m_nFrames(0),
   m_pFile(),
   m_pBufferQueue(new SignalQueue(MAX_BUFFER_ASSUME, sizeof(OMX_BUFFERHEADERTYPE*))),
   m_pThread(new Thread()),
   m_bStarted(OMX_FALSE),
   m_pFrameReleaseFn(NULL)
 {
   VENC_TEST_MSG_LOW("created sink");
 }
   OMX_ERRORTYPE Thread::Start(StartFnType pFn,
                               OMX_PTR pThreadArgs,
                               OMX_S32 nPriority)
   {
      OMX_ERRORTYPE result = OMX_ErrorNone;

      VENC_TEST_MSG_LOW("Start", 0, 0, 0);
      m_pThreadArgs = pThreadArgs;
      m_pFn = pFn;
      
      if (venc_thread_create(&m_pThread, ThreadEntry, this, (int) nPriority) != 0)
      {
         VENC_TEST_MSG_ERROR("failed to create thread", 0, 0, 0);
         result = OMX_ErrorUndefined;
      }

      return result;
   }
   int Thread::ThreadEntry(void* pThreadData)
   {
      Thread* pThread = (Thread*) pThreadData;
      VENC_TEST_MSG_LOW("ThreadEntry", 0, 0, 0);
      OMX_ERRORTYPE result = OMX_ErrorNone;

      if (pThread != NULL)
      {
         result = pThread->m_pFn(pThread->m_pThreadArgs);
      }
      else
      {
         VENC_TEST_MSG_ERROR("failed to create thread", 0, 0, 0);
         result = OMX_ErrorUndefined;
      }


      return (int) result;
   }
   OMX_ERRORTYPE Thread::Join(OMX_ERRORTYPE* pThreadResult)
   {
      OMX_ERRORTYPE result = OMX_ErrorNone;
      int thread_result;

      VENC_TEST_MSG_LOW("Join", 0, 0, 0);
      
      if (venc_thread_destroy(m_pThread, &thread_result) != 0)
      {
         VENC_TEST_MSG_ERROR("failed to destroy thread", 0, 0, 0);
      }

      if (pThreadResult != NULL)
      {
         *pThreadResult = (OMX_ERRORTYPE) thread_result;
      }

      m_pThread = NULL;

      return result;
   }
 Thread::~Thread()
 {
    VENC_TEST_MSG_LOW("destructor", 0, 0, 0);
 }