Add DRM check for Chrome
This commit is contained in:
parent
b6cae36528
commit
6061a3efc5
@ -38,6 +38,9 @@ class ArDetector {
|
|||||||
this._nextTick = false;
|
this._nextTick = false;
|
||||||
|
|
||||||
this.canDoFallbackMode = false;
|
this.canDoFallbackMode = false;
|
||||||
|
|
||||||
|
this.drmNotificationShown = false;
|
||||||
|
|
||||||
this.logger.log('info', 'init', `[ArDetector::ctor] creating new ArDetector. arid: ${this.arid}`);
|
this.logger.log('info', 'init', `[ArDetector::ctor] creating new ArDetector. arid: ${this.arid}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,6 +509,25 @@ class ArDetector {
|
|||||||
id = undefined;
|
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(){
|
frameCheck(){
|
||||||
if(! this.video){
|
if(! this.video){
|
||||||
this.logger.log('error', 'debug', `%c[ArDetect::frameCheck] <@${this.arid}> Video went missing. Destroying current instance of videoData.`);
|
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 {
|
try {
|
||||||
this.blackframeContext.drawImage(this.video, 0, 0, this.blackframeCanvas.width, this.blackframeCanvas.height);
|
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;
|
this.fallbackMode = false;
|
||||||
} catch (e) {
|
} 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);
|
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
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
if (! this.canvasReadyForDrawWindow()) {
|
if (! this.canvasReadyForDrawWindow()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user