
		assert(ds->rep->dasher_ctx->init_seg);
		assert(ds->rep->dasher_ctx->src_url);
		assert(ds->rep->dasher_ctx->template_seg);
	}
}

void dasher_context_update_period_start(GF_DasherCtx *ctx)
{
	u32 i, j, count;

	if (!ctx->mpd) return;
	count = gf_list_count(ctx->current_period->streams);
	for (i=0; i<count; i++) {
		GF_DashStream *ds = gf_list_get(ctx->current_period->streams, i);
		if (!ds->rep) continue;
		if (ds->rep->dasher_ctx) continue;

		//store all static parameters of the rep
		GF_SAFEALLOC(ds->rep->dasher_ctx, GF_DASH_SegmenterContext);
		if (!ds->rep->dasher_ctx) return;

		ds->rep->dasher_ctx->done = 0;

		assert(ds->init_seg);
		ds->rep->dasher_ctx->init_seg = gf_strdup(ds->init_seg);
		assert(ds->src_url);
		ds->rep->dasher_ctx->src_url = gf_strdup(ds->src_url);
		assert(ds->seg_template);
		ds->rep->dasher_ctx->template_seg = gf_strdup(ds->seg_template);
		if (ds->idx_template)
			ds->rep->dasher_ctx->template_idx = gf_strdup(ds->idx_template);

		ds->rep->dasher_ctx->pid_id = ds->pid_id;
		ds->rep->dasher_ctx->dep_pid_id = ds->dep_pid_id;
		ds->rep->dasher_ctx->period_start = ds->period_start;
		ds->rep->dasher_ctx->period_duration = ds->period_dur;
		ds->rep->dasher_ctx->multi_pids = ds->multi_pids ? GF_TRUE : GF_FALSE;
		ds->rep->dasher_ctx->dash_dur = ds->dash_dur;

		if (strcmp(ds->period_id, DEFAULT_PERIOD_ID))
			ds->rep->dasher_ctx->period_id = ds->period_id;

		ds->rep->dasher_ctx->owns_set = (ds->set->udta == ds) ? GF_TRUE : GF_FALSE;

		if (ds->rep->dasher_ctx->mux_pids) gf_free(ds->rep->dasher_ctx->mux_pids);
		ds->rep->dasher_ctx->mux_pids = NULL;
		for (j=0; j<count; j++) {
			char szMuxPID[10];
			GF_DashStream *a_ds = gf_list_get(ctx->current_period->streams, j);
			if (a_ds==ds) continue;
			if (a_ds->muxed_base != ds) continue;

			if (ds->rep->dasher_ctx->mux_pids)
				sprintf(szMuxPID, " %d", a_ds->id);
			else

		assert(ds->rep->dasher_ctx->init_seg);
		assert(ds->rep->dasher_ctx->src_url);
		assert(ds->rep->dasher_ctx->template_seg);
	}
}

void dasher_context_update_period_start(GF_DasherCtx *ctx)
{
	u32 i, j, count;

	if (!ctx->mpd) return;
	count = gf_list_count(ctx->current_period->streams);
	for (i=0; i<count; i++) {
		GF_DashStream *ds = gf_list_get(ctx->current_period->streams, i);
		if (!ds->rep) continue;
		if (ds->rep->dasher_ctx) continue;

		 
		GF_SAFEALLOC(ds->rep->dasher_ctx, GF_DASH_SegmenterContext);
		if (!ds->rep->dasher_ctx) return;

		ds->rep->dasher_ctx->done = 0;

		assert(ds->init_seg);
		ds->rep->dasher_ctx->init_seg = gf_strdup(ds->init_seg);
		assert(ds->src_url);
		ds->rep->dasher_ctx->src_url = gf_strdup(ds->src_url);
		assert(ds->seg_template);
		ds->rep->dasher_ctx->template_seg = gf_strdup(ds->seg_template);
		if (ds->idx_template)
			ds->rep->dasher_ctx->template_idx = gf_strdup(ds->idx_template);

		ds->rep->dasher_ctx->pid_id = ds->pid_id;
		ds->rep->dasher_ctx->dep_pid_id = ds->dep_pid_id;
		ds->rep->dasher_ctx->period_start = ds->period_start;
		ds->rep->dasher_ctx->period_duration = ds->period_dur;
		ds->rep->dasher_ctx->multi_pids = ds->multi_pids ? GF_TRUE : GF_FALSE;
		ds->rep->dasher_ctx->dash_dur = ds->dash_dur;

		if (strcmp(ds->period_id, DEFAULT_PERIOD_ID))
			ds->rep->dasher_ctx->period_id = ds->period_id;

		ds->rep->dasher_ctx->owns_set = (ds->set->udta == ds) ? GF_TRUE : GF_FALSE;

		if (ds->rep->dasher_ctx->mux_pids) gf_free(ds->rep->dasher_ctx->mux_pids);
		ds->rep->dasher_ctx->mux_pids = NULL;
		for (j=0; j<count; j++) {
			char szMuxPID[10];
			GF_DashStream *a_ds = gf_list_get(ctx->current_period->streams, j);
			if (a_ds==ds) continue;
			if (a_ds->muxed_base != ds) continue;

			if (ds->rep->dasher_ctx->mux_pids)
				sprintf(szMuxPID, " %d", a_ds->id);
			else