mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-23 05:53:57 +00:00
Added niceified openal+ffmpeg handler, with test
This commit is contained in:
parent
f95ea1677c
commit
1ba1998223
5 changed files with 83 additions and 3 deletions
|
@ -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"
|
||||
|
|
23
sound/filters/openal_ffmpeg.hpp
Normal file
23
sound/filters/openal_ffmpeg.hpp
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
||||
|
|
52
sound/tests/openal_ffmpeg_test.cpp
Normal file
52
sound/tests/openal_ffmpeg_test.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
#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;
|
||||
}
|
2
sound/tests/output/openal_ffmpeg_test.out
Normal file
2
sound/tests/output/openal_ffmpeg_test.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
Playing cow.wav
|
||||
Playing owl.ogg
|
Loading…
Reference in a new issue