ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

Definition at line 2607 of file output_pin.cpp.

Referenced by CKsProxy::SetPinState().

{
    HRESULT hr = S_OK;
    KSPROPERTY Property;
    KSSTATE CurState;
    ULONG BytesReturned;
    COutputPin * pPin = (COutputPin*)Pin;

#ifdef KSPROXY_TRACE
    WCHAR Buffer[200];
#endif

    Property.Set = KSPROPSETID_Connection;
    Property.Id = KSPROPERTY_CONNECTION_STATE;
    Property.Flags = KSPROPERTY_TYPE_SET;

    EnterCriticalSection(&pPin->m_Lock);

    if (pPin->m_State <= State)
    {
        if (pPin->m_State == KSSTATE_STOP)
        {
            hr = pPin->InitializeIOThread();
            if (FAILED(hr))
            {
                // failed to initialize I/O thread
#ifdef KSPROXY_TRACE
                OutputDebugStringW(L"Failed to initialize I/O Thread\n");
#endif
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }
            CurState = KSSTATE_ACQUIRE;
            hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState, sizeof(KSSTATE), &BytesReturned);

#ifdef KSPROXY_TRACE
            swprintf(Buffer, L"COutputPin_SetState Setting State CurState: KSSTATE_STOP KSSTATE_ACQUIRE PinName %s hr %lx\n", pPin->m_PinName, hr);
            OutputDebugStringW(Buffer);
#endif

            if (FAILED(hr))
            {
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }

            pPin->m_State = CurState;

            if (pPin->m_State == State)
            {
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }
        }
        if (pPin->m_State == KSSTATE_ACQUIRE)
        {
            CurState = KSSTATE_PAUSE;
            hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState, sizeof(KSSTATE), &BytesReturned);

#ifdef KSPROXY_TRACE
            swprintf(Buffer, L"COutputPin_SetState Setting State CurState KSSTATE_ACQUIRE KSSTATE_PAUSE PinName %s hr %lx\n", pPin->m_PinName, hr);
            OutputDebugStringW(Buffer);
#endif

            if (FAILED(hr))
            {
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }

            pPin->m_State = CurState;

            if (pPin->m_State == State)
            {
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }
        }
        if (State == KSSTATE_RUN && pPin->m_State == KSSTATE_PAUSE)
        {
            CurState = KSSTATE_RUN;
            hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState, sizeof(KSSTATE), &BytesReturned);

#ifdef KSPROXY_TRACE
            swprintf(Buffer, L"COutputPin_SetState Setting State CurState: KSSTATE_PAUSE KSSTATE_RUN PinName %s hr %lx\n", pPin->m_PinName, hr);
            OutputDebugStringW(Buffer);
#endif

            if (SUCCEEDED(hr))
            {
                pPin->m_State = CurState;
                // signal start event
                SetEvent(pPin->m_hStartEvent);
            }
        }

        LeaveCriticalSection(&pPin->m_Lock);
        return hr;
    }
    else
    {
        if (pPin->m_State == KSSTATE_RUN)
        {
            // setting pending stop flag
            pPin->m_StopInProgress = true;

            // release any waiting threads
            SetEvent(pPin->m_hBufferAvailable);

            // wait until i/o thread is done
            WaitForSingleObject(pPin->m_hStopEvent, INFINITE);

            CurState = KSSTATE_PAUSE;
            hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState, sizeof(KSSTATE), &BytesReturned);

#ifdef KSPROXY_TRACE
            swprintf(Buffer, L"COutputPin_SetState Setting State CurState: KSSTATE_RUN KSSTATE_PAUSE PinName %s hr %lx\n", pPin->m_PinName, hr);
            OutputDebugStringW(Buffer);
#endif

            if (FAILED(hr))
            {
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }

            pPin->m_State = CurState;

            if (FAILED(hr))
            {
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }
        }
        if (pPin->m_State == KSSTATE_PAUSE)
        {
            CurState = KSSTATE_ACQUIRE;
            hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState, sizeof(KSSTATE), &BytesReturned);

#ifdef KSPROXY_TRACE
            swprintf(Buffer, L"COutputPin_SetState Setting State CurState: KSSTATE_PAUSE KSSTATE_ACQUIRE PinName %s hr %lx\n", pPin->m_PinName, hr);
            OutputDebugStringW(Buffer);
#endif

            if (FAILED(hr))
            {
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }

            pPin->m_State = CurState;

            if (pPin->m_State == State)
            {
                LeaveCriticalSection(&pPin->m_Lock);
                return hr;
            }
        }

        CloseHandle(pPin->m_hStopEvent);
        CloseHandle(pPin->m_hStartEvent);
        CloseHandle(pPin->m_hBufferAvailable);

        /* close event handles */
        pPin->m_hStopEvent = NULL;
        pPin->m_hStartEvent = NULL;
        pPin->m_hBufferAvailable = NULL;

        CurState = KSSTATE_STOP;
        hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState, sizeof(KSSTATE), &BytesReturned);

#ifdef KSPROXY_TRACE
        swprintf(Buffer, L"COutputPin_SetState Setting State CurState: KSSTATE_ACQUIRE KSSTATE_STOP PinName %s hr %lx\n", pPin->m_PinName, hr);
        OutputDebugStringW(Buffer);
#endif

        if (SUCCEEDED(hr))
        {
            // store state
            pPin->m_State = CurState;
        }

        // unset pending stop flag
        pPin->m_StopInProgress = false;

        LeaveCriticalSection(&pPin->m_Lock);
        return hr;
    }
}

Generated on Sun May 27 2012 05:03:05 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.