[Libav-user] variable scope into callback av_log_set_callback and multi threading

Algarve Branqueira branqueira at gmail.com
Thu Mar 24 21:54:17 EET 2022


Just for info for people who don't know JNI.

When calling java code from c, it is mandatory to attach a java thread to
the c thread. When we attach a java thread from the c thread, it creates a
java thread and we specify a name for it.

So your first solution which consists in attaching the thread at the
beginning of the "wrapper_logger" method and detaching at the end of this
method works but I have to monitor if it is not too expensive for the JVM.
I've never been in this case, in general we attach to the creation of the
thread and we detach at the end

Otherwise your second solution is the most interesting if it is not
possible to execute code at the end.
the main thread is already attached because the caller is Java, then as you
say, you have to put the messages of the ffmpeg worker threads in a global
variable

Any idea is good to take, a community is made to share ideas, a bad idea
can lead to other good idea

Thanks very much

Le jeu. 24 mars 2022 à 20:32, Simon <staircase at sector-alpha.net> a écrit :

> Hi,
>
> Even if you aren't creating per-thread objects, java is when you register
> the thread. Two options I can see are:
> 1) tidy up before you return control - this would mean register the thread
> with java only while in your logging callback and unregister before
> returning.
> 2) Only log to java from a single thread and get the other threads to
> queue the log messages up in some global object.
>
> I expect my second option is actually the most practical. You can have a
> thread then runs as long as any task is running and just pulls log messages
> out of the queue and posts them to java.
>
> Hope that's helpful.
>
> Simon
>
> Sent from my Huawei Mobile_______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20220324/65eba0fa/attachment.htm>


More information about the Libav-user mailing list