- USB Camera Filter Driver
- Posted by David on May 27th, 2008
I try to write a USB camera filter driver, and i can print debug stream comming from webcam info. but i can not access data buffer of this stream, following is my code:
I handle RP_MJ_DEVICE_CONTROL to trap stream comming from webcam
NTSTATUS DispatchAny(IN PDEVICE_OBJECT fido, IN PIRP Irp)
PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fido->DeviceExtension;
PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
UCHAR type = stack->MajorFunction;
// Pass request down without additional processing
if(type == IRP_MJ_DEVICE_CONTROL)
{
NTSTATUS status = STATUS_SUCCESS;
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp, SFDDeviceIoCompletion, NULL, TRUE, TRUE, TRUE );
status=IoCallDriver(pdx->LowerDeviceObject,Irp);
return status;
}
else
{
NTSTATUS status;
status = IoAcquireRemoveLock(&pdx->RemoveLock, Irp);
if (!NT_SUCCESS(status))
return CompleteRequest(Irp, status, 0);
IoSkipCurrentIrpStackLocation(Irp);
status = IoCallDriver(pdx->LowerDeviceObject, Irp);
IoReleaseRemoveLock(&pdx->RemoveLock, Irp);
return status;
}
}
I implement a complete function to handle 2 main IRP : IOCTL_KS_READ_STREAM and IOCTL_KS_WRITE_STREAM when next low level driver has completed the requested operation
NTSTATUS SFDDeviceIoCompletion(PDEVICE_OBJECT fido, PIRP Irp, PVOID Context)
{
if(Irp->PendingReturned)
IoMarkIrpPending(Irp);
NTSTATUS status = STATUS_SUCCESS;
PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
switch(IoControlCode)
{
case IOCTL_KS_READ_STREAM:
if(Irp->AssociatedIrp.SystemBuffer)
{
KSSTREAM_HEADER *_StreamHeader;
ULONG _BufferSize = 0;
_StreamHeader = (KSSTREAM_HEADER*)Irp->AssociatedIrp.SystemBuffer;
_BufferSize = _StreamHeader->DataUsed;
KdPrint(("device buffer size 2 %d\n", _BufferSize));
if(_BufferSize > 0)
{
PVOID sysBuf = ExAllocatePool(NonPagedPool, _BufferSize);
if(sysBuf)
{
if(_StreamHeader->Data)
{
KdPrint(("Start copy memory"));
RtlCopyMemory(sysBuf, _StreamHeader->Data, _BufferSize);
KdPrint(("Stop copy memory"));
}
ExFreePool(sysBuf);
}
}
}
else if(Irp->MdlAddress)
{
ULONG deviceBufferSize = 0;
deviceBufferSize = MmGetMdlByteCount(Irp->MdlAddress);
KdPrint(("device buffer size 1 %d\n", deviceBufferSize));
}
break;
case IOCTL_KS_WRITE_STREAM:
KdPrint((DRIVERNAME " - IOCTL_KS_WRITE_STREAM\n"));
break;
default:
break;
}
return status;
}
#1
_BufferSize = _StreamHeader->DataUsed;
KdPrint(("device buffer size 2 %d\n", _BufferSize));
I can see at debug view correct size stream, ex: 320 x 240 x 3 (RGB24) or: YUV12
#2
KdPrint(("Start copy memory"));
RtlCopyMemory(sysBuf, _StreamHeader->Data, _BufferSize);
KdPrint(("Stop copy memory"));
When run to this code system die cause by crash error:
*** ERROR: Module load completed but symbols could not be loaded for usbVM31b.sys
Probably caused by : usbcamerafilter.sys ( usbcamerafilter!SFDDeviceIoCompletion+10b
I do not know why i can not access this buffer, can anybody expert about USB Camera Filter Driver help me explain why?
My References: http://www.calsoftlabs.com/whitepape...driver.html#05
Thanks very much.
David.
- Posted by Tim Roberts on May 28th, 2008
"David" <thuong101277@yahoo.com> wrote:
You need to show us more of the !analyze -v. What was the blue screen
code? Are you absolutely sure the crash happens in RtlCopyMemory? Did you
print the Data address to make sure it made sense?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
- Posted by David on May 28th, 2008
Thank you, i will try to print it.
"Tim Roberts" <timr@probo.com> wrote in message
news:6vvp34lcodoqklo5asctinvn0s2gdc1uu3@4ax.com...
- Posted by Tim Roberts on May 31st, 2008
"David" <thuong101277@yahoo.com> wrote:
This code is very different from the code you originally posted. This code
is copying the data directly from the output buffer of the IRP. That's not
how the IRP_KS_READ_STREAM ioctl works.
Which one are you actually running?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
- Posted by David on June 2nd, 2008
Thank you for reply
Sorry for that, as my originally posted then i can not access buffer webcam
from Irp->AssociatedIrp.SystemBuffer so i try to get form Irp->MdlAddress,
now it work ok.
Now i meet problem listener event open, close stream of webcam from filter
and how to get with, high, bitrate of buffer data, such as see from
reference: http://www.calsoftlabs.com/whitepape...driver.html#05, I need
implemented : IOCTL_KS_PROPERTY handle to trap above informations, it is
correct?
"Tim Roberts" <timr@probo.com> wrote in message
news:kj3344131gefgl844oa2u7voe8uqhekh9d@4ax.com...
- Posted by Tim Roberts on June 3rd, 2008
"David" <thuong101277@yahoo.com> wrote:
Yes.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
- Posted by David on June 3rd, 2008
Thank you for reply
Have any articels guide to implement it, or any example how to implement it?
Can you help me?
"Tim Roberts" <timr@probo.com> wrote in message
news:jof944h7qgmr0pmoclketiunufetjst7l1@4ax.com...
- Posted by Tim Roberts on June 5th, 2008
"David" <thuong101277@yahoo.com> wrote:
No, but filter drivers are not hard to write, especially if you use KMDF.
What have you tried?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.