Commit c16de85c authored by Petri Hintukainen's avatar Petri Hintukainen

BD-J: copy files to cache using libbluray (instead of Java native I/O)

parent be694bc5
...@@ -61,4 +61,11 @@ BD_PRIVATE extern BD_DIR_H* (*dir_open)(const char* dirname); ...@@ -61,4 +61,11 @@ BD_PRIVATE extern BD_DIR_H* (*dir_open)(const char* dirname);
BD_PRIVATE BD_DIR_OPEN dir_open_default(void); BD_PRIVATE BD_DIR_OPEN dir_open_default(void);
/*
* local filesystem
*/
BD_PRIVATE int file_unlink(const char *file);
#endif /* FILE_H_ */ #endif /* FILE_H_ */
...@@ -68,7 +68,6 @@ static int64_t file_read_linux(BD_FILE_H *file, uint8_t *buf, int64_t size) ...@@ -68,7 +68,6 @@ static int64_t file_read_linux(BD_FILE_H *file, uint8_t *buf, int64_t size)
return 0; return 0;
} }
#if 0
static int64_t file_write_linux(BD_FILE_H *file, const uint8_t *buf, int64_t size) static int64_t file_write_linux(BD_FILE_H *file, const uint8_t *buf, int64_t size)
{ {
if (size > 0 && size < BD_MAX_SSIZE) { if (size > 0 && size < BD_MAX_SSIZE) {
...@@ -78,7 +77,6 @@ static int64_t file_write_linux(BD_FILE_H *file, const uint8_t *buf, int64_t siz ...@@ -78,7 +77,6 @@ static int64_t file_write_linux(BD_FILE_H *file, const uint8_t *buf, int64_t siz
BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid write of size %"PRId64" (%p)\n", size, (void*)file); BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid write of size %"PRId64" (%p)\n", size, (void*)file);
return 0; return 0;
} }
#endif
static BD_FILE_H *file_open_linux(const char* filename, const char *mode) static BD_FILE_H *file_open_linux(const char* filename, const char *mode)
{ {
...@@ -89,7 +87,7 @@ static BD_FILE_H *file_open_linux(const char* filename, const char *mode) ...@@ -89,7 +87,7 @@ static BD_FILE_H *file_open_linux(const char* filename, const char *mode)
file->close = file_close_linux; file->close = file_close_linux;
file->seek = file_seek_linux; file->seek = file_seek_linux;
file->read = file_read_linux; file->read = file_read_linux;
//file->write = file_write_linux; file->write = file_write_linux;
file->tell = file_tell_linux; file->tell = file_tell_linux;
//file->eof = file_eof_linux; //file->eof = file_eof_linux;
...@@ -112,3 +110,8 @@ BD_FILE_OPEN file_open_default(void) ...@@ -112,3 +110,8 @@ BD_FILE_OPEN file_open_default(void)
{ {
return file_open_linux; return file_open_linux;
} }
int file_unlink(const char *file)
{
return remove(file);
}
...@@ -83,7 +83,6 @@ static int64_t _file_read(BD_FILE_H *file, uint8_t *buf, int64_t size) ...@@ -83,7 +83,6 @@ static int64_t _file_read(BD_FILE_H *file, uint8_t *buf, int64_t size)
return 0; return 0;
} }
#if 0
static int64_t _file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size) static int64_t _file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size)
{ {
if (size > 0 && size < BD_MAX_SSIZE) { if (size > 0 && size < BD_MAX_SSIZE) {
...@@ -93,7 +92,6 @@ static int64_t _file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size) ...@@ -93,7 +92,6 @@ static int64_t _file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size)
BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid write of size %"PRId64" (%p)\n", size, (void*)file); BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid write of size %"PRId64" (%p)\n", size, (void*)file);
return 0; return 0;
} }
#endif
static BD_FILE_H *_file_open(const char* filename, const char *mode) static BD_FILE_H *_file_open(const char* filename, const char *mode)
{ {
...@@ -109,7 +107,7 @@ static BD_FILE_H *_file_open(const char* filename, const char *mode) ...@@ -109,7 +107,7 @@ static BD_FILE_H *_file_open(const char* filename, const char *mode)
file->close = _file_close; file->close = _file_close;
file->seek = _file_seek; file->seek = _file_seek;
file->read = _file_read; file->read = _file_read;
//file->write = _file_write; file->write = _file_write;
file->tell = _file_tell; file->tell = _file_tell;
//file->eof = _file_eof; //file->eof = _file_eof;
...@@ -127,3 +125,11 @@ BD_FILE_OPEN file_open_default(void) ...@@ -127,3 +125,11 @@ BD_FILE_OPEN file_open_default(void)
{ {
return _file_open; return _file_open;
} }
int file_unlink(const char *file)
{
wchar_t wfile[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, file, -1, wfile, MAX_PATH);
return _wremove(wfile);
}
...@@ -323,6 +323,10 @@ public class Libbluray { ...@@ -323,6 +323,10 @@ public class Libbluray {
return getBdjoN(nativePointer, name + ".bdjo"); return getBdjoN(nativePointer, name + ".bdjo");
} }
public static boolean cacheBdRomFile(String path, String cachePath) {
return cacheBdRomFileN(nativePointer, path, cachePath) == 0;
}
public static void updateGraphic(int width, int height, int[] rgbArray) { public static void updateGraphic(int width, int height, int[] rgbArray) {
updateGraphicN(nativePointer, width, height, rgbArray, updateGraphicN(nativePointer, width, height, rgbArray,
0, 0, width - 1, height - 1); 0, 0, width - 1, height - 1);
...@@ -539,6 +543,7 @@ public class Libbluray { ...@@ -539,6 +543,7 @@ public class Libbluray {
private static native int readGPRN(long np, int num); private static native int readGPRN(long np, int num);
private static native int setVirtualPackageN(long np, String vpPath, boolean psrBackup); private static native int setVirtualPackageN(long np, String vpPath, boolean psrBackup);
private static native int readPSRN(long np, int num); private static native int readPSRN(long np, int num);
private static native int cacheBdRomFileN(long np, String path, String cachePath);
private static native Bdjo getBdjoN(long np, String name); private static native Bdjo getBdjoN(long np, String name);
private static native void updateGraphicN(long np, int width, int height, int[] rgbArray, private static native void updateGraphicN(long np, int width, int height, int[] rgbArray,
int x0, int y0, int x1, int y1); int x0, int y0, int x1, int y1);
......
...@@ -107,7 +107,7 @@ class VFSCache { ...@@ -107,7 +107,7 @@ class VFSCache {
boolean result = false; boolean result = false;
try { try {
inStream = new /*BD*/FileInputStream(srcPath); inStream = new FileInputStream(srcPath);
result = copyStream(inStream, dstPath); result = copyStream(inStream, dstPath);
} catch (IOException e) { } catch (IOException e) {
...@@ -137,8 +137,8 @@ class VFSCache { ...@@ -137,8 +137,8 @@ class VFSCache {
private void copyJarFile(String name) { private void copyJarFile(String name) {
/* copy file from BDMV/JAR/ */ /* copy file from BDMV/JAR/ */
String srcPath = vfsRoot + jarDir + name; String relPath = jarDir + name;
String dstPath = cacheRoot + jarDir + name; String dstPath = cacheRoot + relPath;
File dstFile = new File(dstPath); File dstFile = new File(dstPath);
if (dstFile.exists()) { if (dstFile.exists()) {
...@@ -146,9 +146,9 @@ class VFSCache { ...@@ -146,9 +146,9 @@ class VFSCache {
return; return;
} }
copyFile(srcPath, dstPath); Libbluray.cacheBdRomFile(relPath, dstPath);
logger.info("cached " + name); logger.info("cached " + relPath);
} }
private void copyJarDir(String name) { private void copyJarDir(String name) {
...@@ -190,15 +190,16 @@ class VFSCache { ...@@ -190,15 +190,16 @@ class VFSCache {
new File(fontRoot + fontDir).mkdirs(); new File(fontRoot + fontDir).mkdirs();
String srcPath = vfsRoot + fontDir + fontFile; String relPath = fontDir + fontFile;
String dstPath = fontRoot + fontDir + fontFile; String dstPath = fontRoot + relPath;
File dstFile = new File(dstPath); File dstFile = new File(dstPath);
if (dstFile.exists()) { if (dstFile.exists()) {
//logger.info(dstPath + " already cached"); //logger.info(dstPath + " already cached");
return dstFile; return dstFile;
} }
if (!copyFile(srcPath, dstPath)) { if (!Libbluray.cacheBdRomFile(relPath, dstPath)) {
return null; return null;
} }
......
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
#include "libbluray/bluray.h" #include "libbluray/bluray.h"
#include "libbluray/bluray_internal.h" #include "libbluray/bluray_internal.h"
#include "libbluray/decoders/overlay.h" #include "libbluray/decoders/overlay.h"
#include "libbluray/disc/disc.h"
#include "file/file.h"
#include "util/logging.h" #include "util/logging.h"
#include <string.h> #include <string.h>
...@@ -325,6 +327,35 @@ JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_readPSRN(JNIEnv * env, ...@@ -325,6 +327,35 @@ JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_readPSRN(JNIEnv * env,
return value; return value;
} }
JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_cacheBdRomFileN(JNIEnv * env,
jclass cls, jlong np,
jstring jrel_path, jstring jcache_path) {
BLURAY *bd = (BLURAY*)(intptr_t)np;
BD_DISC *disc = bd_get_disc(bd);
int result = -1;
const char *rel_path = (*env)->GetStringUTFChars(env, jrel_path, NULL);
const char *cache_path = (*env)->GetStringUTFChars(env, jcache_path, NULL);
if (!rel_path || !cache_path) {
BD_DEBUG(DBG_JNI | DBG_CRIT, "cacheBdRomFile() failed: no path\n");
goto out;
}
BD_DEBUG(DBG_JNI, "cacheBdRomFile(%s => %s)\n", rel_path, cache_path);
result = disc_cache_bdrom_file(disc, rel_path, cache_path);
out:
if (rel_path) {
(*env)->ReleaseStringUTFChars(env, jrel_path, rel_path);
}
if (cache_path) {
(*env)->ReleaseStringUTFChars(env, jcache_path, cache_path);
}
return result;
}
JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getBdjoN(JNIEnv * env, JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getBdjoN(JNIEnv * env,
jclass cls, jlong np, jstring jfile) { jclass cls, jlong np, jstring jfile) {
...@@ -569,6 +600,11 @@ Java_org_videolan_Libbluray_methods[] = ...@@ -569,6 +600,11 @@ Java_org_videolan_Libbluray_methods[] =
CC("(JI)I"), CC("(JI)I"),
VC(Java_org_videolan_Libbluray_readPSRN), VC(Java_org_videolan_Libbluray_readPSRN),
}, },
{
CC("cacheBdRomFileN"),
CC("(JLjava/lang/String;Ljava/lang/String;)I"),
VC(Java_org_videolan_Libbluray_cacheBdRomFileN),
},
{ {
CC("getBdjoN"), CC("getBdjoN"),
CC("(JLjava/lang/String;)Lorg/videolan/bdjo/Bdjo;"), CC("(JLjava/lang/String;)Lorg/videolan/bdjo/Bdjo;"),
......
...@@ -220,6 +220,14 @@ JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_readGPRN ...@@ -220,6 +220,14 @@ JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_readGPRN
JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_readPSRN JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_readPSRN
(JNIEnv *, jclass, jlong, jint); (JNIEnv *, jclass, jlong, jint);
/*
* Class: org_videolan_Libbluray
* Method: cacheBdRomFileN
* Signature: (JLjava/lang/String;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_cacheBdRomFileN
(JNIEnv *, jclass, jlong, jstring, jstring);
/* /*
* Class: org_videolan_Libbluray * Class: org_videolan_Libbluray
* Method: getBdjoN * Method: getBdjoN
......
...@@ -1084,6 +1084,13 @@ int bd_set_virtual_package(BLURAY *bd, const char *vp_path, int psr_init_backup) ...@@ -1084,6 +1084,13 @@ int bd_set_virtual_package(BLURAY *bd, const char *vp_path, int psr_init_backup)
} }
#endif #endif
#ifdef USING_BDJAVA
BD_DISC *bd_get_disc(BLURAY *bd)
{
return bd ? bd->disc : NULL;
}
#endif
#ifdef USING_BDJAVA #ifdef USING_BDJAVA
uint32_t bd_reg_read(BLURAY *bd, int psr, int reg) uint32_t bd_reg_read(BLURAY *bd, int psr, int reg)
{ {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <stdint.h> #include <stdint.h>
struct bluray; struct bluray;
struct bd_disc;
BD_PRIVATE const uint8_t *bd_get_aacs_data(struct bluray *bd, int type); BD_PRIVATE const uint8_t *bd_get_aacs_data(struct bluray *bd, int type);
...@@ -32,6 +33,8 @@ BD_PRIVATE const uint8_t *bd_get_aacs_data(struct bluray *bd, int type); ...@@ -32,6 +33,8 @@ BD_PRIVATE const uint8_t *bd_get_aacs_data(struct bluray *bd, int type);
* VFS * VFS
*/ */
BD_PRIVATE struct bd_disc *bd_get_disc(struct bluray *bd);
BD_PRIVATE int bd_set_virtual_package(struct bluray *bd, const char *vp_path, int psr_init_backup); BD_PRIVATE int bd_set_virtual_package(struct bluray *bd, const char *vp_path, int psr_init_backup);
/* /*
......
...@@ -398,6 +398,48 @@ void disc_update(BD_DISC *p, const char *overlay_root) ...@@ -398,6 +398,48 @@ void disc_update(BD_DISC *p, const char *overlay_root)
bd_mutex_unlock(&p->ovl_mutex); bd_mutex_unlock(&p->ovl_mutex);
} }
int disc_cache_bdrom_file(BD_DISC *p, const char *rel_path, const char *cache_path)
{
BD_FILE_H *fp_in;
BD_FILE_H *fp_out;
int64_t got;
/* input file from BD-ROM */
fp_in = p->pf_file_open_bdrom(p->fs_handle, rel_path);
if (!fp_in) {
BD_DEBUG(DBG_FILE | DBG_CRIT, "error caching file %s (does not exist ?)\n", rel_path);
return -1;
}
/* output file in local filesystem */
fp_out = file_open_default()(cache_path, "wb");
if (!fp_out) {
BD_DEBUG(DBG_FILE | DBG_CRIT, "error creating cache file %s\n", cache_path);
file_close(fp_in);
return -1;
}
while (1) {
uint8_t buf[16*2048];
got = file_read(fp_in, buf, sizeof(buf));
if (got <= 0) {
break;
}
if (fp_out->write(fp_out, buf, got) != got) {
BD_DEBUG(DBG_FILE | DBG_CRIT, "error caching file %s\n", rel_path);
file_close(fp_out);
file_close(fp_in);
file_unlink(cache_path);
return -1;
}
}
BD_DEBUG(DBG_FILE, "cached %s to %s\n", rel_path, cache_path);
file_close(fp_out);
file_close(fp_in);
return 0;
}
/* /*
* streams * streams
*/ */
......
...@@ -63,6 +63,8 @@ BD_PRIVATE int64_t disc_read_file(BD_DISC *disc, const char *dir, const char *fi ...@@ -63,6 +63,8 @@ BD_PRIVATE int64_t disc_read_file(BD_DISC *disc, const char *dir, const char *fi
/* Update virtual package */ /* Update virtual package */
BD_PRIVATE void disc_update(BD_DISC *disc, const char *overlay_root); BD_PRIVATE void disc_update(BD_DISC *disc, const char *overlay_root);
BD_PRIVATE int disc_cache_bdrom_file(BD_DISC *p, const char *rel_path, const char *cache_path);
/* /*
* m2ts stream interface * m2ts stream interface
*/ */
......
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