-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Proposal]: Add experimental.enableResolutionChecks loadVideo option
This is a Proposal to optionally move some "resolution checks" that were historically on the application-side on the RxPlayer side. Some devices aren't able to play video content with a higher resolution than e.g. what their screen size can display: some will fail on error, others will just infinitely freeze etc. Many of those devices have vendor-specific API that indicated whether a device was e.g. compatible to 4k content, 1080p content etc. Until now we told the application developers to do the Representation filtering themselves with the help of the `representationFilter` option from the `loadVideo` API. This is because of the vast numbers of devices out there, each with their own API, and because we didn't want to take the risk of having false negatives if it turned out some of those API were not always right. However, many of those devices are very popular (Lg and Samsung TVs, game consoles). Thus I'm wondering if it would be better that we provide some of those resolution checks ourselves, to lower the efforts an application have to make to rely on the RxPlayer on those common devices. For now I added an experimental `loadVideo` option: `experimental.enableResolutionChecks`, that has to be set to `true` to enable the behavior. The long term idea would be that for devices where it seems 100% accurate, we would enable the check by default. It will directly filter out resolutions that are too high, unless all resolutions are too high on the current video track in which case it will disable the check (as a security). In other cases, it follows the exact same rules than the `isCodecSupported` and `decipherable` properties of `Representation`.
- Loading branch information
1 parent
1746fe4
commit 04904c9
Showing
21 changed files
with
425 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import log from "../log"; | ||
import globalScope from "../utils/global_scope"; | ||
import isNullOrUndefined from "../utils/is_null_or_undefined"; | ||
import { isHisense, isTizen, isWebOs } from "./browser_detection"; | ||
|
||
interface IWebOsDeviceCallback { | ||
modelName: string; | ||
modelNameAscii: string; | ||
version: string; | ||
versionMajor: number; | ||
versionMinor: number; | ||
versionDot: number; | ||
sdkVersion: string; | ||
screenWidth: number; | ||
screenHeight: number; | ||
uhd?: boolean; | ||
} | ||
|
||
type IVendorGlobalScope = typeof globalScope & { | ||
/** On Hisense TVs. */ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
Hisense_Get4KSupportState?: (() => boolean) | null | undefined; | ||
/** On Tizen devices. */ | ||
webapis?: | ||
| { | ||
productinfo?: | ||
| { | ||
is8KPanelSupported?: (() => boolean) | null | undefined; | ||
isUdPanelSupported?: (() => boolean) | null | undefined; | ||
} | ||
| null | ||
| undefined; | ||
} | ||
| null | ||
| undefined; | ||
/** On LG TVs. */ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
PalmSystem?: | ||
| { | ||
deviceInfo?: string | null | undefined; | ||
} | ||
| null | ||
| undefined; | ||
/** Also on LG TVs. */ | ||
webOS?: | ||
| { | ||
deviceInfo: | ||
| ((cb: (arg: IWebOsDeviceCallback) => void) => void) | ||
| null | ||
| undefined; | ||
} | ||
| null | ||
| undefined; | ||
}; | ||
const global: IVendorGlobalScope = globalScope; | ||
|
||
export default function getMaxSupportedResolution(): { | ||
width?: number | undefined; | ||
height: number | undefined; | ||
} { | ||
try { | ||
if (isHisense) { | ||
if ( | ||
navigator.userAgent.indexOf(";FHD") >= 0 || | ||
navigator.userAgent.indexOf("/FHD") >= 0 | ||
) { | ||
return { | ||
height: 1080, | ||
width: undefined, | ||
}; | ||
} | ||
if ( | ||
navigator.userAgent.indexOf(";HD") >= 0 || | ||
navigator.userAgent.indexOf("/HD") >= 0 | ||
) { | ||
return { | ||
height: 720, | ||
width: undefined, | ||
}; | ||
} | ||
// Found in VIDAA Web developer documentation | ||
if ( | ||
"Hisense_Get4KSupportState" in global && | ||
typeof global.Hisense_Get4KSupportState === "function" | ||
) { | ||
if (global.Hisense_Get4KSupportState()) { | ||
return { | ||
height: undefined, | ||
width: undefined, | ||
}; | ||
} | ||
} | ||
} | ||
|
||
if (isTizen) { | ||
if ( | ||
!isNullOrUndefined(global.webapis) && | ||
!isNullOrUndefined(global.webapis.productinfo) | ||
) { | ||
if (typeof global.webapis.productinfo.is8KPanelSupported === "function") { | ||
return { | ||
height: undefined, | ||
width: undefined, | ||
}; | ||
} | ||
if (typeof global.webapis.productinfo.isUdPanelSupported === "function") { | ||
return { | ||
height: 3840, | ||
width: 2160, | ||
}; | ||
} | ||
} | ||
} | ||
|
||
if (isWebOs) { | ||
let deviceInfo: IWebOsDeviceCallback | null | undefined; | ||
if ( | ||
!isNullOrUndefined(global.PalmSystem) && | ||
typeof global.PalmSystem.deviceInfo === "string" | ||
) { | ||
deviceInfo = JSON.parse(global.PalmSystem.deviceInfo) as IWebOsDeviceCallback; | ||
} | ||
if ( | ||
!isNullOrUndefined(global.webOS) && | ||
typeof global.webOS.deviceInfo === "function" | ||
) { | ||
global.webOS.deviceInfo((info: IWebOsDeviceCallback) => { | ||
deviceInfo = info; | ||
}); | ||
} | ||
if (!isNullOrUndefined(deviceInfo)) { | ||
if (deviceInfo.uhd === true) { | ||
return { | ||
width: undefined, | ||
height: undefined, | ||
}; | ||
} | ||
if ( | ||
"screenWidth" in deviceInfo && | ||
typeof deviceInfo.screenWidth === "number" && | ||
deviceInfo.screenWidth <= 1920 && | ||
"screenHeight" in deviceInfo && | ||
typeof deviceInfo.screenHeight === "number" && | ||
deviceInfo.screenHeight <= 1080 | ||
) { | ||
return { | ||
width: 1920, | ||
height: 1080, | ||
}; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
log.error( | ||
"Compat: Error when trying to call vendor API", | ||
err instanceof Error ? err : new Error("Unknown Error"), | ||
); | ||
} | ||
return { | ||
height: undefined, | ||
width: undefined, | ||
}; | ||
} |
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
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
Oops, something went wrong.