title: Why is GStreamer playback suffering when using an APK from a Xamarin Android application?
body: <p>I'm trying to get a sample application provided by the media streaming framework Gstreamer to work as a Xamarin Android application. The application plays and displays an RTSP stream. To do so, I took the sample Android application (Java-based, with some C++ interop) from here: <a href="https://github.com/centricular/android_rtsp_example" rel="nofollow noreferrer">https://github.com/centricular/android_rtsp_example</a> and built it as an AAR file in Android studio (as described here <a href="https://developer.android.com/studio/projects/android-library" rel="nofollow noreferrer">https://developer.android.com/studio/projects/android-library</a>). </p>
  
  <p>I then referenced the AAR file from my Xamarin application as described here: <a href="https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar</a>. </p>
  
  <p>I then went into my AndroidManifest.xml file for the Xamarin application and specified the Activity that came along with the AAR file as my main activity. Doing all of this, as far as I know, I should basically have something that's essentially the same as the original APK built from Android Studio in pure Java, but running in the Xamarin framework. So far, so good. Everything built and deployed. The app started up and ran just like it did when built from Android Studio except for one thing: the playback was very, very slow and choppy, with a lot of compression artifacts. This was NOT the case when running the same code/pipeline from the non-Xamarin application. My question is, what could cause this? Did I do something dumb when trying to wrap this APK in Xamarin and launch it? Did I fail to turn on some hardware acceleration that is enabled in the APK that's not enabled in the Xamarin app? Some aspect of playback is worse when wrapped in Xamarin, but I'm not sure exactly what it could be. </p>
  
  <p>Ultimately the way in which the GStreamer application is drawing in Android isn't understood by me, but I know the actual drawing code is implemented in C++ and there's a Java/C++ interoperability layer that's involved (JNI_OnLoad and RegisterNatives is involved). So, it could be that something is no longer accelerated on the hardware, but I'm unsure how that could be. </p>
  
  <p>So in summary: </p>
  
  <ul>
  <li>Existing APK can be built and ran on an Android phone. It plays an RTSP stream very well, with no jitter or compression artifacts. </li>
  <li>Building the APK as an AAR and referencing it from Xamarin, I'm able to get the player to launch just as it did when built as an APK. Button taps, etc. work and the video player shows and connects to the RTSP stream. </li>
  <li>Performance is much, much poorer in the Xamarin application, with severe jitter, data loss and compression artifacts showing up in the visual window. </li>
  <li>Other than build settings (for example, to produce an AAR instead of an APK from Android Studio) and modifying the AndroidManifest.xml file, no code changes were made (See below for my AndroidManifest.xml file). </li>
  </ul>
  
  <p>Any thoughts or feedback?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.XamarinGstreamerTestAndroid" android:installLocation="auto"&gt;
      &lt;uses-sdk android:minSdkVersion="21" android:targetSdkVersion="25" /&gt;
      &lt;application android:allowBackup="true" 
                 android:icon="@mipmap/ic_launcher" 
                android:label="@string/button_play" 
                android:roundIcon="@mipmap/ic_launcher_round" 
                android:supportsRtl="true" 
                android:theme="@style/AppTheme"&gt;
                &lt;/application&gt;
          &lt;activity android:name=".RTSPExample"
                    android:label="@string/app_name"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  &lt;/manifest&gt;
  </code></pre>