-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
120 lines (103 loc) · 4.43 KB
/
index.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>Media Stream Video Example</title>
<script type="text/javascript">
plugin = null; // Global application object.
statusText = 'NO-STATUS';
// Indicate load success.
function moduleDidLoad() {
plugin = document.getElementById('plugin');
updateStatus('SUCCESS');
}
// If the page loads before the Native Client module loads, then set the
// status message indicating that the module is still loading. Otherwise,
// do not change the status message.
function pageDidLoad() {
if (plugin == null) {
updateStatus('LOADING...');
} else {
// It's possible that the Native Client module onload event fired
// before the page's onload event. In this case, the status message
// will reflect 'SUCCESS', but won't be displayed. This call will
// display the current message.
updateStatus();
}
}
// Set the global status message. If the element with id 'statusField'
// exists, then set its HTML to the status message as well.
// opt_message The message test. If this is null or undefined, then
// attempt to set the element with id 'statusField' to the value of
// |statusText|.
function updateStatus(opt_message) {
if (opt_message) {
statusText = opt_message;
}
var statusField = document.getElementById('statusField');
if (statusField) {
statusField.innerHTML = statusText;
}
}
</script>
</head>
<body>
<h1>Pepper MediaStream Video API Example</h1><br>
This example demonstrates receiving frames from a video MediaStreamTrack and
rendering them in a plugin<br>
<div>
<video id="camera_box" width="320" height="240" autoplay="ture" style="display: inline;">
</video>
<canvas id="mycanvas" width="320" height="240" style="position:absolute:top:0px;lift:0px">
</canvas>
</div>
<img id="glasses" src="glasses.png" style="display:none"/>
<div id="listener">
<embed id="plugin"
width=0 height=0
src="facedetect.nmf"
type="application/x-nacl" />
</div>
<h2>Status <code id="statusField">NO-STATUS</code></h2>
<p id="debugOutput">debug output</p>
<script type="text/javascript">
var video = document.getElementById("camera_box");
var canvas = document.getElementById("mycanvas");
var context = canvas.getContext("2d");
var rect;
// Normalizes window.URL
window.URL = window.URL || window.webkitURL || window.msURL || window.oURL;
// Normalizes navigator.getUserMedia
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia|| navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.getUserMedia({ video: true }, successsCallback, errorCallback);
function successsCallback(stream) {
document.getElementById('camera_box').src = (window.URL && window.URL.createObjectURL) ? window.URL.createObjectURL(stream) : stream;
plugin.postMessage({track: stream.getVideoTracks()[0]});
}
function errorCallback(err) {
}
function handleMessage(message_event) {
debug = document.getElementById('debugOutput');
debug.innerHTML = message_event.data;
context.drawImage(video, 0, 0, 320, 240);
var img = document.getElementById('glasses');
rect = eval(message_event.data);
context.drawImage(img, rect[0].x+rect[0].width*0.5-50, rect[0].y+rect[0].height*0.5-35,100,70);
}
timer = setInterval(
function () {
var img = document.getElementById('glasses');
rect = eval(message_event.data);
context.drawImage(video, 0, 0, 320, 240);
context.drawImage(img, rect[0].x+rect[0].width*0.5-50, rect[0].y+rect[0].height*0.5-35,100,70);
}, 0);
var listener = document.getElementById('listener');
listener.addEventListener('load', moduleDidLoad, true);
listener.addEventListener('message', handleMessage, true);
</script>
</body>
</html>