-VOID
-NTAPI
-SetStreamWorkerRoutineWaveCyclic(
- IN PDEVICE_OBJECT DeviceObject,
- IN PVOID Context)
-{
- CPortPinWaveCyclic * This;
- PSETSTREAM_CONTEXT Ctx = (PSETSTREAM_CONTEXT)Context;
- KSSTATE State;
- ULONG MinimumDataThreshold;
- ULONG MaximumDataThreshold;
-
- This = Ctx->Pin;
- State = Ctx->State;
-
- IoFreeWorkItem(Ctx->WorkItem);
- FreeItem(Ctx, TAG_PORTCLASS);
-
- // Has the audio stream resumed?
- if (This->m_IrpQueue->NumMappings() && State == KSSTATE_STOP)
- return;
-
- // Has the audio state already been set?
- if (This->m_State == State)
- return;
-
- // Set the state
- if (NT_SUCCESS(This->m_Stream->SetState(State)))
- {
- // Set internal state
- This->m_State = State;
-
- if (This->m_State == KSSTATE_STOP)
- {
- // reset start stream
- This->m_IrpQueue->CancelBuffers(); //FIX function name
-
- // increase stop counter
- This->m_StopCount++;
- // get current data threshold
- MinimumDataThreshold = This->m_IrpQueue->GetMinimumDataThreshold();
- // get maximum data threshold
- MaximumDataThreshold = ((PKSDATAFORMAT_WAVEFORMATEX)This->m_Format)->WaveFormatEx.nAvgBytesPerSec;
- // increase minimum data threshold by a third sec
- MinimumDataThreshold += This->m_FrameSize * 10;
-
- // assure it has not exceeded
- MinimumDataThreshold = min(MinimumDataThreshold, MaximumDataThreshold);
- // store minimum data threshold
- This->m_IrpQueue->SetMinimumDataThreshold(MinimumDataThreshold);
-
- DPRINT1("Stopping TotalPackets %u StopCount %u\n", This->m_TotalPackets, This->m_StopCount);
- }
- if (This->m_State == KSSTATE_RUN)
- {
- DPRINT1("State RUN %x MinAvailable %u CommonBufferSize %u Offset %u\n", State, This->m_IrpQueue->MinimumDataAvailable(), This->m_CommonBufferSize, This->m_CommonBufferOffset);
- }
- }
-}
-
-VOID
-NTAPI
-CPortPinWaveCyclic::SetStreamState(
- IN KSSTATE State)
-{
- PDEVICE_OBJECT DeviceObject;
- PIO_WORKITEM WorkItem;
- PSETSTREAM_CONTEXT Context;
-
- PC_ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
-
- // Has the audio stream resumed?
- if (m_IrpQueue->NumMappings() && State == KSSTATE_STOP)
- return;
-
- // Has the audio state already been set?
- if (m_State == State)
- return;
-
- // Get device object
- DeviceObject = GetDeviceObject(m_Port);
-
- // allocate set state context
- Context = (PSETSTREAM_CONTEXT)AllocateItem(NonPagedPool, sizeof(SETSTREAM_CONTEXT), TAG_PORTCLASS);
-
- if (!Context)
- return;
-
- // allocate work item
- WorkItem = IoAllocateWorkItem(DeviceObject);
-
- if (!WorkItem)
- {
- ExFreePool(Context);
- return;
- }
-
- Context->Pin = this;
- Context->WorkItem = WorkItem;
- Context->State = State;
-
- // queue the work item
- IoQueueWorkItem(WorkItem, SetStreamWorkerRoutineWaveCyclic, DelayedWorkQueue, (PVOID)Context);
-}
-