changeset 16524:83d101e1bedb

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
author gpoirier
date Mon, 19 Sep 2005 18:22:09 +0000
parents fc520a27131d
children 4144a695f602
files libmpdemux/cdda.c libmpdemux/cddb.c
diffstat 2 files changed, 50 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/cdda.c	Mon Sep 19 17:57:41 2005 +0000
+++ b/libmpdemux/cdda.c	Mon Sep 19 18:22:09 2005 +0000
@@ -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);
 		  }
 
 	}
--- a/libmpdemux/cddb.c	Mon Sep 19 17:57:41 2005 +0000
+++ b/libmpdemux/cddb.c	Mon Sep 19 18:22:09 2005 +0000
@@ -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