Wireless Display for Android


    In early 2013, in the Intel news feed, we announced a new version of WiDi technology, which, inter alia, received compatibility with the related Miracast standard. Then this information went unnoticed, and in our opinion, in 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 kind of functionality they have in a couple, and how to create Android applications using them.

    Variety of features and capabilities

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


    General concept Miracast

    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 exchange data with each other without the help of additional network infrastructure. Simply put, Miracast can be thought of as wireless HDMI.
    Miracast is still quite young: the official certification of Miracast devices by the WiFi Alliance began a little 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 been further enhanced after its support was added to Android 4.2 last year. I note right away that in Android 4.2 on a specific device the availability of Miracast is not guaranteed - this needs to be clarified additionally. For a complete list of certified devices, both transmitters and receivers, see the WiFi Alliance website .


    Miracast architecture (transmitter side)

    The compatibility of Miracast and WiDi version 3.5 means the commonality of basic functionality in devices of both standards. What additional goodies are there in WiDi but not in Miracast? There are three today:
    • Mandatory support for HD video up to 1080p (although the Miracast standard allows for high resolution, but does not oblige all devices to support it);
    • Support for HDCP (High-bandwidth Digital Content Protection);
    • the presence of two additional video modes - advanced and multi-tasking (about them a little later).

    Thus, we can say that WiDi is currently a functional extension of Miracast.
    WiDi is supported by most existing Intel mobile platforms (and will most likely be supported by subsequent ones). As already noted in testing, the technology belongs to the category of “one-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 to WiDi / Miracast - the same picture is displayed on the remote display as on the local one, with the same resolution.
    Dual modealso applies to basic; in it, content is played on the remote display, and the main one is used to control and display service information. This mode is supported through the Android Presentation API.
    Advanced mode is available only in WiDi (and, accordingly, is only available for devices based on the Intel Atom platform). In it, video mode is automatically turned on when a user launches multimedia content on a player using the Android Media Player framework. The resolution of the picture 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 Multitasking.in which the video player sends the image to a remote display, and on the local one at that 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 dual display mode:


    Dual display mode is not only suitable for watching videos. It’s quite easy to sketch out a list of its vital applications:
    • browsing the Internet on a large screen (the smartphone acts as a touchpad);
    • filling out forms or typing small texts (smartphone - touch keyboard);
    • games (smartphone - touch gamepad / joystick);
    • mobile workstation (smartphone is a computer, peripherals are connected to it via Bluetooth).




    We 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 you to:
    • Implement support for the second display in applications without worrying about the way it will be physically connected;
    • work with MHL, HDMI, Slimport or Miracast compatible devices;
    • control the second display regardless of the first.

    Presentation is a base class and should be extended:
    publicclassDemoPresentationextendsPresentation {

    An association with the Display class is also required at creation. Presentatio n inherits from Dialog , and as for Dialog , its life cycle is tied to Activity .
    Before you enable Presentation , you need to select a display, which can be done in two ways:
    1. MediaRouter API (in API 16) - the system itself 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 application:
    //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:
    <itemandroid: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:
    • onRouteUnselected
    • onRouteSelected
    • onRoutePresentationDisplayChanged

    And inside the activity that Presentation owns:
    • onResume
    • onpause

    APIs for managing WiFi displays are present inside Android AOSP, but are not part of the Android framework. Wireless display settings can be called via Intent android.settings.WIFI_DISPLAY_SETTINGS , but it is also not included in 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 to 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 you can test applications for two displays both on real hardware that supports this functionality, and on emulation, available starting from Android 4.2 in the developer options. You can choose the resolution and dpi of the second virtual display, and get an overlay with its display.



    In preparing the post, IDF 2013 materials were used, authors - Xavier Hallade and Costas Stylianou.

    Also popular now: