Camera vedio switch issue?

Dear all:
I have met a difficult during web camera driver developing. Here is the problem.
Using one web camera hardware supports MJPEG 1 and YUY2, and amcap.exe to test my driver.
If driver just creats YUY2 data range, AmCap works well(video frames are displayed continously).
If driver just creats MJPEG data range, AmCap works well also.
However, if driver creats both YUY2 and MJPEG data range, AmCap can not work
continuously when I set data frame as YUY2. And in order to resume amcap, I need switch other windows or clilk amcmp’s window several times.
Furthermore, graphedit is OK.

The next are data ranges:
const
KS_DATARANGE_VIDEO
FormatYUY2_Capture = {

//
// KSDATARANGE
//
{
sizeof (KS_DATARANGE_VIDEO), // FormatSize
0, // Flags
0,//DMAX_X2 * DMAX_Y2 * 2, // SampleSize
0, // Reserved
STATICGUIDOF (KSDATAFORMAT_TYPE_VIDEO), // aka. MEDIATYPE_Video
0x32595559, 0x0000, 0x0010, 0x80, 0x00,
0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71, //aka. MEDIASUBTYPE_YUY2,
STATICGUIDOF (KSDATAFORMAT_SPECIFIER_VIDEOINFO) // aka. FORMAT_VideoInfo
},

TRUE, // BOOL, bFixedSizeSamples (all samples same size?)
TRUE, // BOOL, bTemporalCompression (all I frames?)
0, // Reserved (was StreamDescriptionFlags)
0, // Reserved (was MemoryAllocationFlags
// (KS_VIDEO_ALLOC_*))

//
// _KS_VIDEO_STREAM_CONFIG_CAPS
//
{
STATICGUIDOF( KSDATAFORMAT_SPECIFIER_VIDEOINFO ), // GUID
KS_AnalogVideo_None,// // AnalogVideoStandard
DMAX_X2, DMAX_Y2, // InputSize, (the inherent size of the incoming signal
// with every digitized pixel unique)
D_X2,D_Y2, // MinCroppingSize, smallest rcSrc cropping rect allowed
DMAX_X2, DMAX_Y2, // MaxCroppingSize, largest rcSrc cropping rect allowed
1, // CropGranularityX, granularity of cropping size
1, // CropGranularityY
1, // CropAlignX, alignment of cropping rect
1, // CropAlignY;
D_X2, D_Y2, // MinOutputSize, smallest bitmap stream can produce
DMAX_X2, DMAX_Y2, // MaxOutputSize, largest bitmap stream can produce
1, // OutputGranularityX, granularity of output bitmap size
1, // OutputGranularityY;
0, // StretchTapsX (0 no stretch, 1 pix dup, 2 interp…)
0, // StretchTapsY
0, // ShrinkTapsX
0, // ShrinkTapsY
333333, // MinFrameInterval, 100 nS units
640000000, // MaxFrameInterval, 100 nS units
8 * 2 * 30 * D_X2 * D_Y2, // MinBitsPerSecond;
8 * 2 * 30 * DMAX_X2 * DMAX_Y2, // MaxBitsPerSecond;
},

//
// KS_VIDEOINFOHEADER (default format)
//
{
0, 0, D_X2, D_Y2, // RECT rcSource;
0, 0, D_X2, D_Y2, // RECT rcTarget;
DMAX_X2 * DMAX_Y2 * 2 *8* 30, // DWORD dwBitRate;
0L, // DWORD dwBitErrorRate;
333333, // REFERENCE_TIME AvgTimePerFrame;
sizeof (KS_BITMAPINFOHEADER), // DWORD biSize;
DMAX_X2, // LONG biWidth;
DMAX_Y2, // LONG biHeight;
1, // WORD biPlanes;
16, // WORD biBitCount;
FOURCC_YUY2, // DWORD biCompression;
DMAX_X2 * DMAX_Y2 * 2+1, // DWORD biSizeImage;
0, // LONG biXPelsPerMeter;
0, // LONG biYPelsPerMeter;
0, // DWORD biClrUsed;
0 // DWORD biClrImportant;
}
};

// FormatMJPEG_Capture:
//
// This is the data range description of the YUY2 format we support.
const
KS_DATARANGE_VIDEO
FormatMJPEG_Capture = {

//
// KSDATARANGE
//
{
sizeof (KS_DATARANGE_VIDEO), // FormatSize
0, // Flags
0,//DMAX_X2 * DMAX_Y2 * 2, // SampleSize
0, // Reserved
STATICGUIDOF (KSDATAFORMAT_TYPE_VIDEO), // aka. MEDIATYPE_Video
0x47504A4D, 0x0000, 0x0010, 0x80, 0x00,0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71, //aka. MEDIASUBTYPE_YUY2,
STATICGUIDOF (KSDATAFORMAT_SPECIFIER_VIDEOINFO) // aka. FORMAT_VideoInfo
},

TRUE, // BOOL, bFixedSizeSamples (all samples same size?)
TRUE, // BOOL, bTemporalCompression (all I frames?)
0, // Reserved (was StreamDescriptionFlags)
0, // Reserved (was MemoryAllocationFlags
// (KS_VIDEO_ALLOC_*))

//
// _KS_VIDEO_STREAM_CONFIG_CAPS
//
{
STATICGUIDOF( KSDATAFORMAT_SPECIFIER_VIDEOINFO ), // GUID
KS_AnalogVideo_None,// // AnalogVideoStandard
DMAX_X, DMAX_Y, // InputSize, (the inherent size of the incoming signal
// with every digitized pixel unique)
D_X,D_Y, // MinCroppingSize, smallest rcSrc cropping rect allowed
DMAX_X, DMAX_Y, // MaxCroppingSize, largest rcSrc cropping rect allowed
1, // CropGranularityX, granularity of cropping size
1, // CropGranularityY
1, // CropAlignX, alignment of cropping rect
1, // CropAlignY;
D_X, D_Y, // MinOutputSize, smallest bitmap stream can produce
DMAX_X, DMAX_Y, // MaxOutputSize, largest bitmap stream can produce
1, // OutputGranularityX, granularity of output bitmap size
1, // OutputGranularityY;
0, // StretchTapsX (0 no stretch, 1 pix dup, 2 interp…)
0, // StretchTapsY
0, // ShrinkTapsX
0, // ShrinkTapsY
333333, // MinFrameInterval, 100 nS units
200000000, // MaxFrameInterval, 100 nS units
8 * 2 * 30 * D_X * D_Y, // MinBitsPerSecond;
8 * 2 * 30 * DMAX_X * DMAX_Y, // MaxBitsPerSecond;
},

//
// KS_VIDEOINFOHEADER (default format)
//
{
0, 0, D_X, D_Y, // RECT rcSource;
0, 0, D_X, D_Y, // RECT rcTarget;
DMAX_X * DMAX_Y * 2 *8* 30, // DWORD dwBitRate;
0L, // DWORD dwBitErrorRate;
333333, // REFERENCE_TIME AvgTimePerFrame;
sizeof (KS_BITMAPINFOHEADER), // DWORD biSize;
DMAX_X, // LONG biWidth;
DMAX_Y, // LONG biHeight;
1, // WORD biPlanes;
24, // WORD biBitCount;
FOURCC_MJPEG, // DWORD biCompression;
DMAX_X * DMAX_Y * 2+1, // DWORD biSizeImage;
0, // LONG biXPelsPerMeter;
0, // LONG biYPelsPerMeter;
0, // DWORD biClrUsed;
0 // DWORD biClrImportant;
}
};

zhou_5129327@163.com wrote:

I have met a difficult during web camera driver developing. Here is the problem.
Using one web camera hardware supports MJPEG 1 and YUY2, and amcap.exe to test my driver.
If driver just creats YUY2 data range, AmCap works well(video frames are displayed continously).
If driver just creats MJPEG data range, AmCap works well also.
However, if driver creats both YUY2 and MJPEG data range, AmCap can not work
continuously when I set data frame as YUY2. And in order to resume amcap, I need switch other windows or clilk amcmp’s window several times.
Furthermore, graphedit is OK.

You are using the Amcap “Video capture pin” menu option to change the
format, right? You’re not trying to change it on the fly?

As long as you use that menu option, Amcap stops the graph and rebuilds
it. It’s hard to see how that wouldn’t work. What actually happens?
Does it issue an error, or do you just see a black image?

Do you have KSPIN_FLAG_PROCESS_IN_RUN_STATE_ONLY set?

Remember that, with YUY2, your driver has to be able to accept format
changes on the fly. When the graph starts to play, the renderer will
create an overlay surface, which has a width rounded up to some power of
two. It will send you a format change with the new width. You are
REQUIRED to accept this new width.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Dear Tim Roberts:
Thank you for your reply!

" You are using the Amcap “Video capture pin” menu option to change the
format, right? You’re not trying to change it on the fly? "
Yes, I use the AmCap"Video capture pin"menu option to change the format.
And my driver don’t support change video format on the fly, the microsoft
web camera driver also usbvideo.sys doesn’t support this.

“As long as you use that menu option, Amcap stops the graph and rebuilds
it. It’s hard to see how that wouldn’t work. What actually happens?
Does it issue an error, or do you just see a black image?”
When set data frame format as YUY2, I will see a black image somteimes.
And no error occurs during this period.

“Do you have KSPIN_FLAG_PROCESS_IN_RUN_STATE_ONLY set?”
Yes, I have set this flag. And I have clear other flag, but testing result is the
same.

I have two questions, please hlep me if have some good idea.

  1. My driver copys data to stream buffer and deletes clone stream pointer at
    complete routine with IRQL 2, does this has any question?

  2. My driver creates data frames with default interval 33.333ms, and amcap alway
    set interval as 71.2ms. However, the driver sets hardware with the default interval
    33.333ms, and copys video data to stream pointer buffer when it collects one video
    frame without using timer. Do you think this mechanism have any question?

zhou_5129327@163.com wrote:

" You are using the Amcap “Video capture pin” menu option to change the
format, right? You’re not trying to change it on the fly? "
Yes, I use the AmCap"Video capture pin"menu option to change the format.
And my driver don’t support change video format on the fly, the microsoft
web camera driver also usbvideo.sys doesn’t support this.

Right. Few video applications are prepared to handle this. I was just
making sure. :wink:

When set data frame format as YUY2, I will see a black image somteimes.
And no error occurs during this period.

When you see the black image, are you sure that you are sending frames?
That is, do you have enough trace messages in your driver to know that
you are doing the copies and deleting the clone pointers? The black
image often means that Amcap was not receiving any frames.

I have two questions, please hlep me if have some good idea.

  1. My driver copys data to stream buffer and deletes clone stream pointer at
    complete routine with IRQL 2, does this has any question?

That’s what I do in my USB capture drivers. The URB completion routine
copies the data and deletes the clone pointer.

  1. My driver creates data frames with default interval 33.333ms, and amcap alway
    set interval as 71.2ms. However, the driver sets hardware with the default interval
    33.333ms, and copys video data to stream pointer buffer when it collects one video
    frame without using timer. Do you think this mechanism have any question?

The sample code checks to see whether a clock has been provided. If one
has, it is used to set StreamHeader->PresentationTime. Are you saying
you NEVER set PresentationTime? Do you at least set it to 0? If you
don’t set PresentationTime, no one will be able to record your video to
disk. Preview will be OK, but not capture.

Amcap will not ask for 71.2ms unless you say in your KSDATARANGEs that
you support 71.2ms (14 FPS). If you can’t support that rate, you
shouldn’t offer it. Remember, when you see the Video Capture Pin
dialog, ksproxy creates that dialog from your KSDATARANGEs. The list of
formats, resolutions, and frame rates all came from your data
structure. When you bring up that dialog, what frame rates does it
offer? Does that match what you THINK you put in your KSDATARANGEs?

Does your capture driver support different frame rates? If so, you
should certainly make an effort to support what the client asks for.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Dear Tim Roberts:

I have supported data formats describled by hardware, including YUY2 and MJPEG’s different data frames. But amcap.exe always occurs black screen when I change format to YUY2. In fact, the data flow is OK, I can record this video frames by using AmCap’s “Start Capture” function. It seems
very diffcult to explain the reason?
At the same time, my driver can not support fame rate beyond 25 f/s (by using AmCap.exe), However, recording is OK too. This makes me very puzzled!

Dear Tim Roberts:

Thank you for your help!
Maybe I have found the root cause of the first problem. I try to work out this problem by setting an larger time interval of working timer when data frame changes, and during this period video data will be saved in a cycle buffer.

zhou_5129327@163.com wrote:

I have supported data formats describled by hardware, including YUY2 and MJPEG’s different data frames. But amcap.exe always occurs black screen when I change format to YUY2. In fact, the data flow is OK, I can record this video frames by using AmCap’s “Start Capture” function. It seems
very diffcult to explain the reason?

Are you handling the format change request that you get after streaming
starts? When you use a YUV surface on a system that supports YUV
overlays or textures, the standard renderers will send you a format
change request after streaming starts containing the actual stride of
the overlay surface. You MUST accept this change. You cannot fail it
– the renderers don’t even check the return code.

At the same time, my driver can not support fame rate beyond 25 f/s (by using AmCap.exe), However, recording is OK too. This makes me very puzzled!

I’m not sure what you mean here. Do you mean you are delivering faster
than 25 fps, but AmCap won’t display them? Or do you mean AmCap doesn’t
present the option to capture more than 25 fps? Are you putting
timestamps on your frames?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Dear Tim Roberts:

I have tested microsoft’s usbvideo driver. And find it does not support frame change after streaming has started. The amcap set default sample interval 33.3333ms firstly, and then set the
new sample interval according to selected frame rate. For example, if the selected frame rate is 15 fps , the amcap will request to set sample interval as 66.6666ms. Finally, the amcap tries to start the graph. And in my driver, it doesn’t get any frame format change request after streaming starts.

> At the same time, my driver can not support fame rate beyond 25 f/s (by
using AmCap.exe), However, recording is OK too. This makes me very puzzled!
>

I’m not sure what you mean here. Do you mean you are delivering faster
than 25 fps, but AmCap won’t display them? Or do you mean AmCap doesn’t
present the option to capture more than 25 fps? Are you putting
timestamps on your frames?

I mean that the AmCap can’t display video data continously when I select a new frame
rete beyond 25fps in one table PC(If the amcap’s half window is covered by other widows, amcap can work will with 30 fps.). Furthermore, it can only display video data continously with a frame rate below 17 fps if extenal power is unpluged.

Dear Tim Roberts:
Is KSPIN_DISPATCH’s SetDataFormat is the interface of format change request after after streaming starts? Is there any other interfaces for accepting format chang request?

zhou_5129327@163.com wrote:

I have tested microsoft’s usbvideo driver. And find it does not support frame change after streaming has started. The amcap set default sample interval 33.3333ms firstly, and then set the
new sample interval according to selected frame rate. For example, if the selected frame rate is 15 fps , the amcap will request to set sample interval as 66.6666ms. Finally, the amcap tries to start the graph. And in my driver, it doesn’t get any frame format change request after streaming starts.

OK, and what’s the problem? Are you accepting the change to 15fps, or
are you altering the request to match what you are able to deliver?

I mean that the AmCap can’t display video data continously when I select a new frame
rete beyond 25fps in one table PC(If the amcap’s half window is covered by other widows, amcap can work will with 30 fps.). Furthermore, it can only display video data continously with a frame rate below 17 fps if extenal power is unpluged

Depending on the size of the frames and the ability of your graphics
chip, that’s quite possible. Remember that the CPU clock gets reduced
when you go on battery power.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

zhou_5129327@163.com wrote:

Is KSPIN_DISPATCH’s SetDataFormat is the interface of format change request after after streaming starts? Is there any other interfaces for accepting format chang request?

Yes, SetDataFormat is the way you are told about format changes. In my
experience, the ONLY thing that is likely to change after streaming
starts is the width, to match the stride of the overlay or texture
surface that was assigned. I don’t think you will ever see frame rate
changes on the fly.

Are you supporting PROPSETID_VIDCAP_DROPPEDFRAMES? That’s required for
the tools to know how many frames were really transferred. It’s also
required for WHQL.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.