From 1ba1998223ad88ce89018e7b72adc7c0560bf2d6 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Fri, 13 Aug 2010 16:12:57 +0200 Subject: [PATCH] Added niceified openal+ffmpeg handler, with test --- sound/filters/openal_audiere.hpp | 4 +- sound/filters/openal_ffmpeg.hpp | 23 ++++++++++ sound/tests/Makefile | 5 ++- sound/tests/openal_ffmpeg_test.cpp | 52 +++++++++++++++++++++++ sound/tests/output/openal_ffmpeg_test.out | 2 + 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 sound/filters/openal_ffmpeg.hpp create mode 100644 sound/tests/openal_ffmpeg_test.cpp create mode 100644 sound/tests/output/openal_ffmpeg_test.out diff --git a/sound/filters/openal_audiere.hpp b/sound/filters/openal_audiere.hpp index 5b62bd11b1..5b9b518249 100644 --- a/sound/filters/openal_audiere.hpp +++ b/sound/filters/openal_audiere.hpp @@ -1,5 +1,5 @@ -#ifndef MANGLE_FFMPEG_OPENAL_H -#define MANGLE_FFMPEG_OPENAL_H +#ifndef MANGLE_AUDIERE_OPENAL_H +#define MANGLE_AUDIERE_OPENAL_H #include "input_filter.hpp" #include "../sources/audiere_source.hpp" diff --git a/sound/filters/openal_ffmpeg.hpp b/sound/filters/openal_ffmpeg.hpp new file mode 100644 index 0000000000..42c76af0cd --- /dev/null +++ b/sound/filters/openal_ffmpeg.hpp @@ -0,0 +1,23 @@ +#ifndef MANGLE_FFMPEG_OPENAL_H +#define MANGLE_FFMPEG_OPENAL_H + +#include "input_filter.hpp" +#include "../sources/ffmpeg_source.hpp" +#include "../outputs/openal_out.hpp" + +namespace Mangle { +namespace Sound { + +/// A InputFilter that adds ffmpeg decoding to OpenAL. +class OpenAL_FFMpeg_Factory : public InputFilter +{ + public: + OpenAL_FFMpeg_Factory() + { + set(SoundFactoryPtr(new OpenAL_Factory), + SampleSourceLoaderPtr(new FFMpegLoader)); + } +}; + +}} +#endif diff --git a/sound/tests/Makefile b/sound/tests/Makefile index 79c2ecaf81..a23f18025f 100644 --- a/sound/tests/Makefile +++ b/sound/tests/Makefile @@ -1,6 +1,6 @@ GCC=g++ -I../ -all: audiere_source_test ffmpeg_source_test openal_output_test openal_audiere_test +all: audiere_source_test ffmpeg_source_test openal_output_test openal_audiere_test openal_ffmpeg_test L_FFMPEG=$(shell pkg-config --libs libavcodec libavformat) L_OPENAL=$(shell pkg-config --libs openal) @@ -9,6 +9,9 @@ L_AUDIERE=-laudiere openal_audiere_test: openal_audiere_test.cpp ../sources/audiere_source.cpp ../outputs/openal_out.cpp ../../stream/clients/audiere_file.cpp $(GCC) $^ -o $@ $(L_AUDIERE) $(L_OPENAL) +openal_ffmpeg_test: openal_ffmpeg_test.cpp ../sources/ffmpeg_source.cpp ../outputs/openal_out.cpp + $(GCC) $^ -o $@ $(L_FFMPEG) $(L_OPENAL) + openal_output_test: openal_output_test.cpp ../outputs/openal_out.cpp $(GCC) $^ -o $@ $(L_OPENAL) diff --git a/sound/tests/openal_ffmpeg_test.cpp b/sound/tests/openal_ffmpeg_test.cpp new file mode 100644 index 0000000000..d4b8e93003 --- /dev/null +++ b/sound/tests/openal_ffmpeg_test.cpp @@ -0,0 +1,52 @@ +#include +#include + +#include "../../stream/servers/file_stream.hpp" +#include "../filters/openal_ffmpeg.hpp" + +using namespace std; +using namespace Mangle::Stream; +using namespace Mangle::Sound; + +OpenAL_FFMpeg_Factory mg; + +void play(const char* name, bool stream=false) +{ + // Only load streams if the backend supports it + if(stream && !mg.canLoadStream) + return; + + cout << "Playing " << name; + if(stream) cout << " (from stream)"; + cout << "\n"; + + SoundPtr snd; + + try + { + if(stream) + snd = mg.load(StreamPtr(new FileStream(name))); + else + snd = mg.load(name); + + snd->play(); + + while(snd->isPlaying()) + { + usleep(10000); + if(mg.needsUpdate) mg.update(); + } + } + catch(exception &e) + { + cout << " ERROR: " << e.what() << "\n"; + } +} + +int main() +{ + play("cow.wav"); + play("owl.ogg"); + play("cow.wav", true); + return 0; +} diff --git a/sound/tests/output/openal_ffmpeg_test.out b/sound/tests/output/openal_ffmpeg_test.out new file mode 100644 index 0000000000..96e1db0f9a --- /dev/null +++ b/sound/tests/output/openal_ffmpeg_test.out @@ -0,0 +1,2 @@ +Playing cow.wav +Playing owl.ogg