[MPlayer-cvslog] CVS: main/libmpdemux cdda.c, 1.13, 1.14 cddb.c, 1.17, 1.18

Guillaume Poirier CVS syncmail at mplayerhq.hu
Mon Sep 19 20:22:12 CEST 2005


CVS change done by Guillaume Poirier CVS

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

Modified Files:
	cdda.c cddb.c 
Log Message:
Prints the number of tracks and MSF length for each track of an audio CD,
prints ID_CDDA_TRACK=N output showing the currently played track number
when -identify is given.
Patch by kiriuja < mplayer TIRET patches CHEZ en TIRET directo POIS net >
Doxygen comments by Guillaume POIRIER
Original thread:
Date: Sep 11, 2005 10:49 PM
Subject: Re: [MPlayer-dev-eng] [PATCH] -identify audio CD tracks


Index: cdda.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cdda.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- cdda.c	16 Dec 2003 07:35:04 -0000	1.13
+++ cdda.c	19 Sep 2005 18:22:09 -0000	1.14
@@ -81,6 +81,7 @@
   {NULL, NULL, 0, 0, 0, 0, NULL}
 };
 
+extern int cdd_identify(const char *dev);
 extern int cddb_resolve(const char *dev, char **xmcd_file);
 extern cd_info_t* cddb_parse_xmcd(char *xmcd_file);
 
@@ -112,7 +113,9 @@
   }
 
 #ifdef MPLAYER_NETWORK
-  if(strncmp(st->url,"cddb",4) == 0) {
+  // cdd_identify returns -1 if it cannot read the TOC,
+  // in which case there is no point in calling cddb_resolve
+  if(cdd_identify(p->device) >= 0 && strncmp(st->url,"cddb",4) == 0) {
     i = cddb_resolve(p->device, &xmcd_file);
     if(i == 0) {
       cddb_info = cddb_parse_xmcd(xmcd_file);
@@ -274,7 +277,9 @@
 		  cd_track = cd_info_get_track(p->cd_info, i+1);
 //printf("Track %d, sector=%d\n", i, p->sector-1);
 		  if( cd_track!=NULL ) {
-			  printf("\n%s\n", cd_track->name ); 
+			mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name); 
+			if (identify)
+				mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACK=%d\n", cd_track->track_nb);
 		  }
 		  break;
 	  }
@@ -315,7 +320,9 @@
 //printf("Track %d, sector=%d\n", seeked_track, sec);
 		  cd_track = cd_info_get_track(p->cd_info, seeked_track+1);
 		  if( cd_track!=NULL ) {
-			  printf("\n%s\n", cd_track->name ); 
+			  mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name);
+			  if (identify)
+			    mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACK=%d\n", cd_track->track_nb);
 		  }
 
 	}

Index: cddb.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cddb.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- cddb.c	25 May 2005 08:48:32 -0000	1.17
+++ cddb.c	19 Sep 2005 18:22:09 -0000	1.18
@@ -45,6 +45,7 @@
 stream_t* open_cdda(char *dev, char *track);
 
 static cd_toc_t cdtoc[100];
+static int cdtoc_last_track;
 
 #if defined(__linux__)
 int 
@@ -158,6 +159,39 @@
 }
 #endif
 
+/** 
+\brief Reads TOC from CD in the given device and prints the number of tracks
+       and the length of each track in minute:second:frame format.
+\param *dev the device to analyse
+\return if the command line -identify is given, returns the last track of
+        the TOC or -1 if the TOC can't be read,
+        otherwise just returns 0 and let cddb_resolve the TOC
+*/
+int cdd_identify(const char *dev)
+{
+	cdtoc_last_track = 0;
+	if (identify)
+	{
+		int i, min, sec, frame;
+		cdtoc_last_track = read_toc(dev);
+		if (cdtoc_last_track < 0) {
+			mp_msg(MSGT_OPEN, MSGL_ERR, "Failed to open %s device.\n", dev);
+			return -1;
+		}
+		mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACKS=%d\n", cdtoc_last_track);
+		for (i = 1; i <= cdtoc_last_track; i++)
+		{
+			frame = cdtoc[i].frame - cdtoc[i-1].frame;
+			sec = frame / 75;
+			frame -= sec * 75;
+			min = sec / 60;
+			sec -= min * 60;
+			mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACK_%d_MSF=%02d:%02d:%02d\n", i, min, sec, frame);
+		}
+	}
+	return cdtoc_last_track;
+}
+
 unsigned int 
 cddb_sum(int n) {
 	unsigned int ret;
@@ -619,14 +653,16 @@
 	char cddb_cache_dir[] = DEFAULT_CACHE_DIR;
 	char *home_dir = NULL;
 	cddb_data_t cddb_data;
-	int ret;
 
-	ret = read_toc(dev);
-	if( ret<0 ) {
+	if (cdtoc_last_track <= 0)
+	{
+	    cdtoc_last_track = read_toc(dev);
+	    if (cdtoc_last_track < 0) {
 		printf("Failed to open %s device.\n", dev);
 		return -1;
+	    }
 	}
-	cddb_data.tracks = ret;
+	cddb_data.tracks = cdtoc_last_track;
 	cddb_data.disc_id = cddb_discid(cddb_data.tracks);
 	cddb_data.anonymous = 1;	// Don't send user info by default
 




More information about the MPlayer-cvslog mailing list