首先從類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。