Multicast Support
=================

.. javaimport::
    com.castlabs.*
    com.castlabs.android.*
    com.castlabs.android.drm.*
    com.castlabs.android.player.*

This section covers Multicast Support in the |SDK|. In order to playback ``UDP``
or ``RTP`` content the following criteria must be fulfilled:

1. ``CONFIG_IP_MULTICAST`` must be enabled when compiling the AOSP/Android TV Kernel
   for the device in question.
2. :javaref:`IPTVPlugin` must be registered during |SDK| initialization.

Basic Integration
-----------------

.. code-block:: java

   PlayerSDK.register(new IPTVPlugin(false, true, IPTVPlugin.DEFAULT_RTP_QUEUE_SIZE, IPTVPlugin.DEFAULT_DISCONTINUITY_THRESHOLD));

At creation the user may specify whether the ``IPTVPlugin`` only plays clear content,
whether data till the first Key frame can be ignored in the Multicast Data, the
RTP Queue size (in number of RTP Packets) and a discontinuity threshold which is useful
for error handling.

URL Configuration
-----------------

For Playback to work, one may simply pass the correct Multicast url under the SdkConsts.INTENT_URL
either in the format,

.. code-block:: java

    .put(SdkConsts.INTENT_URL, "udp://<a.b.c.d>:port")

for UDP or,

.. code-block:: java

    .put(SdkConsts.INTENT_URL, "rtp://<a.b.c.d>:port")

for rtp in the :javaref:`PlayerConfig`. The client application may also pass in
an IPTV Player Configuration as part of the :javaref:`com.castlabs.android.player.SingleControllerPlaylist` configuration.

DRM Support with IPTV (experimental)
------------------------------------

Starting from |SDK| version 4.4.4, we support UDP/RTP with CENC Widevine encrypted
``H264-AVC`` and ``H265-HEVC``. In order for this to work a :javaref:`DrmConfiguration`
must be specified along with the Player Configuration.

For this to work, the appropriate Castlabs defined signalling must be enabled in the
bitstream as well as the program PMT.

IPTV Read Timeout
-----------------

In order to detect the unavailability of the IPTV stream during playback the client application
may set the appropriate read timeout.

.. code-block:: java

    NetworkConfiguration networkConfiguration = new NetworkConfiguration.Builder()
				.iptvReadTimeoutMs(x)
				.get();

The client can then listen to the ``IptvAnalyticsListener#onNetworkTimeout()`` callback.
