Commit a45c0972 authored by Edward Wang's avatar Edward Wang

Optimize the DirectoryAdapter a bit by not precaching if there are more than 6 subitems

parent a62f1194
......@@ -18,8 +18,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <dirent.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <vlc/vlc.h>
#include <vlc_common.h>
......@@ -945,3 +948,33 @@ jint Java_org_videolan_vlc_LibVLC_setSpuTrack(JNIEnv *env, jobject thiz, jint in
return libvlc_video_set_spu(mp, index);
return -1;
}
jint Java_org_videolan_vlc_LibVLC_nativeCountDirectoryContents(JNIEnv *env, jobject thiz, jstring path)
{
jboolean isCopy;
/* Get C string */
const char* psz_path = (*env)->GetStringUTFChars(env, path, &isCopy);
jint childrenCount = 0;
DIR* p_dir = opendir(psz_path);
if(!p_dir)
return 0;
struct dirent* p_dirent;
while(1) {
errno = 0;
p_dirent = readdir(p_dir);
if(p_dirent == NULL) {
if(errno > 0) /* error reading this entry */
continue;
else if(errno == 0) /* end of stream */
break;
}
childrenCount++;
}
closedir(p_dir);
/* Clean up */
(*env)->ReleaseStringUTFChars(env, path, psz_path);
return childrenCount;
}
......@@ -408,6 +408,8 @@ public class LibVLC {
public native String nativeToURI(String path);
public native int nativeCountDirectoryContents(String path);
/**
* Return the length of the stream, in milliseconds
*/
......
......@@ -151,10 +151,12 @@ public class DirectoryAdapter extends BaseAdapter {
if(files[i].isFile())
nss.setIsFile();
/*String mCurrentDir_old = mCurrentDir;
mCurrentDir = MRL;
this.populateNode(nss, MRL + "/" + nss.name);
mCurrentDir = mCurrentDir_old;*/
if(nss.isFile() && LibVLC.getExistingInstance().nativeCountDirectoryContents(MRL + "/" + nss.name) < 6) {
String mCurrentDir_old = mCurrentDir;
mCurrentDir = MRL;
this.populateNode(nss, MRL + "/" + nss.name);
mCurrentDir = mCurrentDir_old;
}
n.children.add(nss);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment