changeset 1958:2db72dd92ee3

Use glib types and functions in some places.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Oct 2007 06:26:10 +0300
parents 0d2f57214b0c
children 3fef1171cd6c
files src/cdaudio-ng/cdaudio-ng.c src/cdaudio-ng/cdaudio-ng.h src/cdaudio-ng/configure.c src/cdaudio-ng/configure.h
diffstat 4 files changed, 36 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/cdaudio-ng/cdaudio-ng.c	Tue Oct 02 03:53:19 2007 +0300
+++ b/src/cdaudio-ng/cdaudio-ng.c	Tue Oct 02 06:26:10 2007 +0300
@@ -241,7 +241,7 @@
 		}
 
 			/* check if the requested track actually exists on the current audio cd */
-		int trackno = find_trackno_from_filename(filename);
+		gint trackno = find_trackno_from_filename(filename);
 		if (trackno < firsttrackno || trackno > lasttrackno) {
 			if (debug)
 				printf("cdaudio-ng: \"%s\" is not our file\n", filename);
@@ -280,7 +280,7 @@
 		}
 	}
 	else {
-		char **ppcd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
+		gchar **ppcd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
 		pcdio = NULL;
 		if (ppcd_drives != NULL && *ppcd_drives != NULL) { /* we have at least one audio capable cd drive */
 			pcdio = cdio_open(*ppcd_drives, DRIVER_UNKNOWN);
@@ -321,10 +321,9 @@
 	if (debug)
 		printf("cdaudio-ng: first track is %d and last track is %d\n", firsttrackno, lasttrackno);
 
-	if (trackinfo != NULL) /* if a previously allocated track information exists, we free it */
-		free(trackinfo);
-	trackinfo = (trackinfo_t *) malloc(sizeof(trackinfo_t) * (lasttrackno + 1));
-	int trackno;
+	g_free(trackinfo);
+	trackinfo = (trackinfo_t *) g_new(trackinfo_t, (lasttrackno + 1));
+	gint trackno;
 
 	trackinfo[0].startlsn = cdio_get_track_lsn(pcdrom_drive->p_cdio, 0);
 	trackinfo[0].endlsn = cdio_get_track_last_lsn(pcdrom_drive->p_cdio, CDIO_CDROM_LEADOUT_TRACK);
@@ -476,7 +475,7 @@
 void cdaudio_play_file(InputPlayback *pinputplayback)
 {
 	Tuple *tuple;
-	char *title;
+	gchar *title;
 
 	if (debug)
 		printf("cdaudio-ng: cdaudio_play_file(\"%s\")\n", pinputplayback->filename);
@@ -517,8 +516,8 @@
 	title = tuple_formatter_make_title_string(tuple, get_gentitle_format());
 
 	inputplugin.set_info(title, calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn), 1411200, 44100, 2);
-	free(title); title = NULL;
-	tuple_free(tuple); tuple = NULL;
+	g_free(title);
+	tuple_free(tuple);
 
 	if (use_dae) {
 		if (debug)
@@ -539,7 +538,7 @@
 		if (debug)
 			printf("cdaudio-ng: starting dae thread...\n");
 		*/
-		pdae_params = (dae_params_t *) malloc(sizeof(dae_params_t));
+		pdae_params = (dae_params_t *) g_new(dae_params_t, 1);
 		pdae_params->startlsn = trackinfo[trackno].startlsn;
 		pdae_params->endlsn = trackinfo[trackno].endlsn;
 		pdae_params->pplayback = pinputplayback;
@@ -582,7 +581,7 @@
 	if (use_dae) {
 		if (pdae_params != NULL) {
 			g_thread_join(pdae_params->thread);
-			free(pdae_params);
+			g_free(pdae_params);
 			pdae_params = NULL;
 		}
 	}
@@ -633,7 +632,7 @@
 		}
 	}
 	else {
-		int newstartlsn = trackinfo[playing_track].startlsn + time * 75;
+		gint newstartlsn = trackinfo[playing_track].startlsn + time * 75;
 		msf_t startmsf, endmsf;
 		cdio_lsn_to_msf(newstartlsn, &startmsf);
 		cdio_lsn_to_msf(trackinfo[playing_track].endlsn, &endmsf);
@@ -660,7 +659,7 @@
 			cleanup_on_error();
 			return 0;
 		}
-		int currlsn = cdio_msf_to_lsn(&subchannel.abs_addr);
+		gint currlsn = cdio_msf_to_lsn(&subchannel.abs_addr);
 
 			/* check to see if we have reached the end of the song */
 		if (currlsn == trackinfo[playing_track].endlsn)
@@ -736,7 +735,7 @@
 		pcdio = NULL;
 	}
 	if (trackinfo != NULL) {
-		free(trackinfo);
+		g_free(trackinfo);
 		trackinfo = NULL;
 	}
 	playing_track = -1;
@@ -760,7 +759,7 @@
 	if (debug)
 		printf("cdaudio-ng: cdaudio_get_song_info(\"%s\")\n", filename);
 
-	int trackno = find_trackno_from_filename(filename);
+	gint trackno = find_trackno_from_filename(filename);
 	Tuple *tuple = create_tuple_from_trackinfo(filename);
 
 	if(tuple) {
@@ -819,7 +818,7 @@
 		return NULL;
 
 	Tuple *tuple = tuple_new_from_filename(filename);
-	int trackno = find_trackno_from_filename(filename);
+	gint trackno = find_trackno_from_filename(filename);
 
 	if (trackno < firsttrackno || trackno > lasttrackno)
 		return NULL;
@@ -847,14 +846,14 @@
 
 void dae_play_loop(dae_params_t *pdae_params)
 {
-	unsigned char *buffer = (unsigned char *) malloc(CDDA_DAE_FRAMES * CDIO_CD_FRAMESIZE_RAW);
+	guchar *buffer = g_new(guchar, CDDA_DAE_FRAMES * CDIO_CD_FRAMESIZE_RAW);
 
 	if (debug)
 		printf("cdaudio-ng: dae started\n");
 	cdio_lseek(pcdio, pdae_params->startlsn * CDIO_CD_FRAMESIZE_RAW, SEEK_SET);
 
 	gboolean output_paused = FALSE;
-	int read_error_counter = 0;
+	gint read_error_counter = 0;
 
 	//pdae_params->endlsn += 75 * 3;
 
@@ -867,7 +866,7 @@
 				pdae_params->pplayback->output->pause(TRUE);
 				output_paused = TRUE;
 			}
-			usleep(1000);
+			g_usleep(1000);
 			continue;
 		}
 		else {
@@ -883,7 +882,7 @@
 		if (pdae_params->seektime != -1) {
 			if (debug)
 				printf("cdaudio-ng: requested seek to %d ms\n", pdae_params->seektime);
-			int newlsn = pdae_params->startlsn + pdae_params->seektime * 75 / 1000;
+			gint newlsn = pdae_params->startlsn + pdae_params->seektime * 75 / 1000;
 			cdio_lseek(pcdio, newlsn * CDIO_CD_FRAMESIZE_RAW, SEEK_SET);
 			pdae_params->pplayback->output->flush(pdae_params->seektime);
 			pdae_params->currlsn = newlsn;
@@ -891,7 +890,7 @@
 		}
 
 			/* compute the actual number of sectors to read */
-		int lsncount = CDDA_DAE_FRAMES <= (pdae_params->endlsn - pdae_params->currlsn + 1) ? CDDA_DAE_FRAMES : (pdae_params->endlsn - pdae_params->currlsn + 1);
+		gint lsncount = CDDA_DAE_FRAMES <= (pdae_params->endlsn - pdae_params->currlsn + 1) ? CDDA_DAE_FRAMES : (pdae_params->endlsn - pdae_params->currlsn + 1);
 			/* check too see if we have reached the end of the song */
 		if (lsncount <= 0) {
 			sleep(3);
@@ -910,11 +909,11 @@
 		else
 			read_error_counter = 0;
 
-		int remainingbytes = lsncount * CDIO_CD_FRAMESIZE_RAW;
-		unsigned char *bytebuff = buffer;
+		gint remainingbytes = lsncount * CDIO_CD_FRAMESIZE_RAW;
+		guchar *bytebuff = buffer;
 		while (pdae_params->pplayback->playing && remainingbytes > 0 && pdae_params->seektime == -1) {
 				/* compute the actual number of bytes to play */
-			int bytecount = CDIO_CD_FRAMESIZE_RAW <= remainingbytes ? CDIO_CD_FRAMESIZE_RAW : remainingbytes;
+			gint bytecount = CDIO_CD_FRAMESIZE_RAW <= remainingbytes ? CDIO_CD_FRAMESIZE_RAW : remainingbytes;
 				/* wait until the output buffer has enough room */
 			while (pdae_params->pplayback->playing && pdae_params->pplayback->output->buffer_free() < bytecount && pdae_params->seektime == -1)
 				usleep(1000);
@@ -934,20 +933,20 @@
 	is_paused = FALSE;
 
 	pdae_params->pplayback->output->close_audio();
-	free(buffer);
+	g_free(buffer);
 }
 
-int calculate_track_length(int startlsn, int endlsn)
+gint calculate_track_length(gint startlsn, gint endlsn)
 {
 	return ((endlsn - startlsn + 1) * 1000) / 75;
 }
 
-int find_trackno_from_filename(char *filename)
+gint find_trackno_from_filename(gchar *filename)
 {
+	gchar tracknostr[3];
 	if ((filename == NULL) || strlen(filename) <= 6)
 		return -1;
 
-	char tracknostr[3];
 	strncpy(tracknostr, filename + strlen(filename) - 6, 2);
 	tracknostr[2] = '\0';
 	return strtol(tracknostr, NULL, 10);
@@ -960,7 +959,7 @@
 	}
 
 	if (trackinfo != NULL) {
-		free(trackinfo);
+		g_free(trackinfo);
 		trackinfo = NULL;
 	}
 }
--- a/src/cdaudio-ng/cdaudio-ng.h	Tue Oct 02 03:53:19 2007 +0300
+++ b/src/cdaudio-ng/cdaudio-ng.h	Tue Oct 02 06:26:10 2007 +0300
@@ -30,9 +30,9 @@
 
 typedef struct {
 
-	char				performer[DEF_STRING_LEN];
-	char				name[DEF_STRING_LEN];
-	char				genre[DEF_STRING_LEN];
+	gchar				performer[DEF_STRING_LEN];
+	gchar				name[DEF_STRING_LEN];
+	gchar				genre[DEF_STRING_LEN];
 	lsn_t				startlsn;
 	lsn_t				endlsn;
 
--- a/src/cdaudio-ng/configure.c	Tue Oct 02 03:53:19 2007 +0300
+++ b/src/cdaudio-ng/configure.c	Tue Oct 02 06:26:10 2007 +0300
@@ -49,7 +49,7 @@
 static void				gui_to_values();
 
 
-void configure_set_variables(/*gboolean *_usedae, */int *_limitspeed, gboolean *_usecdtext, gboolean *_usecddb, char *_device, gboolean *_debug, char *_cddbserver, int *_cddbport)
+void configure_set_variables(/*gboolean *_usedae, */gint *_limitspeed, gboolean *_usecdtext, gboolean *_usecddb, gchar *_device, gboolean *_debug, gchar *_cddbserver, gint *_cddbport)
 {
 	/*usedae = _usedae;*/
 	limitspeed = _limitspeed;
@@ -214,6 +214,8 @@
 
 void values_to_gui()
 {
+	gchar portstr[16];
+
 	/*gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usedaecheckbutton), *usedae);*/
 
 	/*gtk_widget_set_sensitive(limitcheckbutton, *usedae);*/
@@ -225,8 +227,7 @@
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usecdtextcheckbutton), *usecdtext);
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usecddbcheckbutton), *usecddb);
 
-	char portstr[10];
-	sprintf(portstr, "%d", *cddbport);
+	g_snprintf(portstr, sizeof(portstr), "%d", *cddbport);
 	gtk_entry_set_text(GTK_ENTRY(cddbserverentry), cddbserver);
 	gtk_entry_set_text(GTK_ENTRY(cddbportentry), portstr);
 	gtk_widget_set_sensitive(cddbserverentry, *usecddb);
--- a/src/cdaudio-ng/configure.h	Tue Oct 02 03:53:19 2007 +0300
+++ b/src/cdaudio-ng/configure.h	Tue Oct 02 06:26:10 2007 +0300
@@ -2,7 +2,7 @@
 #ifndef CONFIGURE_H
 #define CONFIGURE_H
 
-void				configure_set_variables(/*gboolean *usedae, */int *limitspeed, gboolean *usecdtext, gboolean *usecddb, char *device, gboolean *debug, char *cddbserver, int *cddbport);
+void				configure_set_variables(/*gboolean *usedae, */gint *limitspeed, gboolean *usecdtext, gboolean *usecddb, char *device, gboolean *debug, gchar *cddbserver, gint *cddbport);
 void				configure_create_gui();
 void				configure_show_gui();