Log in

View Full Version : JMF/JNI wrapper for Avisynth - closing a file


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.

Bidoche
16th April 2005, 18:26
Originally posted by pawl
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. Why do you use id in the first place !?
Can't you carry around OpenVideo data wrapped inside an object.

pawl
2nd May 2005, 16:30
Originally posted by Bidoche
Why do you use id in the first place !?
Can't you carry around OpenVideo data wrapped inside an object.

Well I do now ;) I used an integer id at first because I knew nothing about jni.

Aside from fixing lackluster code, is that close all I should need to do? Any pitfalls with using avisynth like this that I don't know about?

thanks a bunch