Skip to content

Commit

Permalink
add types for decoder/encoder stats
Browse files Browse the repository at this point in the history
  • Loading branch information
mildsunrise committed Aug 7, 2024
1 parent eb5c545 commit 6a7832e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export * from "./build/types/VideoCodecs";

export type VideoDecoder = import("./build/types/VideoDecoder");
export type { VideoDecoderStats } from "./build/types/VideoDecoder";
export type VideoEncoder = import("./build/types/VideoEncoder");
export type { CodecParams } from "./build/types/VideoEncoder";
export type { VideoEncoderStats, CodecParams } from "./build/types/VideoEncoder";
export type VideoEncoderIncomingStreamTrack = import("./build/types/VideoEncoderIncomingStreamTrack");

export type {
Expand Down
6 changes: 6 additions & 0 deletions lib/VideoCodecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ LFSR.prototype._defaultSeed = function(/** @type {number} */ n) {

/** @typedef {import("./Properties").Properties} Properties */

/**
* @typedef {Object} TimeStats
* @property {number} max
* @property {number} avg
*/

/** @namespace */
const VideoCodecs = {};

Expand Down
15 changes: 15 additions & 0 deletions lib/VideoDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ const Native = require("./Native");
const SharedPointer = require("./SharedPointer");
const Emitter = require("medooze-event-emitter");

/** @typedef {import("./VideoCodecs").TimeStats} TimeStats */

/**
* @typedef {Object} VideoDecoderStats
* @property {Date} timestamp
* @property {number} totalDecodedFrames
* @property {number} fps
* @property {TimeStats} decodingTime
* @property {TimeStats} waitingFrameTime
* @property {TimeStats} deinterlacingTime
*/

/**
* @typedef {Object} VideoDecoderEvents
* @property {(self: VideoDecoder) => void} stopped
Expand Down Expand Up @@ -33,6 +45,9 @@ class VideoDecoder extends Emitter
};
}

/**
* @returns {VideoDecoderStats | null}
*/
getStats()
{
//Get stats from
Expand Down
15 changes: 15 additions & 0 deletions lib/VideoEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ const parseInt = /** @type {(x: number) => number} */ (global.parseInt);
//@ts-expect-error
const parseFloat = /** @type {(x: number) => number} */ (global.parseFloat);

/** @typedef {import("./VideoCodecs").TimeStats} TimeStats */

/**
* @typedef {Object} VideoEncoderStats
* @property {Date} timestamp
* @property {number} totalEncodedFrames
* @property {number} fps
* @property {number} bitrate
* @property {TimeStats} encodingTime
* @property {TimeStats} capturingTime
*/

/**
* @typedef {Object} CodecParams
* @property {number} [width] (integer)
Expand Down Expand Up @@ -84,6 +96,9 @@ class VideoEncoder extends Emitter
this.pipe.SetMaxDelay(delayms);
}

/**
* @returns {VideoEncoderStats | null}
*/
getStats()
{
//Get stats from
Expand Down

0 comments on commit 6a7832e

Please sign in to comment.