Beispiel #1
0
static GF_Err IS_AttachStream(GF_BaseDecoder *plug, 
									 u16 ES_ID, 
									 char *decSpecInfo, 
									 u32 decSpecInfoSize, 
									 u16 DependsOnES_ID,
									 u32 objectTypeIndication, 
									 Bool Upstream)
{
	GF_BitStream *bs;
	u32 len, size, i;
	char devName[255];
	u16 termSeq[20];

	ISPriv *is = (ISPriv *)plug->privateStack;
	if (Upstream) return GF_NOT_SUPPORTED;
	if (!decSpecInfo) return GF_NON_COMPLIANT_BITSTREAM;

	/*no more than one UI stream per object*/
	if (is->ES_ID) return GF_NOT_SUPPORTED;
	is->ES_ID = ES_ID;
	/*parse config*/
	bs = gf_bs_new(decSpecInfo, decSpecInfoSize, GF_BITSTREAM_READ);
	len = gf_bs_read_int(bs, 8);
	for (i=0; i<len; i++) {
		devName[i] = gf_bs_read_int(bs, 8);
	}
	devName[i] = 0;
	size = len + 1;

	is->type = 0;
	if (!stricmp(devName, "KeySensor")) {
		is->type = IS_KeySensor;
		add_field(is, GF_SG_VRML_SFINT32, "keyPressed");
		add_field(is, GF_SG_VRML_SFINT32, "keyReleased");
		add_field(is, GF_SG_VRML_SFINT32, "actionKeyPressed");
		add_field(is, GF_SG_VRML_SFINT32, "actionKeyReleased");
		add_field(is, GF_SG_VRML_SFBOOL, "shiftKeyPressed");
		add_field(is, GF_SG_VRML_SFBOOL, "controlKeyPressed");
		add_field(is, GF_SG_VRML_SFBOOL, "altKeyPressed");

	} else if (!stricmp(devName, "StringSensor")) {
		is->type = IS_StringSensor;
		add_field(is, GF_SG_VRML_SFSTRING, "enteredText");
		add_field(is, GF_SG_VRML_SFSTRING, "finalText");

		is->termChar = '\r';
		is->delChar = '\b';

		/*get escape chars if any specified*/
		if (size<decSpecInfoSize) {
			const char *src = decSpecInfo + size;
			gf_utf8_mbstowcs(termSeq, decSpecInfoSize - size, &src);
			is->termChar = termSeq[0];
			is->delChar = termSeq[1];
		}
	} else if (!stricmp(devName, "Mouse")) {
		is->type = IS_Mouse;
		add_field(is, GF_SG_VRML_SFVEC2F, "position");
		add_field(is, GF_SG_VRML_SFBOOL, "leftButtonDown");
		add_field(is, GF_SG_VRML_SFBOOL, "middleButtonDown");
		add_field(is, GF_SG_VRML_SFBOOL, "rightButtonDown");
		add_field(is, GF_SG_VRML_SFFLOAT, "wheel");

#if GPAC_HTK_DEMO
	} else if (!stricmp(devName, "HTKSensor")) {
		FILE *f;
		u32 nb_word, nbPhone, c, j;
		char szPh[3];
		char szName[1024];
		char *szPath = gf_cfg_get_key(is->scene->root_od->term->user->config, "HTK", "HTKDirectory");
		if (!szPath) szPath = gf_cfg_get_key(is->scene->root_od->term->user->config, "General", "ModulesDirectory");
		strcpy(is->szHTKPath, szPath);
		if (szPath[strlen(szPath)-1] != GF_PATH_SEPARATOR) is->szHTKPath[strlen(szPath)] = GF_PATH_SEPARATOR;

		add_field(is, GF_SG_VRML_SFSTRING, "word");
		add_field(is, GF_SG_VRML_SFINT32, "wordIndex");
		add_field(is, GF_SG_VRML_SFFLOAT, "wordScore");
	
		if (!htk_num_users) {
			HTK_Init(is->szHTKPath);
			htk_num_users++;
		}
		
		sprintf(szName, "HTKD_%d", (u32) is);
		strcat(is->szHTKPath, szName);

		f = fopen(is->szHTKPath, "wt");
		szPh[2] = 0;
		nb_word = gf_bs_read_int(bs, 8);
		for (i=0; i<nb_word; i++) {
			nbPhone = gf_bs_read_int(bs, 8);
			while ((c=gf_bs_read_int(bs, 8))) fprintf(f, "%c", c);
			fprintf(f, " ");
			for (j=0; j<nbPhone; j++) {
				gf_bs_read_data(bs, szPh, 2);
				if (j) fprintf(f, " ");
				if (!stricmp(szPh, "vc")) fprintf(f, "vcl");
				else fprintf(f, "%s", szPh);
			}
			fprintf(f, "\n");
		}
		fprintf(f, "RIEN sp\nSENT-END [] endsil\nSENT-START [] inisil\n");
		fclose(f);
		is->type = IS_HTKSensor;

		StartHTK(is);
#endif
	
	}
	gf_bs_del(bs);
	return GF_OK;
}
Beispiel #2
0
static M4Err IS_AttachStream(BaseDecoder *plug, 
									 u16 ES_ID, 
									 unsigned char *decSpecInfo, 
									 u32 decSpecInfoSize, 
									 u16 DependsOnES_ID,
									 u32 objectTypeIndication, 
									 Bool Upstream)
{
	BitStream *bs;
	u32 len, size, i;
	char devName[255];
	s16 termSeq[20];

	ISPriv *is = plug->privateStack;
	if (Upstream) return M4NotSupported;
	if (!decSpecInfo) return M4NonCompliantBitStream;

	/*no more than one UI stream per object*/
	if (is->ES_ID) return M4NotSupported;
	is->ES_ID = ES_ID;
	/*parse config*/
	bs = NewBitStream(decSpecInfo, decSpecInfoSize, BS_READ);
	len = BS_ReadInt(bs, 8);
	for (i=0; i<len; i++) {
		devName[i] = BS_ReadInt(bs, 8);
	}
	devName[i] = 0;
	size = len + 1;

	is->type = 0;
	if (!stricmp(devName, "KeySensor")) {
		is->type = IS_KeySensor;
		add_field(is, FT_SFInt32, "keyPressed");
		add_field(is, FT_SFInt32, "keyReleased");
		add_field(is, FT_SFInt32, "actionKeyPressed");
		add_field(is, FT_SFInt32, "actionKeyReleased");
		add_field(is, FT_SFBool, "shiftKeyPressed");
		add_field(is, FT_SFBool, "controlKeyPressed");
		add_field(is, FT_SFBool, "altKeyPressed");

	} else if (!stricmp(devName, "StringSensor")) {
		is->type = IS_StringSensor;
		add_field(is, FT_SFString, "enteredText");
		add_field(is, FT_SFString, "finalText");

		is->termChar = '\r';
		is->delChar = '\b';

		/*get escape chars if any specified*/
		if (size<decSpecInfoSize) {
			const char *src = decSpecInfo + size;
			utf8_mbstowcs(termSeq, decSpecInfoSize - size, &src);
			is->termChar = termSeq[0];
			is->delChar = termSeq[1];
		}
	} else if (!stricmp(devName, "Mouse")) {
		is->type = IS_Mouse;
		add_field(is, FT_SFVec2f, "position");
		add_field(is, FT_SFBool, "leftButtonDown");
		add_field(is, FT_SFBool, "middleButtonDown");
		add_field(is, FT_SFBool, "rightButtonDown");
		add_field(is, FT_SFFloat, "wheel");

#if M4_HTK_DEMO
	} else if (!stricmp(devName, "HTKSensor")) {
		FILE *f;
		u32 nb_word, nbPhone, c, j;
		char szPh[3];
		char szName[1024];
		char *szPath = IF_GetKey(is->scene->root_od->term->user->config, "HTK", "HTKDirectory");
		if (!szPath) szPath = IF_GetKey(is->scene->root_od->term->user->config, "General", "PluginsDirectory");
		strcpy(is->szHTKPath, szPath);
		if (szPath[strlen(szPath)-1] != M4_PATH_SEPARATOR) is->szHTKPath[strlen(szPath)] = M4_PATH_SEPARATOR;

		add_field(is, FT_SFString, "word");
		add_field(is, FT_SFInt32, "wordIndex");
		add_field(is, FT_SFFloat, "wordScore");
	
		if (!htk_num_users) {
			fprintf(stdout, "loading HTK...");
			HTK_Init(is->szHTKPath);
			htk_num_users++;
			fprintf(stdout, "done\n");
		}
		
		sprintf(szName, "HTKD_%d", (u32) is);
		strcat(is->szHTKPath, szName);

		f = fopen(is->szHTKPath, "wt");
		szPh[2] = 0;
		nb_word = BS_ReadInt(bs, 8);
		for (i=0; i<nb_word; i++) {
			nbPhone = BS_ReadInt(bs, 8);
			while ((c=BS_ReadInt(bs, 8))) fprintf(f, "%c", c);
			fprintf(f, " ");
			for (j=0; j<nbPhone; j++) {
				BS_ReadData(bs, szPh, 2);
				if (j) fprintf(f, " ");
				if (!stricmp(szPh, "vc")) fprintf(f, "vcl");
				else fprintf(f, "%s", szPh);
			}
			fprintf(f, "\n");
		}
		fprintf(f, "RIEN sp\nSENT-END [] endsil\nSENT-START [] inisil\n");
		fclose(f);
		is->type = IS_HTKSensor;

		StartHTK(is);
#endif
	
	}
	DeleteBitStream(bs);
	return M4OK;
}