NTSTATUS
CImageHardwareSimulation::
SetClock(_In_ PKSPIN pin)
{
    PAGED_CODE();

    if(!NT_SUCCESS(KsPinGetReferenceClockInterface(pin, &m_Clock)))
    {
        m_Clock = NULL;
    }

    return STATUS_SUCCESS;
}
Exemplo n.º 2
0
NTSTATUS
CStillPin::
SetState (
    IN KSSTATE ToState,
    IN KSSTATE FromState
)

/*++

Routine Description:

    This is called when the caputre pin transitions state.  The routine
    attempts to acquire / release any hardware resources and start up
    or shut down capture based on the states we are transitioning to
    and away from.

Arguments:

    ToState -
        The state we're transitioning to

    FromState -
        The state we're transitioning away from

Return Value:

    Success / Failure

--*/

{
    PAGED_CODE();
    DBGU_TRACE("Enter CStillPin::SetState from %d to %d\n",FromState,ToState);

    NTSTATUS Status = STATUS_SUCCESS;
    PKSGATE pGate = KsPinGetAndGate(m_Pin);

    if (!m_Device)
    {
        DBGU_ERROR("m_Device of CStillPin is NULL!\n");
        return STATUS_UNSUCCESSFUL;
    }

    switch (ToState) {
    case KSSTATE_STOP:
        //
        // First, stop the hardware if we actually did anything to it.
        //
        if (m_StreamState != KSSTATE_RUN) {
            Status = m_Device -> Stop (m_Pin);
            //ASSERT (NT_SUCCESS (Status));

            m_StreamState = KSSTATE_STOP;
        }

        //
        // We've stopped the "fake hardware".  It has cleared out
        // it's scatter / gather tables and will no longer be
        // completing clones.  We had locks on some frames that were,
        // however, in hardware.  This will clean them up.  An
        // alternative location would be in the reset dispatch.
        // Note, however, that the reset dispatch can occur in any
        // state and this should be understood.
        //
        // Some hardware may fill all S/G mappings before stopping...
        // in this case, you may not have to do this.  The
        // "fake hardware" here simply stops filling mappings and
        // cleans its scatter / gather tables out on the Stop call.
        //
        Status = CleanupReferences ();

        //
        // Release any hardware resources related to this pin.
        //
        if (m_AcquiredResources) {
            //
            // If we got an interface to the clock, we must release it.
            //
            if (m_Clock) {
                m_Clock -> Release ();
                m_Clock = NULL;
            }

            m_Device -> ReleaseHardwareResources (
                m_Pin->Id
            );

            m_AcquiredResources = FALSE;
            DBGU_TRACE("Enter CStillPin::SetState to KSSTATE_STOP => pStillPin = NULL\n");
            m_Device->pdx->pStillPin = NULL;
        }

        break;

    case KSSTATE_ACQUIRE:
        //
        // Acquire any hardware resources related to this pin.  We should
        // only acquire them here -- **NOT** at filter create time.
        // This means we do not fail creation of a filter because of
        // limited hardware resources.
        //
        if (FromState == KSSTATE_STOP) {
            Status = m_Device -> AcquireHardwareResources (
                         m_VideoInfoHeader,
                         m_Pin->Id
                     );

            if (NT_SUCCESS (Status)) {
                m_AcquiredResources = TRUE;
                DBGU_TRACE("Enter CStillPin::SetState to KSSTATE_ACQUIRE => pStillPin = this\n");
                m_Device->pdx->pStillPin = this;

                //
                // Attempt to get an interface to the master clock.
                // This will fail if one has not been assigned.  Since
                // one must be assigned while the pin is still in
                // KSSTATE_STOP, this is a guranteed method of getting
                // the clock should one be assigned.
                //
                if (!NT_SUCCESS (
                            KsPinGetReferenceClockInterface (
                                m_Pin,
                                &m_Clock
                            )
                        )) {

                    //
                    // If we could not get an interface to the clock,
                    // don't use one.
                    //
                    m_Clock = NULL;
                }
            } else {
                m_AcquiredResources = FALSE;
            }
        } else {
            //
            // Standard transport pins will always receive transitions in
            // +/- 1 manner.  This means we'll always see a PAUSE->ACQUIRE
            // transition before stopping the pin.
            //
            // The below is done because on DirectX 8.0, when the pin gets
            // a message to stop, the queue is inaccessible.  The reset
            // which comes on every stop happens after this (at which time
            // the queue is inaccessible also).  So, for compatibility with
            // DirectX 8.0, I am stopping the "fake" hardware at this
            // point and cleaning up all references we have on frames.  See
            // the comments above regarding the CleanupReferences call.
            //
            // If this sample were targeting XP only, the below code would
            // not be here.  Again, I only do this so the sample does not
            // hang when it is stopped running on a configuration such as
            // Win2K + DX8.
            //
            if (m_StreamState != KSSTATE_STOP) {
                Status = m_Device -> Stop (m_Pin);
                //ASSERT (NT_SUCCESS (Status));

                m_StreamState = KSSTATE_STOP;
            }

            Status = CleanupReferences ();
        }

        break;

    case KSSTATE_PAUSE:
        //
        // Stop the hardware if we're coming down from run.
        //
        if (FromState == KSSTATE_RUN) {

            m_PresentationTime = 0;
            Status = m_Device -> Pause (m_Pin, TRUE);

            if (NT_SUCCESS (Status)) {
                m_StreamState = KSSTATE_PAUSE;
            }

        }

        break;

    case KSSTATE_RUN:
        //
        // Start the hardware or unpause it depending on
        // whether we're initially running or we've paused and restarted.
        //
        if (m_StreamState == KSSTATE_PAUSE) {
            Status = m_Device -> Pause (m_Pin, FALSE);
        } else {
            Status = m_Device -> Start (m_Pin);
        }

        //
        // Turn Off the PinGate to avoid processing
        //
        if (pGate)
        {
            KsGateTurnInputOff(pGate);
        }

        if (NT_SUCCESS (Status)) {
            m_StreamState = KSSTATE_RUN;
        }

        break;
    }

    DBGU_TRACE("Leave CStillPin::SetState with status = %X\n",Status);
    return Status;
}
Exemplo n.º 3
0
NTSTATUS
CCapturePin::
SetState (
    IN KSSTATE ToState,
    IN KSSTATE FromState
)

/*++

Routine Description:

    Called when the pin is transitioning state.  This is a bridge from
    DispatchSetState in the context of the capture pin.  The function itself
    performs basic clock handling (things that all the derived pins would use)
    and then calls the appropriate method in the derived class.

Arguments:

    FromState -
        The state the pin is transitioning away from

    ToState -
        The state the pin is transitioning towards

Return Value:

    Success / Failure of state transition.

--*/

{

    PAGED_CODE();

    NTSTATUS Status = STATUS_SUCCESS;

    switch (ToState) {

    case KSSTATE_STOP:

        //
        // Reset the dropped frame counter.
        //
        m_DroppedFrames = 0;
        m_FrameNumber = 0;

        //
        // On a transition to stop, the clock will be released.
        //
        if (m_Clock) {
            m_Clock -> Release ();
            m_Clock = NULL;
        }

        Status = Stop (FromState);
        break;

    case KSSTATE_ACQUIRE:

        //
        // On a transition to acqiure (from stop), the pin queries for
        // its assigned clock.  This can be done either here or at the
        // transition to pause.
        //
        if (FromState == KSSTATE_STOP) {

            Status = KsPinGetReferenceClockInterface (
                         m_Pin,
                         &m_Clock
                     );

            if (!NT_SUCCESS (Status)) {
                m_Clock = NULL;
            }

        }

        Status = Acquire (FromState);
        break;

    case KSSTATE_PAUSE:

        Status = Pause (FromState);
        break;

    case KSSTATE_RUN:

        Status = Run (FromState);
        break;

    }

    if (NT_SUCCESS (Status)) {
        m_State = ToState;
    }

    return Status;

}