test programs for the codec api

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5250 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2003-11-04 01:28:59 +00:00
parent 21c162a3be
commit 0238e54c3b
9 changed files with 408 additions and 0 deletions
+2
View File
@@ -13,4 +13,6 @@ SimpleTest TimedEventQueueTest : TimedEventQueueTest.cpp
SubInclude OBOS_TOP src tests kits media notificationtest ;
SubInclude OBOS_TOP src tests kits media nodetest ;
SubInclude OBOS_TOP src tests kits media playwav ;
SubInclude OBOS_TOP src tests kits media mp3_reader_test ;
SubInclude OBOS_TOP src tests kits media wav_reader_test ;
@@ -0,0 +1,24 @@
#include "FileDataIO.h"
FileDataIO::FileDataIO(const char *filepath, uint32 open_mode)
: file(new BFile(filepath, open_mode))
{
}
FileDataIO::~FileDataIO()
{
delete file;
}
ssize_t
FileDataIO::Read(void *buffer, size_t size)
{
return file->Read(buffer, size);
}
ssize_t
FileDataIO::Write(const void *buffer, size_t size)
{
return file->Write(buffer, size);
}
@@ -0,0 +1,20 @@
#ifndef _FILE_DATA_IO
#define _FILE_DATA_IO
#include <DataIO.h>
#include <File.h>
class FileDataIO : public BDataIO
{
public:
FileDataIO(const char *filepath, uint32 open_mode);
~FileDataIO();
ssize_t Read(void *buffer, size_t size);
ssize_t Write(const void *buffer, size_t size);
private:
BFile *file;
};
#endif
@@ -0,0 +1,19 @@
SubDir OBOS_TOP src tests kits media mp3_reader_test ;
UsePrivateHeaders media ;
SimpleTest mp3_reader_test
: main.cpp
FileDataIO.cpp
MediaPlugin.cpp
ReaderPlugin.cpp
MP3ReaderPlugin.cpp
: media be root
;
# Tell Jam where to find these sources
SEARCH on [ FGristFiles MP3ReaderPlugin.cpp ]
= [ FDirName $(OBOS_TOP) src add-ons media plugins mp3_reader ] ;
SEARCH on [ FGristFiles MediaPlugin.cpp ReaderPlugin.cpp ]
= [ FDirName $(OBOS_TOP) src kits media ] ;
@@ -0,0 +1,140 @@
#include <OS.h>
#include <File.h>
#include <stdio.h>
#include <DataIO.h>
#include <string.h>
#include "MediaPlugin.h"
#include "ReaderPlugin.h"
#include "FileDataIO.h"
const bool SEEKABLE = 1;
const char * FILENAME = "/boot/home/Desktop/mediastuff/Apocalyptica Feat. Nina Hagen - Seemann.mp3";
#define TRACE_THIS 1
#if TRACE_THIS
#define TRACE printf
#else
#define TRACE ((void)0)
#endif
void *cookies[100];
int main(int argc, char *argv[])
{
TRACE("\n\n");
TRACE("main: creating plugin...\n");
MediaPlugin *plugin = instantiate_plugin();
TRACE("main: creating reader...\n");
ReaderPlugin *readerplugin;
readerplugin = dynamic_cast<ReaderPlugin *>(plugin);
Reader *reader = readerplugin->NewReader();
TRACE("main: opening source file...\n");
BDataIO *source;
if (SEEKABLE)
source = new BFile(FILENAME, O_RDWR);
else
source = new FileDataIO(FILENAME, O_RDWR);
TRACE("main: calling setup...\n");
reader->Setup(source);
TRACE("main: creating ...\n");
TRACE("main: copyright: \"%s\"\n", reader->Copyright());
status_t s;
int32 streamCount;
s = reader->Sniff(&streamCount);
if (s != B_OK) {
TRACE("main: Sniff() failed with error %lx (%s)\n", s, strerror(s));
goto err;
}
TRACE("main: Sniff() found %ld streams\n", streamCount);
for (int i = 0; i < streamCount; i++) {
TRACE("main: calling AllocateCookie(stream = %d)\n", i);
s = reader->AllocateCookie(i, &cookies[i]);
if (s != B_OK) {
TRACE("main: AllocateCookie(stream = %d) failed with error %lx (%s)\n", i, s, strerror(s));
goto err;
}
}
for (int i = 0; i < streamCount; i++) {
TRACE("main: calling GetStreamInfo(stream = %d)\n", i);
int64 frameCount;
bigtime_t duration;
media_format format;
void *infoBuffer;
int32 infoSize;
s = reader->GetStreamInfo(cookies[i], &frameCount, &duration, &format, &infoBuffer, &infoSize);
if (s != B_OK) {
TRACE("main: GetStreamInfo(stream = %d) failed with error %lx (%s)\n", i, s, strerror(s));
goto err;
}
TRACE("main: GetStreamInfo(stream = %d) result: %Ld frames, %.6f sec\n", i, frameCount, duration / 1000000.0);
}
for (int i = 0; i < streamCount; i++) {
void *chunkBuffer;
int32 chunkSize;
media_header mediaHeader;
for (int j = 0; j < 5; j++) {
s = reader->GetNextChunk(cookies[i], &chunkBuffer, &chunkSize, &mediaHeader);
if (s != B_OK) {
TRACE("main: GetNextChunk(stream = %d, chunk = %d) failed with error %lx (%s)\n", i, j, s, strerror(s));
break;
}
}
int64 frame;
bigtime_t time;
time = 1000000; // 1 sec
TRACE("main: calling Seek(stream = %d, time %.6f forward)\n", i, time / 1000000.0);
s = reader->Seek(cookies[i], B_MEDIA_SEEK_TO_TIME | B_MEDIA_SEEK_CLOSEST_FORWARD, &frame, &time);
TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
frame = 1000;
TRACE("main: calling Seek(stream = %d, frame %Ld forward)\n", i, frame);
s = reader->Seek(cookies[i], B_MEDIA_SEEK_TO_FRAME | B_MEDIA_SEEK_CLOSEST_FORWARD, &frame, &time);
TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
time = 1000000; // 1 sec
TRACE("main: calling Seek(stream = %d, time %.6f backward)\n", i, time / 1000000.0);
s = reader->Seek(cookies[i], B_MEDIA_SEEK_TO_TIME | B_MEDIA_SEEK_CLOSEST_BACKWARD, &frame, &time);
TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
frame = 1000;
TRACE("main: calling Seek(stream = %d, frame %Ld backward)\n", i, frame);
s = reader->Seek(cookies[i], B_MEDIA_SEEK_TO_FRAME | B_MEDIA_SEEK_CLOSEST_BACKWARD, &frame, &time);
TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
}
for (int i = 0; i < streamCount; i++) {
TRACE("main: calling FreeCookie(stream = %d)\n", i);
s = reader->FreeCookie(cookies[i]);
if (s != B_OK) {
TRACE("main: FreeCookie(stream = %d) failed with error %lx (%s)\n", i, s, strerror(s));
goto err;
}
}
err:
delete reader;
delete plugin;
delete source;
return 0;
}
@@ -0,0 +1,24 @@
#include "FileDataIO.h"
FileDataIO::FileDataIO(const char *filepath, uint32 open_mode)
: file(new BFile(filepath, open_mode))
{
}
FileDataIO::~FileDataIO()
{
delete file;
}
ssize_t
FileDataIO::Read(void *buffer, size_t size)
{
return file->Read(buffer, size);
}
ssize_t
FileDataIO::Write(const void *buffer, size_t size)
{
return file->Write(buffer, size);
}
@@ -0,0 +1,20 @@
#ifndef _FILE_DATA_IO
#define _FILE_DATA_IO
#include <DataIO.h>
#include <File.h>
class FileDataIO : public BDataIO
{
public:
FileDataIO(const char *filepath, uint32 open_mode);
~FileDataIO();
ssize_t Read(void *buffer, size_t size);
ssize_t Write(const void *buffer, size_t size);
private:
BFile *file;
};
#endif
@@ -0,0 +1,19 @@
SubDir OBOS_TOP src tests kits media wav_reader_test ;
UsePrivateHeaders media ;
SimpleTest wav_reader_test
: main.cpp
FileDataIO.cpp
MediaPlugin.cpp
ReaderPlugin.cpp
WavReaderPlugin.cpp
: media be root
;
# Tell Jam where to find these sources
SEARCH on [ FGristFiles WavReaderPlugin.cpp ]
= [ FDirName $(OBOS_TOP) src add-ons media plugins wav_reader ] ;
SEARCH on [ FGristFiles MediaPlugin.cpp ReaderPlugin.cpp ]
= [ FDirName $(OBOS_TOP) src kits media ] ;
@@ -0,0 +1,140 @@
#include <OS.h>
#include <File.h>
#include <stdio.h>
#include <DataIO.h>
#include <string.h>
#include "MediaPlugin.h"
#include "ReaderPlugin.h"
#include "FileDataIO.h"
const bool SEEKABLE = 1;
const char * FILENAME = "/boot/home/Desktop/mediastuff/test1.wav";
#define TRACE_THIS 1
#if TRACE_THIS
#define TRACE printf
#else
#define TRACE ((void)0)
#endif
void *cookies[100];
int main(int argc, char *argv[])
{
TRACE("\n\n");
TRACE("main: creating plugin...\n");
MediaPlugin *plugin = instantiate_plugin();
TRACE("main: creating reader...\n");
ReaderPlugin *readerplugin;
readerplugin = dynamic_cast<ReaderPlugin *>(plugin);
Reader *reader = readerplugin->NewReader();
TRACE("main: opening source file...\n");
BDataIO *source;
if (SEEKABLE)
source = new BFile(FILENAME, O_RDWR);
else
source = new FileDataIO(FILENAME, O_RDWR);
TRACE("main: calling setup...\n");
reader->Setup(source);
TRACE("main: creating ...\n");
TRACE("main: copyright: \"%s\"\n", reader->Copyright());
status_t s;
int32 streamCount;
s = reader->Sniff(&streamCount);
if (s != B_OK) {
TRACE("main: Sniff() failed with error %lx (%s)\n", s, strerror(s));
goto err;
}
TRACE("main: Sniff() found %ld streams\n", streamCount);
for (int i = 0; i < streamCount; i++) {
TRACE("main: calling AllocateCookie(stream = %d)\n", i);
s = reader->AllocateCookie(i, &cookies[i]);
if (s != B_OK) {
TRACE("main: AllocateCookie(stream = %d) failed with error %lx (%s)\n", i, s, strerror(s));
goto err;
}
}
for (int i = 0; i < streamCount; i++) {
TRACE("main: calling GetStreamInfo(stream = %d)\n", i);
int64 frameCount;
bigtime_t duration;
media_format format;
void *infoBuffer;
int32 infoSize;
s = reader->GetStreamInfo(cookies[i], &frameCount, &duration, &format, &infoBuffer, &infoSize);
if (s != B_OK) {
TRACE("main: GetStreamInfo(stream = %d) failed with error %lx (%s)\n", i, s, strerror(s));
goto err;
}
TRACE("main: GetStreamInfo(stream = %d) result: %Ld frames, %.6f sec\n", i, frameCount, duration / 1000000.0);
}
for (int i = 0; i < streamCount; i++) {
void *chunkBuffer;
int32 chunkSize;
media_header mediaHeader;
for (int j = 0; j < 5; j++) {
s = reader->GetNextChunk(cookies[i], &chunkBuffer, &chunkSize, &mediaHeader);
if (s != B_OK) {
TRACE("main: GetNextChunk(stream = %d, chunk = %d) failed with error %lx (%s)\n", i, j, s, strerror(s));
break;
}
}
int64 frame;
bigtime_t time;
time = 1000000; // 1 sec
TRACE("main: calling Seek(stream = %d, time %.6f forward)\n", i, time / 1000000.0);
s = reader->Seek(cookies[i], B_MEDIA_SEEK_TO_TIME | B_MEDIA_SEEK_CLOSEST_FORWARD, &frame, &time);
TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
frame = 1000;
TRACE("main: calling Seek(stream = %d, frame %Ld forward)\n", i, frame);
s = reader->Seek(cookies[i], B_MEDIA_SEEK_TO_FRAME | B_MEDIA_SEEK_CLOSEST_FORWARD, &frame, &time);
TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
time = 1000000; // 1 sec
TRACE("main: calling Seek(stream = %d, time %.6f backward)\n", i, time / 1000000.0);
s = reader->Seek(cookies[i], B_MEDIA_SEEK_TO_TIME | B_MEDIA_SEEK_CLOSEST_BACKWARD, &frame, &time);
TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
frame = 1000;
TRACE("main: calling Seek(stream = %d, frame %Ld backward)\n", i, frame);
s = reader->Seek(cookies[i], B_MEDIA_SEEK_TO_FRAME | B_MEDIA_SEEK_CLOSEST_BACKWARD, &frame, &time);
TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
}
for (int i = 0; i < streamCount; i++) {
TRACE("main: calling FreeCookie(stream = %d)\n", i);
s = reader->FreeCookie(cookies[i]);
if (s != B_OK) {
TRACE("main: FreeCookie(stream = %d) failed with error %lx (%s)\n", i, s, strerror(s));
goto err;
}
}
err:
delete reader;
delete plugin;
delete source;
return 0;
}