[libbdplus-devel] [Git][videolan/libbdplus][master] Allow overriding conversion table

Petri Hintukainen (@hpi) gitlab at videolan.org
Sat Oct 2 19:00:00 UTC 2021



Petri Hintukainen pushed to branch master at VideoLAN / libbdplus


Commits:
cb46380c by John Doe at 2021-10-02T21:59:02+03:00
Allow overriding conversion table

VM-generated table can be overridden with cached table by using
environment variable BDPLUS_CONVTAB.

- - - - -


5 changed files:

- src/libbdplus/bdplus.c
- src/libbdplus/bdplus.h
- src/libbdplus/bdplus_data.h
- src/libbdplus/bdsvm/segment.c
- src/libbdplus/bdsvm/segment.h


Changes:

=====================================
src/libbdplus/bdplus.c
=====================================
@@ -89,6 +89,14 @@ int32_t bdplus_get_code_date(bdplus_t *plus)
     return plus->date;
 }
 
+int32_t bdplus_is_cached(bdplus_t *plus)
+{
+    if (!plus) return -1;
+    if (!plus->started) return -1;
+
+    return plus->cache_tab != NULL;
+}
+
 
 static char *_slots_file(void)
 {
@@ -232,6 +240,20 @@ int32_t bdplus_start(bdplus_t *plus)
 
     plus->started = 1;
 
+    const char *cachefile = getenv("BDPLUS_CONVTAB");
+    if (cachefile && !plus->cache_tab) {
+        FILE *fp = fopen(cachefile, "rb");
+        if (fp) {
+            conv_table_t *ct = NULL;
+            BD_DEBUG(DBG_BDPLUS|DBG_CRIT, "[bdplus] loading cached conversion table...\n");
+            if(segment_load(&ct, fp) == 1) {
+                segment_activateTable(ct);
+                plus->cache_tab = ct;
+            }
+            fclose(fp);
+        }
+    }
+
     bd_mutex_unlock(&plus->mutex);
 
     return result;
@@ -271,6 +293,9 @@ void bdplus_free(bdplus_t *plus)
         }
         segment_freeTable(&plus->conv_tab);
     }
+    if (plus->cache_tab) {
+        segment_freeTable(&plus->cache_tab);
+    }
 
     X_FREE(plus->device_path);
 
@@ -284,12 +309,22 @@ void bdplus_free(bdplus_t *plus)
 
 bdplus_st_t *bdplus_m2ts(bdplus_t *plus, uint32_t m2ts)
 {
+    bdplus_st_t *st;
+
     BD_DEBUG(DBG_BDPLUS, "[bdplus] set_m2ts %p -> %u\n", plus, m2ts);
 
     if (!plus) return NULL;
 
     bd_mutex_lock(&plus->mutex);
 
+    if (plus->cache_tab) {
+
+        st = segment_set_m2ts(plus->cache_tab, m2ts);
+        if (st) {
+            BD_DEBUG(DBG_BDPLUS|DBG_CRIT, "[bdplus] using cached conversion table for %05u.m2ts\n", m2ts);
+        }
+
+    } else {
     if (!plus->conv_tab) {
         BD_DEBUG(DBG_BDPLUS | DBG_CRIT, "[bdplus] bdplus_m2ts(%05u.m2ts): no conversion table\n", m2ts);
         bd_mutex_unlock(&plus->mutex);
@@ -298,7 +333,8 @@ bdplus_st_t *bdplus_m2ts(bdplus_t *plus, uint32_t m2ts)
 
     bdplus_run_m2ts(plus, m2ts);
 
-    bdplus_st_t *st = segment_set_m2ts(plus->conv_tab, m2ts);
+    st = segment_set_m2ts(plus->conv_tab, m2ts);
+    }
 
     bd_mutex_unlock(&plus->mutex);
 
@@ -384,6 +420,10 @@ static int32_t _bdplus_event(bdplus_t *plus, uint32_t event, uint32_t param1, ui
         /* try to emulate player to get converson table. */
         BD_DEBUG(DBG_BDPLUS, "[bdplus] received CONVERSION TABLE event\n");
 
+        if (plus->cache_tab) {
+            return 0;
+        }
+
         unsigned int num_titles = param2;
 
         bdplus_run_init(plus->vm);


=====================================
src/libbdplus/bdplus.h
=====================================
@@ -72,6 +72,9 @@ int32_t bdplus_get_code_gen(bdplus_t *plus);
 BD_PUBLIC
 int32_t bdplus_get_code_date(bdplus_t *plus);
 
+BD_PUBLIC
+int32_t bdplus_is_cached(bdplus_t *plus);
+
 
 /*
  * Release the bdplus library.


=====================================
src/libbdplus/bdplus_data.h
=====================================
@@ -52,6 +52,7 @@ struct bdplus_s {
     uint8_t  mediaKey[BLURAY_VOLUMEID_LEN]; // This should probably be moved out,API?
 
     struct conv_table_s *conv_tab;
+    struct conv_table_s *cache_tab;
 
     struct bdplus_config_s *config;
 


=====================================
src/libbdplus/bdsvm/segment.c
=====================================
@@ -548,7 +548,37 @@ uint32_t segment_mergeTables(conv_table_t *set1, conv_table_t *set2)
 }
 
 
+//
+// Activates a table. This is usefull if a cached convtab.bin file is being used.
+// Sets all segements as decrypted and all entries as active
+int32_t segment_activateTable(conv_table_t *conv_tab)
+{
+    uint32_t table, currseg, currentry;
+    subtable_t *subtable = NULL;
+    segment_t *segment = NULL;
+    entry_t *entry = NULL;
 
+    BD_DEBUG(DBG_BDPLUS | DBG_CRIT,"[segment] activating conv_tab.bin\n");
+
+    for (table = 0; table < conv_tab->numTables; table++) {
+
+        // Assign pointer so we don't need to keep dereferencing
+        subtable = &conv_tab->Tables[ table ];
+
+        //set all segments as decrypted
+        for (currseg = 0; currseg < subtable->numSegments; currseg++) {
+            segment = &subtable->Segments[ currseg ];
+            segment->encrypted = 0;
+
+            //set all entries as active
+            for (currentry = 0; currentry < segment->numEntries; currentry++) {
+                entry = &segment->Entries[ currentry ];
+                entry->active = 1;
+            }
+        }
+    }
+    return 0;
+}
 
 
 //
@@ -727,6 +757,30 @@ static int segment_sortby_tableid(const void *a1, const void *a2)
 }
 
 
+int32_t segment_load(conv_table_t **conv_tab, FILE *fd)
+{
+    uint32_t fileLen;
+    uint32_t len;
+    uint8_t *buffer = NULL;
+
+    BD_DEBUG(DBG_BDPLUS | DBG_CRIT,"[segment] loading cached convTable file\n");
+    fseek(fd, 0L, SEEK_END);
+    fileLen=ftell(fd);
+    rewind(fd);
+    buffer=(uint8_t *)malloc(fileLen+1);
+    len=fread(buffer, fileLen, 1, fd);
+
+    // Save the table to VM
+    if (len) {
+        // Decode the table into C structures.
+        segment_setTable(conv_tab, buffer, fileLen);
+        X_FREE(buffer);
+
+        if(conv_tab) return 1;
+    }
+    return 0;
+}
+
 
 int32_t segment_save(conv_table_t *ct, FILE *fd)
 {


=====================================
src/libbdplus/bdsvm/segment.h
=====================================
@@ -39,12 +39,14 @@ BD_PRIVATE uint32_t     segment_numEntries ( conv_table_t * );
 BD_PRIVATE int32_t      segment_setTable    ( conv_table_t **, uint8_t *, uint32_t );
 BD_PRIVATE int32_t      segment_freeTable   ( conv_table_t ** );
 BD_PRIVATE uint32_t     segment_mergeTables ( conv_table_t *, conv_table_t * );
+BD_PRIVATE int32_t      segment_activateTable ( conv_table_t * );
 
 BD_PRIVATE int32_t      segment_nextSegment ( conv_table_t *, uint32_t *, uint32_t * );
 BD_PRIVATE int32_t      segment_setSegment  ( conv_table_t *, uint32_t, uint32_t );
 BD_PRIVATE int32_t      segment_decrypt     ( conv_table_t *, uint8_t *, uint8_t * );
 
 BD_PRIVATE int32_t      segment_save        ( conv_table_t *, FILE * );
+BD_PRIVATE int32_t      segment_load        ( conv_table_t **,FILE * );
 
 BD_PRIVATE bdplus_st_t *segment_set_m2ts    ( conv_table_t *, uint32_t );
 BD_PRIVATE int32_t      segment_patchfile   ( conv_table_t *, uint32_t , FILE * );



View it on GitLab: https://code.videolan.org/videolan/libbdplus/-/commit/cb46380c62c4ef7d997a210bc0373eb0d764dcdb

-- 
View it on GitLab: https://code.videolan.org/videolan/libbdplus/-/commit/cb46380c62c4ef7d997a210bc0373eb0d764dcdb
You're receiving this email because of your account on code.videolan.org.




More information about the libbdplus-devel mailing list