The idea here is a "web" cam server that streams frames as JPEGs to a non-Web client, using AVICap32.dll but without screwing up the system Clipboard. A webcam HTTP server has also been added (later in this thread).
Caveats
To begin with it seems that in modern versions of Windows AVICap32.dll must work with a WDM/VFW "adapter" driver. On such systems even if you had 12 webcams plugged in they all appear a Device 0. So here we're defaulting to Dev 0 instead of enumerating them and giving the user a choice.
If there are multiple cameras, when the RemCam server starts you may see the system pop up a dialog and ask you which one to use. I've had no luck at all with this myself, and it seems to be a common problem. The workaround I've seen involves reading and writing to some HKLM key, which requires admin rights so I don't consider it a viable solution.
And so far I haven't gotten this to work on any Win7 system (though the only one I have handy has two built-in cams). I also had it fail on a 64-bit Vista system, though that might be related to drivers or something.
Successes
I've had good luck though using a 32-bit Vista system with a single USB cam plugged in. I also had good luck using a 32-bit XP system with one USB cam plugged in (different cam).
Requirements
As far as I can tell this may well work on any system from Windows XP SP1 on up if you can get past the WDM camera issues. This may simply be a matter of proper drivers, though I'd be unsurprised to find there are Win7 issues and 64-bit issues that cannot be overcome.
On XP systems you need to ensure that you have WIA 2.0 installed. XP SP3 may include this now, I haven't verified this. You can download the SDK which contains the required DLL from Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting.
This must be manually installed: open WIAAutSDK.zip and see the instructions in the readme file.
Also, when creating deployment packages on a system after WinXP be sure that you package the version of this DLL you take from WIAAutSDK.zip and not the one from your running system!
Some Details
Capture w/o Clipboard
This is done here using a frame callback from AVICap32.dll.
TCP Message Framing
The individual JPEGs are sent as a 4-byte Long (length of the following data), and then a JPEG image file's bytes. Note that the techniques used here do not require writing the JPEGs to disk files as an intermediate step though!
Building the Programs
On a system that has WIA 2.0 present and working, just open and Make the two Projects:
Running RemCam
Install RemCam.exe and a USB webcam on each camera source system. Though technically this is a "server" note that it has not been designed as a true Windows Service.
You'll also want to allow RemCam through any software and hardware firewalls in place. The default TCP port is 8765.
Run RemCam.exe, enter the desired service port # (8765 is prefilled in the Textbox), click on the Start button. Soon it should display a small preview window and it should be online for a single client at this point.
Running MultiClient
Install MultiClient.exe and then run it. Since it establishes only outgoing TCP connections your firewalls probably won't require configuration.
When it comes up, for each active RemCam server you can enter the remote host name or IP address and port number, then click the Connect button. If all goes well, Connect becomes Disconnect and the preview pane should begin showing the stream from that RemCam instance.
Clicking on a camera preview pane "selects" it and the larger camera view pane will begin showing the camera's stream at full speed.
Notes
If you are connected to multiple RemCam servers (up to 4 in this version) you can click the the previews to switch views to the large view pane.
Preview panes "drop" every few frames intentionally to improve performance.
Streaming video by sending JPEG images over a TCP connection isn't the best way to do streaming video. But it's simple and cheap to do and may suffice for many purposes, though it might not be too practical over a slow network.
The RemCam server (as written) requires that your camera support 320x240 capture. If your cameras are different you may need to adjust the code, or even add some option selection capability to RemCam's UI.
I'm working on an important optimization in MultiClient, so I expect to be reposting the attachment soon.
Conclusion
Aside from the limitations of this approach, where it works it seems to work fairly well. I'm not saying the code is bug-free, but at least it is a small amount of code so over time we'll probably get things ironed out.
If anyone has any more info to share on some of the gotchas I've described above, or better yet some fixes or workarounds... I'd love to hear them.
I'm not claiming I'm doing anything truly unique here, but I thought it might be worth sharing. Most similar code I've seen uses the clipboard.
Caveats
To begin with it seems that in modern versions of Windows AVICap32.dll must work with a WDM/VFW "adapter" driver. On such systems even if you had 12 webcams plugged in they all appear a Device 0. So here we're defaulting to Dev 0 instead of enumerating them and giving the user a choice.
If there are multiple cameras, when the RemCam server starts you may see the system pop up a dialog and ask you which one to use. I've had no luck at all with this myself, and it seems to be a common problem. The workaround I've seen involves reading and writing to some HKLM key, which requires admin rights so I don't consider it a viable solution.
And so far I haven't gotten this to work on any Win7 system (though the only one I have handy has two built-in cams). I also had it fail on a 64-bit Vista system, though that might be related to drivers or something.
Successes
I've had good luck though using a 32-bit Vista system with a single USB cam plugged in. I also had good luck using a 32-bit XP system with one USB cam plugged in (different cam).
Requirements
As far as I can tell this may well work on any system from Windows XP SP1 on up if you can get past the WDM camera issues. This may simply be a matter of proper drivers, though I'd be unsurprised to find there are Win7 issues and 64-bit issues that cannot be overcome.
On XP systems you need to ensure that you have WIA 2.0 installed. XP SP3 may include this now, I haven't verified this. You can download the SDK which contains the required DLL from Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting.
This must be manually installed: open WIAAutSDK.zip and see the instructions in the readme file.
Also, when creating deployment packages on a system after WinXP be sure that you package the version of this DLL you take from WIAAutSDK.zip and not the one from your running system!
Some Details
Capture w/o Clipboard
This is done here using a frame callback from AVICap32.dll.
TCP Message Framing
The individual JPEGs are sent as a 4-byte Long (length of the following data), and then a JPEG image file's bytes. Note that the techniques used here do not require writing the JPEGs to disk files as an intermediate step though!
Building the Programs
On a system that has WIA 2.0 present and working, just open and Make the two Projects:
- RemCam - the server.
- MulitClient - the client.
Running RemCam
Install RemCam.exe and a USB webcam on each camera source system. Though technically this is a "server" note that it has not been designed as a true Windows Service.
You'll also want to allow RemCam through any software and hardware firewalls in place. The default TCP port is 8765.
Run RemCam.exe, enter the desired service port # (8765 is prefilled in the Textbox), click on the Start button. Soon it should display a small preview window and it should be online for a single client at this point.
Running MultiClient
Install MultiClient.exe and then run it. Since it establishes only outgoing TCP connections your firewalls probably won't require configuration.
When it comes up, for each active RemCam server you can enter the remote host name or IP address and port number, then click the Connect button. If all goes well, Connect becomes Disconnect and the preview pane should begin showing the stream from that RemCam instance.
Clicking on a camera preview pane "selects" it and the larger camera view pane will begin showing the camera's stream at full speed.
Notes
If you are connected to multiple RemCam servers (up to 4 in this version) you can click the the previews to switch views to the large view pane.
Preview panes "drop" every few frames intentionally to improve performance.
Streaming video by sending JPEG images over a TCP connection isn't the best way to do streaming video. But it's simple and cheap to do and may suffice for many purposes, though it might not be too practical over a slow network.
The RemCam server (as written) requires that your camera support 320x240 capture. If your cameras are different you may need to adjust the code, or even add some option selection capability to RemCam's UI.
I'm working on an important optimization in MultiClient, so I expect to be reposting the attachment soon.
Conclusion
Aside from the limitations of this approach, where it works it seems to work fairly well. I'm not saying the code is bug-free, but at least it is a small amount of code so over time we'll probably get things ironed out.
If anyone has any more info to share on some of the gotchas I've described above, or better yet some fixes or workarounds... I'd love to hear them.
I'm not claiming I'm doing anything truly unique here, but I thought it might be worth sharing. Most similar code I've seen uses the clipboard.