Chromium Code Reviews| Index: content/test/data/media/webrtc_test_utilities.js |
| diff --git a/content/test/data/media/webrtc_test_utilities.js b/content/test/data/media/webrtc_test_utilities.js |
| index ba894cd56bf09cf0f4ff920fe7eaf0ac5fda5097..26eedaf5f578cf802a2431bb8c5b96b71b56473a 100644 |
| --- a/content/test/data/media/webrtc_test_utilities.js |
| +++ b/content/test/data/media/webrtc_test_utilities.js |
| @@ -29,24 +29,51 @@ function detectVideoIn(videoElementName, callback) { |
| var height = VIDEO_TAG_HEIGHT; |
| var videoElement = $(videoElementName); |
| var canvas = $(videoElementName + '-canvas'); |
| + var old_pixels = []; |
| var waitVideo = setInterval(function() { |
| var context = canvas.getContext('2d'); |
| context.drawImage(videoElement, 0, 0, width, height); |
| - var pixels = context.getImageData(0, 0, width, height).data; |
| - |
| - if (isVideoPlaying(pixels, width, height)) { |
| + var pixels = context.getImageData(0, 0, width, height / 3).data; |
| + if (old_pixels.length == pixels.length && |
|
phoglund_chromium
2013/11/14 09:01:18
Why is this length check necessary?
perkj_chrome
2013/11/14 13:29:07
Its a prerequisite for isVideoPlaying that they ar
phoglund_chromium
2013/11/14 13:41:05
Ok. Perhaps we should bake that into isVideoPlayin
|
| + isVideoPlaying(pixels, old_pixels)) { |
| clearInterval(waitVideo); |
| callback(); |
| } |
| + old_pixels = pixels; |
| }, 100); |
| } |
| +function detectVideoStopped(videoElementName, callback) { |
|
phoglund_chromium
2013/11/14 09:01:18
You should be able to re-use the old function with
perkj_chrome
2013/11/14 13:29:07
Done.
|
| + var width = VIDEO_TAG_WIDTH; |
| + var height = VIDEO_TAG_HEIGHT; |
| + var videoElement = $(videoElementName); |
| + var canvas = $(videoElementName + '-canvas'); |
| + var old_pixels = []; |
| + var waitVideo = setInterval(function() { |
| + var context = canvas.getContext('2d'); |
| + context.drawImage(videoElement, 0, 0, width, height); |
| + var pixels = context.getImageData(0, 0 , width, height / 3).data; |
| + if (old_pixels.length == pixels.length && |
| + !isVideoPlaying(pixels, old_pixels)) { |
| + clearInterval(waitVideo); |
| + callback(); |
| + } |
| + old_pixels = pixels; |
| + }, 300); |
|
phoglund_chromium
2013/11/14 09:01:18
Don't see why this should be different from the ot
perkj_chrome
2013/11/14 13:29:07
We can increase it a bit. But it it is lower that
|
| +} |
| + |
| function waitForVideo(videoElement) { |
| document.title = 'Waiting for video...'; |
| addExpectedEvent(); |
| detectVideoIn(videoElement, function () { eventOccured(); }); |
| } |
| +function waitForVideoToStop(videoElement) { |
| + document.title = 'Waiting for video to stop...'; |
| + addExpectedEvent(); |
| + detectVideoStopped(videoElement, function () { eventOccured(); }); |
| +} |
| + |
| function waitForConnectionToStabilize(peerConnection) { |
| addExpectedEvent(); |
| var waitForStabilization = setInterval(function() { |
| @@ -68,14 +95,11 @@ function eventOccured() { |
| } |
| } |
| -// This very basic video verification algorithm will be satisfied if any |
| -// pixels are nonzero in a small sample area in the middle. It relies on the |
| -// assumption that a video element with null source just presents zeroes. |
| -function isVideoPlaying(pixels, width, height) { |
| - // Sample somewhere near the middle of the image. |
| - var middle = width * height / 2; |
| - for (var i = 0; i < 20; i++) { |
| - if (pixels[middle + i] > 0) { |
| +//This very basic video verification algorithm will be satisfied if any |
|
phoglund_chromium
2013/11/14 09:01:18
Nit: space between // and letters
perkj_chrome
2013/11/14 13:29:07
Done.
|
| +//pixels are changed. |
| +function isVideoPlaying(pixels, previouse_pixels) { |
|
phoglund_chromium
2013/11/14 09:01:18
Nit: previous_pixels
perkj_chrome
2013/11/14 13:29:07
Done.
|
| + for (var i = 0; i < pixels.length; i++) { |
| + if (pixels[i] != previouse_pixels[i]) { |
| return true; |
| } |
| } |