diff src/mpg123/mpg123.c @ 562:997496d252d4 trunk

[svn] Use InputPlayback standard flags in mpg123, drop set_time().
author iabervon
date Sun, 28 Jan 2007 22:14:55 -0800
parents 914c96de3244
children c5022551db57
line wrap: on
line diff
--- a/src/mpg123/mpg123.c	Sun Jan 28 21:09:12 2007 -0800
+++ b/src/mpg123/mpg123.c	Sun Jan 28 22:14:55 2007 -0800
@@ -33,7 +33,7 @@
 PlayerInfo *mpgdec_info = NULL;
 static GThread *decode_thread;
 
-static gboolean audio_error = FALSE, output_opened = FALSE, dopause = FALSE;
+static gboolean output_opened = FALSE, dopause = FALSE;
 gint mpgdec_bitrate, mpgdec_frequency, mpgdec_length, mpgdec_layer,
     mpgdec_lsf;
 gchar *mpgdec_title = NULL, *mpgdec_filename = NULL;
@@ -645,7 +645,8 @@
 
 
 static int
-mpgdec_seek(struct frame *fr, xing_header_t * xh, gboolean vbr, int time)
+mpgdec_seek(InputPlayback *playback, struct frame *fr, xing_header_t * xh, 
+	    gboolean vbr, int time)
 {
     int jumped = -1;
 
@@ -653,16 +654,16 @@
         int percent = ((double) time * 100.0) /
             (mpgdec_info->num_frames * mpgdec_info->tpf);
         int byte = mpgdec_seek_point(xh, percent);
-        jumped = mpgdec_stream_jump_to_byte(fr, byte);
+        jumped = mpgdec_stream_jump_to_byte(playback, fr, byte);
     }
     else if (vbr && mpgdec_length > 0) {
         int byte = ((guint64) time * 1000 * mpgdec_info->filesize) /
             mpgdec_length;
-        jumped = mpgdec_stream_jump_to_byte(fr, byte);
+        jumped = mpgdec_stream_jump_to_byte(playback, fr, byte);
     }
     else {
         int frame = time / mpgdec_info->tpf;
-        jumped = mpgdec_stream_jump_to_frame(fr, frame);
+        jumped = mpgdec_stream_jump_to_frame(playback, fr, frame);
     }
 
     return jumped;
@@ -688,12 +689,12 @@
 
     mpgdec_read_frame_init();
 
-    mpgdec_open_stream(filename, -1, 0);
+    mpgdec_open_stream(playback, filename, -1, 0);
 
-    if (mpgdec_info->eof || !mpgdec_read_frame(&fr))
-        mpgdec_info->eof = TRUE;
+    if (playback->eof || !mpgdec_read_frame(&fr))
+        playback->eof = TRUE;
 
-    if (!mpgdec_info->eof && mpgdec_info->going) {
+    if (!playback->eof && playback->playing) {
         if (mpgdec_cfg.channels == 2)
             fr.single = -1;
         else
@@ -715,7 +716,7 @@
         for (;;) {
             memcpy(&temp_fr, &fr, sizeof(struct frame));
             if (!mpgdec_read_frame(&temp_fr)) {
-                mpgdec_info->eof = TRUE;
+                playback->eof = TRUE;
                 break;
             }
             if (fr.lay != temp_fr.lay ||
@@ -788,26 +789,27 @@
         output_opened = TRUE;
 
         if (!open_output(playback)) {
-            audio_error = TRUE;
-            mpgdec_info->eof = TRUE;
+	    playback->error = TRUE;
+            playback->eof = TRUE;
         }
         else
             play_frame(playback, &fr);
     }
 
     mpgdec_info->first_frame = FALSE;
-    while (mpgdec_info->going) {
+    while (playback->playing) {
         if (mpgdec_info->jump_to_time != -1) {
             void *xp = NULL;
             if (have_xing_header)
                 xp = &xing_header;
-            if (mpgdec_seek(&fr, xp, vbr, mpgdec_info->jump_to_time) > -1) {
+            if (mpgdec_seek(playback, &fr, xp, vbr, 
+			    mpgdec_info->jump_to_time) > -1) {
                 playback->output->flush(mpgdec_info->jump_to_time * 1000);
-                mpgdec_info->eof = FALSE;
+                playback->eof = FALSE;
             }
             mpgdec_info->jump_to_time = -1;
         }
-        if (!mpgdec_info->eof) {
+        if (!playback->eof) {
             if (mpgdec_read_frame(&fr) != 0) {
                 if (fr.lay != mpgdec_layer || fr.lsf != mpgdec_lsf) {
                     memcpy(&temp_fr, &fr, sizeof(struct frame));
@@ -899,7 +901,7 @@
             else {
                 playback->output->buffer_free();
                 playback->output->buffer_free();
-                mpgdec_info->eof = TRUE;
+                playback->eof = TRUE;
                 g_usleep(10000);
             }
         }
@@ -915,11 +917,10 @@
     old_title = NULL;
     mpgdec_title = NULL;
     mpgdec_stream_close();
-    if (output_opened && !audio_error)
+    if (output_opened && !playback->error)
         playback->output->close_audio();
     g_free(mpgdec_pcm_sample);
     mpgdec_filename = NULL;
-    g_free(filename);
 
     return NULL;
 }
@@ -931,12 +932,13 @@
     memset(&temp_fr, 0, sizeof(struct frame));
 
     mpgdec_info = g_malloc0(sizeof(PlayerInfo));
-    mpgdec_info->going = 1;
+    mpgdec_info->playback = playback;
+    playback->playing = TRUE;
     mpgdec_info->first_frame = TRUE;
     mpgdec_info->output_audio = TRUE;
     mpgdec_info->jump_to_time = -1;
     skip_frames = 0;
-    audio_error = FALSE;
+    playback->error = FALSE;
     output_opened = FALSE;
     dopause = FALSE;
 
@@ -945,10 +947,10 @@
 }
 
 static void
-stop(InputPlayback * data)
+stop(InputPlayback * playback)
 {
-    if (mpgdec_info && mpgdec_info->going) {
-        mpgdec_info->going = FALSE;
+    if (mpgdec_info && playback->playing) {
+        playback->playing = FALSE;
         g_thread_join(decode_thread);
         g_free(mpgdec_info);
         mpgdec_info = NULL;
@@ -973,19 +975,6 @@
         dopause = p;
 }
 
-static int
-get_time(InputPlayback * playback)
-{
-    if (audio_error)
-        return -2;
-    if (!mpgdec_info)
-        return -1;
-    if (!mpgdec_info->going
-        || (mpgdec_info->eof && !playback->output->buffer_playing()))
-        return -1;
-    return playback->output->output_time();
-}
-
 static void
 aboutbox(void)
 {
@@ -1022,7 +1011,7 @@
     do_pause,
     seek,
     NULL,
-    get_time,
+    NULL,
     NULL, NULL,
     cleanup,
     NULL,