| 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..ca319f559ad811e5237272f157bb00f760d12231
|
| --- /dev/null
|
| +++ b/remoting/webapp/video_frame_recorder.js
|
| @@ -0,0 +1,133 @@
|
| +// 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.
|
| + */
|
| +
|
| +'use strict';
|
| +
|
| +/** @suppress {duplicate} */
|
| +var remoting = remoting || {};
|
| +
|
| +/**
|
| + * @constructor
|
| + */
|
| +remoting.VideoFrameRecorder = function() {
|
| + this.fileWriter_ = null;
|
| + this.isRecording_ = false;
|
| +};
|
| +
|
| +/**
|
| + *
|
| + */
|
| +remoting.VideoFrameRecorder.prototype.startStopRecording_ = function() {
|
| + var data = {};
|
| + if (this.isRecording_) {
|
| + this.isRecording_ = false;
|
| + data = { type: 'stop' }
|
| +
|
| + chrome.fileSystem.chooseEntry(
|
| + {type: 'saveFile', suggestedName: "videoRecording.pb"},
|
| + 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);
|
| + this.fileWriter_ = fileWriter;
|
| + this.fetchNextFrame_();
|
| +}
|
| +
|
| +/*
|
| + *
|
| + */
|
| +remoting.VideoFrameRecorder.prototype.onWriteComplete_ = function(e) {
|
| + 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);
|
| + var byteNumbers = new Array(slice.length);
|
| + for (var i = 0; i < slice.length; i++) {
|
| + byteNumbers[i] = slice.charCodeAt(i);
|
| + }
|
| + 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;
|
| +}
|
|
|