Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds more information to parse corresponding to the satellite cue fix pr in MPD repository #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions include/mpd/song.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ const char *
mpd_song_get_tag(const struct mpd_song *song,
enum mpd_tag_type type, unsigned idx);

/**
* Returns the "real" URI of the song, the one to be used for opening
* the resource. If this attribute is nullptr, then #mpd_song_get_uri
* shall be used.
*/
mpd_pure
const char *
mpd_song_get_real_uri(const struct mpd_song *song);

/**
* Returns the duration of this song in seconds. 0 means the duration
* is unknown.
Expand Down Expand Up @@ -128,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.
Expand All @@ -138,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
Expand Down
3 changes: 3 additions & 0 deletions libmpdclient.ld
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,13 @@ global:
mpd_song_dup;
mpd_song_get_uri;
mpd_song_get_tag;
mpd_song_get_real_uri;
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;
Expand Down
66 changes: 65 additions & 1 deletion src/song.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ struct mpd_song {

struct mpd_tag_value tags[MPD_TAG_COUNT];

/**
* The "real" URI, the one to be used for opening the
* resource. If this attribute is nullptr, then #uri
* shall be used.
*/
char *real_uri;

/**
* Duration of the song in seconds, or 0 for unknown.
*/
Expand All @@ -71,13 +78,26 @@ 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
* played to the end.
*/
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.
Expand Down Expand Up @@ -136,10 +156,13 @@ mpd_song_new(const char *uri)
for (unsigned i = 0; i < MPD_TAG_COUNT; ++i)
song->tags[i].value = NULL;

song->real_uri = NULL;
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;
Expand Down Expand Up @@ -179,6 +202,8 @@ void mpd_song_free(struct mpd_song *song) {
}
}

free(song->real_uri);

free(song);
}

Expand Down Expand Up @@ -216,10 +241,13 @@ mpd_song_dup(const struct mpd_song *song)
} while (src_tag != NULL);
}

ret->real_uri = strdup(song->real_uri);
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;
Expand Down Expand Up @@ -331,6 +359,20 @@ mpd_song_get_tag(const struct mpd_song *song,
return tag->value;
}

static void
mpd_song_set_real_uri(struct mpd_song *song, char *real_uri)
{
song->real_uri = real_uri;
}

const char *
mpd_song_get_real_uri(const struct mpd_song *song)
{
assert(song != NULL);

return song->real_uri;
}

static void
mpd_song_set_duration(struct mpd_song *song, unsigned duration)
{
Expand Down Expand Up @@ -371,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)
{
Expand All @@ -379,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)
{
Expand Down Expand Up @@ -483,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
Expand Down Expand Up @@ -546,6 +608,8 @@ mpd_song_feed(struct mpd_song *song, const struct mpd_pair *pair)
mpd_song_set_prio(song, strtoul(pair->value, NULL, 10));
else if (strcmp(pair->name, "Format") == 0)
mpd_song_parse_audio_format(song, pair->value);
else if (strcmp(pair->name, "RealUri") == 0)
mpd_song_set_real_uri(song, strdup(pair->value));

return true;
}
Expand Down