[tracker] tracker-extract: Make MP3 module handle DLNA profiles



commit ee7a7bdd1b7a50eec3ba8e07e97cf9d971a89472
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 27 17:51:05 2011 +0200

    tracker-extract: Make MP3 module handle DLNA profiles
    
    In this custom extractor makes little sense to call any dlna
    library since we have already all necessary data at hand.

 src/tracker-extract/tracker-extract-mp3.c |   55 ++++++++++++++++++++++++-----
 1 files changed, 46 insertions(+), 9 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index e6c57c0..f5b3a69 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -470,6 +470,40 @@ id3v2tag_free (id3v2tag *tags)
 	g_free (tags->title3);
 }
 
+static gboolean
+guess_dlna_profile (gint          bitrate,
+                    gint          frequency,
+                    gint          mpeg_version,
+                    gint          layer_version,
+                    gint          n_channels,
+                    const gchar **dlna_profile,
+                    const gchar **dlna_mimetype)
+{
+	if (mpeg_version == MPEG_V1 &&
+	    layer_version == LAYER_3 &&
+	    (bitrate >= 32000 && bitrate <= 320000) &&
+	    (n_channels == 1 || n_channels == 2) &&
+	    (frequency == freq_table[0][0] ||
+	     frequency == freq_table[1][0] ||
+	     frequency == freq_table[2][0])) {
+		*dlna_profile = "MP3";
+		*dlna_mimetype = "audio/mpeg";
+		return TRUE;
+	}
+
+	if ((bitrate >= 8000 && bitrate <= 320000) &&
+	    (mpeg_version == MPEG_V1 || mpeg_version == MPEG_V2) &&
+	    (frequency == freq_table[0][0] || frequency == freq_table[0][1] ||
+	     frequency == freq_table[1][0] || frequency == freq_table[1][1] ||
+	     frequency == freq_table[2][0] || frequency == freq_table[2][1])) {
+		*dlna_profile = "MP3X";
+		*dlna_mimetype = "audio/mpeg";
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
 static char *
 read_id3v1_buffer (int     fd,
                    goffset size)
@@ -805,6 +839,7 @@ mp3_parse_header (const gchar          *data,
                   TrackerSparqlBuilder *metadata,
                   MP3Data              *filedata)
 {
+	const gchar *dlna_profile, *dlna_mimetype;
 	guint header;
 	gchar mpeg_ver = 0;
 	gchar layer_ver = 0;
@@ -819,6 +854,7 @@ mp3_parse_header (const gchar          *data,
 	guint frame_size;
 	guint frames = 0;
 	size_t pos = 0;
+	gint n_channels;
 
 	pos = seek_pos;
 
@@ -920,12 +956,10 @@ mp3_parse_header (const gchar          *data,
 	tracker_sparql_builder_predicate (metadata, "nfo:codec");
 	tracker_sparql_builder_object_string (metadata, "MPEG");
 
+	n_channels = ((header & ch_mask) == ch_mask) ? 1 : 2;
+
 	tracker_sparql_builder_predicate (metadata, "nfo:channels");
-	if ((header & ch_mask) == ch_mask) {
-		tracker_sparql_builder_object_int64 (metadata, 1);
-	} else {
-		tracker_sparql_builder_object_int64 (metadata, 2);
-	}
+	tracker_sparql_builder_object_int64 (metadata, n_channels);
 
 	avg_bps /= frames;
 
@@ -946,6 +980,13 @@ mp3_parse_header (const gchar          *data,
 	tracker_sparql_builder_predicate (metadata, "nfo:averageBitrate");
 	tracker_sparql_builder_object_int64 (metadata, avg_bps*1000);
 
+	if (guess_dlna_profile (bitrate, sample_rate,
+	                        mpeg_ver, layer_ver, n_channels,
+	                        &dlna_profile, &dlna_mimetype)) {
+		tracker_sparql_builder_predicate (metadata, "nmm:dlnaProfile");
+		tracker_sparql_builder_object_string (metadata, dlna_profile);
+	}
+
 	return TRUE;
 }
 
@@ -2397,10 +2438,6 @@ tracker_extract_get_metadata (const gchar          *uri,
 
 	g_free (md.album_uri);
 
-	/* FIXME We use a hardcoded value here for now. In reality there's a second option MP3X */
-	tracker_sparql_builder_predicate (metadata, "nmm:dlnaProfile");
-	tracker_sparql_builder_object_string (metadata, "MP3");
-
 	/* Get mp3 stream info */
 	mp3_parse (buffer, buffer_size, audio_offset, uri, metadata, &md);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]