aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-10-24 09:09:11 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-10-24 09:09:11 +0000
commit9dad0e6acee4ca2d511334438b8e4417214fd93f (patch)
treee710e94f2c0a6b003345aef40403298f146536c9
parent8913873e901f64846217bfa30c9bc04e1a0ac420 (diff)
downloadusdx-9dad0e6acee4ca2d511334438b8e4417214fd93f.tar.gz
usdx-9dad0e6acee4ca2d511334438b8e4417214fd93f.tar.xz
usdx-9dad0e6acee4ca2d511334438b8e4417214fd93f.zip
more helper functions added, no need for SDL as a plugin dependency anymore
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@2689 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--mediaplugin/src/media/UAudioDecoder_FFmpeg.pas59
-rw-r--r--mediaplugin/src/media/UMediaPlugin.pas259
2 files changed, 263 insertions, 55 deletions
diff --git a/mediaplugin/src/media/UAudioDecoder_FFmpeg.pas b/mediaplugin/src/media/UAudioDecoder_FFmpeg.pas
index 9c734786..3031b46a 100644
--- a/mediaplugin/src/media/UAudioDecoder_FFmpeg.pas
+++ b/mediaplugin/src/media/UAudioDecoder_FFmpeg.pas
@@ -61,7 +61,7 @@ type
TFFmpegDecodeStream = class(TAudioDecodeStream)
private
fFilename: IPath;
- fStream: PDecodeStream;
+ fStream: PAudioDecodeStream;
fFormatInfo: TAudioFormatInfo;
public
@@ -85,7 +85,11 @@ type
type
TAudioDecoder_FFmpeg = class(TInterfacedObject, IAudioDecoder)
+ private
+ fPluginInfo: PMediaPluginInfo;
public
+ constructor Create();
+
function GetName: string;
function InitializeDecoder(): boolean;
@@ -93,6 +97,9 @@ type
function Open(const Filename: IPath): TAudioDecodeStream;
end;
+var
+ AudioDecoderInfo: PAudioDecoderInfo;
+
{ TFFmpegDecodeStream }
constructor TFFmpegDecodeStream.Create();
@@ -118,13 +125,13 @@ begin
Close();
- fStream := DecodeStream_open(PChar(Filename.ToUTF8()));
+ fStream := AudioDecoderInfo.open(PChar(Filename.ToUTF8()));
if (fStream = nil) then
Exit;
fFilename := Filename;
- DecodeStream_getAudioFormatInfo(fStream, Info);
+ AudioDecoderInfo.getAudioFormatInfo(fStream, Info);
fFormatInfo := TAudioFormatInfo.Create(
Info.channels,
Info.sampleRate,
@@ -139,14 +146,14 @@ begin
Self.fFilename := PATH_NONE;
if (fStream <> nil) then
begin
- DecodeStream_close(fStream);
+ AudioDecoderInfo.close(fStream);
fStream := nil;
end;
end;
function TFFmpegDecodeStream.GetLength(): real;
begin
- Result := DecodeStream_getLength(fStream);
+ Result := AudioDecoderInfo.getLength(fStream);
end;
function TFFmpegDecodeStream.GetAudioFormatInfo(): TAudioFormatInfo;
@@ -156,54 +163,78 @@ end;
function TFFmpegDecodeStream.IsEOF(): boolean;
begin
- Result := DecodeStream_isEOF(fStream);
+ Result := AudioDecoderInfo.isEOF(fStream);
end;
function TFFmpegDecodeStream.IsError(): boolean;
begin
- Result := DecodeStream_isError(fStream);
+ Result := AudioDecoderInfo.isError(fStream);
end;
function TFFmpegDecodeStream.GetPosition(): real;
begin
- Result := DecodeStream_getPosition(fStream);
+ Result := AudioDecoderInfo.getPosition(fStream);
end;
procedure TFFmpegDecodeStream.SetPosition(Time: real);
begin
- DecodeStream_setPosition(fStream, Time);
+ AudioDecoderInfo.setPosition(fStream, Time);
end;
function TFFmpegDecodeStream.GetLoop(): boolean;
begin
- Result := DecodeStream_getLoop(fStream);
+ Result := AudioDecoderInfo.getLoop(fStream);
end;
procedure TFFmpegDecodeStream.SetLoop(Enabled: boolean);
begin
- DecodeStream_setLoop(fStream, Enabled);
+ AudioDecoderInfo.setLoop(fStream, Enabled);
end;
function TFFmpegDecodeStream.ReadData(Buffer: PByteArray; BufferSize: integer): integer;
begin
- Result := DecodeStream_readData(fStream, PCUint8(Buffer), BufferSize);
+ Result := AudioDecoderInfo.readData(fStream, PCUint8(Buffer), BufferSize);
end;
{ TAudioDecoder_FFmpeg }
+const
+{$IFDEF MSWINDOWS}
+ ffmpegPlugin = 'ffmpeg_playback.dll';
+{$ENDIF}
+{$IFDEF LINUX}
+ ffmpegPlugin = 'ffmpeg_playback';
+{$ENDIF}
+{$IFDEF DARWIN}
+ ffmpegPlugin = 'ffmpeg_playback.dylib';
+ {$linklib ffmpegPlugin}
+{$ENDIF}
+
+function Plugin_register(core: PMediaPluginCore): PMediaPluginInfo;
+ cdecl; external ffmpegPlugin;
+
+constructor TAudioDecoder_FFmpeg.Create();
+begin
+ inherited Create();
+ fPluginInfo := Plugin_register(MediaPluginCore);
+end;
+
function TAudioDecoder_FFmpeg.GetName: String;
begin
- Result := 'FFmpeg_Decoder';
+ Result := 'Plugin:' + fPluginInfo.name;
end;
function TAudioDecoder_FFmpeg.InitializeDecoder: boolean;
begin
- Result := Plugin_initialize(MediaPluginCore);
+ fPluginInfo.initialize();
+ AudioDecoderInfo := fPluginInfo.audioDecoder;
+ Result := true;
end;
function TAudioDecoder_FFmpeg.FinalizeDecoder(): boolean;
begin
+ fPluginInfo.finalize();
Result := true;
end;
diff --git a/mediaplugin/src/media/UMediaPlugin.pas b/mediaplugin/src/media/UMediaPlugin.pas
index 097a28f2..8e2708bf 100644
--- a/mediaplugin/src/media/UMediaPlugin.pas
+++ b/mediaplugin/src/media/UMediaPlugin.pas
@@ -39,12 +39,46 @@ uses
ctypes;
type
+ PFileStream = Pointer;
+ PThread = Pointer;
+ PMutex = Pointer;
+ PCond = Pointer;
+
PMediaPluginCore = ^TMediaPluginCore;
TMediaPluginCore = record
+ version: cint;
+
log: procedure(level: cint; msg: PChar; context: PChar); cdecl;
+ ticksMillis: function(): cuint32; cdecl;
+
+ fileOpen: function(utf8Filename: PAnsiChar; mode: cint): PFileStream; cdecl;
+ fileClose: procedure(stream: PFileStream); cdecl;
+ fileRead: function(stream: PFileStream; buf: PCuint8; size: cint): cint64; cdecl;
+ fileWrite: function(stream: PFileStream; buf: PCuint8; size: cint): cint64; cdecl;
+ fileSeek: function(stream: PFileStream; pos: cint64; whence: cint): cint64; cdecl;
+ fileSize: function(stream: PFileStream): cint64; cdecl;
+
+ threadCreate: function(func: Pointer; data: Pointer): PThread; cdecl;
+ threadCurrentID: function(): cuint32; cdecl;
+ threadGetID: function(thread: PThread): cuint32; cdecl;
+ threadWait: procedure(thread: PThread; status: PCint); cdecl;
+ threadSleep: procedure(millisecs: cuint32); cdecl;
+
+ mutexCreate: function(): PMutex; cdecl;
+ mutexDestroy: procedure(mutex: PMutex); cdecl;
+ mutexLock: function(mutex: PMutex): cint; cdecl;
+ mutexUnlock: function(mutex: PMutex): cint; cdecl;
+
+ condCreate: function(): PCond; cdecl;
+ condDestroy: procedure(cond: PCond); cdecl;
+ condSignal: function(cond: PCond): cint; cdecl;
+ condBroadcast: function(cond: PCond): cint; cdecl;
+ condWait: function(cond: PCond; mutex: PMutex): cint; cdecl;
+ condWaitTimeout: function(cond: PCond; mutex: PMutex; ms: cuint32): cint; cdecl;
end;
- PDecodeStream = Pointer;
+ PAudioDecodeStream = Pointer;
+ PAudioResampleStream = Pointer;
PCAudioFormatInfo = ^TCAudioFormatInfo;
TCAudioFormatInfo = record
@@ -53,49 +87,46 @@ type
format: cint;
end;
-const
-{$IFDEF MSWINDOWS}
- ffmpegPlugin = 'ffmpeg_playback.dll';
-{$ENDIF}
-{$IFDEF LINUX}
- ffmpegPlugin = 'ffmpeg_playback';
-{$ENDIF}
-{$IFDEF DARWIN}
- ffmpegPlugin = 'ffmpeg_playback.dylib';
- {$linklib ffmpegPlugin}
-{$ENDIF}
+ PAudioDecoderInfo = ^TAudioDecoderInfo;
+ TAudioDecoderInfo = record
+ open: function(filename: PAnsiChar): PAudioDecodeStream; cdecl;
+ close: procedure(stream: PAudioDecodeStream); cdecl;
+ getLength: function(stream: PAudioDecodeStream): double; cdecl;
+ getAudioFormatInfo: procedure(stream: PAudioDecodeStream; var info: TCAudioFormatInfo); cdecl;
+ getPosition: function(stream: PAudioDecodeStream): double; cdecl;
+ setPosition: procedure(stream: PAudioDecodeStream; time: double); cdecl;
+ getLoop: function(stream: PAudioDecodeStream): cbool; cdecl;
+ setLoop: procedure(stream: PAudioDecodeStream; enabled: cbool); cdecl;
+ isEOF: function(stream: PAudioDecodeStream): cbool; cdecl;
+ isError: function(stream: PAudioDecodeStream): cbool; cdecl;
+ readData: function(stream: PAudioDecodeStream; buffer: PCUint8; bufferSize: cint): cint; cdecl;
+ end;
-function Plugin_initialize(core: PMediaPluginCore): cbool;
- cdecl; external ffmpegPlugin;
-
-function DecodeStream_open(filename: PAnsiChar): PDecodeStream;
- cdecl; external ffmpegPlugin;
-procedure DecodeStream_close(stream: PDecodeStream);
- cdecl; external ffmpegPlugin;
-function DecodeStream_getLength(stream: PDecodeStream): double;
- cdecl; external ffmpegPlugin;
-procedure DecodeStream_getAudioFormatInfo(stream: PDecodeStream; var info: TCAudioFormatInfo);
- cdecl; external ffmpegPlugin;
-function DecodeStream_getPosition(stream: PDecodeStream): double;
- cdecl; external ffmpegPlugin;
-procedure DecodeStream_setPosition(stream: PDecodeStream; time: double);
- cdecl; external ffmpegPlugin;
-function DecodeStream_getLoop(stream: PDecodeStream): cbool;
- cdecl; external ffmpegPlugin;
-procedure DecodeStream_setLoop(stream: PDecodeStream; enabled: cbool);
- cdecl; external ffmpegPlugin;
-function DecodeStream_isEOF(stream: PDecodeStream): cbool;
- cdecl; external ffmpegPlugin;
-function DecodeStream_isError(stream: PDecodeStream): cbool;
- cdecl; external ffmpegPlugin;
-function DecodeStream_readData(stream: PDecodeStream; buffer: PCUint8; bufferSize: cint): cint;
- cdecl; external ffmpegPlugin;
+ PAudioConverterInfo = ^TAudioConverterInfo;
+ TAudioConverterInfo = record
+ open: function(inputFormat: PCAudioFormatInfo; outputFormat: PCAudioFormatInfo): PAudioResampleStream; cdecl;
+ close: procedure(stream: PAudioResampleStream); cdecl;
+ convert: function(stream: PAudioResampleStream; input, output: PCuint8; numSamples: cint): cint; cdecl;
+ end;
+
+ PMediaPluginInfo = ^TMediaPluginInfo;
+ TMediaPluginInfo = record
+ version: cint;
+ name: PAnsiChar;
+ initialize: function(): cbool; cdecl;
+ finalize: function(): cbool; cdecl;
+ audioDecoder: PAudioDecoderInfo;
+ audioConverter: PAudioConverterInfo;
+ end;
+
+ Plugin_register = function(core: PMediaPluginCore): PMediaPluginInfo; cdecl;
function MediaPluginCore: PMediaPluginCore;
implementation
uses
+ SDL,
ULog;
var
@@ -111,19 +142,165 @@ const
LOG_LEVEL_CRITICAL
);
-procedure LogFunc(level: cint; msg: PChar; context: PChar); cdecl;
+function MediaPluginCore: PMediaPluginCore;
+begin
+ Result := @MediaPluginCore_Instance;
+end;
+
+{* Misc *}
+
+procedure Core_log(level: cint; msg: PChar; context: PChar); cdecl;
begin
Log.LogMsg(msg, context, DebugLogLevels[level]);
end;
-function MediaPluginCore: PMediaPluginCore;
+function Core_ticksMillis(): cuint32; cdecl;
begin
- Result := @MediaPluginCore_Instance;
+ Result := SDL_GetTicks();
+end;
+
+{* File *}
+
+function Core_fileOpen(utf8Filename: PChar; mode: cint): PFileStream; cdecl;
+begin
+
+end;
+
+procedure Core_fileClose(stream: PFileStream); cdecl;
+begin
+
+end;
+
+function Core_fileRead(stream: PFileStream; buf: PCuint8; size: cint): cint64; cdecl;
+begin
+
+end;
+
+function Core_fileWrite(stream: PFileStream; buf: PCuint8; size: cint): cint64; cdecl;
+begin
+
+end;
+
+function Core_fileSeek(stream: PFileStream; pos: cint64; whence: cint): cint64; cdecl;
+begin
+
+end;
+
+function Core_fileSize(stream: PFileStream): cint64; cdecl;
+begin
+
+end;
+
+{* Thread *}
+
+function Core_threadCreate(func: Pointer; data: Pointer): PThread; cdecl;
+begin
+ Result := SDL_CreateThread(func, data);
+end;
+
+function Core_threadCurrentID(): cuint32; cdecl;
+begin
+ Result := SDL_ThreadID();
+end;
+
+function Core_threadGetID(thread: PThread): cuint32; cdecl;
+begin
+ Result := SDL_GetThreadID(PSDL_Thread(thread));
+end;
+
+procedure Core_threadWait(thread: PThread; status: PCint); cdecl;
+begin
+ SDL_WaitThread(PSDL_Thread(thread), status^);
+end;
+
+procedure Core_threadSleep(millisecs: cuint32); cdecl;
+begin
+ SDL_Delay(millisecs);
+end;
+
+{* Mutex *}
+
+function Core_mutexCreate(): PMutex; cdecl;
+begin
+ Result := PMutex(SDL_CreateMutex());
+end;
+
+procedure Core_mutexDestroy(mutex: PMutex); cdecl;
+begin
+ SDL_DestroyMutex(PSDL_Mutex(mutex));
+end;
+
+function Core_mutexLock(mutex: PMutex): cint; cdecl;
+begin
+ Result := SDL_mutexP(PSDL_Mutex(mutex));
+end;
+
+function Core_mutexUnlock(mutex: PMutex): cint; cdecl;
+begin
+ Result := SDL_mutexV(PSDL_Mutex(mutex));
+end;
+
+{* Condition *}
+
+function Core_condCreate(): PCond; cdecl;
+begin
+ Result := PCond(SDL_CreateCond());
+end;
+
+procedure Core_condDestroy(cond: PCond); cdecl;
+begin
+ SDL_DestroyCond(PSDL_Cond(cond));
+end;
+
+function Core_condSignal(cond: PCond): cint; cdecl;
+begin
+ Result := SDL_CondSignal(PSDL_Cond(cond));
+end;
+
+function Core_condBroadcast(cond: PCond): cint; cdecl;
+begin
+ Result := SDL_CondBroadcast(PSDL_Cond(cond));
+end;
+
+function Core_condWait(cond: PCond; mutex: PMutex): cint; cdecl;
+begin
+ Result := SDL_CondWait(PSDL_Cond(cond), PSDL_Mutex(mutex));
+end;
+
+function Core_condWaitTimeout(cond: PCond; mutex: PMutex; ms: cuint32): cint; cdecl;
+begin
+ Result := SDL_CondWaitTimeout(PSDL_Cond(cond), PSDL_Mutex(mutex), ms);
end;
procedure InitializeMediaPluginCore;
begin
- MediaPluginCore.log := LogFunc;
+ with MediaPluginCore_Instance do
+ begin
+ version := 0;
+ log := Core_log;
+ ticksMillis := Core_ticksMillis;
+ fileOpen := Core_fileOpen;
+ fileClose := Core_fileClose;
+ fileRead := Core_fileRead;
+ fileWrite := Core_fileWrite;
+ fileSeek := Core_fileSeek;
+ fileSize := Core_fileSize;
+ threadCreate := Core_threadCreate;
+ threadCurrentID := Core_threadCurrentID;
+ threadGetID := Core_threadGetID;
+ threadWait := Core_threadWait;
+ threadSleep := Core_threadSleep;
+ mutexCreate := Core_mutexCreate;
+ mutexDestroy := Core_mutexDestroy;
+ mutexLock := Core_mutexLock;
+ mutexUnlock := Core_mutexUnlock;
+ condCreate := Core_condCreate;
+ condDestroy := Core_condDestroy;
+ condSignal := Core_condSignal;
+ condBroadcast := Core_condBroadcast;
+ condWait := Core_condWait;
+ condWaitTimeout := Core_condWaitTimeout;
+ end;
end;
initialization