[Android] Add network caching option

Edward Wang git at videolan.org
Thu Aug 29 10:58:44 CEST 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Aug 29 10:57:32 2013 +0200| [02e5e52cdff0d4228914beaea8197290fd3f449f] | committer: Edward Wang

Add network caching option

Close #7792

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

 NEWS                                               |    3 ++-
 vlc-android/jni/libvlcjni.c                        |    9 +++++++
 vlc-android/res/values/strings.xml                 |    2 ++
 vlc-android/res/xml/preferences.xml                |    7 ++++++
 vlc-android/src/org/videolan/libvlc/LibVLC.java    |    9 +++++++
 vlc-android/src/org/videolan/vlc/Util.java         |    6 +++++
 .../org/videolan/vlc/gui/PreferencesActivity.java  |   25 +++++++++++++++++---
 7 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index df13c95..fa6e21a 100644
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,8 @@ Main Application:
  * Fix opening MRLs and video streaming
  * Fix many crashes and warnings
  * New equalizer
- * Option for frame skip to improve performance
+ * Add an option for frame skip to improve performance
+ * Add an option to set network caching
 
 
 Changes between 0.1.1 and 0.1.2:
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 3cf890d..524af24 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -229,6 +229,14 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
     snprintf(deblockstr, 2, "%d", deblocking);
     LOGD("Using deblocking level %d", deblocking);
 
+    methodId = (*env)->GetMethodID(env, cls, "getNetworkCaching", "()I");
+    int networkCaching = (*env)->CallIntMethod(env, thiz, methodId);
+    char networkCachingstr[25] = "0";
+    if(networkCaching > 0) {
+        snprintf(networkCachingstr, 25, "--network-caching=%d", networkCaching);
+        LOGD("Using network caching of %d ms", networkCaching);
+    }
+
     methodId = (*env)->GetMethodID(env, cls, "getChroma", "()Ljava/lang/String;");
     jstring chroma = (*env)->CallObjectMethod(env, thiz, methodId);
     const char *chromastr = (*env)->GetStringUTFChars(env, chroma, 0);
@@ -261,6 +269,7 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
         "--avcodec-skiploopfilter", deblockstr,
         "--avcodec-skip-frame", enable_frame_skip ? "4" : "0",
         "--avcodec-skip-idct", enable_frame_skip ? "4" : "0",
+        (networkCaching > 0) ? networkCachingstr : "",
         use_opensles ? "--aout=opensles" : "--aout=android_audiotrack",
         "--androidsurface-chroma", chromastr != NULL && chromastr[0] != 0 ? chromastr : "RV32",
     };
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index c1090ea..dd9851c 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -220,6 +220,8 @@
     <string name="aout_audiotrack">AudioTrack (native)</string>
     <string name="aout_audiotrack_java">AudioTrack (Java)</string>
     <string name="aout_opensles">OpenSL ES</string>
+    <string name="network_caching">Network caching value</string>
+    <string name="network_caching_summary">The amount of time to buffer network media (in ms). Does not work with hardware decoding. Leave blank to reset.</string>
     <string name="enable_verbose_mode">Verbose</string>
     <string name="enable_verbose_mode_summary">Increase the verbosity (logcat)</string>
     <string name="set_locale">Set locale</string>
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index 342931f..7bfb556 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -102,6 +102,13 @@
                 android:title="@string/aout" />
 
             <EditTextPreference
+                android:key="network_caching"
+                android:summary="@string/network_caching_summary"
+                android:title="@string/network_caching"
+                android:defaultValue=""
+                android:maxLength="5" />
+
+            <EditTextPreference
                 android:defaultValue=""
                 android:key="set_locale"
                 android:summary="@string/set_locale_detail"
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index 25aa12e..96b3b3a 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -64,6 +64,7 @@ public class LibVLC {
     private boolean verboseMode = true;
     private float[] equalizer = null;
     private boolean frameSkip = false;
+    private int networkCaching = 0;
 
     /** Check in libVLC already initialized otherwise crash */
     private boolean mIsInitialized = false;
@@ -313,6 +314,14 @@ public class LibVLC {
         this.frameSkip = frameskip;
     }
 
+    public int getNetworkCaching() {
+        return this.networkCaching;
+    }
+
+    public void setNetworkCaching(int networkcaching) {
+        this.networkCaching = networkcaching;
+    }
+
     /**
      * Initialize the libVLC class
      */
diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index 34d2e69..7a1d98b 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -138,8 +138,14 @@ public class Util {
         catch(NumberFormatException nfe) {
             deblocking = -1;
         }
+        int networkCaching = pref.getInt("network_caching_value", 0);
+        if(networkCaching > 60000)
+            networkCaching = 60000;
+        else if(networkCaching < 0)
+            networkCaching = 0;
         instance.setAout(aout);
         instance.setDeblocking(deblocking);
+        instance.setNetworkCaching(networkCaching);
     }
 
     /** Print an on-screen message to alert the user */
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 7e2d735..d3b8d72 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -192,6 +192,24 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                 return true;
             }
         });
+        // Network caching
+        EditTextPreference networkCachingPref = (EditTextPreference) findPreference("network_caching");
+        networkCachingPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(PreferencesActivity.this);
+                SharedPreferences.Editor editor = sharedPrefs.edit();
+                try {
+                    editor.putInt("network_caching_value", Integer.parseInt((String)newValue));
+                } catch(NumberFormatException e) {
+                    editor.putInt("network_caching_value", 0);
+                    editor.putString("network_caching", "0");
+                }
+                editor.commit();
+                return true;
+            }
+        });
 
         /*** SharedPreferences Listener to apply changes ***/
         SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
@@ -203,11 +221,12 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
         if(key.equalsIgnoreCase("enable_iomx")
                 || key.equalsIgnoreCase("subtitles_text_encoding")
                 || key.equalsIgnoreCase("aout")
+                || key.equalsIgnoreCase("chroma_format")
+                || key.equalsIgnoreCase("deblocking")
                 || key.equalsIgnoreCase("enable_frame_skip")
                 || key.equalsIgnoreCase("enable_time_stretching_audio")
-                || key.equalsIgnoreCase("deblocking")
-                || key.equalsIgnoreCase("chroma_format")
-                || key.equalsIgnoreCase("enable_verbose_mode")) {
+                || key.equalsIgnoreCase("enable_verbose_mode")
+                || key.equalsIgnoreCase("network_caching")) {
             Util.updateLibVlcSettings(sharedPreferences);
             LibVLC.restart(this);
         }



More information about the Android mailing list