"hutch"... go figure.... in my quest here, I have seen your name alot... now you can figure out who i is !....Anyway... I'm up upon an issue. I am writing a simple webcam procedure so i can access the camera on one of my computers in the shop so I can just "click the app" and it starts streaming the webcam to my main computer here. Ok, everything was going just fine, until, i tried using the following program on windows 7. No matter what I try, as soon as I start the program, win7 asks for a device in the "built in" video dialog that comes with (I know ancient) the vfw32 api. Unless someone can explain to me how to "set" the device i want (i can figure out which device I want by the "capGetDriverDescription") without the stupid "Video Source Dialog" popping up at initialization ? I have been doing (alot) of research and "almost" come to the conclusion I am going to have to convert to "DirectShow", but, alas, I find very little information on that for MASM(32)... Can anyone let me know how to set the video source I want (possibly how to access the drop down box so I can set it manually?) and get around this? -or- of course I would be happy if someone could point me to some information on how to switch over to "DirectShow" and accomplish the same basic thing I have done already? Again, the internet offers very little for MASM(32)... I am open to any input here, just trying to get rid of the annoying "Source Dialog" window when I can already figure out which one I want. Ok, I hope I explained what I'm after sorta clearish here, so here is the (working) code I promised if anyone else can use it (hopefully you'll put "PriNet" mention somewhere *heh*):
Oh yea, don't bash me too hard on this program... it's my first assembly program since 1980 on an Altair 8086.... *heh*
Hi Gary,
You seem to know more about video than I do as multi-media is not really my area but we do have some members who have experience in this area so they may be able to help you. What you will need is a decent grasp of how MASM works and this will take some practice as you have to master both Intel mnemonics and notation as well as the Windows API function set. Also keep in mind that much of modern graphics is done with libraries that are specific to certain types of video cards so there may not be a lot of processing done at the x86 level.
All of my notes was at home, I think I can help you. Somehow Im experimenting on a local wifi server using XAMPP and android. I used Windows 8.1 as the server. I tried using android, but its too small, and it was difficult using Java and OOP, you know, I had some alergic with OOP, each time I saw it, I cant think, I cant remember and I cant learn, not even using google, and each time I saw my manager, sudenly Im afraid and I have to get out of the office :greensml:
Seriously, once Im experimenting for the local wifi server for the video communication, but you know, I wont using it. If I were younger, I might using it, I`ve forgeting how to use photoshop. :greensml:
I think if you remind me, on january I'll provide the source.
Thanx for getting back to me so soon guys... I hope I can be helped (beyond a psychologist anyway). And it's too funny cause all of a sudden I'm seeing names & faces of people I recognize from the internet in my little quest here. Thanx again guys, hope to share what I can with all of ya.
-G
Hi Gary,
I have a webcam example in DirectShow for you.
I'll post it when I'm at home.
Marinus
Yup, I should have signed up here 2 weeks ago !
Hi Gary,
This is a DirectShow Direct3D9 WebCam example.
It enumerates all webcams and screen resolutions. ( also HD resolutions )
I made this for my Car Computer to have a front and back camera.
The reason I made it for Direct3D9 is that I can write other stuff on the Camera Screen. ( gps speed rpm gear etc. )
Press F1 to toggle Full Screen.
You can start this example also in Full Screen mode if you want. ( line 1035 D3D9_WebCam.Asm )
omg.... *lol*.... that's considerably more complicated !.... ok, let me spend a few days digesting this one....which compiler did you use? I don't recognize the "rap" file ? Thanx "Siekmanski", I appreciate it ! -and- I may be busy trying to understand this one... I really prefer comprehending code rather than copy/paste. And I promise to get your "credit where credit due" in there somewhere *heh* Thanx again.
-G
The "rap" file is the project file of the RadASM programming environment.
I used the Masm assembler and linker from Visual Studio 2013 to build this project.
It may look a bit complicated, but that's because Direct3D9 is used in this example.
You can strip that part if you like.
The camera writes it's data to a memory buffer which you can read and copy to your own screen buffer.
So, you don't need Direct3D9.
Look at the "Update_frame" proc how to fetch the webcam data from the buffer.
coinvoke g_pSampleGrabber,ISampleGrabber,GetCurrentBuffer,addr Video_buffer_size,pVideo_buffer
Well, I'm still digesting this one seikmanski... This is going to take some study, but, thanx muchly, this is going to help I believe, alot.... (of course it would have been easier if the old-school vfw worked...*lol*). I may be gone for awhile researchin'.... but I'll be back with results.... it looked like my vfw example was kinda popular, I'll need to post what I learn from this !
-G
Hate to bother you again siekmanski, but i have been stepping through your code for a few hours now and was starting to transpose it to masm. I can find no reference in masm for a "coinvoke" other than a defined macro. Is this something else specific to radasm? can i port this to "invoke" in masm or is this something different that radasm uses ? i couldn't find any "macro" in your code to define this "coinvoke", if this is just a compiler difference i'll (of course) use masm's "invoke" and then continue with the de-ciphering. Like i say, i like to understand code... copy/paste doesn't teach anyone anything...*lol*
DirectShow uses COM.
Coinvoke is a macro for the interfaces used in the Component Object Model. ( COM )
You can find the macro in Includes/dx9macros.inc
All the source code is written in MASM syntax.
I only use RadASM as my programming editor, you can use your own with these MASM-sources.
Quote from: PriNet on November 29, 2015, 06:54:07 PMLike i say, i like to understand code... copy/paste doesn't teach anyone anything...*lol*
Gary,
COM is powerful, you can tap lots of interesting stuff, but prepare for a steep learning curve. Few people here can master COM, I have dabbled a bit but nope, I don't master it after ten years of x86 coding. More on this. (http://masm32.com/board/index.php?topic=2661.msg28374#msg28374)
Here is a simple example by Vortex. (http://www.masmforum.com/board/index.php?topic=15797.0)
So much for my simple little program... *heh*... but? i'm game, guess i have alot of research ahead of me. When you quit learning, it's time to buy a plot... Thanx for everyone's direction, i'm off to learn cambodian :)
Hi Gary,
Just read your first post again.
As far as I understand the thing is, when you start your app the the source dialog pops up and you don't want this to happen?
Do you have multiple camera's connected to your computer?
Do you want to make a choice which camera to use when you start your app without using the source dialog ?
If so, that can also be done the "old way" with the vfw32 api.
edit: try this example first and than if you like, we can write it the way you want. (i'll have to do some Dutch -> English translations then)
Ha! Marinus was faster, it seems. But just for comparison, I attach mine - pure VfW :biggrin:
Hi Jochen,
Mine is much smaller ( that sounds a little weird... :biggrin: ) and also vfw. :t
BTW I got a black screen with your example.
Quote from: Siekmanski on November 30, 2015, 06:05:42 AM
Hi Jochen,
Mine is much smaller ( that sounds a little weird... :biggrin: ) and also vfw. :t
BTW I got a black screen with your example.
Now that's lovely: for me it's the other way round... a black screen with your example. I am on Win7-64, and you?
Version 2 attached, with source (asc=rtf).
I'm on win 8.1 64bit
That's weird, now I got a pink screen with your second example.
Can you select a camera ( combobox ) in my example?
Yes, there is one. Check my source, there is a strange loop that you should try to add. It's a known problem that user needs several attempts to connect.
Btw my code just chooses device 0. Should work in principle...
Here is the source code of the vfw example.
Mine also selects device 0 at startup.
Think I had the preview rate wrong.
No, that's not the problem. Your prog presents me with the infamous video source dialog. When clicking OK or Cancel repeatedly (2...5 times), eventually it will work. That is why I inserted that loop into my code.
Now one interesting question is why my prog won't work on your puter...
P.S.: It won't work on Win 8.1, either. Or rather: once after reboot.
Attached a version that started working on 8.1 after a minor modification.
Just in case anybody else is following this thread: FEEDBACK WELCOME!!! XP somebody? Win 10?
Hey again Marinus !
I'm glad your following me, I'm STILL working on figuring out the DirectShow approach, I think it could "broaden my horizons" ! Sounds like you can do alot with "COM". To answer your most recent questions:
Yes, when I (first) start my program, the source dialog pops up. That's what started this big adventure. I wanted to be able to (using the description) decide "which" source I want to attach to programmaticly, not through the source dialog.
Yes, I have more than 1(one) source on several of my computers here... TV cards, Video Capture (8-cam security system, which I want to be able to incorporate eventually also), sometimes a couple cameras, etc. This is why I was looking for a way to "set" the source programmaticly so I can just use an identifier (eventually) on the command line "which" source to use (but that's after I get things "working" *heh*).
And, yup, I'm trying to find a way to "choose" which camera/source to use without the dialog popping up.
Now, after all that... *lol*... let me look at what you sent and see what it looks like. oh, yea, thanks so much for your help and guidance, and hutch? thanx for the board here, I've learned a lot more in a week or so here than I have "surfing" the internet on my own for "several" weeks.
Quote from: jj2007 on November 30, 2015, 08:35:34 AMP.S.: It won't work on Win 8.1, either. Or rather: once after reboot.
@Marinus: Does your prog work repeatedly? A common problem seems to be that WM_CAP_DRIVER_CONNECT works only once after a reboot - and no real solution on the World Wide Web. Actually, I spent quite a bit of time rebooting :(
ok, what you just sent is actually the one i studied so hard to get the "remote" program i originally posted above. I already used dictionary.com to translate alot of what i couldn't decipher on my own *lol*. It's a VERY good guide (if you can read ?dutch?) but alas, it does the same thing i'm having trouble with, it pops up the source dialog the same as mine when you first start the program. Did you say you knew a way to "assign" a source device programmaticly and stop that from popping up? THAT'S where i'm having the trouble. (i'm not abandoning the com research though, sounds intriguing)
Quote from: jj2007 on November 30, 2015, 08:35:34 AM
...
Just in case anybody else is following this thread: FEEDBACK WELCOME!!! XP somebody? Win 10?
Unfortunately I don't have web cam . The subject of the thread looks interesting though
Quote from: jj2007 on November 30, 2015, 10:34:15 AM
Quote from: jj2007 on November 30, 2015, 08:35:34 AMP.S.: It won't work on Win 8.1, either. Or rather: once after reboot.
@Marinus: Does your prog work repeatedly? A common problem seems to be that WM_CAP_DRIVER_CONNECT works only once after a reboot - and no real solution on the World Wide Web. Actually, I spent quite a bit of time rebooting :(
Yes it works here repeatedly, the source dialog never pops up. Not on my 8.1 or my XP computers nor on my wifes W7 laptop.
Now, this is really strange and a behaviour I have never heard of.
How are we gonna fix this?
Quote from: PriNet on November 30, 2015, 04:58:08 PM
Did you say you knew a way to "assign" a source device programmaticly and stop that from popping up? THAT'S where i'm having the trouble.
I intended to just skip the camera selection and fill in the device number of the camera you want to use, but that will not solve the "source pop up" bug.
Is the DirectShow example working on all your computers?
Maybe we should focus our attention on DirectShow and leave VFW for what it is?
DirectShow is more flexible but requires more programming......
Hi guys,
I've found something for you
Selecting a particular webcam (https://social.msdn.microsoft.com/Forums/vstudio/en-US/c4fd12d8-2870-47ed-8f2e-3dc613afeb6f/selecting-a-particular-webcam)
The good sign is that the thread is from Visual Basic forum ;)
Pay attention to this:
Randy Hemingway
Quote
You can send a windows message to the video device handler that will activate a Video Source dialog that typically allows you to select which of the multiple cameras being serviced by the handler to use. The message ID is: WM_CAP_DLG_VIDEOSOURCE. The problem with this approach is that it requires user interaction, for example, you can't program the application to always select the second webcam. If you don't mind a user dialog solution, the WM_CAP_DLG_VIDEOSOURCE approach should work fine.
Ricky Luk
Quote
The code provided above has references to functions like Getstring that wasnt included, but after I simplied the code it is a matter of
RegOpenKey HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM", lngKey
RegSetValueEx lngKey, "DevicePath", 0, 1, ByVal Strdata, Len(Strdata)
RegCloseKey lngKey
capCreateCaptureWindow("CaptureWindow", WS_CHILD Or WS_VISIBLE, 0, 0, 0, 0, Picture4.hwnd, 0)
Then repeat 1-4 but this time write the second devicepath to registry and then kick the second camera.
PS. Remember not to put "SendMessage hCapWin2, WM_CAP_DLG_VIDEOSOURCE, 0, 0" so the video source window wont pop up.
And finally what seems to be the most valueable post :
Christopher MCSE
Quote
Hi guys,
i recently bought 7 cheap web cams ambitiously thinking i could easily write an application to monitor all 7 symultaneously. oh i love learning things the hard way.
Anyway, The application ive written so far cant monitor all 7 at once, but it can switch cameras automatically without user interaction. it uses the avicap32.dll. I dont know if it will be any use to anyone but heres how i did it.
I discovered that when the user chose the camera source from the dialog that appears, it would write the path to the device in the registry, in the key HKLM\System\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM to a string called DevicePath.
So when the user launches the program for the first time, the program asks the user if they want to add a camera and goes into a loop until the answer is no.
in the loop:
the string DevicePath is deleted from the above mentioned key
the program then tells the driver to "connect", since avicap doesnt know which device to connect to it throws a dialog to the user asking which device to connect to.
when the user choses the device, the driver connects and displays a preview
the program then looks at the DevicePath string in the above mentioned key and saves the value to the program settings
my.settings.cameras.add(
My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM", "DevicePath", Nothing))
when the user clicks No, they dont want to add any more cameras the program should now have an array of device paths for each camera attached.
now when the user clicks the button to start to capture, the program iterates through the array, chosing the next device in the array, it sets the value of DevicePath to the value of the selected element in the array, it tells the driver to connect and send the output to a picturebox for preview, then tells the driver to take a snapshop, saves the snapshot to disk, tells the driver to disconnect, and then deletes the value of DevicePath and the loop starts again.
this works, but isnt ideal. Ive found that each cycle for each camera takes about 2.5 to 3 seconds for the driver to connect, take snapshot, then disconnect. this means that if ive got 7 cameras attached it takes the program about 20 seconds to take snapshots from all 7 cameras.
anyway, it works for now. im actually trying to achieve a capture rate of at least 4 shots per second per camera, symultaneously.
ive got no idea if its possible using avicap32.dll but heres my theory (in case you were interested).
when then program tells the driver to connect, it reads the device path from the above mentioned registry key. the driver should only need to do this when it connects.
so I figure i can iterate through the device array, set the devicepath value in the registry, tell the driver to connect and send output to a new instance of the picturebox, then iterate to the next device, set the device path value in the registry, and tell the driver to connect and send output to a new instance of picturebox.
that way we get all cameras connected at the start of the program and dont have to worry about disconnecting the camera, switching the camera, reconnecting, etc..
no idea if this will work, im going to give it a try.
HTH
P.S.: You may try SysInternals Process Monitor to see if VFW reads / writes certain registry keys
P.P.S.:
Tmax97's source code looks promising :t
Hi gonefishing,
Quotethe program then tells the driver to "connect", since avicap doesnt know which device to connect to it throws a dialog to the user asking which device to connect to.
We give the device number so avicap knows which device to connect:
invoke SendMessage,hCaptureWnd,WM_CAP_DRIVER_CONNECT,camera_devicenumber,0
This is where the source dialog pops up. ( or is it at: capCreateCaptureWindow ? )
He takes snapshots, we want full-rate movies.
Even at the Windows Development Center they can't give us a solution...
https://social.msdn.microsoft.com/Forums/windows/en-US/858192dd-fbc9-4ea1-91fc-9f2d8286b4f7/webcam-access-in-c-using-system-calls-only-works-once-per-restart?forum=winformsdatacontrols
Quote from: Siekmanski on November 30, 2015, 09:59:24 PM
We give the device number so avicap knows which device to connect:
invoke SendMessage,hCaptureWnd,WM_CAP_DRIVER_CONNECT,camera_devicenumber,0
This is where the source dialog pops up.
He takes snapshots, we want full-rate movies.
Even at the Windows Development Center they can't give us a solution...
https://social.msdn.microsoft.com/Forums/windows/en-US/858192dd-fbc9-4ea1-91fc-9f2d8286b4f7/webcam-access-in-c-using-system-calls-only-works-once-per-restart?forum=winformsdatacontrols
Here is my solution:
push 9
.Repeat
invoke SendMessage, hCapWin, WM_CAP_DRIVER_CONNECT, 0, 0
deb 4, "Connect", eax
dec stack
.Until Sign? || eax
pop ecx
mov isConnected, eax
I've lost a lot of time in the reboot loop until I found somewhere the advice "try again until it connects". And it works.
Getting rid of the popup box:
mov hFGW, rv(GetForegroundWindow)
.if Instr_(Win$(eax), "video", 1)
invoke ShowWindow, hFGW, SW_HIDE
invoke SendMessage, hFGW, WM_CLOSE, 0, 0
Delay 127
.endifThere may be languages that don't have "video" in the name of that box, though.
+/- Ten years ago we didn't had this problem with VFW. :(
Jochen, is the DirectShow example working correct on your machine?
Implemented Jochens solution without the "source dialog pop up" solution :
Hope this works on your computers...... :biggrin:
Windows 7 :t
Thanks Tim.
Because I don't have the "source dialog pop up bug", and I don't know where it pops up.
The solution to prevent this may have to be implemented somewhere else in the source code.
I have placed it in the "GetCamera proc"
GetCamera proc camera_dev:DWORD
LOCAL counter:dword
LOCAL FGhwnd:dword
mov counter,100
connectLP:
invoke SendMessage,hCaptureWnd,WM_CAP_DRIVER_CONNECT,camera_dev,0
cmp eax,TRUE
je connect_Ok
dec counter
jnz connectLP
invoke MessageBox,hWnd,TEXT_("Can not connect the camera !"),TEXT_("Error"),MB_OK OR MB_ICONERROR
mov eax,FALSE
ret
connect_Ok:
invoke SendMessage,hCaptureWnd,WM_CAP_DRIVER_GET_CAPS,sizeof CaptureCaps,addr CaptureCaps
invoke SendMessage,hCaptureWnd,WM_CAP_SET_SCALE,TRUE,0
invoke SendMessage,hCaptureWnd,WM_CAP_SET_PREVIEWRATE,1000/30,0
invoke SendMessage,hCaptureWnd,WM_CAP_SET_PREVIEW,TRUE,0
invoke SendMessage,hCaptureWnd,WM_CAP_SET_OVERLAY,TRUE,0
invoke GetForegroundWindow
mov FGhwnd,eax
invoke GetWindowText,eax,addr szString_buffer,128
; invoke lstrcmp,addr szString_buffer,TEXT_("Videobron")
invoke lstrcmp,addr szString_buffer,TEXT_("video")
test eax,eax
jnz compare_done
; invoke MessageBox,hWnd,addr szString_buffer,TEXT_("Window check"),MB_OK
invoke ShowWindow,FGhwnd,SW_HIDE
invoke SendMessage,FGhwnd,WM_CLOSE,0,0
compare_done:
mov eax,TRUE
ret
GetCamera endp
Is this the dialog that pops up ?
(http://members.home.nl/siekmanski/Image1.jpg)
Quote from: Siekmanski on November 30, 2015, 11:44:30 PMIs this the dialog that pops up ?
Yes, that's the one. Sorry, no time yet to test the DirectShow example...
Darn, (go figure) I have to work some pretty long hours these next couple days. I'm anxious to get back and see what has transpired here, looks like I need to try some new examples y'all are providing. I'm the words of Arnold, "I'll be back"...
Thankx for everyone's input here.
Oh... btw; I'm on win7-64 if that gives any insight on the popup window issue...
-G
Direct Show on Win7-64:
IMediaControl.Run niet OK ::)
Then "Misc routines error", and that's it... and afterwards the camera is blocked, both with my own app (attached) and the official Acer Crystal Eye that always worked fine until now :(
So I will reboot now ;-)
P.S.: Could somebody with more than one camera installed please test if the combobox works in my attached example? Thanks.
I had no idea why MS make this problem to appear. I kinda worried about what harm can be done if I answered this. I had no idea, but my OS multiple time having problem. We better not answer kindly about this.
Hi Jochen,
I have only 1 camera connected ( your example works OK )
Anybody else have tested the DirectShow example ?
Marinus
Hi Marinus!
Work very well here with an old and cheap camera.
HSE
PD Windows 7 Ultimate Services Pack1
DirectShow example don't show window.
Have to kill with task-manager:(
OS Windows 7 Home premium.
Thanks guys for testing.
@Tim and @Jochen,
I have added a NullRenderer filter to the render chain.
Hope this solves the problem of the DirectShow example from not showing the render screen.
Marinus
Now this
Made some changes to the renderstream proc.....
Renderstream niet OK...
Attached my latest version, including a nice settings dialog.
Your app works perfect here on my computer. :t
"Renderstream niet OK..." :(
It can drive you mad when it runs ok on one system and doesn't on another........ :icon_confused:
Quote from: Siekmanski on December 02, 2015, 10:35:57 AMIt can drive you mad when it runs ok on one system and doesn't on another........ :icon_confused:
I know. I am maintaining a library that is supposed to work with Masm 6.15 ... 10.0 and JWasm and AsmC :P
Did you know that ML 6.15
occasionally but not
reproducibly has problems with things like
@CatStr(<h>, <cName>, < equ DWORD PTR gcTable.gcHandle[guiCt*gcDATA]>) ; bloody hell!
if (and only if) there is a comment behind it? :eusa_boohoo:
no reason to complain jj - with such usage of EQU you are already in the land of undefined behavior. (because without angle brackets a constant (numeric) expression is expected)
I hope I haven't missed too much here, I'm finally finished at work and back to see what has developed. What has transpired? Which app does someone want me to check on this machine? It looks like there have been several different options to try. Please let me know how I can help now that I'm done with work (till next week anyway *heh*). I appreciate everyone's input, hope to hear back on what y'all want me to test on this machine.
-G
Quote from: PriNet on December 04, 2015, 06:46:32 AMWhich app does someone want me to check on this machine?
That's easy to find, Gary, just start in page 1 of your thread, press Ctrl F, type
.zip and hit F3 repeatedly. You can ignore the fake zips, i.e. attached images whose endings have been changed to .zip to fool the forum software - a bad habit btw because it costs server bandwidth.
It seems that certain WebCams give back wrong format settings after enumeration. ( 0 bits, width 0, height 4 )
This was the reason why the program hung with some webcams.
TWell found this problem with a webcam he used. ( Thanks Tim :t)
I borrowed a webcam and this one had the same issue so, I could now write code to skip those wrong format settings.
Added a WebCam Settings Dialog. Press F2
Hope this version will work now for all WebCams.
Let me know, then I'll clean up the source code and post it.
It works :t
It works here too with a Microsoft LifeCam VX-3000.
Biterider
Thanks guys. :biggrin:
It handles multiple Webcams and all bitmap resolutions and bitformats ( incl. HD res. ) the Webcam can produce.
Works perfectly :t
HI,
Works here with Windows XP and a Gigaware "Webcam with
Retractable Cable". FPS reports a faster frame rate than the
maximum FPS. (Nice?) Shows support for more than one
screen format. Full screen looks good. Nicely done.
Regards,
Steve N.
Came here searching for a solution for the "WM_CAP_DRIVER_CONNECT" and "Video Setup" dialog popup Error.
FOUND the solution:
It's a driver problem. Use the OEM's driver, because the Generic Microsoft Drivers are NOT working for your camera.
Use www.astra32.com to find out the USB camera's device info: Manufacturer or Model; then google for the correct drivers.
Good Luck!
P.S. for robots:
"SOLVED" "WM_CAP_DRIVER_CONNECT" "Video Setup"