[libdvdcss-devel] libdvdcss: Factor out cache initialization from dvdcss_open()

Diego Biurrun git at videolan.org
Tue Nov 4 16:26:03 CET 2014


libdvdcss | branch: master | Diego Biurrun <diego at biurrun.de> | Tue Nov  4 14:18:09 2014 +0100| [29dd1a4f43b2063d05ed8e8be01102481ea21c0a] | committer: Diego Biurrun

libdvdcss: Factor out cache initialization from dvdcss_open()

> http://git.videolan.org/gitweb.cgi/libdvdcss.git/?a=commit;h=29dd1a4f43b2063d05ed8e8be01102481ea21c0a
---

 src/libdvdcss.c |   34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 93615ab..a818744 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -420,6 +420,24 @@ static void create_cache_subdir( dvdcss_t dvdcss, const char *psz_cache )
                  dvdcss->psz_cachefile );
 }
 
+static void init_cache( dvdcss_t dvdcss )
+{
+    /* Set CSS key cache directory. */
+    const char *psz_cache = set_cache_directory( dvdcss );
+
+    /* If the cache is enabled, initialize the cache directory. */
+    if( psz_cache )
+    {
+        init_cache_dir( dvdcss, psz_cache );
+    }
+
+    /* If the cache is enabled, create a DVD-specific subdirectory. */
+    if( psz_cache )
+    {
+        create_cache_subdir( dvdcss, psz_cache );
+    }
+}
+
 /**
  * \brief Open a DVD device or directory and return a dvdcss instance.
  *
@@ -436,7 +454,6 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
 {
     int i_ret;
 
-    const char *psz_cache;
 #ifdef DVDCSS_RAW_OPEN
     const char *psz_raw_device = getenv( "DVDCSS_RAW_DEVICE" );
 #endif
@@ -467,9 +484,6 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
         goto error;
     }
 
-    /* Set CSS key cache directory. */
-    psz_cache = set_cache_directory( dvdcss );
-
     /* Open device. */
     dvdcss_check_device( dvdcss );
     i_ret = dvdcss_open_device( dvdcss );
@@ -518,17 +532,7 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
         }
     }
 
-    /* If the cache is enabled, initialize the cache directory. */
-    if( psz_cache )
-    {
-        init_cache_dir( dvdcss, psz_cache );
-    }
-
-    /* If the cache is enabled, extract a unique disc ID */
-    if( psz_cache )
-    {
-        create_cache_subdir( dvdcss, psz_cache );
-    }
+    init_cache( dvdcss );
 
 #ifdef DVDCSS_RAW_OPEN
     if( psz_raw_device != NULL )



More information about the libdvdcss-devel mailing list