Skip to content

Commit 10305ed

Browse files
committed
Rewview feedback
1 parent da35a6f commit 10305ed

File tree

6 files changed

+16
-100
lines changed

6 files changed

+16
-100
lines changed

samples/audio-video-player/audio_renderer.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@ export class AudioRenderer {
6060
return promise;
6161
}
6262

63-
setVolume(volume) {
64-
if (volume < 0.0 && volume > 1.0) {
65-
return;
66-
}
67-
// Smooth exponential volume ramps on change
68-
this.volume.gain.setTargetAtTime(
69-
volume,
70-
this.audioContext.currentTime,
71-
0.3
72-
);
73-
}
74-
7563
play() {
7664
// resolves when audio has effectively started: this can take some time if using
7765
// bluetooth, for example.
@@ -149,12 +137,12 @@ export class AudioRenderer {
149137
// Decode up to the buffering target or until decoder is saturated.
150138
while (usedBufferSecs < DATA_BUFFER_DECODE_TARGET_DURATION &&
151139
this.decoder.decodeQueueSize < DECODER_QUEUE_SIZE_MAX) {
152-
debugLog(`\tmoar samples. usedBufferSecs:${usedBufferSecs} < target:${DATA_BUFFER_DECODE_TARGET_DURATION}.`);
140+
debugLog(`\tMore samples. usedBufferSecs:${usedBufferSecs} < target:${DATA_BUFFER_DECODE_TARGET_DURATION}.`);
153141
let sample = await this.demuxer.readSample();
154142
this.decoder.decode(this.makeChunk(sample));
155143

156144
// NOTE: awaiting the demuxer.readSample() above will also give the
157-
// decoder output callbacka a chance to run, so we may see usedBufferSecs
145+
// decoder output callbacks a chance to run, so we may see usedBufferSecs
158146
// increase.
159147
usedBufferElements = this.ringbuffer.capacity() - this.ringbuffer.available_write();
160148
usedBufferSecs = usedBufferElements / (this.channelCount * this.sampleRate);

samples/audio-video-player/audiosink.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ registerProcessor("AudioSink", class AudioSink extends AudioWorkletProcessor {
44
let sab = options.processorOptions.sab;
55
this.consumerSide = new RingBuffer(sab, Float32Array);
66
this.mediaChannelCount = options.processorOptions.mediaChannelCount;
7-
this.deinterleaveBuffer = new Float32Array(this.mediaChannelCount * 128);
7+
// https://www.w3.org/TR/webaudio/#render-quantum-size
8+
const RENDER_QUANTUM_SIZE = 128;
9+
this.deinterleaveBuffer = new Float32Array(this.mediaChannelCount * RENDER_QUANTUM_SIZE);
810
this.s = 0;
911
}
1012

samples/audio-video-player/mp4_pull_demuxer.js

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,9 @@ export class MP4PullDemuxer {
1717
}
1818

1919
getAvcDescription(avccBox) {
20-
var i;
21-
var size = 7;
22-
for (i = 0; i < avccBox.SPS.length; i++) {
23-
// nalu length is encoded as a uint16.
24-
size+= 2 + avccBox.SPS[i].length;
25-
}
26-
for (i = 0; i < avccBox.PPS.length; i++) {
27-
// nalu length is encoded as a uint16.
28-
size+= 2 + avccBox.PPS[i].length;
29-
}
30-
31-
var writer = new Writer(size);
32-
33-
writer.writeUint8(avccBox.configurationVersion);
34-
writer.writeUint8(avccBox.AVCProfileIndication);
35-
writer.writeUint8(avccBox.profile_compatibility);
36-
writer.writeUint8(avccBox.AVCLevelIndication);
37-
writer.writeUint8(avccBox.lengthSizeMinusOne + (63<<2));
38-
39-
writer.writeUint8(avccBox.nb_SPS_nalus + (7<<5));
40-
for (i = 0; i < avccBox.SPS.length; i++) {
41-
writer.writeUint16(avccBox.SPS[i].length);
42-
writer.writeUint8Array(avccBox.SPS[i].nalu);
43-
}
44-
45-
writer.writeUint8(avccBox.nb_PPS_nalus);
46-
for (i = 0; i < avccBox.PPS.length; i++) {
47-
writer.writeUint16(avccBox.PPS[i].length);
48-
writer.writeUint8Array(avccBox.PPS[i].nalu);
49-
}
50-
51-
return writer.getData();
20+
const stream = new DataStream(undefined, 0, DataStream.BIG_ENDIAN);
21+
avccBox.write(stream);
22+
return new Uint8Array(stream.buffer, 8); // Remove the box header.
5223
}
5324

5425
async ready() {
@@ -218,37 +189,3 @@ class MP4Source {
218189
this._onSamples(samples);
219190
}
220191
}
221-
222-
class Writer {
223-
constructor(size) {
224-
this.data = new Uint8Array(size);
225-
this.idx = 0;
226-
this.size = size;
227-
}
228-
229-
getData() {
230-
if(this.idx != this.size)
231-
throw "Mismatch between size reserved and sized used"
232-
233-
return this.data.slice(0, this.idx);
234-
}
235-
236-
writeUint8(value) {
237-
this.data.set([value], this.idx);
238-
this.idx++;
239-
}
240-
241-
writeUint16(value) {
242-
// TODO: find a more elegant solution to endianess.
243-
var arr = new Uint16Array(1);
244-
arr[0] = value;
245-
var buffer = new Uint8Array(arr.buffer);
246-
this.data.set([buffer[1], buffer[0]], this.idx);
247-
this.idx +=2;
248-
}
249-
250-
writeUint8Array(value) {
251-
this.data.set(value, this.idx);
252-
this.idx += value.length;
253-
}
254-
}

samples/audio-video-player/server.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ const http = require('http'),
1616
const serverPort = parseInt(port, 10);
1717

1818
http.createServer({}, function(request, response) {
19-
20-
// This server is insecure. Only listen for conncections on localhost.
21-
if (request.headers.host != `localhost:${serverPort}`) {
22-
console.log('Rejecting request for non-localhost');
23-
response.writeHead(502, { "Content-Type": "text/plain" });
24-
response.write("502 Connection Refused\n");
25-
response.end();
26-
return;
27-
}
28-
2919
var uri = url.parse(request.url).pathname,
3020
filename = path.join(process.cwd(), uri);
3121

@@ -67,6 +57,8 @@ http.createServer({}, function(request, response) {
6757
response.end();
6858
});
6959
});
70-
}).listen(serverPort);
60+
61+
// This server is insecure. Only listen for conncections on localhost.
62+
}).listen(serverPort, 'localhost');
7163

7264
console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");

samples/audio-video-player/video_renderer.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ export class VideoRenderer {
8080
if (frameIndex > 0)
8181
debugLog('dropping %d stale frames', frameIndex);
8282

83-
84-
for (let i = 0; i < frameIndex; i++) {
85-
let staleFrame = this.frameBuffer.shift();
86-
staleFrame.close();
87-
}
83+
for (let i = 0; i < frameIndex; i++) {
84+
let staleFrame = this.frameBuffer.shift();
85+
staleFrame.close();
86+
}
8887

8988
let chosenFrame = this.frameBuffer[0];
9089
debugLog('frame time delta = %dms (%d vs %d)', minTimeDelta/1000, timestamp, chosenFrame.timestamp)

samples/audio-video-player/web_audio_controller.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,4 @@ export class WebAudioController {
8787

8888
return Math.max(this.audioContext.currentTime - totalOutputLatency, 0.0);
8989
}
90-
91-
92-
}
90+
}

0 commit comments

Comments
 (0)