资源描述:
《Player 无缝连接》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、unitRenderFilter;interfaceuses Directshow9,DSUtil,BaseClass,ActiveX,Windows,Log,Sample,PushManager,SysUtils,WMF9;type TPlayerVideoRenderFilter=class(TBCBaseRenderer )//视频 private public functionDoRenderSample(MediaSample:IMediaSample):HResult;override; functionCheckMediaType(MediaType:PAMM
2、ediaType):HResult;override; procedureOnReceiveFirstSample(MediaSample:IMediaSample);override; end; TPlayerAudioRenderFilter=class(TBCBaseRenderer) private public functionDoRenderSample(MediaSample:IMediaSample):HResult;override; functionCheckMediaType(MediaType:PAMMediaType):HResult;over
3、ride; procedureOnReceiveFirstSample(MediaSample:IMediaSample);override; end;implementation{TPlayerRenderFilter}functionTPlayerVideoRenderFilter.CheckMediaType( MediaType:PAMMediaType):HResult;beginresult:=E_FAIL; ifIsEqualGUID(MediaType.majortype,MediaType_Video)=falsethen exit; ifIsEqual
4、GUID(MediaType.subtype,CommonType.VideoCommonType.SubType)=falsethen exit; ifIsEqualGUID(MediaType.formattype,CommonType.VideoCommonType.FormatType)=FALSEthen exit;result:=S_OK;end;functionTPlayerVideoRenderFilter.DoRenderSample( MediaSample:IMediaSample):HResult;var Len:integer; Starttime
5、,EndTime:int64; Des,Src:pbyte; flags:DWord;begin Src:=nil; des:=nil; flags:=0; Len:=MediaSample.GetActualDataLength(); //视频SAMPLE大小是可变的,音频则不是,GetSize方法是获得所有大小,而此方法是获得有效数据的大小 PushSampleManager.AllocSample(Len,true); PushSampleManager.VideoSample.SetLength(Len); MediaSample.GetPointer(src); Pu
6、shSampleManager.VideoSample.GetBuffer(des); Move(Src^,Des^,Len); //MediaSample.GetMediaTime(Starttime,Endtime); MediaSample.GetTime(Starttime,Endtime); //这里才得到了真正的时间戳 ifMediaSample.IsSyncPoint=S_OKthen begin Flags:=FlagsorWM_SF_CLEANPOINT; end; ifMediaSample.IsDiscontinuity=S_OKthen begin
7、Flags:=FlagsorWM_SF_DISCONTINUITY; end; //LogFile.Write('VideoStarttime:'+inttostr(Starttime)+#9#9#9); PushMgr.WriteBuffer(Starttime,Endtime,flags,true); result:=NOERROR;end;procedureTPlayerVideoRenderFilter.OnReceiveFirstSample( MediaSample:IMedia