]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
service_mapper: fix lots of problems in the service mapper
authorAdam Sutton <dev@adamsutton.me.uk>
Fri, 11 Oct 2013 14:51:01 +0000 (15:51 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Fri, 11 Oct 2013 14:51:01 +0000 (15:51 +0100)
src/service.c
src/service_mapper.c
src/subscriptions.c

index e2ceb4b6f19122f03573735a8f99f83c32380251..d513ceb06e55e6c96478df00737e18df9d8a2034 100644 (file)
@@ -322,6 +322,8 @@ service_start(service_t *t, int instance)
 
   lock_assert(&global_lock);
 
+  tvhtrace("service", "starting %s", t->s_nicename);
+
   assert(t->s_status != SERVICE_RUNNING);
   t->s_streaming_status = 0;
 
@@ -389,14 +391,16 @@ service_find_instance
   TAILQ_FOREACH(si, sil, si_link) {
     const char *name = ch ? channel_get_name(ch) : NULL;
     if (!name && s) name = s->s_nicename;
-    tvhdebug("service", "%s si %p weight %d prio %d error %d\n",
+    tvhdebug("service", "%s si %p weight %d prio %d error %d",
              name, si, si->si_weight, si->si_prio, si->si_error);
   }
 
   /* Already running? */
   TAILQ_FOREACH(si, sil, si_link)
-    if(si->si_s->s_status == SERVICE_RUNNING && si->si_error == 0)
+    if(si->si_s->s_status == SERVICE_RUNNING && si->si_error == 0) {
+      tvhtrace("service", "return already running %p", si);
       return si;
+    }
 
   /* Forced or Idle */
   TAILQ_FOREACH(si, sil, si_link)
@@ -417,7 +421,12 @@ service_find_instance
   }
 
   /* Start */
-  service_start(si->si_s, si->si_instance);
+  tvhtrace("service", "will start new instance %d", si->si_instance);
+  if (service_start(si->si_s, si->si_instance)) {
+    tvhtrace("service", "tuning failed");
+    *error = SM_CODE_TUNING_FAILED;
+    si = NULL;
+  }
   return si;
 }
 
@@ -769,7 +778,7 @@ service_set_streaming_status_flags(service_t *t, int set)
   int n;
   streaming_message_t *sm;
   lock_assert(&t->s_stream_mutex);
-  
+
   n = t->s_streaming_status;
   
   n |= set;
index 089e95887aecaf50a17e2757c031975e7efd76ce..ed5a902704cc3bcc3da61c8f8897b4f19da68797 100644 (file)
@@ -199,8 +199,8 @@ service_mapper_unlink ( service_t *s, channel_t *c )
 void
 service_mapper_process ( service_t *s )
 {
-  int num;
   channel_t *chn = NULL;
+  const char *name;
 
   /* Ignore */
   if (s->s_status == SERVICE_ZOMBIE)
@@ -211,11 +211,11 @@ service_mapper_process ( service_t *s )
     goto exit;
 
   /* Find existing channel */
-  num = s->s_channel_number(s);
-  if (service_mapper_conf.merge_same_name && s->s_channel_name)
-    chn = channel_find_by_name(s->s_channel_name(s) ?: "");
+  name = service_get_channel_name(s);
+  if (service_mapper_conf.merge_same_name && name && *name)
+    chn = channel_find_by_name(name);
   if (!chn)
-    chn = channel_create(NULL, NULL, s->s_channel_name(s));
+    chn = channel_create(NULL, NULL, NULL);
     
   /* Map */
   if (chn) {
@@ -229,14 +229,10 @@ service_mapper_process ( service_t *s )
     } else if (service_is_sdtv(s)) {
       channel_tag_map(chn, channel_tag_find_by_name("TV channels", 1));
       channel_tag_map(chn, channel_tag_find_by_name("SDTV", 1));
-    } else {
+    } else if (service_is_radio(s)) {
       channel_tag_map(chn, channel_tag_find_by_name("Radio", 1));
     }
 
-    /* Set number */
-    if (!chn->ch_number && num)
-      chn->ch_number = num;
-
     /* Provider */
     if (service_mapper_conf.provider_tags)
       if ((prov = s->s_provider_name(s)))
@@ -263,7 +259,6 @@ service_mapper_thread ( void *aux )
   streaming_queue_t sq;
   streaming_message_t *sm;
   const char *err;
-  streaming_target_t *st;
 
   streaming_queue_init(&sq, 0);
 
@@ -288,8 +283,7 @@ service_mapper_thread ( void *aux )
 
     /* Subscribe */
     tvhinfo("service_mapper", "%s: checking availability", s->s_nicename);
-    st  = tsfix_create(&sq.sq_st);
-    sub = subscription_create_from_service(s, 2, "service_mapper", st,
+    sub = subscription_create_from_service(s, 3, "service_mapper", &sq.sq_st,
                                            0, NULL, NULL, "service_mapper");
 
     /* Failed */
@@ -322,6 +316,9 @@ service_mapper_thread ( void *aux )
           run = 0;
           err = service_tss2text(status);
         }
+      } else if (sm->sm_type == SMT_NOSTART) {
+        run = 0;
+        err = "could not start";
       }
 
       streaming_msg_free(sm);
@@ -333,10 +330,9 @@ service_mapper_thread ( void *aux )
  
     pthread_mutex_lock(&global_lock);
     subscription_unsubscribe(sub);
-    tsfix_destroy(st);
 
     if(err)
-      tvhinfo("service_mapper", "%s: failed %s", s->s_nicename, err);
+      tvhinfo("service_mapper", "%s: failed [err %s]", s->s_nicename, err);
     else
       service_mapper_process(s);
 
index 34ac6f54d725c927a03ae5d241374430ce597ec6..4a06ce6df3ec1b0bc7da0160f235826c8db1038d 100644 (file)
@@ -233,6 +233,9 @@ subscription_reschedule(void)
 
       if (!s->ths_channel)
         s->ths_service = si->si_s;
+
+      s->ths_service->s_streaming_status = 0;
+      s->ths_service->s_status = SERVICE_IDLE;
     }
 
     if (s->ths_channel)