Page 1 of 1

Triggering a callback from within itself causes freeze

Posted: 18 Nov 2012 06:05
by Vaselinessa
I have a callback which can fire its own trigger under a certain circumstance. When this occurs, the GUI freezes (the video keeps playing, but the controls lock up). Does anybody have an idea how I can obviate the freeze-up?

Code: Select all

// in my module's Open function: var_AddCallback( p_input, "time", TimeChangeCallback, NULL ); var_AddCallback( p_input, "position", PositionChangeCallback, NULL ); // ... // The "time" change callback int TimeChangeCallback( vlc_object_t *p_this, const char *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { MyRoutine(newval.i_int); } // The "position" change callback int PositionChangeCallback( vlc_object_t *p_this, const char *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { input_thread_t * p_input; // ... p_input gets set ... mtime_t new_time = newval.f_float * var_GetTime( p_input, "length" ); MyRoutine(new_time); } void MyRoutine(mtime_t time) { input_thread_t * p_input; // ... p_input gets set ... if (time < 1000000000L) var_SetTime( p_input, "time", 2000000000L ); // !!! This line triggers TimeChangeCallback }
My code performs just fine when PositionChangeCallback calls MyRoutine, which triggers TimeChangeCallback, but when TimeChangeCallback calls MyRoutine and thereby triggers TimeChangeCallback, the problem arises.

I imagined that I might solve the problem by acquiring a mutex lock on my module (even though there appears to be no danger of race conditions), but it makes no difference: the programme freezes just the same.

Often freezes are caused by infinite loops, but it doesn't appear to me to be the problem because I added a call to msg_Info() at the start of my callback, and the message only gets outputted once, no more.

Any idea what I should look for?

Re: Triggering a callback from within itself causes freeze

Posted: 18 Nov 2012 10:10
by RĂ©mi Denis-Courmont
Callback loops are not permitted. Fix your code.

Re: Triggering a callback from within itself causes freeze

Posted: 18 Nov 2012 16:56
by Vaselinessa
Thanks. Do you think the loop would be avoided appropriately if I were to fork the process so that MyRoutine ran in a new thread?

(If so, does VLC provide a function for spawning threads which won't require me to concern myself with whether to use posix or win threads? For instance, does vlc_clone(vlc_thread_t * , void (*)(void *), void * , int ) perform that job? )