Browse Source

minor tweaks

David Rose 14 years ago
parent
commit
3a05c89924

+ 50 - 37
panda/src/movies/ffmpegVideoCursor.cxx

@@ -997,53 +997,66 @@ seek(int frame, bool backward) {
   PStatTimer timer(seek_pcollector);
   PStatTimer timer(seek_pcollector);
 
 
   if (ffmpeg_support_seek) {
   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;
+
+  } else {
+    // If seeking isn't supported, close-and-reopen.
     if (backward) {
     if (backward) {
-      flags = AVSEEK_FLAG_BACKWARD;
+      reset_stream();
     }
     }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     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 (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;
-      }
+    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;
+    // 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";
       }
       }
-    }
-
-    fetch_packet(0);
-    fetch_frame(-1);
-
-  } else {
-    // If seeking isn't supported, close-and-reopen.
-    if (backward) {
       reset_stream();
       reset_stream();
+      return;
     }
     }
   }
   }
+
+  fetch_packet(0);
+  fetch_frame(-1);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 0
panda/src/movies/ffmpegVideoCursor.h

@@ -130,6 +130,7 @@ private:
   void decode_frame(int &finished, AVPacket *packet);
   void decode_frame(int &finished, AVPacket *packet);
   void do_decode_frame(int &finished, AVPacket *packet);
   void do_decode_frame(int &finished, AVPacket *packet);
   void seek(int frame, bool backward);
   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);
   int binary_seek(int min_frame, int max_frame, int target_frame, int num_iterations);
   void advance_to_frame(int frame);
   void advance_to_frame(int frame);
   void reset_stream();
   void reset_stream();

+ 5 - 0
panda/src/movies/ffmpegVirtualFile.cxx

@@ -216,6 +216,11 @@ register_protocol() {
   // Here's a good place to call this global ffmpeg initialization
   // Here's a good place to call this global ffmpeg initialization
   // function.
   // function.
   av_register_all();
   av_register_all();
+  
+  // And this one.
+#if LIBAVFORMAT_VERSION_INT >= 0x351400
+  avformat_network_init();
+#endif
 
 
   static URLProtocol protocol;
   static URLProtocol protocol;
   protocol.name = "pandavfs";
   protocol.name = "pandavfs";