-
Notifications
You must be signed in to change notification settings - Fork 49
/
android-mplayer.c
228 lines (197 loc) · 6.73 KB
/
android-mplayer.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
#include <stdio.h>
#include <string.h>
#include <jni.h>
#include <android/log.h>
#include "metadata.h"
#include <pthread.h>
//#include <tag_c.h>
static JNIEnv* JavaEnv = NULL;
static jclass JavaRendererClass = NULL;
static jclass JavaMplayerClass = NULL;
static jobject JavaRenderer = NULL;
static jobject JavaMplayer = NULL;
static jmethodID jnativeConfig = NULL;
static jmethodID jnativeAudio = NULL;
static jmethodID jnativeDeconfig = NULL;
static jmethodID jupdate = NULL;
static jmethodID jupdate1 = NULL;
static jmethodID jupdate_main = NULL;
static jmethodID jupdate_main_string = NULL;
static jmethodID jstop = NULL;
static jobject video;
pthread_t native_thread;
const jbyte *str;
char* command = NULL;
static JavaVM *jniVM=NULL;
int arm_vfp=0;
int arm_neon=0;
static int w1,h1;
jobject temp;
int i,x;
void update_main_string(uint8_t *name){
jstring jstr;
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
jstr=(*JavaEnv)->NewStringUTF(JavaEnv,name);
(*JavaEnv)->CallVoidMethod( JavaEnv,JavaMplayer, jupdate_main_string,jstr);
(*JavaEnv)->DeleteLocalRef(JavaEnv,jstr);
}
void main_init(uint8_t *src[]){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
temp=(*JavaEnv)->NewDirectByteBuffer(JavaEnv,src[0],w1*h1*2);
video=(jobject)(*JavaEnv)->NewGlobalRef(JavaEnv,temp);
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, jupdate,video);
}
void main_flip(){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, jupdate1);
}
void main_stop(int code){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaMplayer, jstop,code);
}
void main_ao_init(){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaMplayer, jnativeAudio);
}
void update(int percent,int current,int total,int pause){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaMplayer, jupdate_main,percent,current,total,pause);
}
JNIEXPORT void JNICALL Java_com_vnd_mplayer_PlasmaView_init(JNIEnv *env, jobject obj,jint delay)
{
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
JavaEnv = env;
JavaRenderer = obj;
JavaRendererClass = (*JavaEnv)->GetObjectClass(JavaEnv, obj);
jnativeConfig = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "jnativeConfig", "(II)I");
jnativeDeconfig = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "jnativeDeconfig", "()V");
jupdate = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "update", "(Ljava/nio/ByteBuffer;)V");
jupdate1 = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "update1", "()V");
}
JNIEXPORT void JNICALL Java_com_vnd_mplayer_MPlayer_nativeExit(JNIEnv *env, jobject obj)
{
//__android_log_print(ANDROID_LOG_ERROR,"MPlayer","stop called");
run_command_android("stop");
}
JNIEXPORT void JNICALL Java_com_vnd_mplayer_MPlayer_play(JNIEnv *env, jobject obj,jstring fname,int cpuflags){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
JavaMplayer = obj;
JavaMplayerClass = (*JavaEnv)->GetObjectClass(JavaEnv, obj);
jnativeAudio = (*JavaEnv)->GetMethodID(JavaEnv, JavaMplayerClass, "jnativeAudio", "()V");
jstop = (*JavaEnv)->GetMethodID(JavaEnv, JavaMplayerClass, "stop", "(I)V");
jupdate_main = (*JavaEnv)->GetMethodID(JavaEnv, JavaMplayerClass, "update_main", "(IIII)V");
jupdate_main_string = (*JavaEnv)->GetMethodID(JavaEnv, JavaMplayerClass, "update_main_string", "(Ljava/lang/String;)V");
if (cpuflags==1)
arm_vfp=1;
if (cpuflags==2)
arm_neon=1;
if (cpuflags==3){
arm_vfp=1;arm_neon=1;}
str = (*JavaEnv)->GetStringUTFChars(JavaEnv, fname, NULL);
char *temp;
temp=malloc(255);
if ((strstr(str,".m3u")!=NULL) || (strstr(str,".pls")!=NULL))
strcpy(temp,"loadlist \"");
else
strcpy(temp,"loadfile \"");
strcat(temp,str);
strcat(temp,"\"");
run_command_android(temp);
free(temp);
}
JNIEXPORT void JNICALL Java_com_vnd_mplayer_MPlayer_nativeCommand(JNIEnv *env, jobject obj,jint command,jint x,jint y)
{
switch (command){
case 1: //Pause
if (x==0 && isPaused()==1)
run_command_android("pause");
if (x==1 && isPaused()==0)
run_command_android("pause");
if (x==2)
run_command_android("pause");
break;
case 2: //Seek
command=(void *)malloc(20);
sprintf((void *)command,"seek %d 1",x);
run_command_android(command);
free((void *)command);
break;
case 3:
if (x==1)
run_command_android("osd 3");
else
run_command_android("osd 0");
break;
case 4:
if (x==1)
run_command_android("pt_step 1 1");
else
run_command_android("pt_step -1 1");
break;
}
}
JNIEXPORT jint JNICALL Java_com_vnd_mplayer_MPlayer_ispaused(JNIEnv *env, jobject obj){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
return isPaused();
}
int nativeConfig(int w,int h){
//mp_msg(MSGT_CPLAYER,MSGL_ERR,"nativeConfig called %d %d",w,h);
w1=w;
h1=h;
i=0;
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
return((*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, jnativeConfig,w,h ));
}
void nativeDeconfig(){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
(*JavaEnv)->DeleteGlobalRef(JavaEnv,video);
(*JavaEnv)->CallVoidMethod (JavaEnv, JavaRenderer, jnativeDeconfig);
}
JNIEXPORT int JNICALL Java_com_vnd_mplayer_MPlayer_nativeTouch(JNIEnv *env, jobject thiz,jfloat x,jfloat y) {
if (x==0)
run_command_android("seek +1");
else
run_command_android("seek -1");
}
//JNIEXPORT int JNICALL Java_com_vnd_mplayer_MPlayer_main(JNIEnv *env, jclass cls) {
void mainp(void){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
int argc=10;char *argv[] ={ "mplayer","-idle","-slave","-osdlevel","0","-vf","format=bgr16","-noaspect","-nocorrect-pts","-quiet"};
main(argc,argv);
}
JNIEXPORT int JNICALL Java_com_vnd_mplayer_MPlayer_quit(JNIEnv *env, jclass cls) {
run_command_android("quit");
}
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
{
jniVM = vm;
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
pthread_create(&native_thread,NULL,mainp,NULL);
return JNI_VERSION_1_2;
};
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
{
jniVM = vm;
run_command_android("quit");
pthread_exit(&native_thread);
};
void run_command_android(char *command){
mp_input_queue_cmd(mp_input_parse_cmd(command));
}
JNIEXPORT int JNICALL Java_com_vnd_mplayer_MPlayer_isalbum(JNIEnv *env, jobject obj,jstring fname,jstring outfile){
(*jniVM)->AttachCurrentThread(jniVM, &JavaEnv, NULL);
const char *str,*fileout;
str = (*env)->GetStringUTFChars(env,fname, NULL);
fileout = (*env)->GetStringUTFChars(env,outfile, NULL);
if (isalbum(str,fileout)){
(*env)->ReleaseStringUTFChars(env, fname, str);
(*env)->ReleaseStringUTFChars(env, outfile, fileout);
return 1;
}
(*env)->ReleaseStringUTFChars(env, fname, str);
(*env)->ReleaseStringUTFChars(env, outfile, fileout);
return 0;
}
int have_neon(){
return arm_neon;
}