From cdca68a36800e02d99fe23fc81a075c4c2177865 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Fri, 1 Jan 2010 20:18:11 +0100 Subject: [PATCH] Fixed up FFMpeg input +test --- sound/sources/ffmpeg_source.cpp | 5 +-- sound/sources/ffmpeg_source.h | 7 ++-- sound/tests/Makefile | 7 +++- sound/tests/audiere_source_test.cpp | 1 - sound/tests/ffmpeg_source_test.cpp | 62 +++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 sound/tests/ffmpeg_source_test.cpp diff --git a/sound/sources/ffmpeg_source.cpp b/sound/sources/ffmpeg_source.cpp index af785eaa3..372d1766d 100644 --- a/sound/sources/ffmpeg_source.cpp +++ b/sound/sources/ffmpeg_source.cpp @@ -1,4 +1,5 @@ -#include "input_ffmpeg.h" +#include "ffmpeg_source.h" +#include using namespace Mangle::Sound; @@ -52,8 +53,6 @@ FFMpegSource::FFMpegSource(const std::string &file) std::string msg; AVCodec *codec; - empty = false; - if(av_open_input_file(&FmtCtx, file.c_str(), NULL, 0, NULL) != 0) fail("Error loading audio file " + file); diff --git a/sound/sources/ffmpeg_source.h b/sound/sources/ffmpeg_source.h index d185098fd..2b33a3222 100644 --- a/sound/sources/ffmpeg_source.h +++ b/sound/sources/ffmpeg_source.h @@ -1,8 +1,7 @@ #ifndef MANGLE_SOUND_FFMPEG_H #define MANGLE_SOUND_FFMPEG_H -#include "../input.h" -#include +#include "../source.h" #include #include @@ -28,7 +27,7 @@ class FFMpegSource : public SampleSource FFMpegSource(const std::string &file); /// Decode the given sound stream (not supported by FFmpeg) - FFMpegSource(Stream::StreamPtr src) { assert(0); } + FFMpegSource(Mangle::Stream::StreamPtr src) { assert(0); } ~FFMpegSource(); @@ -40,7 +39,7 @@ class FFMpegSource : public SampleSource #include "loadertemplate.h" /// A factory that loads FFMpegSources from file -class FFMpegLoader : public SSL_Template +class FFMpegLoader : public SSL_Template { public: diff --git a/sound/tests/Makefile b/sound/tests/Makefile index 75fb1e9e6..79c2ecaf8 100644 --- a/sound/tests/Makefile +++ b/sound/tests/Makefile @@ -1,8 +1,8 @@ GCC=g++ -I../ -all: audiere_source_test openal_output_test openal_audiere_test +all: audiere_source_test ffmpeg_source_test openal_output_test openal_audiere_test -#L_FFMPEG=$(shell pkg-config --libs libavcodec libavformat) +L_FFMPEG=$(shell pkg-config --libs libavcodec libavformat) L_OPENAL=$(shell pkg-config --libs openal) L_AUDIERE=-laudiere @@ -15,5 +15,8 @@ openal_output_test: openal_output_test.cpp ../outputs/openal_out.cpp audiere_source_test: audiere_source_test.cpp ../sources/audiere_source.cpp ../../stream/clients/audiere_file.cpp $(GCC) $^ -o $@ $(L_AUDIERE) +ffmpeg_source_test: ffmpeg_source_test.cpp ../sources/ffmpeg_source.cpp + $(GCC) $^ -o $@ $(L_FFMPEG) + clean: rm *_test diff --git a/sound/tests/audiere_source_test.cpp b/sound/tests/audiere_source_test.cpp index 6dba37b51..1631e89cb 100644 --- a/sound/tests/audiere_source_test.cpp +++ b/sound/tests/audiere_source_test.cpp @@ -2,7 +2,6 @@ #include "../../stream/servers/file_stream.h" #include "../sources/audiere_source.h" -#include "../../stream/filters/buffer_stream.h" #include #include diff --git a/sound/tests/ffmpeg_source_test.cpp b/sound/tests/ffmpeg_source_test.cpp new file mode 100644 index 000000000..294565fb1 --- /dev/null +++ b/sound/tests/ffmpeg_source_test.cpp @@ -0,0 +1,62 @@ +#include + +#include "../../stream/servers/file_stream.h" +#include "../sources/ffmpeg_source.h" + +#include +#include + +using namespace std; +using namespace Mangle::Stream; +using namespace Mangle::Sound; + +// Contents and size of cow.raw +void *orig; +size_t orig_size; + +void run(SampleSourcePtr &src) +{ + int rate, channels, bits; + src->getInfo(&rate, &channels, &bits); + cout << "rate=" << rate << "\nchannels=" << channels + << "\nbits=" << bits << endl; + + cout << "Reading entire buffer into memory\n"; + void *buf = malloc(orig_size); + size_t ss = src->read(buf, orig_size); + cout << "Actually read: " << ss << endl; + assert(ss == orig_size); + + cout << "Comparing...\n"; + if(memcmp(buf, orig, ss) != 0) + { + cout << "Oops!\n"; + assert(0); + } + + cout << "Done\n"; +} + +int main() +{ + { + cout << "Reading cow.raw first\n"; + FileStream tmp("cow.raw"); + orig_size = tmp.size(); + cout << "Size: " << orig_size << endl; + orig = malloc(orig_size); + tmp.read(orig, orig_size); + cout << "Done\n"; + } + + // Initializes the library, not used for anything else. + FFMpegLoader fm; + + { + cout << "\nLoading cow.wav by filename:\n"; + SampleSourcePtr cow_file( new FFMpegSource("cow.wav") ); + run(cow_file); + } + + return 0; +}