diff --git a/src/ext/lib/ar-detect/ArDetector.js b/src/ext/lib/ar-detect/ArDetector.js index 0e88eb7..715c976 100644 --- a/src/ext/lib/ar-detect/ArDetector.js +++ b/src/ext/lib/ar-detect/ArDetector.js @@ -38,6 +38,9 @@ class ArDetector { this._nextTick = false; this.canDoFallbackMode = false; + + this.drmNotificationShown = false; + this.logger.log('info', 'init', `[ArDetector::ctor] creating new ArDetector. arid: ${this.arid}`); } @@ -506,6 +509,25 @@ class ArDetector { id = undefined; } + /** + * Checks whether video we're trying to play is protected by DRM. + * + * When trying to get an image frame of a DRM-protected video in + * firefox, the method canvas.drawImage(video) will throw an exception. + * + * This doesn't happen in Chrome. As opposed to Firefox, chrome will + * simply draw a transparent black image and not tell anyone that + * anything is amiss. However, since the image is (according to my testing + * on netflix) completely transparent, this means we can determine whether + * the video is DRM-protected by looking at the alpha byte of the image. + * + * (Videos don't tend to have an alpha channel, so they're always + * completely opaque (i.e. have value of 255)) + */ + hasDRM() { + return this.blackframeContext.getImageData(0,0,1,1).data[3] === 0; + } + frameCheck(){ if(! this.video){ this.logger.log('error', 'debug', `%c[ArDetect::frameCheck] <@${this.arid}> Video went missing. Destroying current instance of videoData.`); @@ -525,12 +547,19 @@ class ArDetector { // try { this.blackframeContext.drawImage(this.video, 0, 0, this.blackframeCanvas.width, this.blackframeCanvas.height); + + // special browsers require special tests + if (this.hasDRM()) { + throw 'Video is protected by DRM. Autodetection cannot run here.'; + } this.fallbackMode = false; } catch (e) { this.logger.log('error', 'arDetect', `%c[ArDetect::frameCheck] <@${this.arid}> %c[ArDetect::frameCheck] can't draw image on canvas. ${this.canDoFallbackMode ? 'Trying canvas.drawWindow instead' : 'Doing nothing as browser doesn\'t support fallback mode.'}`, "color:#000; backgroud:#f51;", e); // nothing to see here, really, if fallback mode isn't supported by browser - if (! this.canDoFallbackMode) { + if (!this.drmNotificationShown) { + this.drmNotificationShown = true; + this.conf.player.showNotification('AARD_DRM'); return; } if (! this.canvasReadyForDrawWindow()) {