Skip to content

Commit

Permalink
Merge pull request #231 from microsoft/ManagingContinuousReader
Browse files Browse the repository at this point in the history
Moving Start and Stop of Continuous Reader to Run / Pause of Stream
  • Loading branch information
Psychlist1972 authored Feb 12, 2024
2 parents 358391f + 1196711 commit 04b12d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
25 changes: 0 additions & 25 deletions src/api/Drivers/USBMIDI2/Driver/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,6 @@ EvtDeviceD0Entry(

TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Entry");

devCtx = GetDeviceContext(Device);
ASSERT(devCtx != nullptr);

if (devCtx->MidiInPipe)
{
status = WdfIoTargetStart(WdfUsbTargetPipeGetIoTarget(devCtx->MidiInPipe));
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_DEVICE,
"%!FUNC! Could not start interrupt pipe failed %!STATUS!", status);
}
}
else
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE,
"%!FUNC! Could not start interrupt pipe as no MidiInPipe");
}

TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Exit");

Expand Down Expand Up @@ -490,14 +473,6 @@ EvtDeviceD0Exit(
}
}

if (devCtx->MidiInPipe)
{
WdfIoTargetStop(
WdfUsbTargetPipeGetIoTarget(devCtx->MidiInPipe),
WdfIoTargetCancelSentIo
);
}

TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Exit");

return status;
Expand Down
33 changes: 33 additions & 0 deletions src/api/Drivers/USBMIDI2/Driver/StreamEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,20 @@ StreamEngine::Pause()
}
else
{
// Stop the continuous reader
WDFDEVICE devCtx = AcxCircuitGetWdfDevice(AcxPinGetCircuit(m_Pin));
PDEVICE_CONTEXT pDevCtx = GetDeviceContext(devCtx);

if (pDevCtx)
{
WdfIoTargetStop(WdfUsbTargetPipeGetIoTarget(pDevCtx->MidiInPipe), WdfIoTargetCancelSentIo);
}
else
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE,
"%!FUNC! Could not start interrupt pipe as no MidiInPipe");
}

// If g_MidiInStreamEngine is available, the midi out worker thread will loopback.
// If it isn't available, the midi out worker will throw the data away.
// So when we transition midi in from run to paused, acquire the lock that
Expand Down Expand Up @@ -587,6 +601,25 @@ StreamEngine::Run()
auto lock = g_MidiInLock->acquire();
// pDevCtx->pMidiStreamEngine = this;
g_MidiInStreamEngine = this;

// Start the Continuous reader
WDFDEVICE devCtx = AcxCircuitGetWdfDevice(AcxPinGetCircuit(m_Pin));
PDEVICE_CONTEXT pDevCtx = GetDeviceContext(devCtx);

if (pDevCtx)
{
status = WdfIoTargetStart(WdfUsbTargetPipeGetIoTarget(pDevCtx->MidiInPipe));
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_DEVICE,
"%!FUNC! Could not start interrupt pipe failed %!STATUS!", status);
}
}
else
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE,
"%!FUNC! Could not start interrupt pipe as no MidiInPipe");
}
}

//
Expand Down

0 comments on commit 04b12d7

Please sign in to comment.