add ffmpeg-thread-priority

This commit is contained in:
David Rose 2011-11-11 17:59:51 +00:00
parent 0f96fafca5
commit 2584e3d57d
4 changed files with 51 additions and 2 deletions

View File

@ -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<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
// Description: Initializes the library. This must be called at

View File

@ -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<ThreadPriority> ffmpeg_thread_priority;
extern EXPCL_PANDA_MOVIES void init_libmovies();

View File

@ -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;

View File

@ -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.