Author Topic: WebCam Video  (Read 8762 times)

jj2007

  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #30 on: November 30, 2015, 10:10:56 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:
Code: [Select]
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
  .endif


There may be languages that don't have "video" in the name of that box, though.

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: WebCam Video
« Reply #31 on: November 30, 2015, 10:20:47 PM »
+/- Ten years ago we didn't had this problem with VFW.  :(

Jochen, is the DirectShow example working correct on your machine?

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: WebCam Video
« Reply #32 on: November 30, 2015, 10:56:34 PM »
Implemented Jochens solution without the "source dialog pop up" solution :


Hope this works on your computers......  :biggrin:

TWell

  • Member
  • ****
  • Posts: 748
Re: WebCam Video
« Reply #33 on: November 30, 2015, 11:23:11 PM »
Windows 7  :t
« Last Edit: December 01, 2015, 01:46:13 AM by TWell »

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: WebCam Video
« Reply #34 on: November 30, 2015, 11:44:30 PM »
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"

Code: [Select]
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 ?



jj2007

  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #35 on: December 01, 2015, 01:15:48 AM »
Is this the dialog that pops up ?

Yes, that's the one. Sorry, no time yet to test the DirectShow example...

PriNet

  • Regular Member
  • *
  • Posts: 11
  • Using: MASM32
Re: WebCam Video
« Reply #36 on: December 01, 2015, 10:47:12 PM »
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
There has GOT to be a harder way...

jj2007

  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #37 on: December 01, 2015, 11:15:55 PM »
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.

Farabi

  • Member
  • ****
  • Posts: 970
  • Neuroscience Fans
Re: WebCam Video
« Reply #38 on: December 02, 2015, 12:10:47 AM »
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.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: WebCam Video
« Reply #39 on: December 02, 2015, 01:42:49 AM »
Hi Jochen,

I have only 1 camera connected ( your example works OK )

Anybody else have tested the DirectShow example ?

Marinus

HSE

  • Member
  • ****
  • Posts: 532
  • <AMD>< 7-32>
Re: WebCam Video
« Reply #40 on: December 02, 2015, 03:37:54 AM »
Hi Marinus!

Work very well here with an old and cheap camera.

HSE

PD Windows 7 Ultimate Services Pack1
« Last Edit: December 02, 2015, 05:09:13 AM by HSE »

TWell

  • Member
  • ****
  • Posts: 748
Re: WebCam Video
« Reply #41 on: December 02, 2015, 05:05:02 AM »
DirectShow example don't show window.
Have to kill with task-manager:(
OS Windows 7 Home premium.

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: WebCam Video
« Reply #42 on: December 02, 2015, 07:48:00 AM »
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

TWell

  • Member
  • ****
  • Posts: 748
Re: WebCam Video
« Reply #43 on: December 02, 2015, 08:03:15 AM »
Now this

jj2007

  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #44 on: December 02, 2015, 08:14:59 AM »
« Last Edit: December 02, 2015, 09:46:53 AM by jj2007 »