pawl
15th April 2005, 01:11
Hello! I'm writting a JMF demultiplexer that uses a jni interface to Avisynth, and I'm stuck on the last little bit(close).
from the c++ side(jni dll), it looks something like this:
struct OpenVideo{
IScriptEnvironment* env;
PClip clip;
}
OpenVideo open_videos[MAX_FILES];
//returns id for video, multiple instances share jni lib
jint open(filename){
id = find_open_id()
open_videos[id].env = CreateScriptEnvironment();
open_videos[id].clip = env->Invoke("Import", filename).AsClip();
return id;
}
jint readframe(jint id, jint frame_num, jbytearray frame_buffer){
PVideoFrame frame = open_videos[id].clip->GetFrame(frame_num, open_videos[id].env);
memcpy(frame_buffer, frame->GetReadPtr());
}
jint close(jint id){
??what can I legally do here??
open_videos[id].clip = 0;
delete open_videos[id].env;
}
I've tried counting open files, and calling FreeLibrary(avisynth) if on close the number open is 0, then calling LoadLibrary("avisynth.dll") only on first file open. This causes exceptions in the jvm. Actually doing almost anything on close has caused jvm exceptions. I tried calling the PClip destructor directly, as well as deleting the env, but no luck.
I know ScriptEnvs and PClips aren't meant to work as globals, but as a dll I'm not sure what else I can do.
from the c++ side(jni dll), it looks something like this:
struct OpenVideo{
IScriptEnvironment* env;
PClip clip;
}
OpenVideo open_videos[MAX_FILES];
//returns id for video, multiple instances share jni lib
jint open(filename){
id = find_open_id()
open_videos[id].env = CreateScriptEnvironment();
open_videos[id].clip = env->Invoke("Import", filename).AsClip();
return id;
}
jint readframe(jint id, jint frame_num, jbytearray frame_buffer){
PVideoFrame frame = open_videos[id].clip->GetFrame(frame_num, open_videos[id].env);
memcpy(frame_buffer, frame->GetReadPtr());
}
jint close(jint id){
??what can I legally do here??
open_videos[id].clip = 0;
delete open_videos[id].env;
}
I've tried counting open files, and calling FreeLibrary(avisynth) if on close the number open is 0, then calling LoadLibrary("avisynth.dll") only on first file open. This causes exceptions in the jvm. Actually doing almost anything on close has caused jvm exceptions. I tried calling the PClip destructor directly, as well as deleting the env, but no luck.
I know ScriptEnvs and PClips aren't meant to work as globals, but as a dll I'm not sure what else I can do.