Libgpod should return supported codecs from it's device

"[email protected]" <[email protected]>
Newsgroups gmane.comp.ipod.gtkpod
Message-ID <[email protected]>
Ok, so the root of this issue was started in:
https://bugzilla.gnome.org/show_bug.cgi?id=634140

After much examination I modified libgpod to return a GList of supported
codecs, read from SysInfoExtended.

This doesn't quite solve the problem but I think it's a step in the right
direction.

Forewarning, although I am a professional programmer and have been for the
last 8 years... I haven't actually touched linux in about 7 years up until
the past 2 months and everything I know in this area was learned in the past
month.

So I'd really appreciate any feedback anyone might have.

Also, when I was trying to test this with Rhythmbox I ran into a serious
issue attempting to link the new library...  I ended up having to install
the new version of libgpod over top of the old version...  NOthing I did
would influence which libgpod version got linked too.

I thought the variable for this sort of thing was CPPFLAGS.  Here's the
flags I used in rhythmbox:
--enable-maintainer-mode --enable-uninstalled-build 'CFLAGS=-g -O0'
'CXXFLAGS=-g -O0' 'JFLAGS=-g -O0' 'FFLAGS=-g -O0' CPPFLAGS='-L
/usr/local/lib/ -I /usr/local/include/gpod-1.0/'

and here's my stack overflow question when I couldn't figure it out:
http://stackoverflow.com/questions/4391649/how-to-force-linking-on-linux-libgpod-and-rhythmbox

I'd really appreciate any insight.

Patch Attached

------------------------------------------------------------------------------
This SF Dev2Dev email is sponsored by:

WikiLeaks The End of the Free Internet
http://p.sf.net/sfu/therealnews-com

_______________________________________________
Gtkpod-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-devel
libgpod_AudioCodecs.patch (text/x-patch, 6.9 KB)
diff --git a/src/itdb.h b/src/itdb.h
index 2cd6f5a..f8809a4 100644
--- a/src/itdb.h
+++ b/src/itdb.h
@@ -1859,6 +1859,7 @@ gboolean itdb_device_supports_podcast (const Itdb_Device *device);
 const gchar *itdb_info_get_ipod_model_name_string (Itdb_IpodModel model);
 const gchar *itdb_info_get_ipod_generation_string (Itdb_IpodGeneration generation);
 gchar *itdb_device_get_uuid(const Itdb_Device *device);
+GList *itdb_device_get_supported_audio_codecs(const Itdb_Device *device);
 
 /* track functions */
 Itdb_Track *itdb_track_new (void);
@@ -2032,4 +2033,4 @@ gboolean itdb_init_ipod (const gchar *mountpoint,
 
 G_END_DECLS
 
-#endif
+#endif
\ No newline at end of file
diff --git a/src/itdb_device.c b/src/itdb_device.c
index fd256b4..65f52c6 100644
--- a/src/itdb_device.c
+++ b/src/itdb_device.c
@@ -30,8 +30,6 @@
 |  $Id$
 */
 #include <config.h>
-
-#include "db-itunes-parser.h"
 #include "itdb_device.h"
 #include "itdb_private.h"
 #include <ctype.h>
@@ -1704,7 +1702,14 @@ gboolean itdb_device_supports_artwork (const Itdb_Device *device)
     return (formats != NULL);
 }
 
+GList *itdb_device_get_supported_audio_codecs (const Itdb_Device *device)
+{
+    GList *formats = NULL;
+	
+    formats = itdb_sysinfo_properties_get_audio_codecs(device->sysinfo_extended);
 
+	return (formats);
+}
 /**
  * itdb_device_supports_video:
  * @device: an #Itdb_Device
@@ -2287,4 +2292,4 @@ enum ItdbShadowDBVersion itdb_device_get_shadowdb_version (const Itdb_Device *de
     }
 
     return version;
-}
+}
\ No newline at end of file
diff --git a/src/itdb_device.h b/src/itdb_device.h
index 465d398..f6f2c0e 100644
--- a/src/itdb_device.h
+++ b/src/itdb_device.h
@@ -192,4 +192,4 @@ itdb_ipod_info_from_serial (const char *serial);
 
 G_END_DECLS
 
-#endif
+#endif
\ No newline at end of file
diff --git a/src/itdb_sysinfo_extended_parser.c b/src/itdb_sysinfo_extended_parser.c
index 0a0dc5b..9b6a480 100644
--- a/src/itdb_sysinfo_extended_parser.c
+++ b/src/itdb_sysinfo_extended_parser.c
@@ -109,6 +109,7 @@ struct _SysInfoIpodProperties {
         gint games_platform_version;
         gint rental_clock_bias;
 	gboolean sqlite_db;
+	GList * audio_codecs;
 };
 
 static gint64 get_int64 (GHashTable *dict, const char *key)
@@ -330,6 +331,7 @@ void itdb_sysinfo_properties_free (SysInfoIpodProperties *props)
     g_list_free (props->photo_formats);
     g_list_foreach (props->chapter_image_formats, (GFunc)free_image_format, NULL);
     g_list_free (props->chapter_image_formats);
+	g_list_free (props->audio_codecs);
     free_struct (sysinfo_ipod_properties_fields_mapping, props);
 }
 
@@ -378,12 +380,18 @@ static void dump_image_format (Itdb_ArtworkFormat *format)
     g_print ("PixelFormat: %d\n", format->format); 
 }
 
+static void dump_charstar (const char * charstar)
+{
+	g_print ("AudioCodec: %s\n", charstar); 
+}
+
 void itdb_sysinfo_properties_dump (SysInfoIpodProperties *props)
 {
     dump_struct (sysinfo_ipod_properties_fields_mapping, props);
     g_list_foreach (props->artwork_formats, (GFunc)dump_image_format, NULL);
     g_list_foreach (props->photo_formats, (GFunc)dump_image_format, NULL);
     g_list_foreach (props->chapter_image_formats, (GFunc)dump_image_format, NULL);
+	g_list_foreach (props->audio_codecs, (GFunc)dump_charstar, NULL);
 }
 
 static gboolean
@@ -506,6 +514,41 @@ static GList *parse_one_formats_list (GHashTable *sysinfo_dict,
     return formats;
 }
 
+static GList *parse_one_audio_type_list (GHashTable *sysinfo_dict, 
+                                       	const char *key)
+{
+    GValue *to_parse;
+	GList *formatKeys = NULL;
+    GList *formats = NULL;
+    GHashTable *hashtable;
+	gint i;
+	gint length;
+	char * format_string = NULL;
+	
+    to_parse = g_hash_table_lookup (sysinfo_dict, key);
+
+    if (to_parse == NULL) {
+        return NULL;
+    }
+	
+    if (!G_VALUE_HOLDS (to_parse, G_TYPE_HASH_TABLE)) {
+        return NULL;
+    }
+    hashtable = (GHashTable*)g_value_get_boxed (to_parse);
+
+	formatKeys = g_hash_table_get_keys(hashtable);
+	length = g_list_length (formatKeys);
+	
+	for (i = 0; i < length; i ++) {
+		format_string = (char*) g_list_nth_data(formatKeys, i);
+		formats = g_list_prepend(formats, g_strdup(format_string));
+	}
+	
+	g_hash_table_remove (sysinfo_dict, key);
+	
+    return formats;
+}
+
 static SysInfoIpodProperties *g_value_to_ipod_properties (GValue *value)
 {
     GHashTable *sysinfo_dict;
@@ -521,6 +564,8 @@ static SysInfoIpodProperties *g_value_to_ipod_properties (GValue *value)
                                                    "ImageSpecifications");
     props->chapter_image_formats = parse_one_formats_list (sysinfo_dict,
                                                            "ChapterImageSpecs");
+	props->audio_codecs = parse_one_audio_type_list (sysinfo_dict,
+	                                            	"AudioCodecs");
     dict_to_struct (sysinfo_dict,
                     sysinfo_ipod_properties_fields_mapping,
                     props);
@@ -670,6 +715,33 @@ itdb_sysinfo_properties_get_chapter_image_formats (const SysInfoIpodProperties *
 }
 
 /**
+ * itdb_sysinfo_properties_get_audio_codecs:
+ * @props: a #SysInfoIpodProperties structure
+ *
+ * Returns: a #GList of #audio_codecs giving the name of the codec
+ * formats supported by the iPod described in @props. The returned list 
+ * is not constrained.
+ */
+GList *
+itdb_sysinfo_properties_get_audio_codecs (const SysInfoIpodProperties *props)
+{
+	GList *formats = NULL;
+	char *format_string;
+	int i;
+	int length;
+	
+    g_return_val_if_fail (props != NULL, NULL);
+	length = g_list_length (props->audio_codecs);
+	
+	for (i = 0; i < length; i ++) {
+	format_string = (char*) g_list_nth_data (props->audio_codecs , i);
+	formats = g_list_prepend(formats, g_strdup(format_string));
+	}
+	
+    return formats;
+}
+
+/**
  * itdb_sysinfo_properties_supports_sparse_artwork:
  * @props: a #SysInfoIpodProperties structure
  *
@@ -731,4 +803,4 @@ itdb_sysinfo_properties_get_shadow_db_version (const SysInfoIpodProperties *prop
 {
    g_return_val_if_fail (props != NULL, 0);
    return props->shadowdb_version;
-}
+}
\ No newline at end of file
diff --git a/src/itdb_sysinfo_extended_parser.h b/src/itdb_sysinfo_extended_parser.h
index 5ac3bae..6ec368d 100644
--- a/src/itdb_sysinfo_extended_parser.h
+++ b/src/itdb_sysinfo_extended_parser.h
@@ -75,6 +75,9 @@ itdb_sysinfo_properties_get_db_version (const SysInfoIpodProperties *props);
 G_GNUC_INTERNAL gint
 itdb_sysinfo_properties_get_shadow_db_version (const SysInfoIpodProperties *props);
 
+G_GNUC_INTERNAL GList *
+itdb_sysinfo_properties_get_audio_codecs (const SysInfoIpodProperties *props);
+                                          
 G_END_DECLS
 
-#endif
+#endif
\ No newline at end of file
diff --git a/tests/get-timezone.c b/tests/get-timezone.c
index e453ca3..e3b4d0f 100644
--- a/tests/get-timezone.c
+++ b/tests/get-timezone.c
@@ -36,6 +36,6 @@ int main (int argc, char **argv)
     itdb_device_set_mountpoint (device, mountpoint);
 
     g_print ("Timezone: UTC%+d\n", device->timezone_shift/3600);
-
+	
     return 0;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.