--- gst-plugins-base1.0-1.2.4.orig/gst-libs/gst/audio/gstaudiocdsrc.c
+++ gst-plugins-base1.0-1.2.4/gst-libs/gst/audio/gstaudiocdsrc.c
@@ -1188,25 +1188,31 @@ gst_audio_cd_src_calculate_musicbrainz_d
   guchar digest[20];
   gchar *ptr;
   gchar tmp[9];
-  gulong i;
+  gulong i, last_track;
   guint leadout_sector;
   gsize digest_len;
 
   s = g_string_new (NULL);
 
-  leadout_sector =
-      src->priv->tracks[src->priv->num_tracks - 1].end + 1 + CD_MSF_OFFSET;
-
   /* generate SHA digest */
   sha = g_checksum_new (G_CHECKSUM_SHA1);
   g_snprintf (tmp, sizeof (tmp), "%02X", src->priv->tracks[0].num);
   g_string_append_printf (s, "%02X", src->priv->tracks[0].num);
   g_checksum_update (sha, (guchar *) tmp, 2);
 
+  for (last_track = src->priv->num_tracks - 1; last_track >= 0; last_track--) {
+    if (src->priv->tracks[last_track].is_audio) {
+      break;
+    }
+  }
+
+  leadout_sector =
+      src->priv->tracks[last_track].end + 1 + CD_MSF_OFFSET;
+
   g_snprintf (tmp, sizeof (tmp), "%02X",
-      src->priv->tracks[src->priv->num_tracks - 1].num);
+      src->priv->tracks[last_track].num);
   g_string_append_printf (s, " %02X",
-      src->priv->tracks[src->priv->num_tracks - 1].num);
+      src->priv->tracks[last_track].num);
   g_checksum_update (sha, (guchar *) tmp, 2);
 
   g_snprintf (tmp, sizeof (tmp), "%08X", leadout_sector);
@@ -1214,7 +1220,7 @@ gst_audio_cd_src_calculate_musicbrainz_d
   g_checksum_update (sha, (guchar *) tmp, 8);
 
   for (i = 0; i < 99; i++) {
-    if (i < src->priv->num_tracks) {
+    if (i < src->priv->num_tracks && src->priv->tracks[i].is_audio) {
       guint frame_offset = src->priv->tracks[i].start + CD_MSF_OFFSET;
 
       g_snprintf (tmp, sizeof (tmp), "%08X", frame_offset);
