[flac-dev] libFLAC JNA Issue

christophe.dumont at bnf.fr christophe.dumont at bnf.fr
Wed Nov 22 13:52:31 UTC 2017


Hello,

I hope this is the right place for this kind of question.

As developper, i'm actually writing java interface to use libFLAC with 
JNA, to reproduce "flac -t" function, needed to validate/unvalidate flac 
files before sending them in our preservation system.
.
Everything is working fine between java and libFLAC.so. Callback are 
called, C API is smart with void* client_data parameter, which is useful 
to keep custom structure.

My problem is : with JNA and libFLAC, I can't identify if error callback 
has been called, due to variable visibility restriction, because 
error_callback implementation in java cannot communicate with java main 
code (not without an ugly trick).
With native implementaiton of FLAC (decoder.c or other samples), 
client_data sent to FLAC__stream_decoder_init_file is updated by 
error_callback. But java keep initial reference of this parameter and java 
main code never see this update after this step.
Note : when error_callback is called, I update client_data sent in 
parameter, well received updated by native code stored in decoder 
variable.

The only thing is missing to me, is a function to return client_data from 
decoder.

This simple patch do the job for me :

StreamDecoder.h :
FLAC_API void *get_client_data_from_decoder(FLAC__StreamDecoder *decoder);

StreamDecoder.c :
void *get_client_data_from_decoder(FLAC__StreamDecoder *decoder) {
        return decoder->private_->client_data;
}

I finally can use this function after 
FLAC__stream_decoder_process_until_end_of_stream call to check client_data 
and assert no error happened.

My question / suggestion :
I would like to know if it could be insteresting to you (and us) to add 
this client_data return function in libFLAC ? Maybe some other developpers 
will have to use libFLAC with JNA, and continue to update the lib without 
having to patch it.


Thanks for your attention and for your great work with flac development,
Best regards,

--
Christophe Dumont
Bibliothèque nationale de France
DSI
Exposition  Paysages français – Une aventure photographique (1984 - 2017)  - du 24 octobre 2017 au 4 février 2018 - BnF - François-Mitterrand Avant d'imprimer, pensez à l'environnement. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xiph.org/pipermail/flac-dev/attachments/20171122/94330518/attachment.html>


More information about the flac-dev mailing list