static GF_Err writegen_flush_ttml(GF_GenDumpCtx *ctx)
{
	char *data;
	u8 *output;
	u32 size;
	GF_FilterPacket *pck;
	if (!ctx->ttml_root) return GF_OK;

	if (ctx->merge_region) {
		u32 i, count;
		GF_XMLNode *body_global = ttml_get_body(ctx->ttml_root);
		count = body_global ? gf_list_count(body_global->content) : 0;
		for (i=0; i<count; i++) {
			GF_XMLNode *child;
			GF_XMLNode *div = gf_list_get(body_global->content, i);
			if (div->type) continue;
			if (strcmp(div->name, "div")) continue;
			if (gf_list_count(div->content) > 1) continue;;

			child = gf_list_get(div->content, 0);
			if (child && !child->type) continue;;

			gf_list_rem(body_global->content, i);
			i--;
			count--;
			gf_xml_dom_node_del(div);
		}
	}

	data = gf_xml_dom_serialize_root(ctx->ttml_root, GF_FALSE, GF_FALSE);
	if (!data) return GF_OK;
	size = (u32) strlen(data);
	pck = gf_filter_pck_new_alloc(ctx->opid, size, &output);
	if (!pck) return GF_OUT_OF_MEM;

	memcpy(output, data, size);
	gf_free(data);

	if (ctx->ttml_dash_pck) {
		gf_filter_pck_merge_properties(ctx->ttml_dash_pck, pck);
		gf_filter_pck_set_byte_offset(pck, GF_FILTER_NO_BO);
		gf_filter_pck_set_dependency_flags(pck, 0);
		gf_filter_pck_unref(ctx->ttml_dash_pck);
		ctx->ttml_dash_pck = NULL;
	}
	gf_filter_pck_set_framing(pck, GF_TRUE, GF_TRUE);
	gf_xml_dom_node_del(ctx->ttml_root);
	ctx->ttml_root = NULL;
	return gf_filter_pck_send(pck);
}
static GF_Err writegen_flush_ttml(GF_GenDumpCtx *ctx)
{
	char *data;
	u8 *output;
	u32 size;
	GF_FilterPacket *pck;
	if (!ctx->ttml_root) return GF_OK;

	if (ctx->merge_region) {
		u32 i, count;
		GF_XMLNode *body_global = ttml_get_body(ctx->ttml_root);
		count = body_global ? gf_list_count(body_global->content) : 0;
		for (i=0; i<count; i++) {
			GF_XMLNode *child;
			GF_XMLNode *div = gf_list_get(body_global->content, i);
			if (div->type) continue;
			if (strcmp(div->name, "div")) continue;
			if (gf_list_count(div->content) > 1) continue;;

			child = gf_list_get(div->content, 0);
			if (child && !child->type) continue;;

			gf_list_rem(body_global->content, i);
			i--;
			count--;
			gf_xml_dom_node_del(div);
		}
	}

	data = gf_xml_dom_serialize_root(ctx->ttml_root, GF_FALSE, GF_FALSE);
	if (!data) return GF_OK;
	size = (u32) strlen(data);
	pck = gf_filter_pck_new_alloc(ctx->opid, size, &output);
	if (!pck) return GF_OUT_OF_MEM;

	memcpy(output, data, size);
	gf_free(data);

	if (ctx->ttml_dash_pck) {
		gf_filter_pck_merge_properties(ctx->ttml_dash_pck, pck);
		gf_filter_pck_set_byte_offset(pck, GF_FILTER_NO_BO);
		gf_filter_pck_set_dependency_flags(pck, 0);
		gf_filter_pck_unref(ctx->ttml_dash_pck);
		ctx->ttml_dash_pck = NULL;
	}
	gf_filter_pck_set_framing(pck, GF_TRUE, GF_TRUE);
	gf_xml_dom_node_del(ctx->ttml_root);
	ctx->ttml_root = NULL;
	return gf_filter_pck_send(pck);
}