aboutsummaryrefslogtreecommitdiffstats
path: root/mediaplugin/src/plugins/media/include/core/plugin_core.h
blob: e62dd21b35c236d3c2f2a924115c73f623628f60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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
};

typedef struct audioFormatInfo_t {
    double sampleRate;
    uint8_t channels;
    audioSampleFormat_t format;
} audioFormatInfo_t;

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)
extern 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_ */