diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2009-08-05 20:02:29 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2009-08-05 20:43:42 +0200 |
commit | ebacbd95aee9ab9693b0518f700ae64e9106512d (patch) | |
tree | 4224330f4256a70bb8924d5b5a78b709726f4b40 | |
parent | 8e2e95f37a8509c7cbc7b85a61ab7b53f9d7b9d3 (diff) |
slightly better song switching (streamer-wise)
-rw-r--r-- | cmp3.c | 19 | ||||
-rw-r--r-- | gtkplaylist.c | 13 | ||||
-rw-r--r-- | streamer.c | 26 | ||||
-rw-r--r-- | streamer.h | 3 |
4 files changed, 47 insertions, 14 deletions
@@ -43,7 +43,6 @@ int cmp3_init (const char *fname, int track, float start, float end) { buffer.file = fopen (fname, "rb"); if (!buffer.file) { - printf ("failed to read %s\n", fname); return -1; } buffer.remaining = 0; @@ -254,10 +253,10 @@ cmp3_scan_stream (float position) { timer.fraction = (int)((duration - (float)timer.seconds)*MAD_TIMER_RESOLUTION); } if (nframe == 0) { - printf ("file doesn't looks like mpeg stream\n"); + //printf ("file doesn't looks like mpeg stream\n"); return -1; } - printf ("song duration: %f\n", duration); + //printf ("song duration: %f\n", duration); return 0; } @@ -302,9 +301,9 @@ cmp3_decode (void) { { if(stream.error!=MAD_ERROR_LOSTSYNC) { - fprintf(stderr,"recoverable frame level error (%s)\n", - MadErrorString(&stream)); - fflush(stderr); + //fprintf(stderr,"recoverable frame level error (%s)\n", + // MadErrorString(&stream)); + //fflush(stderr); } continue; } @@ -313,8 +312,8 @@ cmp3_decode (void) { continue; else { - fprintf(stderr,"unrecoverable frame level error (%s).\n", - MadErrorString(&stream)); + //fprintf(stderr,"unrecoverable frame level error (%s).\n", + // MadErrorString(&stream)); break; } } @@ -614,7 +613,7 @@ convstr (const char* str, int sz) { sz--; iconv_t cd = iconv_open ("utf8", enc); if (!cd) { - printf ("unknown encoding: %s\n", enc); + // printf ("unknown encoding: %s\n", enc); return NULL; } else { @@ -666,7 +665,7 @@ const char *convstr_id3v1 (const char* str, int sz) { } cd = iconv_open ("utf8", enc); if (!cd) { - printf ("unknown encoding: %s\n", enc); + // printf ("unknown encoding: %s\n", enc); return NULL; } else { diff --git a/gtkplaylist.c b/gtkplaylist.c index ead402ac..ebc802f6 100644 --- a/gtkplaylist.c +++ b/gtkplaylist.c @@ -19,6 +19,7 @@ #include "common.h" #include "messagepump.h" #include "messages.h" +#include "streamer.h" extern GtkWidget *mainwin; static GdkPixmap *backbuf; @@ -466,26 +467,35 @@ gtkps_playsong (void) { } else if (playlist_current_ptr) { printf ("restart\n"); + streamer_set_nextsong (ps_get_idx_of (playlist_current_ptr)); +#if 0 ps_start_current (); GtkWidget *widget = lookup_widget (mainwin, "playlist"); redraw_ps_row (widget, ps_get_idx_of (playlist_current_ptr)); +#endif } else if (playlist_row != -1) { printf ("start under cursor\n"); + streamer_set_nextsong (playlist_row); +#if 0 playItem_t *it = ps_get_for_idx (playlist_row); if (it) { ps_set_current (it); } GtkWidget *widget = lookup_widget (mainwin, "playlist"); redraw_ps_row (widget, playlist_row); +#endif } else { printf ("play 1st in list\n"); + streamer_set_nextsong (0); +#if 0 ps_set_current (playlist_head); if (playlist_current_ptr) { GtkWidget *widget = lookup_widget (mainwin, "playlist"); redraw_ps_row (widget, ps_get_idx_of (playlist_current_ptr)); } +#endif } } @@ -578,6 +588,8 @@ gtkps_pausesong (void) { void gtkps_playsongnum (int idx) { + streamer_set_nextsong (idx); +#if 0 playItem_t *it = ps_get_for_idx (playlist_row); if (it) { //if (it != playlist_current_ptr) @@ -594,6 +606,7 @@ gtkps_playsongnum (int idx) { redraw_ps_row (widget, idx); } } +#endif } static int sb_context_id = -1; @@ -23,6 +23,12 @@ static int streaming_terminate; static int streambuffer_fill; static char streambuffer[STREAM_BUFFER_SIZE+1000]; static uintptr_t mutex; +static int nextsong = -1; + +void +streamer_set_nextsong (int song) { + nextsong = song; +} static int streamer_read_async (char *bytes, int size); @@ -32,6 +38,19 @@ streamer_thread (uintptr_t ctx) { codecleft = 0; while (!streaming_terminate) { + if (nextsong >= 0) { + int sng = nextsong; + nextsong = -1; + codec_lock (); + //streambuffer_fill = 0; + codecleft = 0; + codec_unlock (); + if (ps_set_current (ps_get_for_idx (sng)) < 0) { + while (ps_nextsong () < 0) { + usleep (3000); + } + } + } streamer_lock (); if (streambuffer_fill < STREAM_BUFFER_SIZE) { int sz = STREAM_BUFFER_SIZE - streambuffer_fill; @@ -40,8 +59,8 @@ streamer_thread (uintptr_t ctx) { minsize = 16384; } sz = min (minsize, sz); -// printf ("reading %d\n", sz); int bytesread = streamer_read_async (&streambuffer[streambuffer_fill], sz); + //printf ("req=%d, got=%d\n", sz, bytesread); streambuffer_fill += bytesread; } streamer_unlock (); @@ -146,7 +165,7 @@ streamer_read_async (char *bytes, int size) { fbuffer[i*2+1] = fbuffer[i*2+0]; } } - codec_lock (); + //codec_lock (); // convert samplerate srcdata.data_in = g_fbuffer; srcdata.data_out = g_srcbuffer; @@ -156,7 +175,7 @@ streamer_read_async (char *bytes, int size) { srcdata.end_of_input = 0; // src_set_ratio (src, srcdata.src_ratio); src_process (src, &srcdata); - codec_unlock (); + //codec_unlock (); // convert back to s16 format nbytes = size; int genbytes = srcdata.output_frames_gen * 4; @@ -188,7 +207,6 @@ streamer_read_async (char *bytes, int size) { else { // that means EOF while (ps_nextsong () < 0) { - fprintf (stderr, "bad song encountered in playlist, skipping\n"); usleep (3000); } } @@ -19,4 +19,7 @@ streamer_lock (void); void streamer_unlock (void); +void +streamer_set_nextsong (int song); + #endif // __STREAMER_H |