Browse Source

hey, this time I really found the ffmpeg crash.

David Rose 14 years ago
parent
commit
dca824b5de

+ 14 - 14
dtool/src/dtoolbase/atomicAdjustWin32Impl.I

@@ -53,10 +53,12 @@ dec(TVOLATILE AtomicAdjustWin32Impl::Integer &var) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void AtomicAdjustWin32Impl::
 INLINE void AtomicAdjustWin32Impl::
 add(TVOLATILE AtomicAdjustWin32Impl::Integer &var, AtomicAdjustWin32Impl::Integer delta) {
 add(TVOLATILE AtomicAdjustWin32Impl::Integer &var, AtomicAdjustWin32Impl::Integer delta) {
-  AtomicAdjustWin32Impl::Integer orig_value = var;
-  while (compare_and_exchange(var, orig_value, orig_value + delta) != orig_value) {
-    orig_value = var;
-  }
+  assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0);
+#ifdef _WIN64
+  InterlockedAdd64(&var, delta);
+#else
+  InterlockedAdd(&var, delta);
+#endif  // _WIN64
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -87,13 +89,12 @@ set(TVOLATILE AtomicAdjustWin32Impl::Integer &var,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE AtomicAdjustWin32Impl::Integer AtomicAdjustWin32Impl::
 INLINE AtomicAdjustWin32Impl::Integer AtomicAdjustWin32Impl::
 get(const TVOLATILE AtomicAdjustWin32Impl::Integer &var) {
 get(const TVOLATILE AtomicAdjustWin32Impl::Integer &var) {
-  // On Intel platforms, word-aligned loads are atomic (if performed
-  // in a single instruction).  We can't guarantee the compiler will
-  // generate a single instruction to load this value, but it
-  // certainly won't happen if its address isn't word-aligned, so make
-  // sure that's the case.
   assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0);
   assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0);
-  return var;
+#ifdef _WIN64
+  return InterlockedAdd64((TVOLATILE AtomicAdjustWin32Impl::Integer *)&var, 0);
+#else
+  return InterlockedAdd((TVOLATILE AtomicAdjustWin32Impl::Integer *)&var, 0);
+#endif  // _WIN64
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -116,13 +117,12 @@ set_ptr(TVOLATILE AtomicAdjustWin32Impl::Pointer &var,
 //               indicated variable.  This is the only guaranteed safe
 //               indicated variable.  This is the only guaranteed safe
 //               way to retrieve the value that other threads might be
 //               way to retrieve the value that other threads might be
 //               asynchronously setting, incrementing, or decrementing
 //               asynchronously setting, incrementing, or decrementing
-//               (via other AtomicAjust methods).
+//               (via other AtomicAdjust methods).
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE AtomicAdjustWin32Impl::Pointer AtomicAdjustWin32Impl::
 INLINE AtomicAdjustWin32Impl::Pointer AtomicAdjustWin32Impl::
 get_ptr(const TVOLATILE AtomicAdjustWin32Impl::Pointer &var) {
 get_ptr(const TVOLATILE AtomicAdjustWin32Impl::Pointer &var) {
-  // As in get(), make sure the address is word-aligned.
-  assert((((size_t)&var) & (sizeof(Pointer) - 1)) == 0);
-  return var;
+  assert(sizeof(Pointer) == sizeof(Integer));
+  return (Pointer)get(*(const TVOLATILE Integer *)&var);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 9 - 10
panda/src/movies/ffmpegVideoCursor.cxx

@@ -31,6 +31,10 @@ extern "C" {
 ReMutex FfmpegVideoCursor::_av_lock;
 ReMutex FfmpegVideoCursor::_av_lock;
 TypeHandle FfmpegVideoCursor::_type_handle;
 TypeHandle FfmpegVideoCursor::_type_handle;
 
 
+PStatCollector FfmpegVideoCursor::_fetch_buffer_pcollector("*:FFMPEG Video Decoding:Fetch");
+PStatCollector FfmpegVideoCursor::_seek_pcollector("*:FFMPEG Video Decoding:Seek");
+PStatCollector FfmpegVideoCursor::_export_frame_pcollector("*:FFMPEG Convert Video to BGR");
+
 
 
 #if LIBAVFORMAT_VERSION_MAJOR < 53
 #if LIBAVFORMAT_VERSION_MAJOR < 53
   #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
   #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
@@ -898,8 +902,7 @@ flip_packets() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FfmpegVideoCursor::
 void FfmpegVideoCursor::
 fetch_frame(int frame) {
 fetch_frame(int frame) {
-  static PStatCollector fetch_buffer_pcollector("*:FFMPEG Video Decoding:Fetch");
-  PStatTimer timer(fetch_buffer_pcollector);
+  PStatTimer timer(_fetch_buffer_pcollector);
 
 
   int finished = 0;
   int finished = 0;
 
 
@@ -918,8 +921,7 @@ fetch_frame(int frame) {
       return;
       return;
     }
     }
     while (_packet_frame <= frame) {
     while (_packet_frame <= frame) {
-      static PStatCollector seek_pcollector("*:FFMPEG Video Decoding:Seek");
-      PStatTimer timer(seek_pcollector);
+      PStatTimer timer(_seek_pcollector);
 
 
       // Decode and discard the previous packet.
       // Decode and discard the previous packet.
       decode_frame(finished, _packet1);
       decode_frame(finished, _packet1);
@@ -993,8 +995,7 @@ do_decode_frame(int &finished, AVPacket *packet) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FfmpegVideoCursor::
 void FfmpegVideoCursor::
 seek(int frame, bool backward) {
 seek(int frame, bool backward) {
-  static PStatCollector seek_pcollector("*:FFMPEG Video Decoding:Seek");
-  PStatTimer timer(seek_pcollector);
+  PStatTimer timer(_seek_pcollector);
 
 
   if (ffmpeg_support_seek) {
   if (ffmpeg_support_seek) {
     if (ffmpeg_global_lock) {
     if (ffmpeg_global_lock) {
@@ -1121,8 +1122,7 @@ reset_stream() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FfmpegVideoCursor::
 void FfmpegVideoCursor::
 advance_to_frame(int frame) {
 advance_to_frame(int frame) {
-  static PStatCollector fetch_buffer_pcollector("*:FFMPEG Video Decoding:Fetch");
-  PStatTimer timer(fetch_buffer_pcollector);
+  PStatTimer timer(_fetch_buffer_pcollector);
 
 
   if (frame < _begin_frame) {
   if (frame < _begin_frame) {
     // Frame is in the past.
     // Frame is in the past.
@@ -1210,8 +1210,7 @@ advance_to_frame(int frame) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FfmpegVideoCursor::
 void FfmpegVideoCursor::
 export_frame(FfmpegBuffer *buffer) {
 export_frame(FfmpegBuffer *buffer) {
-  static PStatCollector export_frame_collector("*:FFMPEG Convert Video to BGR");
-  PStatTimer timer(export_frame_collector);
+  PStatTimer timer(_export_frame_pcollector);
 
 
   if (!_frame_ready) {
   if (!_frame_ready) {
     // No frame data ready, just fill with black.
     // No frame data ready, just fill with black.

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

@@ -155,6 +155,11 @@ private:
   bool _frame_ready;
   bool _frame_ready;
   bool _eof_known;
   bool _eof_known;
   int _eof_frame;
   int _eof_frame;
+
+  // PStat collectors.
+  static PStatCollector _fetch_buffer_pcollector;
+  static PStatCollector _seek_pcollector;
+  static PStatCollector _export_frame_pcollector;
   
   
 public:
 public:
   static void register_with_read_factory();
   static void register_with_read_factory();

+ 3 - 1
panda/src/pstatclient/Sources.pp

@@ -23,7 +23,9 @@
   #define INCLUDED_SOURCES  \
   #define INCLUDED_SOURCES  \
      config_pstats.cxx pStatClient.cxx pStatClientImpl.cxx \
      config_pstats.cxx pStatClient.cxx pStatClientImpl.cxx \
      pStatClientVersion.cxx  \
      pStatClientVersion.cxx  \
-     pStatClientControlMessage.cxx pStatCollectorDef.cxx  \
+     pStatClientControlMessage.cxx \
+     pStatCollector.cxx \
+     pStatCollectorDef.cxx  \
      pStatCollectorForward.cxx \
      pStatCollectorForward.cxx \
      pStatFrameData.cxx pStatProperties.cxx  \
      pStatFrameData.cxx pStatProperties.cxx  \
      pStatServerControlMessage.cxx \
      pStatServerControlMessage.cxx \

+ 1 - 0
panda/src/pstatclient/pStatCollector.I

@@ -472,6 +472,7 @@ is_started(const PStatThread &thread) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void PStatCollector::
 INLINE void PStatCollector::
 start(const PStatThread &thread) {
 start(const PStatThread &thread) {
+  nassertv(_client != NULL);
   _client->start(_index, thread._index);
   _client->start(_index, thread._index);
 }
 }
 
 

+ 15 - 0
panda/src/pstatclient/pStatCollector.cxx

@@ -0,0 +1,15 @@
+// Filename: pStatCollector.cxx
+// Created by:  drose (18Nov11)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "pStatCollector.h"

+ 1 - 0
panda/src/pstatclient/pstatclient_composite1.cxx

@@ -4,3 +4,4 @@
 #include "pStatClientImpl.cxx"
 #include "pStatClientImpl.cxx"
 #include "pStatClientVersion.cxx"
 #include "pStatClientVersion.cxx"
 #include "pStatClientControlMessage.cxx"
 #include "pStatClientControlMessage.cxx"
+#include "pStatCollector.cxx"