一个可以进行网络视频传输的Filter ( 积分: 100 )

  • 主题发起人 主题发起人 xingkong97
  • 开始时间 开始时间
X

xingkong97

Unregistered / Unconfirmed
GUEST, unregistred user!
最近作了一个Filter,功能是对接收到的Sample进行下一步的处理,例如可以进行网络视频传输、图像编辑等等,可是在调试的时候,一旦对pin进行连接就出现“Abstract Error”。请各位大哥看看,我调试了很长时间就是不行啊。

unit NetSenderPin;

interface
uses
BaseClass, DirectShow9, DSUtil, ActiveX, Windows, SysUtils,Unit_GlobalDef;
const
CLSID_NetSender: TGUID = (D1:$A7F18A36;D2:$2899;D3:$4546;D4:($8d,$88,$4d,$21,$d4,$f2,$da,$4d));
MyPinType: TRegPinTypes =
(clsMajorType: @MEDIATYPE_Video;
clsMinorType: @MEDIASUBTYPE_NULL);

MyPins : array[0..0] of TRegFilterPins =
((strName: 'Input';

bRendered: FALSE;

bOutput: FALSE;

bZero:FALSE;

bMany: FALSE;
oFilter: nil;
strConnectsToPin: nil;
nMediaTypes: 1;
lpMediaType: @MyPinType));
type
TBCNetSenderPin=Class;
//拥有一个TBCNetSenderPin的Filter
TBCFilterNetSender=class(TBCBaseFilter)
protected
mFilterLock:TBCCritSec;
mInputPin:TBCNetSenderPin;
mPosition:TBCPosPassThru;
public
constructor Create(Name:string;Unk : IUnKnown;out hr: HRESULT);
constructor CreateFromFactory(Factory: TBCClassFactory;const Controller: IUnknown);
override;
destructor destroy;
override;
function GetPinCount: integer;override;
function GetPin(n:Integer): TBCBasePin;override;
function Stop:HResult;stdcall;
function Connect(ReceivePin: IPin;const pmt: PAMMediaType): HRESULT;
stdcall;

end;


TBCNetSenderPin=class(TBCRenderedInputPin)
private
mFilter:TBCFilterNetSender;
mReceiveLock:TBCCritSec;
mIsMediaTypeSent:Boolean;
mMediaType:PAMMEDIATYPE;
public
constructor Create(Filter:TBCFilterNetSender;out hr: HRESULT);
destructor Destroy;
override;
function NonDelegatingQueryInterface(const IID: TGUID;out Obj): HResult;override;stdcall;
//do
something with this media sample
Function Receive(pSample:IMediaSample):HResult;stdcall;
Function EndOfStream:HResult;stdcall;
Function begin
Flush:HResult;stdcall;
Function EndFlush:HResult;stdcall;
Function ReceiveCanBlock:HResult;stdcall;
// Check if the pin can support this specific proposed type and format
Function CheckMediaType(const inMediaType:TBCMediaType):HRESULT;

function CheckConnect(Pin: IPin): HResult;
override;
function Connect(ReceivePin: IPin;
const pmt: PAMMediaType): HRESULT;stdcall;
function CompleteConnect(ReceivePin: IPin): HResult;
override;
function BreakConnect: HResult;override;
private


end;


implementation

constructor TBCFilterNetSender.Create(Name:string;Unk : IUnKnown;out hr: HRESULT);
begin

mFilterLock:=TBCCritSec.Create;


inherited Create(Name, Unk, mFilterLock, CLSID_NetSender);
mInputPin:=TBCNetSenderPin.Create(self,hr);
mPosition:=TBCPosPassThru.Create('Pass Through',GetOwner(),hr, mInputPin);
end;


constructor TBCFilterNetSender.CreateFromFactory(Factory: TBCClassFactory;
const Controller: IUnknown);
var
hr: HRESULT;
begin

Create(Factory.Name, Controller, hr);
end;


destructor TBCFilterNetSender.destroy;
begin

inherited;
mInputPin.Free;
if mPosition<>nil then

begin


mPosition.Free;

end;


end;





function TBCFilterNetSender.GetPin(n:integer):TBCBasePin;
begin

if n=0 then

Result:=mInputPin
else

Result:=nil;
end;


function TBCFilterNetSender.GetPinCount():integer;
begin

Result:=1;
end;


function TBCFilterNetSender.Stop:HResult;
begin


Result:=Inherited Stop;
end;


function TBCFilterNetSender.Connect(ReceivePin: IPin;const pmt: PAMMediaType): HRESULT;
begin

Result := mInputPin.Connect(ReceivePin, pmt);
end;



//-------------------------------TBCNetSenderPin-------------------------------------------




constructor TBCNetSenderPin.Create(Filter:TBCFilterNetSender;out hr: HRESULT);
begin

inherited Create('NetSenderPin', Filter,Filter.mFilterLock, hr, 'Input');
mFilter:=Filter;

mIsMediaTypeSent:=FALSE;
mReceiveLock:=TBCCritSec.Create;

end;


destructor TBCNetSenderPin.Destroy;
begin


Inherited;
end;






Function TBCNetSenderPin.Receive(pSample:IMediaSample):HResult;
var
hr:HRESULT;
pData:PBYTE;
length:longint;
bytes:integer;
begin

try
mReceiveLock.Lock;
hr:=Inherited Receive(pSample);
if SUCCEEDED(hr) then

begin

//对pSample这里做一些事情
end;


end;




Function TBCNetSenderPin.EndOfStream:HResult;
begin

mReceiveLock.Lock;
Result:=Inherited EndOfStream;
mReceiveLock.UnLock;
end;


Function TBCNetSenderPin.begin
Flush:HResult;
begin

try

mReceiveLock.Lock;
Result:=Inherited begin
Flush;
finally
mReceiveLock.UnLock;

end;

end;


Function TBCNetSenderPin.EndFlush:HResult;
begin

try

mReceiveLock.Lock;
Result:=Inherited EndFlush;
finally

mReceiveLock.UnLock;
end;

end;


function TBCNetSenderPin.NonDelegatingQueryInterface(const IID: TGUID;
out Obj): HResult;
var
hr:HRESULT;
begin

if IsEqualGUID(IID, IID_IBaseFilter) then

if GetInterface(IID_IBaseFilter, Obj) then

Result := S_OK
else

Result := E_FAIL
else

Result := Inherited NonDelegatingQueryInterface(IID, Obj);
end;



Function TBCNetSenderPin.ReceiveCanBlock:HResult;
begin

Result:=S_OK;
end;


Function TBCNetSenderPin.CheckMediaType(const inMediaType:TBCMediaType):HRESULT;
begin

if IsEqualGUID(inMediaType.MediaType.majortype,MEDIATYPE_Video) then

begin

Result:=S_OK;
exit;
end;

Result:=E_Fail;
end;


function TBCNetSenderPin.CheckConnect(Pin: IPin): HResult;
begin


Result := Inherited CheckConnect(Pin);
end;


function TBCNetSenderPin.Connect(ReceivePin: IPin;const pmt: PAMMediaType): HResult;
begin

if ReceivePin<>nil then

Result := Inherited Connect(ReceivePin, pmt);
end;



function TBCNetSenderPin.CompleteConnect(ReceivePin: IPin): HResult;
begin


Result := inherited CompleteConnect(ReceivePin)

end;


function TBCNetSenderPin.BreakConnect: HResult;
begin


Result := Inherited BreakConnect;
end;


initialization
// provide an entry in the CFactoryTemplate array
TBCClassFactory.CreateFilter(TBCFilterNetSender,
StringToOleStr('_ NetSenderFilter'),
CLSID_NetSender, CLSID_LegacyAmFilterCategory, MERIT_UNLIKELY,
1, @MyPins);
end.
 
问题已解决!!!
 
互联网上每秒传输几帧?
 
我是在局域网上,每秒30帧
 
多人接受答案了。
 
后退
顶部