Introduction

H.264 is patented and subject to royalties from Mpegla. (More information on http://www.mpegla.com/main/programs/AVC/Documents/AVC_TermsSummary.pdf.)
Since 2013, Cisco has released a free implementation of this codec with  OpenH264, including binary version countable on their MPEG-LA licensing costs.

To benefit from this binary implementation, an application must comply with conditions stated below.

This article describes how an application can first download the binary version of the H264 codec from Cisco web site and then load into Linphone. Note that is mainly relevant for applications running on android versions < 5.1. Newer versions have a decently working MediaCodec integrated H264 codec (hardware codec from the phone), that is used by Linphone without any specific configuration.
 

License

Entire binary licence can be found at http://www.openh264.org/BINARY_LICENSE.txt


---------------------------------------------
AVC/H.264 Patent Portfolio License Conditions
---------------------------------------------

In addition, the Cisco-provided binary of this Software is licensed under Cisco's license from MPEG LA only if the following conditions are met:

  1. The Cisco-provided binary is separately downloaded to an end user’s device, and not integrated into or combined with third party software prior
     to being downloaded to the end user’s device;

2. The end user must have the ability to control (e.g., to enable, disable, or re-enable) the use of the Cisco-provided binary;

3. Third party software, in the location where end users can control the use of the Cisco-provided binary, must display the following text:

       "OpenH264 Video Codec provided by Cisco Systems, Inc."

4.  Any third-party software that makes use of the Cisco-provided binary must reproduce all of the above text, as well as this last condition, in the EULA and/or in another location where licensing information is to be presented to the end user.

Requirements

Android < 5.0

On a device with Android < 5.0 due to a bad library linker after the downloading of OpenH264 codec we need to completely restart the application.

OpenH264DownloadHelper

OpenH264DownloadHelper can download OpenH264 codec and deliver download information.
OpenH264DownloadListener can be used to display download informations to a progress bar and he can be set to OpenH264DownloadHelper with the setter.

new OpenH264DownloadListener() {
   @Override
   public void OnProgress(int current, int max) {
   }
   @Override
   public void OnError(String error) {
   }
};

Use

To know if OpenH264 is enabled:
LinphoneCore lc;

...

lc.enableOpenH264()

To create a new instance of OpenH264DownloadHelper:
Context ctxt;

OpenH264DownloadHelper h264Downloader = new OpenH264DownloadHelper(ctxt);

To create specific assets for example a progress bar:
Context ctxt;
LinphoneCore lc;

...

OpenH264DownloadHelperListener h264Listener = new OpenH264DownloadHelperListener() {
 ProgressDialog progress;
@Override
public void OnProgress(final int current, final int max) {
  mHandler.post(new Runnable() {
  @Override
  public void run() {
   if (progress == null) {
     progress = new ProgressDialog(ctxt);
     progress.setCanceledOnTouchOutside(false);
     progress.setCancelable(false);
     progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
   } else if (current <= max) {
     progress.setMessage("Downloading OpenH264");
     progress.setMax(max);
     progress.setProgress(current);
     progress.show();
   } else {
     progress.dismiss();
     progress = null;
     lc.reloadMsPlugins(null);
   }
  }
 });
}

@Override
public void OnError (final String error){
  mHandler.post(new Runnable() {
  @Override
  public void run() {
   if (progress != null) progress.dismiss();
    AlertDialog.Builder builder = new AlertDialog.Builder(ctxt);
    builder.setMessage("Sorry an error has occurred.");
    builder.setCancelable(false);
    builder.setNeutralButton("Ok", null);
    builder.show();
  }
 });
}
};
h264Downloader.setOpenH264HelperListener(h264Listener);

To check if the file exists: ''isCodecFound()'':
if (h264Downloader.isCodecFound())
Afterwards, a popup ask box can be created which will start the download with method ''downloadCodec()'' of OpenH264DownloadHelper:
Context ctxt;

...

AlertDialog.Builder builder = new AlertDialog.Builder(ctxt);
builder.setCancelable(false);
AlertDialog.Builder show = builder.setMessage("Do you agree to download "
 + h264Downloader.getLicenseMessage()).setPositiveButton("Yes", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
 if (which == DialogInterface.BUTTON_POSITIVE)
   h264Downloader.downloadCodec();
 }
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
 if (which == DialogInterface.BUTTON_NEGATIVE){
 }
}
}).show();

Example

Asking pop-up

To comply with the first license condition:1. The Cisco-provided binary is separately downloaded to an end user’s device, and not integrated into or combined with third party software prior
to being downloaded to the end user’s device;We need to ask the user if he agrees with the download.

On first launch

After the registration we ask the user if he agrees with the download of OpenH264 codec.
If answer is 'yes' we go to download step otherwise we disable H264 option for video.
 

337px-First_launch.jpg

On video settings

When user checks on H264 box, H264 plugin is activated. If OpenH264 is not available, we ask the user to download it.
If 'yes' we go to download step otherwise we enable hardware codec for h264.

337px-Video_settings.jpg

Progress bar

We display a progress bar of the download.
 

337px-Progress_bar.jpg

Codec downloaded popup

We indicate that codec is downloaded and activated.
 

337px-Codec_available.jpg

Created by SandrineAvakian on 2017/01/11 15:36