	GF_SAFEALLOC(s, GF_MPD_SegmentTimelineEntry);
	if (!s) return;
	s->start_time = ds->seg_start_time + pto;
	s->duration = (u32) duration;
	gf_list_add(tl->entries, s);
}

static void dasher_copy_segment_timelines(GF_DasherCtx *ctx, GF_MPD_AdaptationSet *set)
{
	GF_MPD_SegmentTimeline *src_tl = NULL;
	u32 i, j, count, nb_s;
	//get as level segment timeline, set it to NULL, reassign it to first rep and clone for other reps
	if (ctx->tpl) {
		assert(set->segment_template->segment_timeline);
		src_tl = set->segment_template->segment_timeline;
		set->segment_template->segment_timeline = NULL;
	} else {
		assert(set->segment_list->segment_timeline);
		src_tl = set->segment_list->segment_timeline;
		set->segment_list->segment_timeline = NULL;
	}
	nb_s = gf_list_count(src_tl->entries);

	count = gf_list_count(set->representations);
	for (i=0; i<count; i++) {
		GF_MPD_SegmentTimeline *tl = NULL;
		GF_MPD_Representation *rep = gf_list_get(set->representations, i);
		if (ctx->tpl) {
			if (!rep->segment_template) {
				GF_SAFEALLOC(rep->segment_template, GF_MPD_SegmentTemplate);
				if (!rep->segment_template) continue;
			}
			if (!i) {
				rep->segment_template->segment_timeline = src_tl;
				continue;
			}
			if (!rep->segment_template->segment_timeline) {
				rep->segment_template->segment_timeline = gf_mpd_segmentimeline_new();
			}
			tl = rep->segment_template->segment_timeline;
		} else {
			if (!rep->segment_list) {
				GF_SAFEALLOC(rep->segment_list, GF_MPD_SegmentList);
				if (!rep->segment_list) continue;
				rep->segment_list->start_number = (u32) -1;
			}
			if (!i) {
				rep->segment_list->segment_timeline = src_tl;
				continue;
			}
			if (!rep->segment_list->segment_timeline) {
				rep->segment_list->segment_timeline = gf_mpd_segmentimeline_new();
			}
			tl = rep->segment_list->segment_timeline;
		}
		assert(tl);
		for (j=0; j<nb_s; j++) {
			GF_MPD_SegmentTimelineEntry *s;
			GF_MPD_SegmentTimelineEntry *src_s = gf_list_get(src_tl->entries, j);
			GF_SAFEALLOC(s, GF_MPD_SegmentTimelineEntry);
			if (!s) continue;

	GF_SAFEALLOC(s, GF_MPD_SegmentTimelineEntry);
	if (!s) return;
	s->start_time = ds->seg_start_time + pto;
	s->duration = (u32) duration;
	gf_list_add(tl->entries, s);
}

static void dasher_copy_segment_timelines(GF_DasherCtx *ctx, GF_MPD_AdaptationSet *set)
{
	GF_MPD_SegmentTimeline *src_tl = NULL;
	u32 i, j, count, nb_s;
	 
	if (ctx->tpl) {
		assert(set->segment_template->segment_timeline);
		src_tl = set->segment_template->segment_timeline;
		set->segment_template->segment_timeline = NULL;
	} else {
		assert(set->segment_list->segment_timeline);
		src_tl = set->segment_list->segment_timeline;
		set->segment_list->segment_timeline = NULL;
	}
	nb_s = gf_list_count(src_tl->entries);

	count = gf_list_count(set->representations);
	for (i=0; i<count; i++) {
		GF_MPD_SegmentTimeline *tl = NULL;
		GF_MPD_Representation *rep = gf_list_get(set->representations, i);
		if (ctx->tpl) {
			if (!rep->segment_template) {
				GF_SAFEALLOC(rep->segment_template, GF_MPD_SegmentTemplate);
				if (!rep->segment_template) continue;
			}
			if (!i) {
				rep->segment_template->segment_timeline = src_tl;
				continue;
			}
			if (!rep->segment_template->segment_timeline) {
				rep->segment_template->segment_timeline = gf_mpd_segmentimeline_new();
			}
			tl = rep->segment_template->segment_timeline;
		} else {
			if (!rep->segment_list) {
				GF_SAFEALLOC(rep->segment_list, GF_MPD_SegmentList);
				if (!rep->segment_list) continue;
				rep->segment_list->start_number = (u32) -1;
			}
			if (!i) {
				rep->segment_list->segment_timeline = src_tl;
				continue;
			}
			if (!rep->segment_list->segment_timeline) {
				rep->segment_list->segment_timeline = gf_mpd_segmentimeline_new();
			}
			tl = rep->segment_list->segment_timeline;
		}
		assert(tl);
		for (j=0; j<nb_s; j++) {
			GF_MPD_SegmentTimelineEntry *s;
			GF_MPD_SegmentTimelineEntry *src_s = gf_list_get(src_tl->entries, j);
			GF_SAFEALLOC(s, GF_MPD_SegmentTimelineEntry);
			if (!s) continue;
