Переглянути джерело

feat(ts) migrate red/red to TS

dev0
Naman Jain 6 місяці тому
джерело
коміт
e4bad9a345
Аккаунт користувача з таким Email не знайдено
2 змінених файлів з 13 додано та 10 видалено
  1. 1
    1
      modules/red/red.spec.js
  2. 12
    9
      modules/red/red.ts

+ 1
- 1
modules/red/red.spec.js Переглянути файл

@@ -1,4 +1,4 @@
1
-import { RFC2198Encoder } from './red.js';
1
+import { RFC2198Encoder } from './red.ts';
2 2
 
3 3
 describe('RED', () => {
4 4
     let encoder;

modules/red/red.js → modules/red/red.ts Переглянути файл

@@ -4,10 +4,14 @@ const MAX_TIMESTAMP = 0x100000000;
4 4
  * An encoder for RFC 2198 redundancy using WebRTC Insertable Streams.
5 5
  */
6 6
 export class RFC2198Encoder {
7
+    targetRedundancy: number;
8
+    frameBuffer: any[];
9
+    payloadType: number | undefined;
10
+
7 11
     /**
8
-     * @param {Number} targetRedundancy the desired amount of redundancy.
12
+     * @param {number} targetRedundancy the desired amount of redundancy.
9 13
      */
10
-    constructor(targetRedundancy = 1) {
14
+    constructor(targetRedundancy: number = 1) {
11 15
         this.targetRedundancy = targetRedundancy;
12 16
         this.frameBuffer = new Array(targetRedundancy);
13 17
         this.payloadType = undefined;
@@ -16,9 +20,9 @@ export class RFC2198Encoder {
16 20
     /**
17 21
      * Set the desired level of redudancy. 4 means "four redundant frames plus current frame.
18 22
      * It is possible to reduce this to 0 to minimize the overhead to one byte.
19
-     * @param {Number} targetRedundancy the desired amount of redundancy.
23
+     * @param {number} targetRedundancy the desired amount of redundancy.
20 24
      */
21
-    setRedundancy(targetRedundancy) {
25
+    setRedundancy(targetRedundancy: number): void {
22 26
         const currentBuffer = this.frameBuffer;
23 27
 
24 28
         if (targetRedundancy > this.targetRedundancy) {
@@ -39,9 +43,9 @@ export class RFC2198Encoder {
39 43
      * Set the "inner opus payload type". This is typically our RED payload type that we tell
40 44
      * the other side as our opus payload type. Can be queried from the sender using getParameters()
41 45
      * after setting the answer.
42
-     * @param {Number} payloadType the payload type to use for opus.
46
+     * @param {number} payloadType the payload type to use for opus.
43 47
      */
44
-    setPayloadType(payloadType) {
48
+    setPayloadType(payloadType: number): void {
45 49
         this.payloadType = payloadType;
46 50
     }
47 51
 
@@ -50,7 +54,7 @@ export class RFC2198Encoder {
50 54
      * @param {RTCEncodedAudioFrame} encodedFrame - Encoded audio frame.
51 55
      * @param {TransformStreamDefaultController} controller - TransportStreamController.
52 56
      */
53
-    addRedundancy(encodedFrame, controller) {
57
+    addRedundancy(encodedFrame: RTCEncodedAudioFrame, controller: TransformStreamDefaultController): void {
54 58
         // TODO: should this ensure encodedFrame.type being not set and
55 59
         // encodedFrame.getMetadata().payloadType being the same as before?
56 60
         /*
@@ -69,7 +73,7 @@ export class RFC2198Encoder {
69 73
 
70 74
         const newFrame = data.slice(0);
71 75
 
72
-        newFrame.timestamp = encodedFrame.timestamp;
76
+        (newFrame as any).timestamp = encodedFrame.timestamp;
73 77
 
74 78
         let allFrames = this.frameBuffer.filter(x => Boolean(x)).concat(newFrame);
75 79
 
@@ -79,7 +83,6 @@ export class RFC2198Encoder {
79 83
         for (let i = allFrames.length - 2; i >= 0; i--) {
80 84
             const frame = allFrames[i];
81 85
 
82
-
83 86
             // TODO: timestamp wraparound?
84 87
             if ((allFrames[i + 1].timestamp - frame.timestamp + MAX_TIMESTAMP) % MAX_TIMESTAMP >= 16384) {
85 88
                 allFrames = allFrames.slice(i + 1);

Завантаження…
Відмінити
Зберегти