📜 ⬆️ ⬇️

Wireless Display for Android


In early 2013, in the news blog of Intel blog, we reported on a new version of WiDi technology, which, including, received compatibility with the related standard Miracast. Then this information went unnoticed, and in our opinion, it is very vain, since the picture in the field of wireless displays has changed dramatically. And one of the changes is the appearance of Miracast on Android. Let's try to figure out how Miracast and WiDi relate to each other, what features a couple have and how to create Android applications using them.

Variety of features and capabilities

We have already talked about the WiDi standard enough: we followed the news , viewed it from a developer’s point of view, and even tested a live serial adapter . Now for the beginning we will describe in a few words the technology Miracast.


General Miracast Concept

Miracast is a technology for transmitting multimedia information (audio and video) via WiFi. As a transport, it uses the WiFi Direct standard, which allows two devices to communicate with each other without the help of an additional network infrastructure. Simply put, Miracast can be thought of as a wireless HDMI.
Miracast is still quite young: the official certification of the Miracast device by the WiFi Alliance started just over a year ago. For video transmission, the H.264 codec is used, the sound can be two- or five-channel. Miracast is an open standard not owned by any company; its appeal has increased even more since last year its support was added to Android OS 4.2. I note right away that in Android 4.2 on a specific device, the availability of Miracast is not guaranteed - this must be clarified further. A full list of certified devices, both transmitters and receivers, can be viewed on the WiFi Alliance website .
')

Miracast architecture (transmitter side)

Compatibility of Miracast and WiDi version 3.5 means the commonality of the basic functionality in devices of both standards. What are some additional buns in WiDi, but not in Miracast? On this day there are three:

Thus, we can say that WiDi is currently a functional continuation of Miracast.
WiDi is supported by most of Intel's existing mobile platforms (and will most likely be supported by later ones). As noted in the testing, the technology belongs to the category of “single-button”, that is, extremely simple for users.


The process of connecting a wireless display on the example of the Samsung Galaxy S4

Well, now it's time to talk about the modes. Cloning Mode is native for WiDi / Miracast - the remote display shows the same picture as on the local one, with the same resolution.
Dual mode also belongs to the main; the content is played on the remote display, and the main one is used to control and display the service information. This mode is supported through the Android Presentation API.
Advanced mode is available only in WiDi (and, accordingly, is available only for devices on the Intel Atom platform). In it, the video mode is automatically enabled when the user launches multimedia content on the player using the Android Media Player framework. Image resolution remains "native" up to 1080p. At the same time, local video rendering can be turned off to reduce power consumption.
Finally, the most advanced is the Multitasking Mode , in which the video player sends an image to a remote display, and at the local time, the user does what he wants: browses the Internet, receives calls or even watches a completely different video, also in FullHD resolution!

Options for using the dual display mode:


Dual display mode is not only suitable for watching videos. It is completely easy to sketch a list of its vital uses:




Create an Android application for two displays

Support for the second wireless display in Android 4.2 (API Level 17) is implemented using the Presentation class, which allows:

Presentation is a base class and should be extended:
public class DemoPresentation extendsPresentation { 

An association with the Display class is also required when creating it. Presentatio n is inherited from Dialog , and as for Dialog , its life cycle is tied to an Activity .
Before you use Presentation , you need to select a display, which can be done in two ways:
1. MediaRouter API (in API 16) - the system will choose the best display for you
 // Get the media router service. MediaRouter mMediaRouter = (MediaRouter)getSystemService(Context.MEDIA_ROUTER_SERVICE); // Use the MediaRouter that supports live video MediaRouter.RouteInfomRouteInfo =mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO); Display presentationDisplay= mRouteInfo.getPresentationDisplay(); 

2. Display Manager API (in API 17) - a list of displays.
 // Get the display manger service. DisplayManager mDisplayManager = (DisplayManger)getSystemService(Context.DISPLAY_SERVICE); // enumerate the displays Display[] displays =mDisplayManager.getDisplays(DisplayManger.DISPLAY_CATEGORY_PRESENTATION); 

Adding MediaRouteButton to the app:
 //Sets Media Route Button to second screen mode mediaRouteActionProvider.setRouteTypes(MediaRouter.ROUTE_TYPE_LIVE_VIDEO); //Launches the Wireless display setting intent startActivity(newIntent ("android.settings.WIFI_DISPLAY_SETTINGS")); 

In res / menu / default.xml:
 <item android:title="Media Route Settings" android:actionProviderClass="android.app.MediaRouteActionProvider" android:showAsAction="always" /> 

How to make Presentation API work:


Next, using MediaRouter.addCallback , you need to monitor:

And inside the activity that owns Presentation:

APIs for managing WiFi displays are present inside the Android AOSP, but are not part of the Android framework. The parameters of the wireless display can be called via Intent android.settings.WIFI_DISPLAY_SETTINGS , but it is also not part of the framework. Some manufacturers use other options: Samsung - com.samsung.wfd.LAUNCH_WFD_PICKER_DLG , HTC - com.htc.wifidisplay.CONFIGURE_MODE_NORMAL .
All APIs shown in the figure below are internal for Android 4.2 / 4.3. They are part of AOSP and are distributed freely, but are not included in the frameworks and are not required to work.


In conclusion, we note that testing applications for two displays is possible both on real hardware supporting this functionality and on emulation, available starting from Android 4.2 in the developer options. You can select the resolution and dpi of the second virtual display, and get an overlay with its display.



IDF 2013 materials were used in the preparation of the post, the authors are Xavier Hallade and Costas Stylianou.

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


All Articles