K
kingofhourse
Unregistered / Unconfirmed
GUEST, unregistred user!
写了一个Source Filter:
TStreamPin = class(TBCSourceStream)
因为数据大小不恒定,所以初始化的时候暂时分配为128KB:
function TStreamPin.DecideBufferSize(pAlloc: IMemAllocator;
ppropInputRequest: PAllocatorProperties): HRESULT;
var
...
begin
...
ppropInputRequest^.cBuffers := 1;
ppropInputRequest^.cbBuffer := 1024*128;
...
end;
如果数据大于128KB,那么重新设置一次内存大小:
function TStreamPin.FillBuffer(pSample: IMediaSample): HRESULT;
var
...
begin
...
Result := S_FALSE;
nDataLen := pBuffer^.dwLen;
if nDataLen > pSample.GetSize then
begin
pSample._Release;
pSample := nil;
if Deliverbegin
Flush<>S_OK then
Exit;
if DeliverEndFlush<>S_OK then
Exit;
if FAllocator.Decommit<>S_OK then
Exit;
if FAllocator.GetProperties(props)<>S_OK then
Exit;
props.cbBuffer := nDataLen +1024;
if FAllocator.SetProperties(props, actual)<>S_OK then
Exit;
if FAllocator.Commit<>S_OK then
Exit;
if GetDeliveryBuffer(pSample, nil, nil, 0)<>S_OK then
Exit;
end;
pSample.SetSyncPoint(pBuffer^.bSyncPoint);
pSample.SetActualDataLength(nDataLen);
pSample.GetPointer(pData);
ZeroMemory(pData, nDataLen);
CopyMemory(pData, pBuffer,nDataLen);
.....
end;
结果跟踪发现,如果实际数据大于Sample大小.重新设置大小成功,但是没有效果(视频画面仍然停顿),而且释放Filter的时候出错.但是,改用VC的话则一切正常,为什么会这样?如何解决?
TStreamPin = class(TBCSourceStream)
因为数据大小不恒定,所以初始化的时候暂时分配为128KB:
function TStreamPin.DecideBufferSize(pAlloc: IMemAllocator;
ppropInputRequest: PAllocatorProperties): HRESULT;
var
...
begin
...
ppropInputRequest^.cBuffers := 1;
ppropInputRequest^.cbBuffer := 1024*128;
...
end;
如果数据大于128KB,那么重新设置一次内存大小:
function TStreamPin.FillBuffer(pSample: IMediaSample): HRESULT;
var
...
begin
...
Result := S_FALSE;
nDataLen := pBuffer^.dwLen;
if nDataLen > pSample.GetSize then
begin
pSample._Release;
pSample := nil;
if Deliverbegin
Flush<>S_OK then
Exit;
if DeliverEndFlush<>S_OK then
Exit;
if FAllocator.Decommit<>S_OK then
Exit;
if FAllocator.GetProperties(props)<>S_OK then
Exit;
props.cbBuffer := nDataLen +1024;
if FAllocator.SetProperties(props, actual)<>S_OK then
Exit;
if FAllocator.Commit<>S_OK then
Exit;
if GetDeliveryBuffer(pSample, nil, nil, 0)<>S_OK then
Exit;
end;
pSample.SetSyncPoint(pBuffer^.bSyncPoint);
pSample.SetActualDataLength(nDataLen);
pSample.GetPointer(pData);
ZeroMemory(pData, nDataLen);
CopyMemory(pData, pBuffer,nDataLen);
.....
end;
结果跟踪发现,如果实际数据大于Sample大小.重新设置大小成功,但是没有效果(视频画面仍然停顿),而且释放Filter的时候出错.但是,改用VC的话则一切正常,为什么会这样?如何解决?