[Mplayerplug-in-cvs] mplayerplug-in/Source plugin-threads.cpp,1.147,1.148 plugin.cpp,1.192,1.193
Brought to you by:
kdekorte
From: Kevin D. <kde...@us...> - 2005-06-22 16:19:17
|
Update of /cvsroot/mplayerplug-in/mplayerplug-in/Source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1838/Source Modified Files: plugin-threads.cpp plugin.cpp Log Message: Change an assertion into some if checks Handle case where plugin is shutdown, but thread is setup, but has not been signalled and so it may hang Index: plugin-threads.cpp =================================================================== RCS file: /cvsroot/mplayerplug-in/mplayerplug-in/Source/plugin-threads.cpp,v retrieving revision 1.147 retrieving revision 1.148 diff -C2 -d -r1.147 -r1.148 *** plugin-threads.cpp 15 Jun 2005 22:16:04 -0000 1.147 --- plugin-threads.cpp 22 Jun 2005 16:19:06 -0000 1.148 *************** *** 531,535 **** instance->td->argv[i++] = strdup(buffer); } - // snprintf(buffer, 1024, "-nofs"); /* no full screen */ // instance->td->argv[i++] = strdup(buffer); --- 531,534 ---- *************** *** 956,961 **** if (local_td->instance->js_state != JS_STATE_STOPPED) ! local_td->instance->js_state = JS_STATE_PLAYING; ! pthread_mutex_unlock(&(local_td->instance->control_mutex)); pthread_cleanup_pop(0); --- 955,960 ---- if (local_td->instance->js_state != JS_STATE_STOPPED) ! local_td->instance->js_state = JS_STATE_PLAYING; ! pthread_mutex_unlock(&(local_td->instance->control_mutex)); pthread_cleanup_pop(0); *************** *** 1244,1262 **** if (local_td->instance->state < STATE_STARTED_PLAYER) { pthread_cond_wait(&(local_td->instance->playlist_complete_cond), &(local_td->instance->playlist_cond_mutex)); ! assert(local_td != NULL); ! assert(local_td->instance != NULL); ! ! local_td->instance->state = STATE_STARTED_PLAYER; ! if (DEBUG) ! printf ! ("---player thread: got wakeup signal, js_state = %d, state = %d\n", ! local_td->instance->js_state, local_td->instance->state); ! } - pthread_mutex_unlock(&(local_td->instance->playlist_cond_mutex)); pthread_cleanup_pop(0); --- 1243,1280 ---- if (local_td->instance->state < STATE_STARTED_PLAYER) { + // wait for playlist_complete_cond to be signalled + // this should happen when we have completed getting all the playlist elements pthread_cond_wait(&(local_td->instance->playlist_complete_cond), &(local_td->instance->playlist_cond_mutex)); + pthread_mutex_unlock(&(local_td->instance->playlist_cond_mutex)); + + pthread_testcancel(); + sleep(1); + // playlist_cond_mutex should be locked now + if (local_td != NULL) { + if (DEBUG > 1) + printf("local_td = %p\n", local_td); + if (local_td->instance != NULL) { + if (DEBUG > 1) + printf("local_td->instance = %p\n", local_td->instance); ! local_td->instance->state = STATE_STARTED_PLAYER; ! if (DEBUG) ! printf ! ("---player thread: got wakeup signal, js_state = %d, state = %d\n", ! local_td->instance->js_state, ! local_td->instance->state); ! } else { ! if (DEBUG) ! printf("We were signalled to start but local_td->instance is NULL, should not happen\n"); ! pthread_exit(0); ! } ! } else { ! if (DEBUG) ! printf("We were signalled to start but local_td is NULL, should not happen\n"); ! pthread_exit(0); ! } } pthread_cleanup_pop(0); *************** *** 1631,1635 **** printf("----player thread: callbacks complete\n"); } - // free all the data (command line parameters) that is used to start mplayer pthread_mutex_lock(&(local_td->instance->control_mutex)); --- 1649,1652 ---- Index: plugin.cpp =================================================================== RCS file: /cvsroot/mplayerplug-in/mplayerplug-in/Source/plugin.cpp,v retrieving revision 1.192 retrieving revision 1.193 diff -C2 -d -r1.192 -r1.193 *** plugin.cpp 15 Jun 2005 21:18:32 -0000 1.192 --- plugin.cpp 22 Jun 2005 16:19:06 -0000 1.193 *************** *** 322,325 **** --- 322,333 ---- printf("shut called\n"); + if (threadsetup == 1 && threadsignaled == 0) { + if (DEBUG) + printf("Thread is setup but waiting for signal so we need to shut it down\n"); + signalPlayerThread(this); + pthread_cancel(player_thread); + } + + if (pid != 0) { killmplayer(this); *************** *** 551,559 **** --- 559,579 ---- js_state = JS_STATE_UNDEFINED; + if (DEBUG >1) + printf("destorying pthread attrs, mutexes and conds\n"); pthread_attr_destroy(&thread_attr); + if (DEBUG >1) + printf("thread_attr destroyed\n"); pthread_mutex_destroy(&playlist_mutex); + if (DEBUG >1) + printf("playlist_mutex destroyed\n"); pthread_mutex_destroy(&playlist_cond_mutex); + if (DEBUG >1) + printf("playlist_cond_mutex destroyed\n"); pthread_mutex_destroy(&control_mutex); + if (DEBUG >1) + printf("control_mutex destroyed\n"); pthread_cond_destroy(&playlist_complete_cond); + if (DEBUG >1) + printf("playlist_complete_cond destroyed\n"); } *************** *** 1486,1490 **** --- 1506,1514 ---- n = td->list; + if (DEBUG > 2) + printf("Write - scanning playlist for %s\n",stream->url); while (n != NULL) { + if (DEBUG > 2) + printf("Write - current item is %s\n",n->url); if (URLcmp(n->url, stream->url) == 0) { break; *************** *** 1727,1737 **** } ! if (autostart == 0 && threadsignaled == 0) { signalPlayerThread(this); threadsignaled = 1; } pthread_mutex_lock(&control_mutex); // lock the control pipe if (js_state == JS_STATE_UNDEFINED) { //reset the playlist --- 1751,1778 ---- } ! // we are here cause Play was pressed and autostart is 0 ! // also the thread has not been signalled to start, so signal it ! if (autostart == 0 && threadsignaled == 0 && threadsetup == 1) { signalPlayerThread(this); threadsignaled = 1; } + if (threadlaunched == 0) + return; + pthread_mutex_lock(&control_mutex); // lock the control pipe + // normal state, the media is paused or stopped and the thread is active. + if (paused == 1) { + if (DEBUG) + printf("sending play\n"); + sendCommand(this, "pause\n"); // send pause again to unpause + paused = 0; + js_state = JS_STATE_PLAYING; + } + // when js_state == JS_STATE_UNDEFINED, this means that the playlist + // has been completely processed and the window is clear with the controls + // visible + // someone just pressed play so we have to reset the playlist if (js_state == JS_STATE_UNDEFINED) { //reset the playlist *************** *** 1743,1747 **** while (n != NULL) { if (n->play) ! n->played = 0; // reset playlist n = n->next; } --- 1784,1788 ---- while (n != NULL) { if (n->play) ! n->played = 0; // reset playlist n = n->next; } *************** *** 1749,1752 **** --- 1790,1795 ---- } + // the thread is not inited and there is no GUI + // this is for states where there is no gui, such as background audio on a webpage if (threadsetup == 0 && controlwindow == 0) { if (DEBUG > 1) *************** *** 1758,1761 **** --- 1801,1806 ---- } + // the thread has been signalled, but the state is UNDEFINED so that means the + // thread needs to be restarted if (threadsignaled == 1 && js_state == JS_STATE_UNDEFINED) { if (DEBUG > 1) *************** *** 1772,1775 **** --- 1817,1821 ---- threadsignaled = 1; + // autostart is not set, and the thread has not been signalled } else if ((autostart == 0) && (threadsignaled == 0)) { pthread_mutex_unlock(&control_mutex); // not autostarted, but the thread is ready and waiting for a signal *************** *** 1783,1796 **** } - if (paused == 1) { - if (DEBUG) - printf("sending play\n"); - pthread_mutex_lock(&control_mutex); - sendCommand(this, "pause\n"); // send pause again to unpause - paused = 0; - js_state = JS_STATE_PLAYING; - pthread_mutex_unlock(&control_mutex); - } - #ifdef GTK_ENABLED play_callback(NULL, NULL, this); --- 1829,1832 ---- |