OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** | 10 /** |
11 * @param {HTMLMediaElement} videoTag <video> tag to render to. | 11 * @param {HTMLMediaElement} videoTag <video> tag to render to. |
12 * @constructor | 12 * @constructor |
13 */ | 13 */ |
14 remoting.MediaSourceRenderer = function(videoTag) { | 14 remoting.MediaSourceRenderer = function(videoTag) { |
15 /** @type {HTMLMediaElement} */ | 15 /** @type {HTMLMediaElement} */ |
16 this.video_ = videoTag; | 16 this.video_ = videoTag; |
17 | 17 |
18 /** @type {MediaSource} */ | 18 /** @type {MediaSource} */ |
19 this.mediaSource_ = null; | 19 this.mediaSource_ = null; |
20 | 20 |
21 /** @type {SourceBuffer} */ | 21 /** @type {SourceBuffer} */ |
22 this.sourceBuffer_ = null; | 22 this.sourceBuffer_ = null; |
23 | 23 |
24 /** @type {!Array.<ArrayBuffer>} Queue of pending buffers that haven't been | 24 /** @type {!Array.<ArrayBuffer>} Queue of pending buffers that haven't been |
25 * processed . */ | 25 * processed 'null' indicates that the SourceBuffer can be reset because |
Jamie
2014/06/11 21:41:43
Nit: missing period after "processed".
Also, "nul
Sergey Ulanov
2014/06/11 23:41:12
Done.
| |
26 * the following buffer is a keyframe. */ | |
26 this.buffers_ = []; | 27 this.buffers_ = []; |
27 } | 28 } |
28 | 29 |
29 /** | 30 /** |
30 * @param {string} format Format of the stream. | 31 * @param {string} format Format of the stream. |
31 */ | 32 */ |
32 remoting.MediaSourceRenderer.prototype.reset = function(format) { | 33 remoting.MediaSourceRenderer.prototype.reset = function(format) { |
33 // Create a new MediaSource instance. | 34 // Create a new MediaSource instance. |
34 this.sourceBuffer_ = null; | 35 this.sourceBuffer_ = null; |
35 this.mediaSource_ = new MediaSource(); | 36 this.mediaSource_ = new MediaSource(); |
(...skipping 25 matching lines...) Expand all Loading... | |
61 'updateend', this.processPendingData_.bind(this)); | 62 'updateend', this.processPendingData_.bind(this)); |
62 this.processPendingData_(); | 63 this.processPendingData_(); |
63 } | 64 } |
64 | 65 |
65 /** | 66 /** |
66 * @private | 67 * @private |
67 */ | 68 */ |
68 remoting.MediaSourceRenderer.prototype.processPendingData_ = function() { | 69 remoting.MediaSourceRenderer.prototype.processPendingData_ = function() { |
69 if (this.sourceBuffer_) { | 70 if (this.sourceBuffer_) { |
70 while (this.buffers_.length > 0 && !this.sourceBuffer_.updating) { | 71 while (this.buffers_.length > 0 && !this.sourceBuffer_.updating) { |
71 // TODO(sergeyu): Figure out the way to determine when a frame is rendered | 72 /** @type {ArrayBuffer} */ |
72 // and use it to report performance statistics. | 73 var buffer = this.buffers_.shift(); |
73 this.sourceBuffer_.appendBuffer( | 74 if (buffer == null) { |
74 /** @type {ArrayBuffer} */(this.buffers_.shift())); | 75 // Remove all data from the SourceBuffer. By default Chrome buffers up |
76 // 150MB of data in SourceBuffer. We never need to seek the stream, so | |
77 // it doesn't make sense to keep any of that data. | |
78 if (this.sourceBuffer_.buffered.length > 0) { | |
79 this.sourceBuffer_.remove( | |
80 this.sourceBuffer_.buffered.start(0), | |
81 this.sourceBuffer_.buffered.end( | |
82 this.sourceBuffer_.buffered.length - 1)); | |
83 } | |
84 } else { | |
85 // TODO(sergeyu): Figure out the way to determine when a frame is | |
86 // rendered and use it to report performance statistics. | |
87 this.sourceBuffer_.appendBuffer(buffer); | |
88 } | |
75 } | 89 } |
76 } | 90 } |
77 } | 91 } |
78 | 92 |
79 /** | 93 /** |
80 * @param {ArrayBuffer} data | 94 * @param {ArrayBuffer} data |
95 * @param {boolean} keyframe | |
81 */ | 96 */ |
82 remoting.MediaSourceRenderer.prototype.onIncomingData = function(data) { | 97 remoting.MediaSourceRenderer.prototype.onIncomingData = |
98 function(data, keyframe) { | |
99 if (keyframe) { | |
100 // Queue SourceBuffer reset request. | |
101 this.buffers_.push(null); | |
102 } | |
83 this.buffers_.push(data); | 103 this.buffers_.push(data); |
84 this.processPendingData_(); | 104 this.processPendingData_(); |
85 } | 105 } |
86 | 106 |
OLD | NEW |