
static u32 get_track_id(GF_ISOFile *file, TrackIdentifier *tkid)
{
	u32 cur_tk=0, i, count = gf_isom_get_track_count(file);
	if (tkid->type==1) {
		if (!tkid->ID_or_num || (count < tkid->ID_or_num)) return 0;
		return gf_isom_get_track_id(file, tkid->ID_or_num);
	}
	if (tkid->type==0) {
		return tkid->ID_or_num;
	}
	for (i=0; i<count; i++) {
		u32 mtype = gf_isom_get_media_type(file, i+1);
		if (tkid->type==2) {
			if (!gf_isom_is_video_handler_type(mtype)) continue;
		}
		else if (tkid->type==3) {
			if (mtype != GF_ISOM_MEDIA_AUDIO) continue;
		} else if (tkid->type==4) {
			if ((mtype != GF_ISOM_MEDIA_TEXT) && (mtype != GF_ISOM_MEDIA_SUBT)) continue;
		} else {
			continue;
		}
		cur_tk++;
		if (tkid->ID_or_num && (cur_tk != tkid->ID_or_num)) continue;
		return gf_isom_get_track_id(file, i+1);
	}
	return 0;

static u32 get_track_id(GF_ISOFile *file, TrackIdentifier *tkid)
{
	u32 cur_tk=0, i, count = gf_isom_get_track_count(file);
	if (tkid->type==1) {
		if (!tkid->ID_or_num || (count < tkid->ID_or_num)) return 0;
		return gf_isom_get_track_id(file, tkid->ID_or_num);
	}
	if (tkid->type==0) {
		return tkid->ID_or_num;
	}
	for (i=0; i<count; i++) {
		u32 mtype = gf_isom_get_media_type(file, i+1);
		if (tkid->type==2) {
			if (!gf_isom_is_video_handler_type(mtype)) continue;
		}
		else if (tkid->type==3) {
			if (mtype != GF_ISOM_MEDIA_AUDIO) continue;
		} else if (tkid->type==4) {
			if ((mtype != GF_ISOM_MEDIA_TEXT) && (mtype != GF_ISOM_MEDIA_SUBT)) continue;
		} else {
			continue;
		}
		cur_tk++;
		if (tkid->ID_or_num && (cur_tk != tkid->ID_or_num)) continue;
		return gf_isom_get_track_id(file, i+1);
	}
	return 0;