commit - 1b77ad485132dd80c7671fc8119cc0c6dc00d6e1
commit + ff06024f86fb68ea11b030f669b162794eb5bc19
blob - 62e1d02ba3a388d9eb1249ec41f666d8270c6466
blob + 010475656324920fc1b72c00b83ce54e1fa499e6
--- amused.c
+++ amused.c
datalen = IMSG_DATA_SIZE(imsg);
switch (imsg.hdr.type) {
+ case IMSG_POS:
+ if (datalen != sizeof(current_position))
+ fatalx("IMSG_POS: got wrong size (%zu vs %zu)",
+ datalen, sizeof(current_position));
+ memcpy(¤t_position, imsg.data,
+ sizeof(current_position));
+ if (current_position < 0)
+ current_position = -1;
+ break;
+ case IMSG_LEN:
+ if (datalen != sizeof(current_duration))
+ fatalx("IMSG_LEN: got wrong size (%zu vs %zu)",
+ datalen, sizeof(current_duration));
+ memcpy(¤t_duration, imsg.data,
+ sizeof(current_duration));
+ if (current_duration < 0)
+ current_duration = -1;
+ break;
case IMSG_ERR:
if (datalen == 0)
errstr = "unknown error";
if (current_song != NULL)
strlcpy(s.path, current_song, sizeof(s.path));
s.status = play_state;
+ s.position = current_position;
+ s.duration = current_duration;
s.rp.repeat_all = repeat_all;
s.rp.repeat_one = repeat_one;
blob - a367a2191db86563bc283b6308007026c0c1b6c6
blob + f6bc33c15b87d092b1e6e218184abe3dc651c267
--- amused.h
+++ amused.h
IMSG_RESUME,
IMSG_PAUSE,
IMSG_STOP,
+ IMSG_POS,
+ IMSG_LEN,
IMSG_EOF,
IMSG_ERR, /* error string */
struct player_status {
char path[PATH_MAX];
int status;
+ int64_t position;
+ int64_t duration;
struct player_repeat rp;
};
/* player.c */
int player_setup(int, int, int);
+void player_setduration(int64_t);
int play(const void *, size_t);
int player(int, int);
blob - defeffcce38cf120112997bc240612b02ed0f6b0
blob + 848f14a3c782c9627ef53a7817254da3b3cfaf9f
--- player.c
+++ player.c
#include "xmalloc.h"
struct sio_hdl *hdl;
+struct sio_par par;
struct pollfd *player_pfds;
static struct imsgbuf *ibuf;
static int stopped = 1;
static int nextfd = -1;
+static int64_t samples;
volatile sig_atomic_t halted;
int
player_setup(int bits, int rate, int channels)
{
- static struct sio_par par;
int nfds, fpct;
log_debug("%s: bits=%d, rate=%d, channels=%d", __func__,
}
stopped = 0;
return 0;
+}
+
+void
+player_setduration(int64_t duration)
+{
+ int64_t seconds;
+
+ seconds = duration / par.rate;
+ imsg_compose(ibuf, IMSG_LEN, 0, 0, -1, &seconds, sizeof(seconds));
+ imsg_flush(ibuf);
+}
+
+void
+player_onmove(void *arg, int delta)
+{
+ static int64_t reported;
+ int64_t sec;
+
+ samples += delta;
+ if (llabs(samples - reported) >= par.rate) {
+ reported = samples;
+ sec = samples / par.rate;
+
+ imsg_compose(ibuf, IMSG_POS, 0, 0, -1, &sec, sizeof(sec));
+ imsg_flush(ibuf);
+ }
}
/* process only one message */
assert(nextfd != -1);
nextfd = -1;
+ /* reset samples and set position to zero */
+ samples = 0;
+ imsg_compose(ibuf, IMSG_POS, 0, 0, -1, &samples, sizeof(samples));
+ imsg_flush(ibuf);
+
r = read(fd, buf, sizeof(buf));
/* 8 byte is the larger magic number */
if ((hdl = sio_open(SIO_DEVANY, SIO_PLAY, 1)) == NULL)
fatal("sio_open");
+ sio_onmove(hdl, player_onmove, NULL);
+
/* allocate one extra for imsg */
player_pfds = calloc(sio_nfds(hdl) + 1, sizeof(*player_pfds));
if (player_pfds == NULL)
blob - 472bbfe1eb473d4adaaaf1db2e12e9055f47ceed
blob + 64e5452d7f2e271272ce6f375187a95109068027
--- player_123.c
+++ player_123.c
if (!setup(mh))
goto done;
+ player_setduration(mpg123_length(mh));
+
for (;;) {
err = mpg123_read(mh, buf, sizeof(buf), &len);
switch (err) {
blob - 88846e8f416041db4d6c326b5a2e7ef14ffd2e91
blob + 58fc73e10d2b517e8e87573da6fcf6e743f3b86e
--- player_flac.c
+++ player_flac.c
if (player_setup(bits, sample_rate, channels) == -1)
err(1, "player_setup");
+
+ player_setduration(meta->data.stream_info.total_samples);
}
}
blob - 1c9ebd7895c4eb54f0153630e9d31880ec5d49b8
blob + 218771d35ea22a6ad324b2cc6aadfe4d4d72cd9d
--- player_oggvorbis.c
+++ player_oggvorbis.c
if (player_setup(16, vi->rate, vi->channels) == -1)
err(1, "player_setup");
+ player_setduration(ov_time_total(&vf, -1) * vi->rate);
+
while (!eof) {
long r;
blob - 168cde58de46948e84dfc38bec48333ad817214e
blob + 2df2f10b98c6f44843387b38112266d3bbe9d1e5
--- player_opus.c
+++ player_opus.c
void *f;
int r, ret = 0;
OpusFileCallbacks cb = {NULL, NULL, NULL, NULL};
- int i, li, prev_li = -1;
+ int i, li, prev_li = -1, duration_set = 0;
if ((f = op_fdopen(&cb, fd, "r")) == NULL)
err(1, "fdopen");
if (head->input_sample_rate &&
player_setup(16, head->input_sample_rate, 2) == -1)
err(1, "player_setup");
+
+ if (!duration_set) {
+ duration_set = 1;
+ player_setduration(op_pcm_total(of, -1));
+ }
}
for (i = 0; i < 2*r; ++i) {
blob - 3db2815c6b8aeb82a2d7d9efc18ba3b6de7e037a
blob + f2821ef2c9500cc78ba6202d4a4a171047d46fd4
--- playlist.c
+++ playlist.c
int repeat_all = 1;
ssize_t play_off = -1;
const char *current_song;
+int64_t current_position;
+int64_t current_duration;
static void
setsong(ssize_t i)
blob - 63b7b13c147f39aef28532cf6b5851e6ff795ce1
blob + 661528a56a0c09521566e5336720e9e905af4240
--- playlist.h
+++ playlist.h
extern int repeat_all;
extern ssize_t play_off;
extern const char *current_song;
+extern int64_t current_position;
+extern int64_t current_duration;
void playlist_swap(struct playlist *, ssize_t);
void playlist_push(struct playlist *, const char *);