-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor video frame capture logic to its own module. * Use insertable streams where supported. * Support inputFrameBufferType=videoframe. * Support outputFrameBufferContextType=bitmaprenderer. * Support outputFrameBufferContextType=bitmaprenderer only for chrome. * Work around: markdown-it/linkify-it#111 * VBLOCKS-3643 VBLOCKS-3644 * docs: introduce beta support for Video Processor V3 --------- Co-authored-by: twilio-ci <[email protected]> Co-authored-by: Luis Rivas <[email protected]>
- Loading branch information
1 parent
281ae62
commit b9d0b5d
Showing
11 changed files
with
228 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* globals MediaStreamTrackGenerator, MediaStreamTrackProcessor, TransformStream */ | ||
'use strict'; | ||
|
||
const { DEFAULT_FRAME_RATE } = require('../../util/constants'); | ||
|
||
function captureVideoFramesSetInterval(videoEl, processVideoFrame) { | ||
const [track] = videoEl.srcObject.getVideoTracks(); | ||
const { frameRate = DEFAULT_FRAME_RATE } = track.getSettings(); | ||
let sampleInterval; | ||
|
||
const readable = new ReadableStream({ | ||
start(controller) { | ||
sampleInterval = setInterval( | ||
() => controller.enqueue(), | ||
1000 / frameRate | ||
); | ||
} | ||
}); | ||
|
||
const transformer = new TransformStream({ | ||
transform() { | ||
return processVideoFrame(); | ||
} | ||
}); | ||
|
||
readable | ||
.pipeThrough(transformer) | ||
.pipeTo(new WritableStream()) | ||
.then(() => { /* noop */ }); | ||
|
||
return () => { | ||
clearInterval(sampleInterval); | ||
}; | ||
} | ||
|
||
function captureVideoFramesInsertableStreams(videoEl, processVideoFrame, videoFrameType) { | ||
const [track] = videoEl.srcObject.getVideoTracks(); | ||
const { readable } = new MediaStreamTrackProcessor({ track }); | ||
const generator = new MediaStreamTrackGenerator({ kind: 'video' }); | ||
let shouldStop = false; | ||
|
||
const transformer = new TransformStream({ | ||
transform(videoFrame, controller) { | ||
const promise = videoFrameType === 'videoframe' | ||
? processVideoFrame(videoFrame) | ||
: Promise.resolve(videoFrame.close()) | ||
.then(processVideoFrame); | ||
return promise.finally(() => { | ||
if (shouldStop) { | ||
controller.terminate(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
readable | ||
.pipeThrough(transformer) | ||
.pipeTo(generator.writable) | ||
.then(() => { /* noop */ }); | ||
|
||
return () => { | ||
shouldStop = true; | ||
}; | ||
} | ||
|
||
module.exports = typeof MediaStreamTrackGenerator === 'function' && typeof MediaStreamTrackProcessor === 'function' | ||
? captureVideoFramesInsertableStreams | ||
: captureVideoFramesSetInterval; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "twilio-video", | ||
"title": "Twilio Video", | ||
"description": "Twilio Video JavaScript Library", | ||
"version": "2.28.3-dev", | ||
"version": "2.29.1-dev", | ||
"homepage": "https://twilio.com", | ||
"author": "Mark Andrus Roberts <[email protected]>", | ||
"contributors": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
class ReadableStream { | ||
constructor({ start }) { | ||
this._transformStream = null; | ||
this._writableStream = null; | ||
setTimeout(() => start({ | ||
enqueue: arg => { | ||
if (this._transformStream) { | ||
this._transformStream.transform(arg, { | ||
enqueue: arg => { | ||
if (this._writableStream) { | ||
this._writableStream.write(arg); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
})); | ||
} | ||
|
||
pipeThrough(transformStream) { | ||
this._transformStream = transformStream; | ||
return this; | ||
} | ||
|
||
pipeTo(writableStream) { | ||
this._writableStream = writableStream; | ||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
class TransformStream { | ||
constructor({ transform }) { | ||
this.transform = transform; | ||
} | ||
} | ||
|
||
class WritableStream { | ||
constructor() { | ||
this.write = () => {}; | ||
} | ||
} | ||
|
||
function mockStreams(_global) { | ||
_global = _global || global; | ||
_global.ReadableStream = ReadableStream; | ||
_global.TransformStream = TransformStream; | ||
_global.WritableStream = WritableStream; | ||
return _global; | ||
} | ||
|
||
module.exports = mockStreams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.