6

Is there a reliable way to determine if a camera is rotated on the Microsoft Surface?

Basically, I want to know if a specific camera is built into the device (as it will then rotate with the device), is there a way to query this?

My problem is that when the user rotates the device, my camera view is flipped, I cannot however assume that I should just rotate the read frames as the active camera may be an external USB camera.

I'm reading the cameras using the Media Foundation APIs.

monoceres
  • 4,722
  • 4
  • 38
  • 63
  • I'm not quite sure if this will help, but you can check the MF_MT_DEFAULT_STRIDE attribute of the camera's media type: https://msdn.microsoft.com/en-us/library/windows/desktop/ms698965(v=vs.85).aspx. "Stride is positive for top-down images, and negative for bottom-up images." – VuVirt Jan 16 '17 at 12:44
  • I don't think that's it, for example, the device may rotate 90 degrees. :( – monoceres Jan 16 '17 at 12:48
  • 1
    It's rather [`MF_MT_VIDEO_ROTATION`](https://msdn.microsoft.com/en-us/library/windows/desktop/hh162880) but I am not sure if Surface camera is actually using it. – Roman R. Jan 16 '17 at 16:38

1 Answers1

2

Basically, I want to know if a specific camera is built into the device [...] is there a way to query this?

With UWP, you can check the camera's DeviceInformation's enclosureLocation.panel property, which is either:

  • front/back/etc for an integrated camera or
  • unknown for an external camera

An full example is available in the CameraStarterKit sample.


However, if you can't use UWP, it should still be possible to find the underlying information. With MF, you should be able to access MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK.

This will be something like

\\?\usb#vid_046d&pid_0843&mi_00#6&2314864d&0&0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\global

A built-in camera is supposed to register its physical location in

HKLM\SYSTEM\CurrentControlSet\Control\InternalDeviceModification\{GUID}

Where the value of the PLD_Panel key should be a DWORD with values very similar to the Panel enum referenced above.

Here, 6 means unknown. So you should be able to check for the presence of this registry key and, if present check its value. I suspect this is similar to what UWP does under the hood.

Failing that, you can also hack in support by hardcoding some values for camera vendor and product ID's or MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME's.

Grisha Levit
  • 8,194
  • 2
  • 38
  • 53
  • This looks like exactly what I need. Excellent! However, when looking in regedit on my Surface Pro 3 device (running windows 10) the InternalDeviceModification key is missing. Any ideas? – monoceres Jan 25 '17 at 13:06