aboutsummaryrefslogtreecommitdiffstats
path: root/mediaplugin/src/media
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mediaplugin/src/media/UAudioConverter.pas125
-rw-r--r--mediaplugin/src/media/UAudioDecoderPlugin.pas8
-rw-r--r--mediaplugin/src/media/UAudioDecoder_Bass.pas8
-rw-r--r--mediaplugin/src/media/UAudioInput_Bass.pas10
-rw-r--r--mediaplugin/src/media/UAudioInput_Portaudio.pas8
-rw-r--r--mediaplugin/src/media/UAudioPlaybackBase.pas1
-rw-r--r--mediaplugin/src/media/UAudioPlayback_Bass.pas7
-rw-r--r--mediaplugin/src/media/UAudioPlayback_SDL.pas8
-rw-r--r--mediaplugin/src/media/UAudioPlayback_SoftMixer.pas29
-rw-r--r--mediaplugin/src/media/UMediaPlugin.pas3
-rw-r--r--mediaplugin/src/media/UMedia_dummy.pas12
-rw-r--r--mediaplugin/src/media/UVideo.pas9
-rw-r--r--mediaplugin/src/media/UVideoDecoderPlugin.pas10
-rw-r--r--mediaplugin/src/media/UVisualizer.pas6
14 files changed, 180 insertions, 64 deletions
diff --git a/mediaplugin/src/media/UAudioConverter.pas b/mediaplugin/src/media/UAudioConverter.pas
index 7826c265..de6840ca 100644
--- a/mediaplugin/src/media/UAudioConverter.pas
+++ b/mediaplugin/src/media/UAudioConverter.pas
@@ -47,27 +47,30 @@ uses
Math;
type
- {*
- * Notes:
- * - 44.1kHz to 48kHz conversion or vice versa is not supported
- * by SDL 1.2 (will be introduced in 1.3).
- * No conversion takes place in this cases.
- * This is because SDL just converts differences in powers of 2.
- * So the result might not be that accurate.
- * This IS audible (voice to high/low) and it needs good synchronization
- * with the video or the lyrics timer.
- * - float<->int16 conversion is not supported (will be part of 1.3) and
- * SDL (<1.3) is not capable of handling floats at all.
- * -> Using FFmpeg or libsamplerate for resampling is preferred.
- * Use SDL for channel and format conversion only.
- *}
- TAudioConverter_SDL = class(TAudioConverter)
+ TAudioConverter_SDL = class(TInterfacedObject, IAudioConverter)
+ public
+ function GetName(): string;
+ function GetPriority(): integer;
+ function Init(): boolean;
+ function Finalize(): boolean;
+
+ function Open(SrcFormatInfo: TAudioFormatInfo;
+ DstFormatInfo: TAudioFormatInfo): TAudioConvertStream;
+ end;
+
+ TAudioConvertStream_SDL = class(TAudioConvertStream)
private
cvt: TSDL_AudioCVT;
+ function Init(): boolean;
+ protected
+ constructor Create(SrcFormatInfo: TAudioFormatInfo;
+ DstFormatInfo: TAudioFormatInfo);
public
- function Init(SrcFormatInfo: TAudioFormatInfo; DstFormatInfo: TAudioFormatInfo): boolean; override;
destructor Destroy(); override;
+ class function Open(SrcFormatInfo: TAudioFormatInfo;
+ DstFormatInfo: TAudioFormatInfo): TAudioConvertStream_SDL;
+
function Convert(InputBuffer: PByteArray; OutputBuffer: PByteArray; var InputSize: integer): integer; override;
function GetOutputBufferSize(InputSize: integer): integer; override;
function GetRatio(): double; override;
@@ -115,18 +118,85 @@ type
// if people sing along with the song.
// But FFmpeg might offer a better quality/speed ratio than SRC_LINEAR.
const
- SRC_CONVERTER_TYPE = SRC_LINEAR;
+ SRC_CONVERTER_TYPE = SRC_LINEAR;
{$ENDIF}
implementation
-function TAudioConverter_SDL.Init(srcFormatInfo: TAudioFormatInfo; dstFormatInfo: TAudioFormatInfo): boolean;
+{ TAudioConverter_SDL }
+
+function TAudioConverter_SDL.GetName(): string;
+begin
+ Result := 'AudioConverter_SDL';
+end;
+
+function TAudioConverter_SDL.GetPriority(): integer;
+begin
+ {* Notes:
+ * - 44.1kHz to 48kHz conversion or vice versa is not supported
+ * by SDL 1.2 (will be introduced in 1.3).
+ * No conversion takes place in this cases.
+ * This is because SDL just converts differences in powers of 2.
+ * So the result might not be that accurate.
+ * This IS audible (voice to high/low) and it needs good synchronization
+ * with the video or the lyrics timer.
+ * - float<->int16 conversion is not supported (will be part of 1.3) and
+ * SDL (<1.3) is not capable of handling floats at all.
+ * -> Using FFmpeg or libsamplerate for resampling is preferred.
+ * Use SDL for channel and format conversion only.
+ *}
+ Result := 0;
+end;
+
+function TAudioConverter_SDL.Init(): boolean;
+begin
+ Result := true;
+end;
+
+function TAudioConverter_SDL.Finalize(): boolean;
+begin
+ Result := true;
+end;
+
+function TAudioConverter_SDL.Open(SrcFormatInfo: TAudioFormatInfo;
+ DstFormatInfo: TAudioFormatInfo): TAudioConvertStream;
+begin
+ Result := TAudioConvertStream_SDL.Open(SrcFormatInfo, DstFormatInfo);
+end;
+
+{ TAudioConvertStream_SDL }
+
+constructor TAudioConvertStream_SDL.Create(SrcFormatInfo: TAudioFormatInfo;
+ DstFormatInfo: TAudioFormatInfo);
+begin
+ inherited Create(SrcFormatInfo, DstFormatInfo);
+end;
+
+destructor TAudioConvertStream_SDL.Destroy();
+begin
+ inherited;
+end;
+
+class function TAudioConvertStream_SDL.Open(SrcFormatInfo: TAudioFormatInfo;
+ DstFormatInfo: TAudioFormatInfo): TAudioConvertStream_SDL;
+var
+ Stream: TAudioConvertStream_SDL;
+begin
+ Result := nil;
+ Stream := TAudioConvertStream_SDL.Create(SrcFormatInfo, DstFormatInfo);
+ if (not Stream.Init()) then
+ begin
+ Stream.Free;
+ Exit;
+ end;
+ Result := Stream;
+end;
+
+function TAudioConvertStream_SDL.Init(): boolean;
var
srcFormat: UInt16;
dstFormat: UInt16;
begin
- inherited Init(SrcFormatInfo, DstFormatInfo);
-
Result := false;
if (not ConvertAudioFormatToSDL(srcFormatInfo.Format, srcFormat) or
@@ -147,29 +217,23 @@ begin
Result := true;
end;
-destructor TAudioConverter_SDL.Destroy();
-begin
- // nothing to be done here
- inherited;
-end;
-
(*
* Returns the size of the output buffer. This might be bigger than the actual
* size of resampled audio data.
*)
-function TAudioConverter_SDL.GetOutputBufferSize(InputSize: integer): integer;
+function TAudioConvertStream_SDL.GetOutputBufferSize(InputSize: integer): integer;
begin
// Note: len_ratio must not be used here. Even if the len_ratio is 1.0, len_mult might be 2.
// Example: 44.1kHz/mono to 22.05kHz/stereo -> len_ratio=1, len_mult=2
Result := InputSize * cvt.len_mult;
end;
-function TAudioConverter_SDL.GetRatio(): double;
+function TAudioConvertStream_SDL.GetRatio(): double;
begin
Result := cvt.len_ratio;
end;
-function TAudioConverter_SDL.Convert(InputBuffer: PByteArray; OutputBuffer: PByteArray; var InputSize: integer): integer;
+function TAudioConvertStream_SDL.Convert(InputBuffer: PByteArray; OutputBuffer: PByteArray; var InputSize: integer): integer;
begin
Result := -1;
@@ -457,4 +521,7 @@ end;
{$ENDIF}
+initialization
+ MediaManager.add(TAudioConverter_SDL.Create);
+
end. \ No newline at end of file
diff --git a/mediaplugin/src/media/UAudioDecoderPlugin.pas b/mediaplugin/src/media/UAudioDecoderPlugin.pas
index 8298cf17..e518277c 100644
--- a/mediaplugin/src/media/UAudioDecoderPlugin.pas
+++ b/mediaplugin/src/media/UAudioDecoderPlugin.pas
@@ -56,7 +56,8 @@ type
public
constructor Create(Info: PMediaPluginInfo);
- function GetName: string;
+ function GetName(): string;
+ function GetPriority(): integer;
function InitializeDecoder(): boolean;
function FinalizeDecoder(): boolean;
@@ -211,6 +212,11 @@ begin
Result := 'Plugin:AudioDecoder:' + fPluginInfo.name;
end;
+function TAudioDecoderPlugin.GetPriority(): integer;
+begin
+ Result := fPluginInfo.audioDecoder.priority;
+end;
+
function TAudioDecoderPlugin.InitializeDecoder: boolean;
begin
//fPluginInfo.initialize();
diff --git a/mediaplugin/src/media/UAudioDecoder_Bass.pas b/mediaplugin/src/media/UAudioDecoder_Bass.pas
index d6d2425a..e08b91ff 100644
--- a/mediaplugin/src/media/UAudioDecoder_Bass.pas
+++ b/mediaplugin/src/media/UAudioDecoder_Bass.pas
@@ -73,6 +73,7 @@ type
TAudioDecoder_Bass = class( TInterfacedObject, IAudioDecoder )
public
function GetName: string;
+ function GetPriority: integer;
function InitializeDecoder(): boolean;
function FinalizeDecoder(): boolean;
@@ -209,7 +210,12 @@ end;
function TAudioDecoder_Bass.GetName: String;
begin
- result := 'BASS_Decoder';
+ Result := 'BASS_Decoder';
+end;
+
+function TAudioDecoder_Bass.GetPriority: integer;
+begin
+ Result := 90;
end;
function TAudioDecoder_Bass.InitializeDecoder(): boolean;
diff --git a/mediaplugin/src/media/UAudioInput_Bass.pas b/mediaplugin/src/media/UAudioInput_Bass.pas
index 0e79b343..f95c0aa1 100644
--- a/mediaplugin/src/media/UAudioInput_Bass.pas
+++ b/mediaplugin/src/media/UAudioInput_Bass.pas
@@ -59,6 +59,7 @@ type
function EnumDevices(): boolean;
public
function GetName: String; override;
+ function GetPriority: integer; override;
function InitializeRecord: boolean; override;
function FinalizeRecord: boolean; override;
end;
@@ -346,9 +347,14 @@ end;
{ TAudioInput_Bass }
-function TAudioInput_Bass.GetName: String;
+function TAudioInput_Bass.GetName: String;
begin
- result := 'BASS_Input';
+ Result := 'BASS_Input';
+end;
+
+function TAudioInput_Bass.GetPriority: integer;
+begin
+ Result := 90;
end;
function TAudioInput_Bass.EnumDevices(): boolean;
diff --git a/mediaplugin/src/media/UAudioInput_Portaudio.pas b/mediaplugin/src/media/UAudioInput_Portaudio.pas
index c7364eb4..ad93c12a 100644
--- a/mediaplugin/src/media/UAudioInput_Portaudio.pas
+++ b/mediaplugin/src/media/UAudioInput_Portaudio.pas
@@ -61,6 +61,7 @@ type
function EnumDevices(): boolean;
public
function GetName: string; override;
+ function GetPriority: integer; override;
function InitializeRecord: boolean; override;
function FinalizeRecord: boolean; override;
end;
@@ -311,7 +312,12 @@ end;
function TAudioInput_Portaudio.GetName: String;
begin
- result := 'Portaudio';
+ Result := 'Portaudio';
+end;
+
+function TAudioInput_Portaudio.GetPriority: integer;
+begin
+ Result := 40;
end;
function TAudioInput_Portaudio.EnumDevices(): boolean;
diff --git a/mediaplugin/src/media/UAudioPlaybackBase.pas b/mediaplugin/src/media/UAudioPlaybackBase.pas
index 5f317257..65528430 100644
--- a/mediaplugin/src/media/UAudioPlaybackBase.pas
+++ b/mediaplugin/src/media/UAudioPlaybackBase.pas
@@ -52,6 +52,7 @@ type
function OpenDecodeStream(const Filename: IPath): TAudioDecodeStream;
public
function GetName: string; virtual; abstract;
+ function GetPriority: integer; virtual; abstract;
function Open(const Filename: IPath): boolean; // true if succeed
procedure Close;
diff --git a/mediaplugin/src/media/UAudioPlayback_Bass.pas b/mediaplugin/src/media/UAudioPlayback_Bass.pas
index 1d7a44dc..0cdf8624 100644
--- a/mediaplugin/src/media/UAudioPlayback_Bass.pas
+++ b/mediaplugin/src/media/UAudioPlayback_Bass.pas
@@ -121,6 +121,8 @@ type
function CreatePlaybackStream(): TAudioPlaybackStream; override;
public
function GetName: String; override;
+ function GetPriority: integer; override;
+
function InitializePlayback(): boolean; override;
function FinalizePlayback: boolean; override;
procedure SetAppVolume(Volume: single); override;
@@ -649,6 +651,11 @@ begin
Result := 'BASS_Playback';
end;
+function TAudioPlayback_Bass.GetPriority: integer;
+begin
+ Result := 90;
+end;
+
function TAudioPlayback_Bass.EnumDevices(): boolean;
var
BassDeviceID: DWORD;
diff --git a/mediaplugin/src/media/UAudioPlayback_SDL.pas b/mediaplugin/src/media/UAudioPlayback_SDL.pas
index 8403ef03..cbc3056b 100644
--- a/mediaplugin/src/media/UAudioPlayback_SDL.pas
+++ b/mediaplugin/src/media/UAudioPlayback_SDL.pas
@@ -57,7 +57,8 @@ type
function FinalizeAudioPlaybackEngine(): boolean; override;
function GetLatency(): double; override;
public
- function GetName: String; override;
+ function GetName: String; override;
+ function GetPriority: integer; override;
procedure MixBuffers(dst, src: PByteArray; size: Cardinal; volume: Single); override;
end;
@@ -77,6 +78,11 @@ begin
Result := 'SDL_Playback';
end;
+function TAudioPlayback_SDL.GetPriority: integer;
+begin
+ Result := 60;
+end;
+
function TAudioPlayback_SDL.EnumDevices(): boolean;
begin
// Note: SDL does not provide Device-Selection capabilities (will be introduced in 1.3)
diff --git a/mediaplugin/src/media/UAudioPlayback_SoftMixer.pas b/mediaplugin/src/media/UAudioPlayback_SoftMixer.pas
index b8148b4a..39f71147 100644
--- a/mediaplugin/src/media/UAudioPlayback_SoftMixer.pas
+++ b/mediaplugin/src/media/UAudioPlayback_SoftMixer.pas
@@ -59,7 +59,7 @@ type
SourceBufferSize: integer;
SourceBufferCount: integer; // number of available bytes in SourceBuffer
- Converter: TAudioConverter;
+ Converter: TAudioConvertStream;
Status: TStreamStatus;
InternalLock: PSDL_Mutex;
SoundEffects: TList;
@@ -73,7 +73,6 @@ type
procedure Reset();
procedure ApplySoundEffects(Buffer: PByteArray; BufferSize: integer);
- function InitFormatConversion(): boolean;
procedure FlushBuffers();
procedure LockSampleBuffer(); {$IFDEF HasInline}inline;{$ENDIF}
@@ -387,7 +386,9 @@ begin
Exit;
Self.SourceStream := SourceStream;
- if not InitFormatConversion() then
+ Converter := AudioConverter.Open(SourceStream.GetAudioFormatInfo(),
+ GetAudioFormatInfo());
+ if (Converter = nil) then
begin
// reset decode-stream so it will not be freed on destruction
Self.SourceStream := nil;
@@ -422,28 +423,6 @@ begin
SDL_mutexV(InternalLock);
end;
-function TGenericPlaybackStream.InitFormatConversion(): boolean;
-var
- SrcFormatInfo: TAudioFormatInfo;
- DstFormatInfo: TAudioFormatInfo;
-begin
- Result := false;
-
- SrcFormatInfo := SourceStream.GetAudioFormatInfo();
- DstFormatInfo := GetAudioFormatInfo();
-
- // TODO: selection should not be done here, use a factory (TAudioConverterFactory) instead
- {$IF Defined(UseFFmpegResample)}
- Converter := TAudioConverterPlugin.Create();
- {$ELSEIF Defined(UseSRCResample)}
- Converter := TAudioConverter_SRC.Create();
- {$ELSE}
- Converter := TAudioConverter_SDL.Create();
- {$IFEND}
-
- Result := Converter.Init(SrcFormatInfo, DstFormatInfo);
-end;
-
procedure TGenericPlaybackStream.Play();
var
Mixer: TAudioMixerStream;
diff --git a/mediaplugin/src/media/UMediaPlugin.pas b/mediaplugin/src/media/UMediaPlugin.pas
index 9f3c8160..762b5af0 100644
--- a/mediaplugin/src/media/UMediaPlugin.pas
+++ b/mediaplugin/src/media/UMediaPlugin.pas
@@ -91,6 +91,7 @@ type
PAudioDecoderInfo = ^TAudioDecoderInfo;
TAudioDecoderInfo = record
+ priority: cint;
open: function(filename: PAnsiChar): PAudioDecodeStream; cdecl;
close: procedure(stream: PAudioDecodeStream); cdecl;
getLength: function(stream: PAudioDecodeStream): double; cdecl;
@@ -106,6 +107,7 @@ type
PAudioConverterInfo = ^TAudioConverterInfo;
TAudioConverterInfo = record
+ priority: cint;
open: function(inputFormat: PCAudioFormatInfo; outputFormat: PCAudioFormatInfo): PAudioConvertStream; cdecl;
close: procedure(stream: PAudioConvertStream); cdecl;
convert: function(stream: PAudioConvertStream; input, output: PCuint8; numSamples: PCint): cint; cdecl;
@@ -115,6 +117,7 @@ type
PVideoDecoderInfo = ^TVideoDecoderInfo;
TVideoDecoderInfo = record
+ priority: cint;
open: function(filename: PAnsiChar): PVideoDecodeStream; cdecl;
close: procedure(stream: PVideoDecodeStream); cdecl;
setLoop: procedure(stream: PVideoDecodeStream; enable: cbool); cdecl;
diff --git a/mediaplugin/src/media/UMedia_dummy.pas b/mediaplugin/src/media/UMedia_dummy.pas
index 46cbe6b8..1ada6603 100644
--- a/mediaplugin/src/media/UMedia_dummy.pas
+++ b/mediaplugin/src/media/UMedia_dummy.pas
@@ -49,6 +49,7 @@ type
public
constructor Create();
function GetName: string;
+ function GetPriority: integer;
function Init(): boolean;
function Finalize(): boolean;
@@ -157,6 +158,7 @@ type
public
constructor Create();
function GetName: string;
+ function GetPriority: integer;
function Init(): boolean;
function Finalize(): boolean;
@@ -169,6 +171,11 @@ begin
Result := 'AudioDummy';
end;
+function TAudio_Dummy.GetPriority: integer;
+begin
+ Result := -100;
+end;
+
constructor TAudio_Dummy.Create();
begin
inherited;
@@ -469,6 +476,11 @@ begin
Result := 'VideoDummy';
end;
+function TVideoPlayback_Dummy.GetPriority: integer;
+begin
+ Result := -100;
+end;
+
function TVideoPlayback_Dummy.Init(): boolean;
begin
Result := true;
diff --git a/mediaplugin/src/media/UVideo.pas b/mediaplugin/src/media/UVideo.pas
index 6caf9658..d7fab209 100644
--- a/mediaplugin/src/media/UVideo.pas
+++ b/mediaplugin/src/media/UVideo.pas
@@ -170,6 +170,7 @@ type
TVideoPlayback_FFmpeg = class( TInterfacedObject, IVideoPlayback )
public
function GetName: String;
+ function GetPriority: integer;
function Init(): boolean;
function Finalize: boolean;
@@ -183,7 +184,12 @@ type
function TVideoPlayback_FFmpeg.GetName: String;
begin
- result := 'OpenGL_VideoPlayback';
+ Result := 'OpenGL_VideoPlayback';
+end;
+
+function TVideoPlayback_FFmpeg.GetPriority: integer;
+begin
+ Result := 80;
end;
function TVideoPlayback_FFmpeg.Init(): boolean;
@@ -236,7 +242,6 @@ function TVideo_FFmpeg.Open(const Decoder: TVideoDecodeStream): boolean;
var
glErr: GLenum;
begin
- Result := false;
Reset();
fDecoder := Decoder;
diff --git a/mediaplugin/src/media/UVideoDecoderPlugin.pas b/mediaplugin/src/media/UVideoDecoderPlugin.pas
index 684b6031..d513a0b3 100644
--- a/mediaplugin/src/media/UVideoDecoderPlugin.pas
+++ b/mediaplugin/src/media/UVideoDecoderPlugin.pas
@@ -45,7 +45,8 @@ type
public
constructor Create(Info: PMediaPluginInfo);
- function GetName: String;
+ function GetName(): String;
+ function GetPriority(): integer;
function InitializeDecoder(): boolean;
function FinalizeDecoder: boolean;
@@ -98,11 +99,16 @@ begin
fPluginInfo := Info;
end;
-function TVideoDecoderPlugin.GetName: String;
+function TVideoDecoderPlugin.GetName(): String;
begin
Result := 'Plugin:VideoDecoder:' + fPluginInfo.name;
end;
+function TVideoDecoderPlugin.GetPriority(): integer;
+begin
+ Result := fPluginInfo.videoDecoder.priority;
+end;
+
function TVideoDecoderPlugin.InitializeDecoder(): boolean;
begin
//fPluginInfo.initialize();
diff --git a/mediaplugin/src/media/UVisualizer.pas b/mediaplugin/src/media/UVisualizer.pas
index 1cdc3500..d7fc460c 100644
--- a/mediaplugin/src/media/UVisualizer.pas
+++ b/mediaplugin/src/media/UVisualizer.pas
@@ -183,6 +183,7 @@ type
public
function GetName: String;
+ function GetPriority: integer;
function Init(): boolean;
function Finalize(): boolean;
@@ -198,6 +199,11 @@ begin
Result := 'ProjectM';
end;
+function TVideoPlayback_ProjectM.GetPriority: integer;
+begin
+ Result := 80;
+end;
+
function TVideoPlayback_ProjectM.Init(): boolean;
begin
Result := true;