diff --git a/lib/VideoDecoder.js b/lib/VideoDecoder.js index 1d7fad2..c0fcfd5 100644 --- a/lib/VideoDecoder.js +++ b/lib/VideoDecoder.js @@ -14,7 +14,7 @@ class VideoDecoder extends Emitter super(); //Create decoder - this.decoder = new Native.VideoDecoderFacade(); + this.decoder = new Native.VideoDecoderWorker(); //Start decoder this.decoder.Start(); @@ -32,7 +32,7 @@ class VideoDecoder extends Emitter if (this.attached) { //Detach native decoder - this.decoder.SetIncoming(null); + this.attached.RemoveMediaListener(this.decoder.toMediaFrameListener()); //remove listener this.attached.off("stopped",this.ontrackstopped); @@ -49,10 +49,8 @@ class VideoDecoder extends Emitter //Check if valid object if (track) { - //Get first encoding - const encoding = track.encodings.values().next(); - //Set it - this.decoder.SetIncoming(encoding.value.source.toRTPIncomingMediaStream()); + //Set incoming + track.AddMediaListener(this.decoder.toMediaFrameListener()); //Listen for events track.once("stopped",this.ontrackstopped); //Keep attached object diff --git a/src/VideoDecoderFacade.i b/src/VideoDecoderFacade.i index 9b65747..b083290 100644 --- a/src/VideoDecoderFacade.i +++ b/src/VideoDecoderFacade.i @@ -1,57 +1,13 @@ -%{ +%include "MediaFrame.i" -class VideoDecoderFacade : public VideoDecoderWorker -{ -public: - VideoDecoderFacade() = default; - ~VideoDecoderFacade() - { - //Remove listener from old stream - if (this->incoming) - this->incoming->RemoveListener(this); - } - - bool SetIncoming(const RTPIncomingMediaStream::shared& incoming) - { - //If they are the same - if (this->incoming==incoming) - //DO nothing - return false; - //Remove listener from old stream - if (this->incoming) - this->incoming->RemoveListener(this); - - //Store stream and receiver - this->incoming = incoming; - //Double check - if (this->incoming) - //Add us as listeners - this->incoming->AddListener(this); - - //OK - return true; - } - - int Stop() - { - SetIncoming(nullptr); - return VideoDecoderWorker::Stop(); - } - -private: - RTPIncomingMediaStream::shared incoming; -}; - - -%} - -%include "RTPIncomingMediaStream.i" - -struct VideoDecoderFacade +struct VideoDecoderWorker { int Start(); - void AddVideoOutput(VideoOutput* ouput); - void RemoveVideoOutput(VideoOutput* ouput); - bool SetIncoming(const RTPIncomingMediaStreamShared& incoming); int Stop(); }; + +SHARED_PTR_BEGIN(VideoDecoderWorker) +{ + SHARED_PTR_TO(MediaFrameListener) +} +SHARED_PTR_END(VideoDecoderWorker)