[Xfce4-commits] <xfce4-volumed:master> Added a volume channel number check before calling gst_mixer_get_volume

Steve Dodier noreply at xfce.org
Thu Nov 18 17:00:03 CET 2010


Updating branch refs/heads/master
         to 4ad92331c550cdbda9b9d299465f9fab3568cd94 (commit)
       from ffa0271f280f7234d7ab1250f8ce9484390ef302 (commit)

commit 4ad92331c550cdbda9b9d299465f9fab3568cd94
Author: Steve Dodier <sidnioulz at gmail.com>
Date:   Thu Nov 18 16:58:44 2010 +0100

    Added a volume channel number check before calling gst_mixer_get_volume

 ChangeLog       |    3 +++
 src/xvd_mixer.c |   47 +++++++++++++++++++++++++++++------------------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8dcb950..21bbda5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
 2010-11-18  Steve Dodier <sidnioulz at gmail.com>
+	* Check for volume channels before getting a GStreamer track's volume (fixes lp #667617)
+
+2010-11-18  Steve Dodier <sidnioulz at gmail.com>
 	* Add a value check incase a GStreamer track has a volume range of 0 (fixes lp #624520)
 
 2010-11-18  Steve Dodier <sidnioulz at gmail.com>
diff --git a/src/xvd_mixer.c b/src/xvd_mixer.c
index 1cb7977..cd7c006 100644
--- a/src/xvd_mixer.c
+++ b/src/xvd_mixer.c
@@ -155,10 +155,16 @@ void
 xvd_mixer_init_volume(XvdInstance *Inst)
 {
 	if ((Inst->card) && (Inst->track)) {
-		gint *volumes = g_malloc (sizeof (gint) * Inst->track->num_channels);
-		gst_mixer_get_volume (GST_MIXER (Inst->card), Inst->track, volumes);
-		xvd_calculate_avg_volume (Inst, volumes, Inst->track->num_channels);
-		g_free (volumes);
+		if (Inst->track->num_channels) {
+			gint *volumes = g_malloc (sizeof (gint) * Inst->track->num_channels);
+			gst_mixer_get_volume (GST_MIXER (Inst->card), Inst->track, volumes);
+			xvd_calculate_avg_volume (Inst, volumes, Inst->track->num_channels);
+			g_free (volumes);
+		} else {
+			g_debug ("Current track has no volume channels, defaulting volume to 0.\n");
+			xvd_calculate_avg_volume (Inst, NULL, Inst->track->num_channels);
+		}
+
 		Inst->muted = (GST_MIXER_TRACK_HAS_FLAG (Inst->track, GST_MIXER_TRACK_MUTE));
 	}
 }
@@ -389,26 +395,31 @@ xvd_mixer_change_volume(XvdInstance *Inst,
 						gint step)
 {
 	if ((Inst->card) && (Inst->track)) {
-		gint i;
-		gint *volumes = g_malloc (sizeof (gint) * Inst->track->num_channels);
+		if(Inst->track->num_channels) {
+			gint i;
+			gint *volumes = g_malloc (sizeof (gint) * Inst->track->num_channels);
 		
-		gst_mixer_get_volume (GST_MIXER (Inst->card), Inst->track, volumes);
+			gst_mixer_get_volume (GST_MIXER (Inst->card), Inst->track, volumes);
 		
-		for (i=0; i<Inst->track->num_channels; i++) {
-			volumes[i] += _nearest_int ((gdouble)(step * (Inst->track->max_volume - Inst->track->min_volume)) / 100.0);
+			for (i=0; i<Inst->track->num_channels; i++) {
+				volumes[i] += _nearest_int ((gdouble)(step * (Inst->track->max_volume - Inst->track->min_volume)) / 100.0);
 			
-			if (volumes[i] > Inst->track->max_volume)
-				volumes[i] = Inst->track->max_volume;
+				if (volumes[i] > Inst->track->max_volume)
+					volumes[i] = Inst->track->max_volume;
 				
-			if (volumes[i] < Inst->track->min_volume)
-				volumes[i] = Inst->track->min_volume;
-		}
-		xvd_calculate_avg_volume (Inst, volumes, Inst->track->num_channels);
+				if (volumes[i] < Inst->track->min_volume)
+					volumes[i] = Inst->track->min_volume;
+			}
+			xvd_calculate_avg_volume (Inst, volumes, Inst->track->num_channels);
 		
-		gst_mixer_set_volume (GST_MIXER (Inst->card), Inst->track, volumes);
-		g_free (volumes);
+			gst_mixer_set_volume (GST_MIXER (Inst->card), Inst->track, volumes);
+			g_free (volumes);
 		
-		return TRUE;
+			return TRUE;
+		} else {
+			g_debug ("Current track has no volume channels, cannot change volume.\n");
+			return FALSE;
+		}
 	}
 	return FALSE;
 }



More information about the Xfce4-commits mailing list