	gf_mpd_del(mpd);
	gf_xml_dom_del(dom);
	gf_list_del(recompute_sets);
	if (e)
		ctx->in_error = GF_TRUE;
}

static GF_Err dasher_write_and_send_manifest(GF_DasherCtx *ctx, u64 last_period_dur, Bool do_m3u8, Bool m3u8_second_pass, GF_FilterPid *opid, char *alt_name)
{
	void *last_signature;
	u8 sig[GF_SHA1_DIGEST_SIZE];
	GF_Err e;
	FILE *tmp = gf_file_temp(NULL);
	if (do_m3u8) {
		ctx->mpd->m3u8_time = ctx->hlsc;
		ctx->mpd->nb_hls_ext_master = ctx->hlsx.nb_items;
		ctx->mpd->hls_ext_master = (const char **) ctx->hlsx.vals;
		ctx->mpd->llhls_preload = ctx->ll_preload_hint;
		ctx->mpd->llhls_rendition_reports = ctx->ll_rend_rep;
		ctx->mpd->llhls_part_holdback = ctx->ll_part_hb;

		if (ctx->llhls==3)
			ctx->mpd->force_llhls_mode = m3u8_second_pass ? 2 : 1;
		else
			ctx->mpd->force_llhls_mode = 0;

		if (m3u8_second_pass) {
			e = gf_mpd_write_m3u8_master_playlist(ctx->mpd, tmp, ctx->out_path, gf_list_last(ctx->mpd->periods) );
		} else {
			e = gf_mpd_write_m3u8_master_playlist(ctx->mpd, tmp, ctx->out_path, gf_list_last(ctx->mpd->periods) );
		}
	} else {
		e = gf_mpd_write(ctx->mpd, tmp, ctx->cmpd);
	}

	if (e) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("[Dasher] failed to write %s file: %s\n", do_m3u8 ? "M3U8" : "MPD", gf_error_to_string(e) ));
		gf_fclose(tmp);
		if (ctx->current_period->period)
			ctx->current_period->period->duration = last_period_dur;
		return e;
	}

	if (ctx->profile == GF_DASH_PROFILE_HBBTV_1_5_ISOBMF_LIVE) {
		if (gf_ftell(tmp) > 100 * 1024)
			GF_LOG(GF_LOG_WARNING, GF_LOG_DASH, ("[Dasher] manifest MPD is too big for HbbTV 1.5. Limit is 100kB, current size is "LLU"kB\n", gf_ftell(tmp) / 1024));
	}

	gf_sha1_file_ptr(tmp, sig);
	if (do_m3u8) {
		last_signature = (void *) m3u8_second_pass ? ctx->last_hls2_signature : ctx->last_hls_signature;
	} else {
		last_signature = (void *) ctx->last_mpd_signature;
	}

	if (memcmp(sig, last_signature, GF_SHA1_DIGEST_SIZE)) {
	gf_mpd_del(mpd);
	gf_xml_dom_del(dom);
	gf_list_del(recompute_sets);
	if (e)
		ctx->in_error = GF_TRUE;
}

static GF_Err dasher_write_and_send_manifest(GF_DasherCtx *ctx, u64 last_period_dur, Bool do_m3u8, Bool m3u8_second_pass, GF_FilterPid *opid, char *alt_name)
{
	void *last_signature;
	u8 sig[GF_SHA1_DIGEST_SIZE];
	GF_Err e;
	FILE *tmp = gf_file_temp(NULL);
	if (do_m3u8) {
		ctx->mpd->m3u8_time = ctx->hlsc;
		ctx->mpd->nb_hls_ext_master = ctx->hlsx.nb_items;
		ctx->mpd->hls_ext_master = (const char **) ctx->hlsx.vals;
		ctx->mpd->llhls_preload = ctx->ll_preload_hint;
		ctx->mpd->llhls_rendition_reports = ctx->ll_rend_rep;
		ctx->mpd->llhls_part_holdback = ctx->ll_part_hb;

		if (ctx->llhls==3)
			ctx->mpd->force_llhls_mode = m3u8_second_pass ? 2 : 1;
		else
			ctx->mpd->force_llhls_mode = 0;

		if (m3u8_second_pass) {
			e = gf_mpd_write_m3u8_master_playlist(ctx->mpd, tmp, ctx->out_path, gf_list_last(ctx->mpd->periods) );
		} else {
			e = gf_mpd_write_m3u8_master_playlist(ctx->mpd, tmp, ctx->out_path, gf_list_last(ctx->mpd->periods) );
		}
	} else {
		e = gf_mpd_write(ctx->mpd, tmp, ctx->cmpd);
	}

	if (e) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("[Dasher] failed to write %s file: %s\n", do_m3u8 ? "M3U8" : "MPD", gf_error_to_string(e) ));
		gf_fclose(tmp);
		if (ctx->current_period->period)
			ctx->current_period->period->duration = last_period_dur;
		return e;
	}

	if (ctx->profile == GF_DASH_PROFILE_HBBTV_1_5_ISOBMF_LIVE) {
		if (gf_ftell(tmp) > 100 * 1024)
			GF_LOG(GF_LOG_WARNING, GF_LOG_DASH, ("[Dasher] manifest MPD is too big for HbbTV 1.5. Limit is 100kB, current size is "LLU"kB\n", gf_ftell(tmp) / 1024));
	}

	gf_sha1_file_ptr(tmp, sig);
	if (do_m3u8) {
		last_signature = (void *) m3u8_second_pass ? ctx->last_hls2_signature : ctx->last_hls_signature;
	} else {
		last_signature = (void *) ctx->last_mpd_signature;
	}

	if (memcmp(sig, last_signature, GF_SHA1_DIGEST_SIZE)) {