Skip to content

Commit

Permalink
delay worker creation
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed May 15, 2024
1 parent 6e9ff1a commit 6fd2dc8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
21 changes: 14 additions & 7 deletions scripts/save-tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function createWorker(fn) {
return new Worker(url)
}

const saveFileWorker = createWorker(() => {
const saveFileWorkerFn = () => {
const log = (...args) => {
console.log.apply(null, ['[webrtcperf-savefileworker]', ...args])
}
Expand Down Expand Up @@ -155,17 +155,24 @@ const saveFileWorker = createWorker(() => {
readable.pipeTo(writableStream)
}
}
})
}

let saveFileWorker = null
const savingTracks = {
audio: new Set(),
video: new Set(),
}

saveFileWorker.onmessage = event => {
const { name, error, kind, id } = event.data
log(`saveFileWorker name=${name} kind=${kind} id=${id} error=${error}`)
savingTracks[kind].delete(id)
const getSaveFileWorker = () => {
if (!saveFileWorker) {
saveFileWorker = createWorker(saveFileWorkerFn)
saveFileWorker.onmessage = event => {
const { name, error, kind, id } = event.data
log(`saveFileWorker name=${name} kind=${kind} id=${id} error=${error}`)
savingTracks[kind].delete(id)
}
}
return saveFileWorker
}

window.saveMediaTrack = async (
Expand Down Expand Up @@ -198,7 +205,7 @@ window.saveMediaTrack = async (
const { readable } = new window.MediaStreamTrackProcessor({ track })

log(`saveMediaTrack ${filename}`)
saveFileWorker.postMessage(
getSaveFileWorker().postMessage(
{
id,
url,
Expand Down
7 changes: 4 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,10 @@ use the host X server instance.`,
arg: 'enable-gpu',
},
enableBrowserLogging: {
doc: `It enables the Chromium browser logging to standard output.`,
format: 'Boolean',
default: false,
doc: `It enables the Chromium browser logging, e.g. "--v=0" (see https://www.chromium.org/for-testers/enable-logging/).`,
format: String,
nullable: true,
default: '',
env: 'ENABLE_BROWSER_LOGGING',
arg: 'enable-browser-logging',
},
Expand Down
8 changes: 4 additions & 4 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export type SessionParams = {
videoHeight: number
videoFramerate: number
enableGpu: string
enableBrowserLogging: boolean
enableBrowserLogging: string
startTimestamp: number
sessions: number
tabsPerSession: number
Expand Down Expand Up @@ -187,7 +187,7 @@ export class Session extends EventEmitter {
private readonly videoHeight: number
private readonly videoFramerate: number
private readonly enableGpu: string
private readonly enableBrowserLogging: boolean
private readonly enableBrowserLogging: string
private readonly startTimestamp: number
private readonly sessions: number
private readonly tabsPerSession: number
Expand Down Expand Up @@ -585,7 +585,7 @@ export class Session extends EventEmitter {
}

if (this.enableBrowserLogging) {
args = args.concat(['--enable-logging=stderr', '--vmodule=*/webrtc/*=1'])
args = args.concat(['--enable-logging=stderr', this.enableBrowserLogging])
}

return args
Expand Down Expand Up @@ -686,7 +686,7 @@ exec sg ${group} -c /tmp/webrtcperf-launcher-${mark}-browser`,
executablePath,
handleSIGINT: false,
env,
dumpio: this.enableBrowserLogging,
dumpio: !!this.enableBrowserLogging,
// devtools: true,
ignoreHTTPSErrors: true,
defaultViewport: {
Expand Down

0 comments on commit 6fd2dc8

Please sign in to comment.