diff options
Diffstat (limited to 'modules/vorbis')
-rw-r--r-- | modules/vorbis/SCsub | 11 | ||||
-rw-r--r-- | modules/vorbis/audio_stream_ogg_vorbis.cpp | 406 | ||||
-rw-r--r-- | modules/vorbis/audio_stream_ogg_vorbis.h | 137 | ||||
-rw-r--r-- | modules/vorbis/register_types.cpp | 17 | ||||
-rw-r--r-- | modules/vorbis/stub/register_types.cpp | 37 | ||||
-rw-r--r-- | modules/vorbis/stub/register_types.h | 32 |
6 files changed, 8 insertions, 632 deletions
diff --git a/modules/vorbis/SCsub b/modules/vorbis/SCsub index 3824fdd789..bde4359595 100644 --- a/modules/vorbis/SCsub +++ b/modules/vorbis/SCsub @@ -3,6 +3,9 @@ Import('env') Import('env_modules') +# Only kept to build the thirdparty library used by the theora and webm +# modules. We now use stb_vorbis for AudioStreamOGGVorbis. + env_vorbis = env_modules.Clone() stub = True @@ -50,9 +53,5 @@ if env['builtin_libvorbis']: env_thirdparty.disable_warnings() env_thirdparty.add_source_files(env.modules_sources, thirdparty_sources) -if not stub: - # Module files - env_vorbis.add_source_files(env.modules_sources, "*.cpp") -else: - # Module files - env_vorbis.add_source_files(env.modules_sources, "stub/register_types.cpp") +# Module files +env_vorbis.add_source_files(env.modules_sources, "register_types.cpp") diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp deleted file mode 100644 index 1e8ee9b17e..0000000000 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ /dev/null @@ -1,406 +0,0 @@ -/*************************************************************************/ -/* audio_stream_ogg_vorbis.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "audio_stream_ogg_vorbis.h" - -size_t AudioStreamPlaybackOGGVorbis::_ov_read_func(void *p_dst, size_t p_data, size_t p_count, void *_f) { - - //printf("read to %p, %i bytes, %i nmemb, %p\n",p_dst,p_data,p_count,_f); - FileAccess *fa = (FileAccess *)_f; - size_t read_total = p_data * p_count; - - if (fa->eof_reached()) - return 0; - - uint8_t *dst = (uint8_t *)p_dst; - - int read = fa->get_buffer(dst, read_total); - - return read; -} - -int AudioStreamPlaybackOGGVorbis::_ov_seek_func(void *_f, ogg_int64_t offs, int whence) { - - //printf("seek to %p, offs %i, whence %i\n",_f,(int)offs,whence); - -#ifdef SEEK_SET - //printf("seek set defined\n"); - FileAccess *fa = (FileAccess *)_f; - - if (whence == SEEK_SET) { - - fa->seek(offs); - } else if (whence == SEEK_CUR) { - - fa->seek(fa->get_position() + offs); - } else if (whence == SEEK_END) { - - fa->seek_end(offs); - } else { - - ERR_PRINT("Vorbis seek function failure: Unexpected value in _whence\n"); - } - int ret = fa->eof_reached() ? -1 : 0; - //printf("returning %i\n",ret); - return ret; - -#else - return -1; // no seeking -#endif -} -int AudioStreamPlaybackOGGVorbis::_ov_close_func(void *_f) { - - //printf("close %p\n",_f); - if (!_f) - return 0; - FileAccess *fa = (FileAccess *)_f; - if (fa->is_open()) - fa->close(); - return 0; -} -long AudioStreamPlaybackOGGVorbis::_ov_tell_func(void *_f) { - - //printf("close %p\n",_f); - - FileAccess *fa = (FileAccess *)_f; - return fa->get_position(); -} - -int AudioStreamPlaybackOGGVorbis::mix(int16_t *p_buffer, int p_frames) { - - if (!playing) - return 0; - - int total = p_frames; - while (true) { - - int todo = p_frames; - - if (todo < MIN_MIX) { - break; - } - -#ifdef BIG_ENDIAN_ENABLED - long ret = ov_read(&vf, (char *)p_buffer, todo * stream_channels * sizeof(int16_t), 1, 2, 1, ¤t_section); -#else - long ret = ov_read(&vf, (char *)p_buffer, todo * stream_channels * sizeof(int16_t), 0, 2, 1, ¤t_section); -#endif - - if (ret < 0) { - - playing = false; - ERR_BREAK_MSG(ret < 0, "Error reading OGG Vorbis file: " + file + "."); - } else if (ret == 0) { // end of song, reload? - - ov_clear(&vf); - - _close_file(); - - if (!has_loop()) { - - playing = false; - repeats = 1; - break; - } - - f = FileAccess::open(file, FileAccess::READ); - - int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks); - if (errv != 0) { - playing = false; - break; // :( - } - - if (loop_restart_time) { - bool ok = ov_time_seek(&vf, loop_restart_time) == 0; - if (!ok) { - playing = false; - ERR_PRINT("Loop restart time rejected"); - } - - frames_mixed = stream_srate * loop_restart_time; - } else { - - frames_mixed = 0; - } - repeats++; - continue; - } - - ret /= stream_channels; - ret /= sizeof(int16_t); - - frames_mixed += ret; - - p_buffer += ret * stream_channels; - p_frames -= ret; - } - - return total - p_frames; -} - -void AudioStreamPlaybackOGGVorbis::play(float p_from) { - - if (playing) - stop(); - - if (_load_stream() != OK) - return; - - frames_mixed = 0; - playing = true; - if (p_from > 0) { - seek(p_from); - } -} - -void AudioStreamPlaybackOGGVorbis::_close_file() { - - if (f) { - - memdelete(f); - f = NULL; - } -} - -bool AudioStreamPlaybackOGGVorbis::is_playing() const { - return playing; -} -void AudioStreamPlaybackOGGVorbis::stop() { - - _clear_stream(); - playing = false; - //_clear(); -} - -float AudioStreamPlaybackOGGVorbis::get_playback_position() const { - - int32_t frames = int32_t(frames_mixed); - if (frames < 0) - frames = 0; - return double(frames) / stream_srate; -} - -void AudioStreamPlaybackOGGVorbis::seek(float p_time) { - - if (!playing) - return; - bool ok = ov_time_seek(&vf, p_time) == 0; - ERR_FAIL_COND(!ok); - frames_mixed = stream_srate * p_time; -} - -String AudioStreamPlaybackOGGVorbis::get_stream_name() const { - - return ""; -} - -void AudioStreamPlaybackOGGVorbis::set_loop(bool p_enable) { - - loops = p_enable; -} - -bool AudioStreamPlaybackOGGVorbis::has_loop() const { - - return loops; -} - -int AudioStreamPlaybackOGGVorbis::get_loop_count() const { - return repeats; -} - -Error AudioStreamPlaybackOGGVorbis::set_file(const String &p_file) { - - file = p_file; - stream_valid = false; - Error err; - f = FileAccess::open(file, FileAccess::READ, &err); - ERR_FAIL_COND_V_MSG(err, err, "Cannot open file '" + p_file + "'."); - - int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks); - switch (errv) { - - case OV_EREAD: { // - A read from media returned an error. - memdelete(f); - f = NULL; - ERR_FAIL_V(ERR_FILE_CANT_READ); - } break; - case OV_EVERSION: // - Vorbis version mismatch. - case OV_ENOTVORBIS: { // - Bitstream is not Vorbis data. - memdelete(f); - f = NULL; - ERR_FAIL_V(ERR_FILE_UNRECOGNIZED); - } break; - case OV_EBADHEADER: { // - Invalid Vorbis bitstream header. - memdelete(f); - f = NULL; - ERR_FAIL_V(ERR_FILE_CORRUPT); - } break; - case OV_EFAULT: { // - Internal logic fault; indicates a bug or heap/stack corruption. - memdelete(f); - f = NULL; - ERR_FAIL_V(ERR_BUG); - } break; - } - const vorbis_info *vinfo = ov_info(&vf, -1); - stream_channels = vinfo->channels; - stream_srate = vinfo->rate; - length = ov_time_total(&vf, -1); - ov_clear(&vf); - memdelete(f); - f = NULL; - stream_valid = true; - - return OK; -} - -Error AudioStreamPlaybackOGGVorbis::_load_stream() { - - ERR_FAIL_COND_V(!stream_valid, ERR_UNCONFIGURED); - - _clear_stream(); - if (file == "") - return ERR_INVALID_DATA; - - Error err; - f = FileAccess::open(file, FileAccess::READ, &err); - ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + file + "'."); - - int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks); - switch (errv) { - - case OV_EREAD: { // - A read from media returned an error. - memdelete(f); - f = NULL; - ERR_FAIL_V(ERR_FILE_CANT_READ); - } break; - case OV_EVERSION: // - Vorbis version mismatch. - case OV_ENOTVORBIS: { // - Bitstream is not Vorbis data. - memdelete(f); - f = NULL; - ERR_FAIL_V(ERR_FILE_UNRECOGNIZED); - } break; - case OV_EBADHEADER: { // - Invalid Vorbis bitstream header. - memdelete(f); - f = NULL; - ERR_FAIL_V(ERR_FILE_CORRUPT); - } break; - case OV_EFAULT: { // - Internal logic fault; indicates a bug or heap/stack corruption. - memdelete(f); - f = NULL; - ERR_FAIL_V(ERR_BUG); - } break; - } - repeats = 0; - stream_loaded = true; - - return OK; -} - -float AudioStreamPlaybackOGGVorbis::get_length() const { - - if (!stream_loaded) { - if (const_cast<AudioStreamPlaybackOGGVorbis *>(this)->_load_stream() != OK) - return 0; - } - return length; -} - -void AudioStreamPlaybackOGGVorbis::_clear_stream() { - - if (!stream_loaded) - return; - - ov_clear(&vf); - _close_file(); - - stream_loaded = false; - //stream_channels=1; - playing = false; -} - -void AudioStreamPlaybackOGGVorbis::set_paused(bool p_paused) { - - paused = p_paused; -} - -bool AudioStreamPlaybackOGGVorbis::is_paused() const { - - return paused; -} - -AudioStreamPlaybackOGGVorbis::AudioStreamPlaybackOGGVorbis() { - - loops = false; - playing = false; - _ov_callbacks.read_func = _ov_read_func; - _ov_callbacks.seek_func = _ov_seek_func; - _ov_callbacks.close_func = _ov_close_func; - _ov_callbacks.tell_func = _ov_tell_func; - f = NULL; - stream_loaded = false; - stream_valid = false; - repeats = 0; - paused = true; - stream_channels = 0; - stream_srate = 0; - current_section = 0; - length = 0; - loop_restart_time = 0; -} - -AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() { - - _clear_stream(); -} - -RES ResourceFormatLoaderAudioStreamOGGVorbis::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { - if (r_error) - *r_error = OK; - - AudioStreamOGGVorbis *ogg_stream = memnew(AudioStreamOGGVorbis); - ogg_stream->set_file(p_path); - return Ref<AudioStreamOGGVorbis>(ogg_stream); -} - -void ResourceFormatLoaderAudioStreamOGGVorbis::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("ogg"); -} -String ResourceFormatLoaderAudioStreamOGGVorbis::get_resource_type(const String &p_path) const { - - if (p_path.get_extension().to_lower() == "ogg") - return "AudioStreamOGGVorbis"; - return ""; -} - -bool ResourceFormatLoaderAudioStreamOGGVorbis::handles_type(const String &p_type) const { - return (p_type == "AudioStream" || p_type == "AudioStreamOGG" || p_type == "AudioStreamOGGVorbis"); -} diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h deleted file mode 100644 index db621f88d2..0000000000 --- a/modules/vorbis/audio_stream_ogg_vorbis.h +++ /dev/null @@ -1,137 +0,0 @@ -/*************************************************************************/ -/* audio_stream_ogg_vorbis.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef AUDIO_STREAM_OGG_VORBIS_H -#define AUDIO_STREAM_OGG_VORBIS_H - -#include "core/io/resource_loader.h" -#include "core/os/file_access.h" -#include "core/os/thread_safe.h" -#include "scene/resources/audio_stream.h" - -#include <vorbis/vorbisfile.h> - -class AudioStreamPlaybackOGGVorbis : public AudioStreamPlayback { - - GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlayback); - - enum { - MIN_MIX = 1024 - }; - - FileAccess *f; - - ov_callbacks _ov_callbacks; - float length; - static size_t _ov_read_func(void *p_dst, size_t p_data, size_t p_count, void *_f); - static int _ov_seek_func(void *_f, ogg_int64_t offs, int whence); - static int _ov_close_func(void *_f); - static long _ov_tell_func(void *_f); - - String file; - int64_t frames_mixed; - - bool stream_loaded; - volatile bool playing; - OggVorbis_File vf; - int stream_channels; - int stream_srate; - int current_section; - - bool paused; - bool loops; - int repeats; - - Error _load_stream(); - void _clear_stream(); - void _close_file(); - - bool stream_valid; - float loop_restart_time; - -public: - Error set_file(const String &p_file); - - virtual void play(float p_from = 0); - virtual void stop(); - virtual bool is_playing() const; - - virtual void set_loop_restart_time(float p_time) { loop_restart_time = p_time; } - - virtual void set_paused(bool p_paused); - virtual bool is_paused() const; - - virtual void set_loop(bool p_enable); - virtual bool has_loop() const; - - virtual float get_length() const; - - virtual String get_stream_name() const; - - virtual int get_loop_count() const; - - virtual float get_playback_position() const; - virtual void seek(float p_time); - - virtual int get_channels() const { return stream_channels; } - virtual int get_mix_rate() const { return stream_srate; } - - virtual int get_minimum_buffer_size() const { return 0; } - virtual int mix(int16_t *p_buffer, int p_frames); - - AudioStreamPlaybackOGGVorbis(); - ~AudioStreamPlaybackOGGVorbis(); -}; - -class AudioStreamOGGVorbis : public AudioStream { - - GDCLASS(AudioStreamOGGVorbis, AudioStream); - - String file; - -public: - Ref<AudioStreamPlayback> instance_playback() { - Ref<AudioStreamPlaybackOGGVorbis> pb = memnew(AudioStreamPlaybackOGGVorbis); - pb->set_file(file); - return pb; - } - - void set_file(const String &p_file) { file = p_file; } -}; - -class ResourceFormatLoaderAudioStreamOGGVorbis : public ResourceFormatLoader { -public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; -}; - -#endif // AUDIO_STREAM_OGG_H diff --git a/modules/vorbis/register_types.cpp b/modules/vorbis/register_types.cpp index de055551ad..8874b3887b 100644 --- a/modules/vorbis/register_types.cpp +++ b/modules/vorbis/register_types.cpp @@ -30,19 +30,8 @@ #include "register_types.h" -#include "audio_stream_ogg_vorbis.h" +// Dummy module as libvorbis is needed by other modules (theora ...) -static Ref<ResourceFormatLoaderAudioStreamOGGVorbis> vorbis_stream_loader; +void register_vorbis_types() {} -void register_vorbis_types() { - - vorbis_stream_loader.instance(); - ResourceLoader::add_resource_format_loader(vorbis_stream_loader); - ClassDB::register_class<AudioStreamOGGVorbis>(); -} - -void unregister_vorbis_types() { - - ResourceLoader::remove_resource_format_loader(vorbis_stream_loader); - vorbis_stream_loader.unref(); -} +void unregister_vorbis_types() {} diff --git a/modules/vorbis/stub/register_types.cpp b/modules/vorbis/stub/register_types.cpp deleted file mode 100644 index 8874b3887b..0000000000 --- a/modules/vorbis/stub/register_types.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "register_types.h" - -// Dummy module as libvorbis is needed by other modules (theora ...) - -void register_vorbis_types() {} - -void unregister_vorbis_types() {} diff --git a/modules/vorbis/stub/register_types.h b/modules/vorbis/stub/register_types.h deleted file mode 100644 index 83d4904a87..0000000000 --- a/modules/vorbis/stub/register_types.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -void register_vorbis_types(); -void unregister_vorbis_types(); |