GF_Err ilst_item_box_dump(GF_Box *a, FILE * trace)
{
	u32 val, itype=0;
	Bool no_dump = GF_FALSE;
	Bool unknown = GF_FALSE;
	GF_DataBox *dbox = NULL;
	const char *name = "UnknownBox";
	GF_ListItemBox *itune = (GF_ListItemBox *)a;


	if (itune->type==GF_ISOM_BOX_TYPE_iTunesSpecificInfo) {
		name = "iTunesSpecificBox";
		no_dump = GF_TRUE;
		dbox = itune->data;
	} else if (itune->type==GF_ISOM_BOX_TYPE_UNKNOWN) {
		dbox = (GF_DataBox *) gf_isom_box_find_child(itune->child_boxes, GF_ISOM_BOX_TYPE_DATA);
		unknown = GF_TRUE;
	} else {
		s32 idx = gf_itags_find_by_itag(itune->type);
		if (idx>=0) {
			name = gf_itags_get_name((u32) idx);
			itype = gf_itags_get_type((u32) idx);
			dbox = itune->data;
		}
	}
	gf_isom_box_dump_start(a, name, trace);

	if (!no_dump && dbox) {
		GF_BitStream *bs;
		switch (itune->type) {
		case GF_ISOM_ITUNE_DISK:
		case GF_ISOM_ITUNE_TRACKNUMBER:
			bs = gf_bs_new(dbox->data, dbox->dataSize, GF_BITSTREAM_READ);
			gf_bs_read_int(bs, 16);
			val = gf_bs_read_int(bs, 16);
			if (itune->type==GF_ISOM_ITUNE_DISK) {
				gf_fprintf(trace, " DiskNumber=\"%d\" NbDisks=\"%d\" ", val, gf_bs_read_int(bs, 16) );
			} else {
				gf_fprintf(trace, " TrackNumber=\"%d\" NbTracks=\"%d\" ", val, gf_bs_read_int(bs, 16) );
			}
			gf_bs_del(bs);
			break;
		case GF_ISOM_ITUNE_TEMPO:
			bs = gf_bs_new(dbox->data, dbox->dataSize, GF_BITSTREAM_READ);
			gf_fprintf(trace, " BPM=\"%d\" ", gf_bs_read_int(bs, 16) );
			gf_bs_del(bs);
			break;
		case GF_ISOM_ITUNE_COMPILATION:
			gf_fprintf(trace, " IsCompilation=\"%s\" ", (dbox && dbox->data && dbox->data[0]) ? "yes" : "no");
			break;
		case GF_ISOM_ITUNE_GAPLESS:
			gf_fprintf(trace, " IsGapeless=\"%s\" ", (dbox && dbox->data && itune->data->data[0]) ? "yes" : "no");
			break;
		case GF_ISOM_ITUNE_GENRE:
			if (dbox && dbox->data && itune->data->dataSize>=2) {
				u32 genre = itune->data->data[0];
				genre<<=8;
				genre |= itune->data->data[1];
				gf_fprintf(trace, " value=\"%s\" ", gf_id3_get_genre((u32) genre));
			}
			break;
		default:
			if (dbox && dbox->data) {
				gf_fprintf(trace, " value=\"");
				if (!unknown && (itype==GF_ITAG_STR)) {
					dump_data_string(trace, dbox->data, dbox->dataSize);
				}
				else if (!unknown && gf_utf8_is_legal(dbox->data, dbox->dataSize) ) {
					dump_data_string(trace, dbox->data, dbox->dataSize);
				} else {
					dump_data(trace, dbox->data, dbox->dataSize);
				}
				gf_fprintf(trace, "\" ");
			}
			break;
		}
	}
	gf_fprintf(trace, ">\n");
	gf_isom_box_dump_done(name, a, trace);
	return GF_OK;
}
GF_Err ilst_item_box_dump(GF_Box *a, FILE * trace)
{
	u32 val, itype=0;
	Bool no_dump = GF_FALSE;
	Bool unknown = GF_FALSE;
	GF_DataBox *dbox = NULL;
	const char *name = "UnknownBox";
	GF_ListItemBox *itune = (GF_ListItemBox *)a;


	if (itune->type==GF_ISOM_BOX_TYPE_iTunesSpecificInfo) {
		name = "iTunesSpecificBox";
		no_dump = GF_TRUE;
		dbox = itune->data;
	} else if (itune->type==GF_ISOM_BOX_TYPE_UNKNOWN) {
		dbox = (GF_DataBox *) gf_isom_box_find_child(itune->child_boxes, GF_ISOM_BOX_TYPE_DATA);
		unknown = GF_TRUE;
	} else {
		s32 idx = gf_itags_find_by_itag(itune->type);
		if (idx>=0) {
			name = gf_itags_get_name((u32) idx);
			itype = gf_itags_get_type((u32) idx);
			dbox = itune->data;
		}
	}
	gf_isom_box_dump_start(a, name, trace);

	if (!no_dump && dbox) {
		GF_BitStream *bs;
		switch (itune->type) {
		case GF_ISOM_ITUNE_DISK:
		case GF_ISOM_ITUNE_TRACKNUMBER:
			bs = gf_bs_new(dbox->data, dbox->dataSize, GF_BITSTREAM_READ);
			gf_bs_read_int(bs, 16);
			val = gf_bs_read_int(bs, 16);
			if (itune->type==GF_ISOM_ITUNE_DISK) {
				gf_fprintf(trace, " DiskNumber=\"%d\" NbDisks=\"%d\" ", val, gf_bs_read_int(bs, 16) );
			} else {
				gf_fprintf(trace, " TrackNumber=\"%d\" NbTracks=\"%d\" ", val, gf_bs_read_int(bs, 16) );
			}
			gf_bs_del(bs);
			break;
		case GF_ISOM_ITUNE_TEMPO:
			bs = gf_bs_new(dbox->data, dbox->dataSize, GF_BITSTREAM_READ);
			gf_fprintf(trace, " BPM=\"%d\" ", gf_bs_read_int(bs, 16) );
			gf_bs_del(bs);
			break;
		case GF_ISOM_ITUNE_COMPILATION:
			gf_fprintf(trace, " IsCompilation=\"%s\" ", (dbox && dbox->data && dbox->data[0]) ? "yes" : "no");
			break;
		case GF_ISOM_ITUNE_GAPLESS:
			gf_fprintf(trace, " IsGapeless=\"%s\" ", (dbox && dbox->data && itune->data->data[0]) ? "yes" : "no");
			break;
		case GF_ISOM_ITUNE_GENRE:
			if (dbox && dbox->data && itune->data->dataSize>=2) {
				u32 genre = itune->data->data[0];
				genre<<=8;
				genre |= itune->data->data[1];
				gf_fprintf(trace, " value=\"%s\" ", gf_id3_get_genre((u32) genre));
			}
			break;
		default:
			if (dbox && dbox->data) {
				gf_fprintf(trace, " value=\"");
				if (!unknown && (itype==GF_ITAG_STR)) {
					dump_data_string(trace, dbox->data, dbox->dataSize);
				}
				else if (!unknown && gf_utf8_is_legal(dbox->data, dbox->dataSize) ) {
					dump_data_string(trace, dbox->data, dbox->dataSize);
				} else {
					dump_data(trace, dbox->data, dbox->dataSize);
				}
				gf_fprintf(trace, "\" ");
			}
			break;
		}
	}
	gf_fprintf(trace, ">\n");
	gf_isom_box_dump_done(name, a, trace);
	return GF_OK;
}