Feasibility of write a webcam driver for cheap webcam

@Tim_Roberts said:
I assume this conversation will be moved to the [ntdev] forum, where it belongs.

If you want to post the make and model, and even the numbers from the chips, we can look things up. However, since the sensor chips are usually hidden underneath a lens, you may not find numbers. Even cameras with AGC usually let you shut that off. Is that really not an option? Once you turn off AGC, it’s easy to do manual brightness/contrast in software.

The vast majority of modern cameras are USB Video Class compliant, where Microsoft provides the drivers. The camera advertises its capabilities, and usbvideo.sys does the rest. If the camera does not advertise “AGC disable”, then there’s no way for you to request it.

Hello Tom and thanks for your comments. Apologies for putting the post in the wrong place.

Makes and models - these cheap cameras come with many brandings that are independent of the make and model, but for the camera I am most interested in the drivers (as reported by Device Manager) are: Drivers: C:\WINDOWS\system32\drivers\ksthunk.sys, …/WdmCompanionFilter.sys, …/DRIVERS\UMDF\Secure\USBVideo.dll, and …/USBVideo.sys
The controller chip is: JL 9or maybe JC) AC20AP22748-13B4 - I can’t find that online.
When I connect this webcam to me software the exposure controls are greyed out, which I take to mean this is not offered by the controller.
In other models, the controls are not greyed out, and I cna move them - but they have no effect.

I don’t know if anything I’ve said helps you to help me more, but again - thanks fo royur help so far.

@“Peter_Viscarola_(OSR)” said:
Moved from the “A&A” category to NTDEV.

can you give me a feel for the level of effort required for someone with my background to get up and running with a driver

VERY significant. Assuming you’re an accomplished C Language programmer, unless you have kernel-mode programming experience (on any OS) or want to take a seminar to learn, your ramp-up time would be considerable… the actual amount of time depending on your background and how dedicated you are to the task. Then you can begin the process of trying to write the driver for the device you chose, and – assuming you don’t have somebody to mentor you – that becomes a long trial-and-error process on the order of months.

You can read some comments that I wrote on this topic a few years back.

Peter

Thanks Peter. “onsiderable”, huh? I program in C but I’m 61 and my thinking is mushing out as the years roll on. I’m thinking now, then, that I’m not up to it. I’ve tried to hire people from fiverr.com but so far - only idiots have applied.

@Tim_Roberts said:
Yes, but…

Assuming the camera is UVC, and essentially all web cams are, there’s simply no opportunity for you to do this kind of thing. There’s no way for you to “get around” the UVC interface to control the sensor at a low level. If the hardware designers did not make something controllable through the UVC interface, then it cannot be controlled. It’s as simple as that.

That hs to be true, of course. I guess this leaves trawling for a webcam that has a controller that allowsmanual control. Trouble is sellers don’t know what they’re selling very often. Asking them on EBay, for example, is futile. In fact, they’re busy trying to pass off VGA cameras as HD. Maybe I can take up basket weaving.

I can’t see a way to get notifications of updates to this thread. Is it possible?

I wonder if it’s possible to watch the exchange of data via the USB interface. Presumably, in that dialogue, the hardware announcees its capabilities to the host. Alternatively, a program that just interrogates any USB device and asked it to declare its capabilities?

It’s all in the descriptors. You can go look at the descriptors using the UVCView tool (derived from USBView). It will tell you which features of the feature units it supports. You’ll need to download the USB Video Class specification from usb.org.

I believe that’s manufactured by Shenzhen Jing Cheng Digital Surveillance Co in China. You have zero chance of getting any details about the chip. If you need to have specific features, then you need to find specific cameras. You might take a look at Videology.

@Tim_Roberts said:
I believe that’s manufactured by Shenzhen Jing Cheng Digital Surveillance Co in China. You have zero chance of getting any details about the chip. If you need to have specific features, then you need to find specific cameras. You might take a look at Videology.

Tim, you’v ebeen very helpful. I’m installing the SDK, and I’ll follow your other advice too. I appreciate your time and your advice - thanks.

Hmmm, USBView seems to tell me that the controller at least supports everything.
I guess the sensor chip to which it’s attached may not be able to implement all the features of the controller.
Either way, the drivers installed don’t allow manual exposure control.
By the way, those drivers seem to be the same for every webcam I’ve plugged in (ksthunk.sys, CompanionFilter.sys, USBVideo.dll, USBVideo.sys).
Given your earlier comments about the learning curve, it looks like I may have to bite the bullet and accept a 5x price hike and buy the boards which implement the features I need.

Thanks again folks, for your time.

      ===>Interface Descriptor<===

bLength: 0x09
bDescriptorType: 0x04
bInterfaceNumber: 0x00
bAlternateSetting: 0x00
bNumEndpoints: 0x01
bInterfaceClass: 0x0E → Video Interface Class
bInterfaceSubClass: 0x01 → Video Control Interface SubClass
bInterfaceProtocol: 0x00
iInterface: 0x06
English (United States) “USB CAMERA”

      ===>Class-Specific Video Control Interface Header Descriptor<===

bLength: 0x0D
bDescriptorType: 0x24
bDescriptorSubtype: 0x01
bcdVDC: 0x0100
wTotalLength: 0x0067 → Validated
dwClockFreq: 0x01C9C380 = (30000000) Hz
bInCollection: 0x01
baInterfaceNr[1]: 0x01
USB Video Class device: spec version 1.0

      ===>Video Control Input Terminal Descriptor<===

bLength: 0x12
bDescriptorType: 0x24
bDescriptorSubtype: 0x02
bTerminalID: 0x01
wTerminalType: 0x0201 = (ITT_CAMERA)
bAssocTerminal: 0x00
iTerminal: 0x00
===>Camera Input Terminal Data
wObjectiveFocalLengthMin: 0x0000
wObjectiveFocalLengthMax: 0x0000
wOcularFocalLength: 0x0000
bControlSize: 0x03
bmControls : 0xFF 0xFF 0x1F
D00 = 1 yes - Scanning Mode
D01 = 1 yes - Auto-Exposure Mode
D02 = 1 yes - Auto-Exposure Priority
D03 = 1 yes - Exposure Time (Absolute)
D04 = 1 yes - Exposure Time (Relative)
D05 = 1 yes - Focus (Absolute)
D06 = 1 yes - Focus (Relative)
D07 = 1 yes - Iris (Absolute)
D08 = 1 yes - Iris (Relative)
D09 = 1 yes - Zoom (Absolute)
D10 = 1 yes - Zoom (Relative)
D11 = 1 yes - PanTilt (Absolute)
D12 = 1 yes - PanTilt (Relative)
D13 = 1 yes - Roll (Absolute)
D14 = 1 yes - Roll (Relative)
D15 = 1 yes - Reserved
D16 = 1 yes - Reserved
D17 = 1 yes - Focus, Auto
D18 = 1 yes - Privacy
D19 = 1 yes - Focus, Simple
D20 = 1 yes - Window
D21 = 0 no - Region of Interest
D22 = 0 no - Reserved
D23 = 0 no - Reserved

      ===>Video Control Processing Unit Descriptor<===

bLength: 0x0B
bDescriptorType: 0x24
bDescriptorSubtype: 0x05
bUnitID: 0x02
bSourceID: 0x01
wMaxMultiplier: 0x0000
bControlSize: 0x02
bmControls : 0xFF 0xFF
D00 = 1 yes - Brightness
D01 = 1 yes - Contrast
D02 = 1 yes - Hue
D03 = 1 yes - Saturation
D04 = 1 yes - Sharpness
D05 = 1 yes - Gamma
D06 = 1 yes - White Balance Temperature
D07 = 1 yes - White Balance Component
D08 = 1 yes - Backlight Compensation
D09 = 1 yes - Gain
D10 = 1 yes - Power Line Frequency
D11 = 1 yes - Hue, Auto
D12 = 1 yes - White Balance Temperature, Auto
D13 = 1 yes - White Balance Component, Auto
D14 = 1 yes - Digital Multiplier
D15 = 1 yes - Digital Multiplier Limit
iProcessing : 0x00

Given that set, you ought to be able to turn off auto-exposure. If you bring up the camera properties in graphedt or amcap, do you not see a checkbox to turn off auto-exposure?

@Tim_Roberts said:
Given that set, you ought to be able to turn off auto-exposure. If you bring up the camera properties in graphedt or amcap, do you not see a checkbox to turn off auto-exposure?
Thanks again.
I don’t have Amcap and the download places I tried all look like the kind that will stiunk up my PC, wiht several layers of “download now” each one of which tries to dupe me into downloading something which isn’t Amcap.
I installed the SDK which is how I ran usbview of course, but I don’t have graphedt and it’s not where the doc says it is nor anywhere else I look.
I have several programs which use video capture but only one shows me the video input controls: “theremino spectrometer”.
That allows me to un-tick AUTO and the exposure number is then un-greyed out, but the slider won’t move.
I guess I really need one of those you mentioned. Do you know of a safe download link ofr Amcap?
Thanks.

@chrisxenon noeld.com/programs.asp?cat=video

https://docs.microsoft.com/en-us/windows/win32/directshow/amcap-sample

I’m not sure auto-exposure is really the targets. That controls the exposure time. I didn’t notice if the descriptors showed auto-brightness or not.

@Tim_Roberts said:
I’m not sure auto-exposure is really the targets. That controls the exposure time. I didn’t notice if the descriptors showed auto-brightness or not.

OK I got Amcap working and, like the usual program I use it shows the same thing. The exposure control is present. I can un-tick AUTO and move the slider, but the exposure is not changed. With my old cameras, exposure changes with the slider. So the USB interface advertises manual exposure, and the UI presents it, but it doesn’t work.

The reason I need manual exposure is that my application is a spectrometer where the image I want is high contrast and mostly dark. Auto-exposure tries to compensate, over-exposing my spectrum image, making it useless. Manual gain works, but even at zero, auto-exposure has saturated the spectrum.

I guess this is the end of the line?

Remember that “exposure” is just the exposure time, which for a digital camera isn’t terribly meaningful. If you turn off auto-exposure, do you have manual gain, brightness, and contrast? Do specific settings of those give you something you can work with? If your camera is incompetent, you can certainly compensate in software. As I mentioned before, gain, brightness and contrast are all very easy to implement in software.

@Tim_Roberts said:
Remember that “exposure” is just the exposure time, which for a digital camera isn’t terribly meaningful. If you turn off auto-exposure, do you have manual gain, brightness, and contrast? Do specific settings of those give you something you can work with? If your camera is incompetent, you can certainly compensate in software. As I mentioned before, gain, brightness and contrast are all very easy to implement in software.

As I understand it, the exposure time allows charge to accumulate on the sensor pixels, so a fast exposure would accumulate less charge and proivide a darker picture - or prevent a picture from saturating the sensor. Once the sensor has saturated nothing in the software can fix it, because all (or far too many) of the pixels are maxed out. Like it’s sending all pixels at brightness 255 to the software. No?

No settings give me a picture I can work with. In Theremino Spectrometer, I can un-tick EXP auto and the slider is no longer greyed out, but I can’t move it. (I though it did move before, but it doesn’t now, and either way it doesnt do anything).
In other software, I can move it but it doesn’t change the picture.

If I open the “Source panel” I get the WDM video input control Properties dialogue which I can also get from Amcap.
Here, the Brightness slider moves but doesn’t affect the preview. Same with gain, contrast, saturation, white balance, backlight comp. Hue won’t move.

If you have special requirements, pair a cheap modern camera with a cheap modern microcontroller and have it process the picture as you like.
Connect this thing to the PC by standard USB or Ethernet interface (the same microcontroller again) and that’s it.
Full control and 100% satisfaction.
If this sounds too complicated - many good folks around can offer affordable help.
(Sorry, cannot elaborate on the last phrase… it is against the rules of this forum. Google.)
– pa

@Pavel_A said:
If you have special requirements, pair a cheap modern camera with a cheap modern microcontroller and have it process the picture as you like.
Connect this thing to the PC by standard USB or Ethernet interface (the same microcontroller again) and that’s it.
Full control and 100% satisfaction.
If this sounds too complicated - many good folks around can offer affordable help.
(Sorry, cannot elaborate on the last phrase… it is against the rules of this forum. Google.)
– pa
THanks for oyur thoughts.
I can’t find where to buy camera modules like the OV2710 without IR filters glued ot the chip, and I don’t know how to remove them.
ESPCAM has this sensor (HD) and I have written a program which retrieves bitymaps - from where the rest is easy, but the IR filters, bonded to the sensor die itself - are a killer. I know they can be obtained becuase expensive camera board sellers offer alternatives wiht no IR.
I even rang the makers, but they will nt deal with anyone who wants less than thousands of these cameras.
I can buy chearp USB webcams, but these days none of them have manual expoure control from the USB cable, so that’s a killer.
It seems, from USB viewer, that the board does exposure the manual controls, but the driver does not provide access to them.
I have tried to get someone to write a Windows sriver, but that was not promising. So I came here tro explore writing my own.
I can buy expensive webcams which do, and I am currently thinking I’ll have to do that, and I have one coming from China.
But it smashes the profit margin on my product, which is why I’m looking for a better answer.

Anwyhooo - onward, ever onward.

Can you drop me an email? I have a suggestion.