diff --git a/src/Player.js b/src/Player.js index 1ea54f6..3199862 100644 --- a/src/Player.js +++ b/src/Player.js @@ -60,6 +60,7 @@ class Player extends BaseClass { autoPlay = true duration = 0 tsNumber = 0 + useWebGl = false /** * @property {string} sourceURL - The url of the video to play * @property {string} source - The url of the video to play @@ -85,6 +86,7 @@ class Player extends BaseClass { * @property {AlertError} alertError - The alert info when error happens * @property {Worker} httpWorker - set User's web worker * @property {Function} afterLoadPlaylist - To handle operations after playlist is loaded + * @property {Boolean} useWebGl - If use yuv-canvas webGl to drawFrame */ constructor (el, options = {}) { super() @@ -106,6 +108,7 @@ class Player extends BaseClass { this.startTime = options.startTime === undefined ? this.startTime : options.startTime this.originStartTime = this.startTime this.playbackRate = options.playbackRate === undefined ? this.playbackRate : options.playbackRate + this.useWebGl = options.useWebGl === undefined ? this.useWebGl : options.useWebGl } setAlertError () { this.options.alertError = this.alertError = AlertError.getInstance({ diff --git a/src/imageplayer/Screen.js b/src/imageplayer/Screen.js index bd9eb02..55dcbaf 100644 --- a/src/imageplayer/Screen.js +++ b/src/imageplayer/Screen.js @@ -20,7 +20,8 @@ export default class Screen extends BaseClass { } setRender(canvas) { - this.render = yuvCanvas.attach(canvas || this.canvas) + const realCanvas = canvas || this.canvas + this.render = yuvCanvas.attach(realCanvas, { webGL: realCanvas.useWebGl }) } clear() { @@ -28,12 +29,12 @@ export default class Screen extends BaseClass { } drawFrame(data) { let st = Date.now() - let { buf_y, buf_u, buf_v, width, height, stride_y, stride_u, stride_v} = data + let { buf_y, buf_u, buf_v, width, height, stride_y, stride_u, stride_v } = data let y, u, v, format, frameDisplay let width_y = width let height_y = height let width_u = width_y / 2 - let height_u = height_y /2 + let height_u = height_y / 2 y = { bytes: buf_y, stride: stride_y diff --git a/src/utils/PlayerUtil.js b/src/utils/PlayerUtil.js index 15efe05..1b7033c 100644 --- a/src/utils/PlayerUtil.js +++ b/src/utils/PlayerUtil.js @@ -49,6 +49,7 @@ export default class PlayerUtil { $ele.classList.add(cssName.screenCanvas) $ele.width = player.options.screenWidth || player.screenWidth $ele.height = player.options.screenHeight || player.screenHeight + $ele.useWebGl = player.options.useWebGl || player.useWebGl return $ele }