changeset 152:30e91361506a

EXPERIMENTAL: Enable change phisical channel by DLNA.(ISDB-T only)
author Naoya OYAMA <naoya.oyama@gmail.com>
date Sun, 02 Sep 2012 01:59:27 +0900
parents f7f594bf4e98
children e040d91c5cc7
files src/http.c src/metadata.c src/recpt1.c src/recpt1.h src/tssplitter_lite.c src/ushare.c src/ushare.h
diffstat 7 files changed, 176 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/src/http.c	Fri Aug 31 23:39:46 2012 +0900
+++ b/src/http.c	Sun Sep 02 01:59:27 2012 +0900
@@ -343,6 +343,9 @@
     extern thread_data *gp_tdata;
     thread_data *tdata = gp_tdata;
     int channel_length = 0;
+    char tmp[1024];
+    char *p;
+    tmp[0] = '\0';
 
     if (!filename)
         return NULL;
@@ -376,18 +379,12 @@
      * 1. http_open() $B$G$O(B entry $B$,%9%H%j!<%`:F@8MQ$N$b$N$G$"$k>l9g$K!"(B
      * get_file_stream()$B$r8F$S=P$7%O%s%I%i$rJV5Q$9$k(B
      */
-    log_verbose ("Fullpath : %s\n", entry->fullpath);
-    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);
-            }
+    for (i=0; i < ut->channel_list->nr_channel; i++) {
+        if (!strcmp(entry->fullpath, ut->channel_list->channel_info[i]->sid)) {
+            ut->sid = ut->channel_list->channel_info[i]->sid;
+            ut->tp  = ut->channel_list->channel_info[i]->tp;
+            return get_file_stream (ut->sid, tdata);
+        }
     }
 
     fd = open (entry->fullpath, O_RDONLY | O_NONBLOCK | O_SYNC | O_NDELAY);
--- a/src/metadata.c	Fri Aug 31 23:39:46 2012 +0900
+++ b/src/metadata.c	Sun Sep 02 01:59:27 2012 +0900
@@ -38,6 +38,7 @@
 #include "content.h"
 #include "gettext.h"
 #include "trace.h"
+#include "recpt1.h"
 
 #define TITLE_UNKNOWN "unknown"
 
@@ -556,56 +557,20 @@
   if (!ut->root_entry)
     ut->root_entry = upnp_entry_new (ut, "root", NULL, NULL, -1, true);
 
-#if 0
-  entry = upnp_entry_new (ut, "stream.ts", "/web/stream.ts",
-                          ut->root_entry, -1, false);
-    upnp_entry_add_child (ut, ut->root_entry, entry);
-    metadata_add_container (ut, entry, "/web/");
-#endif
   struct upnp_entry_t *entry = ut->root_entry;
   st.st_size = 100*1024*1024;
-  if (ut->nr_channel == 0) {
-    metadata_add_file (ut, ut->root_entry, STREAM_LOCATION, STREAM_FILE_NAME, &st);
-  } else {
-    for (i=0; i < ut->nr_channel; i++)
-      metadata_add_file (ut, ut->root_entry, ut->location_name[i], ut->channel_name[i], &st);
+  for(i=0; i < ut->channel_list->nr_channel; i++) {
+      char name[1024];
+      name[0] = '\0';
+      strncpy(name, ut->channel_list->channel_info[i]->name, sizeof(name));
+      strncat(name, ".ts", sizeof(name));
+      metadata_add_file (ut,
+                         ut->root_entry,
+                         ut->channel_list->channel_info[i]->sid,
+                         name,
+                         &st);
   }
   ut->contentlist = NULL;
-  //metadata_add_container (ut, ut->root_entry, "/web/");
-
-#if 0
-  /* add files from content directory */
-  for (i=0 ; i < ut->contentlist->count ; i++)
-  {
-    struct upnp_entry_t *entry = NULL;
-    char *title = NULL;
-    int size = 0;
-
-    log_info (_("Looking for files in content directory : %s\n"),
-              ut->contentlist->content[i]);
-
-    size = strlen (ut->contentlist->content[i]);
-    if (ut->contentlist->content[i][size - 1] == '/')
-      ut->contentlist->content[i][size - 1] = '\0';
-    title = strrchr (ut->contentlist->content[i], '/');
-    if (title)
-      title++;
-    else
-    {
-      /* directly use content directory name if no '/' before basename */
-      title = ut->contentlist->content[i];
-    }
-
-    entry = upnp_entry_new (ut, title, ut->contentlist->content[i],
-                            ut->root_entry, -1, true);
-
-    if (!entry)
-      continue;
-    upnp_entry_add_child (ut, ut->root_entry, entry);
-    metadata_add_container (ut, entry, ut->contentlist->content[i]);
-  }
-#endif
-
   log_info (_("Found %d files and subdirectories.\n"), ut->nr_entries);
   ut->init = 1;
 }
--- a/src/recpt1.c	Fri Aug 31 23:39:46 2012 +0900
+++ b/src/recpt1.c	Sun Sep 02 01:59:27 2012 +0900
@@ -50,6 +50,7 @@
 
 /* globals */
 boolean f_exit = FALSE;
+struct channel_info_list *channel_list = NULL;
 extern struct ushare_t *ut;
 
 /* prototypes */
@@ -57,6 +58,96 @@
 int close_tuner(thread_data *tdata);
 static int get_device_id_by_name ( const char *name );
 
+static struct channel_info_list *open_list_file(char *type)
+{
+    char   *buf                                 = NULL;
+    char   filename[PATH_MAX];
+    char   *home                                = NULL;
+    char   *p                                   = NULL;
+    struct channel_info      *channel_info      = NULL;
+    struct channel_info_list *channel_info_list = NULL;
+    FILE   *f                                   = NULL;
+
+    home = getenv("HOME");
+    snprintf(filename, PATH_MAX, "%s/.recpt1_%s", home, type);
+    f = fopen(filename, "r");
+    if(!f) {
+        return channel_info_list;
+   	}
+    channel_info_list = malloc(sizeof(*channel_info_list));
+    if(!channel_info_list)
+        return NULL;
+    channel_info_list->nr_channel = 0;
+    while(1) {
+        buf = NULL;
+        buf = malloc(256);
+        if(!buf)
+            break;
+        if(!fgets(buf, 255, f)) {
+            free(buf);
+            buf = NULL;
+            break;
+        }
+        channel_info = NULL;
+        channel_info = malloc(sizeof(*channel_info));
+        if(!channel_info)
+            break;
+
+        channel_info->sid  = NULL;
+        channel_info->tp   = NULL;
+        channel_info->name = NULL;
+
+        channel_info->sid = buf;
+
+        p = strchr(buf, C_CHAR_COMMA);
+        if (p == NULL) {
+            /* FILE ERROR */
+            free(channel_info);
+			channel_info = NULL;
+           	continue;
+        }
+        *p = '\0';
+        channel_info->tp = ++p;
+
+        p = strchr(p, C_CHAR_COMMA);
+        if (p == NULL) {
+            /* FILE ERROR */
+            free(channel_info);
+            channel_info = NULL;
+            continue;
+        }
+        *p = '\0';
+        channel_info->name = ++p;
+        p = strchr(p, '\n');
+        if (p)
+            *p = '\0';
+
+        if(channel_info_list->nr_channel < CHANNEL_MAX) {
+            channel_info_list->channel_info[channel_info_list->nr_channel] = channel_info;
+            channel_info_list->nr_channel += 1;
+        }
+    }
+    fclose(f);
+    return channel_info_list;
+}
+
+static void close_list_file(struct channel_info_list *channel_info_list)
+{
+    int i;
+    if (!channel_info_list)
+        return;
+    for (i=0; i < channel_info_list->nr_channel; i++) {
+        free(channel_info_list->channel_info[i]->sid);
+        channel_info_list->channel_info[i]->sid = NULL;
+        free(channel_info_list->channel_info[i]);
+        channel_info_list->channel_info[i] = NULL;
+    }
+    channel_info_list->nr_channel = 0;
+    free(channel_info_list);
+    channel_info_list = NULL;
+    return;
+}
+
 /* ipc message receive */
 void *
 mq_recv(void *t)
@@ -416,7 +507,9 @@
     int code;
     int split_select_finish = TSS_ERROR;
     int old_sid = 0, new_sid = 0;
+    int old_tp = 0, new_tp = 0;
     time_t split_start_time;
+    struct channel_info *channel_info = NULL;
 
     time(&split_start_time);
 
@@ -521,16 +614,50 @@
          *        2.2.3.1 enqueue() $B$O(B tdata->stream_queue->mutex $B$r(B lock/unlock $B$7$F=q$-9~$_;~$NF1;~99?7$rKI;_$7$F$$$k(B
          */
         /*
-         * DLNA $B$G$N(BSID$BJQ99$N<BAu<B83(B
+         * DLNA $B$G$NJ*M}%A%c%s%M%k!&(BSID$BJQ99$N<BAu<B83(B
          */
         if ( use_dlna && buf.size > 0 &&
              strcmp("all", ut->request_channel)) {
             if ( use_splitter ) {
-                new_sid = atoi(ut->request_channel);
+                if (ut->tp)
+                    new_tp  = atoi(ut->tp);
+                if (ut->sid)
+                    new_sid = atoi(ut->sid);
+                if (old_tp != new_tp) {
+                    old_tp = new_tp;
+                    // msgsnd() $B$r<+J,<+?H$KAw$l$k$N$J$i$=$NJ}$,NI$5$=$&$J5$$,$9$k(B
+                    ioctl(data->tfd, STOP_REC, 0);
+                    if(close_tuner(data) != 0)
+                        break;
+                    pthread_mutex_lock(&data->queue->mutex);
+                    while(data->queue->num_used > 0) {
+                        while(1) {
+                             QUEUE_T *p_queue = data->queue;
+                             if (p_queue->num_used == 0)
+                                 break;
+                             free(p_queue->buffer[p_queue->out]);
+                             p_queue->buffer[p_queue->out] = NULL;
+                             p_queue->out++;
+                             p_queue->out %= p_queue->size;
+
+                             /* update counters */
+                             p_queue->num_avail++;
+                             p_queue->num_used--;
+                        }
+                    }
+                    pthread_mutex_unlock(&data->queue->mutex);
+                    tune(ut->tp, data, NULL);
+                    if(ioctl(data->tfd, START_REC, 0) < 0) {
+                        // $B$3$3$N07$$$I$3$m$,LB$&$H$3$m!#(Bexit $B$7$F$b$$$$5$$,$9$k(B
+                        fprintf(stderr, "Tuner cannot start recording\n");
+                        break;
+                    }
+                    time(&split_start_time);
+                }
                 if ( old_sid != new_sid ) {
                     old_sid = new_sid;
                     split_shutdown(splitter);
-                    splitter = split_startup(ut->request_channel, NULL, NULL);
+                    splitter = split_startup(ut->sid, NULL, NULL);
                     if ( splitter == NULL ) {
                         fprintf (stderr, "reader_func() splitter RESTART FAILED.\n", old_sid, new_sid);
                         use_splitter = FALSE;
@@ -556,7 +683,6 @@
                          p_queue->num_used--;
                     }
                     pthread_mutex_unlock(&data->stream_queue->mutex);
-                    fprintf (stderr, "reader_func() free stream queue finish.\n");
                     time(&split_start_time);
                     continue;
                 }
@@ -1392,6 +1518,8 @@
     /* initialize DLNA */
     if(use_dlna) {
         do {
+            if(use_splitter)
+                channel_list = open_list_file("ISDB");
             tdata.stream_queue = stream_queue;
             tdata.streamer = malloc(sizeof(streamer));
             if ( tdata.streamer == NULL ) {
@@ -1531,6 +1659,8 @@
     pthread_join(ipc_thread, NULL);
     if ( use_dlna ) {
         pthread_join(dlna_thread, NULL);
+        if ( channel_list )
+            close_list_file(channel_list);
     }
 
     /* close tuner */
--- a/src/recpt1.h	Fri Aug 31 23:39:46 2012 +0900
+++ b/src/recpt1.h	Sun Sep 02 01:59:27 2012 +0900
@@ -19,6 +19,7 @@
 #define TRUE                1
 #define FALSE               0
 #define STREAM_MAX (16)
+#define CHANNEL_MAX (256)
 
 
 /* type definitions */
@@ -100,6 +101,17 @@
     streamer *streamer;
 } thread_data;
 
+struct channel_info {
+    char *sid;
+    char *tp;
+    char *name;
+};
+
+struct channel_info_list {
+    int                  nr_channel;
+    struct channel_info *channel_info[CHANNEL_MAX];
+};
+
 QUEUE_T *create_queue(size_t size);
 BUFSZ *dequeue(QUEUE_T *p_queue);
 ARIB_STD_B25_BUFFER *stream_dequeue(STREAM_QUEUE_T *p_queue);
--- a/src/tssplitter_lite.c	Fri Aug 31 23:39:46 2012 +0900
+++ b/src/tssplitter_lite.c	Sun Sep 02 01:59:27 2012 +0900
@@ -736,34 +736,8 @@
 
 		/* print SIDs */
 		fprintf(stderr, "Available sid = ");
-		for(k=0; k < sp->num_pmts; k++) {
+		for(k=0; k < sp->num_pmts; k++)
 			fprintf(stderr, "%d ", avail_sids[k]);
-			/* ut->channel_name にSID番号を入れる
-			 * ushare 側(TV表示上)には channel_name を表示させる
-			 * TODO 局名も含めて入れたいなぁ
-			 */
-			if(!strcmp("all", sp->sid_list[0])) {
-#define CHANNEL_NAME_LENGTH (64)
-				ut->channel_name[ut->nr_channel] = malloc(CHANNEL_NAME_LENGTH);
-				if(!ut->channel_name[ut->nr_channel])
-					return TSS_NULL;
-				snprintf(ut->channel_name[ut->nr_channel],
-						CHANNEL_NAME_LENGTH,
-						"%d.ts",
-						avail_sids[k]);
-				ut->location_name[ut->nr_channel] = malloc(CHANNEL_NAME_LENGTH);
-				if(!ut->location_name[ut->nr_channel])
-					return TSS_NULL;
-				snprintf(ut->location_name[ut->nr_channel],
-						CHANNEL_NAME_LENGTH,
-						VIRTUAL_DIR "/%d.ts",
-						avail_sids[k]);
-				ut->nr_channel += 1;
-			}
-		}
-		// metadata list を作り直す
-		free_metadata_list(ut);
-		build_metadata_list(ut);
 		fprintf(stderr, "\n");
 		fprintf(stderr, "Chosen sid    =%s\n", chosen_sid);
 
--- a/src/ushare.c	Fri Aug 31 23:39:46 2012 +0900
+++ b/src/ushare.c	Sun Sep 02 01:59:27 2012 +0900
@@ -83,6 +83,7 @@
 ushare_new (void)
 {
   extern thread_data *gp_tdata;
+  extern struct channel_info_list *channel_list;
   thread_data *tdata = gp_tdata;
   struct ushare_t *ut = (struct ushare_t *) malloc (sizeof (struct ushare_t));
   char model_name[32];
@@ -137,6 +138,9 @@
     return NULL;
   ut->request_channel[0] = '\0';
   ut->nr_channel         = 0;
+  ut->channel_list = channel_list;
+  ut->sid = NULL;
+  ut->tp  = NULL;
 
   return ut;
 }
@@ -905,6 +909,8 @@
     return NULL;
   }
 
+  build_metadata_list(ut);
+
   /* Let main sleep until it's time to die... */
   pthread_mutex_lock (&ut->termination_mutex);
   pthread_cond_wait (&ut->termination_cond, &ut->termination_mutex);
--- a/src/ushare.h	Fri Aug 31 23:39:46 2012 +0900
+++ b/src/ushare.h	Sun Sep 02 01:59:27 2012 +0900
@@ -127,6 +127,9 @@
   char **location_name;
   char request_channel[64];
   int  nr_channel;
+  struct channel_info_list *channel_list;
+  char *sid;
+  char *tp;
 };
 
 struct action_event_t {