[libdvdnav-devel] [RFC PATCH] src/dvd_input.c: Rework css/non css function calling

Andrew Clayton andrew at digital-domain.net
Fri Oct 24 18:18:17 CEST 2014


This is just a request for comments patch (and lacks a s-o-b) to see if
this is suitable or if there is a better way.

When compiling src/dvd_input.c we get the following warnings (from GCC
4.8.3)

    src/dvd_input.c: In function 'file_error':
    src/dvd_input.c:186:37: warning: unused parameter 'dev'
      [-Wunused-parameter]
     static char *file_error(dvd_input_t dev)
                                         ^
    src/dvd_input.c: In function 'file_title':
    src/dvd_input.c:210:35: warning: unused parameter 'dev'
      [-Wunused-parameter]
     static int file_title(dvd_input_t dev, int block)
                                       ^
    src/dvd_input.c:210:44: warning: unused parameter 'block'
      [-Wunused-parameter]
     static int file_title(dvd_input_t dev, int block)
                                                ^
    src/dvd_input.c: In function 'file_read':
    src/dvd_input.c:218:69: warning: unused parameter 'flags'
      [-Wunused-parameter]
     static int file_read(dvd_input_t dev, void *buffer, int blocks,
                          int flags)

This is due to those functions not taking all the same parameters as
their css counterparts do.

One way to fix this would be to use __attribute__((unused)) in the
variables being passed in, however I believe this is a GCC extension and
this would maybe break other platforms.

What this patch does is create file_*_proxy functions that call the css
or file version with the correct required parameters depending on if
libdvdcss is being used.

Apart from fixing the compiler warnings it does simplify
dvdinput_setup() a little.
---
 src/dvd_input.c | 108 ++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 77 insertions(+), 31 deletions(-)

diff --git a/src/dvd_input.c b/src/dvd_input.c
index 3b7f679..276c28b 100644
--- a/src/dvd_input.c
+++ b/src/dvd_input.c
@@ -75,6 +75,8 @@ struct dvd_input_s {
   int fd;
 };
 
+/* Are we using CSS */
+static void *dvdcss_library;
 
 /**
  * initialize and open a DVD device or file.
@@ -183,7 +185,7 @@ static dvd_input_t file_open(const char *target)
 /**
  * return the last error message
  */
-static char *file_error(dvd_input_t dev)
+static char *file_error(void)
 {
   /* use strerror(errno)? */
   return (char *)"unknown error";
@@ -207,7 +209,7 @@ static int file_seek(dvd_input_t dev, int blocks)
 /**
  * set the block for the beginning of a new title (key).
  */
-static int file_title(dvd_input_t dev, int block)
+static int file_title(void)
 {
   return -1;
 }
@@ -215,7 +217,7 @@ static int file_title(dvd_input_t dev, int block)
 /**
  * read data from the device.
  */
-static int file_read(dvd_input_t dev, void *buffer, int blocks, int flags)
+static int file_read(dvd_input_t dev, void *buffer, int blocks)
 {
   size_t len;
 
@@ -267,11 +269,71 @@ static int file_close(dvd_input_t dev)
 
 
 /**
+ * calls css_open or file_open depending on if CSS is being used.
+ */
+static dvd_input_t file_open_proxy(const char *target)
+{
+  if(dvdcss_library)
+    return css_open(target);
+  return file_open(target);
+}
+
+/**
+ * calls css_close or file_close depending on if CSS is being used.
+ */
+static int file_close_proxy(dvd_input_t dev)
+{
+  if(dvdcss_library)
+    return css_close(dev);
+  return file_close(dev);
+}
+
+/**
+ * calls css_seek or file_seek depending on if CSS is being used.
+ */
+static int file_seek_proxy(dvd_input_t dev, int blocks)
+{
+  if(dvdcss_library)
+    return css_seek(dev, blocks);
+  return file_seek(dev, blocks);
+}
+
+/**
+ * calls css_title or file_title depending on if CSS is being used.
+ */
+static int file_title_proxy(dvd_input_t dev, int block)
+{
+  if(dvdcss_library)
+    return css_title(dev, block);
+  return file_title();
+}
+
+/**
+ * calls css_read or file_read depending on if CSS is being used.
+ */
+static int file_read_proxy(dvd_input_t dev, void *buffer, int blocks, int flags)
+{
+  if(dvdcss_library)
+    return css_read(dev, buffer, blocks, flags);
+  return file_read(dev, buffer, blocks);
+}
+
+/**
+ * calls css_error or file_error depending on if CSS is being used.
+ */
+static char *file_error_proxy(dvd_input_t dev)
+{
+  if(dvdcss_library)
+    return css_error(dev);
+  return file_error();
+}
+
+
+/**
  * Setup read functions with either libdvdcss or minimal DVD access.
  */
 int dvdinput_setup(void)
 {
-  void *dvdcss_library = NULL;
 
 #ifdef HAVE_DVDCSS_DVDCSS_H
   /* linking to libdvdcss */
@@ -324,34 +386,18 @@ int dvdinput_setup(void)
     }
   }
 #endif /* HAVE_DVDCSS_DVDCSS_H */
-
-  if(dvdcss_library != NULL) {
-    /*
-    char *psz_method = getenv( "DVDCSS_METHOD" );
-    char *psz_verbose = getenv( "DVDCSS_VERBOSE" );
-    fprintf(stderr, "DVDCSS_METHOD %s\n", psz_method);
-    fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose);
-    */
-
-    /* libdvdcss wrapper functions */
-    dvdinput_open  = css_open;
-    dvdinput_close = css_close;
-    dvdinput_seek  = css_seek;
-    dvdinput_title = css_title;
-    dvdinput_read  = css_read;
-    dvdinput_error = css_error;
-    return 1;
-
-  } else {
+  if(!dvdcss_library)
     fprintf(stderr, "libdvdread: Encrypted DVD support unavailable.\n");
 
-    /* libdvdcss replacement functions */
-    dvdinput_open  = file_open;
-    dvdinput_close = file_close;
-    dvdinput_seek  = file_seek;
-    dvdinput_title = file_title;
-    dvdinput_read  = file_read;
-    dvdinput_error = file_error;
+  dvdinput_open  = file_open_proxy;
+  dvdinput_close = file_close_proxy;
+  dvdinput_seek  = file_seek_proxy;
+  dvdinput_title = file_title_proxy;
+  dvdinput_read  = file_read_proxy;
+  dvdinput_error = file_error_proxy;
+
+  if(dvdcss_library)
+    return 1;
+  else
     return 0;
-  }
 }
-- 
1.9.3



More information about the libdvdnav-devel mailing list