changeset 220:1e2d575fd2e7 trunk

[svn] - allow seeking in http streams that define a content length.
author nenolod
date Sun, 05 Nov 2006 02:21:22 -0800
parents 469078516127
children 8932ad49b51f
files ChangeLog src/mpg123/common.c src/mpg123/http.c src/mpg123/mpg123.c src/mpg123/mpg123.h
diffstat 5 files changed, 60 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Nov 05 01:07:34 2006 -0800
+++ b/ChangeLog	Sun Nov 05 02:21:22 2006 -0800
@@ -1,3 +1,11 @@
+2006-11-05 09:07:34 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
+  revision [438]
+  - fix a typo which preventes compile
+  
+  trunk/src/esd/audio.c |    1 -
+  1 file changed, 1 deletion(-)
+
+
 2006-11-05 08:34:45 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
   revision [436]
   - fix for stream save if filename duplicates exist
--- a/src/mpg123/common.c	Sun Nov 05 01:07:34 2006 -0800
+++ b/src/mpg123/common.c	Sun Nov 05 02:21:22 2006 -0800
@@ -167,21 +167,37 @@
 int
 mpgdec_stream_jump_to_frame(struct frame *fr, int frame)
 {
-    if (!filept)
-        return -1;
-    mpgdec_read_frame_init();
-    vfs_fseek(filept, frame * (fr->framesize + 4), SEEK_SET);
-    mpgdec_read_frame(fr);
+    if (filept == NULL)
+    {
+        unsigned long r;
+
+        r = frame * (fr->framesize + 4);
+        mpgdec_stream_close();
+        mpgdec_open_stream(mpgdec_filename, -1, r);
+    }
+    else
+    {
+        mpgdec_read_frame_init();
+        vfs_fseek(filept, frame * (fr->framesize + 4), SEEK_SET);
+        mpgdec_read_frame(fr);
+    }
     return 0;
 }
 
 int
 mpgdec_stream_jump_to_byte(struct frame *fr, int byte)
 {
-    if (!filept)
-        return -1;
-    vfs_fseek(filept, byte, SEEK_SET);
-    mpgdec_read_frame(fr);
+    if (filept == NULL)
+    {
+        mpgdec_stream_close();
+        mpgdec_open_stream(mpgdec_filename, -1, (unsigned long)byte);
+    }
+    else
+    {
+        vfs_fseek(filept, byte, SEEK_SET);
+        mpgdec_read_frame(fr);
+    }
+
     return 0;
 }
 
@@ -382,12 +398,12 @@
 }
 
 void
-mpgdec_open_stream(char *bs_filenam, int fd)
+mpgdec_open_stream(char *bs_filenam, int fd, unsigned long range)
 {
     filept_opened = 1;
     if (!strncasecmp(bs_filenam, "http://", 7)) {
         filept = NULL;
-        mpgdec_http_open(bs_filenam);
+        mpgdec_http_open(bs_filenam, range);
         mpgdec_info->filesize = 0;
         mpgdec_info->network_stream = TRUE;
         mpgdec_info->stream_type = STREAM_HTTP;
--- a/src/mpg123/http.c	Sun Nov 05 01:07:34 2006 -0800
+++ b/src/mpg123/http.c	Sun Nov 05 02:21:22 2006 -0800
@@ -64,6 +64,7 @@
 static gchar *buffer;
 static GThread *thread;
 static GtkWidget *error_dialog = NULL;
+static unsigned long range;
 
 static VFSFile *output_file = NULL;
 
@@ -339,7 +340,7 @@
 http_buffer_loop(gpointer arg)
 {
     gchar line[1024], *user, *pass, *host, *filename,
-        *status, *url, *temp, *file;
+        *status, *url, *temp, *temp2, *file;
     gchar *chost;
     gint cnt, written, error, port, cport;
     guint err_len;
@@ -510,16 +511,22 @@
                 }
                 else
                     file = g_strconcat("/", filename, NULL);
-                temp = g_strdup_printf("GET %s HTTP/1.0\r\n"
+                if (range)
+                {
+                    temp2 = g_strdup_printf("Range: bytes=%lu-\r\n", range);
+                } else
+                    temp2 = NULL;
+                temp = g_strdup_printf("GET %s HTTP/1.1\r\n"
                                        "Host: %s\r\n"
                                        "User-Agent: %s/%s\r\n"
-                                       "%s%s%s%s\r\n",
+                                       "%s%s%s%s%s\r\n",
                                        file, host, PACKAGE_NAME, PACKAGE_VERSION,
                                        proxy_auth ? proxy_auth : "",
                                        auth ? auth : "",
                                        "Icy-MetaData:1\r\n",
                                        mpgdec_cfg.
-                                       use_udp_channel ? udpspace : "");
+                                       use_udp_channel ? udpspace : "",
+				       temp2 != NULL ? temp2 : "");
 
                 g_free(file);
                 if (proxy_auth)
@@ -598,8 +605,12 @@
                                         atoi(line + 20));
 #endif
 /*  								udp_serverport = atoi (line + 20); */
+
                             }
 
+                            if (!strncasecmp(line, "content-length:", 15)) {
+                                mpgdec_info->filesize = atoi(line + 15);
+                            }
                         }
                         else {
                             eof = TRUE;
@@ -725,7 +736,7 @@
 }
 
 int
-mpgdec_http_open(gchar * _url)
+mpgdec_http_open(gchar * _url, unsigned long rng)
 {
     gchar *url;
 
@@ -742,6 +753,7 @@
     going = TRUE;
     eof = FALSE;
     buffer = g_malloc(buffer_length);
+    range = rng;
 
     thread = g_thread_create(http_buffer_loop, url, TRUE, NULL);
 
--- a/src/mpg123/mpg123.c	Sun Nov 05 01:07:34 2006 -0800
+++ b/src/mpg123/mpg123.c	Sun Nov 05 02:21:22 2006 -0800
@@ -698,7 +698,7 @@
 
     mpgdec_read_frame_init();
 
-    mpgdec_open_stream(filename, -1);
+    mpgdec_open_stream(filename, -1, 0);
 
     if (mpgdec_info->eof || !mpgdec_read_frame(&fr))
         mpgdec_info->eof = TRUE;
@@ -762,9 +762,10 @@
 	    mpgdec_frequency = (gint) m;
 	}
 
-        if (strncasecmp(filename, "http://", 7)) {
+        mpgdec_length = mpgdec_info->num_frames * mpgdec_info->tpf * 1000;
+
+        if (mpgdec_info->filesize == 0) {
 	    TitleInput *tuple = NULL;
-            mpgdec_length = mpgdec_info->num_frames * mpgdec_info->tpf * 1000;
             if (!mpgdec_title)
 	    {
 	        tuple = get_song_tuple(filename);
@@ -775,7 +776,6 @@
         else {
             if (!mpgdec_title)
                 mpgdec_title = mpgdec_http_get_title(filename);
-            mpgdec_length = -1;
         }
 
         set_synth_functions(&fr);
--- a/src/mpg123/mpg123.h	Sun Nov 05 01:07:34 2006 -0800
+++ b/src/mpg123/mpg123.h	Sun Nov 05 02:21:22 2006 -0800
@@ -91,14 +91,11 @@
 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
 
+#define CHECK_STREAM(var_is_deprecated) (mpgdec_info->filesize == 0)
+
 struct id3v1tag_t {
     char tag[3];                /* always "TAG": defines ID3v1 tag 128 bytes before EOF */
     char title[30];
@@ -239,7 +236,7 @@
 
 /* ------ Declarations from "http.c" ------ */
 
-extern int mpgdec_http_open(char *url);
+extern int mpgdec_http_open(char *url, unsigned long rng);
 int mpgdec_http_read(gpointer data, gsize length);
 void mpgdec_http_close(void);
 char *mpgdec_http_get_title(char *url);
@@ -251,7 +248,7 @@
 extern unsigned int mpgdec_getbits(int);
 extern unsigned int mpgdec_getbits_fast(int);
 
-extern void mpgdec_open_stream(char *bs_filenam, int fd);
+extern void mpgdec_open_stream(char *bs_filenam, int fd, unsigned long range);
 extern int mpgdec_head_check(unsigned long);
 extern void mpgdec_stream_close(void);