User Tools

Site Tools


android_tunerhal

Android DVB Tuner Framework

Important

This information in this page relates to the first release of the DTVkit TunerHAL implementation. This is an alpha release and has primarily been tested using the Android emulator. The Android emulator has certain restrictions in that only H264 video is currently supported and audio is not supported for broadcast media formats. The release has been made available for members that want to experiment with the code at an early stage. The release makes use of a modified version of the Android 'TunerHAL' code that enables transport stream data to be read from a file. With this the DTVkit release can be run in the Android Emulator, it is then possible to 'tune' to the file source, receive SI/EPG information, decode video (H264), and change channel. The code base is currently being tested on reference hardware and will be updated in due course.

Background

Android 11 introduces a new hardware abstraction layer for tuner, demux and descrambler the TunerHAL. This enables the front-end hardware components to be accessed using standard Android APIs in a platform independent manner. Android 11 also introduces new 'passthrough' AV decoding which enables AV decoding to be performed by the secure video hardware of the platform under the control of the standard Android Media Framework APIs. By making use of both the TunerHAL and Android Media Framework APIs it is possible to create an Android integration of DVBcore that is platform independent. It will run on any Android platform that support the new TunerHAL APIs and is not specific to any one silicon platform. This makes it simpler to use the same instance of DVBcore across a range of Android devices.

Overview

The DTVKit Android Tuner HAL solution integrates DVBCore with Android using the Android TV Input Framework (TIF) and the Android Tuner Framework. By using the TIF and the Tuner Framework, manufacturers can provide a TV input source that new and existing apps, such as Live Channels, can use through a standard Android API.

DTVKit Android Architecture

Input Source

The input source is built as an Android system application. It provides:

  1. A TvInputService/TvInputService.Session implementation. Applications interact with this through the TvView abstraction to show programs provided by the input source.
  2. The set up activity. This is launched by the TV app (e.g. Live Channels) and provides a user-interface for doing a service search.
  3. The TV provider sync job. A background service that updates the TV provider database to match the channels and programs in the DVBCore database.

Companion Library

The TV input source uses parts of the companion library (Apache License 2.0), which can be found in the Android TV sample inputs project (the companion library is not used as a third-party library, but is copied into the project).

Our copy has a number of modifications. We have removed ads, XMLTV parsing, the template set up activity and the base TV input service (which has been replaced by our own implementation).

Building DTVKit Android 11 Reference

The repository can be cloned from Github and can be placed in the external directory from the Android source tree.

Build and installation

1. Set up Android build environment

source build/envsetup.sh
lunch BUILD_TARGET

2. Clone the DTVKit Android components and overlay DVBCore

cd $ANDROID_BUILD_TOP
git clone https://github.com/DTVKit/Android_11_Reference external/dtvkit
git clone https://github.com/DTVKit/DVBCore external/dtvkit/androidtunerlibrary/src/main/libs/dvbcore/DVBCore

3. Build androidtunerlibrary module and native library

mmm external/dtvkit -j8

4. Copy the built libraries into tis module as dependencies

cd external/dtvkit
mkdir -p tis/libs
cp $ANDROID_PRODUCT_OUT/obj/JAVA_LIBRARIES/androidtunerlibrary_intermediates/javalib.jar tis/libs/androidtunerlibrary.jar
cp $ANDROID_PRODUCT_OUT/system/lib/libdvbglue.so tis/libs/libdvbglue.so

5. Build tis module (TV input service app) using Gradle. This can be done from within Android Studio or command line

6. Sign the built app with the platform keys from your Android source

SIGN_APK_JAR=$ANDROID_BUILD_TOP/prebuilts/sdk/tools/lib/signapk.jar
PLATFORM_KEYS_DIR=$ANDROID_BUILD_TOP/build/target/product/security
PLATFORM_KEYS="$PLATFORM_KEYS_DIR/platform.x509.pem $PLATFORM_KEYS_DIR/platform.pk8"

java -Djava.library.path="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/linux/lib64" -jar $SIGN_APK_JAR $PLATFORM_KEYS ./tis/build/outputs/apk/debug/tis-debug.apk ./tis/build/outputs/apk/debug/tis-debug-signed.apk

7. Run the zipalign tool

ZIPALIGN=$ANDROID_SDK/build-tools/30.0.3/zipalign

$ZIPALIGN -p -f -v 4 ./tis/build/outputs/apk/debug/tis-debug-signed.apk ./tis/build/outputs/apk/debug/tis-debug-zipaligned.apk

8. Install native library onto device

adb root
adb remount
adb push ./tis/libs/libdvbglue.so /system/lib/libdvbglue.so

9. Install the TIS app onto device as a system app. First time installation will require device reboot after running the following command:

adb push ./tis/build/outputs/apk/debug/tis-debug-zipaligned.apk /system/app/inputsource/inputsource.apk

Building DTVKit Android 11 TunerHAL

The repository can be cloned from Github. This release of the Tuner HAL implementation is for the emulator.

Build and installation

1. Clone repo and copy default folder contents into $ANDROID_BUILD_TOP/hardware/interfaces/tv/tuner/1.0/default

2. Build the tuner interface

cd $ANDROID_BUILD_TOP
mmm hardware/interfaces/tv/tuner/1.0/default -j8

3. Install the built service onto device

adb root
adb remount
adb push $ANDROID_PRODUCT_OUT/vendor/bin/hw/android.hardware.tv.tuner@1.0-service /vendor/bin/hw/android.hardware.tv.tuner@1.0-service

Run

This Tuner HAL implementation looks for TS files under /vendor, every file must have a valid frequency as name. For example 470000000.ts (frequency in Hz) for DVB-T.

SELinux Configuration Android 11

Android uses Security-Enhanced Linux (SELinux) to enforce mandatory access control (MAC) over all processes. SELinux operates in two modes:

  • Permissive - SELinux security policy is not enforced, only logged
  • Enforcing - SELinux security policy is enforced and logged

Permissive Mode

For non-production devices (e.g. development) SELinux can be disabled by setting it to permissive mode.

Currently the DTVKit Tuner HAL solution only works in permissive mode.

android_tunerhal.txt · Last modified: 2021/10/28 08:30 by jason