Why dows my window get stuck when using #WM_CAP_EDIT_COPY ?

Just starting out? Need help? Post your questions and find answers here.
AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Why dows my window get stuck when using #WM_CAP_EDIT_COPY ?

Post by AndyMK »

You will need a webcam or a capture card to run this. Wen i run it, the window seems busy and wont move or respond to the mouse. Ive managed to pin it down to #WM_CAP_EDIT_COPY which seems take control from the window. If i call #WM_CAP_EDIT_COPY every 100ms or higher, the window is ok but the final update is slow (10fps@100ms) Is this something to do with overlay mode? I need to use overlay as using preview stops the image update when the preview video is covered by another application. Overlay is on the left and jpeg stream on the right.

Code: Select all

InitSprite()
UseJPEGImageEncoder()
UseJPEGImageDecoder()

#WM_CAP_START = #WM_USER 
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10 
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11 
#WM_CAP_DRIVER_GET_CAPS = #WM_CAP_START + 14
#WM_CAP_EDIT_COPY = #WM_CAP_START + 30
#WM_CAP_DLG_VIDEOFORMAT = #WM_CAP_START + 41 
#WM_CAP_DLG_VIDEOSOURCE = #WM_CAP_START + 42 
#WM_CAP_DLG_VIDEODISPLAY = #WM_CAP_START + 43 
#WM_CAP_GET_VIDEOFORMAT = #WM_CAP_START + 44 
#WM_CAP_SET_VIDEOFORMAT = #WM_CAP_START + 45 
#WM_CAP_DLG_VIDEOCOMPRESSION = #WM_CAP_START + 46  
#WM_CAP_SET_OVERLAY = #WM_CAP_START + 51
#WM_CAP_GRAB_FRAME_NOSTOP = #WM_CAP_START + 61 
#WM_CAP_STOP = #WM_CAP_START + 68 

  OpenWindow(0, 0, 0, 700, 270, "Server Preview", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
  SetWindowColor(0,RGB($00,$00,$00))
  OpenWindowedScreen(WindowID(0),365,15,685,255,0,0,0)
  If OpenLibrary(0, "avicap32.dll") 
    *capAddress = GetFunction(0, "capCreateCaptureWindowA") 
    hWndC.l = CallFunctionFast(*capAddress, "My Capture Window",#WS_CHILD | #WS_VISIBLE , 15, 15, 320, 240, WindowID(0),0) 
    SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0) 
    SendMessage_(hWndC, #WM_CAP_SET_OVERLAY, #True, 0) 
  EndIf 

Repeat
  event=WaitWindowEvent(1)
  SendMessage_(hWndC, #WM_CAP_EDIT_COPY, 0, 0)
  img = GetClipboardImage(#PB_Any)
  If img
  SaveImage(img,"c:\1.jpg",#PB_ImagePlugin_JPEG,5)
  FreeImage(img)
  Sprite = LoadSprite(#PB_Any, "c:\1.jpg"); 
  DisplaySprite(Sprite,0,0)
  FreeSprite(sprite)
  EndIf
  FlipBuffers()
Until event=#PB_Event_CloseWindow
*EDIT*
If i hide the overlay window by removing "#WS_VISIBLE", it seems to work ok but i only get the resultant jpeg and not the overlay itself so it would seem, using overlay is the problem and not #WM_CAP_EDIT_COPY... my knowledge is too limited :( and it is so frustrating :evil:
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post by Jan Vooijs »

This is the result of the dutch jury:

Code: Select all

InitSprite()
UseJPEGImageEncoder()
UseJPEGImageDecoder()

#WM_CAP_START = #WM_USER
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11
#WM_CAP_DRIVER_GET_CAPS = #WM_CAP_START + 14
#WM_CAP_EDIT_COPY = #WM_CAP_START + 30
#WM_CAP_DLG_VIDEOFORMAT = #WM_CAP_START + 41
#WM_CAP_DLG_VIDEOSOURCE = #WM_CAP_START + 42
#WM_CAP_DLG_VIDEODISPLAY = #WM_CAP_START + 43
#WM_CAP_GET_VIDEOFORMAT = #WM_CAP_START + 44
#WM_CAP_SET_VIDEOFORMAT = #WM_CAP_START + 45
#WM_CAP_DLG_VIDEOCOMPRESSION = #WM_CAP_START + 46 
#WM_CAP_SET_OVERLAY = #WM_CAP_START + 51
#WM_CAP_GRAB_FRAME_NOSTOP = #WM_CAP_START + 61
#WM_CAP_STOP = #WM_CAP_START + 68

#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52

OpenWindow(0, 0, 0, 700, 270, "Server Preview", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowColor(0,RGB($00,$cc,$00))
  OpenWindowedScreen(WindowID(0),365,15,685,255,0,0,0)
  If OpenLibrary(0, "avicap32.dll")
    *capAddress = GetFunction(0, "capCreateCaptureWindowA")
    hWndC.l = CallFunctionFast(*capAddress, "My Capture Window",#WS_CHILD | #WS_VISIBLE , 15, 15, 320, 240, WindowID(0),0)
    SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
    SendMessage_(hWndC, #WM_CAP_SET_OVERLAY, #True, 0)
		SendMessage_( hWndC, #WM_CAP_SET_PREVIEW, #True, 0)
		SendMessage_( hWndC, #WM_CAP_SET_PREVIEWRATE, 1, 0)
  EndIf

Repeat
  event=WaitWindowEvent(10)
  SendMessage_(hWndC, #WM_CAP_EDIT_COPY, 0, 0)
  img = GetClipboardImage(#PB_Any)
  If img
  	SaveImage(img,"c:\1.jpg",#PB_ImagePlugin_JPEG,5)
  	FreeImage(img)
  	Sprite = LoadSprite(#PB_Any, "c:\1.jpg");
  	DisplaySprite(Sprite,0,0)
  	FreeSprite(sprite)
  EndIf
  FlipBuffers()
Until event=#PB_Event_CloseWindow
add these two:
#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52

and in the sendmessage part these two:
SendMessage_( hWndC, #WM_CAP_SET_PREVIEW, #True, 0)
SendMessage_( hWndC, #WM_CAP_SET_PREVIEWRATE, 1, 0)

And it works.

Jan V.
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Post by AndyMK »

Excelent! this works BUT my webcam preview streams at 15 frames per second and if i move the window it also moves across the screen at 15 frames per second.. it moves but very jerky..
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post by Jan Vooijs »

AndyK,

Yes that is because wincap is writing to the screen via your window this has to do with pointers, so move the window and wincap needs to update its internal wizardry that takes time!!.

And 15 frames is not enough? MSN does it with 10 max and most of the time with 'only'5 frames.

Jan V.
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Post by AndyMK »

I understand what you are saying and im not really worried about the framerate of the webcam but surely there must be a way to make the window move smooth? is there any way i can temporarily stop the webcam while the window is moving? would this solve the problem? it does not look too professional when you are draggina an app and it stutters as its moving.
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post by Jan Vooijs »

AndyMk,

You have to test for #WM_MOVE in your message pump (being the PB or a callback). Than temporally stop the capture, after the #WM_MOVE stop you can capture again I believe there is a 'pause' constant to send to AviCap.

Oh and one tip make an image with somthing like 'No Video'To be placed instead of the capture if you drag.

And it is not 'professionel' look at all the dvd players drag THEM and they all stutter. It is inherent to DirectShow (aka Microsoft).

Something like this (from my own working code):

Code: Select all


;- MSG pump
			Repeat
				EventID  = WaitWindowEvent( Frame/2)		; Event twice EVERY frame..
				evGadget = EventGadget()
				evWindow = EventWindow()
				evType   = EventType() 
				;

.... snip of code ....


ElseIf EventID = #WM_MOVE
					; Debug "WindowEvent = #WM_MOVE"
					If evWindow = #hWnd
						; Main screen is moving, so 'rubberband' the control window..
						GetWindowRect_( hWnd, @Rect.RECT)
						ResizeWindow( #hWndRC, Rect\left, Rect\bottom, #PB_Ignore, #PB_Ignore)
					EndIf	
Jan V.
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Post by AndyMK »

Thanks for your help. Much appreciated.
Post Reply