|
From: <ny...@us...> - 2007-01-26 03:44:58
|
Revision: 282
http://svn.sourceforge.net/pmplib/?rev=282&view=rev
Author: nyaochi
Date: 2007-01-25 19:44:58 -0800 (Thu, 25 Jan 2007)
Log Message:
-----------
Synchronize pmp_portalplayer1 with the latest API.
Modified Paths:
--------------
trunk/pmplib/lib/pmp/pmp.c
trunk/pmplib/lib/pmp_portalplayer1/playlist.c
trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.c
trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.vcproj
trunk/pmplib/lib/pmp_portalplayer1/pp1db.h
Modified: trunk/pmplib/lib/pmp/pmp.c
===================================================================
--- trunk/pmplib/lib/pmp/pmp.c 2007-01-26 02:36:01 UTC (rev 281)
+++ trunk/pmplib/lib/pmp/pmp.c 2007-01-26 03:44:58 UTC (rev 282)
@@ -78,6 +78,7 @@
for (i = 0;i < num_records;++i) {
pmplib_record_clone(&dst[i], &src[i]);
}
+ return 0;
}
void pmplib_playlist_init(pmp_playlist_t* playlist)
Modified: trunk/pmplib/lib/pmp_portalplayer1/playlist.c
===================================================================
--- trunk/pmplib/lib/pmp_portalplayer1/playlist.c 2007-01-26 02:36:01 UTC (rev 281)
+++ trunk/pmplib/lib/pmp_portalplayer1/playlist.c 2007-01-26 03:44:58 UTC (rev 282)
@@ -50,19 +50,29 @@
return count;
}
-int playlist_write(
- const ucs2char_t *filename,
+int pp1db_playlist_write(
+ pp1db_t* db,
+ const ucs2char_t *name,
ucs2char_t* const mediafiles[],
int num_mediafiles,
- const ucs2char_t *path_to_root
+ const ucs2char_t *path_to_root,
+ const ucs2char_t *path_to_playlist,
+ const ucs2char_t *ext
)
{
+ FILE *fp = NULL;
static const ucs2char_t header1_str[] = {'P','L','P',' ','P','L','A','Y','L','I','S','T','\r','\n', 0};
static const ucs2char_t header2_str[] = {'V','E','R','S','I','O','N',' ','1','.','2','0','\r','\n', 0};
static const ucs2char_t entry_str[] = {'H','D','D',',',' ', 0};
static const ucs2char_t crlf_str[] = {'\r','\n', 0};
+ ucs2char_t dst[MAX_PATH];
+
+ filepath_combinepath(dst, MAX_PATH, path_to_root, path_to_playlist);
+ filepath_addslash(dst);
+ ucs2cat(dst, name);
+ ucs2cat(dst, ext);
- FILE *fp = ucs2fopen(filename, "wb");
+ fp = ucs2fopen(dst, "wb");
if (!fp) {
return -1;
} else {
Modified: trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.c
===================================================================
--- trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.c 2007-01-26 02:36:01 UTC (rev 281)
+++ trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.c 2007-01-26 03:44:58 UTC (rev 282)
@@ -55,6 +55,9 @@
const char *max_version;
const char *fw_filename;
const char *hdr_filename;
+ const char *extensions;
+ uint32_t codecs[8];
+ const char *path_to_system;
const char *path_to_music;
const char *path_to_playlist;
const char *playlist_ext;
@@ -67,7 +70,10 @@
"iriver_h10_5/6gb_ums_2.04-2.53", "iriver", "H10 5GB/6GB UMS",
5, "UM",
"2.04", "2.53",
- "System\\H10.mi4", "System\\DATA\\H10DB.hdr", "Media\\Music\\", "Media\\Playlist\\",
+ "System\\H10.mi4", "System\\DATA\\H10DB.hdr",
+ ".mp3\0.wma\0.wav\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0},
+ "System\\", "Media\\Music\\", "Media\\Playlist\\",
".plp",
hdr_init_h10_5gb_ums_0205_0253, iriver_h10_parse_model
},
@@ -75,7 +81,10 @@
"iriver_h10pure_5/6gb_ums_2.04-2.51", "iriver", "H10Pure 5GB/6GB UMS",
5, "UM",
"2.04", "2.51",
- "System\\H10_5GP.mi4", "System\\DATA\\H10DB.hdr", "Media\\Music\\", "Media\\Playlist\\",
+ "System\\H10_5GP.mi4", "System\\DATA\\H10DB.hdr",
+ ".mp3\0.wma\0.wav\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0},
+ "System\\", "Media\\Music\\", "Media\\Playlist\\",
".plp",
hdr_init_h10_5gb_ums_0205_0253, iriver_h10_parse_model
},
@@ -83,7 +92,10 @@
"iriver_h10_5/6gb_mtp_2.03-2.10", "iriver", "H10 5GB/6GB MTP",
5, "MT",
"2.03", "2.10",
- "System\\H10.mi4", "System\\DATA\\H10DB.hdr", "Music\\", "Playlists\\",
+ "System\\H10.mi4", "System\\DATA\\H10DB.hdr",
+ ".mp3\0.wma\0.wav\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0},
+ "System\\", "Music\\", "Playlists\\",
".pla",
hdr_init_h10_5gb_mtp_0203_0210, iriver_h10_parse_model
},
@@ -91,7 +103,10 @@
"iriver_h10pure_5/6gb_mtp_2.03-2.10", "iriver", "H10Pure 5GB/6GB MTP",
5, "MT",
"2.03", "2.10",
- "System\\H10EMP.mi4", "System\\DATA\\H10DB.hdr", "Music\\", "Playlists\\",
+ "System\\H10EMP.mi4", "System\\DATA\\H10DB.hdr",
+ ".mp3\0.wma\0.wav\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0},
+ "System\\", "Music\\", "Playlists\\",
".pla",
hdr_init_h10_5gb_mtp_0203_0210, iriver_h10_parse_model
},
@@ -99,7 +114,10 @@
"iriver_h10_5/6gb_mtp_2.51", "iriver", "H10 5GB/6GB MTP",
5, "MT",
"2.51", "2.51",
- "System\\H10.mi4", "System\\DATA\\H10DB.hdr", "Music\\", "Playlists\\",
+ "System\\H10.mi4", "System\\DATA\\H10DB.hdr",
+ ".mp3\0.wma\0.wav\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0},
+ "System\\", "Music\\", "Playlists\\",
".pla",
hdr_init_h10_5gb_mtp_0251, iriver_h10_parse_model
},
@@ -107,7 +125,10 @@
"iriver_h10pure_5/6gb_mtp_2.51", "iriver", "H10Pure 5GB/6GB MTP",
5, "MT",
"2.51", "2.51",
- "System\\H10EMP.mi4", "System\\DATA\\H10DB.hdr", "Music\\", "Playlists\\",
+ "System\\H10EMP.mi4", "System\\DATA\\H10DB.hdr",
+ ".mp3\0.wma\0.wav\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0},
+ "System\\", "Music\\", "Playlists\\",
".pla",
hdr_init_h10_5gb_mtp_0251, iriver_h10_parse_model
},
@@ -115,7 +136,10 @@
"iriver_h10_20gb_mtp_1.00-1.02", "iriver", "H10 20GB MTP",
20, "MT",
"1.00", "1.02",
- "System\\H10_20GC.mi4", "System\\DATA\\H10DB.hdr", "Music\\", "Playlists\\",
+ "System\\H10_20GC.mi4", "System\\DATA\\H10DB.hdr",
+ ".mp3\0.wma\0.wav\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0},
+ "System\\", "Music\\", "Playlists\\",
".pla",
hdr_init_h10_20gb_mtp_0100_0102, iriver_h10_parse_model
},
@@ -123,7 +147,10 @@
"iriver_h10_20gb_mtp_2.51", "iriver", "H10 20GB MTP",
20, "MT",
"2.51", "2.51",
- "System\\H10_20GC.mi4", "System\\DATA\\H10DB.hdr", "Music\\", "Playlists\\",
+ "System\\H10_20GC.mi4", "System\\DATA\\H10DB.hdr",
+ ".mp3\0.wma\0.wav\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, PMPCODEC_WAV, 0, 0, 0, 0},
+ "System\\", "Music\\", "Playlists\\",
".pla",
hdr_init_h10_20gb_mtp_0251, iriver_h10_parse_model
},
@@ -131,7 +158,10 @@
"medion_mdjuke220", "MEDION", "MDJUKE220",
20, "UM",
"1.4.2", "1.4.2",
- "SYSTEM\\JUKEBOX.mi4", "SYSTEM\\DATA\\PP5000.HDR", "MyJukeBox\\MUSIC\\", "MyJukeBox\\Playlist\\",
+ "SYSTEM\\JUKEBOX.mi4", "SYSTEM\\DATA\\PP5000.HDR",
+ ".mp3\0.wma\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, 0, 0, 0, 0},
+ "SYSTEM\\", "MyJukeBox\\MUSIC\\", "MyJukeBox\\Playlist\\",
".pla",
hdr_init_medion_mdjuke220, medion_mdjuke220_parse_model
},
@@ -139,7 +169,10 @@
"medion_mdjuke440", "MEDION", "MDJUKE440",
20, "UM",
"1.5.5", "1.5.5",
- "SYSTEM\\JUKEBOX.mi4", "SYSTEM\\DATA\\PP5000.HDR", "MyJukeBox\\MUSIC\\", "MyJukeBox\\Playlist\\",
+ "SYSTEM\\JUKEBOX.mi4", "SYSTEM\\DATA\\PP5000.HDR",
+ ".mp3\0.wma\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, 0, 0, 0, 0},
+ "SYSTEM\\", "MyJukeBox\\MUSIC\\", "MyJukeBox\\Playlist\\",
".pla",
hdr_init_medion_mdjuke440, medion_mdjuke220_parse_model
},
@@ -147,7 +180,10 @@
"samsung_yh820", "Samsung", "YH-820",
5, "UM",
"3.00", "3.00",
- "SYSTEM\\FW_YH820.mi4", "System\\DATA\\PP5000.HDR", "System\\MUSIC\\", "System\\PLAYLIST\\",
+ "SYSTEM\\FW_YH820.mi4", "System\\DATA\\PP5000.HDR",
+ ".mp3\0.wma\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, 0, 0, 0, 0},
+ "System\\", "System\\MUSIC\\", "System\\PLAYLIST\\",
".plp",
hdr_init_samsung_yh820, samsung_parse_model
},
@@ -155,7 +191,10 @@
"samsung_yh920", "Samsung", "YH-920",
20, "UM",
"5.15", "5.15",
- "SYSTEM\\FW_YH920.mi4", "System\\DATA\\PP5000.HDR", "System\\MUSIC\\", "System\\PLAYLIST\\",
+ "SYSTEM\\FW_YH920.mi4", "System\\DATA\\PP5000.HDR",
+ ".mp3\0.wma\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, 0, 0, 0, 0},
+ "System\\", "System\\MUSIC\\", "System\\PLAYLIST\\",
".plp",
hdr_init_samsung_yh920, samsung_parse_model
},
@@ -163,7 +202,10 @@
"samsung_yh925", "Samsung", "YH-925",
5, "UM",
"1.61", "1.61",
- "SYSTEM\\FW_YH925.mi4", "System\\DATA\\PP5000.HDR", "System\\MUSIC\\", "System\\PLAYLIST\\",
+ "SYSTEM\\FW_YH925.mi4", "System\\DATA\\PP5000.HDR",
+ ".mp3\0.wma\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, 0, 0, 0, 0},
+ "System\\", "System\\MUSIC\\", "System\\PLAYLIST\\",
".plp",
hdr_init_samsung_yh925, samsung_parse_model
},
@@ -171,7 +213,10 @@
"philips_hdd6320", "Philips", "HDD6320",
20, "UM",
"5.40", "5.40",
- "SYSTEM\\FWImage.ebn", "System\\DATA\\PP5000.HDR", "Music\\", "Playlists\\",
+ "SYSTEM\\FWImage.ebn", "System\\DATA\\PP5000.HDR",
+ ".mp3\0.wma\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, 0, 0, 0, 0},
+ "SYSTEM\\", "Music\\", "Playlists\\",
".pla",
hdr_init_philips_hdd6320, philips_hdd6320_parse_model
},
@@ -179,7 +224,10 @@
"msi_megaplayer540", "MSI", "MEGA PLAYER 540",
8, "UM",
"01.00.16", "01.00.16",
- "SYSTEM\\PP5020.mi4", "System\\DATA\\PP5000.HDR", "MUSIC\\", "Playlists\\",
+ "SYSTEM\\PP5020.mi4", "System\\DATA\\PP5000.HDR",
+ ".mp3\0.wma\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, 0, 0, 0, 0},
+ "SYSTEM\\", "MUSIC\\", "Playlists\\",
".pla",
hdr_init_msi_megaplayer540, megaplayer_parse_model
},
@@ -188,7 +236,10 @@
"sirius_s50", "Sirius", "S50",
1, "UM",
"0.00", "0.00",
- "SYSTEM\\config\\sysinfo.cfg", "SYSTEM\\DB\\SONG\\Xena.HDR", "SYSTEM\\MEDIA\\MP3\\", "SYSTEM\\MEDIA\\PLAYLIST\\",
+ "SYSTEM\\config\\sysinfo.cfg", "SYSTEM\\DB\\SONG\\Xena.HDR",
+ ".mp3\0.wma\0",
+ {PMPCODEC_MPEGLAYER3, PMPCODEC_WMA, 0, 0, 0, 0},
+ "SYSTEM\\", "SYSTEM\\MEDIA\\MP3\\", "SYSTEM\\MEDIA\\PLAYLIST\\",
".pla",
hdr_init_sirius_s50, iriver_h10_parse_model
},
@@ -197,146 +248,196 @@
NULL, NULL, NULL,
0, NULL,
0, 0,
- NULL, NULL, NULL, NULL,
+ NULL, NULL,
NULL,
+ {0, 0, 0, 0, 0, 0, 0, 0},
+ NULL, NULL, NULL,
+ NULL,
NULL, NULL
},
};
typedef struct {
- pp1model_t model;
- ucs2char_t path_to_root[MAX_PATH];
- ucs2char_t path_to_music[MAX_PATH];
- ucs2char_t path_to_playlist[MAX_PATH];
- ucs2char_t fw_filename[MAX_PATH];
- ucs2char_t hdr_filename[MAX_PATH];
- ucs2char_t playlist_ext[MAX_PATH];
- hdr_init_t hdr_initproc;
-} pp1_environment_t;
-
-
-typedef struct {
- pp1_environment_t env;
+ const pp1model_descriptor_t* decl;
} pmp_internal_t;
typedef struct {
pp1db_t pp1db;
-} pmpdb_internal_t;
+ pmp_music_record_t* records;
+ int num_records;
+ pmp_playlist_t* playlists;
+ int num_playlists;
+} pmp_music_internal_t;
static uint32_t pmp_add_ref(pmp_t* pmp);
static uint32_t pmp_release(pmp_t* pmp);
static result_t pmp_open(pmp_t* pmp, uint32_t flag);
-static result_t pmp_close(pmp_t* pmp, uint32_t flag);
-static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb);
-static result_t pmp_create_instance_pl(pmp_t* pmp, pmp_playlist_t** ptr_pmppl);
+static result_t pmp_close(pmp_t* pmp);
+static result_t pmp_create_instance_music(pmp_t* pmp, pmp_music_t** ptr_pmpdb);
-static uint32_t pmpdb_release(pmp_music_t* pmpdb);
-static result_t pmpdb_read(pmp_music_t* pmpdb);
-static result_t pmpdb_write(pmp_music_t* pmpdb);
-static result_t pmpdb_set(pmp_music_t* pmpdb, const pmp_music_record_t* records, uint32_t num_records);
-static result_t pmpdb_get(pmp_music_t* pmpdb, pmp_music_record_t* records, uint32_t* num_records);
-static result_t pmpdb_dump(pmp_music_t* pmpdb, FILE *fp, int level);
-static int pmpdb_is_supported_codec(pmp_music_t* pmpdb, uint32_t codec);
-static int pmpdb_is_supported_ext(pmp_music_t* pmpdb, const ucs2char_t* filename);
+static uint32_t pmpmusic_release(pmp_music_t* music);
+static uint32_t pmpmusic_open(pmp_music_t* music);
+static uint32_t pmpmusic_close(pmp_music_t* music);
+static result_t pmpmusic_set_records(pmp_music_t* music, const pmp_music_record_t* records, uint32_t num_records);
+static result_t pmpmusic_get_records(pmp_music_t* music, pmp_music_record_t* records, uint32_t* num_records);
+static result_t pmpmusic_dump(pmp_music_t* music, FILE *fp, int level);
+static result_t pmpmusic_set_playlists(pmp_music_t* music, const pmp_playlist_t* playlists, uint32_t num_playlists);
-static uint32_t pmppl_add_ref(pmp_playlist_t* pmppl);
-static uint32_t pmppl_release(pmp_playlist_t* pmppl);
-static result_t pmppl_write(pmp_playlist_t* pmppl, const ucs2char_t* filename, ucs2char_t* const files[], uint32_t num_files);
+#define COMP(a, b) ((a)>(b))-((a)<(b))
+static char* strip(char *str)
+{
+ char *p = str + strlen(str) - 1;
+ while (*str && isspace(*str)) {
+ str++;
+ }
+ while (str <= p && isspace(*p)) {
+ *p-- = 0;
+ }
+ return str;
+}
+static const char *strcpy_if_empty(char *dst, const char *src)
+{
+ return *dst ? dst : strcpy(dst, src);
+}
-static void set_environment(
- pp1_environment_t* env,
+static void set_filenames(ucs2char_t *hdr, pmp_t *pmp)
+{
+ ucs2char_t* ucs2 = NULL;
+ pmp_internal_t* pmpi = (pmp_internal_t*)pmp->instance;
+
+ ucs2cpy(hdr, pmp->info.path_to_root);
+ filepath_addslash(hdr);
+ ucs2 = mbsdupucs2(pmpi->decl->hdr_filename);
+ ucs2cat(hdr, ucs2);
+ ucs2free(ucs2);
+}
+
+static void set_device_info(
+ const char *id,
+ const ucs2char_t* path_to_device,
const pp1model_descriptor_t* md,
- const ucs2char_t* path_to_device
+ pmp_device_information_t* info
)
{
+ uint32_t n;
+ const char *p = NULL;
ucs2char_t* ucs2 = NULL;
+ pmp_device_description_t* decl = (pmp_device_description_t*)&info->decl;
- ucs2cpy(env->fw_filename, path_to_device);
- filepath_addslash(env->fw_filename);
- ucs2 = mbsdupucs2(md->fw_filename);
- ucs2cat(env->fw_filename, ucs2);
- ucs2free(ucs2);
+ strcpy_if_empty(decl->id, id);
+ strcpy_if_empty(decl->manufacturer, md->manufacturer);
+ strcpy_if_empty(decl->name, md->name);
+ strcpy_if_empty(decl->mode, md->mode);
+ strcpy_if_empty(decl->min_version, md->min_version);
+ strcpy_if_empty(decl->max_version, md->max_version);
- ucs2cpy(env->hdr_filename, path_to_device);
- filepath_addslash(env->hdr_filename);
- ucs2 = mbsdupucs2(md->hdr_filename);
- ucs2cat(env->hdr_filename, ucs2);
+ ucs2cpy(info->path_to_root, path_to_device);
+
+ ucs2 = mbsdupucs2(md->path_to_system);
+ ucs2cpy(info->path_to_system, ucs2);
ucs2free(ucs2);
- ucs2cpy(env->path_to_root, path_to_device);
-
- ucs2cpy(env->path_to_music, path_to_device);
- filepath_addslash(env->path_to_music);
ucs2 = mbsdupucs2(md->path_to_music);
- ucs2cat(env->path_to_music, ucs2);
+ ucs2cpy(info->path_to_music, ucs2);
ucs2free(ucs2);
- ucs2cpy(env->path_to_playlist, path_to_device);
- filepath_addslash(env->path_to_playlist);
ucs2 = mbsdupucs2(md->path_to_playlist);
- ucs2cat(env->path_to_playlist, ucs2);
+ ucs2cpy(info->path_to_playlist, ucs2);
ucs2free(ucs2);
- ucs2 = mbsdupucs2(md->playlist_ext);
- ucs2cpy(env->playlist_ext, ucs2);
- ucs2free(ucs2);
+ info->music_flag = PMPMF_SUPPORT | PMPMF_RECURSIVE;
+ info->playlist_flag = PMPPF_SUPPORT;
- env->hdr_initproc = md->hdr_initproc;
+ // Audio codecs.
+ for (n = 0;md->codecs[n];++n) ;
+ info->num_audio_codecs = n;
+ info->audio_codecs = (uint32_t*)ucs2malloc(sizeof(uint32_t) * info->num_audio_codecs);
+ for (n = 0;n < info->num_audio_codecs;++n) {
+ info->audio_codecs[n] = md->codecs[n];
+ }
+
+ // Obtain the number of extensions separated by '\0' characters.
+ for (n = 0, p = md->extensions;*p;p += (strlen(p)+1)) {
+ n++;
+ }
+ info->num_audio_extensions = n;
+ info->audio_extensions = (ucs2char_t**)ucs2malloc(sizeof(ucs2char_t*) * info->num_audio_extensions);
+ for (n = 0, p = md->extensions;*p;p += (strlen(p)+1)) {
+ info->audio_extensions[n++] = mbsdupucs2(p);
+ }
}
-static int match_model(
- const char *id,
- const ucs2char_t* path_to_device,
- const pp1model_descriptor_t* md,
- pp1_environment_t* env
- )
+static void free_device_info(pmp_device_information_t* info)
{
- memset(env, 0, sizeof(pp1_environment_t));
+ uint32_t i;
+ for (i = 0;i < info->num_audio_extensions;++i) {
+ ucs2free(info->audio_extensions[i]);
+ }
+ ucs2free(info->audio_codecs);
+ ucs2free(info->audio_extensions);
+ memset(info, 0, sizeof(*info));
+}
- if (!id || strcmp(md->id, id) != 0) {
- return 0;
+static int compare_version(const char *x, const char *y)
+{
+ char *p = NULL, *q = NULL;
+
+ for (;;) {
+ long a = strtol(x, &p, 10);
+ long b = strtol(y, &q, 10);
+ int value = COMP(a, b);
+ if (value != 0) {
+ return value;
+ }
+ if (!*p || !*q || *p != *q) {
+ return COMP(*p, *q);
+ }
+ x = p+1;
+ y = q+1;
}
-
- set_environment(env, md, path_to_device);
- return 1;
}
-
static int detect_model(
const ucs2char_t* path_to_device,
const pp1model_descriptor_t* md,
- pp1_environment_t* env
+ pmp_device_information_t* ptr_info
)
{
ucs2char_t* ucs2 = NULL;
ucs2char_t filename[MAX_PATH];
+ pp1model_t model;
+ pmp_device_description_t decl;
- memset(env, 0, sizeof(pp1_environment_t));
+ memset(&model, 0, sizeof(model));
+ memset(&decl, 0, sizeof(decl));
- // Check the existence of a firmware file.
+ // filename = "${path_to_device}/${md->sys_filename}"
ucs2cpy(filename, path_to_device);
filepath_addslash(filename);
ucs2 = mbsdupucs2(md->fw_filename);
ucs2cat(filename, ucs2);
ucs2free(ucs2);
+
if (filepath_file_exists(filename)) {
// Check the product identifier and firmware version.
- if (md->parse_model_proc(filename, &env->model)) {
- if (compare_version(env->model.version, md->min_version) < 0) {
- return 0;
+ if (md->parse_model_proc(filename, &model)) {
+ int match = 1;
+ strcpy(decl.name, model.name);
+ strcpy(decl.mode, model.mode);
+ strcpy(decl.language, model.language);
+ strcpy(decl.version, model.version);
+
+ match &= (strcmp(decl.mode, md->mode) == 0);
+ match &= (compare_version(md->min_version, decl.version) <= 0);
+ match &= (compare_version(decl.version, md->max_version) <= 0);
+
+ if (match) {
+ memcpy((pmp_device_description_t*)&ptr_info->decl, &decl, sizeof(decl));
+ return 1;
}
- if (compare_version(md->max_version, env->model.version) < 0) {
- return 0;
- }
- if (strcmp(env->model.mode, md->mode) != 0) {
- return 0;
- }
-
- set_environment(env, md, path_to_device);
- return 1;
}
}
return 0;
@@ -360,26 +461,32 @@
pmp_t* pmp = NULL;
pmp_internal_t* pmpi = NULL;
const pp1model_descriptor_t* md = NULL;
- pp1_environment_t env;
- pmp_device_environment_t* pmpenv = NULL;
+ pmp_device_information_t info;
- // Initialize.
+ // Initialize device information.
+ memset(&info, 0, sizeof(info));
+
+ // Return a NULL pointer by default.
*ptr_pmp = 0;
// Find a suitable model for the device.
md = g_model_descriptions;
for (;md->id;++md) {
- if (detect_model(path_to_device, md, &env)) {
- if (!id || !id[0]) {
+ if (id && *id) {
+ // Match the device identifier.
+ if (strcmp(md->id, id) == 0) {
+ // This will fill some members in decl.
+ detect_model(path_to_device, md, &info);
+ set_device_info(id, path_to_device, md, &info);
break;
}
- if (strcmp(md->id, id) == 0) {
+ } else {
+ // Detect the model automatically.
+ if (detect_model(path_to_device, md, &info)) {
+ set_device_info(md->id, path_to_device, md, &info);
break;
}
}
- if (match_model(id, path_to_device, md, &env)) {
- break;
- }
}
if (!md->id) {
return PMP_DEVICENOTFOUND;
@@ -391,10 +498,8 @@
return PMPDBE_OUTOFMEMORY;
}
- // Set methods.
pmp->add_ref = pmp_add_ref;
pmp->release = pmp_release;
- pmp->create_instance_pl = pmp_create_instance_pl;
pmp->open = pmp_open;
pmp->close = pmp_close;
pmp->add_ref(pmp);
@@ -402,36 +507,17 @@
// Allocate the internal variables.
pmpi = (pmp_internal_t*)calloc(1, sizeof(pmp_internal_t));
if (!pmpi) {
- pmp_release(pmp);
+ free(pmp);
return PMPDBE_OUTOFMEMORY;
}
- pmp->instance = pmpi;
+ pmpi->decl = md;
// Initialize the internal variables.
- memcpy(&pmpi->env, &env, sizeof(env));
+ pmp->instance = pmpi;
+ memcpy((pmp_device_information_t*)&pmp->info, &info, sizeof(info));
- // Initialize the device description.
- strcpy(pmp->decl.id, md->id);
- strcpy(pmp->decl.manufacturer, md->manufacturer);
- strcpy(pmp->decl.name, md->name);
- strcpy(pmp->decl.mode, md->mode);
- strcpy(pmp->decl.language, pmpi->env.model.language);
- strcpy(pmp->decl.version, pmpi->env.model.version);
- strcpy(pmp->decl.min_version, md->min_version);
- strcpy(pmp->decl.max_version, md->max_version);
-
- // Initialize the (exportable) env.
- pmpenv = &pmp->env;
- pmpenv->path_to_root.flag = PMPPEF_SUPPORT | PMPPEF_CONSTANT;
- ucs2cpy(pmpenv->path_to_root.path, pmpi->env.path_to_root);
- pmpenv->path_to_music.flag = PMPPEF_SUPPORT | PMPPEF_RECURSIVE;
- ucs2cpy(pmpenv->path_to_music.path, pmpi->env.path_to_music);
- pmpenv->path_to_playlist.flag = PMPPEF_SUPPORT;
- ucs2cpy(pmpenv->path_to_playlist.path, pmpi->env.path_to_playlist);
- ucs2cpy(pmpenv->playlist_ext, pmpi->env.playlist_ext);
-
// Create music instance.
- ret = pmp_create_instance_db(pmp, &pmp->music);
+ ret = pmp_create_instance_music(pmp, &pmp->music);
if (ret != 0) {
pmp_release(pmp);
return ret;
@@ -451,7 +537,8 @@
{
uint32_t count = pmplib_interlocked_decrement(&pmp->ref_count);
if (count == 0) {
- pmpdb_release(pmp->music);
+ pmpmusic_release(pmp->music);
+ free_device_info(&pmp->info);
free(pmp->instance);
free(pmp);
}
@@ -461,162 +548,198 @@
static result_t pmp_open(pmp_t* pmp, uint32_t flag)
{
result_t ret = 0;
+
+ // Set the open flag.
pmp->flag = flag;
- if (pmp->flag & PMPOF_MUSIC_DB_READ) {
- ret = pmpdb_read(pmp->music);
- if (ret != 0) {
- return ret;
- }
+ // Open the music database.
+ ret = pmpmusic_open(pmp->music);
+ if (ret) {
+ return ret;
}
+
return 0;
}
-static result_t pmp_close(pmp_t* pmp, uint32_t flag)
+static result_t pmp_close(pmp_t* pmp)
{
result_t ret = 0;
- if (pmp->flag & PMPOF_MUSIC_DB_WRITE) {
- ret = pmpdb_write(pmp->music);
- if (ret != 0) {
- return ret;
- }
+
+ // Close the music database.
+ ret = pmpmusic_close(pmp->music);
+ if (ret) {
+ return ret;
}
+
return 0;
}
-static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb)
+static result_t pmp_create_instance_music(pmp_t* pmp, pmp_music_t** ptr_music)
{
- pmp_music_t* pmpdb = NULL;
+ pmp_music_t* music = NULL;
pmp_internal_t* pmpi = (pmp_internal_t*)pmp->instance;
- pmpdb_internal_t* pmpdbi = NULL;
+ pmp_music_internal_t* pmpmi = NULL;
- *ptr_pmpdb = 0;
+ *ptr_music = 0;
- pmpdb = calloc(1, sizeof(pmp_music_t));
- if (!pmpdb) {
+ music = calloc(1, sizeof(pmp_music_t));
+ if (!music) {
return PMPDBE_OUTOFMEMORY;
}
- pmpdb->set = pmpdb_set;
- pmpdb->get = pmpdb_get;
- pmpdb->dump = pmpdb_dump;
- pmpdb->is_supported_codec = pmpdb_is_supported_codec;
- pmpdb->is_supported_ext = pmpdb_is_supported_ext;
-
- pmpdbi = calloc(1, sizeof(pmpdb_internal_t));
- if (!pmpdbi) {
+ pmpmi = calloc(1, sizeof(pmp_music_internal_t));
+ if (!pmpmi) {
+ free(music);
return PMPDBE_OUTOFMEMORY;
}
- pp1db_init(&pmpdbi->pp1db, pmpi->env.hdr_initproc);
+ pp1db_init(&pmpmi->pp1db, pmpi->decl->hdr_initproc);
- pmpdb->pmp = pmp;
- pmpdb->instance = pmpdbi;
+ music->set_records = pmpmusic_set_records;
+ music->get_records = pmpmusic_get_records;
+ music->dump = pmpmusic_dump;
+ music->set_playlists = pmpmusic_set_playlists;
+ music->pmp = pmp;
+ music->instance = pmpmi;
- *ptr_pmpdb = pmpdb;
+ *ptr_music = music;
return 0;
}
-static result_t pmp_create_instance_pl(pmp_t* pmp, pmp_playlist_t** ptr_pmppl)
-{
- pmp_internal_t* pmpi = (pmp_internal_t*)pmp->instance;
- pmp_playlist_t* pmppl = NULL;
- *ptr_pmppl = 0;
- pmppl = calloc(1, sizeof(pmp_playlist_t));
- if (!pmppl) {
- return PMPDBE_OUTOFMEMORY;
- }
- pmppl->add_ref = pmppl_add_ref;
- pmppl->release = pmppl_release;
- pmppl->write = pmppl_write;
-
- pmppl->pmp = pmp;
-
- pmppl->add_ref(pmppl);
- *ptr_pmppl = pmppl;
+static uint32_t pmpmusic_release(pmp_music_t* music)
+{
+ pmp_music_internal_t* pmpmi = (pmp_music_internal_t*)music->instance;
+ pp1db_finish(&pmpmi->pp1db);
+ pmplib_records_finish(pmpmi->records, pmpmi->num_records);
+ free(pmpmi->playlists);
+ free(pmpmi);
+ free(music);
return 0;
}
+static uint32_t pmpmusic_open(pmp_music_t* music)
+{
+ result_t ret = 0;
+ pmp_t* pmp = music->pmp;
+ pmp_music_internal_t* pmpmi = (pmp_music_internal_t*)music->instance;
+ // Free the existing records.
+ pmplib_records_finish(pmpmi->records, pmpmi->num_records);
+ pmpmi->records = 0;
+ pmpmi->num_records = 0;
+ // Open the music database if necessary.
+ if (pmp->flag & PMPOF_MUSIC_DB_READ) {
+ ucs2char_t hdr[MAX_PATH];
+ pmp_music_internal_t* pmpmi = (pmp_music_internal_t*)pmp->music->instance;
+ // Read the music database.
+ set_filenames(hdr, pmp);
+ ret = pp1db_read(&pmpmi->pp1db, hdr);
+ if (ret) {
+ return ret;
+ }
-static uint32_t pmpdb_release(pmp_music_t* pmpdb)
-{
- pmpdb_internal_t* pmpdbi = (pmpdb_internal_t*)pmpdb->instance;
- pp1db_finish(&pmpdbi->pp1db);
- free(pmpdb->instance);
- free(pmpdb);
+ return pp1db_get(&pmpmi->pp1db, pmpmi->records, &pmpmi->num_records, pmp->info.path_to_root);
+ }
+
return 0;
}
-static result_t pmpdb_read(pmp_music_t* pmpdb)
+static uint32_t pmpmusic_close(pmp_music_t* music)
{
- pmpdb_internal_t* pmpdbi = (pmpdb_internal_t*)pmpdb->instance;
- pmp_internal_t* pmpi = (pmp_internal_t*)pmpdb->pmp->instance;
- return pp1db_read(&pmpdbi->pp1db, pmpi->env.hdr_filename);
-}
+ result_t ret = 0;
+ pmp_t* pmp = music->pmp;
+ pmp_music_internal_t* pmpmi = (pmp_music_internal_t*)music->instance;
+ static const ucs2char_t plp_ext[] = {'.','p','l','p',0};
-static result_t pmpdb_write(pmp_music_t* pmpdb)
-{
- pmpdb_internal_t* pmpdbi = (pmpdb_internal_t*)pmpdb->instance;
- pmp_internal_t* pmpi = (pmp_internal_t*)pmpdb->pmp->instance;
- return pp1db_write(&pmpdbi->pp1db, pmpi->env.hdr_filename);
-}
+ if (pmp->flag & PMPOF_MUSIC_DB_WRITE) {
+ ucs2char_t hdr[MAX_PATH];
-static result_t pmpdb_set(pmp_music_t* pmpdb, const pmp_music_record_t* records, uint32_t num_records)
-{
- pmpdb_internal_t* pmpdbi = (pmpdb_internal_t*)pmpdb->instance;
- pmp_internal_t* pmpi = (pmp_internal_t*)pmpdb->pmp->instance;
- return pp1db_set(&pmpdbi->pp1db, records, num_records, pmpi->env.path_to_root);
-}
+ pp1db_set(&pmpmi->pp1db, pmpmi->records, pmpmi->num_records, pmp->info.path_to_root);
-static result_t pmpdb_get(pmp_music_t* pmpdb, pmp_music_record_t* records, uint32_t* num_records)
-{
- pmpdb_internal_t* pmpdbi = (pmpdb_internal_t*)pmpdb->instance;
- pmp_internal_t* pmpi = (pmp_internal_t*)pmpdb->pmp->instance;
- return pp1db_get(&pmpdbi->pp1db, records, num_records, pmpi->env.path_to_root);
-}
+ set_filenames(hdr, pmp);
+ ret = pp1db_write(&pmpmi->pp1db, hdr);
+ if (ret) {
+ return ret;
+ }
+ }
-static result_t pmpdb_dump(pmp_music_t* pmpdb, FILE *fp, int level)
-{
- pmpdb_internal_t* pmpdbi = (pmpdb_internal_t*)pmpdb->instance;
- return pp1db_repr(&pmpdbi->pp1db, fp, level);
-}
+ if (pmp->flag & PMPOF_MUSIC_PL_WRITE) {
+ int i;
-static int pmpdb_is_supported_codec(pmp_music_t* pmpdb, uint32_t codec)
-{
- return pp1db_is_supported_codec(codec);
+ for (i = 0;i < pmpmi->num_playlists;++i) {
+ const pmp_playlist_t* pl = &pmpmi->playlists[i];
+ if (pp1db_playlist_write(
+ &pmpmi->pp1db,
+ pl->name,
+ pl->entries,
+ pl->num_entries,
+ pmp->info.path_to_root,
+ pmp->info.path_to_playlist,
+ plp_ext
+ ) != 0) {
+ return PMPPLE_WRITE;
+ }
+ }
+ }
+
+ return ret;
}
-static int pmpdb_is_supported_ext(pmp_music_t* pmpdb, const ucs2char_t* filename)
+static result_t pmpmusic_set_records(pmp_music_t* music, const pmp_music_record_t* records, uint32_t num_records)
{
- return pp1db_is_supported_ext(filename);
-}
+ pmp_t* pmp = music->pmp;
+ pmp_music_internal_t* pmpmi = (pmp_music_internal_t*)music->instance;
+ /* Free records attached to pmpmi. */
+ pmplib_records_finish(pmpmi->records, pmpmi->num_records);
+ /* Allocate new records. */
+ pmpmi->records = (pmp_music_record_t*)ucs2malloc(sizeof(pmp_music_record_t) * num_records);
+ pmpmi->num_records = num_records;
+ pmplib_records_clone(pmpmi->records, records, num_records);
-static uint32_t pmppl_add_ref(pmp_playlist_t* pmppl)
+ return 0;
+ }
+
+static result_t pmpmusic_get_records(pmp_music_t* music, pmp_music_record_t* records, uint32_t* num_records)
{
- return pmplib_interlocked_increment(&pmppl->ref_count);
+ pmp_t* pmp = music->pmp;
+ pmp_music_internal_t* pmpmi = (pmp_music_internal_t*)music->instance;
+
+ if (!records) {
+ *num_records = pmpmi->num_records;
+ return 0;
+ } else if (*num_records == pmpmi->num_records) {
+ pmplib_records_clone(records, pmpmi->records, pmpmi->num_records);
+ return 0;
+ } else {
+ return PMPDBE_INSUFFICIENT;
+ }
}
-static uint32_t pmppl_release(pmp_playlist_t* pmppl)
+static result_t pmpmusic_dump(pmp_music_t* music, FILE *fp, int level)
{
- uint32_t count = pmplib_interlocked_decrement(&pmppl->ref_count);
- if (count == 0) {
- free(pmppl);
- }
- return count;
+ pmp_music_internal_t* pmpmi = (pmp_music_internal_t*)music->instance;
+ return pp1db_repr(&pmpmi->pp1db, fp, level);
}
-static result_t pmppl_write(pmp_playlist_t* pmppl, const ucs2char_t* filename, ucs2char_t* const files[], uint32_t num_files)
+static result_t pmpmusic_set_playlists(pmp_music_t* music, const pmp_playlist_t* playlists, uint32_t num_playlists)
{
- pmp_internal_t* pmpi = (pmp_internal_t*)pmppl->pmp->instance;
- if (playlist_write(filename, files, num_files, pmpi->env.path_to_root) != 0) {
- return PMPPLE_WRITE;
- }
+ pmp_music_internal_t* pmpmi = (pmp_music_internal_t*)music->instance;
+
+ // Free playlists attached to pmpmi.
+ pmplib_playlists_finish(pmpmi->playlists, pmpmi->num_playlists);
+
+ // Allocate a new playlists.
+ pmpmi->playlists = (pmp_playlist_t*)calloc(num_playlists, sizeof(pmp_playlist_t));
+ pmpmi->num_playlists = num_playlists;
+
+ // Copy the playlist array.
+ pmplib_playlists_clone(pmpmi->playlists, playlists, num_playlists);
+
return 0;
}
Modified: trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.vcproj
===================================================================
--- trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.vcproj 2007-01-26 02:36:01 UTC (rev 281)
+++ trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.vcproj 2007-01-26 03:44:58 UTC (rev 282)
@@ -206,34 +206,6 @@
>
</File>
<File
- RelativePath=".\model_iriver_h10.c"
- >
- </File>
- <File
- RelativePath=".\model_medion_mdjuke220.c"
- >
- </File>
- <File
- RelativePath=".\model_medion_mdjuke440.c"
- >
- </File>
- <File
- RelativePath=".\model_msi_megaplayer.c"
- >
- </File>
- <File
- RelativePath=".\model_philips_hdd6320.c"
- >
- </File>
- <File
- RelativePath=".\model_samsung.c"
- >
- </File>
- <File
- RelativePath=".\model_sirius_s50.c"
- >
- </File>
- <File
RelativePath=".\playlist.c"
>
</File>
@@ -286,6 +258,38 @@
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
+ <Filter
+ Name="Model"
+ >
+ <File
+ RelativePath=".\model_iriver_h10.c"
+ >
+ </File>
+ <File
+ RelativePath=".\model_medion_mdjuke220.c"
+ >
+ </File>
+ <File
+ RelativePath=".\model_medion_mdjuke440.c"
+ >
+ </File>
+ <File
+ RelativePath=".\model_msi_megaplayer.c"
+ >
+ </File>
+ <File
+ RelativePath=".\model_philips_hdd6320.c"
+ >
+ </File>
+ <File
+ RelativePath=".\model_samsung.c"
+ >
+ </File>
+ <File
+ RelativePath=".\model_sirius_s50.c"
+ >
+ </File>
+ </Filter>
</Files>
<Globals>
</Globals>
Modified: trunk/pmplib/lib/pmp_portalplayer1/pp1db.h
===================================================================
--- trunk/pmplib/lib/pmp_portalplayer1/pp1db.h 2007-01-26 02:36:01 UTC (rev 281)
+++ trunk/pmplib/lib/pmp_portalplayer1/pp1db.h 2007-01-26 03:44:58 UTC (rev 282)
@@ -149,11 +149,14 @@
void idx_repr(const idx_t* elem, FILE *fp);
// playlist.c
-int playlist_write(
- const ucs2char_t *filename,
+int pp1db_playlist_write(
+ pp1db_t* db,
+ const ucs2char_t *name,
ucs2char_t* const mediafiles[],
int num_mediafiles,
- const ucs2char_t *path_to_root
+ const ucs2char_t *path_to_root,
+ const ucs2char_t *path_to_playlist,
+ const ucs2char_t *ext
);
// pp1db.c
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|