1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Fixed up FFMpeg input +test

This commit is contained in:
Nicolay Korslund 2010-01-01 20:18:11 +01:00
parent fbb77478c0
commit cdca68a368
5 changed files with 72 additions and 10 deletions

View File

@ -1,4 +1,5 @@
#include "input_ffmpeg.h" #include "ffmpeg_source.h"
#include <exception>
using namespace Mangle::Sound; using namespace Mangle::Sound;
@ -52,8 +53,6 @@ FFMpegSource::FFMpegSource(const std::string &file)
std::string msg; std::string msg;
AVCodec *codec; AVCodec *codec;
empty = false;
if(av_open_input_file(&FmtCtx, file.c_str(), NULL, 0, NULL) != 0) if(av_open_input_file(&FmtCtx, file.c_str(), NULL, 0, NULL) != 0)
fail("Error loading audio file " + file); fail("Error loading audio file " + file);

View File

@ -1,8 +1,7 @@
#ifndef MANGLE_SOUND_FFMPEG_H #ifndef MANGLE_SOUND_FFMPEG_H
#define MANGLE_SOUND_FFMPEG_H #define MANGLE_SOUND_FFMPEG_H
#include "../input.h" #include "../source.h"
#include <exception>
#include <vector> #include <vector>
#include <assert.h> #include <assert.h>
@ -28,7 +27,7 @@ class FFMpegSource : public SampleSource
FFMpegSource(const std::string &file); FFMpegSource(const std::string &file);
/// Decode the given sound stream (not supported by FFmpeg) /// Decode the given sound stream (not supported by FFmpeg)
FFMpegSource(Stream::StreamPtr src) { assert(0); } FFMpegSource(Mangle::Stream::StreamPtr src) { assert(0); }
~FFMpegSource(); ~FFMpegSource();
@ -40,7 +39,7 @@ class FFMpegSource : public SampleSource
#include "loadertemplate.h" #include "loadertemplate.h"
/// A factory that loads FFMpegSources from file /// A factory that loads FFMpegSources from file
class FFMpegLoader : public SSL_Template<AudiereSource,false,true> class FFMpegLoader : public SSL_Template<FFMpegSource,false,true>
{ {
public: public:

View File

@ -1,8 +1,8 @@
GCC=g++ -I../ 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_OPENAL=$(shell pkg-config --libs openal)
L_AUDIERE=-laudiere 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 audiere_source_test: audiere_source_test.cpp ../sources/audiere_source.cpp ../../stream/clients/audiere_file.cpp
$(GCC) $^ -o $@ $(L_AUDIERE) $(GCC) $^ -o $@ $(L_AUDIERE)
ffmpeg_source_test: ffmpeg_source_test.cpp ../sources/ffmpeg_source.cpp
$(GCC) $^ -o $@ $(L_FFMPEG)
clean: clean:
rm *_test rm *_test

View File

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

View File

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