Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: ppapi/examples/video_encode/video_encode.html

Issue 859313002: Pepper: Define PPB_VideoEncoder API + Implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright 2014 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
7 -->
8 <head>
9 <title>Video Encoder Example</title>
10 <style type="text/css">
11 #video {
12 position: fixed;
13 }
14 #plugin {
15 position: fixed;
16 }
17 </style>
18 <script type="text/javascript">
19 var plugin;
20 var stream;
21 var video;
22
23 function success(s) {
24 console.log(stream);
25 stream = s;
26 video.src = URL.createObjectURL(stream);
27 video.play();
28
29 plugin.postMessage({
30 command: 'start',
31 track: stream.getVideoTracks()[0]
32 });
33 }
34
35 function failure(e) {
36 console.log("Error: ", e);
37 }
38
39 function startRecord() {
40 console.log("starting record");
41 navigator.webkitGetUserMedia({audio: false, video: true}, success, failure );
42 }
43
44 function stopRecord() {
45 plugin.postMessage({
46 command: "stop"
47 });
48 var video = document.getElementById('video');
49 video.pause();
50 }
51
52 function saveBlob(blob) {
53 var blobUrl = URL.createObjectURL(blob);
54 window.location = blobUrl;
55 }
56
57 function handleMessage(msg) {
58 if (msg.data.name == 'started') {
59 console.log('recording!');
60 } else if (msg.data.name == 'data') {
61 appendData(msg.data.data);
62 } else if (msg.data.name == 'stopped') {
63 console.log('done recording! bytes: ' + dataArray.byteLength);
64 saveBlob(new Blob([dataArray], { type: "application/octet-stream" }));
65 resetData();
66 }
67 }
68
69 function resetData() {
70 window.dataArray = new ArrayBuffer(0);
71 }
72
73 function appendData(data) {
74 var tmp = new Uint8Array(dataArray.byteLength + data.byteLength);
75 tmp.set(new Uint8Array(dataArray), 0 );
76 tmp.set(new Uint8Array(data), dataArray.byteLength);
77 dataArray = tmp.buffer;
78 }
79
80 function initialize() {
81 plugin = document.getElementById('plugin');
82 plugin.addEventListener('message', handleMessage, false);
83
84 video = document.getElementById('video');
85
86 var selectEl = document.getElementById('start');
87 selectEl.addEventListener('click', function (e) {
88 console.log("start clicked");
89 resetData();
90 startRecord();
91 });
92 selectEl = document.getElementById('stop');
93 selectEl.addEventListener('click', function (e) {
94 console.log("stop clicked");
95 stopRecord();
96 });
97 }
98
99 document.addEventListener('DOMContentLoaded', initialize, false);
100 </script>
101 </head>
102
103 <body>
104 <h1>Video Encoder API Example</h1><br>
105 This example demonstrates receiving frames from a video MediaStreamTrack and
106 encoding them in a plugin.
107 <br>
108 <input type="button" id="start" value="Start Recording"/>
109 <input type="button" id="stop" value="Stop Recording"/>
110 <br>
111 <div>
112 <embed id="plugin" type="application/x-ppapi-example-video-encode"
113 width="640" height="480"/>
114 <video id="video" width="640" height="480"/>
115 </div>
116 </body>
117 </html>
OLDNEW
« no previous file with comments | « ppapi/examples/video_encode/video_encode.cc ('k') | ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698