📄 baseclass.pas
字号:
(*********************************************************************
* DSPack 2.3.3 *
* DirectShow BaseClass *
* *
* home page : http://www.progdigy.com *
* email : hgourvest@progdigy.com *
* *
* date : 21-02-2003 *
* *
* The contents of this file are used with permission, subject to *
* the Mozilla Public License Version 1.1 (the "License"); you may *
* not use this file except in compliance with the License. You may *
* obtain a copy of the License at *
* http://www.mozilla.org/MPL/MPL-1.1.html *
* *
* Software distributed under the License is distributed on an *
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
* implied. See the License for the specific language governing *
* rights and limitations under the License. *
* *
* Contributor(s) *
* Andriy Nevhasymyy <a.n@email.com> *
* Milenko Mitrovic <dcoder@dsp-worx.de> *
* Michael Andersen <michael@mechdata.dk> *
* Martin Offenwanger <coder@dsplayer.de> *
* *
*********************************************************************)
{.$DEFINE DEBUG} // Debug Log
{.$DEFINE TRACE} // Trace Criteral Section (DEBUG must be ON)
{.$DEFINE MESSAGE} // Use OutputDebugString instead of a File (DEBUG must be ON)
{.$DEFINE PERF} // Show Performace Counter
{.$DEFINE VTRANSPERF} // Show additional TBCVideoTransformFilter Performace Counter (PERF must be ON)
{$MINENUMSIZE 4}
{$ALIGN ON}
unit BaseClass;
{$IFDEF VER150}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CAST OFF}
{$ENDIF}
interface
uses Windows, SysUtils, Classes, Math, ActiveX, Forms, Messages, Controls,
DirectShow9, dialogs, ComObj, mmsystem, DSUtil;
const
OATRUE = -1;
OAFALSE = 0;
DEFAULTCACHE = 10; // Default node object cache size
type
TBCCritSec = class
private
FCritSec : TRTLCriticalSection;
{$IFDEF DEBUG}
FcurrentOwner: Longword;
FlockCount : Longword;
{$ENDIF}
public
constructor Create;
destructor Destroy; override;
procedure Lock;
procedure UnLock;
function CritCheckIn: boolean;
function CritCheckOut: boolean;
end;
TBCBaseObject = class(TObJect)
private
FName: string;
public
constructor Create(Name: string);
destructor Destroy; override;
class function NewInstance: TObject; override;
procedure FreeInstance; override;
class function ObjectsActive: integer;
end;
TBCClassFactory = Class;
TBCUnknown = class(TBCBaseObject, IUnKnown)
private
FRefCount: integer;
FOwner : Pointer;
protected
function IUnknown.QueryInterface = NonDelegatingQueryInterface;
function IUnknown._AddRef = NonDelegatingAddRef;
function IUnknown._Release = NonDelegatingRelease;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
public
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
constructor Create(name: string; Unk: IUnknown);
constructor CreateFromFactory(Factory: TBCClassFactory; const Controller: IUnknown); virtual;
function NonDelegatingQueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
function NonDelegatingAddRef: Integer; virtual; stdcall;
function NonDelegatingRelease: Integer; virtual; stdcall;
function GetOwner: IUnKnown;
end;
TBCUnknownClass = Class of TBCUnknown;
TFormPropertyPage = class;
TFormPropertyPageClass = class of TFormPropertyPage;
TBCBaseFilter = class;
TBCBaseFilterClass = class of TBCBaseFilter;
TBCClassFactory = class(TObject, IUnKnown, IClassFactory)
private
FNext : TBCClassFactory;
FComClass : TBCUnknownClass;
FPropClass: TFormPropertyPageClass;
FName : String;
FClassID : TGUID;
FCategory : TGUID;
FMerit : LongWord;
FPinCount : Cardinal;
FPins : PRegFilterPins;
function RegisterFilter(FilterMapper: IFilterMapper; Register: Boolean): boolean; overload;
function RegisterFilter(FilterMapper: IFilterMapper2; Register: Boolean): boolean; overload;
procedure UpdateRegistry(Register: Boolean); overload;
protected
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
function CreateInstance(const UnkOuter: IUnknown; const IID: TGUID;
out Obj): HResult; stdcall;
function LockServer(fLock: BOOL): HResult; stdcall;
public
constructor CreateFilter(ComClass: TBCUnknownClass; Name: string;
const ClassID: TGUID; const Category: TGUID; Merit: LongWord;
PinCount: Cardinal; Pins: PRegFilterPins);
constructor CreatePropertyPage(ComClass: TFormPropertyPageClass; const ClassID: TGUID);
property Name: String read FName;
property ClassID: TGUID read FClassID;
end;
TBCFilterTemplate = class
private
FFactoryList : TBCClassFactory;
procedure AddObjectFactory(Factory: TBCClassFactory);
public
constructor Create;
destructor Destroy; override;
function RegisterServer(Register: Boolean): boolean;
function GetFactoryFromClassID(const CLSID: TGUID): TBCClassFactory;
end;
TBCMediaType = object
MediaType: PAMMediaType;
function Equal(mt: TBCMediaType): boolean; overload;
function Equal(mt: PAMMediaType): boolean; overload;
function MatchesPartial(Partial: PAMMediaType): boolean;
function IsPartiallySpecified: boolean;
function IsValid: boolean;
procedure InitMediaType;
function FormatLength: Cardinal;
end;
TBCBasePin = class;
TBCBaseFilter = class(TBCUnknown, IBaseFilter, IAMovieSetup)
protected
FState : TFilterState; // current state: running, paused
FClock : IReferenceClock; // this graph's ref clock
FStart : TReferenceTime; // offset from stream time to reference time
FCLSID : TGUID; // This filters clsid used for serialization
FLock : TBCCritSec; // Object we use for locking
FFilterName : WideString; // Full filter name
FGraph : IFilterGraph; // Graph we belong to
FSink : IMediaEventSink; // Called with notify events
FPinVersion: Integer; // Current pin version
public
constructor Create(Name: string; // Object description
Unk : IUnKnown; // IUnknown of delegating object
Lock: TBCCritSec; // Object who maintains lock
const clsid: TGUID // The clsid to be used to serialize this filter
); overload;
constructor Create(Name: string; // Object description
Unk : IUnKnown; // IUnknown of delegating object
Lock: TBCCritSec; // Object who maintains lock
const clsid: TGUID; // The clsid to be used to serialize this filter
out hr: HRESULT // General OLE return code
); overload;
constructor CreateFromFactory(Factory: TBCClassFactory; const Controller: IUnknown); override;
destructor destroy; override;
// --- IPersist method ---
function GetClassID(out classID: TCLSID): HResult; stdcall;
// --- IMediaFilter methods ---
// override Stop and Pause so we can activate the pins.
// Note that Run will call Pause first if activation needed.
// Override these if you want to activate your filter rather than
// your pins.
function Stop: HRESULT; virtual; stdcall;
function Pause: HRESULT; virtual; stdcall;
// the start parameter is the difference to be added to the
// sample's stream time to get the reference time for
// its presentation
function Run(tStart: TReferenceTime): HRESULT; virtual; stdcall;
function GetState(dwMilliSecsTimeout: DWORD; out State: TFilterState): HRESULT; virtual; stdcall;
function SetSyncSource(pClock: IReferenceClock): HRESULT; stdcall;
function GetSyncSource(out pClock: IReferenceClock): HRESULT; stdcall;
// --- helper methods ---
// return the current stream time - ie find out what
// stream time should be appearing now
function StreamTime(out rtStream: TReferenceTime): HRESULT; virtual;
// Is the filter currently active?
function IsActive: boolean;
// Is this filter stopped (without locking)
function IsStopped: boolean;
// --- IBaseFilter methods ---
// pin enumerator
function EnumPins(out ppEnum: IEnumPins): HRESULT; stdcall;
// default behaviour of FindPin assumes pin ids are their names
function FindPin(Id: PWideChar; out Pin: IPin): HRESULT; virtual; stdcall;
function QueryFilterInfo(out pInfo: TFilterInfo): HRESULT; stdcall;
// milenko start (added virtual to be able to override it in the renderers)
function JoinFilterGraph(pGraph: IFilterGraph; pName: PWideChar): HRESULT; virtual; stdcall;
// milenko end
// return a Vendor information string. Optional - may return E_NOTIMPL.
// memory returned should be freed using CoTaskMemFree
// default implementation returns E_NOTIMPL
function QueryVendorInfo(out pVendorInfo: PWideChar): HRESULT; stdcall;
// --- helper methods ---
// send an event notification to the filter graph if we know about it.
// returns S_OK if delivered, S_FALSE if the filter graph does not sink
// events, or an error otherwise.
function NotifyEvent(EventCode, EventParam1, EventParam2: LongInt): HRESULT;
// return the filter graph we belong to
function GetFilterGraph: IFilterGraph;
// Request reconnect
// pPin is the pin to reconnect
// pmt is the type to reconnect with - can be NULL
// Calls ReconnectEx on the filter graph
function ReconnectPin(Pin: IPin; pmt: PAMMediaType): HRESULT;
// find out the current pin version (used by enumerators)
function GetPinVersion: LongInt; virtual;
procedure IncrementPinVersion;
// you need to supply these to access the pins from the enumerator
// and for default Stop and Pause/Run activation.
function GetPinCount: integer; virtual; abstract;
function GetPin(n: Integer): TBCBasePin; virtual; abstract;
// --- IAMovieSetup methods ---
{nev: start 04/16/04 added "virtual"}
function Register: HRESULT; virtual; stdcall;
function Unregister: HRESULT; virtual; stdcall;
{nev: end}
property State: TFilterState read FState;
property GRaph : IFilterGraph read FGRaph;
end;
{ NOTE The implementation of this class calls the CUnknown constructor with
a NULL outer unknown pointer. This has the effect of making us a self
contained class, ie any QueryInterface, AddRef or Release calls will be
routed to the class's NonDelegatingUnknown methods. You will typically
find that the classes that do this then override one or more of these
virtual functions to provide more specialised behaviour. A good example
of this is where a class wants to keep the QueryInterface internal but
still wants its lifetime controlled by the external object }
TBCBasePin = class(TBCUnknown, IPin, IQualityControl)
protected
FPinName: WideString;
FConnected : IPin; // Pin we have connected to
Fdir : TPinDirection; // Direction of this pin
FLock : TBCCritSec; // Object we use for locking
FRunTimeError : boolean; // Run time error generated
FCanReconnectWhenActive: boolean; // OK to reconnect when active
FTryMyTypesFirst : boolean; // When connecting enumerate
// this pin's types first
FFilter : TBCBaseFilter; // Filter we were created by
FQSink : IQualityControl; // Target for Quality messages
FTypeVersion : LongInt; // Holds current type version
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -