pthread_join(de->de_thread, NULL);
- subscription_unsubscribe(de->de_s, 0);
+ subscription_unsubscribe(de->de_s, UNSUBSCRIBE_FINAL);
de->de_s = NULL;
de->de_chain = NULL;
LIST_REMOVE(hs, hs_link);
LIST_INSERT_HEAD(&htsp->htsp_dead_subscriptions, hs, hs_link);
- subscription_unsubscribe(hs->hs_s, 0);
+ subscription_unsubscribe(hs->hs_s, UNSUBSCRIBE_FINAL);
if(hs->hs_prch.prch_st != NULL)
profile_chain_close(&hs->hs_prch);
ths_next = LIST_NEXT(ths, ths_global_link);
if (ths->ths_source == (tvh_input_t *)mi && !strcmp(ths->ths_title, "keep") &&
ths->ths_service != t)
- subscription_unsubscribe(ths, 0);
+ subscription_unsubscribe(ths, UNSUBSCRIBE_FINAL);
}
}
}
n = LIST_NEXT(s, ths_mux_link);
t = s->ths_service;
if (t && t->s_type == STYPE_RAW && !strcmp(s->ths_title, name))
- subscription_unsubscribe(s, 0);
+ subscription_unsubscribe(s, UNSUBSCRIBE_FINAL);
s = n;
}
}
/* Upate timer */
if (!mms->mms_enabled) {
if (mms->mms_sub)
- subscription_unsubscribe(mms->mms_sub, 0);
+ subscription_unsubscribe(mms->mms_sub, UNSUBSCRIBE_FINAL);
mms->mms_sub = NULL;
mms->mms_active = 0;
gtimer_disarm(&mms->mms_timer);
/* Cancel sub */
} else {
if (mms->mms_sub) {
- subscription_unsubscribe(mms->mms_sub, 0);
+ subscription_unsubscribe(mms->mms_sub, UNSUBSCRIBE_FINAL);
mms->mms_sub = NULL;
}
mms->mms_active = 0;
if (delconf)
hts_settings_remove("muxsched/%s", idnode_uuid_as_sstr(&mms->mms_id));
if (mms->mms_sub)
- subscription_unsubscribe(mms->mms_sub, 0);
+ subscription_unsubscribe(mms->mms_sub, UNSUBSCRIBE_FINAL);
gtimer_disarm(&mms->mms_timer);
idnode_unlink(&mms->mms_id);
free(mms->mms_cronstr);
rs->frontend, rs->session, rs->stream, slave->s_nicename);
master->s_unlink(master, slave);
if (sub->ths)
- subscription_unsubscribe(sub->ths, 0);
+ subscription_unsubscribe(sub->ths, UNSUBSCRIBE_FINAL);
if (sub->prch.prch_id)
profile_chain_close(&sub->prch);
LIST_REMOVE(sub, link);
while ((sub = LIST_FIRST(&rs->slaves)) != NULL)
rtsp_slave_remove(rs, (mpegts_service_t *)rs->subs->ths_raw_service,
sub->service);
- subscription_unsubscribe(rs->subs, 0);
+ subscription_unsubscribe(rs->subs, UNSUBSCRIBE_FINAL);
rs->subs = NULL;
}
if (rs->prch.prch_id)
pthread_mutex_unlock(&sq->sq_mutex);
pthread_mutex_lock(&global_lock);
- subscription_unsubscribe(sub, 0);
+ subscription_unsubscribe(sub, UNSUBSCRIBE_FINAL);
if(err) {
tvhinfo("service_mapper", "%s: failed [err %s]", s->s_nicename, err);
LIST_REMOVE(s, ths_service_link);
- if (stop && s-(s->ths_flags & SUBSCRIPTION_ONESHOT) != 0)
+ if (stop && (s->ths_flags & SUBSCRIPTION_ONESHOT) != 0)
gtimer_arm(&s->ths_remove_timer, subscription_unsubscribe_cb, s, 0);
stop:
static void
subscription_unsubscribe_cb(void *aux)
{
- subscription_unsubscribe((th_subscription_t *)aux, 0);
+ subscription_unsubscribe((th_subscription_t *)aux, UNSUBSCRIBE_FINAL);
+}
+
+static void
+subscription_destroy(th_subscription_t *s)
+{
+ streaming_msg_free(s->ths_start_message);
+
+ if(s->ths_output->st_cb == subscription_input_null)
+ free(s->ths_output);
+
+ free(s->ths_title);
+ free(s->ths_hostname);
+ free(s->ths_username);
+ free(s->ths_client);
+ free(s->ths_dvrfile);
+ free(s);
+
}
void
-subscription_unsubscribe(th_subscription_t *s, int quiet)
+subscription_unsubscribe(th_subscription_t *s, int flags)
{
service_t *t;
char buf[512];
t = s->ths_service;
raw = s->ths_raw_service;
- assert(s->ths_state != SUBSCRIPTION_ZOMBIE);
+ if (s->ths_state == SUBSCRIPTION_ZOMBIE) {
+ if ((flags & UNSUBSCRIBE_FINAL) != 0) {
+ subscription_destroy(s);
+ return;
+ }
+ abort();
+ }
s->ths_state = SUBSCRIPTION_ZOMBIE;
service_instance_list_clear(&s->ths_instances);
tvh_strlcatf(buf, sizeof(buf), l, ", username=\"%s\"", s->ths_username);
if (s->ths_client)
tvh_strlcatf(buf, sizeof(buf), l, ", client=\"%s\"", s->ths_client);
- tvhlog(quiet ? LOG_TRACE : LOG_INFO, "subscription", "%04X: %s", shortid(s), buf);
+ tvhlog((flags & UNSUBSCRIBE_QUIET) != 0 ? LOG_TRACE : LOG_INFO,
+ "subscription", "%04X: %s", shortid(s), buf);
if (t)
service_remove_subscriber(t, s, SM_CODE_OK);
gtimer_disarm(&s->ths_remove_timer);
- streaming_msg_free(s->ths_start_message);
-
- if(s->ths_output->st_cb == subscription_input_null)
- free(s->ths_output);
-
- free(s->ths_title);
- free(s->ths_hostname);
- free(s->ths_username);
- free(s->ths_client);
- free(s->ths_dvrfile);
- free(s);
+ if ((flags & UNSUBSCRIBE_FINAL) != 0 ||
+ (s->ths_flags & SUBSCRIPTION_ONESHOT) != 0)
+ subscription_destroy(s);
gtimer_arm(&subscription_reschedule_timer,
subscription_reschedule_cb, NULL, 0);
if (flags & SUBSCRIPTION_ONESHOT) {
if ((si = subscription_start_instance(s, error)) == NULL) {
- subscription_unsubscribe(s, 1);
+ subscription_unsubscribe(s, UNSUBSCRIBE_QUIET | UNSUBSCRIBE_FINAL);
return NULL;
}
subscription_link_service(s, si->si_s);
#define SUBSCRIPTION_PRIO_MAPPER 7 ///< Channel mapper
#define SUBSCRIPTION_PRIO_MIN 10 ///< User defined / Normal levels
+/* Unsubscribe flags */
+#define UNSUBSCRIBE_QUIET 0x01
+#define UNSUBSCRIBE_FINAL 0x02
+
typedef struct th_subscription {
int ths_id;
void subscription_done(void);
-void subscription_unsubscribe(th_subscription_t *s, int quiet);
+void subscription_unsubscribe(th_subscription_t *s, int flags);
void subscription_set_weight(th_subscription_t *s, unsigned int weight);
pthread_mutex_unlock(&global_lock);
http_stream_run(hc, &prch, name, s);
pthread_mutex_lock(&global_lock);
- subscription_unsubscribe(s, 0);
+ subscription_unsubscribe(s, UNSUBSCRIBE_FINAL);
res = 0;
}
}
http_stream_run(hc, &prch, name, s);
pthread_mutex_lock(&global_lock);
}
- subscription_unsubscribe(s, 0);
+ subscription_unsubscribe(s, UNSUBSCRIBE_FINAL);
res = 0;
}
}
pthread_mutex_unlock(&global_lock);
http_stream_run(hc, &prch, name, s);
pthread_mutex_lock(&global_lock);
- subscription_unsubscribe(s, 0);
+ subscription_unsubscribe(s, UNSUBSCRIBE_FINAL);
res = 0;
}
}
pthread_mutex_lock(&global_lock);
if (sub)
- subscription_unsubscribe(sub, 0);
+ subscription_unsubscribe(sub, UNSUBSCRIBE_FINAL);
http_stream_postop(tcp_id);
pthread_mutex_unlock(&global_lock);
return ret;