From 2584e3d57d88c715a76f7f06af7503330df53edb Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 11 Nov 2011 17:59:51 +0000 Subject: [PATCH] add ffmpeg-thread-priority --- panda/src/movies/config_movies.cxx | 5 ++++ panda/src/movies/config_movies.h | 4 ++- panda/src/movies/ffmpegVideoCursor.cxx | 39 +++++++++++++++++++++++++- panda/src/movies/ffmpegVideoCursor.h | 5 ++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/panda/src/movies/config_movies.cxx b/panda/src/movies/config_movies.cxx index 3609a50660..cd06ea7c6b 100644 --- a/panda/src/movies/config_movies.cxx +++ b/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 " "decode ffmpeg videos in the main thread.")); +ConfigVariableEnum 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 // Description: Initializes the library. This must be called at diff --git a/panda/src/movies/config_movies.h b/panda/src/movies/config_movies.h index e7617e24d1..4d2a238580 100644 --- a/panda/src/movies/config_movies.h +++ b/panda/src/movies/config_movies.h @@ -18,7 +18,8 @@ #include "pandabase.h" #include "notifyCategoryProxy.h" #include "configVariableEnum.h" -#include "configVariableDouble.h" +#include "configVariableInt.h" +#include "threadPriority.h" #include "dconfig.h" 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); extern ConfigVariableInt ffmpeg_max_readahead_frames; +extern ConfigVariableEnum ffmpeg_thread_priority; extern EXPCL_PANDA_MOVIES void init_libmovies(); diff --git a/panda/src/movies/ffmpegVideoCursor.cxx b/panda/src/movies/ffmpegVideoCursor.cxx index f4b3c9c004..178c811a56 100644 --- a/panda/src/movies/ffmpegVideoCursor.cxx +++ b/panda/src/movies/ffmpegVideoCursor.cxx @@ -43,6 +43,7 @@ TypeHandle FfmpegVideoCursor::_type_handle; FfmpegVideoCursor:: FfmpegVideoCursor() : _max_readahead_frames(0), + _thread_priority(ffmpeg_thread_priority), _lock("FfmpegVideoCursor::_lock"), _action_cvar(_lock), _thread_status(TS_stopped), @@ -171,6 +172,7 @@ init_from(FfmpegVideo *source) { FfmpegVideoCursor:: FfmpegVideoCursor(FfmpegVideo *src) : _max_readahead_frames(0), + _thread_priority(ffmpeg_thread_priority), _lock("FfmpegVideoCursor::_lock"), _action_cvar(_lock), _thread_status(TS_stopped), @@ -249,6 +251,41 @@ get_max_readahead_frames() const { 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 // Access: Published @@ -271,7 +308,7 @@ start_thread() { // Create and start the thread object. _thread_status = TS_wait; _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. _thread = NULL; _thread_status = TS_stopped; diff --git a/panda/src/movies/ffmpegVideoCursor.h b/panda/src/movies/ffmpegVideoCursor.h index 3b7dfd09ce..fcf0106346 100644 --- a/panda/src/movies/ffmpegVideoCursor.h +++ b/panda/src/movies/ffmpegVideoCursor.h @@ -24,6 +24,7 @@ #include "pointerTo.h" #include "ffmpegVirtualFile.h" #include "genericThread.h" +#include "threadPriority.h" #include "pmutex.h" #include "conditionVar.h" @@ -49,6 +50,9 @@ PUBLISHED: void set_max_readahead_frames(int max_readahead_frames); int get_max_readahead_frames() const; + void set_thread_priority(ThreadPriority thread_priority); + ThreadPriority get_thread_priority() const; + void start_thread(); BLOCKING void stop_thread(); bool is_thread_started() const; @@ -63,6 +67,7 @@ private: Filename _filename; string _sync_name; int _max_readahead_frames; + ThreadPriority _thread_priority; PT(GenericThread) _thread; // This global Mutex protects calls to avcodec_open/close/etc.