[MPlayer-dev-eng] [PATCH] working dvd player for cygwin

Joey Parrish joey at yunamusic.com
Fri Jul 5 03:10:52 CEST 2002


Hello!!

I'm quite excited about this!
Attached below is a patch for mpdvdkit under cygwin.
This patch has been verified to work using the latest
cygwin packages and the latest mplayer source.

And now I can finally go eat and maybe even sleep tonight.
:D

--Joey

-- 
"Living in the complex world of the future is somewhat
like having bees live in your head.  But, there they are."
-------------- next part --------------
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/configure ./configure
--- ../main.cvs/configure	Thu Jul  4 11:39:02 2002
+++ ./configure	Thu Jul  4 19:51:27 2002
@@ -2971,14 +2971,16 @@
 echocheck "DVD support (libmpdvdkit)"
 if test "$_dvdkit" = auto ; then
  _dvdkit=no
- if linux || freebsd || netbsd || darwin; then
+ if linux || freebsd || netbsd || darwin || cygwin; then
   test -f "./libmpdvdkit/Makefile" && _dvdkit=yes
  fi
 fi
 if test "$_dvdkit" = yes ; then
-  if test "$_dvd" = yes || test "$_cdrom" = yes || test "$_cdio" = yes || test "$_dvdio" = yes || test "$_bdsi_dvd" = yes ; then
+  if test "$_dvd" = yes || test "$_cdrom" = yes || test "$_cdio" = yes || test "$_dvdio" = yes || test "$_bdsi_dvd" = yes || cygwin; then
     _inputmodules="mpdvdkit $_inputmodules"
     _dvdread=included
+  else
+    _noinputmodules="mpdvdkit $_noinputmodules"
   fi
   _def_dvd_linux='#undef HAVE_LINUX_DVD_STRUCT'
   _def_dvd_bsd='#undef HAVE_BSD_DVD_STRUCT'
@@ -4371,6 +4373,9 @@
 #ifdef sun
 #define	DEFAULT_CDROM_DEVICE	"/vol/dev/aliases/cdrom0"
 #define DEFAULT_DVD_DEVICE	DEFAULT_CDROM_DEVICE
+#elif defined(WIN32)
+#define DEFAULT_CDROM_DEVICE    "D:"
+#define DEFAULT_DVD_DEVICE	"D:"
 #else
 #define DEFAULT_CDROM_DEVICE    "/dev/cdrom"
 #define DEFAULT_DVD_DEVICE	"/dev/dvd"
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/libmpdvdkit/bswap.h ./libmpdvdkit/bswap.h
--- ../main.cvs/libmpdvdkit/bswap.h	Tue Jun  4 15:11:15 2002
+++ ./libmpdvdkit/bswap.h	Thu Jul  4 19:51:28 2002
@@ -48,6 +48,44 @@
 #define B2N_32(x) x = swap32(x)
 #define B2N_64(x) x = swap64(x)
 
+#elif defined(ARCH_X86)
+inline static unsigned short bswap_16(unsigned short x)
+{
+  __asm("xchgb %b0,%h0" :
+        "=q" (x)        :
+        "0" (x));
+    return x;
+}
+#define B2N_16(x) x = bswap_16(x)
+
+inline static unsigned int bswap_32(unsigned int x)
+{
+ __asm(
+#if __CPU__ > 386
+      "bswap   %0":
+      "=r" (x)     :
+#else
+      "xchgb   %b0,%h0\n"
+      " rorl    $16,%0\n"
+      " xchgb   %b0,%h0":
+      "=q" (x)          :
+#endif
+      "0" (x));
+  return x;
+}
+#define B2N_32(x) x = bswap_32(x)
+
+inline static unsigned long long int bswap_64(unsigned long long int x)
+{
+  register union { __extension__ uint64_t __ll;
+          uint32_t __l[2]; } __x;
+  asm("xchgl    %0,%1":
+      "=r"(__x.__l[0]),"=r"(__x.__l[1]):
+      "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
+  return __x.__ll;
+}
+#define B2N_64(x) x = bswap_64(x)
+
 /* This is a slow but portable implementation, it has multiple evaluation 
  * problems so beware.
  * FreeBSD and Solaris don't have <byteswap.h> or any other such 
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/libmpdvdkit/common.h ./libmpdvdkit/common.h
--- ../main.cvs/libmpdvdkit/common.h	Wed Jun 19 01:57:32 2002
+++ ./libmpdvdkit/common.h	Thu Jul  4 19:51:28 2002
@@ -140,7 +140,7 @@
  *****************************************************************************/
 #ifdef NTOHL_IN_SYS_PARAM_H
 #   include <sys/param.h>
-#elif defined(WIN32) && !defined(__CYGWIN__)
+#elif defined(WIN32)
 #   include <winsock.h>
 #else
 #   include <netinet/in.h>
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/libmpdvdkit/css.c ./libmpdvdkit/css.c
--- ../main.cvs/libmpdvdkit/css.c	Thu Apr 25 12:08:03 2002
+++ ./libmpdvdkit/css.c	Thu Jul  4 19:51:28 2002
@@ -33,6 +33,12 @@
  * Preamble
  *****************************************************************************/
 
+#include "config.h"
+
+#if defined(WIN32)
+# define __USE_W32_SOCKETS 1
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -40,7 +46,6 @@
 
 #include <sys/types.h>
 
-#include "config.h"
 #include "common.h"
 
 #include "dvdcss.h"
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/libmpdvdkit/dvd_reader.c ./libmpdvdkit/dvd_reader.c
--- ../main.cvs/libmpdvdkit/dvd_reader.c	Thu Jun 13 00:11:16 2002
+++ ./libmpdvdkit/dvd_reader.c	Thu Jul  4 19:51:28 2002
@@ -16,6 +16,9 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+
+#include "config.h"
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h> /* For the timing of dvdcss_title crack. */
@@ -40,12 +43,18 @@
 #include <mntent.h>
 #endif
 
-#if defined(SYS_BSD) || defined(__CYGWIN__)
+#if defined(SYS_BSD)
 typedef off_t off64_t;
 #define lseek64 lseek
 #define stat64 stat
 #endif
 
+#if defined(WIN32)
+typedef u_int64_t off64_t;
+#define lseek64 lseek
+#define stat64 stat
+#endif
+
 #if defined(SYS_DARWIN)
 typedef u_int64_t off64_t;
 #define lseek64 lseek
@@ -252,11 +261,13 @@
 
 dvd_reader_t *DVDOpen( const char *path )
 {
+#if !defined(WIN32)
     struct stat64 fileinfo;
+#endif
     int ret;
     char * dir;
 
-
+#if !defined(WIN32)
     if( !path ) return 0;
 
     ret = stat64( path, &fileinfo );
@@ -266,17 +277,22 @@
 	perror("");
 	return 0;
     }
-
+#endif
+    
     dir=get_path( "" );
     if ( dir ) { mkdir( dir,493 ); free( dir ); }
     dir=get_path( "DVDKeys" );
     if ( !dir ) dir=strdup( "/tmp" );
     mkdir( dir,493 );
 
+#if !defined(WIN32)
     /* First check if this is a block/char device or a file*/
     if( S_ISBLK( fileinfo.st_mode ) || 
 	S_ISCHR( fileinfo.st_mode ) || 
 	S_ISREG( fileinfo.st_mode ) ) {
+#else
+    {
+#endif
 
 	/**
 	 * Block devices and regular files are assumed to be DVD-Video images.
@@ -293,6 +309,7 @@
 	device = path;
 #endif
 
+#if !defined(WIN32)
 	if ( (img=fopen( device,"r" )) )
 	 {
 	  int i;
@@ -311,6 +328,10 @@
 
 	if ( (dvd_key_dir=(char *)calloc( 1,strlen( dir ) + 18 )) == NULL ) return 0;
 	sprintf( dvd_key_dir,"%s/%.16s",dir,discid );
+#else
+	if ( (dvd_key_dir=(char *)calloc( 1,strlen( dir ) + 18 )) == NULL ) return 0;
+	sprintf( dvd_key_dir,"%s/oops",dir);
+#endif
 	mkdir( dvd_key_dir,493 );
 
 	free( dir );
@@ -318,7 +339,9 @@
         return DVDOpenImageFile( device );
 // ---
 
-    } else if( S_ISDIR( fileinfo.st_mode ) ) {
+    }
+#if !defined(WIN32)
+    else if( S_ISDIR( fileinfo.st_mode ) ) {
 	dvd_reader_t *auth_drive = 0;
 	char *path_copy;
 #if defined(SYS_BSD)
@@ -441,6 +464,7 @@
 	fprintf( stderr, "libdvdread: Using normal filesystem access.\n" );
         return DVDOpenPath( path );
     }
+#endif
 
     /* If it's none of the above, screw it. */
     fprintf( stderr, "libdvdread: Could not open %s\n", path );
@@ -780,7 +804,6 @@
 		     lb_number );
             return 0;
         }
-
         return (int64_t) ( dvdcss_read( device->dev, (char *) data, 
 					(int) block_count, encrypted ) 
 			   * (uint64_t) DVD_VIDEO_LB_LEN );
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/libmpdvdkit/input_iovec.h ./libmpdvdkit/input_iovec.h
--- ../main.cvs/libmpdvdkit/input_iovec.h	Wed Dec 31 18:00:00 1969
+++ ./libmpdvdkit/input_iovec.h	Thu Jul  4 19:51:28 2002
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * input_iovec.h: iovec structure
+ *****************************************************************************
+ * Copyright (C) 2001 VideoLAN
+ *
+ * Authors: Samuel Hocevar <sam at zoy.org>
+ *          Jon Lech Johansen <jon-vl at nanocrew.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * iovec structure: vectored data entry
+ *****************************************************************************/
+struct iovec
+{
+    void *iov_base;     /* Pointer to data. */
+    size_t iov_len;     /* Length of data.  */
+};
+
+/*****************************************************************************
+ * readv_*: readv() replacements for iovec-impaired C libraries
+ *****************************************************************************/
+#if defined( WIN32 )
+static inline int readv( int i_fd, struct iovec *p_iovec, int i_count )
+{
+    int i_index, i_len, i_total = 0;
+    unsigned char *p_base;
+    int i_bytes;
+
+    for( i_index = i_count; i_index; i_index-- )
+    {
+
+        i_len  = p_iovec->iov_len;
+        p_base = p_iovec->iov_base;
+
+        /* Loop is unrolled one time to spare the (i_bytes <= 0) test */
+
+        if( i_len > 0 )
+        {
+            i_bytes = read( i_fd, p_base, i_len );
+
+            if( i_bytes < 0 )
+            {
+                /* One of the reads failed, too bad.
+                   We won't even bother returning the reads that went ok,
+                   and as in the posix spec the file postition is left
+                   unspecified after a failure */
+                return -1;
+            }
+
+            i_total += i_bytes;
+
+            if( i_bytes != i_len )
+            {
+                /* we reached the end of the file or a signal interrupted
+                   the read */
+                return i_total;
+            }
+        }
+
+        p_iovec++;
+    }
+
+    return i_total;
+}
+#endif /* WIN32 */
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/libmpdvdkit/ioctl.c ./libmpdvdkit/ioctl.c
--- ../main.cvs/libmpdvdkit/ioctl.c	Thu Jun 13 18:10:12 2002
+++ ./libmpdvdkit/ioctl.c	Thu Jul  4 19:51:28 2002
@@ -29,6 +29,10 @@
  *****************************************************************************/
 #include "config.h"
 
+#if defined(WIN32)
+# define __USE_W32_SOCKETS 1
+#endif
+
 #include <string.h>                                    /* memcpy(), memset() */
 #include <sys/types.h>
 
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/libmpdvdkit/ioctl.h ./libmpdvdkit/ioctl.h
--- ../main.cvs/libmpdvdkit/ioctl.h	Tue Jun  4 15:11:15 2002
+++ ./libmpdvdkit/ioctl.h	Thu Jul  4 19:51:28 2002
@@ -32,13 +32,6 @@
 int ioctl_SendChallenge     ( int, int *, u8 * );
 int ioctl_SendKey2          ( int, int *, u8 * );
 
-#if defined (__CYGWIN__)
-#include <w32api/windef.h>
-#include <w32api/winnt.h>
-#define va_list void
-#include <w32api/winbase.h>
-#endif
-
 /*****************************************************************************
  * Common macro, BeOS specific
  *****************************************************************************/
diff -Naur -x CVS -x libavcodec -x *~ ../main.cvs/libmpdvdkit/libdvdcss.c ./libmpdvdkit/libdvdcss.c
--- ../main.cvs/libmpdvdkit/libdvdcss.c	Tue Jun  4 15:11:15 2002
+++ ./libmpdvdkit/libdvdcss.c	Thu Jul  4 19:51:28 2002
@@ -26,6 +26,12 @@
  * Preamble
  *****************************************************************************/
 
+#include "config.h"
+
+#if defined(WIN32)
+# define __USE_W32_SOCKETS 1
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -34,16 +40,15 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#if defined( WIN32 ) && !defined(__CYGWIN__)
+#if defined( WIN32 )
 #   include <io.h>                                                 /* read() */
 #else
 #   include <sys/uio.h>                                      /* struct iovec */
 #endif
 
-#include "config.h"
 #include "common.h"
 
-#if defined( WIN32 ) && !defined(__CYGWIN__)
+#if defined( WIN32 )
 #   include "input_iovec.h"
 #endif
 
@@ -505,7 +510,7 @@
 
         li_read.LowPart = SetFilePointer( (HANDLE) dvdcss->i_fd,
                                           li_read.LowPart,
-                                          &li_read.HighPart, FILE_BEGIN );
+                                          &(li_read.HighPart), FILE_BEGIN );
         if( (li_read.LowPart == INVALID_SET_FILE_POINTER)
             && GetLastError() != NO_ERROR)
         {


More information about the MPlayer-dev-eng mailing list