Re: [libdc1394-devel] Threading libdc1394
Capture and control API for IIDC compliant cameras
Brought to you by:
ddouxchamps,
gordp
From: Mark M. <mar...@po...> - 2007-02-22 15:35:49
|
Hi Thomas, I'm using a similar setup: main thread is used to set camera settings =20= (like brightness, contrast) through the GUI, while dequeue/enqueue is =20= handled by a separate capture thread. Examining my apps logfiles, I see once in a while I receive an error =20 when trying to read or set some camera setting. I am wondering what's the cause for this. Is it ok to set camera =20 values from one thread and enqueue/dequeue from another without some =20 locking mechanism, or might that be the cause of the errors. Does this happen to you too, are you serializing commands sent to the =20= camera? Best regards from Konstanz Mark On 22.02.2007, at 12:53, Tho...@t-... wrote: > Hey! > Threading the libdc1394 has not caused any > problems for me. I am using it to record and display images in a > Qt-based application. > > Basically I got: > 1) main thread > Which initializes the camera like your exammple > > 2) event > thread > Which i.e. starts the capture process when I hit my > "Start Capture" button. > > It also takes care of > setting camera features, like brightness, contrast, sharpness =20 > through my > config dialog. > > 3) capture thread > Does the dequeue > enqueue DMA buffer handling and converts the image data to RGB. When a > new frame is ready it emits a callback to the render thread. > > 4) render thread > Fetches the last image data and displays it as > an OpenGL texture. > > Didn't give me a single crash (outside of > my own code) or problem. Only thing happened to me that some settings > could not be applied when a capture process is already running. In =20 > that > case I had to properly stop the capture thread before doing the > changes. > > Hope this helps! > > Thomas W=F6llert, cand. > M.Sc. > Munich University of Applied Sciences > > > /** > *---------------------------------------------------------- > */ > So I've moved on to attempting to thread with libdc1394. I can't > find > a good description in the list or the faq on what I can and > can't do > between multiple threads though so I cooked up some > semi-specific > pseudocode on how I plan to implement this. > > If anyone has any opinions let me know. I haven't actually tried > the > corresponding real code for this yet, but I should have > initial > results in a couple hours. > > main thread: > > void > init() > { > create_run_lock() ; > create_camera_mutex() ; > create_img_cond_lock() ; > frame =3D > NULL ; > stamp =3D 0 ; > last_stamp =3D 0 ; > > create_reader_thread() ; > } > > void > read_image() > { > lock( mutex ) > while( frame =3D=3D NULL && stamp =3D=3D > last_stamp ) > cond_wait( new_img_cond, mutex ) ; > > > last_stamp =3D stamp ; > use_image() ; > > unlock( > mutex ) ; > } > > void > set_gain() > { > lock( > camera_mutex ) ; > change_feature() ; > unlock( camera_mutex ) > ; > } > > ---------------- > > reader thread: > > Loop: > lock( camera_mutex ) ; > if( stop_running ) > { > break ; > } > > if( read_frame !=3D NULL ) > { > enqueue_frame( read_frame ) ; > } > > dequeue_frame( read_frame ) ; > unlock( camera_mutex ) ; > > try_lock( mutex ) ; > if( locked ) > { > temp_frame =3D frame ; > frame =3D read_frame ; > read_frame =3D > frame ; > stamp++ ; > unlock( mutex ) ; > cond_signal( > new_img_cond ) ; > } > > lock( run_mutex ) ; > > keep_running =3D running ; > unlock( run_mutex ) ; > End loop > > exit_thread() ; > > > > ----------------------------------------------------------------------=20= > --- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to =20 > share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?=20 > page=3Djoin.php&p=3Dsourceforge&CID=3DDEVDEV____________________________= ____=20 > _______________ > Mailing list for libdc1394-devel > lib...@li... > https://lists.sourceforge.net/lists/listinfo/libdc1394-devel |