[MPlayer-cvslog] CVS: main/libmpdemux cdda.c, 1.17, 1.18 cddb.c, 1.18, 1.19 cdd.h, 1.2, 1.3

Sascha Sommer CVS syncmail at mplayerhq.hu
Sun Nov 6 18:42:22 CET 2005


CVS change done by Sascha Sommer CVS

Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var2/tmp/cvs-serv7053/libmpdemux

Modified Files:
	cdda.c cddb.c cdd.h 
Log Message:
make it optionally  possible to compile MPlayer with libcdio instead of libcdparanoia
patch by Erik Lunchpail <erik_27can at yahoo.com>
base on patch by Rocky Bernstein <rocky at panix.com>
minor modification by myself


Index: cdda.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cdda.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- cdda.c	6 Nov 2005 14:17:51 -0000	1.17
+++ cdda.c	6 Nov 2005 17:42:20 -0000	1.18
@@ -87,13 +87,17 @@
 
 static int seek(stream_t* s,off_t pos);
 static int fill_buffer(stream_t* s, char* buffer, int max_len);
-static void close(stream_t* s);
+static void close_cdda(stream_t* s);
 
 static int open_cdda(stream_t *st,int m, void* opts, int* file_format) {
   struct cdda_params* p = (struct cdda_params*)opts;
   int mode = p->paranoia_mode;
   int offset = p->toc_offset;
+#ifndef HAVE_LIBCDIO
   cdrom_drive* cdd = NULL;
+#else
+  cdrom_drive_t* cdd = NULL;
+#endif
   cdda_priv* priv;
   cd_info_t *cd_info,*cddb_info = NULL;
   unsigned int audiolen=0;
@@ -125,9 +129,11 @@
   }
 #endif
   
+#ifndef HAVE_LIBCDIO
   if(p->generic_dev)
     cdd = cdda_identify_scsi(p->generic_dev,p->device,0,NULL);
   else
+#endif
 #if defined(__NetBSD__)
     cdd = cdda_identify_scsi(p->device,p->device,0,NULL);
 #else
@@ -144,7 +150,9 @@
 
   if(p->sector_size) {
     cdd->nsectors = p->sector_size;
+#ifndef HAVE_LIBCDIO
     cdd->bigbuff = p->sector_size * CD_FRAMESIZE_RAW;
+#endif
   }
 
   if(cdda_open(cdd) != 0) {
@@ -218,10 +226,17 @@
   
   if(p->no_skip)
     mode |= PARANOIA_MODE_NEVERSKIP;
+#ifndef HAVE_LIBCDIO
   paranoia_modeset(cdd, mode);
 
   if(p->search_overlap >= 0)
     paranoia_overlapset(cdd,p->search_overlap);
+#else
+  paranoia_modeset(priv->cdp, mode);
+
+  if(p->search_overlap >= 0)
+    paranoia_overlapset(priv->cdp,p->search_overlap);
+#endif
 
   paranoia_seek(priv->cdp,priv->start_sector,SEEK_SET);
   priv->sector = priv->start_sector;
@@ -235,14 +250,21 @@
 #endif
 
   st->priv = priv;
+#ifndef HAVE_LIBCDIO
   st->start_pos = priv->start_sector*CD_FRAMESIZE_RAW;
   st->end_pos = priv->end_sector*CD_FRAMESIZE_RAW;
   st->type = STREAMTYPE_CDDA;
   st->sector_size = CD_FRAMESIZE_RAW;
+#else
+  st->start_pos = priv->start_sector*CDIO_CD_FRAMESIZE_RAW;
+  st->end_pos = priv->end_sector*CDIO_CD_FRAMESIZE_RAW;
+  st->type = STREAMTYPE_CDDA;
+  st->sector_size = CDIO_CD_FRAMESIZE_RAW;
+#endif
 
   st->fill_buffer = fill_buffer;
   st->seek = seek;
-  st->close = close;
+  st->close = close_cdda;
 
   *file_format = DEMUXER_TYPE_RAWAUDIO;
 
@@ -251,7 +273,11 @@
   return STREAM_OK;
 }
 
+#ifndef HAVE_LIBCDIO
 static void cdparanoia_callback(long inpos, int function) {
+#else
+static void cdparanoia_callback(long int inpos, paranoia_cb_mode_t function) {
+#endif
 }
 
 static int fill_buffer(stream_t* s, char* buffer, int max_len) {
@@ -263,13 +289,22 @@
   buf = paranoia_read(p->cdp,cdparanoia_callback);
 
 #ifdef WORDS_BIGENDIAN 
+#ifndef HAVE_LIBCDIO
   for(i=0;i<CD_FRAMESIZE_RAW/2;i++)
+#else
+  for(i=0;i<CDIO_CD_FRAMESIZE_RAW/2;i++)
+#endif
           buf[i]=le2me_16(buf[i]);
 #endif
 
   p->sector++;
+#ifndef HAVE_LIBCDIO
   s->pos = p->sector*CD_FRAMESIZE_RAW;
   memcpy(buffer,buf,CD_FRAMESIZE_RAW);
+#else
+  s->pos = p->sector*CDIO_CD_FRAMESIZE_RAW;
+  memcpy(buffer,buf,CDIO_CD_FRAMESIZE_RAW);
+#endif
 
   if((p->sector < p->start_sector) || (p->sector >= p->end_sector)) {
     s->eof = 1;
@@ -290,7 +325,11 @@
   }
 
   
+#ifndef HAVE_LIBCDIO
   return CD_FRAMESIZE_RAW;
+#else
+  return CDIO_CD_FRAMESIZE_RAW;
+#endif
 }
 
 static int seek(stream_t* s,off_t newpos) {
@@ -306,8 +345,13 @@
     return 0;
   }
 
+#ifndef HAVE_LIBCDIO
   sec = s->pos/CD_FRAMESIZE_RAW;
 //printf("pos: %d, sec: %d ## %d\n", (int)s->pos, (int)sec, CD_FRAMESIZE_RAW);
+#else
+  sec = s->pos/CDIO_CD_FRAMESIZE_RAW;
+//printf("pos: %d, sec: %d ## %d\n", (int)s->pos, (int)sec, CDIO_CD_FRAMESIZE_RAW);
+#endif
 //printf("sector: %d  new: %d\n", p->sector, sec );
  
   for(i=0;i<p->cd->tracks;i++){
@@ -338,14 +382,18 @@
 #endif
 
   p->sector = sec;
+#ifndef HAVE_LIBCDIO
 //  s->pos = sec*CD_FRAMESIZE_RAW;
+#else
+//  s->pos = sec*CDIO_CD_FRAMESIZE_RAW;
+#endif
 
 //printf("seek: %d, sec: %d\n", (int)s->pos, sec);
   paranoia_seek(p->cdp,sec,SEEK_SET);
   return 1;
 }
 
-static void close(stream_t* s) {
+static void close_cdda(stream_t* s) {
   cdda_priv* p = (cdda_priv*)s->priv;
   paranoia_free(p->cdp);
   cdda_close(p->cd);

Index: cddb.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cddb.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- cddb.c	19 Sep 2005 18:22:09 -0000	1.18
+++ cddb.c	6 Nov 2005 17:42:20 -0000	1.19
@@ -21,10 +21,18 @@
 #include <fcntl.h>
 #include <stdarg.h>
 #include <errno.h>
-#include <netdb.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef WIN32
+#ifdef __MINGW32__
+#define mkdir(a,b) mkdir(a)
+#endif
+#include <windows.h>
+#include <winsock2.h>
+#else
+#include <netdb.h>
 #include <sys/ioctl.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -32,6 +40,8 @@
 	#include <linux/cdrom.h>
 #elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
 	#include <sys/cdio.h>
+#elif defined(WIN32)
+        #include <ddk/ntddcdrm.h>
 #endif
 
 #include "cdd.h"
@@ -83,6 +93,41 @@
 	return tochdr.cdth_trk1;
 }
 
+#elif defined(WIN32)
+int
+read_toc(const char *dev) {
+        HANDLE drive;
+        DWORD r;
+        CDROM_TOC toc;
+        char device[10];
+        int i;
+
+        sprintf(device, "\\\\.\\%s", dev);
+        drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+
+        if(!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(CDROM_TOC), &r, 0)) {
+                mp_msg(MSGT_OPEN, MSGL_ERR, "Failed to read TOC.\n");
+                return 0;
+        }
+
+        for (i = toc.FirstTrack; i <= toc.LastTrack; i++) {
+                toc.FirstTrack = i;
+		cdtoc[i-1].min = toc.TrackData[i - 1].Address[1];
+		cdtoc[i-1].sec = toc.TrackData[i - 1].Address[2];
+		cdtoc[i-1].frame = toc.TrackData[i - 1].Address[3];
+		cdtoc[i-1].frame += cdtoc[i-1].min*60*75;
+		cdtoc[i-1].frame += cdtoc[i-1].sec*75;
+        }
+        toc.FirstTrack = 0xAA;
+        cdtoc[toc.LastTrack].min = toc.TrackData[toc.LastTrack].Address[1];
+        cdtoc[toc.LastTrack].sec = toc.TrackData[toc.LastTrack].Address[2];
+        cdtoc[toc.LastTrack].frame = toc.TrackData[toc.LastTrack].Address[3];
+        cdtoc[toc.LastTrack].frame += cdtoc[toc.LastTrack].min*60*75;
+        cdtoc[toc.LastTrack].frame += cdtoc[toc.LastTrack].sec*75;
+        CloseHandle(drive);
+        return toc.LastTrack;
+}
+
 #elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__DragonFly__)
 int 
 read_toc(const char *dev) {
@@ -281,7 +326,11 @@
 	
 	sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id);
 	
-	file_fd = open(file_name, O_RDONLY);
+	file_fd = open(file_name, O_RDONLY
+#ifdef WIN32
+	| O_BINARY
+#endif
+	);
 	if( file_fd<0 ) {
 		printf("No cache found\n");
 		return -1;
@@ -328,7 +377,11 @@
 	if( ret<0 ) {
 		// Directory not present, create it.
 		ret = mkdir( cddb_data->cache_dir, 0755 );
+#ifdef __MINGW32__
+		if( ret<0 && errno != EEXIST ) {
+#else
 		if( ret<0 ) {
+#endif
 			perror("mkdir");
 			printf("Failed to create directory %s\n", cddb_data->cache_dir );
 			return -1;
@@ -674,6 +727,12 @@
 	}
 	
 	home_dir = getenv("HOME");
+#ifdef __MINGW32__
+	if( home_dir==NULL ) home_dir = getenv("USERPROFILE");
+	if( home_dir==NULL ) home_dir = getenv("HOMEPATH");
+	// Last resort, store the cddb cache in the mplayer directory
+	if( home_dir==NULL ) home_dir = (char *)get_path("");
+#endif
 	if( home_dir==NULL ) {
 		cddb_data.cache_dir = NULL;
 	} else {

Index: cdd.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cdd.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- cdd.h	29 Oct 2002 09:18:53 -0000	1.2
+++ cdd.h	6 Nov 2005 17:42:20 -0000	1.3
@@ -1,8 +1,14 @@
 #ifndef __CDD_H__
 #define __CDD_H__
 
+#include "config.h"
+#ifndef HAVE_LIBCDIO
 #include <cdda_interface.h>
 #include <cdda_paranoia.h>
+#else
+#include <cdio/cdda.h>
+#include <cdio/paranoia.h>
+#endif
 
 typedef struct {
 	char cddb_hello[1024];	
@@ -48,8 +54,13 @@
 } cd_info_t;
 
 typedef struct {
+#ifndef HAVE_LIBCDIO
 	cdrom_drive* cd;
 	cdrom_paranoia* cdp;
+#else
+	cdrom_drive_t* cd;
+	cdrom_paranoia_t* cdp;
+#endif
 	int sector;
 	int start_sector;
 	int end_sector;




More information about the MPlayer-cvslog mailing list