changeset 1660:4c72daee66e3 trunk

[svn] rtsp support in mp3
author lu_zero
date Sat, 09 Sep 2006 21:52:25 -0700
parents eeaf62b288a3
children a588ea8ec873
files ChangeLog Plugins/Input/mpg123/Makefile.in Plugins/Input/mpg123/common.c Plugins/Input/mpg123/mpg123.c Plugins/Input/mpg123/mpg123.h Plugins/Input/mpg123/rtsp.c audacious/credits.c configure.ac mk/rules.mk.in
diffstat 9 files changed, 194 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Sep 09 18:04:36 2006 -0700
+++ b/ChangeLog	Sat Sep 09 21:52:25 2006 -0700
@@ -1,3 +1,11 @@
+2006-09-10 01:04:36 +0000  Tony Vroon <chainsaw@gentoo.org>
+  revision [2255]
+  Make the playback resume code a lot more robust.
+
+  Changes:        Modified:
+  +6 -3           trunk/audacious/main.c  
+
+
 2006-09-10 01:02:42 +0000  
   revision [2253]
   avoid segfaults
--- a/Plugins/Input/mpg123/Makefile.in	Sat Sep 09 18:04:36 2006 -0700
+++ b/Plugins/Input/mpg123/Makefile.in	Sat Sep 09 21:52:25 2006 -0700
@@ -8,14 +8,14 @@
 SOURCES = mpg123.c configure.c fileinfo.c common.c \
 	resample.c \
 	layer1.c layer2.c layer3.c \
-	tabinit.c http.c \
+	tabinit.c http.c $(LIBNMS_SRC) \
 	dxhead.c decode.c $(DCT64) paranoia.c interface.c
 
 OBJECTS = ${SOURCES:.c=.o} tag_c_hacked.o
 
-CFLAGS   += -UPSYCHO $(PICFLAGS) $(GTK_CFLAGS) $(TAGLIB_CFLAGS) $(ARCH_DEFINES) -I../../../intl -I../../..
+CFLAGS   += -UPSYCHO $(PICFLAGS) $(GTK_CFLAGS) $(TAGLIB_CFLAGS) $(ARCH_DEFINES) $(LIBNMS_CFLAGS) -I../../../intl -I../../..
 CXXFLAGS += -UPSYCHO $(PICFLAGS) $(GTK_CFLAGS) $(TAGLIB_CFLAGS) $(ARCH_DEFINES) -I../../../intl -I../../..
 
-LIBADD = -ltag_c $(GTK_LIBS) $(TAGLIB_LIBS)
+LIBADD = -ltag_c $(GTK_LIBS) $(TAGLIB_LIBS) $(LIBNMS_LIBS)
 
 include ../../../mk/objective.mk
--- a/Plugins/Input/mpg123/common.c	Sat Sep 09 18:04:36 2006 -0700
+++ b/Plugins/Input/mpg123/common.c	Sat Sep 09 21:52:25 2006 -0700
@@ -50,7 +50,18 @@
         if (fd)
             ret = vfs_fread(buf + cnt, 1, count - cnt, fd);
         else
-            ret = mpgdec_http_read(buf + cnt, count - cnt);
+            switch(mpgdec_info->stream_type) {
+                case STREAM_HTTP:
+                    ret = mpgdec_http_read(buf + cnt, count - cnt);
+                    break;
+#ifdef HAVE_NEMESI
+                case STREAM_RTSP:
+                    ret = mpgdec_rtsp_read(buf + cnt, count - cnt);
+                    break;
+#endif
+                default:
+                    return -1;
+            }
         if (ret < 0)
             return ret;
         if (ret == 0)
@@ -73,8 +84,19 @@
 {
     if (filept)
         vfs_fclose(filept);
-    else if (mpgdec_info->network_stream)
-        mpgdec_http_close();
+    else 
+        switch(mpgdec_info->stream_type) {
+            case STREAM_HTTP:
+                mpgdec_http_close();
+                break;
+#ifdef HAVE_NEMESI
+            case STREAM_RTSP:
+                mpgdec_rtsp_close();
+                break;
+#endif
+            default:
+                break;
+        }
 }
 
 /**************************************** 
@@ -368,8 +390,18 @@
         mpgdec_http_open(bs_filenam);
         mpgdec_info->filesize = 0;
         mpgdec_info->network_stream = TRUE;
-    }
-    else {
+        mpgdec_info->stream_type = STREAM_HTTP;
+    } 
+    else
+#ifdef HAVE_NEMESI
+    if (!strncasecmp(bs_filenam, "rtsp://", 7)) {
+        filept = NULL;
+        mpgdec_info->filesize = 0;
+        mpgdec_info->network_stream = TRUE;
+        mpgdec_info->stream_type = STREAM_RTSP;
+        if (mpgdec_rtsp_open(bs_filenam)) mpgdec_info->eof = TRUE;
+#endif
+    } else {
         if ((filept = vfs_fopen(bs_filenam, "rb")) == NULL ||
             stream_init() == -1)
             mpgdec_info->eof = TRUE;
--- a/Plugins/Input/mpg123/mpg123.c	Sat Sep 09 18:04:36 2006 -0700
+++ b/Plugins/Input/mpg123/mpg123.c	Sat Sep 09 21:52:25 2006 -0700
@@ -342,7 +342,9 @@
 {
     gchar *ext = strrchr(filename, '.');
 
-    if (!strncasecmp(filename, "http://", 7) && (ext && strncasecmp(ext, ".ogg", 4)) && (ext && strncasecmp(ext, ".flac", 5)))
+    if (CHECK_STREAM(filename) &&
+        (ext && strncasecmp(ext, ".ogg", 4)) &&
+        (ext && strncasecmp(ext, ".flac", 5)))
 	return TRUE;
     else if (mpgdec_detect_by_content(filename))
         return TRUE;
@@ -617,7 +619,7 @@
     /*
      * TODO: Getting song info from http streams.
      */
-    if (!strncasecmp(filename, "http://", 7))
+    if (CHECK_STREAM(filename))
         return;
 
     if ((tuple = get_song_tuple(filename)) != NULL) {
@@ -705,7 +707,7 @@
         set_synth_functions(&fr);
 
         mpgdec_info->tpf = mpgdec_compute_tpf(&fr);
-        if (strncasecmp(filename, "http://", 7)) {
+        if (!CHECK_STREAM(filename)) {
             if (mpgdec_stream_check_for_xing_header(&fr, &xing_header)) {
                 mpgdec_info->num_frames = xing_header.frames;
                 have_xing_header = TRUE;
@@ -727,7 +729,7 @@
                 break;
         }
 
-        if (!have_xing_header && strncasecmp(filename, "http://", 7))
+        if (!have_xing_header && !CHECK_STREAM(filename))
             mpgdec_info->num_frames = mpgdec_calc_numframes(&fr);
 
         memcpy(&fr, &temp_fr, sizeof(struct frame));
@@ -829,7 +831,7 @@
                         /* FIXME networks streams */
                         disp_bitrate = mpgdec_bitrate;
                         if (!have_xing_header
-                            && strncasecmp(filename, "http://", 7)) {
+                            && !CHECK_STREAM(filename)) {
                             double rel = mpgdec_relative_pos();
                             if (rel) {
                                 mpgdec_length =
--- a/Plugins/Input/mpg123/mpg123.h	Sat Sep 09 18:04:36 2006 -0700
+++ b/Plugins/Input/mpg123/mpg123.h	Sat Sep 09 21:52:25 2006 -0700
@@ -62,6 +62,12 @@
     DETECT_BOTH
 };
 
+enum {
+    STREAM_FILE,
+    STREAM_HTTP,
+    STREAM_RTSP
+};
+
 #include <gtk/gtk.h>
 
 #include "audacious/plugin.h"
@@ -81,6 +87,18 @@
 
 #define		MAXFRAMESIZE		4096
 
+#ifdef HAVE_NEMESI
+int mpgdec_rtsp_open(char *url);
+int mpgdec_rtsp_read(gpointer data, gsize length);
+void mpgdec_rtsp_close (void);
+#define CHECK_STREAM(filename) \
+    (!strncasecmp(filename, "http://", 7) ||\
+     !strncasecmp(filename, "rtsp://", 7))
+#else
+#define CHECK_STREAM(filename) \
+    (!strncasecmp(filename, "http://", 7))
+#endif
+
 struct id3v1tag_t {
     char tag[3];                /* always "TAG": defines ID3v1 tag 128 bytes before EOF */
     char title[30];
@@ -116,6 +134,7 @@
     double tpf;
     float eq_mul[576];
     gboolean output_audio, first_frame, network_stream;
+    gint stream_type;
     guint32 filesize;           /* Filesize without junk */
 } PlayerInfo;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Input/mpg123/rtsp.c	Sat Sep 09 21:52:25 2006 -0700
@@ -0,0 +1,108 @@
+/*  Audacious - Cross-platform multimedia player
+ *  Copyright (C) 2006  Audacious development team.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software Foundation,
+ *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nemesi/rtp.h>
+#include <nemesi/rtsp.h>
+#include <libaudacious/util.h>
+
+#include "mpg123.h"
+
+extern gint mpgdec_bitrate, mpgdec_frequency, mpgdec_stereo;
+extern gboolean mpgdec_stereo;
+
+//FIXME that's ugly!
+static rtsp_ctrl *ctl;
+static rtsp_session *sess;
+static rtp_ssrc *ssrc;
+static size_t foff;
+static rtp_buff conf;
+static rtp_frame fr;
+static rtp_thread *rtp_th;
+
+int mpgdec_rtsp_open(char *url)
+{
+//    nms_verbosity_set(0);
+    nms_rtsp_hints rtsp_hints = { -1 };
+    foff = 0;
+
+    if ( (ctl = rtsp_init(&rtsp_hints))==NULL ) {
+        fprintf (stderr, "Cannot init rtsp.\n");
+        return 1;
+    }
+
+    if ( rtsp_open( ctl, url) )
+    {
+        fprintf (stderr, "rtsp_open failed.\n");
+        // die
+        return 1;
+    }
+
+    rtsp_wait(ctl);
+
+    sess = ctl->rtsp_queue;
+
+    if (!sess) {
+        fprintf (stderr, "No session available.\n");
+        return 1;
+    }
+//look for the first mp3 track
+    rtsp_play(ctl,0.0,0.0);
+    
+    rtp_th = rtsp_get_rtp_th(ctl);    
+    
+    rtp_fill_buffers(rtp_th);
+
+    for (ssrc = rtp_active_ssrc_queue(rtsp_get_rtp_queue(ctl));
+         ssrc; ssrc = rtp_next_active_ssrc(ssrc)) {
+        if (ssrc->rtp_sess->announced_fmts->pt == 14) {
+            return 0;
+        }
+    }
+    return 1;
+}
+
+int mpgdec_rtsp_read(gpointer data, gsize length)
+{
+    gint ret = 0, len;
+    gsize off = 0;
+    while (length && !ret && !rtp_fill_buffers(rtp_th)){
+        if (!foff)
+            ret = rtp_fill_buffer(ssrc, &fr, &conf);
+        len = min(length, fr.len - foff);
+        memcpy((char *)data + off, fr.data + foff, len);
+        length -= len;
+        off += len;
+        foff = (len+foff)%fr.len;
+    }
+    return off;
+}
+
+void mpgdec_rtsp_close (void)
+{
+    foff = 0;    
+    rtsp_close(ctl);
+
+}
+
--- a/audacious/credits.c	Sat Sep 09 18:04:36 2006 -0700
+++ b/audacious/credits.c	Sat Sep 09 21:52:25 2006 -0700
@@ -69,6 +69,7 @@
 
     N_("Plugin development:"),
     "Kiyoshi Aman",
+    "Luca Barbato",
     "Shay Green",
     "Giacomo Lozito",
     "William Pitcock",
--- a/configure.ac	Sat Sep 09 18:04:36 2006 -0700
+++ b/configure.ac	Sat Sep 09 21:52:25 2006 -0700
@@ -355,7 +355,14 @@
 )
 
 if test "$enable_mp3" = "yes"; then
-	INPUT_PLUGINS="$INPUT_PLUGINS mpg123"
+        INPUT_PLUGINS="$INPUT_PLUGINS mpg123"
+        PKG_CHECK_MODULES(LIBNMS,[libnms >= 0.6.0],
+            [LIBNMS_SRC=rtsp.c,
+             AC_DEFINE(HAVE_NEMESI,,[Define if rtp/rtsp support is available])
+            ],[LIBNMS_SRC=""])
+        AC_SUBST(LIBNMS_CFLAGS)
+        AC_SUBST(LIBNMS_LIBS)
+        AC_SUBST(LIBNMS_SRC)
 fi
 
 dnl *** ThinkLight support
--- a/mk/rules.mk.in	Sat Sep 09 18:04:36 2006 -0700
+++ b/mk/rules.mk.in	Sat Sep 09 21:52:25 2006 -0700
@@ -200,6 +200,9 @@
 LIBFLAC_LIBS ?= @LIBFLAC_LIBS@
 LIBGLADE_CFLAGS ?= @LIBGLADE_CFLAGS@
 LIBGLADE_LIBS ?= @LIBGLADE_LIBS@
+LIBNMS_CFLAGS ?= @LIBNMS_CFLAGS@
+LIBNMS_LIBS ?= @LIBNMS_LIBS@
+LIBNMS_SRC ?= @LIBNMS_SRC@
 LIBICONV ?= @LIBICONV@
 LIBINTL ?= @LIBINTL@
 LIBOBJS ?= @LIBOBJS@