changeset 2132:3aa95f65c24d

Automated merge with ssh://hg.atheme.org//hg/audacious-plugins
author William Pitcock <nenolod@atheme.org>
date Sat, 27 Oct 2007 07:26:32 -0500
parents c162b6a0f11f (diff) 902540201c0d (current diff)
children bba61e3fe881
files src/paranormal-ng/.depend src/paranormal-ng/libcalc/.depend src/paranormal-ng/presets/.depend src/paranormal-ng/presets/.depend-done src/vorbis/vorbis.c
diffstat 1 files changed, 21 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/src/vorbis/vorbis.c	Sat Oct 27 13:10:24 2007 +0300
+++ b/src/vorbis/vorbis.c	Sat Oct 27 07:26:32 2007 -0500
@@ -63,7 +63,6 @@
 extern vorbis_config_t vorbis_cfg;
 
 static Tuple *get_song_tuple(gchar *filename);
-static int vorbis_check_file(char *filename);
 static int vorbis_check_fd(char *filename, VFSFile *stream);
 static void vorbis_play(InputPlayback *data);
 static void vorbis_stop(InputPlayback *data);
@@ -91,6 +90,13 @@
     ovcb_tell
 };
 
+ov_callbacks vorbis_callbacks_stream = {
+    ovcb_read,
+    NULL,
+    ovcb_close,
+    NULL
+};
+
 gchar *vorbis_fmts[] = { "ogg", "ogm", NULL };
 
 InputPlugin vorbis_ip = {
@@ -98,7 +104,6 @@
     .init = vorbis_init,                /* init */
     .about = vorbis_aboutbox,            /* aboutbox */
     .configure = vorbis_configure,           /* configure */
-    .is_our_file = vorbis_check_file,          /* is_our_file */
     .play_file = vorbis_play,
     .stop = vorbis_stop,
     .pause = vorbis_pause,
@@ -118,8 +123,6 @@
 static OggVorbis_File vf;
 
 static GThread *thread;
-static int vorbis_is_streaming = 0;
-static int vorbis_bytes_streamed = 0;
 static volatile int seekneeded = -1;
 static int samplerate, channels;
 GMutex *vf_mutex;
@@ -127,89 +130,6 @@
 gchar **vorbis_tag_encoding_list = NULL;
 
 static int
-vorbis_check_file(char *filename)
-{
-    VFSFile *stream;
-    OggVorbis_File vfile;       /* avoid thread interaction */
-    gint result;
-    VFSVorbisFile *fd;
-
-    if (!(stream = aud_vfs_fopen(filename, "r"))) {
-        return FALSE;
-    }
-
-    fd = g_new0(VFSVorbisFile, 1);
-    fd->fd = stream;
-    fd->probe = TRUE;
-
-    /*
-     * The open function performs full stream detection and machine
-     * initialization.  If it returns zero, the stream *is* Vorbis and
-     * we're fully ready to decode.
-     */
-
-    /* libvorbisfile isn't thread safe... */
-    memset(&vfile, 0, sizeof(vfile));
-    g_mutex_lock(vf_mutex);
-
-    result = ov_test_callbacks(fd, &vfile, NULL, 0, vorbis_callbacks);
-
-    switch (result) {
-    case OV_EREAD:
-#ifdef DEBUG
-        g_message("** vorbis.c: Media read error: %s", filename);
-#endif
-        g_mutex_unlock(vf_mutex);
-        aud_vfs_fclose(stream);
-        return FALSE;
-        break;
-    case OV_ENOTVORBIS:
-#ifdef DEBUG
-        g_message("** vorbis.c: Not Vorbis data: %s", filename);
-#endif
-        g_mutex_unlock(vf_mutex);
-        aud_vfs_fclose(stream);
-        return FALSE;
-        break;
-    case OV_EVERSION:
-#ifdef DEBUG
-        g_message("** vorbis.c: Version mismatch: %s", filename);
-#endif
-        g_mutex_unlock(vf_mutex);
-        aud_vfs_fclose(stream);
-        return FALSE;
-        break;
-    case OV_EBADHEADER:
-#ifdef DEBUG
-        g_message("** vorbis.c: Invalid Vorbis bistream header: %s",
-                  filename);
-#endif
-        g_mutex_unlock(vf_mutex);
-        aud_vfs_fclose(stream);
-        return FALSE;
-        break;
-    case OV_EFAULT:
-#ifdef DEBUG
-        g_message("** vorbis.c: Internal logic fault while reading %s",
-                  filename);
-#endif
-        g_mutex_unlock(vf_mutex);
-        aud_vfs_fclose(stream);
-        return FALSE;
-        break;
-    case 0:
-        break;
-    default:
-        break;
-    }
-
-    ov_clear(&vfile);           /* once the ov_open succeeds, the stream belongs to
-                                   vorbisfile.a.  ov_clear will fclose it */
-    g_mutex_unlock(vf_mutex);
-    return TRUE;
-}
-
-static int
 vorbis_check_fd(char *filename, VFSFile *stream)
 {
     OggVorbis_File vfile;       /* avoid thread interaction */
@@ -230,7 +150,7 @@
     memset(&vfile, 0, sizeof(vfile));
     g_mutex_lock(vf_mutex);
 
-    result = ov_test_callbacks(fd, &vfile, NULL, 0, vorbis_callbacks);
+    result = ov_test_callbacks(fd, &vfile, NULL, 0, aud_vfs_is_streaming(stream) ? vorbis_callbacks_stream : vorbis_callbacks);
 
     switch (result) {
     case OV_EREAD:
@@ -304,7 +224,7 @@
 static void
 do_seek(InputPlayback *playback)
 {
-    if (seekneeded != -1 && !vorbis_is_streaming) {
+    if (seekneeded != -1) {
         vorbis_jump_to_time(playback, seekneeded);
         seekneeded = -1;
         playback->eof = FALSE;
@@ -438,7 +358,7 @@
      */
 
     g_mutex_lock(vf_mutex);
-    if (ov_open_callbacks(datasource, &vf, NULL, 0, vorbis_callbacks) < 0) {
+    if (ov_open_callbacks(datasource, &vf, NULL, 0, aud_vfs_is_streaming(fd->fd) ? vorbis_callbacks_stream : vorbis_callbacks) < 0) {
         vorbis_callbacks.close_func(datasource);
         g_mutex_unlock(vf_mutex);
         playback->eof = TRUE;
@@ -446,10 +366,7 @@
     }
     vi = ov_info(&vf, -1);
 
-    /* XXX this isn't very correct, but it works */
-    vorbis_is_streaming = ((time = ov_time_total(&vf, -1)) <= 1.);
-
-    if (vorbis_is_streaming)
+    if (aud_vfs_is_streaming(fd->fd))
     {
         time = -1;
 	vf.seekable = FALSE;   /* XXX: don't ask. -nenolod */
@@ -513,9 +430,7 @@
             title = vorbis_generate_title(&vf, filename);
             use_rg = vorbis_update_replaygain(&rg_scale);
 
-            if (vorbis_is_streaming)
-                time = -1;
-            else
+            if (time != -1)
                 time = ov_time_total(&vf, -1) * 1000;
 
             g_mutex_unlock(vf_mutex);
@@ -540,7 +455,6 @@
     g_mutex_lock(vf_mutex);
     ov_clear(&vf);
     g_mutex_unlock(vf_mutex);
-    vorbis_is_streaming = 0;
     playback->playing = 0;
     return NULL;
 }
@@ -549,7 +463,6 @@
 vorbis_play(InputPlayback *playback)
 {
     playback->playing = 1;
-    vorbis_bytes_streamed = 0;
     playback->eof = 0;
     playback->error = FALSE;
 
@@ -576,9 +489,6 @@
 static void
 vorbis_seek(InputPlayback *data, int time)
 {
-    if (vorbis_is_streaming)
-        return;
-
     seekneeded = time;
 
     while (seekneeded != -1)
@@ -728,11 +638,15 @@
  * Ok, nhjm449! Are you *happy* now?!  -nenolod
  */
 static Tuple *
-get_aud_tuple_for_vorbisfile(OggVorbis_File * vorbisfile, gchar *filename, gboolean is_stream)
+get_aud_tuple_for_vorbisfile(OggVorbis_File * vorbisfile, gchar *filename)
 {
+    VFSVorbisFile *vfd = (VFSVorbisFile *) vorbisfile->datasource;
     Tuple *tuple = NULL;
+    gboolean is_stream;
     vorbis_comment *comment;
+
     tuple = aud_tuple_new_from_filename(filename);
+    is_stream = aud_vfs_is_streaming(vfd->fd);
 
     /* Retrieve the length */
     aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL,
@@ -771,7 +685,6 @@
     VFSFile *stream = NULL;
     OggVorbis_File vfile;          /* avoid thread interaction */
     Tuple *tuple = NULL;
-    gboolean is_stream = FALSE;
     VFSVorbisFile *fd = NULL;
 
     if ((stream = aud_vfs_fopen(filename, "r")) == NULL)
@@ -785,13 +698,12 @@
      * machine initialization.  If it returns zero, the stream
      * *is* Vorbis and we're fully ready to decode.
      */
-    if (ov_open_callbacks(fd, &vfile, NULL, 0, vorbis_callbacks) < 0) {
-        if (is_stream == FALSE)
-            aud_vfs_fclose(stream);
+    if (ov_open_callbacks(fd, &vfile, NULL, 0, aud_vfs_is_streaming(stream) ? vorbis_callbacks_stream : vorbis_callbacks) < 0) {
+        aud_vfs_fclose(stream);
         return NULL;
     }
 
-    tuple = get_aud_tuple_for_vorbisfile(&vfile, filename, is_stream);
+    tuple = get_aud_tuple_for_vorbisfile(&vfile, filename);
 
     /*
      * once the ov_open succeeds, the stream belongs to
@@ -810,7 +722,7 @@
     Tuple *input;
     gchar *tmp;
 
-    input = get_aud_tuple_for_vorbisfile(vorbisfile, filename, vorbis_is_streaming);
+    input = get_aud_tuple_for_vorbisfile(vorbisfile, filename);
 
     displaytitle = aud_tuple_formatter_make_title_string(input, vorbis_cfg.tag_override ?
                                                   vorbis_cfg.tag_format : aud_get_gentitle_format());