summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2019-02-12 09:44:57 +0100
committerLars-Dominik Braun <lars@6xq.net>2019-02-14 09:24:14 +0100
commit24852ca110c7240dd5c57aa7201d802302a097ce (patch)
tree5ec7b14adb45ac4da2fe29cb5d29131440ca57b5 /src
parentde41ceabebb3decd46456fb7c81a3f7a4e1dd29a (diff)
downloadpianobar-24852ca110c7240dd5c57aa7201d802302a097ce.tar.gz
pianobar-24852ca110c7240dd5c57aa7201d802302a097ce.tar.bz2
pianobar-24852ca110c7240dd5c57aa7201d802302a097ce.zip
player: Fix time display for MP3 files
Their time_base is not the same for stream and buffersink. See issue #678.
Diffstat (limited to 'src')
-rw-r--r--src/player.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/player.c b/src/player.c
index d3eb475..92f230e 100644
--- a/src/player.c
+++ b/src/player.c
@@ -519,6 +519,7 @@ void *BarAoPlayThread (void *data) {
assert (filteredFrame != NULL);
int ret;
+ const AVRational timeBase = av_buffersink_get_time_base (player->fbufsink);
while (!shouldQuit(player)) {
pthread_mutex_lock (&player->aoplayLock);
ret = av_buffersink_get_frame (player->fbufsink, filteredFrame);
@@ -541,11 +542,13 @@ void *BarAoPlayThread (void *data) {
ao_play (player->aoDev, (char *) filteredFrame->data[0],
filteredFrame->nb_samples * numChannels * bps);
- const unsigned int songPlayed = av_q2d (player->st->time_base) *
- (double) filteredFrame->pts;
+ /* we could also use av_q2d here and use double arithmetic */
+ const AVRational ptsQ = av_make_q (filteredFrame->pts, 1);
+ const AVRational timestampQ = av_mul_q (timeBase, ptsQ);
+ const unsigned int songPlayed = timestampQ.num/timestampQ.den;
+
pthread_mutex_lock (&player->lock);
player->songPlayed = songPlayed;
-
/* pausing */
if (player->doPause) {
do {