Fixed up FFMpeg input +test

actorid
Nicolay Korslund 15 years ago
parent fbb77478c0
commit cdca68a368

@ -1,4 +1,5 @@
#include "input_ffmpeg.h"
#include "ffmpeg_source.h"
#include <exception>
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);

@ -1,8 +1,7 @@
#ifndef MANGLE_SOUND_FFMPEG_H
#define MANGLE_SOUND_FFMPEG_H
#include "../input.h"
#include <exception>
#include "../source.h"
#include <vector>
#include <assert.h>
@ -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<AudiereSource,false,true>
class FFMpegLoader : public SSL_Template<FFMpegSource,false,true>
{
public:

@ -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

@ -2,7 +2,6 @@
#include "../../stream/servers/file_stream.h"
#include "../sources/audiere_source.h"
#include "../../stream/filters/buffer_stream.h"
#include <assert.h>
#include <string.h>

@ -0,0 +1,62 @@
#include <iostream>
#include "../../stream/servers/file_stream.h"
#include "../sources/ffmpeg_source.h"
#include <assert.h>
#include <string.h>
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;
}
Loading…
Cancel
Save