gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Displaying live video -- how to notify main loop from another thread


From: David Chisnall
Subject: Re: Displaying live video -- how to notify main loop from another thread?
Date: Fri, 9 Jul 2010 13:33:32 +0100

Hi Marek,

For playing video, Eric wrote a simple view a while ago that used an 
NSOpenGLView, so bypassed the entire GNUstep drawing stack and gave good 
performance, so you might consider this approach.  This also has the advantage 
that the image stays in VRAM as a texture once the camera has captured it, so 
redraws are very cheap.  

With regard to your actual questions...

You can receive notification of data available on a file descriptor by wrapping 
it in an NSFileHandle and then calling a method like 
-waitForDataInBackgroundAndNotify.  This will post a notification when there is 
data available for drawing.  

-setNeedsDisplay: also ought to work.  I think this is a bug in GNUstep - this 
ought to wake up the main thread if it is sleeping and trigger a redraw.  If it 
doesn't, you can poke the main thread with -performSelectorInMainThread:

David

On 9 Jul 2010, at 12:44, Marek Peca wrote:

> Dear GNUsteppers,
> 
> I am writing a scientific imaging application, which should display a live 
> video coming from camera with some grid and text superimposed on it.
> I have achieved the basic operation using NSBitmapImageRep, filled with 
> camera images, displayed by a descendant of NSView.
> 
> The GNUstep GUI (application event loop) runs in one thread, while the camera 
> input runs in another thread (there is a blocking select). The problem is, 
> how to notify the GUI, that redrawing of camera image is needed. I thought, 
> that NSView->setNeedsDisplay: YES exists for this purpose, however, it does 
> not seem to work for me. The image is not updated, until some GUI events 
> interrupt the loop (eg. mouse input).
> 
> How can I solve this issue? It would be fine, if I could somehow propagate 
> the request from another thread. If this is not possible, I would appreciate 
> at least, if GNUstep supports external "file" events, like XtAppAddInput in 
> XToolkit. Does it?
> 
> And the second question is, whether I have chosen the right method of image 
> display: I am calling NSBitmapImageRep->draw from within ImgView->drawRect:, 
> where ImgView is descendant of NSView. Camera is grabbing at few fps, 
> 640x480x8bit, calling [imgView setNeedsDisplay: YES]; if the event queue is 
> being refreshed by continuous mouse motion, I can easily get CPU load 60% on 
> my 3GHz Pentium. (Similar program under Gtk takes 2% CPU.) So I am asking, 
> whether, and what am I doing wrong.
> 
> And my last question, do you know about some program or a demo under GNUstep, 
> displaying live "webcam"?
> 
> 
> Thank you very much for your help.
> 
> Best regards,
> Marek
> 
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gnustep-dev


-- Sent from my IBM 1620




reply via email to

[Prev in Thread] Current Thread [Next in Thread]