Example #1
0
void Signal::Wait()
{
    DWORD   ret;
    bool    stuck;

    SetWaiting(true);
    stuck = false;

    while (true)
    {
        DWORD timeout = 10000;
        //ret = WaitForSingleObject((HANDLE) impl.event, INFINITE);
        ret = WaitForSingleObject((HANDLE) impl.event, timeout);
        if (ret == WAIT_FAILED)
            Log_Errno();
        if (ret != WAIT_OBJECT_0 && ret != WAIT_TIMEOUT)
            Log_Debug("WaitForSingleObject: ret %d", ret);

        if (ret == WAIT_TIMEOUT)
        {
            if (stuck == false)
            {
                //Log_Debug("Waiting for long: %p in %U", this, ThreadPool::GetThreadID());
                stuck = true;
            }
            continue;
        }
        break;
    }
    SetWaiting(false);
}
Example #2
0
void Signal::Wait()
{
    DWORD   ret;

    SetWaiting(true);
    ret = WaitForSingleObject((HANDLE) impl.event, INFINITE);
    if (ret == WAIT_FAILED)
        Log_Errno();
    if (ret != WAIT_OBJECT_0)
        Log_Debug("WaitForSingleObject: ret %d", ret);
    SetWaiting(false);
}
//------------------------------------------------------------------------------
// GetBuffer
// get container for a sample. Blocking, synchronous call to get the
// next free buffer (as represented by an IMediaSample interface).
// on return, the time etc properties will be invalid and in this case
// the buffer pointer and size will be set when the app returns a buffer.
HRESULT CCustomAllocator::GetBuffer(IMediaSample** ppBuffer, REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime, DWORD dwFlags)
{
    UNREFERENCED_PARAMETER(pStartTime);
    UNREFERENCED_PARAMETER(pEndTime);
    UNREFERENCED_PARAMETER(dwFlags);
    CMediaSample* pSample;

    *ppBuffer = NULL;
    for (;;)
    {
        {  // scope for lock
            CAutoLock cObjectLock(this);

            /* Check we are committed */
            if (!m_bCommitted)
            {
                return VFW_E_NOT_COMMITTED;
            }
            pSample = (CMediaSample*)m_lDeliver.RemoveHead();
            if (pSample == NULL)
            {
                SetWaiting();
            }
        }

        /* If we didn't get a sample then wait for the list to signal */

        if (pSample)
        {
            break;
        }
        if (dwFlags & AM_GBF_NOWAIT)
        {
            return VFW_E_TIMEOUT;
        }
        ASSERT(m_hSem != NULL);
        WaitForSingleObject(m_hSem, INFINITE);
    }

    /* Addref the buffer up to one. On release
       back to zero instead of being deleted, it will requeue itself by
       calling the ReleaseBuffer member function. NOTE the owner of a
       media sample must always be derived from CBaseAllocator */

    ASSERT(pSample->m_cRef == 0);
    pSample->m_cRef = 1;
    *ppBuffer = pSample;

	DbgLog((LOG_TRACE, DBG_MEM, TEXT("CCustomAllocator::GetBuffer(): m_lFree: %d  m_lDeliver: %d"), m_lFree.GetCount(), m_lDeliver.GetCount()));

    return NOERROR;
}