首先从类BVideoStreamBinding看起,help文档里描述“Instances of this class serve as the glue between a BVideoPlayer widget and a driver's BIVideoCamera component.”
从started一路往下看到initiateStream,里面有两处注意:1,resolveFresh;2, this.videoStream = this.videoPlaybackSession.establishVideoStream(this.videoSource, this.playbackParams, this.videoDecoder, this)。
resolveFresh里解析各种相关资源,包括videoPlayer, videoSource, videoPlaybackSession和videoDecoder等。
VideoPlaybackSession:
establishVideoStream里赋值IVideoDecoder,最重要的是Thread.start(),用jadx反编译看到的是一个匿名内部类,run方法反编译错误,但是可以看到这一句BIVideoSource.streamToDestination(...),BDdfVideoCamera实现了该接口。 streamToDestination ( BPlaybackParams , IVideoDestination ) 这里的IVideoDestination实际传入的就是this(VideoPlaybackSession)。
DdfVideoStreamUtil:
BIVideoSource.streamToDestination(...)里调用了DdfVideoStreamUtil的streamToDestinatio(...):获得BIDdfVideoStreamRequest(就是你在getVideoStreamRequestType里指定的类型,一般是BDdfRtspStreamRequest的子类),在新线程中调用BIDdfVideoStreamRequest.makeVideoStream(),将返回的IVideoStream传入IVideoDestination.receiveVideoStream(IVideoStream)。
VideoPlaybackSession->IVideoDecoder(继承IVideoDestination):
VideoPlaybackSession的receiveVideoStream(IVideoStream)里调用了IVideoDecoder.receiveVideoStream(IVideoStream),IVideoDecoder就是你在makeVideoDecoder里指定的类型。抽象类VideoDecoder实现了receiveVideoStream。
VideoDecoder:
这里只简单的贴出代码,都很好理解了。
后记:我是在niagara3.7下开发,在3.8上运行,结果出现“java.lang.NoSuchFieldError”。原因是类VidFrame的成员变量rawData的类型在3.7里是javax.baja.io.ByteBuffer,但在3.8里变成了javax.baja.nre.util.ByteBuffer。