<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 14, 2022, 2:35 AM Algarve Branqueira <<a href="mailto:branqueira@gmail.com">branqueira@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">In libav as in many frameworks, logging is understood to be a global, context free operation. Other than the implicit context of thread ID (which as you note isn't as useful when more threads are created) there is nothing to distinguish a log event made by one of your instances from a log event made by another.</div><div dir="auto"><br></div><div dir="auto">Your options as I know them (unless there's some secret inside libav I don't know about):</div><div dir="auto"><br></div><div dir="auto">1. Yes, use globals. Maybe have one singleton call from the Java side that sets up the logging hook, and store its env and jobj value for the logging callback. Within Java, you'll need to figure out what to do with those callbacks, but I don't know your requirements there.</div><div dir="auto"><br></div><div dir="auto">2. More complicated: Try to wrap thread creation in libav (I think there's a hook?) to copy thread local logging context into every thread. I don't really recommend this path.</div><div dir="auto"><br></div><div dir="auto">3. Also more complicated: Store various env/jobj pairs for every active object in some global structure on the C side, and try to figure out which one to "dispatch" to. I don't recommend this path either.</div><div dir="auto"><br></div><div dir="auto">I don't know the details of your application, but my advice would be to understand that logging is a stream of information that comes globally without attribution to any particular object or instance, and architect accordingly. That's not very helpful, I'm sorry!</div><div dir="auto"><br></div><div dir="auto">-- egnor</div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"></div>
</blockquote></div></div></div>