CVSROOT: /sources/gnash Module name: gnash Changes by: Sandro Santilli <strk> 07/06/04 09:04:32
Modified files: . : ChangeLog server/asobj : NetStreamFfmpeg.cpp NetStreamFfmpeg.h Log message: * server/asobj/NetStreamFfmpeg.{cpp,h}: Drop the decoder mutex and conditional variable. Decoder should never stop till the end of the stream is fully decoder. Rename {pause,unpause}Decoding to {pause,unpause}Playback, which is matches reality more, and is also more correct. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3443&r2=1.3444 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.84&r2=1.85 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.h?cvsroot=gnash&r1=1.44&r2=1.45 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.3443 retrieving revision 1.3444 diff -u -b -r1.3443 -r1.3444 --- ChangeLog 4 Jun 2007 08:10:26 -0000 1.3443 +++ ChangeLog 4 Jun 2007 09:04:32 -0000 1.3444 @@ -1,5 +1,13 @@ 2007-06-04 Sandro Santilli <[EMAIL PROTECTED]> + * server/asobj/NetStreamFfmpeg.{cpp,h}: Drop the decoder mutex and + conditional variable. Decoder should never stop till the end of + the stream is fully decoder. Rename {pause,unpause}Decoding to + {pause,unpause}Playback, which is matches reality more, and is + also more correct. + +2007-06-04 Sandro Santilli <[EMAIL PROTECTED]> + * server/timers.cpp (expired): allow now == _start. Hopefully fixes bug #20047. Index: server/asobj/NetStreamFfmpeg.cpp =================================================================== RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v retrieving revision 1.84 retrieving revision 1.85 diff -u -b -r1.84 -r1.85 --- server/asobj/NetStreamFfmpeg.cpp 3 Jun 2007 18:40:21 -0000 1.84 +++ server/asobj/NetStreamFfmpeg.cpp 4 Jun 2007 09:04:32 -0000 1.85 @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // -/* $Id: NetStreamFfmpeg.cpp,v 1.84 2007/06/03 18:40:21 strk Exp $ */ +/* $Id: NetStreamFfmpeg.cpp,v 1.85 2007/06/04 09:04:32 strk Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -91,13 +91,13 @@ if (mode == -1) { - if (m_pause) unpauseDecoding(); - else pauseDecoding(); + if (m_pause) unpausePlayback(); + else pausePlayback(); } else { - if (mode == 0) pauseDecoding(); - else unpauseDecoding(); + if (mode == 0) pausePlayback(); + else unpausePlayback(); } if (!m_pause && !m_go) { setStatus(playStart); @@ -112,23 +112,15 @@ if (m_go) { - // terminate thread + // request decoder thread termination m_go = false; -#ifdef GNASH_DEBUG_THREADS - log_debug("Waking up decoder thread on close()"); -#endif - decode_wait.notify_one(); // wait till thread is complete before main continues _decodeThread->join(); + delete _decodeThread; } - else - { - // WARNING: decoder might be still waiting on the decode_wait condition... - } - // When closing gnash before playback is finished, the soundhandler // seems to be removed before netstream is destroyed. @@ -225,7 +217,7 @@ // Is it already playing ? if (m_go) { - if (m_pause) unpauseDecoding(); + unpausePlayback(); // will check for m_pause itself.. return; } @@ -245,7 +237,7 @@ } m_go = true; - pauseDecoding(); + pausePlayback(); // This starts the decoding thread _decodeThread = new boost::thread(boost::bind(NetStreamFfmpeg::av_streamer, this)); @@ -574,7 +566,7 @@ } - unpauseDecoding(); + unpausePlayback(); return true; } @@ -607,14 +599,6 @@ { //GNASH_REPORT_FUNCTION; -#ifdef GNASH_DEBUG_THREADS - log_debug("Thread %d locking on ::av_streamer", pthread_self()); -#endif - boost::mutex::scoped_lock lock(ns->decoding_mutex); -#ifdef GNASH_DEBUG_THREADS - log_debug(" obtained (av_streamer)"); -#endif - // This should only happen if close() is called before this thread is ready if (!ns->m_go) { @@ -667,26 +651,6 @@ } } - if (ns->m_pause || (ns->m_qvideo.size() > 10 && ns->m_qaudio.size() > 10)) - { - if ( ! ns->m_go ) - { - log_debug("m_go=%d, m_start_onbuffer=%d, qVideoSize=%d, qAudioSize=%d", ns->m_go, ns->m_start_onbuffer, ns->m_qvideo.size(), ns->m_qaudio.size()); - // decodeFLVFrame above might set m_go to false when parsed buffer is over - // note that when parsed buffer is over decodeFLVFrame would return false, - // but the break above might still not be reached due to m_start_onbuffer - // or queue sizes not being 0. - assert(0); - break; - } -#ifdef GNASH_DEBUG_THREADS - log_debug("Waiting on lock.."); -#endif - ns->decode_wait.wait(lock); -#ifdef GNASH_DEBUG_THREADS - log_debug("Finished waiting."); -#endif - } } else { // If we have problems with decoding - break @@ -695,19 +659,6 @@ break; } - // If paused, wait for being unpaused, or - // if the queue is full we wait until someone notifies us that data is needed. - if (ns->m_pause || ((ns->m_qvideo.size() > 0 && ns->m_qaudio.size() > 0) && ns->m_unqueued_data)) - { - assert ( ns->m_go ); // or we'll have a problem ending the wait... -#ifdef GNASH_DEBUG_THREADS - log_debug("Waiting on lock.."); -#endif - ns->decode_wait.wait(lock); -#ifdef GNASH_DEBUG_THREADS - log_debug("Finished waiting."); -#endif - } } } @@ -730,17 +681,8 @@ NetStreamFfmpeg* ns = static_cast<NetStreamFfmpeg*>(owner); -#ifdef GNASH_DEBUG_THREADS - log_debug("Thread %d locking on ::audio_streamer", pthread_self()); -#endif - boost::mutex::scoped_lock lock(ns->decoding_mutex); -#ifdef GNASH_DEBUG_THREADS - log_debug(" obtained (audio_streamer)"); -#endif - if (!ns->m_go || ns->m_pause) { - // WARNING: decoder might be still waiting on the decode_wait condition... return false; } @@ -748,16 +690,6 @@ { raw_mediadata_t* samples = ns->m_qaudio.front(); - // If less than 3 frames in the queue notify the decoding thread - // so that we don't suddenly run out. - if (ns->m_qaudio.size() < 3) - { -#ifdef GNASH_DEBUG_THREADS - log_debug("Waking up decoder thread from audio_streamer due to short qaudio size (%lu)", static_cast<unsigned long>(ns->m_qaudio.size())); -#endif - ns->decode_wait.notify_one(); - } - int n = imin(samples->m_size, len); memcpy(stream, samples->m_ptr, n); stream += n; @@ -797,7 +729,7 @@ // Stop! m_go = false; } else { - pauseDecoding(); + pausePlayback(); setStatus(bufferEmpty); m_start_onbuffer = true; } @@ -1005,13 +937,6 @@ bool NetStreamFfmpeg::decodeMediaFrame() { -#ifdef GNASH_DEBUG_THREADS - log_debug("Thread %d locking on ::decodeMediaFrame", pthread_self()); -#endif - boost::mutex::scoped_lock lock(decoding_mutex); -#ifdef GNASH_DEBUG_THREADS - log_debug(" obtained (decodeMediaFrame)"); -#endif if (m_unqueued_data) { @@ -1161,14 +1086,9 @@ // will return NULL if empty(). See multithread_queue::front raw_mediadata_t* video = m_qvideo.front(); - // If the queue is empty, we tell the decoding thread to wake up, - // and decode some more. + // If the queue is empty we have nothing to do if (!video) { -#ifdef GNASH_DEBUG_THREADS - log_debug("Waking up decoder thread from refreshVideoFrame due to empty video queue"); -#endif - decode_wait.notify_one(); return; } @@ -1210,15 +1130,6 @@ return; } - // If less than 3 frames in the queue notify the decoding thread - // so that we don't suddenly run out. - if (m_qvideo.size() < 3) - { -#ifdef GNASH_DEBUG_THREADS - log_debug("Waking up decoder thread from refreshVideoFrame due short video queue (%lu)", static_cast<unsigned long>(m_qvideo.size())); -#endif - decode_wait.notify_one(); - } } } @@ -1226,13 +1137,6 @@ void NetStreamFfmpeg::advance() { -#ifdef GNASH_DEBUG_THREADS - log_debug("Thread %d locking on ::advance", pthread_self()); -#endif - boost::mutex::scoped_lock lock(decoding_mutex); -#ifdef GNASH_DEBUG_THREADS - log_debug(" obtained (advance)"); -#endif // Make sure al decoding has stopped // This can happen in 2 cases: @@ -1247,7 +1151,7 @@ log_debug("(advance): setting buffer full"); #endif setStatus(bufferFull); - unpauseDecoding(); + unpausePlayback(); m_start_onbuffer = false; } @@ -1276,12 +1180,10 @@ } } -void NetStreamFfmpeg::pauseDecoding() +void NetStreamFfmpeg::pausePlayback() { //GNASH_REPORT_FUNCTION - // assert(decoding_mutex is locked by this thread!) - if (m_pause) return; m_pause = true; @@ -1290,13 +1192,10 @@ m_time_of_pause = tu_timer::get_ticks(); } -void NetStreamFfmpeg::unpauseDecoding() +void NetStreamFfmpeg::unpausePlayback() { - // assert(decoding_mutex is locked by this thread!) - - if (!m_pause) + if (!m_pause) // already not paused { - // WARNING: decoder might be still waiting on the decode_wait condition... return; } @@ -1310,13 +1209,8 @@ m_start_clock += tu_timer::get_ticks() - m_time_of_pause; } - // Notify the decode thread/loop that we are running again -#ifdef GNASH_DEBUG_THREADS - log_debug("Waking up decoder thread from unpauseDecoding..."); -#endif - decode_wait.notify_one(); - - // Re-connect to the soundhandler + // Re-connect to the soundhandler. + // It was disconnected to avoid to keep playing sound while paused sound_handler* s = get_sound_handler(); if (s) s->attach_aux_streamer(audio_streamer, (void*) this); } Index: server/asobj/NetStreamFfmpeg.h =================================================================== RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.h,v retrieving revision 1.44 retrieving revision 1.45 diff -u -b -r1.44 -r1.45 --- server/asobj/NetStreamFfmpeg.h 31 May 2007 15:52:28 -0000 1.44 +++ server/asobj/NetStreamFfmpeg.h 4 Jun 2007 09:04:32 -0000 1.45 @@ -15,7 +15,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -/* $Id: NetStreamFfmpeg.h,v 1.44 2007/05/31 15:52:28 tgc Exp $ */ +/* $Id: NetStreamFfmpeg.h,v 1.45 2007/06/04 09:04:32 strk Exp $ */ #ifndef __NETSTREAMFFMPEG_H__ #define __NETSTREAMFFMPEG_H__ @@ -235,45 +235,37 @@ NetStreamFfmpeg(); ~NetStreamFfmpeg(); - // Locks decoding_mutex - // - /// does NOT lock decoding_mutex, intended to be called - /// by ::advance which locks and by destructor (locking in destructor might be needed) - /// + // See dox in NetStream.h void close(); - /// Locks decoding_mutex - // - /// does NOT lock decoding_mutex, intended to be only called - /// by ::advance, itself locking. - /// + // See dox in NetStream.h void pause(int mode); - /// does NOT lock decoding_mutex, intended to be only called - /// by ::advance, itself locking. - /// + // See dox in NetStream.h void play(const std::string& source); - /// does NOT lock decoding_mutex. Users: - /// - ::advance (VM), itself locking - /// - ::startPlayback() non locking but called by av_streamer which locks - /// - ::seekMedia() set as a callback with init_put_byte (??) - /// + // See dox in NetStream.h + // + // Users: + // - ::advance (VM), itself locking + // - ::startPlayback() non locking but called by av_streamer which locks + // - ::seekMedia() set as a callback with init_put_byte (??) + // void seek(uint32_t pos); + // See dox in NetStream.h int32_t time(); - // Locks decoding_mutex + // See dox in NetStream.h void advance(); // Used for ffmpeg data read and seek callbacks with non-FLV static int readPacket(void* opaque, uint8_t* buf, int buf_size); + + // Used for ffmpeg data read and seek callbacks with non-FLV static offset_t seekMedia(void *opaque, offset_t offset, int whence); /// The decoding thread. Sets up the decoder, and decodes. - // - /// Locks decoding_mutex - /// static void av_streamer(NetStreamFfmpeg* ns); /// Callback used by sound_handler to get audio data @@ -282,8 +274,6 @@ /// /// It will be invoked by a separate thread (neither main, nor decoder thread). /// - /// Locks decoding_mutex - /// static bool audio_streamer(void *udata, uint8_t *stream, int len); private: @@ -291,28 +281,29 @@ // Setups the playback bool startPlayback(); - // Pauses the decoding - don't directly modify m_pause!! + // Pauses the playhead // - // does NOT lock decoding_mutex. Users: - // - ::decodeFLVFrame() not locking byt called by av_streamer which locks - // - ::pause() not locking but called by ::advance - // - ::play() not locking but called by ::advance which locks + // Users: + // - ::decodeFLVFrame() + // - ::pause() + // - ::play() // - void pauseDecoding(); + void pausePlayback(); - // Unpauses/resumes the decoding - don't directly modify m_pause!! + // Resumes the playback // - // does NOT lock decoding_mutex. Users: - // - ::av_streamer() which locks - // - ::play() not locking but called by ::advance which locks - // - ::startPlayback() not locking but called by ::av_streamer - // - ::advance() which locks + // Users: + // - ::av_streamer() + // - ::play() + // - ::startPlayback() + // - ::advance() // - void unpauseDecoding(); + void unpausePlayback(); /// Update the image/videoframe to be returned by next get_video() call. // - /// Does NOT lock decoding_mutex, uses by ::advance() which locks. + /// Uses by ::advance(). + /// /// Note that get_video will be called by video_stream_instance::display, which /// is usually called right after video_stream_instance::advance, so the result /// is that refreshVideoFrame() is called right before get_video(). This is important @@ -325,7 +316,7 @@ // Used to decode push the next available FLV frame to the audio or video queue // - // does NOT lock decoding_mutex, uses by ::advance() which locks + // Uses by ::advance(). // bool decodeFLVFrame(); @@ -363,16 +354,6 @@ // The decoding thread boost::thread* _decodeThread; - // Mutex used to make sure things arn't messed up when seeking and decoding (is it really necessary?) - boost::mutex decoding_mutex; - - // Condition used to pause the decoding thread/loop when - // playback is paused, or when the video and audio queues are full - // - // Associated with the decoding_mutex - // - boost::condition decode_wait; - // The timestamp of the last decoded video frame, in seconds. volatile uint32_t m_last_video_timestamp; _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit