Skip to content

Commit 86a9321

Browse files
committed
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.
1 parent eef2dde commit 86a9321

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

include/mpd/song.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ mpd_pure
137137
unsigned
138138
mpd_song_get_start(const struct mpd_song *song);
139139

140+
/**
141+
* Returns the start of the virtual song within the physical file in
142+
* milliseconds.
143+
*/
144+
mpd_pure
145+
unsigned
146+
mpd_song_get_start_ms(const struct mpd_song *song);
147+
140148
/**
141149
* Returns the end of the virtual song within the physical file in
142150
* seconds. 0 means that the physical song file is played to the end.
@@ -147,6 +155,14 @@ mpd_pure
147155
unsigned
148156
mpd_song_get_end(const struct mpd_song *song);
149157

158+
/**
159+
* Returns the end of the virtual song within the physical file in
160+
* milliseconds. 0 means that the physical song file is played to the end.
161+
*/
162+
mpd_pure
163+
unsigned
164+
mpd_song_get_end_ms(const struct mpd_song *song);
165+
150166
/**
151167
* @return the POSIX UTC time stamp of the last modification, or 0 if
152168
* that is unknown

libmpdclient.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ global:
366366
mpd_song_get_duration;
367367
mpd_song_get_duration_ms;
368368
mpd_song_get_start;
369+
mpd_song_get_start_ms;
369370
mpd_song_get_end;
371+
mpd_song_get_end_ms;
370372
mpd_song_get_last_modified;
371373
mpd_song_set_pos;
372374
mpd_song_get_pos;

src/song.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,26 @@ struct mpd_song {
7878
*/
7979
unsigned start;
8080

81+
/**
82+
* Start of the virtual song within the physical file in
83+
* milliseconds.
84+
*/
85+
unsigned start_ms;
86+
8187
/**
8288
* End of the virtual song within the physical file in
8389
* seconds. Zero means that the physical song file is
8490
* played to the end.
8591
*/
8692
unsigned end;
8793

94+
/**
95+
* End of the virtual song within the physical file in
96+
* milliseconds. Zero means that the physical song
97+
* file is played to the end.
98+
*/
99+
unsigned end_ms;
100+
88101
/**
89102
* The POSIX UTC time stamp of the last modification, or 0 if
90103
* that is unknown.
@@ -147,7 +160,9 @@ mpd_song_new(const char *uri)
147160
song->duration = 0;
148161
song->duration_ms = 0;
149162
song->start = 0;
163+
song->start_ms = 0;
150164
song->end = 0;
165+
song->end_ms = 0;
151166
song->last_modified = 0;
152167
song->pos = 0;
153168
song->id = 0;
@@ -230,7 +245,9 @@ mpd_song_dup(const struct mpd_song *song)
230245
ret->duration = song->duration;
231246
ret->duration_ms = song->duration_ms;
232247
ret->start = song->start;
248+
ret->start_ms = song->start_ms;
233249
ret->end = song->end;
250+
ret->end_ms = song->end_ms;
234251
ret->last_modified = song->last_modified;
235252
ret->pos = song->pos;
236253
ret->id = song->id;
@@ -396,6 +413,14 @@ mpd_song_get_start(const struct mpd_song *song)
396413
return song->start;
397414
}
398415

416+
unsigned
417+
mpd_song_get_start_ms(const struct mpd_song *song)
418+
{
419+
assert(song != NULL);
420+
421+
return song->start_ms;
422+
}
423+
399424
unsigned
400425
mpd_song_get_end(const struct mpd_song *song)
401426
{
@@ -404,6 +429,14 @@ mpd_song_get_end(const struct mpd_song *song)
404429
return song->end;
405430
}
406431

432+
unsigned
433+
mpd_song_get_end_ms(const struct mpd_song *song)
434+
{
435+
assert(song != NULL);
436+
437+
return song->end_ms;
438+
}
439+
407440
static void
408441
mpd_song_set_last_modified(struct mpd_song *song, time_t mtime)
409442
{
@@ -508,15 +541,19 @@ mpd_song_parse_range(struct mpd_song *song, const char *value)
508541
}
509542

510543
song->start = start > 0.0 ? (unsigned)start : 0;
544+
song->start_ms = start > 0.0 ? (unsigned)(start * 1000) : 0;
511545

512546
if (end > 0.0) {
513547
song->end = (unsigned)end;
548+
song->end_ms = (unsigned)(end * 1000);
514549
if (song->end == 0)
515550
/* round up, because the caller must sees that
516551
there's an upper limit */
517552
song->end = 1;
518-
} else
553+
} else {
519554
song->end = 0;
555+
song->end_ms = 0;
556+
}
520557
}
521558

522559
static void

0 commit comments

Comments
 (0)