-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp-android.c
293 lines (235 loc) · 6.07 KB
/
app-android.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
Copyright(C) 2011 MotionPortrait, Inc. All Rights Reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it.
*/
#include <jni.h>
#include <sys/time.h>
#include <time.h>
#include <android/log.h>
#include <stdint.h>
#include "Base64Transcoder.h"
#include "app.h"
// seigo3
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
int gAppAlive = 1;
int gWindowWidth = 512;
int gWindowHeight = 512;
float gTouchX;
float gTouchY;
static long sTimeOffset = 0;
static int sTimeOffsetInit = 0;
static long sTimeStopped = 0;
// seigo3
static int sVoiceFd = -1;
static long
_getTime(void)
{
struct timeval now;
gettimeofday(&now, NULL);
return (long)(now.tv_sec*1000 + now.tv_usec/1000);
}
/* Call to initialize the graphics state */
void
Java_de_gui_avatar_DemoRenderer_nativeInit( JNIEnv* env )
{
appInit();
gAppAlive = 1;
sTimeOffsetInit = 0;
}
void
Java_de_gui_avatar_DemoRenderer_nativeResize( JNIEnv* env, jobject thiz, jint w, jint h )
{
gWindowWidth = w;
gWindowHeight = h;
}
/* Call to finalize the graphics state */
void
Java_de_gui_avatar_DemoRenderer_nativeDone( JNIEnv* env )
{
appDeinit();
}
/* seigo : for SurfaceView scale animation */
void
Java_de_gui_avatar_DemoRenderer_nativeAnimateScreenSize( JNIEnv* env, jobject thiz, jfloat jscale )
{
appScale(jscale);
}
jint
Java_de_gui_avatar_DemoRenderer_nativeLipSynchUri( JNIEnv* env, jobject thiz, jstring uri )
{
int ret = 0;
// convert Java string to UTF-8
const jbyte *utf8 = (*env)->GetStringUTFChars(env, uri, NULL);
char path[128];
sprintf(path, "%s", utf8);
__android_log_print(ANDROID_LOG_INFO, "GuideNative", "Loading lip sync: %s", path);
speakWav(path);
(*env)->ReleaseStringUTFChars(env, uri, utf8);
return ret;
}
jint
Java_de_gui_avatar_DemoRenderer_nativeLipSynchStart( JNIEnv* env, jobject thiz )
{
int ret = 0;
__android_log_print(ANDROID_LOG_INFO, "GuideNative", "Starting lip sync...");
appAction("Speech");
return ret;
}
/* This is called to indicate to the render loop that it should
* stop as soon as possible.
*/
void
Java_de_gui_avatar_AvatarView_nativeTouch( JNIEnv* env, jobject thiz, jfloat x, jfloat y )
{
gTouchX = x;
gTouchY = y;
appTouch() ;
}
void
Java_de_gui_avatar_AvatarView_nativeTouchMove( JNIEnv* env, jobject thiz, jfloat x, jfloat y )
{
gTouchX = x;
gTouchY = y;
appTouchMove() ;
}
void
Java_de_gui_avatar_AvatarView_nativeTouchFinish( JNIEnv* env )
{
appTouchFinish() ;
}
/* Call to render the next GL frame */
void
Java_de_gui_avatar_DemoRenderer_nativeRender( JNIEnv* env )
{
long curTime;
curTime = _getTime() + sTimeOffset;
if (sTimeOffsetInit == 0) {
sTimeOffsetInit = 1;
sTimeOffset = -curTime;
curTime = 0;
}
appRender(curTime, gWindowWidth, gWindowHeight);
}
void
Java_de_gui_avatar_AvatarView_nativeOnClick( JNIEnv* env, jobject thiz, jstring button )
{
const char *action = (*env)->GetStringUTFChars(env, button, NULL);
appAction( action );
(*env)->ReleaseStringUTFChars(env, button, action);
}
jbyteArray Java_de_gui_avatar_Avatar_decodeString( JNIEnv* env,
jobject thiz ,
jstring inStr)
{
jboolean jbool;
bool bRet;
jbyteArray result;
const char *cpStr;
int len;
int outLen;
jbyte* bpOutData;
jbyte* dst;
int i;
cpStr= (*env)->GetStringUTFChars(env, inStr, NULL);;
if (cpStr == NULL) return NULL;
len = (int)(*env)->GetStringUTFLength(env, inStr);
outLen=(int) EstimateBas64DecodedDataSize(len);
bpOutData=calloc(1,outLen);
if(bpOutData!=NULL)
{
bRet=Base64DecodeData(cpStr, len, bpOutData, &outLen);
if(bRet==false)
{
result=NULL;
}
else
{
result= (*env)->NewByteArray(env, outLen);
if (result == NULL) {
(*env)->ReleaseStringUTFChars(env, inStr, cpStr);
free(bpOutData);
return NULL;
}
dst = (*env)->GetByteArrayElements(env, result, NULL);
if (dst == NULL) {
(*env)->ReleaseStringUTFChars(env, inStr, cpStr);
free(bpOutData);
return NULL;
}
for(i = 0; i < outLen; i++){
dst[i] = bpOutData[i];
}
(*env)->ReleaseByteArrayElements(env, result, dst, 0);
}
free(bpOutData);
}
else
{
}
(*env)->ReleaseStringUTFChars(env, inStr, cpStr);
return result;
}
// encode to base64
jstring Java_de_gui_avatar_Avatar_encodeData( JNIEnv* env,
jobject thiz ,
jbyteArray inStr)
{
jbyte * bpStr;
jboolean b;
jstring jsRet;
int len;
int outLen;
bool bRet;
char * cpOutStr;
bpStr=(*env)->GetByteArrayElements(env, inStr, &b);
len = (int)(*env)->GetArrayLength(env,inStr);
outLen=(int)EstimateBas64EncodedDataSize(len);
cpOutStr=calloc(1,outLen+1);
if(cpOutStr==NULL)
{
jsRet=(*env)->NewStringUTF(env, "");
}
else
{
// encode
bRet=Base64EncodeData(bpStr,len, cpOutStr, &outLen);
if(bRet==true)
{
jsRet=(*env)->NewStringUTF(env, cpOutStr);
}else
{
jsRet=(*env)->NewStringUTF(env, "");
}
free(cpOutStr);
}
(*env)->ReleaseByteArrayElements(env, inStr, bpStr,0);
return jsRet;
}
void
Java_de_gui_avatar_DemoRenderer_nativeLoadFaceNumber(JNIEnv* env, jobject thiz, jint x)
{
loadFaces(x);
}
jint Java_de_gui_avatar_AvatarView_setFaceInfo( JNIEnv* env,
jobject thiz ,
jstring newStr)
{
int ret;
const char *src;
src = (*env)->GetStringUTFChars(env, newStr, NULL);
if (src == NULL){
return -1;
}
ret=setFaceInfo(src);
(*env)->ReleaseStringUTFChars(env, newStr, src);
return ret;
}