aboutsummaryrefslogtreecommitdiffstats
path: root/mediaplugin/src/plugins/media/include/core
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-11-05 09:31:03 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-11-05 09:31:03 +0000
commit4b808ab7f4b12551f5737bb666361efd79f62a3a (patch)
tree121a00d5ecf189837a7f49438722864ed260d09d /mediaplugin/src/plugins/media/include/core
parent3a079aafc4f98dc83ea36858bbca071342beb03d (diff)
downloadusdx-4b808ab7f4b12551f5737bb666361efd79f62a3a.tar.gz
usdx-4b808ab7f4b12551f5737bb666361efd79f62a3a.tar.xz
usdx-4b808ab7f4b12551f5737bb666361efd79f62a3a.zip
media plugins
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@2710 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'mediaplugin/src/plugins/media/include/core')
-rw-r--r--mediaplugin/src/plugins/media/include/core/begin_pack.h36
-rw-r--r--mediaplugin/src/plugins/media/include/core/end_pack.h35
-rw-r--r--mediaplugin/src/plugins/media/include/core/logger.h73
-rw-r--r--mediaplugin/src/plugins/media/include/core/plugin_audio_convert.h69
-rw-r--r--mediaplugin/src/plugins/media/include/core/plugin_audio_decode.h51
-rw-r--r--mediaplugin/src/plugins/media/include/core/plugin_core.h222
-rw-r--r--mediaplugin/src/plugins/media/include/core/plugin_video_decode.h53
-rw-r--r--mediaplugin/src/plugins/media/include/core/util.h292
8 files changed, 831 insertions, 0 deletions
diff --git a/mediaplugin/src/plugins/media/include/core/begin_pack.h b/mediaplugin/src/plugins/media/include/core/begin_pack.h
new file mode 100644
index 00000000..504f2f75
--- /dev/null
+++ b/mediaplugin/src/plugins/media/include/core/begin_pack.h
@@ -0,0 +1,36 @@
+/* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+#ifndef _BEGIN_PACK_H_
+#define _BEGIN_PACK_H_
+
+/*
+ * begin structure packing with 4 byte alignment.
+ */
+#ifdef _MSC_VER
+#pragma warning(disable: 4103) \
+#pragma pack(push,4)
+#endif
+
+#endif /* _BEGIN_PACK_H_ */
diff --git a/mediaplugin/src/plugins/media/include/core/end_pack.h b/mediaplugin/src/plugins/media/include/core/end_pack.h
new file mode 100644
index 00000000..f6ee748b
--- /dev/null
+++ b/mediaplugin/src/plugins/media/include/core/end_pack.h
@@ -0,0 +1,35 @@
+/* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+#ifndef _END_PACK_H_
+#define _END_PACK_H_
+
+/*
+ * end structure packing at previous byte alignment
+ */
+#if defined(_MSC_VER)
+#pragma pack(pop)
+#endif
+
+#endif /* _END_PACK_H_ */
diff --git a/mediaplugin/src/plugins/media/include/core/logger.h b/mediaplugin/src/plugins/media/include/core/logger.h
new file mode 100644
index 00000000..c9924b83
--- /dev/null
+++ b/mediaplugin/src/plugins/media/include/core/logger.h
@@ -0,0 +1,73 @@
+/* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+#ifndef _LOGGER_H_
+#define _LOGGER_H_
+
+#include "plugin_core.h"
+#include <string>
+
+#ifdef __cplusplus
+
+#define logger (Logger::getInstance())
+class Logger {
+private:
+ static Logger _instance;
+
+ Logger() {}
+ ~Logger() {}
+
+public:
+ static const Logger &getInstance() {
+ return _instance;
+ }
+
+ void log(log_level level, const std::string &msg, const std::string &context) const {
+ pluginCore->log(level, msg.c_str(), context.c_str());
+ }
+
+ void info(const std::string &msg, const std::string &context) const {
+ log(INFO, msg, context);
+ }
+
+ void status(const std::string &msg, const std::string &context) const {
+ log(STATUS, msg, context);
+ }
+
+ void warn(const std::string &msg, const std::string &context) const {
+ log(WARN, msg, context);
+ }
+
+ void error(const std::string &msg, const std::string &context) const {
+ log(ERROR, msg, context);
+ }
+
+ void critical(const std::string &msg, const std::string &context) const {
+ log(CRITICAL, msg, context);
+ }
+};
+
+#endif /* __cplusplus */
+
+#endif /* _LOGGER_H_ */
diff --git a/mediaplugin/src/plugins/media/include/core/plugin_audio_convert.h b/mediaplugin/src/plugins/media/include/core/plugin_audio_convert.h
new file mode 100644
index 00000000..e3a31b26
--- /dev/null
+++ b/mediaplugin/src/plugins/media/include/core/plugin_audio_convert.h
@@ -0,0 +1,69 @@
+/* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+#ifndef _PLUGIN_AUDIO_CONVERT_H_
+#define _PLUGIN_AUDIO_CONVERT_H_
+
+#include "util.h"
+#include "plugin_core.h"
+#include "logger.h"
+
+#ifdef __cplusplus
+
+class AudioConvertStream {
+protected:
+ AudioFormatInfo _srcFormatInfo;
+ AudioFormatInfo _dstFormatInfo;
+
+ AudioConvertStream(const AudioFormatInfo &srcFormatInfo, const AudioFormatInfo &dstFormatInfo) {
+ _srcFormatInfo = srcFormatInfo;
+ _dstFormatInfo = dstFormatInfo;
+ }
+
+public:
+ virtual ~AudioConvertStream() {};
+
+ /**
+ * Converts the InputBuffer and stores the result in OutputBuffer.
+ * If the result is not -1, inputSize will be set to the actual number of
+ * input-buffer bytes used.
+ * Returns the number of bytes written to the output-buffer or -1 if an error occured.
+ */
+ virtual int convert(uint8_t *inputBuffer, uint8_t *outputBuffer, int &inputSize) = 0;
+
+ /**
+ * Destination/Source size ratio
+ */
+ virtual double getRatio() = 0;
+
+ /**
+ * Size of an output buffer needed to store the result of a converted buffer with
+ * an input size of inputSize bytes.
+ */
+ virtual int getOutputBufferSize(int inputSize) = 0;
+};
+
+#endif /* __cplusplus */
+
+#endif /* _PLUGIN_AUDIO_CONVERT_H_ */
diff --git a/mediaplugin/src/plugins/media/include/core/plugin_audio_decode.h b/mediaplugin/src/plugins/media/include/core/plugin_audio_decode.h
new file mode 100644
index 00000000..2385f77c
--- /dev/null
+++ b/mediaplugin/src/plugins/media/include/core/plugin_audio_decode.h
@@ -0,0 +1,51 @@
+/* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+#ifndef _PLUGIN_AUDIO_DECODE_H_
+#define _PLUGIN_AUDIO_DECODE_H_
+
+#include "util.h"
+#include "plugin_core.h"
+#include "logger.h"
+
+#ifdef __cplusplus
+
+class PluginDecodeStream {
+public:
+ virtual ~PluginDecodeStream() {};
+
+ virtual double getLength() = 0;
+ virtual const AudioFormatInfo &getAudioFormatInfo() = 0;
+ virtual double getPosition() = 0;
+ virtual void setPosition(double time) = 0;
+ virtual bool getLoop() = 0;
+ virtual void setLoop(bool Enabled) = 0;
+ virtual bool isEOF() = 0;
+ virtual bool isError() = 0;
+ virtual int readData(uint8_t *buffer, int bufferSize) = 0;
+};
+
+#endif /* __cplusplus */
+
+#endif /* _PLUGIN_AUDIO_DECODE_H_ */
diff --git a/mediaplugin/src/plugins/media/include/core/plugin_core.h b/mediaplugin/src/plugins/media/include/core/plugin_core.h
new file mode 100644
index 00000000..f0cb19da
--- /dev/null
+++ b/mediaplugin/src/plugins/media/include/core/plugin_core.h
@@ -0,0 +1,222 @@
+/* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+#ifndef _PLUGIN_CORE_H_
+#define _PLUGIN_CORE_H_
+
+#include "inttypes.h"
+
+/*
+ * C Interface
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* declaration for export */
+#ifndef DLL_EXPORT
+# if defined(__WIN32__)
+# define DLL_EXPORT __declspec(dllexport)
+# else
+# if defined(__GNUC__) && __GNUC__ >= 4
+# define DLL_EXPORT __attribute__ ((visibility("default")))
+# else
+# define DLL_EXPORT
+# endif
+# endif
+#endif /* DLL_EXPORT */
+
+/* use C calling convention */
+#ifndef CDECL
+#if defined(__WIN32__) && !defined(__GNUC__)
+#define CDECL __cdecl
+#else
+#define CDECL
+#endif
+#endif /* CDECL */
+
+#define PLUGIN_CALL CDECL
+
+// VERSION: AAABBBCCC (A: Major, B: Minor, C: Revision)
+#define MAKE_VERSION(a,b,c) ((((a) * 1000 + (b)) * 1000) + (c))
+
+typedef enum { FALSE , TRUE } BOOL;
+
+typedef enum log_level {
+ DEBUG,
+ INFO,
+ STATUS,
+ WARN,
+ ERROR,
+ CRITICAL
+} log_level;
+
+typedef struct{} fileStream_t;
+typedef struct{} cond_t;
+typedef struct{} mutex_t;
+typedef struct{} thread_t;
+
+#define FILE_OPEN_MODE_READ 0x01
+#define FILE_OPEN_MODE_WRITE 0x02
+#define FILE_OPEN_MODE_READ_WRITE (FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE)
+
+/* returned by condWaitTimeout() if a timeout occurs. */
+#define MUTEX_TIMEDOUT 1
+
+typedef struct pluginCore_t {
+ int version;
+
+ void PLUGIN_CALL (*log)(int level, const char *msg, const char *context);
+ uint32_t PLUGIN_CALL (*ticksMillis);
+
+ fileStream_t* PLUGIN_CALL (*fileOpen)(const char *utf8Filename, int mode);
+ void PLUGIN_CALL (*fileClose)(fileStream_t *stream);
+ int64_t PLUGIN_CALL (*fileRead)(fileStream_t *stream, uint8_t *buf, int size);
+ int64_t PLUGIN_CALL (*fileWrite)(fileStream_t *stream, const uint8_t *buf, int size);
+ int64_t PLUGIN_CALL (*fileSeek)(fileStream_t *stream, int64_t pos, int whence);
+ int64_t PLUGIN_CALL (*fileSize)(fileStream_t *stream);
+
+ thread_t* PLUGIN_CALL (*threadCreate)(int (PLUGIN_CALL *fn)(void *), void *data);
+ uint32_t PLUGIN_CALL (*threadCurrentID)();
+ uint32_t PLUGIN_CALL (*threadGetID)(thread_t *thread);
+ void PLUGIN_CALL (*threadWait)(thread_t *thread, int *status);
+ void PLUGIN_CALL (*threadSleep)(uint32_t millisecs);
+
+ mutex_t* PLUGIN_CALL (*mutexCreate)();
+ void PLUGIN_CALL (*mutexDestroy)(mutex_t *mutex);
+ int PLUGIN_CALL (*mutexLock)(mutex_t *mutex);
+ int PLUGIN_CALL (*mutexUnlock)(mutex_t *mutex);
+
+ cond_t* PLUGIN_CALL (*condCreate)();
+ void PLUGIN_CALL (*condDestroy)(cond_t *cond);
+ int PLUGIN_CALL (*condSignal)(cond_t *cond);
+ int PLUGIN_CALL (*condBroadcast)(cond_t *cond);
+ int PLUGIN_CALL (*condWait)(cond_t *cond, mutex_t *mutex);
+ int PLUGIN_CALL (*condWaitTimeout)(cond_t *cond, mutex_t *mutex, uint32_t ms);
+} pluginCore_t;
+
+typedef enum audioSampleFormat_t {
+ asfUnknown, // unknown format
+ asfU8, asfS8, // unsigned/signed 8 bits
+ asfU16LSB, asfS16LSB, // unsigned/signed 16 bits (endianness: LSB)
+ asfU16MSB, asfS16MSB, // unsigned/signed 16 bits (endianness: MSB)
+ asfU16, asfS16, // unsigned/signed 16 bits (endianness: System)
+ asfS32, // signed 32 bits (endianness: System)
+ asfFloat, // float
+ asfDouble // double
+} audioSampleFormat_t;
+
+// Size of one sample (one channel only) in bytes
+static const int g_audioSampleSize[] = {
+ 0, // asfUnknown
+ 1, 1, // asfU8, asfS8
+ 2, 2, // asfU16LSB, asfS16LSB
+ 2, 2, // asfU16MSB, asfS16MSB
+ 2, 2, // asfU16, asfS16
+ 3, // asfS24
+ 4, // asfS32
+ 4, // asfFloat
+};
+
+struct audioFormatInfo_t {
+ double sampleRate;
+ uint8_t channels;
+ audioSampleFormat_t format;
+};
+
+typedef struct{} audioDecodeStream_t;
+typedef struct{} audioConvertStream_t;
+typedef struct{} videoDecodeStream_t;
+
+typedef struct audioDecoderInfo_t {
+ int priority;
+ BOOL PLUGIN_CALL (*init)();
+ BOOL PLUGIN_CALL (*finalize)();
+ audioDecodeStream_t* PLUGIN_CALL (*open)(const char *filename);
+ void PLUGIN_CALL (*close)(audioDecodeStream_t *stream);
+ double PLUGIN_CALL (*getLength)(audioDecodeStream_t *stream);
+ void PLUGIN_CALL (*getAudioFormatInfo)(audioDecodeStream_t *stream, audioFormatInfo_t *info);
+ double PLUGIN_CALL (*getPosition)(audioDecodeStream_t *stream);
+ void PLUGIN_CALL (*setPosition)(audioDecodeStream_t *stream, double time);
+ BOOL PLUGIN_CALL (*getLoop)(audioDecodeStream_t *stream);
+ void PLUGIN_CALL (*setLoop)(audioDecodeStream_t *stream, BOOL enabled);
+ BOOL PLUGIN_CALL (*isEOF)(audioDecodeStream_t *stream);
+ BOOL PLUGIN_CALL (*isError)(audioDecodeStream_t *stream);
+ int PLUGIN_CALL (*readData)(audioDecodeStream_t *stream, uint8_t *buffer, int bufferSize);
+} audioDecoderInfo_t;
+
+typedef struct audioConverterInfo_t {
+ int priority;
+ BOOL PLUGIN_CALL (*init)();
+ BOOL PLUGIN_CALL (*finalize)();
+ audioConvertStream_t* PLUGIN_CALL (*open)(audioFormatInfo_t *inputFormat,
+ audioFormatInfo_t *outputFormat);
+ void PLUGIN_CALL (*close)(audioConvertStream_t *stream);
+ int PLUGIN_CALL (*convert)(audioConvertStream_t *stream,
+ uint8_t *input, uint8_t *output, int *numSamples);
+ int PLUGIN_CALL (*getOutputBufferSize)(audioConvertStream_t *stream, int inputSize);
+ double PLUGIN_CALL (*getRatio)(audioConvertStream_t *stream);
+} audioConverterInfo_t;
+
+typedef struct videoDecoderInfo_t {
+ int priority;
+ BOOL PLUGIN_CALL (*init)();
+ BOOL PLUGIN_CALL (*finalize)();
+ videoDecodeStream_t* PLUGIN_CALL (*open)(const char *filename);
+ void PLUGIN_CALL (*close)(videoDecodeStream_t *stream);
+ void PLUGIN_CALL (*setLoop)(videoDecodeStream_t *stream, BOOL enable);
+ BOOL PLUGIN_CALL (*getLoop)(videoDecodeStream_t *stream);
+ void PLUGIN_CALL (*setPosition)(videoDecodeStream_t *stream, double time);
+ double PLUGIN_CALL (*getPosition)(videoDecodeStream_t *stream);
+ int PLUGIN_CALL (*getFrameWidth)(videoDecodeStream_t *stream);
+ int PLUGIN_CALL (*getFrameHeight)(videoDecodeStream_t *stream);
+ double PLUGIN_CALL (*getFrameAspect)(videoDecodeStream_t *stream);
+ uint8_t* PLUGIN_CALL (*getFrame)(videoDecodeStream_t *stream, long double time);
+} videoDecoderInfo_t;
+
+typedef struct pluginInfo_t {
+ int version;
+ const char *name;
+ BOOL PLUGIN_CALL (*initialize)();
+ BOOL PLUGIN_CALL (*finalize)();
+ const audioDecoderInfo_t *audioDecoder;
+ const audioConverterInfo_t *audioConverter;
+ const videoDecoderInfo_t *videoDecoder;
+} pluginInfo_t;
+
+
+// plugin entry function (must be implemented by the plugin)
+DLL_EXPORT const pluginInfo_t* PLUGIN_CALL Plugin_register(const pluginCore_t *core);
+
+// must be provided by the plugin and initialized on plugin initialization
+extern const pluginCore_t *pluginCore;
+
+BOOL pluginInitCore(const pluginCore_t *core);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _PLUGIN_CORE_H_ */
diff --git a/mediaplugin/src/plugins/media/include/core/plugin_video_decode.h b/mediaplugin/src/plugins/media/include/core/plugin_video_decode.h
new file mode 100644
index 00000000..6403852f
--- /dev/null
+++ b/mediaplugin/src/plugins/media/include/core/plugin_video_decode.h
@@ -0,0 +1,53 @@
+/* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+#ifndef _PLUGIN_VIDEO_DECODE_H_
+#define _PLUGIN_VIDEO_DECODE_H_
+
+#include "util.h"
+#include "plugin_core.h"
+#include "logger.h"
+
+#ifdef __cplusplus
+
+class VideoDecodeStream {
+public:
+ virtual ~VideoDecodeStream() {}
+
+ virtual void setLoop(bool enable) = 0;
+ virtual bool getLoop() = 0;
+
+ virtual void setPosition(double time) = 0;
+ virtual double getPosition() = 0;
+
+ virtual int getFrameWidth() = 0;
+ virtual int getFrameHeight() = 0;
+
+ virtual double getFrameAspect() = 0;
+ virtual uint8_t* getFrame(long double time) = 0;
+};
+
+#endif /* __cplusplus */
+
+#endif /* _PLUGIN_VIDEO_DECODE_H_ */
diff --git a/mediaplugin/src/plugins/media/include/core/util.h b/mediaplugin/src/plugins/media/include/core/util.h
new file mode 100644
index 00000000..55c5e93f
--- /dev/null
+++ b/mediaplugin/src/plugins/media/include/core/util.h
@@ -0,0 +1,292 @@
+/* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+#ifndef _UTIL_H_
+#define _UTIL_H_
+
+#include <string>
+#include "plugin_core.h"
+
+class AudioFormatInfo {
+private:
+ double _sampleRate;
+ uint8_t _channels;
+ audioSampleFormat_t _format;
+ int _frameSize;
+
+ void updateFrameSize() {
+ _frameSize = g_audioSampleSize[_format] * _channels;
+ }
+
+public:
+ double getSampleRate() const { return _sampleRate; }
+ void setSampleRate(double sampleRate) { _sampleRate = sampleRate; }
+
+ uint8_t getChannels() const { return _channels; }
+ void setChannels(uint8_t channels) {
+ _channels = channels;
+ updateFrameSize();
+ }
+
+ audioSampleFormat_t getFormat() const { return _format; }
+ void setFormat(audioSampleFormat_t sampleFormat) {
+ _format = sampleFormat;
+ updateFrameSize();
+ }
+
+ long getFrameSize() const { return _frameSize; }
+ double getBytesPerSec() const { return _frameSize * _sampleRate; }
+
+public:
+ AudioFormatInfo() :
+ _sampleRate(0),
+ _channels(0),
+ _format(asfUnknown),
+ _frameSize(0)
+ {}
+
+ AudioFormatInfo(int channels, int sampleRate, audioSampleFormat_t sampleFormat) :
+ _sampleRate(sampleRate), _channels(channels), _format(sampleFormat)
+ {
+ updateFrameSize();
+ }
+
+ AudioFormatInfo(audioFormatInfo_t *info) :
+ _sampleRate(info->sampleRate),
+ _channels(info->channels),
+ _format(info->format)
+ {
+ updateFrameSize();
+ }
+
+ /**
+ * Returns the inverse ratio of the size of data in this format to its
+ * size in a given target format.
+ * Example: SrcSize*SrcInfo.GetRatio(TgtInfo) = TgtSize
+ */
+ double getRatio(const AudioFormatInfo &targetInfo) const {
+ return (targetInfo.getFrameSize() / this->_frameSize) *
+ (targetInfo.getSampleRate() / this->_sampleRate);
+ }
+
+ void toCStruct(audioFormatInfo_t *info) const {
+ info->channels = _channels;
+ info->format = _format;
+ info->sampleRate = _sampleRate;
+ }
+
+ //AudioFormatInfo copy();
+};
+
+class IPath {
+private:
+ std::string _filename;
+public:
+ IPath(const char *filename) :
+ _filename(filename)
+ {
+ // TODO
+ }
+
+ IPath(std::string filename) :
+ _filename(filename)
+ {
+ // TODO
+ }
+
+ std::string toNative() const {
+ // TODO
+ return _filename;
+ }
+
+ std::string toUTF8() const {
+ // TODO
+ return _filename;
+ }
+
+ bool isFile() const {
+ // TODO
+ return true;
+ }
+};
+
+extern "C" {
+PLUGIN_CALL int threadMainRoutine(void *data);
+}
+
+class Thread {
+private:
+ thread_t *_thread;
+public:
+ Thread() : _thread(0) {}
+ virtual ~Thread() {}
+
+ virtual int run() = 0;
+
+ void start() {
+ _thread = pluginCore->threadCreate(threadMainRoutine, this);
+ }
+
+ /**
+ * Get the 32-bit thread identifier for the current thread.
+ */
+ static uint32_t getCurrentThreadID() {
+ return pluginCore->threadCurrentID();
+ }
+
+ /**
+ * Get the 32-bit thread identifier for the specified thread,
+ * equivalent to SDL_ThreadID() if the specified thread is NULL.
+ */
+ uint32_t getThreadID() {
+ return pluginCore->threadGetID(_thread);
+ }
+
+ /**
+ * Wait a specified number of milliseconds before returning.
+ */
+ static void sleep(uint32_t ms) {
+ pluginCore->threadSleep(ms);
+ }
+
+ /**
+ * Wait for a thread to finish.
+ * The return code for the thread function is placed in the area
+ * pointed to by 'status', if 'status' is not NULL.
+ */
+ void wait(int *status) {
+ if (_thread) {
+ pluginCore->threadWait(_thread, status);
+ }
+ }
+
+ void wait() {
+ int status;
+ if (_thread) {
+ pluginCore->threadWait(_thread, &status);
+ }
+ }
+};
+
+class Condition;
+
+class Mutex {
+private:
+ friend class Condition;
+ mutex_t *_mutex;
+public:
+ Mutex() {
+ _mutex = pluginCore->mutexCreate();
+ }
+
+ ~Mutex() {
+ pluginCore->mutexDestroy(_mutex);
+ }
+
+ /**
+ * Lock the mutex
+ * Returns 0, or -1 on error
+ */
+ int lock() {
+ return pluginCore->mutexLock(_mutex);
+ }
+
+ /**
+ * Unlock the mutex
+ * It is an error to unlock a mutex that has not been locked by
+ * the current thread, and doing so results in undefined behavior.
+ *
+ * Returns 0, or -1 on error
+ */
+ int unlock() {
+ return pluginCore->mutexUnlock(_mutex);
+ }
+
+ class RegionLock {
+ private:
+ Mutex *_mutex;
+ public:
+ RegionLock(Mutex &mutex) :
+ _mutex(&mutex)
+ {
+ _mutex->lock();
+ }
+
+ ~RegionLock() {
+ _mutex->unlock();
+ }
+ };
+};
+
+class Condition {
+private:
+ cond_t *_cond;
+public:
+ Condition() {
+ _cond = pluginCore->condCreate();
+ }
+
+ ~Condition() {
+ pluginCore->condDestroy(_cond);
+ }
+
+ /**
+ * Wait on the condition variable, unlocking the provided mutex.
+ * The mutex must be locked before entering this function!
+ * The mutex is re-locked once the condition variable is signaled.
+ * Returns 0 when it is signaled, or -1 on error.
+ */
+ int wait(const Mutex &mutex) {
+ return pluginCore->condWait(_cond, mutex._mutex);
+ }
+
+ /*
+ * Waits for at most 'ms' milliseconds, and returns 0 if the condition
+ * variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
+ * signaled in the allotted time, and -1 on error.
+ * On some platforms this function is implemented by looping with a delay
+ * of 1 ms, and so should be avoided if possible.
+ */
+ int waitTimeout(const Mutex &mutex, uint32_t ms) {
+ return pluginCore->condWaitTimeout(_cond, mutex._mutex, ms);
+ }
+
+ /**
+ * Restart one of the threads that are waiting on the condition variable.
+ * Returns 0 or -1 on error.
+ */
+ int signal() {
+ return pluginCore->condSignal(_cond);
+ }
+
+ /**
+ * Restart all threads that are waiting on the condition variable.
+ * Returns 0 or -1 on error.
+ */
+ int broadcast() {
+ return pluginCore->condBroadcast(_cond);
+ }
+};
+
+#endif /* _UTIL_H_ */