From ddcd74047b6f7e68142866c1b288fed8e69f6b89 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 10 Feb 2014 11:24:36 +0000 Subject: [PATCH] more error checks and allow disabling seeking and VFS behaviour --- panda/src/movies/config_movies.cxx | 10 ++++++++++ panda/src/movies/config_movies.h | 2 ++ panda/src/movies/vorbisAudioCursor.cxx | 23 +++++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/panda/src/movies/config_movies.cxx b/panda/src/movies/config_movies.cxx index a38f5976d7..d5a01b272d 100644 --- a/panda/src/movies/config_movies.cxx +++ b/panda/src/movies/config_movies.cxx @@ -50,6 +50,16 @@ ConfigVariableList load_video_type "either the name of a module, or a space-separate list of filename " "extensions, followed by the name of the module.")); +ConfigVariableBool vorbis_enable_vfs +("vorbis-enable-vfs", true, + PRC_DESC("Set this to false if you're having trouble loading Ogg Vorbis " + "files and don't need to use the virtual file system.")); + +ConfigVariableBool vorbis_enable_seek +("vorbis-enable-seek", true, + PRC_DESC("Set this to false if you're having trouble with seeking while " + "using the Ogg Vorbis decoder.")); + ConfigVariableBool vorbis_seek_lap ("vorbis-seek-lap", true, PRC_DESC("If this is set to true, the Ogg Vorbis decoder will automatically " diff --git a/panda/src/movies/config_movies.h b/panda/src/movies/config_movies.h index d0c02724d8..ada94cb98c 100644 --- a/panda/src/movies/config_movies.h +++ b/panda/src/movies/config_movies.h @@ -28,6 +28,8 @@ NotifyCategoryDecl(movies, EXPCL_PANDA_MOVIES, EXPTP_PANDA_MOVIES); extern ConfigVariableList load_audio_type; extern ConfigVariableList load_video_type; +extern ConfigVariableBool vorbis_enable_vfs; +extern ConfigVariableBool vorbis_enable_seek; extern ConfigVariableBool vorbis_seek_lap; extern EXPCL_PANDA_MOVIES void init_libmovies(); diff --git a/panda/src/movies/vorbisAudioCursor.cxx b/panda/src/movies/vorbisAudioCursor.cxx index a0265f10ed..b6a8d2d6a6 100644 --- a/panda/src/movies/vorbisAudioCursor.cxx +++ b/panda/src/movies/vorbisAudioCursor.cxx @@ -37,10 +37,15 @@ VorbisAudioCursor(VorbisAudio *src, istream *stream) : // Set up the callbacks to read via the VFS. ov_callbacks callbacks; callbacks.read_func = &cb_read_func; - callbacks.seek_func = &cb_seek_func; callbacks.close_func = &cb_close_func; callbacks.tell_func = &cb_tell_func; + if (vorbis_enable_seek) { + callbacks.seek_func = &cb_seek_func; + } else { + callbacks.seek_func = NULL; + } + if (ov_open_callbacks((void*) stream, &_ov, NULL, 0, callbacks) != 0) { movies_cat.error() << "Failed to read Ogg Vorbis file.\n"; @@ -53,7 +58,7 @@ VorbisAudioCursor(VorbisAudio *src, istream *stream) : _audio_channels = vi->channels; _audio_rate = vi->rate; - _can_seek = (ov_seekable(&_ov) != 0); + _can_seek = vorbis_enable_seek && (ov_seekable(&_ov) != 0); _can_seek_fast = _can_seek; _is_valid = true; @@ -78,6 +83,10 @@ VorbisAudioCursor:: //////////////////////////////////////////////////////////////////// void VorbisAudioCursor:: seek(double t) { + if (!vorbis_enable_seek) { + return; + } + t = max(t, 0.0); // Use ov_time_seek_lap if cross-lapping is enabled. @@ -163,6 +172,7 @@ read_samples(int n, PN_int16 *data) { size_t VorbisAudioCursor:: cb_read_func(void *ptr, size_t size, size_t nmemb, void *datasource) { istream *stream = (istream*) datasource; + nassertr(stream != NULL, -1); stream->read((char *)ptr, size * nmemb); return stream->gcount(); @@ -176,7 +186,12 @@ cb_read_func(void *ptr, size_t size, size_t nmemb, void *datasource) { //////////////////////////////////////////////////////////////////// int VorbisAudioCursor:: cb_seek_func(void *datasource, ogg_int64_t offset, int whence) { + if (!vorbis_enable_seek) { + return -1; + } + istream *stream = (istream*) datasource; + nassertr(stream != NULL, -1); switch (whence) { case SEEK_SET: @@ -213,6 +228,8 @@ cb_seek_func(void *datasource, ogg_int64_t offset, int whence) { int VorbisAudioCursor:: cb_close_func(void *datasource) { istream *stream = (istream*) datasource; + nassertr(stream != NULL, -1); + VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); vfs->close_read_file(stream); @@ -229,6 +246,8 @@ cb_close_func(void *datasource) { long VorbisAudioCursor:: cb_tell_func(void *datasource) { istream *stream = (istream*) datasource; + nassertr(stream != NULL, -1); + return stream->tellg(); }