GF_Err trun_box_dump(GF_Box *a, FILE * trace)
{
	u32 i, flags;
	Bool full_dump = GF_FALSE;
	GF_TrackFragmentRunBox *p;

	p = (GF_TrackFragmentRunBox *)a;
	flags = p->flags;
#ifdef GF_ENABLE_CTRN
	if (p->use_ctrn) {
		p->flags = p->ctrn_flags;
		p->type = GF_ISOM_BOX_TYPE_CTRN;
	}
	gf_isom_box_dump_start(a, p->use_ctrn ? "CompactTrackRunBox" : "TrackRunBox", trace);
#else
	gf_isom_box_dump_start(a, "TrackRunBox", trace);
#endif
	p->flags = flags;
	p->type = GF_ISOM_BOX_TYPE_TRUN;
	gf_fprintf(trace, "SampleCount=\"%d\"", p->sample_count);

	if (p->flags & GF_ISOM_TRUN_DATA_OFFSET)
		gf_fprintf(trace, " DataOffset=\"%d\"", p->data_offset);

#ifdef GF_ENABLE_CTRN
	if (p->use_ctrn) {
		if (p->ctrn_flags & GF_ISOM_CTRN_DATAOFFSET_16)
			gf_fprintf(trace, " dataOffset16Bits=\"yes\"");

		if (p->ctso_multiplier)
			gf_fprintf(trace, " ctsoMultiplier=\"%d\"", p->ctso_multiplier);

		if (p->ctrn_flags & GF_ISOM_CTRN_INHERIT_DUR)
			gf_fprintf(trace, " inheritDuration=\"yes\"");
		if (p->ctrn_flags & GF_ISOM_CTRN_INHERIT_SIZE)
			gf_fprintf(trace, " inheritSize=\"yes\"");
		if (p->ctrn_flags & GF_ISOM_CTRN_INHERIT_FLAGS)
			gf_fprintf(trace, " inheritFlags=\"yes\"");
		if (p->ctrn_flags & GF_ISOM_CTRN_INHERIT_CTSO)
			gf_fprintf(trace, " inheritCTSOffset=\"yes\"");

		gf_fprintf(trace, " firstSampleDurationBits=\"%d\"", gf_isom_ctrn_field_size_bits(p->ctrn_first_dur));
		gf_fprintf(trace, " firstSampleSizeBits=\"%d\"", gf_isom_ctrn_field_size_bits(p->ctrn_first_size));
		gf_fprintf(trace, " firstSampleFlagsBits=\"%d\"", gf_isom_ctrn_field_size_bits(p->ctrn_first_sample_flags));
		gf_fprintf(trace, " firstSampleCTSOBits=\"%d\"", gf_isom_ctrn_field_size_bits(p->ctrn_first_ctts));
		gf_fprintf(trace, " sampleDurationBits=\"%d\"", gf_isom_ctrn_field_size_bits(p->ctrn_dur));
		gf_fprintf(trace, " sampleSizeBits=\"%d\"", gf_isom_ctrn_field_size_bits(p->ctrn_size));
		gf_fprintf(trace, " sampleFlagsBits=\"%d\"", gf_isom_ctrn_field_size_bits(p->ctrn_sample_flags));
		gf_fprintf(trace, " sampleCTSOBits=\"%d\"", gf_isom_ctrn_field_size_bits(p->ctrn_ctts));
		if (p->ctrn_flags & 0x00FFFF00)
			full_dump = GF_TRUE;

		gf_fprintf(trace, ">\n");
	} else
#endif
	{
		gf_fprintf(trace, ">\n");

		if (p->flags & GF_ISOM_TRUN_FIRST_FLAG) {
			sample_flags_dump("FirstSampleFlags", p->first_sample_flags, trace);
		}
		if (p->flags & (GF_ISOM_TRUN_DURATION|GF_ISOM_TRUN_SIZE|GF_ISOM_TRUN_CTS_OFFSET|GF_ISOM_TRUN_FLAGS)) {
			full_dump = GF_TRUE;
		}
	}

	if (full_dump) {
		for (i=0; i<p->nb_samples; i++) {
			GF_TrunEntry *ent = &p->samples[i];
			
			gf_fprintf(trace, "<TrackRunEntry");

#ifdef GF_ENABLE_CTRN
			if (p->use_ctrn) {
				if ((i==1) && (p->ctrn_flags&GF_ISOM_CTRN_FIRST_SAMPLE) ) {
					if (p->ctrn_first_dur)
						gf_fprintf(trace, " Duration=\"%u\"", ent->Duration);
					if (p->ctrn_first_size)
						gf_fprintf(trace, " Size=\"%u\"", ent->size);
					if (p->ctrn_first_ctts) {
						if (p->version == 0)
							gf_fprintf(trace, " CTSOffset=\"%u\"", (u32) ent->CTS_Offset);
						else
							gf_fprintf(trace, " CTSOffset=\"%d\"", ent->CTS_Offset);
					}
					if (p->ctrn_first_sample_flags)
						frag_dump_sample_flags(trace, ent->flags, p->ctrn_first_sample_flags);
				} else {
					if (p->ctrn_dur)
						gf_fprintf(trace, " Duration=\"%u\"", ent->Duration);
					if (p->ctrn_size)
						gf_fprintf(trace, " Size=\"%u\"", ent->size);
					if (p->ctrn_ctts) {
						if (p->version == 0)
							gf_fprintf(trace, " CTSOffset=\"%u\"", (u32) ent->CTS_Offset);
						else
							gf_fprintf(trace, " CTSOffset=\"%d\"", ent->CTS_Offset);
					}
					if (p->ctrn_sample_flags)
						frag_dump_sample_flags(trace, ent->flags, p->ctrn_sample_flags);
				}
			} else
#endif
			{

				if (p->flags & GF_ISOM_TRUN_DURATION)
					gf_fprintf(trace, " Duration=\"%u\"", ent->Duration);
				if (p->flags & GF_ISOM_TRUN_SIZE)
					gf_fprintf(trace, " Size=\"%u\"", ent->size);
				if (p->flags & GF_ISOM_TRUN_CTS_OFFSET)
				{
					if (p->version == 0)
						gf_fprintf(trace, " CTSOffset=\"%u\"", (u32) ent->CTS_Offset);
					else
						gf_fprintf(trace, " CTSOffset=\"%d\"", ent->CTS_Offset);
				}

				if (p->flags & GF_ISOM_TRUN_FLAGS) {
					frag_dump_sample_flags(trace, ent->flags, 3);
				}
			}
			gf_fprintf(trace, "/>\n");
		}
	} else if (p->size) {
		gf_fprintf(trace, "<!-- all default values used -->\n");
	} else {
		gf_fprintf(trace, "<TrackRunEntry Duration=\"\" Size=\"\" CTSOffset=\"\"");
		frag_dump_sample_flags(trace, 0, 3);
		gf_fprintf(trace, "/>\n");
	}

#ifdef GF_ENABLE_CTRN
	gf_isom_box_dump_done(p->use_ctrn ? "CompactTrackRunBox" : "TrackRunBox", a, trace);
#else
	gf_isom_box_dump_done("TrackRunBox", a, trace);
#endif
	return GF_OK;
}