Skip to content

Commit

Permalink
Add VideoEncoder stats (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
murillo128 authored Jul 22, 2024
1 parent 682d294 commit aab7c63
Show file tree
Hide file tree
Showing 5 changed files with 1,444 additions and 212 deletions.
30 changes: 30 additions & 0 deletions lib/VideoDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@ class VideoDecoder extends Emitter
this.detach();
};
}

getStats()
{
//Get stats from
const stats = this.decoder.GetStats();

//Ensure they are not too old
if (stats.timestamp + 1000 < new Date().time)
//Nothing
return null;

//Return encoder stats
return {
timestamp : new Date(stats.timestamp),
totalDecodedFrames : stats.totalDecodedFrames,
fps : stats.fps,
decodingTime : {
max : stats.maxDecodingTime,
avg : stats.avgDecodingTime,
},
waitingFrameTime : {
max : stats.maxWaitingFrameTime,
avg : stats.avgWaitingFrameTime,
},
deinterlacingTime : {
max : stats.maxDeinterlacingTime,
avg : stats.avgDeinterlacingTime,
}
};
}

detach()
{
Expand Down
28 changes: 28 additions & 0 deletions lib/VideoEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,33 @@ class VideoEncoder extends Emitter
this.pipe.SetMaxDelay(delayms);
}

getStats()
{
//Get stats from
const stats = this.encoder.GetStats();

//Ensure they are not too old
if (stats.timestamp + 1000 < new Date().time)
//Nothing
return null;

//Return encoder stats
return {
timestamp : new Date(stats.timestamp),
totalEncodedFrames : stats.totalEncodedFrames,
fps : stats.fps,
bitrate : stats.bitrate,
encodingTime : {
max : stats.maxEncodingTime,
avg : stats.avgEncodingTime,
},
capturingTime : {
maxa : stats.maxCapturingTime,
avg : stats.avgCapturingTime,
}
};
}

createIncomingStreamTrack(trackId, frameDispatchCoordinator)
{
//Create the source
Expand Down Expand Up @@ -89,6 +116,7 @@ class VideoEncoder extends Emitter
//Not attached
this.attached = null;
}


attachTo(decoder)
{
Expand Down
19 changes: 19 additions & 0 deletions src/VideoDecoderWorker.i
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
%include "MediaFrame.i"

%{
using VideoDecoderWorkerStats = VideoDecoderWorker::Stats;
%}

struct VideoDecoderWorkerStats
{
uint64_t timestamp = 0;
uint64_t totalDecodedFrames = 0;
uint16_t fps = 0;
uint16_t maxDecodingTime = 0;
uint16_t avgDecodingTime = 0;
uint16_t maxWaitingFrameTime = 0;
uint16_t avgWaitingFrameTime = 0;
uint16_t maxDeinterlacingTime = 0;
uint16_t avgDeinterlacingTime = 0;
};

struct VideoDecoderWorker : public MediaFrameListener
{
int Start();
void AddVideoOutput(VideoOutput* ouput);
void RemoveVideoOutput(VideoOutput* ouput);
int Stop();

VideoDecoderWorkerStats GetStats();
};

SHARED_PTR_BEGIN(VideoDecoderWorker)
Expand Down
14 changes: 14 additions & 0 deletions src/VideoEncoderFacade.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
%include "VideoInput.i"

%{
using VideoEncoderStats = VideoEncoderWorker::Stats;

class VideoEncoderFacade :
public VideoEncoderWorker,
Expand Down Expand Up @@ -42,6 +43,18 @@ private:
};
%}

struct VideoEncoderStats
{
uint64_t timestamp = 0;
uint64_t totalEncodedFrames = 0;
uint16_t fps = 0;
uint32_t bitrate = 0;
uint16_t maxEncodingTime = 0;
uint16_t avgEncodingTime = 0;
uint16_t maxCapturingTime = 0;
uint16_t avgCapturingTime = 0;
};

struct VideoEncoderFacade : public RTPReceiver
{
VideoEncoderFacade();
Expand All @@ -54,5 +67,6 @@ struct VideoEncoderFacade : public RTPReceiver
int End();
int IsEncoding();

VideoEncoderStats GetStats();
TimeService& GetTimeService();
};
Loading

0 comments on commit aab7c63

Please sign in to comment.