Screen capture of an external display on Android?

Android applications through the Presentation class and related tools can display separate content on an external display (HDMI, MHL, Miracast, etc.) than on the touch screen of a phone or tablet (what I will call the "primary display" here).

For the main display, we can use screencap or DDMS to take a screenshot.

Is there any way to take a screenshot of the external display?

Ideally, this would be a solution that could be used with screencap / DDMS without changing the application. However, solutions that somehow copy the contents of a Window representing an external display will also be interesting.

+5
source share
1 answer

There is no OS function to capture an external display.

The main display consists of several sources, as well as an external display. The screen capture feature is actually another way to combine different sources. Since it uses the same parameters as the main display, you get the same result. (Note that any “protected” layers, such as DRM-protected videos, are not displayed.) Thus, to “capture” an external display, you need a screen capture option that uses the outer layer of the “stack stack” rather than basic, and there is no API for this.

(see SurfaceFlinger::captureScreenImplLocked() in SurfaceFlinger.cpp .)

The screenrecord command does something similar: it creates a virtual display with a stack level of the main display and captures everything that is displayed there.

Regarding the output of the Presentation output, there are several CTS tests that may be of interest. VirtualDisplayTest creates Presentation and captures it using ImageReader , and EncodeVirtualDisplayTest delivers the presentation through the full encoding / decoding path of the video. Tests simply draw a series of colors and then verify that the colors can be read. Both of them require the latest versions of Android (for example, ImageReader did not exist before API 19), and limited application permissions limit the output to the fact that the application itself is rendering.

+7
source

Source: https://habr.com/ru/post/1206927/


All Articles