[libbluray-devel] [PATCH] Add the possibility to set the persistent/cache root path via bd_set_player_setting_str().
Petri Hintukainen
phintuka at users.sourceforge.net
Fri Sep 26 12:27:56 CEST 2014
On ma, 2014-09-22 at 10:21 +0200, Andreas Zelend wrote:
> From 72b9bb8c2c20e7e2080e16c3129e73fb7acf9933 Mon Sep 17 00:00:00 2001
> From: ace20022 <ace20022 at ymail.com>
> Date: Fri, 19 Sep 2014 16:00:06 +0200
> Subject: [PATCH 1/2] Add the possibility to set the persistent/cache
> root path
> via bd_set_player_setting_str().
>
> ---
> src/examples/bdj_test.c | 5 ++++-
> src/libbluray/bdj/bdj.c | 34 +++++++++++++++++++++++-----------
> src/libbluray/bdj/bdj.h | 8 +++++++-
> src/libbluray/bluray.c | 43
> ++++++++++++++++++++++++++++++++++++++++++-
> src/libbluray/bluray.h | 2 ++
> 5 files changed, 78 insertions(+), 14 deletions(-)
>
> diff --git a/src/examples/bdj_test.c b/src/examples/bdj_test.c
> index d9ebd16..b258562 100644
> --- a/src/examples/bdj_test.c
> +++ b/src/examples/bdj_test.c
> @@ -31,6 +31,7 @@
> #include <unistd.h>
>
> #include "libbluray/bluray.h"
> +#include "file/dirs.h"
>
> #if defined(_WIN32)
> #include <windows.h>
> @@ -53,7 +54,9 @@ int main(int argc, char** argv)
> BLURAY* bd = bd_open(argv[1], NULL);
>
> bd_get_titles(bd, TITLES_ALL, 0);
> -
> +
> + bd_set_player_setting_str(bd, BLURAY_PLAYER_PERSISTENT_ROOT,
> file_get_data_home());
> + bd_set_player_setting_str(bd, BLURAY_PLAYER_CACHE_ROOT,
> file_get_cache_home());
file_*() functions are library internal and can't be used in
applications. Linking bdj_test fails:
bdj_test.c:58: undefined reference to `file_get_data_home'
bdj_test.c:59: undefined reference to `file_get_cache_home'
Also note that those two directories must be different (I think in
Windows data and cache home are mapped to the same location).
> if (!bd_start_bdj(bd, argv[2])) {
> printf("Failed to start BD-J application.\n");
> } else {
> diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
> index c54e7ee..b250aa0 100644
> --- a/src/libbluray/bdj/bdj.c
> +++ b/src/libbluray/bdj/bdj.c
> @@ -155,10 +155,10 @@ static void *_load_jvm(const char **p_java_home)
> static const char jvm_lib[] = "jvm";
> # else
> static const char *jvm_path[] = {NULL, JDK_HOME,
> - "/usr/lib/jvm/default-java",
> - "/usr/lib/jvm/java-6-openjdk",
> - "/usr/lib/jvm/java-7-openjdk",
> -
> "/etc/java-config-2/current-system-vm"};
> + "/usr/lib/jvm/default-java",
> + "/usr/lib/jvm/java-6-openjdk",
> + "/usr/lib/jvm/java-7-openjdk",
> + "/etc/java-config-2/current-system-vm"};
> static const char jvm_dir[] = "jre/lib/" JAVA_ARCH "/server";
> static const char jvm_lib[] = "libjvm";
> # endif
Unrelated change
> @@ -254,7 +254,7 @@ static const char *_find_libbluray_jar(void)
> return classpath;
> }
>
> -static const char *_bdj_persistent_root(void)
> +static const char *_bdj_persistent_root(BDJ_STORAGE *storage)
> {
> static const char *root = NULL;
>
> @@ -262,6 +262,12 @@ static const char *_bdj_persistent_root(void)
> return root;
> }
>
> + if (storage) {
> + root = storage->persistent_root;
> + if (root)
> + return root;
> + }
> +
> root = getenv("LIBBLURAY_PERSISTENT_ROOT");
> if (root) {
> return root;
There's problem with assigning the pointer to
static const char *root;
The string is allocated in bd_set_player_setting_str() and freed in
bd_close(). When playing second disc, it will use already freed pointer.
Maybe just
if (storage && storage->persistent_root) {
return storage->persistent_root;
}
> @@ -278,7 +284,7 @@ static const char *_bdj_persistent_root(void)
> return root;
> }
>
> -static const char *_bdj_buda_root(void)
> +static const char *_bdj_buda_root(BDJ_STORAGE *storage)
> {
> static const char *root = NULL;
>
> @@ -286,6 +292,12 @@ static const char *_bdj_buda_root(void)
> return root;
> }
>
> + if (storage) {
> + root = storage->cache_root;
> + if (root)
> + return root;
> + }
> +
> root = getenv("LIBBLURAY_CACHE_ROOT");
> if (root) {
> return root;
Same here.
> @@ -383,7 +395,7 @@ static int _find_jvm(void *jvm_lib, JNIEnv **env,
> JavaVM **jvm)
> return 0;
> }
>
> -static int _create_jvm(void *jvm_lib, const char *java_home, JNIEnv
> **env, JavaVM **jvm)
> +static int _create_jvm(void *jvm_lib, const char *java_home, JNIEnv
> **env, JavaVM **jvm, BDJ_STORAGE *storage)
> {
> (void)java_home; /* used only with J2ME */
>
> @@ -396,8 +408,8 @@ static int _create_jvm(void *jvm_lib, const char
> *java_home, JNIEnv **env, JavaV
> JavaVMOption* option = calloc(1, sizeof(JavaVMOption) * 20);
> int n = 0;
> JavaVMInitArgs args;
> - option[n++].optionString = str_printf("-Ddvb.persistent.root=%s",
> _bdj_persistent_root());
> - option[n++].optionString = str_printf("-Dbluray.bindingunit.root=
> %s", _bdj_buda_root());
> + option[n++].optionString = str_printf("-Ddvb.persistent.root=%s",
> _bdj_persistent_root(storage));
> + option[n++].optionString = str_printf("-Dbluray.bindingunit.root=
> %s", _bdj_buda_root(storage));
>
> option[n++].optionString = str_dup
> ("-Dawt.toolkit=java.awt.BDToolkit");
> option[n++].optionString = str_dup
> ("-Djava.awt.graphicsenv=java.awt.BDGraphicsEnvironment");
> @@ -452,7 +464,7 @@ static int _create_jvm(void *jvm_lib, const char
> *java_home, JNIEnv **env, JavaV
> }
>
> BDJAVA* bdj_open(const char *path, struct bluray *bd,
> - bdj_overlay_cb osd_cb, struct bd_argb_buffer_s *buf)
> + bdj_overlay_cb osd_cb, struct bd_argb_buffer_s *buf,
> BDJ_STORAGE *storage)
> {
> BD_DEBUG(DBG_BDJ, "bdj_open()\n");
>
> @@ -467,7 +479,7 @@ BDJAVA* bdj_open(const char *path, struct bluray
> *bd,
>
> JNIEnv* env = NULL;
> JavaVM *jvm = NULL;
> - if (!_find_jvm(jvm_lib, &env, &jvm) && !_create_jvm(jvm_lib,
> java_home, &env, &jvm)) {
> + if (!_find_jvm(jvm_lib, &env, &jvm) && !_create_jvm(jvm_lib,
> java_home, &env, &jvm, storage)) {
> dl_dlclose(jvm_lib);
> return NULL;
> }
> diff --git a/src/libbluray/bdj/bdj.h b/src/libbluray/bdj/bdj.h
> index a177510..721c02f 100644
> --- a/src/libbluray/bdj/bdj.h
> +++ b/src/libbluray/bdj/bdj.h
> @@ -42,6 +42,11 @@ typedef enum {
> BDJ_EVENT_RATE,
> } BDJ_EVENT;
>
> +typedef struct {
> + char *persistent_root;
> + char *cache_root;
> +} BDJ_STORAGE;
> +
> /* bdj_get_uo_mask() */
> #define BDJ_MENU_CALL_MASK 0x01
> #define BDJ_TITLE_SEARCH_MASK 0x02
> @@ -55,7 +60,8 @@ typedef void (*bdj_overlay_cb)(struct bluray *,
> const unsigned *, int, int,
> int, int, int, int);
>
> BD_PRIVATE BDJAVA* bdj_open(const char *path, struct bluray *bd,
> - bdj_overlay_cb osd_cb, struct
> bd_argb_buffer_s *buf);
> + bdj_overlay_cb osd_cb, struct
> bd_argb_buffer_s *buf,
> + BDJ_STORAGE *storage);
> BD_PRIVATE void bdj_close(BDJAVA *bdjava);
> BD_PRIVATE int bdj_process_event(BDJAVA *bdjava, unsigned ev,
> unsigned param);
> BD_PRIVATE int bdj_get_uo_mask(BDJAVA *bdjava);
> diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
> index 320f009..efca0c4 100644
> --- a/src/libbluray/bluray.c
> +++ b/src/libbluray/bluray.c
> @@ -159,6 +159,7 @@ struct bluray {
> uint8_t hdmv_suspended;
> #ifdef USING_BDJAVA
> BDJAVA *bdjava;
> + BDJ_STORAGE *bdjstorage;
> #endif
> /* delayed sending of BDJ_EVENT_END_OF_PLAYLIST:
> * 1 - message pending. 3 - message sent. */
> @@ -1236,7 +1237,7 @@ static int _start_bdj(BLURAY *bd, unsigned
> title)
> {
> #ifdef USING_BDJAVA
> if (bd->bdjava == NULL) {
> - bd->bdjava = bdj_open(bd->device_path, bd, _bdj_osd_cb,
> bd->argb_buffer);
> + bd->bdjava = bdj_open(bd->device_path, bd, _bdj_osd_cb,
> bd->argb_buffer, bd->bdjstorage);
> if (!bd->bdjava) {
> return 0;
> }
> @@ -1283,6 +1284,19 @@ static void _close_bdj(BLURAY *bd)
> #define _close_bdj(bd) do{}while(0)
> #endif
>
> +#ifdef USING_BDJAVA
> +static void _storage_free(BLURAY *bd)
> +{
> + if (bd->bdjstorage){
> + X_FREE(bd->bdjstorage->cache_root);
> + X_FREE(bd->bdjstorage->persistent_root);
> + X_FREE(bd->bdjstorage);
> + }
> +}
> +#else
> +#define _storage_free(bd) do{}while(0)
> +#endif
> +
> #ifdef HAVE_MNTENT_H
> /*
> * Replace device node (/dev/sr0) by mount point
> @@ -1423,6 +1437,7 @@ void bd_close(BLURAY *bd)
> _free_event_queue(bd);
> X_FREE(bd->device_path);
> array_free((void**)&bd->titles);
> + _storage_free(bd);
>
> bd_mutex_destroy(&bd->mutex);
>
> @@ -2588,6 +2603,32 @@ int bd_set_player_setting_str(BLURAY *bd,
> uint32_t idx, const char *s)
> case BLURAY_PLAYER_SETTING_COUNTRY_CODE:
> return bd_set_player_setting(bd, idx, str_to_uint32(s,
> 2));
>
> +#ifdef USING_BDJAVA
> + case BLURAY_PLAYER_CACHE_ROOT:
> + case BLURAY_PLAYER_PERSISTENT_ROOT:
> + if (!bd->bdjstorage) {
> + bd->bdjstorage = malloc(sizeof(BDJ_STORAGE*));
Use calloc() or initialize to zero
(nothing guarantees both strings are set by the app)
> + }
> + switch (idx) {
> + case BLURAY_PLAYER_CACHE_ROOT:
> + if (bd->bdjstorage) {
> + bd->bdjstorage->cache_root = str_dup(s);
This will leak memory if already set
> + BD_DEBUG(DBG_BDJ, "Cache root dir set to %s\n",
> bd->bdjstorage->cache_root);
> + return 1;
> + }
> + else
> + return 0;
> +
> + case BLURAY_PLAYER_PERSISTENT_ROOT:
> + if (bd->bdjstorage) {
> + bd->bdjstorage->persistent_root = str_dup(s);
Same
> + BD_DEBUG(DBG_BDJ, "Persistent root dir set to %s\n",
> bd->bdjstorage->persistent_root);
> + return 1;
> + }
> + else
> + return 0;
> + }
> +#endif /* USING_BDJAVA */
> default:
> return 0;
> }
> diff --git a/src/libbluray/bluray.h b/src/libbluray/bluray.h
> index 54f4df7..7e991df 100644
> --- a/src/libbluray/bluray.h
> +++ b/src/libbluray/bluray.h
> @@ -561,6 +561,8 @@ typedef enum {
> BLURAY_PLAYER_SETTING_PLAYER_PROFILE = 31, /* Profile1: 0,
> Profile1+: 1, Profile2: 3, Profile3: 8 */
>
> BLURAY_PLAYER_SETTING_DECODE_PG = 0x100, /* enable/disable
> PG (subtitle) decoder */
> + BLURAY_PLAYER_PERSISTENT_ROOT = 400, /* Root path
> (string) to the BD_J persistent storage location */
> + BLURAY_PLAYER_CACHE_ROOT = 401, /* Root path
> (string) to the BD_J cache storage location */
> } bd_player_setting;
>
> /**
More information about the libbluray-devel
mailing list