|
Line 0
a/LayoutTests/webrtc/captureStream-color-space.html_sec1
|
|
|
1 |
<!DOCTYPE html> |
| 2 |
<title>Test that colors in a canvas.captureStream() video track are preserved when sent over a peer connection</title> |
| 3 |
<script src="../resources/testharness.js"></script> |
| 4 |
<script src="../resources/testharnessreport.js"></script> |
| 5 |
<canvas id="src" width="16" height="16"></canvas> |
| 6 |
<video id="vid" width="16" height="16" autoplay></video> |
| 7 |
<canvas id="dst" width="16" height="16"></canvas> |
| 8 |
<script> |
| 9 |
function drawSourceThenCheckDestination() { |
| 10 |
const srcContext = src.getContext("2d"); |
| 11 |
srcContext.fillStyle = "#800000"; |
| 12 |
srcContext.fillRect(0, 0, 16, 16); |
| 13 |
|
| 14 |
const dstContext = dst.getContext("2d"); |
| 15 |
dstContext.clearRect(0, 0, 16, 16); |
| 16 |
dstContext.drawImage(vid, 0, 0); |
| 17 |
|
| 18 |
// The stream takes a few frames to get started. Wait until the drawImage() call paints something. |
| 19 |
const imageData = dstContext.getImageData(0, 0, 1, 1); |
| 20 |
if (!imageData.data[3]) { |
| 21 |
requestAnimationFrame(t.step_func(drawSourceThenCheckDestination)); |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
const actual = [...imageData.data]; |
| 26 |
const expected = [128, 0, 0, 255]; |
| 27 |
assert_array_approx_equals(actual, expected, 2, `actual = ${actual}, expected = ${expected}`); |
| 28 |
t.done(); |
| 29 |
} |
| 30 |
|
| 31 |
var t = async_test(async function(t) { |
| 32 |
requestAnimationFrame(t.step_func(drawSourceThenCheckDestination)); |
| 33 |
|
| 34 |
const connectionA = new RTCPeerConnection(); |
| 35 |
const connectionB = new RTCPeerConnection(); |
| 36 |
|
| 37 |
connectionA.onicecandidate = e => connectionB.addIceCandidate(e.candidate); |
| 38 |
connectionB.onicecandidate = e => connectionA.addIceCandidate(e.candidate); |
| 39 |
|
| 40 |
connectionA.addTrack(src.captureStream().getVideoTracks()[0]); |
| 41 |
connectionB.ontrack = e => vid.srcObject = new MediaStream([e.track]); |
| 42 |
|
| 43 |
const descriptionA = await connectionA.createOffer(); |
| 44 |
connectionA.setLocalDescription(descriptionA); |
| 45 |
await connectionB.setRemoteDescription(descriptionA); |
| 46 |
|
| 47 |
const descriptionB = await connectionB.createAnswer(); |
| 48 |
connectionB.setLocalDescription(descriptionB); |
| 49 |
connectionA.setRemoteDescription(descriptionB); |
| 50 |
}); |
| 51 |
</script> |