diff options
author | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2010-11-01 20:13:59 +0000 |
---|---|---|
committer | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2010-11-01 20:13:59 +0000 |
commit | 0b833c98bc6e9f79320b45dfc331cd5121078150 (patch) | |
tree | 2bb362f67ab82c8be0a5503b55c33fbab077b4fd /mediaplugin | |
parent | 4063388c8b0df5be7b1877d32e89723aae612618 (diff) | |
download | usdx-0b833c98bc6e9f79320b45dfc331cd5121078150.tar.gz usdx-0b833c98bc6e9f79320b45dfc331cd5121078150.tar.xz usdx-0b833c98bc6e9f79320b45dfc331cd5121078150.zip |
- audio converter managed by media interface handler
- added (yet unused) interface priorities
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@2700 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'mediaplugin')
-rw-r--r-- | mediaplugin/src/base/UMusic.pas | 213 | ||||
-rw-r--r-- | mediaplugin/src/base/URecord.pas | 1 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioConverter.pas | 125 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioDecoderPlugin.pas | 8 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioDecoder_Bass.pas | 8 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioInput_Bass.pas | 10 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioInput_Portaudio.pas | 8 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioPlaybackBase.pas | 1 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioPlayback_Bass.pas | 7 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioPlayback_SDL.pas | 8 | ||||
-rw-r--r-- | mediaplugin/src/media/UAudioPlayback_SoftMixer.pas | 29 | ||||
-rw-r--r-- | mediaplugin/src/media/UMediaPlugin.pas | 3 | ||||
-rw-r--r-- | mediaplugin/src/media/UMedia_dummy.pas | 12 | ||||
-rw-r--r-- | mediaplugin/src/media/UVideo.pas | 9 | ||||
-rw-r--r-- | mediaplugin/src/media/UVideoDecoderPlugin.pas | 10 | ||||
-rw-r--r-- | mediaplugin/src/media/UVisualizer.pas | 6 |
16 files changed, 309 insertions, 149 deletions
diff --git a/mediaplugin/src/base/UMusic.pas b/mediaplugin/src/base/UMusic.pas index 182fef4c..e93a1037 100644 --- a/mediaplugin/src/base/UMusic.pas +++ b/mediaplugin/src/base/UMusic.pas @@ -331,36 +331,31 @@ type procedure SetLoop(Enabled: boolean); override; end; - TVideoDecodeStream = class + TAudioConvertStream = class + protected + fSrcFormatInfo: TAudioFormatInfo; + fDstFormatInfo: TAudioFormatInfo; public - function Open(const FileName: IPath): boolean; virtual; abstract; - procedure Close; virtual; abstract; - - procedure SetLoop(Enable: boolean); virtual; abstract; - function GetLoop(): boolean; virtual; abstract; - - procedure SetPosition(Time: real); virtual; abstract; - function GetPosition: real; virtual; abstract; - - function GetFrameAspect(): real; virtual; abstract; - function GetFrame(Time: Extended): PByteArray; virtual; abstract; + constructor Create(SrcFormatInfo: TAudioFormatInfo; + DstFormatInfo: TAudioFormatInfo); + destructor Destroy(); override; - function GetFrameWidth(): integer; virtual; abstract; - function GetFrameHeight(): integer; virtual; abstract; - end; + (** + * 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. + *) + function Convert(InputBuffer: PByteArray; OutputBuffer: PByteArray; var InputSize: integer): integer; virtual; abstract; -type - // soundcard output-devices information - TAudioOutputDevice = class - public - Name: UTF8String; // soundcard name - end; - TAudioOutputDeviceList = array of TAudioOutputDevice; + (** + * Destination/Source size ratio + *) + function GetRatio(): double; virtual; abstract; -type - IGenericPlayback = Interface - ['{63A5EBC3-3F4D-4F23-8DFB-B5165FCE33DD}'] - function GetName: String; + function GetOutputBufferSize(InputSize: integer): integer; virtual; abstract; + property SrcFormatInfo: TAudioFormatInfo read fSrcFormatInfo; + property DstFormatInfo: TAudioFormatInfo read fDstFormatInfo; end; IVideo = interface @@ -377,40 +372,40 @@ type procedure SetScreen(Screen: integer); function GetScreen(): integer; - + procedure SetScreenPosition(X, Y: double; Z: double = 0.0); procedure GetScreenPosition(var X, Y, Z: double); - procedure SetWidth(Width: double); - function GetWidth(): double; - - procedure SetHeight(Height: double); - function GetHeight(): double; - + procedure SetWidth(Width: double); + function GetWidth(): double; + + procedure SetHeight(Height: double); + function GetHeight(): double; + {** * Sub-image of the video frame to draw. * This can be used for zooming or similar purposes. *} procedure SetFrameRange(Range: TRectCoords); function GetFrameRange(): TRectCoords; - + function GetFrameAspect(): real; - + procedure SetAspectCorrection(AspectCorrection: TAspectCorrection); function GetAspectCorrection(): TAspectCorrection; - + procedure SetAlpha(Alpha: double); function GetAlpha(): double; - + procedure SetReflectionSpacing(Spacing: double); function GetReflectionSpacing(): double; procedure GetFrame(Time: Extended); procedure Draw(); procedure DrawReflection(); - - + + property Screen: integer read GetScreen; property Width: double read GetWidth write SetWidth; property Height: double read GetHeight write SetHeight; @@ -422,7 +417,44 @@ type property Position: real read GetPosition write SetPosition; end; - IVideoPlayback = Interface( IGenericPlayback ) + TVideoDecodeStream = class + public + function Open(const FileName: IPath): boolean; virtual; abstract; + procedure Close; virtual; abstract; + + procedure SetLoop(Enable: boolean); virtual; abstract; + function GetLoop(): boolean; virtual; abstract; + + procedure SetPosition(Time: real); virtual; abstract; + function GetPosition: real; virtual; abstract; + + function GetFrameAspect(): real; virtual; abstract; + function GetFrame(Time: Extended): PByteArray; virtual; abstract; + + function GetFrameWidth(): integer; virtual; abstract; + function GetFrameHeight(): integer; virtual; abstract; + end; + +type + // soundcard output-devices information + TAudioOutputDevice = class + public + Name: UTF8String; // soundcard name + end; + TAudioOutputDeviceList = array of TAudioOutputDevice; + +type + IMediaInterface = interface + ['{9C31F7EF-76DB-4EEC-949F-009A26D553A2}'] + function GetName: String; + function GetPriority(): integer; + end; + + IGenericPlayback = interface(IMediaInterface) + ['{63A5EBC3-3F4D-4F23-8DFB-B5165FCE33DD}'] + end; + + IVideoPlayback = interface(IGenericPlayback) ['{3574C40C-28AE-4201-B3D1-3D1F0759B131}'] function Init(): boolean; function Finalize: boolean; @@ -430,15 +462,15 @@ type function Open(const FileName: IPath): IVideo; end; - IVideoVisualization = Interface( IVideoPlayback ) + IVideoVisualization = interface(IVideoPlayback) ['{5AC17D60-B34D-478D-B632-EB00D4078017}'] end; - IAudioPlayback = Interface( IGenericPlayback ) + IAudioPlayback = interface(IGenericPlayback) ['{E4AE0B40-3C21-4DC5-847C-20A87E0DFB96}'] function InitializePlayback: boolean; function FinalizePlayback: boolean; - + function GetOutputDeviceList(): TAudioOutputDeviceList; procedure SetAppVolume(Volume: single); @@ -484,27 +516,25 @@ type function CreateVoiceStream(ChannelMap: integer; FormatInfo: TAudioFormatInfo): TAudioVoiceStream; end; - IGenericDecoder = Interface + IGenericDecoder = interface(IMediaInterface) ['{557B0E9A-604D-47E4-B826-13769F3E10B7}'] - function GetName(): string; function InitializeDecoder(): boolean; function FinalizeDecoder(): boolean; //function IsSupported(const Filename: string): boolean; end; - IVideoDecoder = Interface( IGenericDecoder ) + IVideoDecoder = interface(IGenericDecoder) ['{2F184B2B-FE69-44D5-9031-0A2462391DCA}'] function Open(const FileName: IPath): TVideoDecodeStream; end; - IAudioDecoder = Interface( IGenericDecoder ) + IAudioDecoder = interface(IGenericDecoder) ['{AB47B1B6-2AA9-4410-BF8C-EC79561B5478}'] function Open(const Filename: IPath): TAudioDecodeStream; end; - IAudioInput = Interface + IAudioInput = interface(IMediaInterface) ['{A5C8DA92-2A0C-4AB2-849B-2F7448C6003A}'] - function GetName: String; function InitializeRecord: boolean; function FinalizeRecord(): boolean; @@ -512,31 +542,13 @@ type procedure CaptureStop; end; -type - TAudioConverter = class - protected - fSrcFormatInfo: TAudioFormatInfo; - fDstFormatInfo: TAudioFormatInfo; - public - function Init(SrcFormatInfo: TAudioFormatInfo; DstFormatInfo: TAudioFormatInfo): boolean; virtual; - destructor Destroy(); override; - - (** - * 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. - *) - function Convert(InputBuffer: PByteArray; OutputBuffer: PByteArray; var InputSize: integer): integer; virtual; abstract; - - (** - * Destination/Source size ratio - *) - function GetRatio(): double; virtual; abstract; + IAudioConverter = interface(IMediaInterface) + ['{01FB458C-D631-4CA2-9E39-BF1B0ACB1AD7}'] + function Init(): boolean; + function Finalize(): boolean; - function GetOutputBufferSize(InputSize: integer): integer; virtual; abstract; - property SrcFormatInfo: TAudioFormatInfo read fSrcFormatInfo; - property DstFormatInfo: TAudioFormatInfo read fDstFormatInfo; + function Open(SrcFormatInfo: TAudioFormatInfo; + DstFormatInfo: TAudioFormatInfo): TAudioConvertStream; end; (* TODO @@ -607,12 +619,13 @@ procedure InitializeSound; procedure InitializeVideo; procedure FinalizeMedia; -function Visualization(): IVideoPlayback; -function VideoPlayback(): IVideoPlayback; -function VideoDecoder(): IVideoDecoder; -function AudioPlayback(): IAudioPlayback; -function AudioInput(): IAudioInput; -function AudioDecoders(): TInterfaceList; +function Visualization(): IVideoPlayback; +function VideoPlayback(): IVideoPlayback; +function VideoDecoder(): IVideoDecoder; +function AudioPlayback(): IAudioPlayback; +function AudioInput(): IAudioInput; +function AudioDecoders(): TInterfaceList; +function AudioConverter(): IAudioConverter; function MediaManager: TInterfaceList; @@ -635,6 +648,7 @@ var DefaultVisualization : IVideoPlayback; DefaultAudioPlayback : IAudioPlayback; DefaultAudioInput : IAudioInput; + DefaultAudioConverter: IAudioConverter; AudioDecoderList : TInterfaceList; MediaInterfaceList : TInterfaceList; @@ -719,6 +733,11 @@ begin Result := AudioDecoderList; end; +function AudioConverter(): IAudioConverter; +begin + Result := DefaultAudioConverter; +end; + procedure FilterInterfaceList(const IID: TGUID; InList, OutList: TInterfaceList); var i: integer; @@ -745,6 +764,7 @@ var InterfaceList: TInterfaceList; CurrentAudioDecoder: IAudioDecoder; CurrentAudioPlayback: IAudioPlayback; + CurrentAudioConverter: IAudioConverter; CurrentAudioInput: IAudioInput; begin // create a temporary list for interface enumeration @@ -781,6 +801,21 @@ begin MediaManager.Remove(CurrentAudioPlayback); end; + // find and initialize converter interface + DefaultAudioConverter := nil; + FilterInterfaceList(IAudioConverter, MediaManager, InterfaceList); + for i := 0 to InterfaceList.Count-1 do + begin + CurrentAudioConverter := InterfaceList[i] as IAudioConverter; + if (CurrentAudioConverter.Init()) then + begin + DefaultAudioConverter := CurrentAudioConverter; + break; + end; + Log.LogError('Initialize failed, Removing - '+ CurrentAudioConverter.GetName); + MediaManager.Remove(CurrentAudioConverter); + end; + // find and initialize input interface DefaultAudioInput := nil; FilterInterfaceList(IAudioInput, MediaManager, InterfaceList); @@ -879,7 +914,9 @@ begin FreeAndNil(AudioDecoderList); DefaultAudioPlayback := nil; DefaultAudioInput := nil; + DefaultAudioConverter := nil; DefaultVideoPlayback := nil; + DefaultVideoDecoder := nil; DefaultVisualization := nil; // create temporary interface list @@ -900,17 +937,22 @@ begin for i := 0 to InterfaceList.Count-1 do (InterfaceList[i] as IAudioDecoder).FinalizeDecoder(); + // finalize audio converter interfaces + FilterInterfaceList(IAudioConverter, MediaManager, InterfaceList); + for i := 0 to InterfaceList.Count-1 do + (InterfaceList[i] as IAudioConverter).Finalize(); + // finalize video interfaces FilterInterfaceList(IVideoPlayback, MediaManager, InterfaceList); for i := 0 to InterfaceList.Count-1 do (InterfaceList[i] as IVideoPlayback).Finalize(); - // finalize video interfaces + // finalize video decoder interfaces FilterInterfaceList(IVideoDecoder, MediaManager, InterfaceList); for i := 0 to InterfaceList.Count-1 do (InterfaceList[i] as IVideoDecoder).FinalizeDecoder(); - // finalize audio decoder interfaces + // finalize visualization interfaces FilterInterfaceList(IVideoVisualization, MediaManager, InterfaceList); for i := 0 to InterfaceList.Count-1 do (InterfaceList[i] as IVideoVisualization).Finalize(); @@ -945,6 +987,7 @@ begin writeln( '--------------------------------------------------------------' ); writeln( 'Registered Audio Playback Interface : ' + AudioPlayback.GetName ); writeln( 'Registered Audio Input Interface : ' + AudioInput.GetName ); + writeln( 'Registered Audio Converter Interface: ' + AudioConverter.GetName ); writeln( 'Registered Video Playback Interface : ' + VideoPlayback.GetName ); writeln( 'Registered Video Decoder Interface : ' + VideoDecoder.GetName ); writeln( 'Registered Visualization Interface : ' + Visualization.GetName ); @@ -1049,16 +1092,16 @@ begin end; end; -{ TAudioConverter } +{ TAudioConvertStream } -function TAudioConverter.Init(SrcFormatInfo: TAudioFormatInfo; DstFormatInfo: TAudioFormatInfo): boolean; +constructor TAudioConvertStream.Create( + SrcFormatInfo: TAudioFormatInfo; DstFormatInfo: TAudioFormatInfo); begin fSrcFormatInfo := SrcFormatInfo.Copy(); fDstFormatInfo := DstFormatInfo.Copy(); - Result := true; end; -destructor TAudioConverter.Destroy(); +destructor TAudioConvertStream.Destroy(); begin FreeAndNil(fSrcFormatInfo); FreeAndNil(fDstFormatInfo); diff --git a/mediaplugin/src/base/URecord.pas b/mediaplugin/src/base/URecord.pas index 5cddcc77..de567aba 100644 --- a/mediaplugin/src/base/URecord.pas +++ b/mediaplugin/src/base/URecord.pas @@ -176,6 +176,7 @@ type function UnifyDeviceName(const name: UTF8String; deviceIndex: integer): UTF8String; public function GetName: String; virtual; abstract; + function GetPriority: integer; virtual; abstract; function InitializeRecord: boolean; virtual; abstract; function FinalizeRecord: boolean; virtual; 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; |