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

Unified Diff: ppapi/examples/video_encode/video_encode.html

Issue 937643006: Pepper: add video_encoder example (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bbudge-ppb-video-encoder-impl
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/examples/video_encode/video_encode.html
diff --git a/ppapi/examples/video_encode/video_encode.html b/ppapi/examples/video_encode/video_encode.html
new file mode 100644
index 0000000000000000000000000000000000000000..3cf18cb031d4f3c7b6ca665c552fec47a6e7804c
--- /dev/null
+++ b/ppapi/examples/video_encode/video_encode.html
@@ -0,0 +1,115 @@
+<!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>Video Encoder Example</title>
+ <style type="text/css">
+ #video {
+ position: fixed;
+ }
+ #plugin {
+ position: fixed;
+ }
+ </style>
+ <script type="text/javascript">
+ var plugin;
+ var track;
+ var video;
+
+ function success(stream) {
+ track = stream.getVideoTracks()[0];
+ video.src = URL.createObjectURL(stream);
+ video.play();
+
+ plugin.postMessage({
+ command: 'start',
+ track: track
+ });
+ }
+
+ function failure(e) {
+ console.log("Error: ", e);
+ }
+
+ function startRecord() {
+ console.log("starting record");
+ navigator.webkitGetUserMedia({audio: false, video: true}, success, failure);
+ }
+
+ function stopRecord() {
+ plugin.postMessage({
+ command: "stop"
+ });
+ var video = document.getElementById('video');
+ video.pause();
+ track.stop();
+ }
+
+ function saveBlob(blob) {
+ var blobUrl = URL.createObjectURL(blob);
+ window.location = blobUrl;
+ }
+
+ function handleMessage(msg) {
+ if (msg.data.name == 'started') {
+ console.log('recording!');
+ } else if (msg.data.name == 'data') {
+ appendData(msg.data.data);
+ } else if (msg.data.name == 'stopped') {
+ console.log('done recording! bytes: ' + dataArray.byteLength);
+ saveBlob(new Blob([dataArray], { type: "application/octet-stream" }));
+ resetData();
+ }
+ }
+
+ function resetData() {
+ window.dataArray = new ArrayBuffer(0);
+ }
+
+ function appendData(data) {
+ var tmp = new Uint8Array(dataArray.byteLength + data.byteLength);
+ tmp.set(new Uint8Array(dataArray), 0 );
+ tmp.set(new Uint8Array(data), dataArray.byteLength);
+ dataArray = tmp.buffer;
+ }
+
+ function initialize() {
+ plugin = document.getElementById('plugin');
+ plugin.addEventListener('message', handleMessage, false);
+
+ video = document.getElementById('video');
+
+ var selectEl = document.getElementById('start');
+ selectEl.addEventListener('click', function (e) {
+ resetData();
+ startRecord();
+ });
+ selectEl = document.getElementById('stop');
+ selectEl.addEventListener('click', function (e) {
+ stopRecord();
+ });
+ }
+
+ document.addEventListener('DOMContentLoaded', initialize, false);
+ </script>
+</head>
+
+<body>
+ <h1>Video Encoder API Example</h1><br>
+ This example demonstrates receiving frames from a video MediaStreamTrack and
+ encoding them in a plugin.
+ <br>
+ <input type="button" id="start" value="Start Recording"/>
+ <input type="button" id="stop" value="Stop Recording"/>
+ <br>
+ <div>
+ <embed id="plugin" type="application/x-ppapi-example-video-encode"
+ width="640" height="480"/>
+ <video id="video" width="640" height="480"/>
+ </div>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698