[libbluray-devel] Remove static storage path variables from bdj.c

hpi1 git at videolan.org
Wed Jan 7 12:06:22 CET 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Jan  7 12:22:17 2015 +0200| [882c5a46ec43264aa9f8ed0962f0556708ca6452] | committer: hpi1

Remove static storage path variables from bdj.c

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=882c5a46ec43264aa9f8ed0962f0556708ca6452
---

 src/libbluray/bdj/bdj.c |   28 ++++++++++------------------
 src/libbluray/bluray.c  |   33 ++++++++++++++-------------------
 2 files changed, 24 insertions(+), 37 deletions(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 565eefa..aed4174 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -263,16 +263,12 @@ static const char *_find_libbluray_jar(void)
 
 static const char *_bdj_persistent_root(BDJ_STORAGE *storage)
 {
-    static const char *root = NULL;
+    const char *root;
 
-    if (storage && storage->persistent_root) {
+    if (storage->persistent_root) {
         return storage->persistent_root;
     }
 
-    if (root) {
-        return root;
-    }
-
     root = getenv("LIBBLURAY_PERSISTENT_ROOT");
     if (root) {
         return root;
@@ -282,25 +278,21 @@ static const char *_bdj_persistent_root(BDJ_STORAGE *storage)
     if (!root) {
         root = "";
     }
-    root = str_printf("%s/bluray/dvb.persistent.root/", root);
+        storage->persistent_root = str_printf("%s/bluray/dvb.persistent.root/", root);
 
-    BD_DEBUG(DBG_BDJ, "LIBBLURAY_PERSISTENT_ROOT not set, using %s\n", root);
+        BD_DEBUG(DBG_BDJ, "LIBBLURAY_PERSISTENT_ROOT not set, using %s\n", storage->persistent_root);
 
-    return root;
+    return storage->persistent_root;
 }
 
 static const char *_bdj_buda_root(BDJ_STORAGE *storage)
 {
-    static const char *root = NULL;
+    const char *root;
 
-    if (storage && storage->cache_root) {
+    if (storage->cache_root) {
         return storage->cache_root;
     }
 
-    if (root) {
-        return root;
-    }
-
     root = getenv("LIBBLURAY_CACHE_ROOT");
     if (root) {
         return root;
@@ -310,11 +302,11 @@ static const char *_bdj_buda_root(BDJ_STORAGE *storage)
     if (!root) {
         root = "";
     }
-    root = str_printf("%s/bluray/bluray.bindingunit.root/", root);
+        storage->cache_root = str_printf("%s/bluray/bluray.bindingunit.root/", root);
 
-    BD_DEBUG(DBG_BDJ, "LIBBLURAY_CACHE_ROOT not set, using %s\n", root);
+        BD_DEBUG(DBG_BDJ, "LIBBLURAY_CACHE_ROOT not set, using %s\n", storage->cache_root);
 
-    return root;
+    return storage->cache_root;
 }
 
 static int _get_method(JNIEnv *env, jclass *cls, jmethodID *method_id,
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 6924f55..a507a04 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -151,7 +151,7 @@ struct bluray {
     uint8_t        hdmv_suspended;
 #ifdef USING_BDJAVA
     BDJAVA         *bdjava;
-    BDJ_STORAGE    *bdjstorage;
+    BDJ_STORAGE     bdjstorage;
 #endif
     /* delayed sending of BDJ_EVENT_END_OF_PLAYLIST:
      * 1 - message pending. 3 - message sent. */
@@ -1271,7 +1271,7 @@ static int _start_bdj(BLURAY *bd, unsigned title)
 {
 #ifdef USING_BDJAVA
     if (bd->bdjava == NULL) {
-        bd->bdjava = bdj_open(bd->device_path, bd, bd->disc_info.bdj_disc_id, bd->bdjstorage);
+        bd->bdjava = bdj_open(bd->device_path, bd, bd->disc_info.bdj_disc_id, &bd->bdjstorage);
         if (!bd->bdjava) {
             return 0;
         }
@@ -1326,11 +1326,8 @@ static void _close_bdj(BLURAY *bd)
 #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);
-  }
+    X_FREE(bd->bdjstorage.cache_root);
+    X_FREE(bd->bdjstorage.persistent_root);
 }
 #else
 #define _storage_free(bd) do{}while(0)
@@ -2601,23 +2598,21 @@ int bd_set_player_setting_str(BLURAY *bd, uint32_t idx, const char *s)
 #ifdef USING_BDJAVA
         case BLURAY_PLAYER_CACHE_ROOT:
         case BLURAY_PLAYER_PERSISTENT_ROOT:
-            if (!bd->bdjstorage) {
-                bd->bdjstorage = calloc(1, sizeof(BDJ_STORAGE));
-                if (!bd->bdjstorage) {
-                    return 0;
-                }
-            }
             switch (idx) {
                 case BLURAY_PLAYER_CACHE_ROOT:
-                    X_FREE(bd->bdjstorage->cache_root);
-                    bd->bdjstorage->cache_root = str_dup(s);
-                    BD_DEBUG(DBG_BDJ, "Cache root dir set to %s\n", bd->bdjstorage->cache_root);
+                    bd_mutex_lock(&bd->mutex);
+                    X_FREE(bd->bdjstorage.cache_root);
+                    bd->bdjstorage.cache_root = str_dup(s);
+                    bd_mutex_unlock(&bd->mutex);
+                    BD_DEBUG(DBG_BDJ, "Cache root dir set to %s\n", bd->bdjstorage.cache_root);
                     return 1;
 
                 case BLURAY_PLAYER_PERSISTENT_ROOT:
-                    X_FREE(bd->bdjstorage->persistent_root);
-                    bd->bdjstorage->persistent_root = str_dup(s);
-                    BD_DEBUG(DBG_BDJ, "Persistent root dir set to %s\n", bd->bdjstorage->persistent_root);
+                    bd_mutex_lock(&bd->mutex);
+                    X_FREE(bd->bdjstorage.persistent_root);
+                    bd->bdjstorage.persistent_root = str_dup(s);
+                    bd_mutex_unlock(&bd->mutex);
+                    BD_DEBUG(DBG_BDJ, "Persistent root dir set to %s\n", bd->bdjstorage.persistent_root);
                     return 1;
             }
 #endif /* USING_BDJAVA */



More information about the libbluray-devel mailing list