<div dir="ltr">Hello,<br><br>I describe my application quickly before talking about my problem.<br><br>For more than a year, my application has been running very well for a client.<br>It is a web application which displays on an html page with different cameras.<br>It is a Java application that makes a JNI call for each camera.<br>The C code connects using the rtsp protocol to the different cameras and the ffmpeg library converts the rtsp stream to mpeg1.<br>The mpeg1 data is uploaded on the Java side and then various things are done to  use a JavaScript library to display the video.<br><br>This works perfectly and the instance has been running on a raspberry for over a year.<br><br>Now I would like to activate multi-threading on decoding and encoding, it works well except when I want to use my own logger.<br><br>Let me explain.<br><br>In my code, I use:<br><br>            <i>av_log_set_callback</i><br><br>This allows me to retrieve messages from the ffmpeg to java side with log4j.<br>So far no problem.<br>But if we take the doc, we see this:<br><br>           The callback must be thread safe, even if the application does not use threads itself as some codecs are multithreaded.<br><br>Unfortunately in the callback code, I use JNI methods, for example:<br><br>            <i> (*jniEnv)->CallVoidMethod(jniEnv, jobj, callLoggerMethod, level, jstr);</i><br><br>I explain little for those who don't know JNI (I'm on ffmpeg forum and not Java :))<br>To call this method, I must already have the following 2 objects jniEnv and jobj.<br>These 2 variables are obtained at the time of the input call in c, example:<br><br>               <i>JNIEXPORT void JNICALL Java_ffmpeg_RTSPToMPEG1_rtspToFfmpeg0 (JNIEnv *env, jobject obj)</i><br><br>It is in this method that all processing for decoding and encoding video.<br><br>The difficulty is that the callback signature of the logger is as follows:<br><br>              <i>  void wrapper_logger(void *ptr, int level, const char* fmt, va_list vl)</i><br><br>I therefore no longer have the JNIEnv *env variable (this is not a problem because i can recover it otherwise) but it is above all that I no longer have the obj variable.<br><br>For the moment in mono thread on the decoding and the encoding, I kept it in a variable thread local storage, example:<br><br>                   <i>__thread JNIEnv *jniEnv;<br>                   __thread jobject jobj;<br><br>                   JNIEXPORT void JNICALL Java_fr_ms_ffmpeg_RTSPToMPEG1_rtspToFfmpeg0 (JNIEnv *env, jobject obj) {<br>                            jniEnv = env;<br>                            jobj = obj;<br>                            ...<br><br>                           etc..</i><br><br>And like that I use the 2 variables without problems.<br><br><br>Of course someone can tell me why I am not using a global variable but that is not possible, there is not only one call to the method "Java_fr_ms_ffmpeg_RTSPToMPEG1_rtspToFfmpeg0"<br><br>But x calls for x cameras in the same instance.<br><br><br>So my question is this,<br><br>How can I in the callback method (for me wrapper_logger) retrieve the "jobj" variable (make it any variable of the main method) when the decoder or the encoder is in another thread?<br>I hope I explained my problem well.<br><br>Thanks,<br></div>