Open Bug 1242816 Opened 9 years ago Updated 2 years ago

Use applyConstraints facingMode to switch front/back camera on Android

Categories

(Core :: WebRTC: Audio/Video, defect, P3)

All
Android
defect

Tracking

()

People

(Reporter: mathieu.hofman.dev+mozilla, Unassigned)

Details

Once a webcam stream has been acquired on Android, it should be possible to switch between front and back camera by changing the "facingMode" constraint in an applyConstraints() call. Currently it seems that the "facingMode" constraint only works during the initial gUM call for selection. This would avoid interruptions of the stream since both cameras cannot be active at the same time (forcing the app to stop the previous stream first), and a permission prompt is normally shown to the user for each gUM call. See https://github.com/w3c/mediacapture-main/issues/304#issuecomment-174213158 for some more background.
Flags: needinfo?(jib)
Unfortunately, I believe it would violate the spec to have track.applyConstraints() switch to another device that's observably different in device enumeration. To be compliant, this would have to be a new single virtual device abstracting both cameras. Lets call it "Both". gUM may be fine, but web sites calling enumerateDevices would be affected. Would they see: A) three devices ("Front", "Back", and "Both")? B) One device ("Both")? or C) two devices ("Front (by default)" and "Back (by default)")? Ironically, sites would probably want to translate this back into a list of two devices for their UX, so maybe C is best? Furthermore, devinfo.getCapabilities() would have to show { ... facingMode: ["user", "environment"] } on this new thing, which may be fine, except in C, where one wouldn't be able to tell the two apart except by the label. In the end, web sites would have to recognize this thing and know how it works, which might mean we'd want buy-in from other vendors on this anyway.
Flags: needinfo?(jib)
What I had in mind was B) a single "Both". For lack of actual experience with Firefox Android, and seeing examples with "facingMode", I thought that was already the case. As a transition A) seems like an acceptable solution. There is already plenty of cases where 2 different entries in the enumeration are actually the same device, e.g. the "default" option in Chrome, or virtual webcam drivers on desktop. Indeed developers would need to use getCapabilities() to understand this "Both" device is capable of switching. As an app developer, I actually might show a completely different UI on mobile, instead of a "list", I'd simply show a "flip" button. IMHO, C) is not the right approach for the same issues you raise. I agree that getting buy-in from other vendors would be a good idea. I just filed https://code.google.com/p/chromium/issues/detail?id=581401 with Chrome. Justin, do you have any opinion on the matter?
Flags: needinfo?(juberti)
Any action on that Chrome bug?
Flags: needinfo?(mathieu.hofman)
Whiteboard: [needinfo 2016/05/12]
I haven't seen much traction on that Google bug. Maybe Justin has more info?
Flags: needinfo?(mathieu.hofman)
I looked into it and I agree with the B) proposal - this matches how Android and iOS do camera switching under the covers. Updated the chromium bug as such.
Flags: needinfo?(juberti)
Status: UNCONFIRMED → NEW
Rank: 25
Ever confirmed: true
Priority: -- → P2
Whiteboard: [needinfo 2016/05/12]
Mass change P2->P3 to align with new Mozilla triage process.
Priority: P2 → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.