ExoPlayer and Kotlin Thoughts

This past weekend I finally took the plunge and updated my Android TV / Fire TV application to use ExoPlayer.   Yeah, I’m a bit behind the curve here, and should have done this a while ago.   When I first wrote Serenity for Android about 5 years ago, you pretty much had to roll your own Player UI if you wanted anything more than the bare basics.   Thankfully, things are much simpler with ExoPlayer and the provided SimpleExoplayerView.   Everything I had to roll by hand and brute force implement in MediaController and the SurfaceView are now bundled directly in the SimpleExoplayerView.   This includes the ability to display Subtitles.   What took me about a good 2 months to implement myself, was basically done in a couple of days with Exoplayer.

The other nice thing about Exoplayer is that it brings video playback stability across devices.   Using the old player and MiBox Android TV device, if I tried to play back a movie with Dolby Digital Audio it would crash the app.    With ExoPlayer it works directly out of the box with the basic configuration.    This was the main reason that I made the switch to ExoPlayer.    The other reason is the ability to support Transcoding and choose either HLS or Dash support.    Currently Serenity supports the Universal Transcoder from the latest Plex Servers, but will hopefully start supporting the Emby Media Server as well.

While we are talking about Plex… why haven’t they provided 3rd party developers with a real documented API yet?    Emby has a complete Java API as well as APIs for multiple other languages.   Plex makes it so you have to reverse engineer what they are doing, or hope you can decipher one of the few remaining Open Source clients they have available to use and browse the code.    It is one of the reasons I’m starting the migration to Emby instead of Plex.  Functionality wise they are about equal now, but the open source nature of Emby fits better with my goals.   Having a documented API will help foster your third party developers, which can help drive users to possibly look at some of your paid subscription options for your applications.

Back to Exoplayer, I highly recommend taking a look at the library if you haven’t already.  If your last experience creating a video player or audio player was with the old Android APIs, then you will be presently surprised what you get out of the box for free now with ExoPlayer.

Now on to Kotlin.   It has been the rage for a while now in the Android community, especially with Google adopting it as an official supported language for Android development now.   Kotlin has a lot of good things too it, but along with the good comes some very frustrating things.

  • Increase in method count size.  If you have an app that needs to run on older devices still and you are near the 64K method limit.  You can be pushed over the edge with Kotlin and will need to start using Multi Dex.   One of the issues (features) is that Kotlin generates property accessors (getter/setters) for all field level variables you define that aren’t private.   This means that you can needlessly have extra methods generated that are never used.
  • If you do Test Drive Development or just write Unit Tests for your application (you do do this right???).   Then you will run into how much of a pain that Kotlin’s close by default nature becomes.   A work around for this is to use the Kotlin All Open plugin, to make classes and functions annotated with a particular annotation open by default.   This allows mocking frameworks like Mockito to play better with Kotlin generated code.   I understand the reasoning and I think closed by default is perfectly valid for Data classes within Kotlin, I just don’t agree that everything should be closed by default for all classes.
  • If you have a Java Interface that you need to implement in a Kotlin, and that interface has getter and setters defined.  You will not be able to use a Data class for this implementation.  The reason being you need to override the default definitions of the getter and setters within Kotlin.   So you loose the conciseness that Data classes provide.
  • There are pain points still if your application is a Hybrid application (i.e. a mix of Java and Kotlin code).   Accessing singleton instances from within Java code that was written in Kotlin can be a pain due to having to access inner Companion classes.
  • Dependency Injection is a bit funky with Kotlin if you use Dagger.   Because Dagger requires at least protected or internal fields and these fields can’t be private.  You’ll end up with a lot of getters and settters in the generated code.   Plus, you will need to use lateinit var option on your fields that will be injected.   If you need to annotate a field with more than one annotation you will need to use the really funky @field:[Inject ForVideoQueue] annotation format, where the options in the @field annotation are the multiple Annotations to be assigned to the field.   The added levels of syntax sugar can make the underlying code more verbose.
  • Becareful with the use of the null (?) operator in Kotlin, it can generate a bunch of extra code that you normally wouldn’t see generated as it checks for Null every time the method is used.   This can affect your code coverage results if you aren’t careful.

Kotlin isn’t all frustrating though.  It does force you to really do some defensive programming, and with some refactoring of existing code and knowing the flow of your application, use of @NonNull annotations in your Java Code can help detect possible NPE’s and keep you from passing these to Kotlin code.    Also the short cuts for one line methods is nice as well for reducing some boiler plate code.

I’m still early in my Kotlin adoption, but I see why people like it, but as much as people talk it up as the greatest thing since sliced bread, it still has it’s warts just like any other language.


Posted in android, kotlin, open source, plex media server | Leave a comment

OBS-Studio and Hardware Encoding for Linux

There are a lot of different ways to do hardware based encoding with obs-studio, however, this particular article will discuss getting things to work with the libva api standard that some Intel and AMD gpu’s support.   Unfortunately, obs-studio doesn’t support this right out of the box, but since it is open source, several people have made the necessary files available.

First though why do you want Hardware Encoding of your videos, obs-studio by default comes with access to the x264 software based encoder that is used with ffmpeg.  While this does a good enough job, it is also very CPU intensive, and in my experience this is is pretty picky on CPU usage that can start to drop your frame’s per seconds down.  Dropped frames means stuttering or laggy video.  Which isn’t a good thing.

On my particular system using software encoding with OBS-Studio running would take between 18 to 25 percent cpu.  If it creeped up into the 20% range, it would  start to drop frames.   So I had to be judicial about what was being done with the scenes.   With Hardware encoding enabled, the system is consistently using between 5 to 8 percent CPU.  A huge difference that frees up the CPU to be used for other things by other applications.

If you have Ubuntu installed, you probably already have the necessary drivers needed to use LIBVA api for hardware encoding.   To check this you can run the command vainfo to get the necessary information if your system supports hardware encoding.

vainfo libva info: VA-API version
    0.38.0 libva info: va_getDriverName() returns 0 libva info: Trying to open /usr/lib64/dri/i965_drv_video.so libva info: Found init function
    __vaDriverInit_0_38 libva info: va_openDriver() returns 0 vainfo: VA-API version: 0.38 (libva 1.6.1) vainfo: Driver version: Intel i965 driver for Intel(R) Haswell Desktop -
    1.6.1 vainfo: Supported profile and entrypoints
          VAProfileMPEG2Simple            : VAEntrypointVLD
          VAProfileMPEG2Simple            : VAEntrypointEncSlice
          VAProfileMPEG2Main              : VAEntrypointVLD
          VAProfileMPEG2Main              : VAEntrypointEncSlice
          VAProfileH264ConstrainedBaseline: VAEntrypointVLD
          VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
          VAProfileH264Main               : VAEntrypointVLD
          VAProfileH264Main               : VAEntrypointEncSlice
          VAProfileH264High               : VAEntrypointVLD
          VAProfileH264High               : VAEntrypointEncSlice
          VAProfileH264MultiviewHigh      : VAEntrypointVLD
          VAProfileH264MultiviewHigh      : VAEntrypointEncSlice
          VAProfileH264StereoHigh         : VAEntrypointVLD
          VAProfileH264StereoHigh         : VAEntrypointEncSlice
          VAProfileVC1Simple              : VAEntrypointVLD
          VAProfileVC1Main                : VAEntrypointVLD
          VAProfileVC1Advanced            : VAEntrypointVLD
          VAProfileNone                   : VAEntrypointVideoProc
          VAProfileJPEGBaseline           : VAEntrypointVLD
          VAProfileH264MultiviewHigh      : VAEntrypointVLD
          VAProfileH264MultiviewHigh      : VAEntrypointEncSlice
          VAProfileH264StereoHigh         : VAEntrypointVLD
          VAProfileH264StereoHigh         : VAEntrypointEncSlice

If you get information like above, you are set to move to the next step.  If you don’t, then either your system doesn’t support libva, or you may need to install the necessary deb file (intel-libva-driver I believe).

Next we need to recompile OBS-Studio with the necessary support plugin.  Fortunately, Reboot from GitHub has create the necessary plugin for us.   I’ve forked his code, and updated it to work with 19.x or above.   You will need to clone the repository and check out the vaapi-h264 branch I have.

I’m not going to go into detail on how to compile OBS-Studio, that is documented on the Wiki.   But once you recompile, you should now have a new menu option in the Output section of the preferences.   It will still default to x264, but you should be able to select the VA-API encoder option.   I would recommend this for both Streaming and Recording.  You shouldn’t need to mess with changing any of the defaults.

Start your recordings, and you should not see your CPU spiking as you did in the past.  You can play with the settings if you want, but the defaults worked well for me.




Posted in obs-studio, streaming, Uncategorized | Tagged , | 2 Comments

The State of Android and Eclipse

So it has been a while since I posted an update of where things stand.  Honestly, not a lot has changed on the eclipse front.  We still don’t have built in AAR support, there is no integrated Gradle support between Buildship and Andmore, we are behind on Nougat support, and O is fast approaching release status.   With that said, there have been a few bug fixes contributed by the community, which were released as a maintenance release, but the larger corporate adoption… is pretty much non-existent from a contribution stand point.

The later I’m not sure how to fix, as I whole heartily believe that Andmore needs a corporate backer and sponsor to fund things.   This could probably be avoided if several people that really have an itch to fix the base wanted to scratch it.   There is a lot to work on that it can be a bit overwhelming to figure out where to start.

When Google had announced a couple years ago that Android Development Tools would not be maintained any longer, I had that itch to see if I could at least get it and the Moto Dev Studio tools to a place where it would have a chance to survive.  I managed to scratch that and over the next year with the help of several other committers bring you Andmore 0.5.0.   Believe me the most difficult work has been done, and that is getting everything through the IP process, what is there is clean from that stand point.

So the general question now that Andmore is at the Eclipse Foundation, is there a dire need from the community to have Android tooling?   There was much outrage and yelling when Google made the decision to move to Intellij, some of it rightfully deserved some of it just background noise.   Regardless of the reasons, Android Tooling was always a Google controlled and sponsored project, it was open source in really name only (it took nearly 2 years for Doug’s CDT integration to be integrated into the core).   The same is happening with Android Studio, it is controlled and dominated by Google and is really open source in name only.  If Google decides for whatever reason that they want to move all development to the cloud and abandon Android Studio and Intellij, there is nothing that anyone will be able to do to prevent it.  The difference though is, that Jet Brains will pickup and continue developing Android support themselves.  Why, because they have a financial interest to make sure their IDE supports it for their corporate customers.

This brings us back to the question… Does the community really want Android tooling built off the eclipse platform?   If so, how do we improve it, given that right now, this is largely a volunteer effort.


Posted in android, eclipse, open source | Leave a comment

Andmore 0.5.1

A small maintenance release for the Andmore project has been released. This release contains a handful of bug fixes that have been provided entirely by the community. So if you have the will and desire to help move Android development for eclipse along, you just need to submit a pull request to the project and it will more than likely be included.

If you really, want to become a committer. The barrier to entry is pretty low. Just submit some quality pull requests to the project, and if you have the desire to work on the project more we will probably ask. Andmore is what the community makes it.

The maintenance release is available through the eclipse marketplace.

Posted in android, eclipse | 1 Comment

Andmore 0.5-M7 available.

Screen Shot 2015-04-19 at 4.44.52 PM

It’s been a while since I posted an update.  Milestone 0.5-M7 is available for download.  This is a pretty big upgrade to the underlying support libraries.   You should now be able to work with Android versions up to M with the this update.   It is recommended that you update your SDK as well if you haven’t already.

Android N may work as well, and we’ll need people to test this out.   The latest version is out in the Eclipse Market Place


The latest version can always be obtained from the following p2 url:


Please do give this a tire kick, and thanks again to Matthew Piggot for contributing the update and  Kaloyan for getting this big change out.

Posted in android, eclipse, planetandroid | Tagged , | 2 Comments

Andmore 0.5-M3 available.

Screen Shot 2015-04-19 at 4.44.52 PM

The third stable milestone is ready for you, the user community to kick the tires, and use for your development.  This is primarily a bug and stability milestone.  The one big addition is that Andmore now supports multi-dexing of the APK files.    Also, starting with the next Neon milestone, an Android Developers EPP package will be available.   This effort is being lead by the newest committer Kaloyan Raev.

Also this release of Andmore can be installed on older versions of Eclipse other than Mars.   There is also now an Eclipse Marketplace entry for the project as well to make installing the tooling even easier.



The latest version can always be obtained from the following p2 url:


Posted in android, eclipse, planetandroid | Tagged , | Leave a comment

Andmore 0.5-M2 Released

Screen Shot 2015-04-19 at 4.44.52 PM

The second stable milestone release is ready for you, the user community to kick the tires, and start to use for your development.  Thanks to several community members for fixes in this release.  The most important being that the Android XML Editor no longer tries to be the only XML editor in the system.  This should allow Andmore to play nicer with other plugins that you may be using.   Also the Database Perspective got some attention and when browsing a Database from a device you should no longer get an error dialog displayed. Full details can be found in the New and Noteworthy section for the release notes.

There is a p2 site for your installation needs, I haven’t had time yet to do a composite repository yet, but it is on the list.  In the mean time add the following update site to get the latest milestone release.


Add the above url to your available software sites.

It is recommended to get also get the latest m2e-android as well.  It adds some support to guarantee that source folders stay in the correct order and helps guarantee that other eclipse plugins work well with Andmore when using maven.

We are still waiting for some extension points from the Buildship project so that we can provide Gradle integration.

Thanks again the community members that provided patches.  It helps move the project forward.

Posted in android, eclipse | Tagged , | 1 Comment