Skip to content

Commit

Permalink
chore: format.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Sep 18, 2023
1 parent d3987f7 commit 1badb4a
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/e2ee/worker/FrameCryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ export function needsRbspUnescaping(frameData: Uint8Array) {
}

export function ParseRbsp(stream: Uint8Array): Uint8Array {
const data_out: number[] = [];
const dataOut: number[] = [];
var length = stream.length;
for (var i = 0; i < stream.length;) {
// Be careful about over/underflow here. byte_length_ - 3 can underflow, and
Expand All @@ -601,40 +601,40 @@ export function ParseRbsp(stream: Uint8Array): Uint8Array {
// the stream including the byte at i.
if (length - i >= 3 && !stream[i] && !stream[i + 1] && stream[i + 2] == 3) {
// Two rbsp bytes.
data_out.push(stream[i++]);
data_out.push(stream[i++]);
dataOut.push(stream[i++]);
dataOut.push(stream[i++]);
// Skip the emulation byte.
i++;
} else {
// Single rbsp byte.
data_out.push(stream[i++]);
dataOut.push(stream[i++]);
}
}
return new Uint8Array(data_out);
return new Uint8Array(dataOut);
}

const kZerosInStartSequence = 2;
const kEmulationByte = 3;

export function WriteRbsp(data_in: Uint8Array): Uint8Array {
const data_out: number[] = [];
var num_consecutive_zeros = 0;
const dataOut: number[] = [];
var numConsecutiveZeros = 0;
for (var i = 0; i < data_in.length; ++i) {
var byte = data_in[i];
if (byte <= kEmulationByte &&
num_consecutive_zeros >= kZerosInStartSequence) {
numConsecutiveZeros >= kZerosInStartSequence) {
// Need to escape.
data_out.push(kEmulationByte);
num_consecutive_zeros = 0;
dataOut.push(kEmulationByte);
numConsecutiveZeros = 0;
}
data_out.push(byte);
dataOut.push(byte);
if (byte == 0) {
++num_consecutive_zeros;
++numConsecutiveZeros;
} else {
num_consecutive_zeros = 0;
numConsecutiveZeros = 0;
}
}
return new Uint8Array(data_out);
return new Uint8Array(dataOut);
}

/**
Expand Down

0 comments on commit 1badb4a

Please sign in to comment.