Exemple #1
0
Bool gf_sc_uri_is_hardcoded_proto(GF_Compositor *compositor, const char *uri)
{
	/*check proto modules*/
	if (compositor && compositor->proto_modules ) {
		u32 j = 0;
		GF_HardcodedProto *ifce;
		while ( (ifce = (GF_HardcodedProto *)gf_list_enum(compositor->proto_modules, &j) )) {
			if ( ifce->can_load_proto(uri)) {
				return 1;
			}
		}
	}
	return 0;
}
Exemple #2
0
/*we assume a node field is not ISed several times (that's stated as "undefined behaviour" in VRML*/
GF_Route *gf_bifs_enc_is_field_ised(GF_BifsEncoder *codec, GF_Node *node, u32 fieldIndex)
{
	GF_Route *r;
	u32 i;
	if (!codec->encoding_proto) return NULL;

	if (node->sgprivate->interact && node->sgprivate->interact->routes) {
		i=0;
		while ((r = (GF_Route*)gf_list_enum(node->sgprivate->interact->routes, &i))) {
			if (!r->IS_route) continue;
			if ((r->ToNode == node) && (r->ToField.fieldIndex==fieldIndex)) return r;
			else if ((r->FromNode == node) && (r->FromField.fieldIndex==fieldIndex)) return r;
		}
	}

	i=0;
	while ((r = (GF_Route*)gf_list_enum(codec->encoding_proto->sub_graph->Routes, &i))) {
		if (!r->IS_route) continue;
		if ((r->ToNode == node) && (r->ToField.fieldIndex==fieldIndex)) return r;
		else if ((r->FromNode == node) && (r->FromField.fieldIndex==fieldIndex)) return r;
	}
	return NULL;
}
Exemple #3
0
/*locate session by control*/
RTSPSession *RP_CheckSession(RTPClient *rtp, char *control)
{
	u32 i;
	RTSPSession *sess;
	if (!control) return NULL;

	if (!strcmp(control, "*")) control = (char *) gf_service_get_url(rtp->service);

	i=0;
	while ( (sess = (RTSPSession *)gf_list_enum(rtp->sessions, &i)) ) {
		if (gf_rtsp_is_my_session(sess->session, control)) return sess;
	}
	return NULL;
}
Exemple #4
0
GF_Err gf_odf_size_od_update(GF_ODUpdate *odUp, u32 *outSize)
{
	GF_Descriptor *tmp;
	u32 i, tmpSize;
	if (!odUp) return GF_BAD_PARAM;

	*outSize = 0;
	i = 0;
	while ((tmp = (GF_Descriptor *)gf_list_enum(odUp->objectDescriptors, &i))) {
		gf_odf_size_descriptor(tmp, &tmpSize);
		*outSize += tmpSize + gf_odf_size_field_size(tmpSize);
	}
	return GF_OK;
}
Exemple #5
0
static void CTXLoad_CheckStreams(CTXLoadPriv *priv )
{
	u32 i, j, max_dur;
	GF_AUContext *au;
	GF_StreamContext *sc;
	max_dur = 0;
	i=0;
	while ((sc = (GF_StreamContext *)gf_list_enum(priv->ctx->streams, &i))) {
		/*all streams in root OD are handled with ESID 0 to differentiate with any animation streams*/
		if (CTXLoad_StreamInRootOD(priv->ctx->root_od, sc->ESID)) sc->in_root_od = 1;
		if (!sc->timeScale) sc->timeScale = 1000;

		j=0;
		while ((au = (GF_AUContext *)gf_list_enum(sc->AUs, &j))) {
			if (!au->timing) au->timing = (u64) (sc->timeScale*au->timing_sec);
		}
		if (au && sc->in_root_od && (au->timing>max_dur)) max_dur = (u32) (au->timing * 1000 / sc->timeScale);
	}
	if (max_dur) {
		priv->scene->root_od->duration = max_dur;
		gf_scene_set_duration(priv->scene);
	}
}
Exemple #6
0
static void FixSDTPInTRAF(GF_MovieFragmentBox *moof)
{
	u32 k;
	if (!moof)
		return;

	for (k = 0; k < gf_list_count(moof->TrackList); k++) {
		GF_TrackFragmentBox *traf = gf_list_get(moof->TrackList, k);
		if (traf->sdtp) {
			GF_TrackFragmentRunBox *trun;
			u32 j = 0, sample_index = 0;

			if (traf->sdtp->sampleCount == gf_list_count(traf->TrackRuns)) {
				GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] Warning: TRAF box of track id=%u contains a SDTP. Converting to TRUN sample flags.\n", traf->tfhd->trackID));
			}

			while ((trun = (GF_TrackFragmentRunBox*)gf_list_enum(traf->TrackRuns, &j))) {
				u32 i = 0;
				GF_TrunEntry *entry;
				trun->flags |= GF_ISOM_TRUN_FLAGS;
				while ((entry = (GF_TrunEntry*)gf_list_enum(trun->entries, &i))) {
					const u8 info = traf->sdtp->sample_info[sample_index];
					entry->flags |= GF_ISOM_GET_FRAG_DEPEND_FLAGS(info >> 6, info >> 4, info >> 2, info);
					sample_index++;
					if (sample_index > traf->sdtp->sampleCount) {
						GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso file] Error: TRAF box of track id=%u contained an inconsistent SDTP.\n", traf->tfhd->trackID));
						return;
					}
				}
			}
			if (sample_index < traf->sdtp->sampleCount) {
				GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso file] Error: TRAF box of track id=%u list less samples than SDTP.\n", traf->tfhd->trackID));
			}
			gf_isom_box_del((GF_Box*)traf->sdtp);
			traf->sdtp = NULL;
		}
	}
Exemple #7
0
GF_Err gf_odf_delete_descriptor_list(GF_List *descList)
{
	GF_Err e;
	GF_Descriptor*tmp;
	u32 i;
	//no error if NULL chain...
	if (! descList) return GF_OK;
	i=0;
	while ((tmp = (GF_Descriptor*)gf_list_enum(descList, &i))) {
		e = gf_odf_delete_descriptor(tmp);
		if (e) return e;
	}
	gf_list_del(descList);
	return GF_OK;
}
Exemple #8
0
//same function, but for QoS, as a Qualifier IS NOT a descriptor
GF_EXPORT
GF_Err gf_odf_qos_add_qualif(GF_QoS_Descriptor *desc, GF_QoS_Default *qualif)
{
	u32 i;
	GF_QoS_Default *def;

	if (desc->tag != GF_ODF_QOS_TAG) return GF_BAD_PARAM;
	if (desc->predefined) return GF_ODF_FORBIDDEN_DESCRIPTOR;

	i=0;
	while ((def = (GF_QoS_Default *)gf_list_enum(desc->QoS_Qualifiers, &i))) {
		//if same Qualifier, not allowed...
		if (def->tag == qualif->tag) return GF_ODF_FORBIDDEN_DESCRIPTOR;
	}
	return gf_list_add(desc->QoS_Qualifiers, qualif);
}
Exemple #9
0
static Bool check_in_scene(GF_Scene *scene, GF_ObjectManager *odm)
{
    u32 i;
    GF_ObjectManager *ptr, *root;
    if (!scene) return 0;
    root = scene->root_od;
    if (odm == root) return 1;
    scene = root->subscene;

    i=0;
    while ((ptr = (GF_ObjectManager *)gf_list_enum(scene->resources, &i))) {
        if (ptr == odm) return 1;
        if (check_in_scene(ptr->subscene, odm)) return 1;
    }
    return 0;
}
Exemple #10
0
static GF_Err PNG_AttachStream(GF_BaseDecoder *ifcg, GF_ESD *esd)
{
	u32 i = 0;
	GF_Descriptor *d = NULL;
	PNGCTX();
	if (ctx->ES_ID && ctx->ES_ID!=esd->ESID) return GF_NOT_SUPPORTED;
	ctx->ES_ID = esd->ESID;

	while ((d = (GF_Descriptor*)gf_list_enum(esd->extensionDescriptors, &i))) {
		if (d->tag == GF_ODF_AUX_VIDEO_DATA) {
			ctx->aux_type = ((GF_AuxVideoDescriptor*)d)->aux_video_type;
			break;
		}
	}
	return GF_OK;
}
Exemple #11
0
GF_EXPORT
void gf_cfg_del_section(GF_Config *iniFile, const char *secName)
{
	u32 i;
	IniSection *p;
	if (!iniFile) return;

	i = 0;
	while ((p = gf_list_enum(iniFile->sections, &i))) {
		if (!strcmp(secName, p->section_name)) {
			DelSection(p);
			gf_list_rem(iniFile->sections, i-1);
			return;
		}
	}
}
Exemple #12
0
static void ttd_set_blink_fraction(GF_Node *node, GF_Route *route)
{
	M_Material2D *m;
	u32 i;
	TTDPriv *priv = (TTDPriv *)gf_node_get_private(node);

	Bool blink_on = 1;
	if (priv->process_blink->set_fraction>FIX_ONE/2) blink_on = 0;
	i=0;
	while ((m = (M_Material2D*)gf_list_enum(priv->blink_nodes, &i))) {
		if (m->filled != blink_on) {
			m->filled = blink_on;
			gf_node_changed((GF_Node *) m, NULL);
		}
	}
}
Exemple #13
0
GF_EXPORT
GF_Descriptor *gf_seng_get_iod(GF_SceneEngine *seng)
{
	u32 i=0;
	GF_Descriptor *out_iod = NULL;
	GF_StreamContext*sc = NULL;

	if (!seng->ctx->root_od) return NULL;
	while ((sc = (GF_StreamContext*)gf_list_enum(seng->ctx->streams, &i))) {
		if ((sc->streamType == GF_STREAM_SCENE) && (sc->objectType != GPAC_OTI_SCENE_DIMS))
			break;
	}
	if (!sc) return NULL;
	gf_odf_desc_copy((GF_Descriptor *)seng->ctx->root_od, &out_iod);
	return out_iod;
}
Exemple #14
0
GF_EXPORT
GF_Err gf_bifs_decoder_remove_stream(GF_BifsDecoder *codec, u16 ESID)
{
	u32 i;
	BIFSStreamInfo *ptr;

	i=0;
	while ((ptr = (BIFSStreamInfo*)gf_list_enum(codec->streamInfo, &i))) {
		if(ptr->ESID==ESID) {
			gf_free(ptr);
			gf_list_rem(codec->streamInfo, i-1);
			return GF_OK;
		}
	}
	return GF_BAD_PARAM;
}
Exemple #15
0
static void svg_text_area_shift_bounds(SVG_TextStack *st, GF_TraverseState *tr_state)
{
	u32 i=0;
	GF_TextSpan *span;
	/*finally compute text bounds*/
	st->bounds.width = st->bounds.height = 0;
	st->bounds.x = st->bounds.y = 0;
	while ( (span = (GF_TextSpan*)gf_list_enum(st->spans, &i)) ) {
		u32 j;
		for (j=0; j<span->nb_glyphs; j++)
			span->dy[j] += tr_state->base_shift;

		gf_font_manager_refresh_span_bounds(span);
		gf_rect_union(&st->bounds, &span->bounds);
	}
}
Exemple #16
0
void gf_term_set_priority(GF_Terminal *term, s32 Priority)
{
	u32 i;
	CodecEntry *ce;
	gf_mx_p(term->mm_mx);

	gf_th_set_priority(term->mm_thread, Priority);

	i=0;
	while ((ce = (CodecEntry*)gf_list_enum(term->codecs, &i))) {
		if (ce->flags & GF_MM_CE_THREADED)
			gf_th_set_priority(ce->thread, Priority);
	}
	term->priority = Priority;
	gf_mx_v(term->mm_mx);
}
Exemple #17
0
static void RP_FlushCommands(RTPClient *rtp)
{
	u32 i, nb_com;
	RTSPSession *sess;
	/*process teardown on all sessions*/
	while (1) {
		nb_com = 0;
		i=0;
		while ((sess = (RTSPSession *)gf_list_enum(rtp->sessions, &i))) {
			if (!sess->connect_error)
				nb_com += gf_list_count(sess->rtsp_commands);
		}
		if (!nb_com) break;
		gf_sleep(10);
	}
}
Exemple #18
0
GF_EXPORT
GF_Err gf_sm_make_random_access(GF_SceneManager *ctx)
{
	GF_Err e;
	u32 i, j, stream_count, au_count, com_count;
	GF_AUContext *au;
	GF_Command *com;

	e = GF_OK;
	stream_count = gf_list_count(ctx->streams);
	for (i=0; i<stream_count; i++) {
		GF_StreamContext *sc = (GF_StreamContext *)gf_list_get(ctx->streams, i);
		/*FIXME - do this as well for ODs*/
		if (sc->streamType == GF_STREAM_SCENE) {
			/*apply all commands - this will also apply the SceneReplace*/
			j=0;
			while ((au = (GF_AUContext *)gf_list_enum(sc->AUs, &j))) {
				e = gf_sg_command_apply_list(ctx->scene_graph, au->commands, 0);
				if (e) return e;
			}

			/* Delete all the commands in the stream */
			while ( (au_count = gf_list_count(sc->AUs)) ) {
				au = (GF_AUContext *)gf_list_get(sc->AUs, au_count-1);
				gf_list_rem(sc->AUs, au_count-1);
				while ( (com_count = gf_list_count(au->commands)) ) {
					com = (GF_Command*)gf_list_get(au->commands, com_count - 1);
					gf_list_rem(au->commands, com_count - 1);
					gf_sg_command_del(com);
				}
				gf_list_del(au->commands);
				free(au);
			}
			/*and recreate scene replace*/
			au = gf_sm_stream_au_new(sc, 0, 0, 1);
			com = gf_sg_command_new(ctx->scene_graph, GF_SG_SCENE_REPLACE);
			com->node = ctx->scene_graph->RootNode;
			ctx->scene_graph->RootNode = NULL;
			gf_list_del(com->new_proto_list);
			com->new_proto_list = ctx->scene_graph->protos;
			ctx->scene_graph->protos = NULL;
			/*FIXME - check routes & protos*/
			gf_list_add(au->commands, com);
		}
	}
	return e;
}
Exemple #19
0
static RTPChannel *set_broadcast_params(LiveSession *livesess, u16 esid, u32 period, u32 ts_delta, u16 aggregate_on_stream, Bool adjust_carousel_time, Bool force_rap, Bool aggregate_au, Bool discard_pending, Bool signal_rap, u32 signal_critical, Bool version_inc)
{
	RTPChannel *rtpch = NULL;

	/*locate our stream*/
	if (esid) {
		u32 i=0;
		while ( (rtpch = gf_list_enum(livesess->streams, &i))) {
			if (rtpch->ESID == esid) break;
		}
	} else {
		rtpch = gf_list_get(livesess->streams, 0);
	}

	/*TODO - set/reset the ESID for the parsers*/
	if (!rtpch) return NULL;

	/*TODO - if discard is set, abort current carousel*/
	if (discard_pending) {
	}

	/*remember RAP flag*/
	rtpch->rap = signal_rap;
	rtpch->critical = signal_critical;
	rtpch->m2ts_vers_inc = version_inc;

	rtpch->ts_delta = ts_delta;
	rtpch->aggregate = aggregate_au;
	rtpch->adjust_carousel_time = adjust_carousel_time;

	/*change stream aggregation mode*/
	if ((aggregate_on_stream != (u16)-1) && (rtpch->aggregate_on_stream != aggregate_on_stream)) {
		gf_seng_enable_aggregation(livesess->seng, esid, aggregate_on_stream);
		rtpch->aggregate_on_stream = aggregate_on_stream;
	}
	/*change stream aggregation mode*/
	if ((period!=(u32)-1) && (rtpch->carousel_period != period)) {
		rtpch->carousel_period = period;
		rtpch->last_carousel_time = 0;
	}

	if (force_rap) {
		livesess->force_carousel = 1;
	}
	return rtpch;
}
Exemple #20
0
//
//		Size
//
GF_Err gf_odf_size_qos(GF_QoS_Descriptor *qos, u32 *outSize)
{
	GF_Err e;
	u32 i;
	GF_QoS_Default *tmp;

	if (!qos) return GF_BAD_PARAM;
	
	*outSize = 1;
	
	i=0;
	while ((tmp = (GF_QoS_Default *)gf_list_enum(qos->QoS_Qualifiers, &i))) {
		e = gf_odf_size_qos_qual(tmp);
		if (e) return e;
		*outSize += tmp->size + gf_odf_size_field_size(tmp->size);
	}
	return GF_OK;
}
Exemple #21
0
GF_EXPORT
GF_Err gf_seng_get_stream_carousel_info(GF_SceneEngine *seng, u16 ESID, u32 *carousel_period, u16 *aggregate_on_es_id)
{
	u32 i=0;
    GF_StreamContext *sc;

	if (carousel_period) *carousel_period = (u32) -1;
	if (aggregate_on_es_id) *aggregate_on_es_id = 0;

	while (NULL != (sc = gf_list_enum(seng->ctx->streams, &i))) {
		if (sc->ESID==ESID) {
			if (carousel_period) *carousel_period = sc->carousel_period;
			if (aggregate_on_es_id) *aggregate_on_es_id = sc->aggregate_on_esid;
			return GF_OK;
		}
	}
    return GF_OK;
}
Exemple #22
0
GF_Err gf_isom_remove_meta_xml(GF_ISOFile *file, Bool root_meta, u32 track_num)
{
	u32 i;
	GF_Box *a;
	GF_MetaBox *meta = gf_isom_get_meta(file, root_meta, track_num);
	if (!meta) return GF_BAD_PARAM;
	i=0;
	while ((a = (GF_Box*)gf_list_enum(meta->other_boxes, &i))) {
		switch (a->type) {
		case GF_ISOM_BOX_TYPE_XML:
		case GF_ISOM_BOX_TYPE_BXML:
			gf_list_rem(meta->other_boxes, i-1);
			gf_isom_box_del(a);
			return GF_OK;
		}
	}
	return GF_OK;
}
Exemple #23
0
GF_Err Track_RemoveRef(GF_TrackBox *trak, u32 ReferenceType)
{
    GF_TrackReferenceBox *ref;
    GF_Box *a;
    u32 i;
    if (! trak) return GF_BAD_PARAM;
    if (! trak->References) return GF_OK;
    ref = trak->References;
    i=0;
    while ((a = (GF_Box *)gf_list_enum(ref->other_boxes, &i))) {
        if (a->type == ReferenceType) {
            gf_isom_box_del(a);
            gf_list_rem(ref->other_boxes, i-1);
            return GF_OK;
        }
    }
    return GF_OK;
}
Exemple #24
0
GF_EXPORT
GF_Err gf_seng_enable_aggregation(GF_SceneEngine *seng, u16 ESID, u16 onESID)
{
	GF_StreamContext *sc;

	if (ESID) {
		u32 i=0;
		while (NULL != (sc = (GF_StreamContext*)gf_list_enum(seng->ctx->streams, &i))) {
			if (0 != (sc->ESID==ESID)) break;
		}
	} else {
		sc = (GF_StreamContext*)gf_list_get(seng->ctx->streams, 0);
	}
	if (!sc) return GF_STREAM_NOT_FOUND;

	sc->aggregate_on_esid = onESID;
	return GF_OK;
}
Exemple #25
0
void Bindable_OnSetBind(GF_Node *bindable, GF_List *stack_list, GF_List *for_stack)
{
	u32 i;
	Bool on_top, is_bound, set_bind;
	GF_Node *node;
	GF_List *stack;

	set_bind = Bindable_GetSetBind(bindable);
	is_bound = Bindable_GetIsBound(bindable);

	if (!set_bind && !is_bound) return;
	if (set_bind && is_bound) return;

	i=0;
	while ((stack = (GF_List*)gf_list_enum(stack_list, &i))) {
		if (for_stack && (for_stack!=stack)) continue;

		on_top = (gf_list_get(stack, 0)==bindable) ? GF_TRUE : GF_FALSE;

		if (!set_bind) {
			if (is_bound) Bindable_SetIsBound(bindable, GF_FALSE);
			if (on_top && (gf_list_count(stack)>1)) {
				gf_list_rem(stack, 0);
				gf_list_add(stack, bindable);
				node = (GF_Node*)gf_list_get(stack, 0);
				Bindable_SetIsBound(node, GF_TRUE);
			}
		} else {
			if (!is_bound) Bindable_SetIsBound(bindable, GF_TRUE);
			if (!on_top) {
				/*push old top one down and unbind*/
				node = (GF_Node*)gf_list_get(stack, 0);
				Bindable_SetIsBound(node, GF_FALSE);
				/*insert new top*/
				gf_list_del_item(stack, bindable);
				gf_list_insert(stack, bindable, 0);
			}
		}
	}
	/*force invalidate of the bindable stack's owner*/
	gf_node_dirty_set(bindable, 0, GF_TRUE);
	/*and redraw scene*/
	gf_sc_invalidate(gf_sc_get_compositor(bindable), NULL);
}
Exemple #26
0
/*locate channel - if requested remove from session*/
RTPStream *RP_FindChannel(RTPClient *rtp, LPNETCHANNEL ch, u32 ES_ID, char *es_control, Bool remove_stream)
{
	u32 i=0;
	RTPStream *st;

	while ((st = (RTPStream *)gf_list_enum(rtp->channels, &i))) {
		if (ch && (st->channel==ch)) goto found;
		if (ES_ID && (st->ES_ID==ES_ID)) goto found;
		if (es_control && st->control) {
			char *ctrl_start = strstr(es_control, st->control);
			if (ctrl_start && !strcmp(ctrl_start, st->control)) goto found;
		}
	}
	return NULL;

found:
	if (remove_stream) gf_list_rem(rtp->channels, i-1);
	return st;
}
Exemple #27
0
static GF_Descriptor *SAF_GetServiceDesc(GF_InputService *plug, u32 expect_type, const char *sub_url)
{
	u32 i=0;
	SAFChannel *root;
	SAFIn *read = (SAFIn *)plug->priv;
	GF_ObjectDescriptor *od = (GF_ObjectDescriptor *) gf_odf_desc_new(GF_ODF_IOD_TAG);

	od->objectDescriptorID = 1;

	while ( (root = (SAFChannel *)gf_list_enum(read->channels, &i))) {
		if (root->esd && (root->esd->decoderConfig->streamType==GF_STREAM_SCENE)) break;
	}
	if (!root) return NULL;

	/*inline scene*/
	gf_list_add(od->ESDescriptors, root->esd);
	root->esd = NULL;
	return (GF_Descriptor *) od;
}
Exemple #28
0
GF_Err gf_odf_size_esd_update(GF_ESDUpdate *esdUp, u32 *outSize)
{
	u32 i, BitSize, tmpSize;
	GF_Descriptor *tmp;
	if (!esdUp) return GF_BAD_PARAM;

	*outSize = 0;
	BitSize = 10;
	i = 0;
	while ((tmp = (GF_Descriptor *)gf_list_enum(esdUp->ESDescriptors, &i))) {
		gf_odf_size_descriptor(tmp, &tmpSize);
		BitSize += (tmpSize + gf_odf_size_field_size(tmpSize)) * 8;
	}
	while ((s32)BitSize > 0) {
		BitSize -= 8;
		*outSize += 1;
	}
	return GF_OK;
}
Exemple #29
0
static void mpeg4_sensor_deleted(GF_Node *node, GF_SensorHandler *hdl)
{
	GF_Compositor *compositor = gf_sc_get_compositor(node);
	if (compositor) {
		GF_VisualManager *visual;
		u32 i=0;
		gf_list_del_item(compositor->sensors, hdl);
		gf_list_del_item(compositor->previous_sensors, hdl);
		if (compositor->interaction_sensors) compositor->interaction_sensors--;
		while ( (visual=gf_list_enum(compositor->visuals, &i)) ) {
			if (visual->offscreen)
				compositor_compositetexture_sensor_delete(visual->offscreen, hdl);
		}

#ifndef GPAC_DISABLE_SVG
		gf_sg_unregister_event_type(gf_node_get_graph(node), GF_DOM_EVENT_MOUSE|GF_DOM_EVENT_KEY);
#endif
	}
}
Exemple #30
0
GF_EXPORT
GF_Err gf_odf_codec_encode(GF_ODCodec *codec, u32 cleanup_type)
{
	GF_ODCom *com;
	GF_Err e = GF_OK;
	u32 i;

	if (!codec) return GF_BAD_PARAM;

	//check our bitstream: if existing, this means the previous encoded AU was not retrieved
	//we DON'T allow that
	if (codec->bs) return GF_BAD_PARAM;
	codec->bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
	if (!codec->bs) return GF_OUT_OF_MEM;

	/*encode each command*/
	i = 0;
	while ((com = (GF_ODCom *)gf_list_enum(codec->CommandList, &i))) {
		e = gf_odf_write_command(codec->bs, com);
		if (e) goto err_exit;
		//don't forget OD Commands are aligned...
		gf_bs_align(codec->bs);
	}

	//if an error occurs, delete the GF_BitStream and empty the codec
err_exit:
	if (e) {
		gf_bs_del(codec->bs);
		codec->bs = NULL;
	}
	if (cleanup_type == 1) {
		while (gf_list_count(codec->CommandList)) {
			com = (GF_ODCom *)gf_list_get(codec->CommandList, 0);
			gf_odf_delete_command(com);
			gf_list_rem(codec->CommandList, 0);
		}
	}
	if (cleanup_type == 0) {
		gf_list_reset(codec->CommandList);
	}
	return e;
}