changeset 430:ed94145472df trunk

[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept failure on seeking to the end of the file.
author iabervon
date Sun, 14 Jan 2007 23:53:59 -0800
parents 74b23aec578d
children f757e1aa62e6
files ChangeLog src/curl/curl.c src/mpg123/common.c
diffstat 3 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Jan 14 22:39:39 2007 -0800
+++ b/ChangeLog	Sun Jan 14 23:53:59 2007 -0800
@@ -1,3 +1,12 @@
+2007-01-15 06:39:39 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
+  revision [942]
+  - buildsystem glue for curl http:// transport
+  
+  trunk/configure.ac      |    2 +-
+  trunk/src/curl/Makefile |   18 ++++++++++++++++++
+  2 files changed, 19 insertions(+), 1 deletion(-)
+
+
 2007-01-15 06:34:57 +0000  Daniel Barkalow <barkalow@iabervon.org>
   revision [940]
   Add code for a plugin to use CURL for http. Needs some build-system
--- a/src/curl/curl.c	Sun Jan 14 22:39:39 2007 -0800
+++ b/src/curl/curl.c	Sun Jan 14 23:53:59 2007 -0800
@@ -30,7 +30,7 @@
 struct _CurlHandle {
   CURL *curl;
 
-  gsize length; // the length of the file
+  gssize length; // the length of the file
   gsize rd_abs; // the absolute position for reading from the stream
   gsize wr_abs; // the absolute position where the input connection is
 
@@ -46,7 +46,7 @@
 };
 
 /* TODO:
- *  - Icecast
+ *  - Fix hang if the server closes the connection in the middle
  *  - Clever buffer stuff when you read a bit of the beginning and a bit of the
  *    end of a file
  */
@@ -97,9 +97,13 @@
       if (retcode == CURLE_OK)
 	{
 	  handle->length = value;
+	  if (handle->length == 0)
+	    handle->length = -2;
+	  //g_print("Length: %d\n", handle->length);
 	}
       else
 	{
+	  handle->length = -2;
 	  g_print("getinfo gave error\n");
 	}
     }
@@ -140,6 +144,7 @@
 curl_manage_request(gpointer arg)
 {
   CurlHandle *handle = arg;
+  CURLcode result;
   //g_print("Connect %p\n", handle);
 
   if (handle->no_data)
@@ -153,8 +158,13 @@
       curl_easy_setopt(handle->curl, CURLOPT_HTTPGET, 1);
     }
 
-  curl_easy_perform(handle->curl);
-  update_length(handle);
+  result = curl_easy_perform(handle->curl);
+  if (result == CURLE_OK)
+    update_length(handle);
+  if (result != CURLE_OK && result != CURLE_WRITE_ERROR)
+    {
+      g_print("Got curl error %d\n", result);
+    }
   //g_print("Done %p%s", handle, handle->cancel ? " (aborted)\n" : "\n");
   handle->cancel = 1;
   return NULL;
@@ -271,9 +281,7 @@
   while (ret < sz)
     {
       size_t available;
-      while (!(available = buf_available(handle)) && 
-	     (handle->length == -1 || handle->rd_abs < handle->length) &&
-	     !handle->cancel)
+      while (!(available = buf_available(handle)) && !handle->cancel)
 	g_usleep(10000);
       if (available > sz - ret)
 	available = sz - ret;
@@ -345,7 +353,7 @@
 	}
     }
 
-  if (whence == SEEK_END && handle->length == -1)
+  if (whence == SEEK_END && handle->length < 0)
     {
       //g_print("Tried to seek to the end of a file with unknown length\n");
       // don't know how long it is...
--- a/src/mpg123/common.c	Sun Jan 14 22:39:39 2007 -0800
+++ b/src/mpg123/common.c	Sun Jan 14 23:53:59 2007 -0800
@@ -222,8 +222,10 @@
 
     if (filept == NULL)
         return -1;
-    if (vfs_fseek(filept, 0, SEEK_END) < 0)
-        return -1;
+    if (vfs_fseek(filept, 0, SEEK_END) < 0) {
+        mpgdec_info->filesize = 0;
+        return 0;
+    }
 
     mpgdec_info->filesize = vfs_ftell(filept);
     if (vfs_fseek(filept, -128, SEEK_END) < 0)