From 0e0ed5823706ef195fb269c64101ac8ae783b6ea Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Mon, 11 May 2020 05:45:26 -0700 Subject: [PATCH] Add a test to check the video detector helper function. This also checks that the video luma settles to a reasonable value for a large range of values, so could be considered a codec test. WPT bug: https://github.com/web-platform-tests/wpt/issues/23340 Bug: none Change-Id: I6ce0537b90903d823945e2fe3c5389fa4c132608 --- webrtc/RTCPeerConnection-helper.js | 9 +- .../RTCPeerConnection-videoDetectorTest.html | 84 +++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 webrtc/RTCPeerConnection-videoDetectorTest.html diff --git a/webrtc/RTCPeerConnection-helper.js b/webrtc/RTCPeerConnection-helper.js index 25d126f9a9baddd..29145c8b927dd0d 100644 --- a/webrtc/RTCPeerConnection-helper.js +++ b/webrtc/RTCPeerConnection-helper.js @@ -594,7 +594,8 @@ const trackFactories = { ctx.fillStyle = `rgb(${count%255}, ${count*count%255}, ${count%255})`; count += 1; ctx.fillRect(0, 0, width, height); - // If signal is set, add a constant-color box to the video frame. + // If signal is set, add a constant-color box to the video frame + // at coordinates 10 to 30 in both X and Y direction. if (signal !== null) { ctx.fillStyle = `rgb(${signal}, ${signal}, ${signal})`; ctx.fillRect(10, 10, 20, 20); @@ -623,7 +624,9 @@ function getVideoSignal(v) { context.drawImage(v, 0, 0, v.videoWidth, v.videoHeight); // Extract pixel value at position 20, 20 let pixel = context.getImageData(20, 20, 1, 1); - return (pixel.data[0] + pixel.data[1] + pixel.data[2]) / 3; + // Use luma reconstruction to get back original value according to + // ITU-R rec BT.709 + return (pixel.data[0] * 0.21 + pixel.data[1] * 0.72 + pixel.data[2] * 0.07); } function detectSignal(t, v, value) { @@ -633,6 +636,8 @@ function detectSignal(t, v, value) { if (signal !== null && signal < value + 1 && signal > value - 1) { resolve(); } else { + // We would like to wait for each new frame instead here, + // but there seems to be no such callback. t.step_timeout(check, 100); } } diff --git a/webrtc/RTCPeerConnection-videoDetectorTest.html b/webrtc/RTCPeerConnection-videoDetectorTest.html new file mode 100644 index 000000000000000..c9d0f24b12b3354 --- /dev/null +++ b/webrtc/RTCPeerConnection-videoDetectorTest.html @@ -0,0 +1,84 @@ + + + +RTCPeerConnection Video detector test + + + +