Browse Source

add ffmpeg-thread-priority

David Rose 14 năm trước cách đây
mục cha
commit
2584e3d57d

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

@@ -50,6 +50,11 @@ ConfigVariableInt ffmpeg_max_readahead_frames
           "should read in advance of actual playback.  Set this to 0 to "
           "should read in advance of actual playback.  Set this to 0 to "
           "decode ffmpeg videos in the main thread."));
           "decode ffmpeg videos in the main thread."));
 
 
+ConfigVariableEnum<ThreadPriority> ffmpeg_thread_priority
+("ffmpeg-thread-priority", TP_normal,
+ PRC_DESC("The default thread priority at which to run the ffmpeg decoder thread "
+          "for a given video texture."));
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: init_libmovies
 //     Function: init_libmovies
 //  Description: Initializes the library.  This must be called at
 //  Description: Initializes the library.  This must be called at

+ 3 - 1
panda/src/movies/config_movies.h

@@ -18,7 +18,8 @@
 #include "pandabase.h"
 #include "pandabase.h"
 #include "notifyCategoryProxy.h"
 #include "notifyCategoryProxy.h"
 #include "configVariableEnum.h"
 #include "configVariableEnum.h"
-#include "configVariableDouble.h"
+#include "configVariableInt.h"
+#include "threadPriority.h"
 #include "dconfig.h"
 #include "dconfig.h"
 
 
 ConfigureDecl(config_movies, EXPCL_PANDA_MOVIES, EXPTP_PANDA_MOVIES);
 ConfigureDecl(config_movies, EXPCL_PANDA_MOVIES, EXPTP_PANDA_MOVIES);
@@ -26,6 +27,7 @@ NotifyCategoryDecl(movies, EXPCL_PANDA_MOVIES, EXPTP_PANDA_MOVIES);
 NotifyCategoryDecl(ffmpeg, EXPCL_PANDA_MOVIES, EXPTP_PANDA_MOVIES);
 NotifyCategoryDecl(ffmpeg, EXPCL_PANDA_MOVIES, EXPTP_PANDA_MOVIES);
 
 
 extern ConfigVariableInt ffmpeg_max_readahead_frames;
 extern ConfigVariableInt ffmpeg_max_readahead_frames;
+extern ConfigVariableEnum<ThreadPriority> ffmpeg_thread_priority;
 
 
 extern EXPCL_PANDA_MOVIES void init_libmovies();
 extern EXPCL_PANDA_MOVIES void init_libmovies();
 
 

+ 38 - 1
panda/src/movies/ffmpegVideoCursor.cxx

@@ -43,6 +43,7 @@ TypeHandle FfmpegVideoCursor::_type_handle;
 FfmpegVideoCursor::
 FfmpegVideoCursor::
 FfmpegVideoCursor() :
 FfmpegVideoCursor() :
   _max_readahead_frames(0),
   _max_readahead_frames(0),
+  _thread_priority(ffmpeg_thread_priority),
   _lock("FfmpegVideoCursor::_lock"),
   _lock("FfmpegVideoCursor::_lock"),
   _action_cvar(_lock),
   _action_cvar(_lock),
   _thread_status(TS_stopped),
   _thread_status(TS_stopped),
@@ -171,6 +172,7 @@ init_from(FfmpegVideo *source) {
 FfmpegVideoCursor::
 FfmpegVideoCursor::
 FfmpegVideoCursor(FfmpegVideo *src) : 
 FfmpegVideoCursor(FfmpegVideo *src) : 
   _max_readahead_frames(0),
   _max_readahead_frames(0),
+  _thread_priority(ffmpeg_thread_priority),
   _lock("FfmpegVideoCursor::_lock"),
   _lock("FfmpegVideoCursor::_lock"),
   _action_cvar(_lock),
   _action_cvar(_lock),
   _thread_status(TS_stopped),
   _thread_status(TS_stopped),
@@ -249,6 +251,41 @@ get_max_readahead_frames() const {
   return _max_readahead_frames;
   return _max_readahead_frames;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegVideoCursor::set_thread_priority
+//       Access: Published
+//  Description: Changes the thread priority of the thread that
+//               decodes the ffmpeg video stream (if
+//               max_readahead_frames is nonzero).  Normally you
+//               shouldn't mess with this, but there may be special
+//               cases where a precise balance of CPU utilization
+//               between the main thread and the various ffmpeg
+//               service threads may be needed.
+////////////////////////////////////////////////////////////////////
+void FfmpegVideoCursor::
+set_thread_priority(ThreadPriority thread_priority) {
+  if (_thread_priority != thread_priority) {
+    _thread_priority = thread_priority;
+    if (is_thread_started()) {
+      stop_thread();
+      start_thread();
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegVideoCursor::get_thread_priority
+//       Access: Published
+//  Description: Returns the current thread priority of the thread that
+//               decodes the ffmpeg video stream (if
+//               max_readahead_frames is nonzero).  See
+//               set_thread_priority().
+////////////////////////////////////////////////////////////////////
+ThreadPriority FfmpegVideoCursor::
+get_thread_priority() const {
+  return _thread_priority;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: FfmpegVideoCursor::start_thread
 //     Function: FfmpegVideoCursor::start_thread
 //       Access: Published
 //       Access: Published
@@ -271,7 +308,7 @@ start_thread() {
     // Create and start the thread object.
     // Create and start the thread object.
     _thread_status = TS_wait;
     _thread_status = TS_wait;
     _thread = new GenericThread(_filename.get_basename(), _sync_name, st_thread_main, this);
     _thread = new GenericThread(_filename.get_basename(), _sync_name, st_thread_main, this);
-    if (!_thread->start(TP_normal, true)) {
+    if (!_thread->start(_thread_priority, true)) {
       // Couldn't start the thread.
       // Couldn't start the thread.
       _thread = NULL;
       _thread = NULL;
       _thread_status = TS_stopped;
       _thread_status = TS_stopped;

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

@@ -24,6 +24,7 @@
 #include "pointerTo.h"
 #include "pointerTo.h"
 #include "ffmpegVirtualFile.h"
 #include "ffmpegVirtualFile.h"
 #include "genericThread.h"
 #include "genericThread.h"
+#include "threadPriority.h"
 #include "pmutex.h"
 #include "pmutex.h"
 #include "conditionVar.h"
 #include "conditionVar.h"
 
 
@@ -49,6 +50,9 @@ PUBLISHED:
   void set_max_readahead_frames(int max_readahead_frames);
   void set_max_readahead_frames(int max_readahead_frames);
   int get_max_readahead_frames() const;
   int get_max_readahead_frames() const;
 
 
+  void set_thread_priority(ThreadPriority thread_priority);
+  ThreadPriority get_thread_priority() const;
+
   void start_thread();
   void start_thread();
   BLOCKING void stop_thread();
   BLOCKING void stop_thread();
   bool is_thread_started() const;
   bool is_thread_started() const;
@@ -63,6 +67,7 @@ private:
   Filename _filename;
   Filename _filename;
   string _sync_name;
   string _sync_name;
   int _max_readahead_frames;
   int _max_readahead_frames;
+  ThreadPriority _thread_priority;
   PT(GenericThread) _thread;
   PT(GenericThread) _thread;
 
 
   // This global Mutex protects calls to avcodec_open/close/etc.
   // This global Mutex protects calls to avcodec_open/close/etc.