Skip to content

Commit

Permalink
attach VideoDecoder to depacketizer instead of source
Browse files Browse the repository at this point in the history
  • Loading branch information
mildsunrise committed Mar 20, 2024
1 parent 8bd61c0 commit 14c3c1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 58 deletions.
10 changes: 4 additions & 6 deletions lib/VideoDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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
Expand Down
60 changes: 8 additions & 52 deletions src/VideoDecoderFacade.i
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 14c3c1a

Please sign in to comment.