Motion - Restart On Video Source Error

Restart threads and/or motion when capture errors detected from camera source

Description of Patch

Due to my capture device causing large amounts of interference, frequently my video capture device would stop responding, which causes the motion thread to exit with 'sync error in proc 18453: Timer expired' 'Thread exiting' I therefore needed a method to restart that thread, clearing the buffers on the video capture device, etc. Ideally, I wanted to just restart the thread, however after coding in a thread restart, and finding that cleaning up the video device was very complex, I have initially made motion restart when it finds a thread has died, which at least restores the sources as expected.

A future change (maybe somebody with more knowledge of the video.c element) will be when thread has died, munmap and free video device relating to the thread. Start/open the video device for that thread, then pthread_create the thread again to start things over.

I'm not experienced with C coding so this code will need to be reviewed for problems!

(This patch does not include my changes to video.c as they aren't worth noting, as they are ugly hacks that don't work! There are easier ways of sending kill to motion when an individual thread dies, however doing so in the manner I have in motion.c it permits further development of thread handling and hopefully aims at a future full-patch to restart individual threads)

Installation of Patch

patch < restartonvideosourceerror_v1.0.diff

Then re-build Motion and test the patch.

Change History of Patch

  • 1.0 Initial revision Under test locally by AndyBrown

Discussion and Comments

we thought some time ago how to solve the problem , there's a topic talking about :

http://www.lavrsen.dk/twiki/bin/view/Motion/MotionWatchdog

We know that restart motion is not the best solution but simplest one ... so before include your patch as a temporary solution let us review it.

Thank !

-- AngelCarpintero - 29 Dec 2006


Thanks Angel, And yes, I've read the MotionWatchdog, and part of my patch does indeed handle a couple of the requirements of the Watchdog:

* Each thread have to use a flag to show if it's alive or not , one way to implement this flag is to use a variable and set and reset it between critic sections.

In my patch, I mark a variable with current time each time child thread updates an image, the variable being cnt->threadtime which can be read by the main thread handling loop

* Main thread have to loop checking the state of the thread flag.

I implement this by checking cnt->threadtime and comparing against cnt->threadoldtime and if they are the same, means we have lost an image capture on that thread loop

As it will be of use, I'll post the code I did adding in the restart thread code I wrote, which also had tie-ins to video.c to handle restarting/closing the video devices on thread close/restart.

-- AndyBrown - 29 Dec 2006

Sorry I meant to add, that YES my patch is a temporary solution, and that users should be aware it can cause the process to keep restarting frequently/quickly in case of a buggy/faulty device. SO BEWARE!!

-- AndyBrown - 29 Dec 2006


As we have a solution this patch is cancelled.

http://www.lavrsen.dk/twiki/bin/view/Motion/WatchdogAndThreadPatch

-- AngelCarpintero - 04 Jan 2008


Topic revision: r4 - 04 Jan 2008, AngelCarpintero
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.