Icecast Streaming Media Server Forum Index Icecast Streaming Media Server
Icecast is a Xiph Foundation Project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Icecast Server 2.3.2 and iPhone Streaming Feature and Patch

 
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
czenzel



Joined: 29 Nov 2008
Posts: 1

PostPosted: Sat Nov 29, 2008 8:56 pm    Post subject: Icecast Server 2.3.2 and iPhone Streaming Feature and Patch Reply with quote

Hello Everyone,

Mods: Please fell free to move this if its in the wrong section!

Today I added iPhone support to a local Icecast server by modifying an existing patch on the icecast-dev mailing lists. This patch I modified now includes the ability to check a user agent to make sure its an iPhone "Core Media" client.

I am looking for some testers to try it and let me know how it works.

I have tested it in my home network, streaming a weather radio, and it is working great!

Let me know how it works or if you need any help applying it. I hope to see this in Icecast Server as a feature one day!

Attached to the post is the source code for the patch files.

Thanks,
Christopher Zenzel

format.c - Patch
Code:

--- src/format.c   2008-04-19 23:24:30.000000000 -0400
+++ src/format.c   2008-11-29 15:50:59.000000000 -0500
@@ -280,12 +280,32 @@
     avl_node *node;
     ice_config_t *config;
 
+    /* Partial hack, check for range and user agent in this function */
+    const char *useragent;
+    useragent = httpp_getvar (client->parser, "user-agent");
+    int appledevicesupp = 0;
+   
+    if (useragent && strstr(useragent, "CoreMedia")) {
+        appledevicesupp = 1;
+    }
+
     remaining = client->refbuf->len;
     ptr = client->refbuf->data;
     client->respcode = 200;
 
-    bytes = snprintf (ptr, remaining, "HTTP/1.0 200 OK\r\n"
-            "Content-Type: %s\r\n", source->format->contenttype);
+    if (!appledevicesupp) {
+        bytes = snprintf (ptr, remaining, "HTTP/1.0 200 OK\r\n"
+                "Content-Type: %s\r\n", source->format->contenttype);
+    } else {
+        char *range = httpp_getvar(client->parser, "range");
+        if (range) {
+            bytes = snprintf(ptr, remaining, "HTTP/1.1 206 Partial Content\r\n"
+                 "Content-Type: %s\r\n", source->format->contenttype);
+        } else {
+            bytes = snprintf(ptr, remaining, "HTTP/1.0 200 OK\r\n",
+                 "Content-Type: %s\r\n", source->format->contenttype);
+        }
+    }
 
     remaining -= bytes;
     ptr += bytes;


format_mp3.c - Patch
Code:

--- src/format_mp3.c   2007-10-18 23:02:35.000000000 -0400
+++ src/format_mp3.c   2008-11-29 15:50:49.000000000 -0500
@@ -658,6 +658,53 @@
         ptr += bytes;
     }
 
+    /* hack for iPhone OS or Simulator with CoreMedia. checks user agent then adds iPhone-specific headers */
+    char *range;
+    range = httpp_getvar(client->parser, "range");
+    int appledevicesupp = 0;
+    if (useragent && strstr(useragent, "CoreMedia")) {
+        appledevicesupp = 1;
+    }
+    if (appledevicesupp)
+    {
+        int rangenumber;
+        int rangenumber2;
+        if (range != NULL) {
+             int ret = 0;
+             int rangeproblem = 0;
+             ret = sscanf(range, "bytes=%d-%d", &rangenumber, &rangenumber2);
+             if (ret != 2) {
+                  rangeproblem = 1;
+             }
+             if (rangenumber < 0) {
+                  rangeproblem = 1;
+             }
+             if (!rangeproblem) {
+                  char currenttime[50];
+                  time_t now;
+                  int strflen;
+                  struct tm result;
+                  time(&now);
+                  strflen = strftime(currenttime, 50, "%a, %d-%b-%Y %X GMT",
+                                     gmtime_r(&now, &result));
+                  client->respcode = 206;
+                  bytes = snprintf(ptr, remaining, "Date: %s\r\n", currenttime);
+                  if (bytes > 0)
+                  {
+                       remaining -= bytes;
+                       ptr += bytes;
+                  }
+                  bytes = snprintf(ptr, remaining, "Content-Range: bytes %d-%d/221183499\r\n",
+                                   rangenumber, rangenumber2);
+                  if (bytes > 0)
+                  {
+                       remaining -= bytes;
+                       ptr += bytes;
+                  }
+             }
+        }
+    }
+
     client->format_data = client_mp3;
     client->free_client_data = free_mp3_client_data;
     metadata = httpp_getvar(client->parser, "icy-metadata");
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
subRebel style by ktauber