]> granicus.if.org Git - handbrake/commitdiff
libhb: DVD drive region detection on linux
authorjstebbins <jstebbins.hb@gmail.com>
Thu, 9 Jul 2009 16:36:17 +0000 (16:36 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Thu, 9 Jul 2009 16:36:17 +0000 (16:36 +0000)
Read and log the region mask of the DVD drive.
We get the occasional linux user that has an unset region.  Logging
the region will help isolate the problem more quickly.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2675 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/dvd.c
libhb/dvdnav.c
libhb/ports.c
libhb/ports.h

index 29ed04fd4c9c68bf8e80eec2eba112b705cac24f..39b519d4c91f1bb494f2829d68b14cc9a1de602c 100644 (file)
@@ -87,10 +87,21 @@ hb_dvd_t * hb_dvdread_init( char * path )
 {
     hb_dvd_t * e;
     hb_dvdread_t * d;
+    int region_mask;
 
     e = calloc( sizeof( hb_dvd_t ), 1 );
     d = &(e->dvdread);
 
+       /* Log DVD drive region code */
+    if ( hb_dvd_region( path, &region_mask ) == 0 )
+    {
+        hb_log( "dvd: Region mask 0x%02x", region_mask );
+        if ( region_mask == 0xFF )
+        {
+            hb_log( "dvd: Warning, DVD device has no region set" );
+        }
+    }
+
     /* Open device */
     if( !( d->reader = DVDOpen( path ) ) )
     {
index 378c1334b85956b5b47e6e6881e96c0f675cf3e4..40587b7ed0ebec3b2636a79a8ecd511d36108907 100644 (file)
@@ -142,10 +142,21 @@ static hb_dvd_t * hb_dvdnav_init( char * path )
 {
     hb_dvd_t * e;
     hb_dvdnav_t * d;
+    int region_mask;
 
     e = calloc( sizeof( hb_dvd_t ), 1 );
     d = &(e->dvdnav);
 
+       /* Log DVD drive region code */
+    if ( hb_dvd_region( path, &region_mask ) == 0 )
+    {
+        hb_log( "dvd: Region mask 0x%02x", region_mask );
+        if ( region_mask == 0xFF )
+        {
+            hb_log( "dvd: Warning, DVD device has no region set" );
+        }
+    }
+
     /* Open device */
     if( dvdnav_open(&d->dvdnav, path) != DVDNAV_STATUS_OK )
     {
index 6c6960633556f83337c7f93d0bc348f9371948d0..7b18ce89695c6c2b6b2c54e07e452f78991b8e1f 100644 (file)
 #include <netinet/in.h>
 #endif
 
+#if defined( SYS_LINUX )
+#include <linux/cdrom.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#elif defined( SYS_OPENBSD )
+#include <sys/dvdio.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#endif
+
 #include <stddef.h>
 
 #include "hb.h"
@@ -82,6 +92,33 @@ int gettimeofday( struct timeval * tv, struct timezone * tz )
 #endif
 */
 
+int hb_dvd_region(char *device, int *region_mask)
+{
+#if defined( DVD_LU_SEND_RPC_STATE ) && defined( DVD_AUTH )
+    struct stat  st;
+    dvd_authinfo ai;
+    int          fd, ret;
+
+    fd = open( device, O_RDONLY );
+    if ( fd < 0 )
+        return -1;
+    if ( fstat( fd, &st ) < 0 )
+        return -1;
+    if ( !( S_ISBLK( st.st_mode ) || S_ISCHR( st.st_mode ) ) )
+        return -1;
+
+    ai.type = DVD_LU_SEND_RPC_STATE;
+    ret = ioctl(fd, DVD_AUTH, &ai);
+    if ( ret < 0 )
+        return ret;
+
+    *region_mask = ai.lrpcs.region_mask;
+    return 0;
+#else
+    return -1;
+#endif
+}
+
 uint64_t hb_get_date()
 {
     struct timeval tv;
index c544f19a6a236db5affdadda8292a549d394c966..0f3697f0def413ffec03e4426e0ca28d3b890a74 100644 (file)
@@ -18,6 +18,11 @@ int      hb_get_cpu_count();
 
 /* Everything from now is only used internally and hidden to the UI */
 
+/************************************************************************
+ * DVD utils
+ ***********************************************************************/
+int hb_dvd_region(char *device, int *region_mask);
+
 /************************************************************************
  * Files utils
  ***********************************************************************/