static void gf_filter_setup_failure_task(GF_FSTask *task)
{
	s32 res;
	GF_Err e;
	GF_Filter *f = ((struct _gf_filter_setup_failure *)task->udta)->filter;
	if (task->udta) {
		e = ((struct _gf_filter_setup_failure *)task->udta)->e;
		gf_free(task->udta);
		f->session->last_connect_error = e;
	}

	if (!f->finalized && f->freg->finalize) {
		FSESS_CHECK_THREAD(f)
		f->freg->finalize(f);
	}
	gf_mx_p(f->session->filters_mx);

	res = gf_list_del_item(f->session->filters, f);
	if (res < 0) {
		GF_LOG(GF_LOG_WARNING, GF_LOG_FILTER, ("Filter %s task failure callback on already removed filter!\n", f->name));
	}

	gf_mx_v(f->session->filters_mx);

	gf_mx_p(f->tasks_mx);
	//detach all input pids
	while (gf_list_count(f->input_pids)) {
		GF_FilterPidInst *pidinst = gf_list_pop_back(f->input_pids);
		pidinst->filter = NULL;
	}
	//detach all output pids
	while (gf_list_count(f->output_pids)) {
		u32 j;
		GF_FilterPid *pid = gf_list_pop_back(f->output_pids);
		for (j=0; j<pid->num_destinations; j++) {
			GF_FilterPid *pidinst = gf_list_get(pid->destinations, j);
			pidinst->pid = NULL;
		}
	}
	gf_mx_v(f->tasks_mx);

	gf_filter_del(f);
}
static void gf_filter_setup_failure_task(GF_FSTask *task)
{
	s32 res;
	GF_Err e;
	GF_Filter *f = ((struct _gf_filter_setup_failure *)task->udta)->filter;
	if (task->udta) {
		e = ((struct _gf_filter_setup_failure *)task->udta)->e;
		gf_free(task->udta);
		f->session->last_connect_error = e;
	}

	if (!f->finalized && f->freg->finalize) {
		FSESS_CHECK_THREAD(f)
		f->freg->finalize(f);
	}
	gf_mx_p(f->session->filters_mx);

	res = gf_list_del_item(f->session->filters, f);
	if (res < 0) {
		GF_LOG(GF_LOG_WARNING, GF_LOG_FILTER, ("Filter %s task failure callback on already removed filter!\n", f->name));
	}

	gf_mx_v(f->session->filters_mx);

	gf_mx_p(f->tasks_mx);
	 
	while (gf_list_count(f->input_pids)) {
		GF_FilterPidInst *pidinst = gf_list_pop_back(f->input_pids);
		pidinst->filter = NULL;
	}
	 
	while (gf_list_count(f->output_pids)) {
		u32 j;
		GF_FilterPid *pid = gf_list_pop_back(f->output_pids);
		for (j=0; j<pid->num_destinations; j++) {
			GF_FilterPid *pidinst = gf_list_get(pid->destinations, j);
			pidinst->pid = NULL;
		}
	}
	gf_mx_v(f->tasks_mx);

	gf_filter_del(f);
}