mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
more error checks and allow disabling seeking and VFS behaviour
This commit is contained in:
parent
67d12cdd4a
commit
ddcd74047b
@ -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 "
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user