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

Unified Diff: remoting/webapp/video_frame_recorder.js

Issue 386853002: Add a Record button to the web-app if the host supports video recording. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move code out into OptionsMenu and VideoFrameRecorder Created 6 years, 4 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: remoting/webapp/video_frame_recorder.js
diff --git a/remoting/webapp/video_frame_recorder.js b/remoting/webapp/video_frame_recorder.js
new file mode 100644
index 0000000000000000000000000000000000000000..7a9eab560120b05cfc71f65c00cb192af92a8970
--- /dev/null
+++ b/remoting/webapp/video_frame_recorder.js
@@ -0,0 +1,134 @@
+// 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.
+
+/**
+ * @fileoverview
+ * Class implement the video frame recorder extension client.
Jamie 2014/08/19 00:48:56 s/implement/implementing/
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/**
+ * @constructor
+ */
+remoting.VideoFrameRecorder = function(plugin) {
+ this.fileWriter_ = null;
+ this.isRecording_ = false;
+ this.plugin_ = plugin;
+};
+
+/**
+ *
+ */
+remoting.VideoFrameRecorder.prototype.startStopRecording = function() {
+ var data = {};
+ if (this.isRecording_) {
+ this.isRecording_ = false;
+ data = { type: 'stop' }
+
+ chrome.fileSystem.chooseEntry(
+ {type: 'saveFile', suggestedName: "videoRecording.pb"},
Jamie 2014/08/19 00:48:56 You've used padding spaces after '{' and before '}
+ this.onFileChosen_.bind(this));
+ } else {
+ this.isRecording_ = true;
+ data = { type: 'start' }
+ }
+ this.plugin_.sendClientMessage('video-recorder', JSON.stringify(data));
+}
+
+/**
+ *
+ */
+remoting.VideoFrameRecorder.prototype.onFileChosen_ = function(fileEntry) {
+ if (!fileEntry) {
+ console.log("Cancelled save of video frames.");
+ } else {
+ chrome.fileSystem.getDisplayPath(fileEntry, function(path) {
+ console.log("Saving video frames to:" + path);
+ });
+ fileEntry.createWriter(this.onFileWriter_.bind(this));
+ }
+}
+
+/**
+ *
+ */
+remoting.VideoFrameRecorder.prototype.onFileWriter_ = function(fileWriter) {
+ console.log("Obtained FileWriter for video frame write");
+ fileWriter.onwriteend = this.onWriteComplete_.bind(this);
Jamie 2014/08/19 00:48:56 Do you need an onerror handler?
+ this.fileWriter_ = fileWriter;
+ this.fetchNextFrame_();
+}
+
+/*
+ *
+ */
+remoting.VideoFrameRecorder.prototype.onWriteComplete_ = function(e) {
Jamie 2014/08/19 00:48:56 In JS, there's no need to declare parameters if yo
+ console.log("Video frame write complete");
+ this.fetchNextFrame_();
+}
+
+/*
+ *
+ */
+remoting.VideoFrameRecorder.prototype.fetchNextFrame_ = function() {
+ console.log("Request next video frame");
+ var data = { type: 'next-frame' }
+ this.plugin_.sendClientMessage('video-recorder', JSON.stringify(data));
+}
+
+/**
+ *
+ */
+remoting.VideoFrameRecorder.prototype.handleMessage =
+ function(type, data) {
+ if (type != 'video-recorder') {
+ return false;
+ }
+
+ var message = getJsonObjectFromString(data);
+
+ if (message.type == 'next-frame-reply') {
+ if (!this.fileWriter_) {
+ console.log("Received frame but have no writer");
+ return true;
+ }
+ if (!message.data) {
+ console.log("Finished receiving frames");
+ this.fileWriter_ = null;
+ return true;
+ }
+
+ console.log("Received frame");
+ var videoPacketString = atob(message.data);
+
+ console.log("Converted from Base64 - length:" + videoPacketString.length);
+ var byteArrays = [];
+
+ for (var offset = 0; offset < videoPacketString.length; offset += 512) {
+ var slice = videoPacketString.slice(offset, offset + 512);
Jamie 2014/08/19 00:48:56 Indentation.
+ var byteNumbers = new Array(slice.length);
+ for (var i = 0; i < slice.length; i++) {
+ byteNumbers[i] = slice.charCodeAt(i);
+ }
Jamie 2014/08/19 00:48:56 Can you do this more succinctly with Array.map?
+ var byteArray = new Uint8Array(byteNumbers);
+ byteArrays.push(byteArray);
+ }
+
+ console.log("Writing frame");
+ videoPacketString = null;
+ var videoPacketBlob = new Blob(byteArrays);
+ byteArrays = null;
+
+ this.fileWriter_.write(videoPacketBlob);
+
+ return true;
+ }
+
+ console.log("Unrecognized message: " + message.type);
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698