[Merge] lp:~abreu-alexandre/webbrowser-app/front-camera-as-default-capture into lp:webbrowser-app
Olivier Tilloy
olivier.tilloy at canonical.com
Mon Jun 13 15:44:47 UTC 2016
I’m probably missing something: why can’t this hack reside solely in the apps’ code? At app startup, check whether a specific default camera has been requested (via command-line flag), if not default to front, then enumerate all video capture devices, and set the default one accordingly if any matches.
See also a couple of inline comments.
Diff comments:
> === modified file 'src/Ubuntu/Web/UbuntuWebContext.qml'
> --- src/Ubuntu/Web/UbuntuWebContext.qml 2015-12-11 10:30:42 +0000
> +++ src/Ubuntu/Web/UbuntuWebContext.qml 2016-06-10 18:02:02 +0000
> @@ -99,4 +99,80 @@
> devtoolsIp: webviewDevtoolsDebugHost
>
> hostMappingRules: webviewHostMappingRules
> +
> + /**
> + * The goal of this chunk of code is to allow one to setup
> + * a default selection for the camera based on its position.
> + * As requested by:
> + * https://launchpad.net/bugs/1563398
> + *
> + * At the moment though, there is an Oxide bug that prevents
> + * camera positions to be properly reported.
> + *
> + * https://launchpad.net/bugs/1568145
> + *
> + * In order to workaround this for now, we use a hack based on the fact
> + * that in hybris backed systems, the various video capture devices' names
> + * are reported as "Front Camera" & "Back Camera", the string being translated.
On my krillin they are reported as "Front camera" and "Rear camera".
> + * We used this dirty heuristic instead of the position as a fallback for now.
> + */
> + property QtObject __internal : QtObject {
> + readonly property string cameraNamePrefixVideoCaptureDefault: (cameraPositionVideoCaptureDefault === "frontface") ? i18n.tr("Front") : ""
I don’t understand why this string is localized: on my device with the system language set to French, the name for the front camera is not translated, it’s still "Front camera".
Additionally, translations templates are not generated for QML files under src/Ubuntu.
> + readonly property string cameraPositionUnspecified: "unspecified"
> + }
> +
> + property string cameraIdVideoCaptureDefault: webcontextDefaultCameraIdVideoCapture
> + property string cameraPositionVideoCaptureDefault: webcontextDefaultVideoCaptureCameraPosition
> + Component.onCompleted: {
> + var OxideGlobals = Oxide.Oxide
> +
> + function updateDefaultVideoCaptureDevice() {
> + var devices = OxideGlobals.availableVideoCaptureDevices
> +
> + if (! oxideContext.defaultVideoCaptureDeviceId
> + && devices
> + && devices.length > 0) {
> +
> + for (var i = 0; i < devices.length; ++i) {
> + /**
> + * cameraIdVideoCaptureDefault has precedence
> + */
> +
> + if (cameraIdVideoCaptureDefault
> + && devices[i].id === cameraIdVideoCaptureDefault) {
> + oxideContext.defaultVideoCaptureDeviceId = devices[i].id
> + break
> + }
> +
> + if (cameraPositionVideoCaptureDefault) {
> + if (devices[i].position === cameraPositionVideoCaptureDefault) {
> + oxideContext.defaultVideoCaptureDeviceId = devices[i].id
> + break
> + }
> +
> + /**
> + * This is only there to act as a fallback with a reasonnable
> + * heuristic that tracks the case described above.
> + */
> + var displayName = devices[i].displayName
> + if (__internal.cameraNamePrefixVideoCaptureDefault
> + && __internal.cameraPositionUnspecified === devices[i].position
> + && displayName.indexOf(
> + __internal.cameraNamePrefixVideoCaptureDefault) === 0) {
> + oxideContext.defaultVideoCaptureDeviceId = devices[i].id
> + break
> + }
> + }
> + }
> + }
> + }
> +
> + var devices = OxideGlobals.availableVideoCaptureDevices
> + if (devices.length !== 0) {
> + updateDefaultVideoCaptureDevice()
> + }
> + OxideGlobals.availableVideoCaptureDevicesChanged.connect(function(){
> + updateDefaultVideoCaptureDevice()
> + })
> + }
> }
--
https://code.launchpad.net/~abreu-alexandre/webbrowser-app/front-camera-as-default-capture/+merge/291527
Your team Ubuntu Phablet Team is requested to review the proposed merge of lp:~abreu-alexandre/webbrowser-app/front-camera-as-default-capture into lp:webbrowser-app.
More information about the Ubuntu-reviews
mailing list