()
| 72 | } |
| 73 | |
| 74 | parse() { |
| 75 | const startIndex = this._index; |
| 76 | let isKey = false; |
| 77 | |
| 78 | while (this._index < this._data.length) { |
| 79 | const startSequenceLen = this._getStartSequenceLen(this._index); |
| 80 | if (startSequenceLen == 0) { |
| 81 | throw new Error('Invalid start sequence in bit stream'); |
| 82 | } |
| 83 | |
| 84 | const { slice, key } = this._parseNalUnit(this._index + startSequenceLen); |
| 85 | |
| 86 | let nextIndex = this._indexOfNextNalUnit(this._index + startSequenceLen); |
| 87 | if (nextIndex == -1) { |
| 88 | this._index = this._data.length; |
| 89 | } else { |
| 90 | this._index = nextIndex; |
| 91 | } |
| 92 | |
| 93 | if (key) { |
| 94 | isKey = true; |
| 95 | } |
| 96 | if (slice) { |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if (startIndex === this._index) { |
| 102 | return null; |
| 103 | } |
| 104 | |
| 105 | return { |
| 106 | frame: this._data.subarray(startIndex, this._index), |
| 107 | key: isKey, |
| 108 | }; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | export class H264Context { |
no test coverage detected