Triggering a callback from within itself causes freeze

This forum is about all development around libVLC.
Vaselinessa
Blank Cone
Blank Cone
Posts: 48
Joined: 03 Apr 2011 02:26
Location: Sacramento, CA

Triggering a callback from within itself causes freeze

Postby Vaselinessa » 18 Nov 2012 06:05

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?

Rémi Denis-Courmont
Developer
Developer
Posts: 15267
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Triggering a callback from within itself causes freeze

Postby Rémi Denis-Courmont » 18 Nov 2012 10:10

Callback loops are not permitted. Fix your code.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

Vaselinessa
Blank Cone
Blank Cone
Posts: 48
Joined: 03 Apr 2011 02:26
Location: Sacramento, CA

Re: Triggering a callback from within itself causes freeze

Postby Vaselinessa » 18 Nov 2012 16:56

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? )


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 21 guests