diff src/http.c @ 146:066f33b2213a

EXPERIMENTAL: Select a particular program from multi-channel.
author Naoya OYAMA <naoya.oyama@gmail.com>
date Tue, 21 Aug 2012 04:21:11 +0900
parents 2a9ac5ce2c7e
children a9f60d56d673
line wrap: on
line diff
--- a/src/http.c	Thu Aug 16 21:57:34 2012 +0900
+++ b/src/http.c	Tue Aug 21 04:21:11 2012 +0900
@@ -97,7 +97,7 @@
 {
     extern struct ushare_t *ut;
     struct upnp_entry_t *entry = NULL;
-    int upnp_id = 0;
+    int i, upnp_id = 0;
     char *content_type = NULL;
     char *protocol = NULL;
 
@@ -109,19 +109,28 @@
     upnp_id = atoi (strrchr (filename, '/') + 1);
     entry = upnp_get_entry (ut, upnp_id);
 
-#if 0
-    if ( (!strcmp (filename, STREAM_LOCATION)) ||
-          ( (entry->fullpath != NULL) &&
-            ( !strcmp(entry->fullpath, STREAM_LOCATION))) ) {
-#endif
-    if (!strcmp (filename, STREAM_LOCATION)) {
-        log_verbose ("http_get_info, stream location found.\n");
-        info->is_readable = 1;
-        info->file_length = get_streaming_length();
-        info->last_modified = time(NULL);
-        info->is_directory = 0;
-        info->content_type = ixmlCloneDOMString ("video/mpeg");
-        return 0;
+    if (ut->nr_channel == 0) {
+       if (!strcmp (filename, STREAM_LOCATION)) {
+           log_verbose ("http_get_info, stream location found.\n");
+           info->is_readable = 1;
+           info->file_length = get_streaming_length();
+           info->last_modified = time(NULL);
+           info->is_directory = 0;
+           info->content_type = ixmlCloneDOMString ("video/mpeg");
+           return 0;
+       }
+    } else {
+       for (i=0; i < ut->nr_channel; i++) {
+           if (!strcmp(filename, ut->location_name[i])) {
+              log_verbose ("http_get_info, stream location found [%s].\n", filename);
+              info->is_readable = 1;
+              info->file_length = get_streaming_length();
+              info->last_modified = time(NULL);
+              info->is_directory = 0;
+              info->content_type = ixmlCloneDOMString ("video/mpeg");
+              return 0;
+           }
+       }
     }
     if (!strcmp (filename, CDS_LOCATION))
     {
@@ -330,9 +339,10 @@
     extern struct ushare_t *ut;
     struct upnp_entry_t *entry = NULL;
     struct web_file_t *file;
-    int fd, upnp_id = 0;
+    int i, fd, upnp_id = 0;
     extern thread_data *gp_tdata;
     thread_data *tdata = gp_tdata;
+    int channel_length = 0;
 
     if (!filename)
         return NULL;
@@ -367,8 +377,18 @@
      * get_file_stream()を呼び出しハンドラを返却する
      */
     log_verbose ("Fullpath : %s\n", entry->fullpath);
-    if (!strcmp (entry->fullpath, STREAM_LOCATION))
-        return get_file_stream (STREAM_LOCATION, tdata);
+    if (ut->nr_channel == 0) {
+        if (!strcmp (entry->fullpath, STREAM_LOCATION))
+            return get_file_stream (STREAM_LOCATION, tdata);
+    } else {
+        for (i=0; i < ut->nr_channel; i++)
+            if (!strcmp(entry->fullpath, ut->location_name[i])) {
+                channel_length = strspn(ut->channel_name[i], "0123456789");
+                strncpy(ut->request_channel, ut->channel_name[i], channel_length);
+                log_verbose ("http_open: request_channel[%s].\n", ut->request_channel);
+                return get_file_stream (ut->location_name[i], tdata);
+            }
+    }
 
     fd = open (entry->fullpath, O_RDONLY | O_NONBLOCK | O_SYNC | O_NDELAY);
     if (fd < 0)
@@ -528,6 +548,7 @@
     static int
 http_close (UpnpWebFileHandle fh)
 {
+    extern struct ushare_t *ut;
     struct web_file_t *file = (struct web_file_t *) fh;
     extern thread_data *gp_tdata;
     thread_data *tdata = gp_tdata;
@@ -569,6 +590,8 @@
                 pthread_mutex_unlock(&p_queue->mutex);
                 destroy_stream_queue(p_queue);
                 tdata->streamer->stream_session[id]->p_queue = NULL;
+                strcpy(ut->request_channel, "all");
+                ut->nr_channel = 0;
             }
             break;
         default: