From 3a05c89924078a80a0b8aafbd061326c2617daad Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 17 Nov 2011 02:23:56 +0000 Subject: [PATCH] minor tweaks --- panda/src/movies/ffmpegVideoCursor.cxx | 91 +++++++++++++++----------- panda/src/movies/ffmpegVideoCursor.h | 1 + panda/src/movies/ffmpegVirtualFile.cxx | 5 ++ 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/panda/src/movies/ffmpegVideoCursor.cxx b/panda/src/movies/ffmpegVideoCursor.cxx index cbf7bcf0ee..cf634c99ae 100644 --- a/panda/src/movies/ffmpegVideoCursor.cxx +++ b/panda/src/movies/ffmpegVideoCursor.cxx @@ -997,46 +997,12 @@ seek(int frame, bool backward) { PStatTimer timer(seek_pcollector); if (ffmpeg_support_seek) { - // Protect the call to av_seek_frame() in a global lock, just to be - // paranoid. - ReMutexHolder av_holder(_av_lock); - - PN_int64 target_ts = (PN_int64)frame; - if (target_ts < (PN_int64)(_initial_dts)) { - // Attempts to seek before the first packet will fail. - target_ts = _initial_dts; + if (ffmpeg_global_lock) { + ReMutexHolder av_holder(_av_lock); + do_seek(frame, backward); + } else { + do_seek(frame, backward); } - int flags = 0; - if (backward) { - flags = AVSEEK_FLAG_BACKWARD; - } - - if (av_seek_frame(_format_ctx, _video_index, target_ts, flags) < 0) { - if (ffmpeg_cat.is_spam()) { - ffmpeg_cat.spam() - << "Seek failure.\n"; - } - - if (backward) { - // Now try to seek forward. - reset_stream(); - seek(frame, false); - return; - } - - // Try a binary search to get a little closer. - if (binary_seek(_initial_dts, frame, frame, 1) < 0) { - if (ffmpeg_cat.is_spam()) { - ffmpeg_cat.spam() - << "Seek double failure.\n"; - } - reset_stream(); - return; - } - } - - fetch_packet(0); - fetch_frame(-1); } else { // If seeking isn't supported, close-and-reopen. @@ -1046,6 +1012,53 @@ seek(int frame, bool backward) { } } +//////////////////////////////////////////////////////////////////// +// Function: FfmpegVideoCursor::do_seek +// Access: Private +// Description: As above, with the ffmpeg global lock held (if +// configured on). Also only if ffmpeg-support-seek is +// on. +//////////////////////////////////////////////////////////////////// +void FfmpegVideoCursor:: +do_seek(int frame, bool backward) { + PN_int64 target_ts = (PN_int64)frame; + if (target_ts < (PN_int64)(_initial_dts)) { + // Attempts to seek before the first packet will fail. + target_ts = _initial_dts; + } + int flags = 0; + if (backward) { + flags = AVSEEK_FLAG_BACKWARD; + } + + if (av_seek_frame(_format_ctx, _video_index, target_ts, flags) < 0) { + if (ffmpeg_cat.is_spam()) { + ffmpeg_cat.spam() + << "Seek failure.\n"; + } + + if (backward) { + // Now try to seek forward. + reset_stream(); + seek(frame, false); + return; + } + + // Try a binary search to get a little closer. + if (binary_seek(_initial_dts, frame, frame, 1) < 0) { + if (ffmpeg_cat.is_spam()) { + ffmpeg_cat.spam() + << "Seek double failure.\n"; + } + reset_stream(); + return; + } + } + + fetch_packet(0); + fetch_frame(-1); +} + //////////////////////////////////////////////////////////////////// // Function: FfmpegVideoCursor::binary_seek // Access: Private diff --git a/panda/src/movies/ffmpegVideoCursor.h b/panda/src/movies/ffmpegVideoCursor.h index 1503f17b04..13faa170a3 100644 --- a/panda/src/movies/ffmpegVideoCursor.h +++ b/panda/src/movies/ffmpegVideoCursor.h @@ -130,6 +130,7 @@ private: void decode_frame(int &finished, AVPacket *packet); void do_decode_frame(int &finished, AVPacket *packet); void seek(int frame, bool backward); + void do_seek(int frame, bool backward); int binary_seek(int min_frame, int max_frame, int target_frame, int num_iterations); void advance_to_frame(int frame); void reset_stream(); diff --git a/panda/src/movies/ffmpegVirtualFile.cxx b/panda/src/movies/ffmpegVirtualFile.cxx index 88f7cd3786..ef814634a1 100644 --- a/panda/src/movies/ffmpegVirtualFile.cxx +++ b/panda/src/movies/ffmpegVirtualFile.cxx @@ -216,6 +216,11 @@ register_protocol() { // Here's a good place to call this global ffmpeg initialization // function. av_register_all(); + + // And this one. +#if LIBAVFORMAT_VERSION_INT >= 0x351400 + avformat_network_init(); +#endif static URLProtocol protocol; protocol.name = "pandavfs";