Skip to content

Commit

Permalink
Split RtpStream.ts into rtpStreamStatsTypes.ts and `rtpStreamStat…
Browse files Browse the repository at this point in the history
…sFbsUtils`

Rename `scalabilityModes.ts` tp `scalabilityModesTypes.ts`
  • Loading branch information
ibc committed Nov 9, 2024
1 parent a4ee487 commit 7dd9e61
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 60 deletions.
2 changes: 1 addition & 1 deletion node/src/Consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
parseRtpEncodingParameters,
parseRtpParameters,
} from './rtpParametersFbsUtils';
import { parseRtpStreamStats } from './RtpStream';
import { parseRtpStreamStats } from './rtpStreamStatsFbsUtils';
import type { AppData } from './types';
import * as fbsUtils from './fbsUtils';
import { Event, Notification } from './fbs/notification';
Expand Down
2 changes: 1 addition & 1 deletion node/src/ConsumerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
RtpEncodingParameters,
RtpParameters,
} from './rtpParametersTypes';
import type { RtpStreamSendStats } from './RtpStream';
import type { RtpStreamSendStats } from './rtpStreamStatsTypes';
import type { AppData } from './types';

export type ConsumerOptions<ConsumerAppData extends AppData = AppData> = {
Expand Down
2 changes: 1 addition & 1 deletion node/src/Producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Channel } from './Channel';
import type { TransportInternal } from './Transport';
import type { MediaKind, RtpParameters } from './rtpParametersTypes';
import { parseRtpParameters } from './rtpParametersFbsUtils';
import { parseRtpStreamRecvStats } from './RtpStream';
import { parseRtpStreamRecvStats } from './rtpStreamStatsFbsUtils';
import type { AppData } from './types';
import * as fbsUtils from './fbsUtils';
import { Event, Notification } from './fbs/notification';
Expand Down
2 changes: 1 addition & 1 deletion node/src/ProducerTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EnhancedEventEmitter } from './enhancedEvents';
import type { MediaKind, RtpParameters } from './rtpParametersTypes';
import type { RtpStreamRecvStats } from './RtpStream';
import type { RtpStreamRecvStats } from './rtpStreamStatsTypes';
import type { AppData } from './types';

export type ProducerOptions<ProducerAppData extends AppData = AppData> = {
Expand Down
2 changes: 0 additions & 2 deletions node/src/fbsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Type as FbsRtpParametersType } from './fbs/rtp-parameters';

/**
* Parse flatbuffers vector into an array of the given T.
*/
Expand Down
12 changes: 6 additions & 6 deletions node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Logger, LoggerEmitter } from './Logger';
import { EnhancedEventEmitter } from './enhancedEvents';
import type { Worker, WorkerSettings } from './WorkerTypes';
import { WorkerImpl, workerBin } from './Worker';
import * as utils from './utils';
import { supportedRtpCapabilities } from './supportedRtpCapabilities';
import type { RtpCapabilities } from './rtpParametersTypes';
import type * as types from './types';
import * as utils from './utils';

/**
* Expose all types.
Expand All @@ -18,11 +18,6 @@ export { types };
// eslint-disable-next-line @typescript-eslint/no-require-imports
export const version: string = require('../../package.json').version;

/**
* Expose parseScalabilityMode() function.
*/
export { parse as parseScalabilityMode } from './scalabilityModes';

export type Observer = EnhancedEventEmitter<ObserverEvents>;

export type ObserverEvents = {
Expand Down Expand Up @@ -146,3 +141,8 @@ export async function createWorker<
export function getSupportedRtpCapabilities(): RtpCapabilities {
return utils.clone<RtpCapabilities>(supportedRtpCapabilities);
}

/**
* Expose parseScalabilityMode() function.
*/
export { parseScalabilityMode } from './scalabilityModesUtils';
2 changes: 1 addition & 1 deletion node/src/ortc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as h264 from 'h264-profile-level-id';
import * as flatbuffers from 'flatbuffers';
import { supportedRtpCapabilities } from './supportedRtpCapabilities';
import { parse as parseScalabilityMode } from './scalabilityModes';
import { parseScalabilityMode } from './scalabilityModesUtils';
import type {
RtpCapabilities,
MediaKind,
Expand Down
45 changes: 6 additions & 39 deletions node/src/RtpStream.ts → node/src/rtpStreamStatsFbsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,12 @@
import {
RtpStreamRecvStats,
RtpStreamSendStats,
BaseRtpStreamStats,
BitrateByLayer,
} from './rtpStreamStatsTypes';
import * as FbsRtpStream from './fbs/rtp-stream';
import * as FbsRtpParameters from './fbs/rtp-parameters';

type BitrateByLayer = { [key: string]: number };

export type RtpStreamRecvStats = BaseRtpStreamStats & {
type: string;
jitter: number;
packetCount: number;
byteCount: number;
bitrate: number;
bitrateByLayer: BitrateByLayer;
};

export type RtpStreamSendStats = BaseRtpStreamStats & {
type: string;
packetCount: number;
byteCount: number;
bitrate: number;
};

type BaseRtpStreamStats = {
timestamp: number;
ssrc: number;
rtxSsrc?: number;
rid?: string;
kind: string;
mimeType: string;
packetsLost: number;
fractionLost: number;
packetsDiscarded: number;
packetsRetransmitted: number;
packetsRepaired: number;
nackCount: number;
nackPacketCount: number;
pliCount: number;
firCount: number;
score: number;
roundTripTime?: number;
rtxPacketsDiscarded?: number;
};

export function parseRtpStreamStats(
binary: FbsRtpStream.Stats
): RtpStreamRecvStats | RtpStreamSendStats {
Expand Down
38 changes: 38 additions & 0 deletions node/src/rtpStreamStatsTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export type RtpStreamRecvStats = BaseRtpStreamStats & {
type: string;
jitter: number;
packetCount: number;
byteCount: number;
bitrate: number;
bitrateByLayer: BitrateByLayer;
};

export type RtpStreamSendStats = BaseRtpStreamStats & {
type: string;
packetCount: number;
byteCount: number;
bitrate: number;
};

export type BaseRtpStreamStats = {
timestamp: number;
ssrc: number;
rtxSsrc?: number;
rid?: string;
kind: string;
mimeType: string;
packetsLost: number;
fractionLost: number;
packetsDiscarded: number;
packetsRetransmitted: number;
packetsRepaired: number;
nackCount: number;
nackPacketCount: number;
pliCount: number;
firCount: number;
score: number;
roundTripTime?: number;
rtxPacketsDiscarded?: number;
};

export type BitrateByLayer = { [key: string]: number };
5 changes: 5 additions & 0 deletions node/src/scalabilityModesTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type ScalabilityMode = {
spatialLayers: number;
temporalLayers: number;
ksvc: boolean;
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { ScalabilityMode } from './scalabilityModesTypes';

const ScalabilityModeRegex = new RegExp(
'^[LS]([1-9]\\d{0,1})T([1-9]\\d{0,1})(_KEY)?'
);

export type ScalabilityMode = {
spatialLayers: number;
temporalLayers: number;
ksvc: boolean;
};

export function parse(scalabilityMode?: string): ScalabilityMode {
export function parseScalabilityMode(
scalabilityMode?: string
): ScalabilityMode {
const match = ScalabilityModeRegex.exec(scalabilityMode ?? '');

if (match) {
Expand Down
3 changes: 2 additions & 1 deletion node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export type * from './RtpObserverTypes';
export type * from './ActiveSpeakerObserverTypes';
export type * from './AudioLevelObserverTypes';
export type * from './rtpParametersTypes';
export type * from './rtpStreamStatsTypes';
export type * from './sctpParametersTypes';
export type * from './srtpParametersTypes';
export type * from './scalabilityModes';
export type * from './scalabilityModesTypes';

// TODO: Here we are exporting real classes rather than types. This should
// be exported somehow else rather than in mediasoup.types namespace.
Expand Down

0 comments on commit 7dd9e61

Please sign in to comment.