# All files / src/utils timescale-conversion.ts

50% Statements 8/16
40% Branches 4/10
50% Functions 2/4
60% Lines 6/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    191x

    4x
    2x
    2x

    2x
    2x

     const MPEG_TS_CLOCK_FREQ_HZ = 90000;

    export function toTimescaleFromScale (value, destScale: number, srcScale: number = 1, round: boolean = false): number {
      return toTimescaleFromBase(value, destScale, 1 / srcScale);
    }

    export function toTimescaleFromBase (value, destScale: number, srcBase: number = 1, round: boolean = false): number {
      const result = value * destScale * srcBase; // equivalent to `(value * scale) / (1 / base)`
      return round ? Math.round(result) : result;
    }

    export function toMsFromMpegTsClock (value: number, round: boolean = false): number {
      return toTimescaleFromBase(value, 1000, 1 / MPEG_TS_CLOCK_FREQ_HZ, round);
    }

    export function toMpegTsClockFromTimescale (value: number, srcScale: number = 1): number E{
      return toTimescaleFromBase(value, MPEG_TS_CLOCK_FREQ_HZ, 1 / srcScale);
    }