[Android] allow to select chroma (RV32/RV16/YV12)

Sébastien Toque git at videolan.org
Fri Feb 8 00:33:08 CET 2013


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Wed Feb  6 17:34:06 2013 +0100| [a19a8e0e134d5ea6a380f33bba4a8d59f6b30452] | committer: Sébastien Toque

allow to select chroma (RV32/RV16/YV12)

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=a19a8e0e134d5ea6a380f33bba4a8d59f6b30452
---

 vlc-android/jni/libvlcjni.c                                |   10 ++++++----
 vlc-android/res/values-fr/strings.xml                      |    4 ++--
 vlc-android/res/values/strings.xml                         |   10 ++++++++--
 vlc-android/res/xml/preferences.xml                        |   12 +++++++-----
 vlc-android/src/org/videolan/vlc/LibVLC.java               |    5 +++--
 .../src/org/videolan/vlc/gui/PreferencesActivity.java      |    2 +-
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java    |   10 +++++++++-
 7 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 68b937f..bf5d06e 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -407,13 +407,14 @@ void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean
     methodId = (*env)->GetMethodID(env, cls, "timeStretchingEnabled", "()Z");
     bool enable_time_stretch = (*env)->CallBooleanMethod(env, thiz, methodId);
 
-    methodId = (*env)->GetMethodID(env, cls, "yv12Enabled", "()Z");
-    bool yv12enabled = (*env)->CallBooleanMethod(env, thiz, methodId);
+    methodId = (*env)->GetMethodID(env, cls, "getChroma", "()Ljava/lang/String;");
+    jstring chroma = (*env)->CallObjectMethod(env, thiz, methodId);
+    const char *chromastr = (*env)->GetStringUTFChars(env, chroma, 0);
+    LOGD("Chroma set to \"%s\"", chromastr);
 
     methodId = (*env)->GetMethodID(env, cls, "getSubtitlesEncoding", "()Ljava/lang/String;");
     jstring subsencoding = (*env)->CallObjectMethod(env, thiz, methodId);
     const char *subsencodingstr = (*env)->GetStringUTFChars(env, subsencoding, 0);
-
     LOGD("Subtitle encoding set to \"%s\"", subsencodingstr);
 
     verbosity = verbose;
@@ -432,12 +433,13 @@ void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean
         "--subsdec-encoding", subsencodingstr,
         enable_time_stretch ? "--audio-time-stretch" : "--no-audio-time-stretch",
         use_opensles ? "--aout=opensles" : "--aout=android_audiotrack",
-        yv12enabled ? "--androidsurface-chroma=YV12" : "--androidsurface-chroma=RV32",
+        "--androidsurface-chroma", chromastr != NULL && chromastr[0] != 0 ? chromastr : "RV32",
     };
     libvlc_instance_t *instance = libvlc_new(sizeof(argv) / sizeof(*argv), argv);
 
     setLong(env, thiz, "mLibVlcInstance", (jlong)(intptr_t) instance);
 
+    (*env)->ReleaseStringUTFChars(env, chroma, chromastr);
     (*env)->ReleaseStringUTFChars(env, subsencoding, subsencodingstr);
 
     if (!instance)
diff --git a/vlc-android/res/values-fr/strings.xml b/vlc-android/res/values-fr/strings.xml
index 7c6467c..de2c47a 100644
--- a/vlc-android/res/values-fr/strings.xml
+++ b/vlc-android/res/values-fr/strings.xml
@@ -144,8 +144,8 @@
     <string name="set_locale">Définir la langue</string>
     <string name="set_locale_detail">Laisser vide pour réinitialiser</string>
     <string name="set_locale_popup">Quitter et relancer VLC pour appliquer la langue.</string>
-    <string name="enable_yv12_format">Forcer le format YV12</string>
-    <string name="enable_yv12_format_detail">NE PAS ACTIVER!!! Ne fonctionne pas sur tous les appareils. Android 2.3 et supérieur uniquement.</string>
+    <string name="chroma_format">Forcer le chroma</string>
+    <string name="chroma_format_detail">NE PAS ACTIVER!!! Ne fonctionne pas sur tous les appareils. Android 2.3 et supérieur uniquement.</string>
     <string name="detect_headset">Détecter le casque</string>
     <string name="detect_headset_detail">Pause lors du débranchement du casque, Reprise lors du branchement du casque</string>
     <string name="steal_remote_control">Contrôle exclusif de la télécommande</string>
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 94c1795..ef2f877 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -165,8 +165,8 @@
     <string name="set_locale">Set locale</string>
     <string name="set_locale_detail">Leave blank to reset</string>
     <string name="set_locale_popup">Quit and reset VLC for changes to take effect.</string>
-    <string name="enable_yv12_format">Force YV12 format</string>
-    <string name="enable_yv12_format_detail">DO NOT ACTIVATE!!! May not work with all devices. 2.3 and later only.</string>
+    <string name="chroma_format">Force chroma</string>
+    <string name="chroma_format_detail">DO NOT ACTIVATE!!! May not work with all devices. 2.3 and later only.</string>
     <string name="detect_headset">Detect headset</string>
     <string name="detect_headset_detail">Pause on headset removed; resume on headset inserted</string>
     <string name="steal_remote_control">Exclusive headset remote control</string>
@@ -316,4 +316,10 @@
         <item>2</item>
     </string-array>
 
+    <string-array name="chroma_formats" translatable="false">
+        <item>RV32</item>
+        <item>RV16</item>
+        <item>YV12</item>
+    </string-array>
+
 </resources>
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index 4a77ecc..c670852 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -85,11 +85,13 @@
                 android:summary="@string/set_locale_detail"
                 android:key="set_locale"
                 android:defaultValue="" />
-            <CheckBoxPreference
-                android:defaultValue="false"
-                android:key="enable_yv12_format"
-                android:summary="@string/enable_yv12_format_detail"
-                android:title="@string/enable_yv12_format" />
+            <ListPreference
+                android:defaultValue=""
+                android:key="chroma_format"
+                android:title="@string/chroma_format"
+                android:summary="@string/chroma_format_detail"
+                android:entries="@array/chroma_formats"
+                android:entryValues="@array/chroma_formats" />
         </PreferenceScreen>
     </PreferenceCategory>
 
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index e89caf1..ceeae5c 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -180,9 +180,10 @@ public class LibVLC {
         final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
         return p.getBoolean("enable_time_stretching_audio", false);
     }
-    public boolean yv12Enabled() {
+    public String getChroma() {
         final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
-        return (p.getBoolean("enable_yv12_format", false) && Util.isGingerbreadOrLater());
+        String chroma = p.getString("chroma_format", "");
+        return chroma.equals("YV12") && !Util.isGingerbreadOrLater() ? "" : chroma;
     }
 
     /**
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index cf34390..f4be4d7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -208,7 +208,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
             key.equalsIgnoreCase("subtitles_text_encoding") ||
             key.equalsIgnoreCase("aout") ||
             key.equalsIgnoreCase("enable_time_stretching_audio") ||
-            key.equalsIgnoreCase("enable_yv12_format")) {
+            key.equalsIgnoreCase("chroma_format")) {
                 LibVLC.restart();
         }
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 26d4c7b..bc66a0d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -260,9 +260,15 @@ public class VideoPlayerActivity extends Activity {
         mSurfaceHolder = mSurface.getHolder();
         mSurfaceFrame = (FrameLayout) findViewById(R.id.player_surface_frame);
         int pitch;
-        if(Util.isGingerbreadOrLater() && pref.getBoolean("enable_yv12_format", false)) {
+        String chroma = pref.getString("chroma_format", "");
+        if(Util.isGingerbreadOrLater() && chroma.equals("YV12")) {
             mSurfaceHolder.setFormat(ImageFormat.YV12);
             pitch = ImageFormat.getBitsPerPixel(ImageFormat.YV12) / 8;
+        } else if (chroma.equals("RV16")) {
+            mSurfaceHolder.setFormat(PixelFormat.RGB_565);
+            PixelFormat info = new PixelFormat();
+            PixelFormat.getPixelFormatInfo(PixelFormat.RGB_565, info);
+            pitch = info.bytesPerPixel;
         } else {
             mSurfaceHolder.setFormat(PixelFormat.RGBX_8888);
             PixelFormat info = new PixelFormat();
@@ -1109,6 +1115,8 @@ public class VideoPlayerActivity extends Activity {
         public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
             if(format == PixelFormat.RGBX_8888)
                 Log.d(TAG, "Pixel format is RGBX_8888");
+            else if(format == PixelFormat.RGB_565)
+                Log.d(TAG, "Pixel format is RGB_565");
             else if(format == ImageFormat.YV12)
                 Log.d(TAG, "Pixel format is YV12");
             else



More information about the Android mailing list