From 86a9321173cb87268c54258e8886af2bf522f66d Mon Sep 17 00:00:00 2001 From: datasone Date: Tue, 11 Apr 2023 22:44:42 +0800 Subject: [PATCH] Add range start and end properties in milliseconds into `mpd_song` Range `start` and `end` values in `mpd_song` is stored in seconds only, which makes range times in `ProxySong` truncated to seconds and leads to precision loss on satellite cue track range times. This commit adds `start_ms` and `end_ms` properties to store range start and end times in milliseconds, and corresponding functions to access them: `mpd_song_get_start_ms`, `mpd_song_get_end_ms`. The values are parsed from float time values returned by mpd server. --- include/mpd/song.h | 16 ++++++++++++++++ libmpdclient.ld | 2 ++ src/song.c | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/mpd/song.h b/include/mpd/song.h index c733c29..c4f9063 100644 --- a/include/mpd/song.h +++ b/include/mpd/song.h @@ -137,6 +137,14 @@ mpd_pure unsigned mpd_song_get_start(const struct mpd_song *song); +/** + * Returns the start of the virtual song within the physical file in + * milliseconds. + */ +mpd_pure +unsigned +mpd_song_get_start_ms(const struct mpd_song *song); + /** * Returns the end of the virtual song within the physical file in * seconds. 0 means that the physical song file is played to the end. @@ -147,6 +155,14 @@ mpd_pure unsigned mpd_song_get_end(const struct mpd_song *song); +/** + * Returns the end of the virtual song within the physical file in + * milliseconds. 0 means that the physical song file is played to the end. + */ +mpd_pure +unsigned +mpd_song_get_end_ms(const struct mpd_song *song); + /** * @return the POSIX UTC time stamp of the last modification, or 0 if * that is unknown diff --git a/libmpdclient.ld b/libmpdclient.ld index af5ba60..98ca371 100644 --- a/libmpdclient.ld +++ b/libmpdclient.ld @@ -366,7 +366,9 @@ global: mpd_song_get_duration; mpd_song_get_duration_ms; mpd_song_get_start; + mpd_song_get_start_ms; mpd_song_get_end; + mpd_song_get_end_ms; mpd_song_get_last_modified; mpd_song_set_pos; mpd_song_get_pos; diff --git a/src/song.c b/src/song.c index a209db9..2fea65a 100644 --- a/src/song.c +++ b/src/song.c @@ -78,6 +78,12 @@ struct mpd_song { */ unsigned start; + /** + * Start of the virtual song within the physical file in + * milliseconds. + */ + unsigned start_ms; + /** * End of the virtual song within the physical file in * seconds. Zero means that the physical song file is @@ -85,6 +91,13 @@ struct mpd_song { */ unsigned end; + /** + * End of the virtual song within the physical file in + * milliseconds. Zero means that the physical song + * file is played to the end. + */ + unsigned end_ms; + /** * The POSIX UTC time stamp of the last modification, or 0 if * that is unknown. @@ -147,7 +160,9 @@ mpd_song_new(const char *uri) song->duration = 0; song->duration_ms = 0; song->start = 0; + song->start_ms = 0; song->end = 0; + song->end_ms = 0; song->last_modified = 0; song->pos = 0; song->id = 0; @@ -230,7 +245,9 @@ mpd_song_dup(const struct mpd_song *song) ret->duration = song->duration; ret->duration_ms = song->duration_ms; ret->start = song->start; + ret->start_ms = song->start_ms; ret->end = song->end; + ret->end_ms = song->end_ms; ret->last_modified = song->last_modified; ret->pos = song->pos; ret->id = song->id; @@ -396,6 +413,14 @@ mpd_song_get_start(const struct mpd_song *song) return song->start; } +unsigned +mpd_song_get_start_ms(const struct mpd_song *song) +{ + assert(song != NULL); + + return song->start_ms; +} + unsigned mpd_song_get_end(const struct mpd_song *song) { @@ -404,6 +429,14 @@ mpd_song_get_end(const struct mpd_song *song) return song->end; } +unsigned +mpd_song_get_end_ms(const struct mpd_song *song) +{ + assert(song != NULL); + + return song->end_ms; +} + static void mpd_song_set_last_modified(struct mpd_song *song, time_t mtime) { @@ -508,15 +541,19 @@ mpd_song_parse_range(struct mpd_song *song, const char *value) } song->start = start > 0.0 ? (unsigned)start : 0; + song->start_ms = start > 0.0 ? (unsigned)(start * 1000) : 0; if (end > 0.0) { song->end = (unsigned)end; + song->end_ms = (unsigned)(end * 1000); if (song->end == 0) /* round up, because the caller must sees that there's an upper limit */ song->end = 1; - } else + } else { song->end = 0; + song->end_ms = 0; + } } static void