Skip to content

Commit

Permalink
Merge pull request webrtc#1410 from dogben/nodestroy
Browse files Browse the repository at this point in the history
Migrate from VideoFrame.destroy() to VideoFrame.close()
  • Loading branch information
guidou authored Jan 21, 2021
2 parents 37d4e0a + a4005d4 commit 583fc1a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CanvasTransform { // eslint-disable-line no-unused-vars
async transform(frame, controller) {
const ctx = this.ctx_;
if (!this.canvas_ || !ctx) {
frame.destroy();
frame.close();
return;
}
const width = frame.displayWidth;
Expand All @@ -57,7 +57,7 @@ class CanvasTransform { // eslint-disable-line no-unused-vars
// non-optional.
const timestamp = /** @type {number} */ (frame.timestamp);
const inputBitmap = await frame.createImageBitmap();
frame.destroy();
frame.close();

ctx.drawImage(inputBitmap, 0, 0);
inputBitmap.close();
Expand Down
7 changes: 6 additions & 1 deletion src/content/insertable-streams/video-processing/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ if (typeof MediaStreamTrackProcessor === 'undefined' ||
'page.');
}

// In Chrome 88, VideoFrame.close() was called VideoFrame.destroy()
if (VideoFrame.prototype.close === undefined) {
VideoFrame.prototype.close = VideoFrame.prototype.destroy;
}

/* global CameraSource */ // defined in camera-source.js
/* global CanvasTransform */ // defined in canvas-transform.js
/* global PeerConnectionSink */ // defined in peer-connection-sink.js
Expand All @@ -39,7 +44,7 @@ let debug = {};
* FrameTransformFn applies a transform to a frame and queues the output frame
* (if any) using the controller. The first argument is the input frame and the
* second argument is the stream controller.
* The VideoFrame should be destroyed as soon as it is no longer needed to free
* The VideoFrame should be closed as soon as it is no longer needed to free
* resources and maintain good performance.
* @typedef {function(
* !VideoFrame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DropTransform { // eslint-disable-line no-unused-vars
if (Math.random() < 0.5) {
controller.enqueue(frame);
} else {
frame.destroy();
frame.close();
}
}
/** @override */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WebCodecTransform { // eslint-disable-line no-unused-vars
/** @override */
async transform(frame, controller) {
if (!this.encoder_) {
frame.destroy();
frame.close();
return;
}
this.controller_ = controller;
Expand All @@ -54,7 +54,7 @@ class WebCodecTransform { // eslint-disable-line no-unused-vars

handleDecodedFrame(videoFrame) {
if (!this.controller_) {
videoFrame.destroy();
videoFrame.close();
return;
}
this.controller_.enqueue(videoFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class WebGLTransform { // eslint-disable-line no-unused-vars
async transform(frame, controller) {
const gl = this.gl_;
if (!gl || !this.canvas_) {
frame.destroy();
frame.close();
return;
}
const width = frame.displayWidth;
Expand All @@ -169,7 +169,7 @@ class WebGLTransform { // eslint-disable-line no-unused-vars
// non-optional.
const timestamp = /** @type {number} */ (frame.timestamp);
const inputBitmap = await frame.createImageBitmap();
frame.destroy();
frame.close();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, this.texture_);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
Expand Down

0 comments on commit 583fc1a

Please sign in to comment.