diff options
-rw-r--r-- | callbacks.c | 2 | ||||
-rw-r--r-- | cdumb.c | 8 | ||||
-rw-r--r-- | cflac.c | 26 | ||||
-rw-r--r-- | cgme.c | 8 | ||||
-rw-r--r-- | cmp3.c | 8 | ||||
-rw-r--r-- | codec.h | 3 | ||||
-rw-r--r-- | csid.cpp | 12 | ||||
-rw-r--r-- | cvorbis.c | 4 | ||||
-rw-r--r-- | main.c | 7 | ||||
-rw-r--r-- | streamer.c | 12 | ||||
-rw-r--r-- | streamer.h | 3 |
11 files changed, 48 insertions, 45 deletions
diff --git a/callbacks.c b/callbacks.c index 6d8f2e25..c0b51d47 100644 --- a/callbacks.c +++ b/callbacks.c @@ -880,7 +880,7 @@ seekbar_draw (GtkWidget *widget) { } else { if (playlist_current.codec && playlist_current.duration > 0) { - pos = playlist_current.codec->info.position / playlist_current.duration; + pos = streamer_get_playpos () / playlist_current.duration; pos *= widget->allocation.width; } } @@ -97,7 +97,7 @@ cdumb_init (playItem_t *it) { cdumb.info.bitsPerSample = 16; cdumb.info.channels = 2; cdumb.info.samplesPerSecond = p_get_rate (); - cdumb.info.position = 0; + cdumb.info.readposition = 0; if (cdumb_startrenderer () < 0) { return -1; @@ -150,15 +150,15 @@ cdumb_read (char *bytes, int size) { int cdumb_seek (float time) { - if (time < cdumb.info.position) { + if (time < cdumb.info.readposition) { cdumb_startrenderer (); } else { - time -= cdumb.info.position; + time -= cdumb.info.readposition; } int pos = time * cdumb.info.samplesPerSecond; duh_sigrenderer_generate_samples (renderer, 0, 65536.0f / cdumb.info.samplesPerSecond, pos, NULL); - cdumb.info.position = duh_sigrenderer_get_position (renderer) / 65536.f; + cdumb.info.readposition = duh_sigrenderer_get_position (renderer) / 65536.f; return 0; } @@ -69,7 +69,7 @@ cflac_metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMe cflac.info.samplesPerSecond = sample_rate; cflac.info.channels = channels; cflac.info.bitsPerSample = bps; - cflac.info.position = 0; + cflac.info.readposition = 0; } void @@ -106,21 +106,8 @@ cflac_init (playItem_t *it) { timestart = it->timestart; timeend = it->timeend; if (timeend > timestart || timeend < 0) { - // take from cue and seek -// if (timeend < 0) { -// // must be last (or broken) track -// timeend = playlist_current.duration; // set from metainfo -// } -// cflac.info.duration = timeend - timestart; cflac.seek (0); } -// if (cflac.info.duration == -1) { -// printf ("FLAC duration calculation failed\n"); -// return -1; -// } -// else { -// //printf ("%s duration %f, start %f (%f), end %f (%f)\n", fname, cflac.info.duration, timestart, start, timeend, end); -// } remaining = 0; return 0; @@ -138,6 +125,11 @@ int cflac_read (char *bytes, int size) { int initsize = size; int nsamples = size / (cflac.info.channels * cflac.info.bitsPerSample / 8); + if (timeend > timestart) { + if (cflac.info.readposition + timestart > timeend) { + return 0; + } + } do { if (remaining) { int sz = min (remaining, size); @@ -148,9 +140,9 @@ cflac_read (char *bytes, int size) { remaining -= sz; bytes += sz; size -= sz; -// cflac.info.position += (float)sz / (cflac.info.channels * cflac.info.samplesPerSecond * cflac.info.bitsPerSample / 8); + cflac.info.readposition += (float)sz / (cflac.info.channels * cflac.info.samplesPerSecond * cflac.info.bitsPerSample / 8); if (timeend > timestart) { - if (cflac.info.position + timestart > timeend) { + if (cflac.info.readposition + timestart > timeend) { break; } } @@ -179,7 +171,7 @@ cflac_seek (float time) { return -1; } remaining = 0; - cflac.info.position = time - timestart; + cflac.info.readposition = time - timestart; return 0; } @@ -43,7 +43,7 @@ cgme_init (playItem_t *it) { cgme.info.samplesPerSecond = p_get_rate (); reallength = inf.length; nzerosamples = 0; - cgme.info.position = 0; + cgme.info.readposition = 0; return 0; } @@ -58,8 +58,8 @@ cgme_free (void) { int cgme_read (char *bytes, int size) { float t = (size/4) / (float)cgme.info.samplesPerSecond; - if (cgme.info.position + t >= playlist_current.duration) { - t = playlist_current.duration - cgme.info.position; + if (cgme.info.readposition + t >= playlist_current.duration) { + t = playlist_current.duration - cgme.info.readposition; if (t <= 0) { return 0; } @@ -96,7 +96,7 @@ cgme_seek (float time) { if (gme_seek (emu, (long)(time * 1000))) { return -1; } - cgme.info.position = time; + cgme.info.readposition = time; return 0; } @@ -111,7 +111,7 @@ cmp3_init (struct playItem_s *it) { buffer.output = NULL; buffer.readsize = 0; buffer.cachefill = 0; - cmp3.info.position = 0; + cmp3.info.readposition = 0; mad_timer_reset(&buffer.timer); fseek (buffer.file, buffer.startoffset, SEEK_SET); @@ -617,15 +617,15 @@ cmp3_seek (float time) { mad_timer_reset(&buffer.timer); if (time == 0) { - cmp3.info.position = 0; + cmp3.info.readposition = 0; return 0; } if (cmp3_scan_stream (&buffer, time) == -1) { - cmp3.info.position = 0; + cmp3.info.readposition = 0; return -1; } - cmp3.info.position = (float)buffer.timer.seconds + (float)buffer.timer.fraction / MAD_TIMER_RESOLUTION; + cmp3.info.readposition = (float)buffer.timer.seconds + (float)buffer.timer.fraction / MAD_TIMER_RESOLUTION; return 0; } @@ -25,7 +25,8 @@ typedef struct { int bitsPerSample; int channels; int samplesPerSecond; - float position; +// float position; + float readposition; } fileinfo_t; struct playItem_s; @@ -276,7 +276,7 @@ csid_init (struct playItem_s *it) { sidplay->load (tune); csid.info.bitsPerSample = 16; csid.info.samplesPerSecond = p_get_rate (); - csid.info.position = 0; + csid.info.readposition = 0; int maxsids = sidplay->info ().maxsids; for (int k = 0; k < maxsids; k++) { @@ -303,23 +303,23 @@ csid_free (void) { extern "C" int csid_read (char *bytes, int size) { - if (csid.info.position > playlist_current.duration) { + if (csid.info.readposition > playlist_current.duration) { return 0; } int rd = sidplay->play (bytes, size/csid.info.channels); -// csid.info.position += size/csid.info.channels/2 / (float)csid.info.samplesPerSecond; + csid.info.readposition += size/csid.info.channels/2 / (float)csid.info.samplesPerSecond; return rd * csid.info.channels; } extern "C" int csid_seek (float time) { float t = time; - if (t < csid.info.position) { + if (t < csid.info.readposition) { // reinit sidplay->load (tune); } else { - t -= csid.info.position; + t -= csid.info.readposition; } resid->filter (false); int samples = t * csid.info.samplesPerSecond; @@ -335,7 +335,7 @@ csid_seek (float time) { samples -= done; } resid->filter (true); - csid.info.position = time; + csid.info.readposition = time; return 0; } @@ -54,7 +54,7 @@ cvorbis_init (struct playItem_s *it) { //cvorbis.info.dataSize = ov_pcm_total (&vorbis_file, -1) * vi->channels * 2; cvorbis.info.channels = vi->channels; cvorbis.info.samplesPerSecond = vi->rate; - cvorbis.info.position = 0; + cvorbis.info.readposition = 0; // printf ("vorbis info: bps: %d, size: %d, chan: %d, rate: %d, dur: %f\n", cvorbis.info.bitsPerSample, cvorbis.info.dataSize, cvorbis.info.channels, cvorbis.info.samplesPerSecond, cvorbis.info.duration); return 0; } @@ -109,7 +109,7 @@ cvorbis_seek (float time) { int res = ov_time_seek (&vorbis_file, time); if (res != 0 && res != OV_ENOSEEK) return -1; - cvorbis.info.position = ov_time_tell(&vorbis_file); + cvorbis.info.readposition = ov_time_tell(&vorbis_file); // printf ("seek result: %d\n", res); return 0; } @@ -73,14 +73,15 @@ update_songinfo (void) { else if (playlist_current.codec) { codec_lock (); codec_t *c = playlist_current.codec; - int minpos = c->info.position / 60; - int secpos = c->info.position - minpos * 60; + float playpos = streamer_get_playpos (); + int minpos = playpos / 60; + int secpos = playpos - minpos * 60; int mindur = playlist_current.duration / 60; int secdur = playlist_current.duration - mindur * 60; const char *mode = c->info.channels == 1 ? "Mono" : "Stereo"; int samplerate = c->info.samplesPerSecond; int bitspersample = c->info.bitsPerSample; - songpos = c->info.position; + songpos = playpos; codec_unlock (); snprintf (sbtext_new, 512, "[%s] %dHz | %d bit | %s | %d:%02d / %d:%02d | %d songs total", playlist_current.filetype ? playlist_current.filetype:"-", samplerate, bitspersample, mode, minpos, secpos, mindur, secdur, pl_getcount ()); @@ -48,6 +48,13 @@ static int nextsong_pstate = -1; static float seekpos = -1; +static float playpos = 0; // play position of current song + +float +streamer_get_playpos (void) { + return playpos; +} + void streamer_set_nextsong (int song, int pstate) { nextsong = song; @@ -102,6 +109,7 @@ streamer_thread (uintptr_t ctx) { seekpos = -1; if (playlist_current.codec && playlist_current.codec->seek (pos) >= 0) { streamer_lock (); + playpos = playlist_current.codec->info.readposition; streambuffer_fill = 0; streamer_unlock (); codec_lock (); @@ -301,9 +309,7 @@ streamer_read (char *bytes, int size) { memmove (streambuffer, &streambuffer[sz], streambuffer_fill-sz); } streambuffer_fill -= sz; - if (playlist_current.codec) { - playlist_current.codec->info.position += (float)sz/p_get_rate ()/4.f; - } + playpos += (float)sz/p_get_rate ()/4.f; bytes_until_next_song -= sz; if (bytes_until_next_song < 0) { bytes_until_next_song = 0; @@ -49,4 +49,7 @@ streamer_set_seek (float pos); int streamer_get_fill_level (void); +float +streamer_get_playpos (void); + #endif // __STREAMER_H |