[libbluray-devel] commit: Splitted _libaacs_open() and _libbdplus_open() (hpi1 )

git at videolan.org git at videolan.org
Mon Oct 25 12:00:21 CEST 2010


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Oct 25 12:38:26 2010 +0300| [01249ff5dcbf1ad1c6ef6ae8d315036429f59a6f] | committer: hpi1 

Splitted _libaacs_open() and _libbdplus_open()

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

 src/libbluray/bluray.c |  169 +++++++++++++++++++++++++++++++----------------
 1 files changed, 111 insertions(+), 58 deletions(-)

diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 504012d..1e84ee2 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -117,6 +117,7 @@ struct bluray {
     void           *h_libaacs;   // library handle
 #endif
     void           *aacs;
+    fptr_p_void    libaacs_open;
     fptr_int       libaacs_decrypt_unit;
 
     /* BD+ */
@@ -124,6 +125,7 @@ struct bluray {
     void           *h_libbdplus; // library handle
 #endif
     void           *bdplus;
+    fptr_p_void    bdplus_init;
     fptr_int32     bdplus_seek;
     fptr_int32     bdplus_fixup;
 
@@ -276,9 +278,9 @@ static int _read_block(BLURAY *bd, BD_STREAM *st, uint8_t *buf)
                 if (read_len != len)
                     DEBUG(DBG_STREAM | DBG_CRIT, "Read %d bytes at %"PRIu64" ; requested %d ! (%p)\n", read_len, st->clip_block_pos, len, bd);
 
-                if (bd->libaacs_decrypt_unit) {
+                if (bd->aacs && bd->libaacs_decrypt_unit) {
                     if (!bd->libaacs_decrypt_unit(bd->aacs, buf)) {
-                        DEBUG(DBG_AACS | DBG_CRIT, "Unable decrypt unit! (%p)\n", bd);
+                        DEBUG(DBG_AACS | DBG_CRIT, "Unable decrypt unit (AACS)! (%p)\n", bd);
 
                         return 0;
                     } // decrypt
@@ -396,7 +398,7 @@ static int64_t _seek_stream(BLURAY *bd, BD_STREAM *st,
 }
 
 /*
- * open / close
+ * libaacs and libbdplus open / close
  */
 
 static void _libaacs_close(BLURAY *bd)
@@ -418,6 +420,7 @@ static void _libaacs_unload(BLURAY *bd)
     }
 #endif
 
+    bd->libaacs_open         = NULL;
     bd->libaacs_decrypt_unit = NULL;
 }
 
@@ -441,52 +444,70 @@ static int _libaacs_required(BLURAY *bd)
     return 0;
 }
 
-static int _libaacs_open(BLURAY *bd, const char *keyfile_path)
+static int _libaacs_load(BLURAY *bd)
 {
-    _libaacs_unload(bd);
-
-    if (!_libaacs_required(bd)) {
-        /* no AACS */
-        return 1; /* no error if libaacs is not needed */
+#ifdef DLOPEN_CRYPTO_LIBS
+    if (bd->h_libaacs) {
+        return 1;
     }
 
-#ifdef DLOPEN_CRYPTO_LIBS
     if ((bd->h_libaacs = dl_dlopen("libaacs", "0"))) {
-        DEBUG(DBG_BLURAY, "Downloaded libaacs (%p)\n", bd->h_libaacs);
 
-        fptr_p_void fptr = dl_dlsym(bd->h_libaacs, "aacs_open");
+        DEBUG(DBG_BLURAY, "Loading libaacs (%p)\n", bd->h_libaacs);
+
+        bd->libaacs_open         = dl_dlsym(bd->h_libaacs, "aacs_open");
         bd->libaacs_decrypt_unit = dl_dlsym(bd->h_libaacs, "aacs_decrypt_unit");
 
-        if (fptr && bd->libaacs_decrypt_unit) {
-            if ((bd->aacs = fptr(bd->device_path, keyfile_path))) {
-                DEBUG(DBG_BLURAY, "Opened libaacs (%p)\n", bd->aacs);
-                return 1;
-            }
-            DEBUG(DBG_BLURAY, "aacs_open() failed!\n");
+        if (bd->libaacs_open && bd->libaacs_decrypt_unit) {
+            DEBUG(DBG_BLURAY, "Loaded libaacs (%p)\n", bd->h_libaacs);
+            return 1;
+
         } else {
-            DEBUG(DBG_BLURAY, "libaacs dlsym failed!\n");
+            DEBUG(DBG_BLURAY, "libaacs dlsym failed! (%p)\n", bd->h_libaacs);
         }
-        dl_dlclose(bd->h_libaacs);
-        bd->h_libaacs = NULL;
 
     } else {
-        DEBUG(DBG_BLURAY, "libaacs not found!\n");
+        DEBUG(DBG_BLURAY, "libaacs not found! (%p)\n", bd);
     }
+
+    _libaacs_unload(bd);
+
+    return 0;
+
 #else
     DEBUG(DBG_BLURAY, "Using libaacs via normal linking\n");
 
+    bd->libaacs_open         = &aacs_open;
     bd->libaacs_decrypt_unit = &aacs_decrypt_unit;
 
-    if ((bd->aacs = aacs_open(bd->device_path, keyfile_path))) {
+    return 1;
+#endif
+}
+
+static int _libaacs_open(BLURAY *bd, const char *keyfile_path)
+{
+    _libaacs_close(bd);
+
+    if (!_libaacs_required(bd)) {
+        /* no AACS */
+        return 1; /* no error if libaacs is not needed */
+    }
+
+    if (!_libaacs_load(bd)) {
+        /* no libaacs */
+        return 0;
+    }
+
+    bd->aacs = bd->libaacs_open(bd->device_path, keyfile_path);
 
+    if (bd->aacs) {
         DEBUG(DBG_BLURAY, "Opened libaacs (%p)\n", bd->aacs);
         return 1;
     }
-    DEBUG(DBG_BLURAY, "aacs_open() failed!\n");
-#endif
 
-    bd->libaacs_decrypt_unit = NULL;
+    DEBUG(DBG_BLURAY, "aacs_open() failed!\n");
 
+    _libaacs_unload(bd);
     return 0;
 }
 
@@ -509,6 +530,7 @@ static void _libbdplus_unload(BLURAY *bd)
     }
 #endif
 
+    bd->bdplus_init  = NULL;
     bd->bdplus_seek  = NULL;
     bd->bdplus_fixup = NULL;
 }
@@ -533,55 +555,86 @@ static int _libbdplus_required(BLURAY *bd)
     return 0;
 }
 
-static int _libbdplus_open(BLURAY *bd, const char *keyfile_path)
+static int _libbdplus_load(BLURAY *bd)
 {
-    _libbdplus_unload(bd);
+    DEBUG(DBG_BDPLUS, "attempting to load libbdplus\n");
 
-    if (!_libbdplus_required(bd)) {
-        /* no BD+ */
-        return 1; /* no error if libbdplus is not needed */
+#ifdef DLOPEN_CRYPTO_LIBS
+    if (bd->h_libbdplus) {
+        return 1;
     }
 
-    // Take a quick stab to see if we want/need bdplus
-    // we should fix this, and add various string functions.
-    uint8_t vid[16] = {
-        0xC5,0x43,0xEF,0x2A,0x15,0x0E,0x50,0xC4,0xE2,0xCA,
-        0x71,0x65,0xB1,0x7C,0xA7,0xCB}; // FIXME
-
-    DEBUG(DBG_BDPLUS, "attempting to load libbdplus\n");
-#ifdef DLOPEN_CRYPTO_LIBS
     if ((bd->h_libbdplus = dl_dlopen("libbdplus", "0"))) {
-        DEBUG(DBG_BLURAY, "Downloaded libbdplus (%p)\n", bd->h_libbdplus);
 
-        fptr_p_void bdplus_init = dl_dlsym(bd->h_libbdplus, "bdplus_init");
-        //bdplus_t *bdplus_init(path,configfile_path,*vid );
-        if (bdplus_init) {
-            bd->bdplus = bdplus_init(bd->device_path, keyfile_path, vid);
-        }
-        if (bd->bdplus) {
-            // Since we will call these functions a lot, we assign them
-            // now.
-            bd->bdplus_seek  = dl_dlsym(bd->h_libbdplus, "bdplus_seek");
-            bd->bdplus_fixup = dl_dlsym(bd->h_libbdplus, "bdplus_fixup");
-        } else {
-            dl_dlclose(bd->h_libbdplus);
-            bd->h_libbdplus = NULL;
+        DEBUG(DBG_BLURAY, "Loading libbdplus (%p)\n", bd->h_libbdplus);
+
+        bd->bdplus_init  = dl_dlsym(bd->h_libbdplus, "bdplus_init");
+        bd->bdplus_seek  = dl_dlsym(bd->h_libbdplus, "bdplus_seek");
+        bd->bdplus_fixup = dl_dlsym(bd->h_libbdplus, "bdplus_fixup");
+
+        if (bd->bdplus_init && bd->bdplus_seek && bd->bdplus_fixup) {
+            DEBUG(DBG_BLURAY, "Loaded libbdplus (%p)\n", bd->h_libbdplus);
+            return 1;
         }
+
+        DEBUG(DBG_BLURAY, "libbdplus dlsym failed! (%p)\n", bd->h_libbdplus);
+
+    } else {
+        DEBUG(DBG_BLURAY, "libbdplus not found! (%p)\n", bd);
     }
+
+    _libbdplus_unload(bd);
+
+    return 0;
+
 #else
     DEBUG(DBG_BLURAY,"Using libbdplus via normal linking\n");
 
-    bd->bdplus = bdplus_init(bd->device_path, keyfile_path, vid);
-
-    // Since we will call these functions a lot, we assign them
-    // now.
+    bd->bdplus_init  = &bdplus_init;
     bd->bdplus_seek  = &bdplus_seek;
     bd->bdplus_fixup = &bdplus_fixup;
+
+    return 1;
 #endif
+}
 
-    return !!bd->bdplus;
+static int _libbdplus_open(BLURAY *bd, const char *keyfile_path)
+{
+    // Take a quick stab to see if we want/need bdplus
+    // we should fix this, and add various string functions.
+    uint8_t vid[16] = {
+        0xC5,0x43,0xEF,0x2A,0x15,0x0E,0x50,0xC4,0xE2,0xCA,
+        0x71,0x65,0xB1,0x7C,0xA7,0xCB}; // FIXME
+
+    _libbdplus_close(bd);
+
+    if (!_libbdplus_required(bd)) {
+        /* no BD+ */
+        return 1; /* no error if libbdplus is not needed */
+    }
+
+    if (!_libbdplus_load(bd)) {
+        /* no libbdplus */
+        return 0;
+    }
+
+    bd->bdplus = bd->bdplus_init(bd->device_path, keyfile_path, vid);
+
+    if (bd->bdplus) {
+        DEBUG(DBG_BLURAY,"libbdplus initialized\n");
+        return 1;
+    }
+
+    DEBUG(DBG_BLURAY,"bdplus_init() failed\n");
+
+    _libbdplus_unload(bd);
+    return 0;
 }
 
+/*
+ * index open
+ */
+
 static int _index_open(BLURAY *bd)
 {
     if (!bd->index) {



More information about the libbluray-devel mailing list