1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42

content / test / data / gpu / webcodecs / terminate-worker.html [blame]

<!DOCTYPE html>
<!--
Terminate a worker while it's doing readback and video encoding
-->
<title>Frame readback in a worker</title>
<script src="webcodecs_common.js"></script>

<script type="text/javascript">
  'use strict';

  function makeWorker() {
    const worker = new Worker('terminate-worker-worker.js');
    let resolve_promise = null;
    worker.onmessage = function(e) { resolve_promise(e.data); }
    let worker_promise = new Promise((resolve) => {
      resolve_promise = resolve;
    });
    return { worker, worker_promise };
  }

  async function main(arg) {
    let source_type = arg.source_type;
    TEST.log('Starting test with arguments: ' + JSON.stringify(arg));
    let source = await createFrameSource(source_type, 320, 240);
    if (!source) {
      TEST.skip('Unsupported source: ' + source_type);
      return;
    }

    let frame = await source.getNextFrame();
    let {worker, worker_promise} = makeWorker();
    worker.postMessage(frame, [frame]);
    await worker_promise;

    worker.terminate();

    frame.close();
    source.close();
    TEST.log('Worker termination initiated');
  }
  addManualTestButton([{'source_type': 'offscreen'}]);
</script>