gf_free(info);
	}
	gf_list_del(pinfos);

	return nb_periods;
}

static void dasher_init_utc(GF_Filter *filter, GF_DasherCtx *ctx)
{
	const char *cache_name;
	u32 size;
	u8 *data;
	u64 remote_utc;
	GF_Err e;
	GF_DownloadSession *sess;
	GF_DownloadManager *dm;
	char *url;
	DasherUTCTimingType def_type = DASHER_UTCREF_NONE;

	ctx->utc_initialized = GF_TRUE;
	ctx->utc_timing_type = DASHER_UTCREF_NONE;
	if (!ctx->utcs) {
		return;
	}
	url = ctx->utcs;
	if (!strncmp(url, "xsd@", 4)) {
		def_type = DASHER_UTCREF_XSDATE;
		url += 4;
	}

	dm  = gf_filter_get_download_manager(filter);
	if (!dm) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("[DASH] Failed to get download manager, cannot sync to remote UTC clock\n"));
		return;
	}
	if (!strcmp(ctx->utcs, "inband")) {
		ctx->utc_timing_type = DASHER_UTCREF_INBAND;
		return;
	}

	sess = gf_dm_sess_new(dm, url, GF_NETIO_SESSION_MEMORY_CACHE|GF_NETIO_SESSION_NOT_THREADED, NULL, NULL, &e);
	if (e) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("[DASH] Failed to create session for remote UTC source %s: %s - local clock will be used instead\n", url, gf_error_to_string(e) ));
		return;
	}
	while (1) {
		GF_NetIOStatus status;
		e = gf_dm_sess_process(sess);
		if (e) break;
		gf_dm_sess_get_stats(sess, NULL, NULL, NULL, NULL, NULL, &status);
		if (status>=GF_NETIO_DATA_TRANSFERED) break;
	}
	if (e<0) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("[DASH] Failed to fetch remote UTC source %s: %s\n", url, gf_error_to_string(e) ));
		gf_dm_sess_del(sess);
		return;
	}
	cache_name = gf_dm_sess_get_cache_name(sess);
	gf_blob_get(cache_name, &data, &size, NULL);
	if (data) {
		//xsDate or isoDate - we always signal using iso
		if (strchr(data, 'T')) {
			remote_utc = gf_net_parse_date(data);
			if (remote_utc)
				ctx->utc_timing_type = def_type ? def_type : DASHER_UTCREF_ISO;
		}
		//ntp
		else if (sscanf(data, LLU, &remote_utc) == 1) {
			//ntp value not counted since 1900, assume format is seconds till 1 jan 1970
			if (remote_utc<=GF_NTP_SEC_1900_TO_1970) {
				remote_utc = remote_utc*1000;
			} else {
				remote_utc = gf_net_ntp_to_utc(remote_utc);
			}
			if (remote_utc)
				ctx->utc_timing_type = DASHER_UTCREF_NTP;
		}
	}
	gf_blob_release(cache_name);

	//not match, try http date
	if (!ctx->utc_timing_type) {
		const char *hdr = gf_dm_sess_get_header(sess, "Date");
		if (hdr) {
			//http-head
			remote_utc = gf_net_parse_date(hdr);
			if (remote_utc)
				ctx->utc_timing_type = DASHER_UTCREF_HTTP_HEAD;
		}
	}

	if (!ctx->utc_timing_type) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("[DASH] Failed to parse response %s from remote UTC source %s\n", data, url ));
	} else {
		ctx->utc_diff = (s32) ( (s64) gf_net_get_utc() - (s64) remote_utc );
		if (ABS(ctx->utc_diff) > 3600000) {
			GF_LOG(GF_LOG_WARNING, GF_LOG_DASH, ("[Dasher] Diff between local clock and remote %s is %d, way too large! Assuming 0 ms UTC diff\n", url, ctx->utc_diff));
			ctx->utc_diff = 0;
		} else {
			GF_LOG(GF_LOG_INFO, GF_LOG_DASH, ("[Dasher] Synchronized clock to remote %s - UTC diff (local - remote) %d ms\n", url, ctx->utc_diff));
		}

		if (!gf_list_count(ctx->mpd->utc_timings) ) {
			Bool dashif_ok = GF_FALSE;
			GF_MPD_Descriptor *utc_t;
			GF_SAFEALLOC(utc_t, GF_MPD_Descriptor);
			utc_t->value = gf_strdup(url);
			switch (ctx->utc_timing_type) {
			case DASHER_UTCREF_HTTP_HEAD:
				utc_t->scheme_id_uri = gf_strdup("urn:mpeg:dash:utc:http-head:2014");
				break;
			case DASHER_UTCREF_XSDATE:
				utc_t->scheme_id_uri = gf_strdup("urn:mpeg:dash:utc:http-xsdate:2014");
				dashif_ok = GF_TRUE;
				break;
			case DASHER_UTCREF_ISO:
				utc_t->scheme_id_uri = gf_strdup("urn:mpeg:dash:utc:http-iso:2014");
				dashif_ok = GF_TRUE;
				break;
			case DASHER_UTCREF_NTP:
				utc_t->scheme_id_uri = gf_strdup("urn:mpeg:dash:utc:http-ntp:2014");
				dashif_ok = GF_TRUE;
				break;
			case DASHER_UTCREF_INBAND:
				utc_t->scheme_id_uri = gf_strdup("urn:mpeg:dash:utc:direct:2014");
				break;
			default:
				break;
			}
			if (!dashif_ok && (ctx->profile==GF_DASH_PROFILE_DASHIF_LL)) {
				GF_LOG(GF_LOG_WARNING, GF_LOG_DASH, ("[Dasher] UTC reference %s allowed in DASH-IF Low Latency profile\n\tswitching to regular live profile\n", utc_t->scheme_id_uri));
				ctx->profile = GF_DASH_PROFILE_LIVE;
			}