From 721f3b139bd4779230fa01d453b0871a8076e5f7 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Tue, 22 Dec 2009 13:04:44 +0100 Subject: [PATCH] Added Stream input method to sound interfaces (not implemented, NOT TESTED YET) --- sound/imp/audiere_imp.cpp | 1 + sound/imp/audiere_imp.h | 4 ++++ sound/imp/input_ffmpeg.cpp | 2 ++ sound/imp/input_ffmpeg.h | 3 +++ sound/imp/input_filter.h | 33 +++++++++++++++++++-------------- sound/imp/output_openal.cpp | 3 +++ sound/imp/output_openal.h | 1 + sound/input.h | 8 ++++++++ sound/sound.h | 15 +++++++++++++++ 9 files changed, 56 insertions(+), 14 deletions(-) diff --git a/sound/imp/audiere_imp.cpp b/sound/imp/audiere_imp.cpp index 266fcb2e2..ecdb0580a 100644 --- a/sound/imp/audiere_imp.cpp +++ b/sound/imp/audiere_imp.cpp @@ -27,6 +27,7 @@ AudiereManager::AudiereManager() canRepeatStream = true; canLoadFile = true; canLoadSource = false; + canLoadStream = false; device = OpenDevice(""); diff --git a/sound/imp/audiere_imp.h b/sound/imp/audiere_imp.h index 083e33258..480611ce3 100644 --- a/sound/imp/audiere_imp.h +++ b/sound/imp/audiere_imp.h @@ -19,6 +19,10 @@ class AudiereManager : public Manager virtual Sound *load(const std::string &file, bool stream=false); + /// not implemented yet + virtual Sound *load(Stream::InputStream *input, bool stream=false) + { assert(0); } + /// disabled virtual Sound *load(InputSource *input, bool stream=false) { assert(0); } diff --git a/sound/imp/input_ffmpeg.cpp b/sound/imp/input_ffmpeg.cpp index 9ce822444..f29ddfdb6 100644 --- a/sound/imp/input_ffmpeg.cpp +++ b/sound/imp/input_ffmpeg.cpp @@ -32,6 +32,8 @@ FFM_InputManager::FFM_InputManager() av_log_set_level(AV_LOG_ERROR); init = true; } + + canLoadStream = false; } InputSource *FFM_InputManager::load(const std::string &file) diff --git a/sound/imp/input_ffmpeg.h b/sound/imp/input_ffmpeg.h index 8c19d381e..cc8feffd4 100644 --- a/sound/imp/input_ffmpeg.h +++ b/sound/imp/input_ffmpeg.h @@ -34,6 +34,9 @@ class FFM_InputManager : public InputManager public: FFM_InputManager(); virtual InputSource *load(const std::string &file); + + /// not supported + virtual InputSource *load(Stream::InputStream *input) { assert(0); } }; /// FFMpeg implementation of InputSource diff --git a/sound/imp/input_filter.h b/sound/imp/input_filter.h index f81f1e8a5..c3da8599d 100644 --- a/sound/imp/input_filter.h +++ b/sound/imp/input_filter.h @@ -43,26 +43,31 @@ class InputFilter : public Manager /// Assign an input manager and a sound manager to this object void set(Manager *_snd, InputManager *_inp) - { - inp = _inp; - snd = _snd; + { + inp = _inp; + snd = _snd; - needsUpdate = snd->needsUpdate; - has3D = snd->has3D; - canRepeatStream = snd->canRepeatStream; + // Set capabilities + needsUpdate = snd->needsUpdate; + has3D = snd->has3D; + canRepeatStream = snd->canRepeatStream; + canLoadStream = inp->canLoadStream; - // Both these should be true, or the use of this class is pretty - // pointless - canLoadSource = snd->canLoadSource; - canLoadFile = canLoadSource; - assert(canLoadSource && canLoadFile); - } + // Both these should be true, or the use of this class is pretty + // pointless + canLoadSource = snd->canLoadSource; + canLoadFile = canLoadSource; + assert(canLoadSource && canLoadFile); + } virtual Sound *load(const std::string &file, bool stream=false) - { return load(inp->load(file), stream); } + { return load(inp->load(file), stream); } + + virtual Sound *load(Stream::InputStream *input, bool stream=false) + { return load(inp->load(input), stream); } virtual Sound *load(InputSource *input, bool stream=false) - { return snd->load(input, stream); } + { return snd->load(input, stream); } virtual void update() { snd->update(); } virtual void setListenerPos(float x, float y, float z, diff --git a/sound/imp/output_openal.cpp b/sound/imp/output_openal.cpp index c56e8c379..190d0638d 100644 --- a/sound/imp/output_openal.cpp +++ b/sound/imp/output_openal.cpp @@ -97,6 +97,9 @@ OpenAL_Manager::~OpenAL_Manager() Sound *OpenAL_Manager::load(const std::string &file, bool stream) { assert(0 && "OpenAL cannot decode files"); } +Sound *OpenAL_Manager::load(Stream::InputStream*,bool) +{ assert(0 && "OpenAL cannot decode streams"); } + Sound *OpenAL_Manager::load(InputSource *source, bool stream) { return new OpenAL_Sound(source, this, stream); } diff --git a/sound/imp/output_openal.h b/sound/imp/output_openal.h index 41f801e5a..bf92197df 100644 --- a/sound/imp/output_openal.h +++ b/sound/imp/output_openal.h @@ -26,6 +26,7 @@ public: void remove_stream(LST::iterator); virtual Sound *load(const std::string &file, bool stream=false); + virtual Sound *load(Stream::InputStream *input, bool stream=false); virtual Sound *load(InputSource* input, bool stream=false); virtual void update(); virtual void setListenerPos(float x, float y, float z, diff --git a/sound/input.h b/sound/input.h index b030885fb..d27de97a6 100644 --- a/sound/input.h +++ b/sound/input.h @@ -4,6 +4,8 @@ #include #include +#include "../stream/input.h" + namespace Mangle { namespace Sound { @@ -64,9 +66,15 @@ class InputSource class InputManager { public: + /// If true, the stream version of load() works + bool canLoadStream; + /// Load a sound input source from file virtual InputSource *load(const std::string &file) = 0; + /// Load a sound input source from stream (if canLoadStream is true) + virtual InputSource *load(Stream::InputStream *input) = 0; + /// Virtual destructor virtual ~InputManager() {} }; diff --git a/sound/sound.h b/sound/sound.h index 0d1aecf6e..90407141e 100644 --- a/sound/sound.h +++ b/sound/sound.h @@ -4,6 +4,8 @@ #include #include "input.h" +#include "../stream/input.h" + namespace Mangle { namespace Sound { @@ -115,6 +117,9 @@ class Manager /// true if we can load sounds from an InputSource bool canLoadSource; + /// If true, we can lound sound files from a Stream + bool canLoadStream; + /** @brief Load a sound from an input source. Only valid if canLoadSource is true. @@ -132,6 +137,16 @@ class Manager */ virtual Sound *load(InputSource *input, bool stream=false) = 0; + /** + @brief Load a sound directly from file. Only valid if canLoadStream + is true. + + @param input audio file stream + @param stream true if the file should be streamed + @see load(InputSource*,bool) + */ + virtual Sound *load(Stream::InputStream *input, bool stream=false) = 0; + /** @brief Load a sound directly from file. Only valid if canLoadFile is true.