1 /*
2  *			GPAC - Multimedia Framework C SDK
3  *
4  *			Authors: Jean Le Feuvre
5  *			Copyright (c) Telecom ParisTech 2009-2012
6  *					All rights reserved
7  *
8  *  This file is part of GPAC / Dummy input module
9  *
10  *  GPAC is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU Lesser General Public License as published by
12  *  the Free Software Foundation; either version 2, or (at your option)
13  *  any later version.
14  *
15  *  GPAC is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Lesser General Public
21  *  License along with this library; see the file COPYING.  If not, write to
22  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  */
25 
26 
27 #include <gpac/modules/codec.h>
28 #include <gpac/scenegraph_vrml.h>
29 
DEV_RegisterDevice(struct __input_device * ifce,const char * urn,const char * dsi,u32 dsi_size,void (* AddField)(struct __input_device * _this,u32 fieldType,const char * name))30 static Bool DEV_RegisterDevice(struct __input_device *ifce, const char *urn, const char *dsi, u32 dsi_size, void (*AddField)(struct __input_device *_this, u32 fieldType, const char *name))
31 {
32 	if (strcmp(urn, "DemoSensor")) return 0;
33 
34 	AddField(ifce, GF_SG_VRML_SFSTRING, "content");
35 
36 	return 1;
37 }
38 
DEV_Start(struct __input_device * ifce)39 static void DEV_Start(struct __input_device *ifce)
40 {
41 	GF_BitStream *bs;
42 	char *buf, *szWord;
43 	u32 len, val, i, buf_size;
44 
45 	szWord = "Hello InputSensor!";
46 
47 	bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
48 	/*HTK sensor buffer format: SFString - SFInt32 - SFFloat*/
49 	gf_bs_write_int(bs, 1, 1);
50 	len = strlen(szWord);
51 	val = gf_get_bit_size(len);
52 	gf_bs_write_int(bs, val, 5);
53 	gf_bs_write_int(bs, len, val);
54 	for (i=0; i<len; i++) gf_bs_write_int(bs, szWord[i], 8);
55 
56 	gf_bs_align(bs);
57 	gf_bs_get_content(bs, &buf, &buf_size);
58 	gf_bs_del(bs);
59 
60 	ifce->DispatchFrame(ifce, buf, buf_size);
61 	gf_free(buf);
62 }
63 
DEV_Stop(struct __input_device * ifce)64 static void DEV_Stop(struct __input_device *ifce)
65 {
66 }
67 
68 
69 GPAC_MODULE_EXPORT
QueryInterfaces()70 const u32 *QueryInterfaces()
71 {
72 	static u32 si [] = {
73 		GF_INPUT_DEVICE_INTERFACE,
74 		0
75 	};
76 	return si;
77 }
78 
79 GPAC_MODULE_EXPORT
LoadInterface(u32 InterfaceType)80 GF_BaseInterface *LoadInterface(u32 InterfaceType)
81 {
82 	GF_InputSensorDevice *plug;
83 	if (InterfaceType != GF_INPUT_DEVICE_INTERFACE) return NULL;
84 
85 	GF_SAFEALLOC(plug, GF_InputSensorDevice);
86 	GF_REGISTER_MODULE_INTERFACE(plug, GF_INPUT_DEVICE_INTERFACE, "GPAC Demo InputSensor", "gpac distribution")
87 
88 	plug->RegisterDevice = DEV_RegisterDevice;
89 	plug->Start = DEV_Start;
90 	plug->Stop = DEV_Stop;
91 
92 	return (GF_BaseInterface *)plug;
93 }
94 
95 GPAC_MODULE_EXPORT
ShutdownInterface(GF_BaseInterface * bi)96 void ShutdownInterface(GF_BaseInterface *bi)
97 {
98 	GF_InputSensorDevice *ifcn = (GF_InputSensorDevice*)bi;
99 	if (ifcn->InterfaceType==GF_INPUT_DEVICE_INTERFACE) {
100 		gf_free(bi);
101 	}
102 }
103 
104 GPAC_MODULE_STATIC_DECLARATION( demo_is )
105