Can Of Code

The History of Video Decoding on Android

In this post I aim to give a brief overview of the differences with video decoding on Android. This overview is mainly focused on whats available if MediaPlayer or VideoView doesn’t fit your requirements.

 

From the beginning (Android 1.0)

The first media framework on Android came from PacketVideo and was called OpenCore.

 

Donut time (Android 1.6)

Android-Donut

Image source: http://www.huntlogo.com/android-donut-logo/

 

A updated version of OpenCore was released with the catchy title of “OpenCore 2.0”.  The new version of OpenCore included support for the OpenMax IL API which enabled apps to make use of dedicated hardware encoder/decoders.

The inclusion of OpenMax support was a massive step in bringing high resolution video to mobile devices. A dedicated Hardware decoding/encoding chip would take the stress away from the CPU,  essential in the days when a device like the HTC Hero had a CPU speed of 528Mhz.

That is all I know of OpenCore and considering that it’s only available for 0.1% of the distribution it’s probably not worth implementing.

 

Eclair has Stagefright (Android 2.0 – 2.1)

Android-Eclair

Image source: http://www.huntlogo.com/android-eclair-logo/

 

The Stagefright library was introduced as a replacement for the previously mentioned OpenCore.

From the Java side you only get a handful of classes which should use hardware decoding when available. If you want to use media formats that are not support by Eclair you will need to go down the painful route of using private Android libraries.

When going down this route you will read of people warning you against it, the main reason being that there is no guarantee that the libraries will be the same on every device.

The OMXCodec would be your best bet at decoding via hardware. A good demo of this can be found here. What that demo doesn’t mention is how to include the private libraries and headers so you can actually use OMXCodec. One way would be to copy the libstagefright.so (among others) from an emulator into your project.

 

Gingerbread also has Stagefright (Android 2.3)

Android-Gingerbread

Image source: http://www.huntlogo.com/android-gingerbread-logo/

 

Not much relating to video was changed in Gingerbread. One point of interest is the addition of being able to use the Surface from native code via the NDK.

 

Honeycomb HLS (Android 3.0)

Android-Honeycomb-2

Image source: http://www.huntlogo.com/android-honeycomb-logo-2/

 

Although nobody uses Honeycomb it did bring along support for HTTP Live Streaming (HLS). However Android’s implementation is a little flaky especially when seeking.

 

Ice Cream Sandwich (Android 4.0)

Android-Ice-Cream-Sandwich

Image source: http://www.huntlogo.com/android-ice-cream-sandwich-logo/
 

Ice Cream Sandwich introduced OpenMax AL Support via the NDK. One significant downfall with Android’s implementation of OpenMax AL is that it only supports the decoding of “MPEG-2 transport stream via a buffer queue“. This rules out passing raw h264 NALUs or other media formats for that matter.

 

Jellybean brings MediaCodec (Android 4.1 – 4.3)

Android-Jelly-Bean-logo

 

 

Image source: http://www.huntlogo.com/android-jelly-bean-logo/
 

In jellybean the MediaCodec was introduced which provides a Java API for Encoding / Decoding using both software and hardware decoders.

Although the introduction of the MediaCodec gives the benefit of staying within the comfort of a Java environment. One frustration with MediaCodec is the poor documentation, especially if you want to use your own demuxer instead of the MediaExtractor.

A good example of the lack of documentation revolves around how codec private data should be handled. For example with a H264 Stream you should put the SPS in a ByteBuffer with the key “csd-0” and the PPS with a key of “csd-1”. The best approach i found was to study the MediaFormat that is created by the MediaExtractor and then emulate the results in your project.

A really helpful working example of the MediaCodec can be found here, its worth keeping the site in your favorites as they also has a few other useful related posts.

Update: Android 4.3 has a new “modular DRM framework” for handling streams that make use of DRM.

 

Finally

That’s my overview of video decoding on Android. You may notice i have missed a few of the smaller release mainly because nothing interesting had changed. I am relatively new to both Android and Video decoding so if i have missed something important or made any incorrect statements please let me know in the comments.

Posted in Uncategorised | 4 Comments

Increasing the touch area of a Rectangle in XAML

I have been recently working on a Windows Phone project that required a small item to be dragged across the screen.

It was soon discovered that while it worked nicely on the emulator using the precise mouse it wasn’t so easy to use when using my chubby fingers on a REAL device.

The element i was working with was a Rectangle, so after some playing i discovered that creating a large “invisible” stroke around the rectangle would fit the task.

To achieve this i created the rectangle as shown:

 <Rectangle Fill="#FFF4F4F5" Height="270" Width="270"  Stroke="#00FF0000"   StrokeThickness="120" />

 

This XAML creates an invisible hit area of 120 each side of the rectangle using the stroke property therefore creating a rectangle of 30 x 30. The stroke is invisible by using a color with 0% alpha.

 

 

Posted in Uncategorised | 1 Comment

Windows 8 – Adding a Share Contract to your App in C#

I’ve finally started playing around with Windows 8 after spending ages getting it to work in VirtualBox. I struggled to find any sample code / tutorials on adding a share contract in C# so here is my guide.

 

First things first we need to add a import statement:

Using Windows.ApplicationModel.DataTransfer;

 

Next up we need to fetch a DataTransferManager and then associate a method with the DataRequested event. I placed this code in the constructor of the MainPage.xaml.cs.

DataTransferManager manager = DataTransferManager.GetForCurrentView();
manager.DataRequested += new TypedEventHandler(share_DataRequested);

 

Now we need to create the share_DataRequested Method that’s called when a share request is made.

private void share_DataRequested(object sender, DataRequestedEventArgs e)
{
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Sharing something";
    request.Data.Properties.Describtion = "Sharing something with someone";
    request.Data.setText("I'm sharing!");

}

 

The method above is where you tell Windows what data your app wants to share. The example above shows the sharing of a simple string saying “I’m sharing”. The picture below shows how the message will apear once the user select a Share compatible App to share with. On the Enterprise Edition you can only share using Mail by default so you may need to download some other Apps to test the sharing.

 

Your App now makes use of a share contract! If you want to manually launch the Share Contract UI for the user you can use the following code:

DataTransferManager.ShowShareUI();

 

Which will bring up the below UI.

 

Posted in Uncategorised | Leave a comment