service_mapper: fix lots of problems in the service mapper

This commit is contained in:
Adam Sutton 2013-10-11 15:51:01 +01:00
parent 8901334cc0
commit 822b70928e
3 changed files with 27 additions and 19 deletions

View 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;

View 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);

View 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)