|
From: <ny...@us...> - 2007-09-12 17:04:51
|
Revision: 412
http://pmplib.svn.sourceforge.net/pmplib/?rev=412&view=rev
Author: nyaochi
Date: 2007-09-12 10:04:54 -0700 (Wed, 12 Sep 2007)
Log Message:
-----------
- Added mhsd (type = 4).
Modified Paths:
--------------
trunk/pmplib/lib/pmp_ipod/ipod.c
trunk/pmplib/lib/pmp_ipod/itunesdb.c
Modified: trunk/pmplib/lib/pmp_ipod/ipod.c
===================================================================
--- trunk/pmplib/lib/pmp_ipod/ipod.c 2007-09-12 16:20:00 UTC (rev 411)
+++ trunk/pmplib/lib/pmp_ipod/ipod.c 2007-09-12 17:04:54 UTC (rev 412)
@@ -535,6 +535,22 @@
return ret;
}
+static int comp_album_for_list(const void *_x, const void *_y)
+{
+ int ret = 0;
+ const sorted_index_t *xi = (const sorted_index_t*)_x;
+ const sorted_index_t *yi = (const sorted_index_t*)_y;
+ const pmp_music_record_t* base = (const pmp_music_record_t*)xi->base;
+ const pmp_music_record_t* x = &base[xi->index];
+ const pmp_music_record_t* y = &base[yi->index];
+
+ ret = comp_string(x->album, y->album);
+ if (ret == 0) {
+ ret = comp_string(x->artist, y->artist);
+ }
+ return ret;
+}
+
static int comp_artist(const void *_x, const void *_y)
{
int ret = 0;
@@ -583,6 +599,59 @@
return ret;
}
+static int set_album_list(itunesdb_chunk_t* mhla, const pmp_music_record_t* records, int num_records)
+{
+ int i;
+ int ret = 0;
+ const ucs2char_t* prev_album = NULL;
+ const ucs2char_t* prev_artist = NULL;
+ itunesdb_chunk_t *mhod = NULL, *mhia = NULL;
+ itunesdb_mhia_t *mhia_data = NULL;
+ sorted_index_t* si = (sorted_index_t*)calloc(num_records, sizeof(sorted_index_t));
+
+ if (!si) {
+ return IPODE_OUTOFMEMORY;
+ }
+ for (i = 0;i < num_records;++i) {
+ si[i].base = records;
+ si[i].index = i;
+ }
+ qsort(si, num_records, sizeof(si[0]), comp_album_for_list);
+
+ for (i = 0;i < num_records;++i) {
+ const pmp_music_record_t* cur = &records[si[i].index];
+ const ucs2char_t* album = cur->album;
+ const ucs2char_t* artist = cur->artist;
+
+ if (prev_album == NULL || ucs2cmp(prev_album, album) != 0) {
+ mhia = itunesdb_new_child(mhla);
+ if (ret = itunesdb_init(mhia, "mhia", NULL)) return ret;
+ mhia_data = (itunesdb_mhia_t*)mhia->data;
+
+ mhod = itunesdb_new_child(mhia);
+ if (mhod) {
+ if (ret = itunesdb_init(mhod, "mhod", "album_albumlist")) return ret;
+ if (ret = itunesdb_set_mhod_string(mhod, album)) return ret;
+ }
+
+ mhod = itunesdb_new_child(mhia);
+ if (mhod) {
+ if (ret = itunesdb_init(mhod, "mhod", "artist_albumlist")) return ret;
+ if (ret = itunesdb_set_mhod_string(mhod, artist)) return ret;
+ }
+
+ mhia_data->num_children = 2;
+ mhia_data->album_id = i;
+ mhia_data->timestamp = 0;
+ mhia_data->unknown1 = 2;
+ }
+
+ prev_album = album;
+ }
+
+ return 0;
+}
+
static int set_master_playlist(itunesdb_chunk_t* mhyp, const pmp_music_record_t* records, int num_records)
{
int i;
@@ -807,6 +876,7 @@
int i;
int ret = 0;
itunesdb_chunk_t *mhbd = NULL, *mhsd = NULL;
+ itunesdb_chunk_t *mhla = NULL;
itunesdb_chunk_t *mhlt = NULL, *mhit = NULL;
itunesdb_chunk_t *mhlp = NULL, *mhyp = NULL;
itunesdb_mhbd_t* mhbd_data = NULL;
@@ -820,7 +890,25 @@
mhbd_data = (itunesdb_mhbd_t*)mhbd->data;
/* Construct "mhsd" chunk with album_list type (type = 4). */
+ mhsd = itunesdb_new_child(mhbd);
+ if (mhsd) {
+ itunesdb_mhsd_t* mhsd_data = NULL;
+ if (ret = itunesdb_init(mhsd, "mhsd", NULL)) return ret;
+ mhsd_data = (itunesdb_mhsd_t*)mhsd->data;
+ mhsd_data->type = 4; /* album_list type. */
+ /* Construct "mhla" chunk. */
+ mhla = itunesdb_new_child(mhsd);
+ if (mhla) {
+ if (ret = itunesdb_init(mhla, "mhla", NULL)) return ret;
+ if (ret = set_album_list(mhla, records, num_records)) return ret;
+ } else {
+ return IPODE_FAILEDNEWCHUNK;
+ }
+ } else {
+ return IPODE_FAILEDNEWCHUNK;
+ }
+
/* Construct "mhsd" chunk with track type (type = 1). */
mhsd = itunesdb_new_child(mhbd);
if (mhsd) {
Modified: trunk/pmplib/lib/pmp_ipod/itunesdb.c
===================================================================
--- trunk/pmplib/lib/pmp_ipod/itunesdb.c 2007-09-12 16:20:00 UTC (rev 411)
+++ trunk/pmplib/lib/pmp_ipod/itunesdb.c 2007-09-12 17:04:54 UTC (rev 412)
@@ -960,7 +960,7 @@
}
/* Calculate chunk->overall_size. */
- if (strncmp(chunk->id, "mhlt", 4) == 0 || strncmp(chunk->id, "mhlp", 4) == 0) {
+ if (strncmp(chunk->id, "mhla", 4) == 0 || strncmp(chunk->id, "mhlt", 4) == 0 || strncmp(chunk->id, "mhlp", 4) == 0) {
/* chunk->overall_size represents the number of children for "mhlt" and "mhlp" chunks */
chunk->overall_size = chunk->num_children;
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|