[sip-comm-dev] Probable wrong port from C / C++ to Java in low-level codec code


#1

To all our codec gurus,

during the process of removing warnings I stumbled over a
possible problem:

package "net.java.sip.communicator.impl.media.codec.audio.ilbc.*"

The problem is a misunderstanding of the differences of char and byte
between C and Java. A char in Java holds a UTF-8 character not only a
single byte as in C. Looking at several places in the ilbc classes
this misunderstanding is evident, look at ilbc_decoder.java,
ilbc_encoder.java, bitstream.java in the mentioned package.

bitstream.java:
This class defines a char[] buffer array at line 18 and initializes it
at line 36. However, the buffer is used in a manner that indicates that
it shall be a byte[] buffer. See also comments at lines 85ff and usage
of the buffer at lines 163ff (as examples) .

ilbc_decoder.java, look at the following code snippet (for example):

    public short decode( /* (o) Number of decoded samples */
       short decoded_data[], /* (o) Decoded signal block*/
       short encoded_data[], /* (i) Encoded bytes */
       short mode) /* (i) 0=PL, 1=Normal */
    {
       int k;
       float decblock [] = new float[ilbc_constants.BLOCKL_MAX];
       float dtmp;
       // char en_data[] = new char [this.ULP_inst.no_of_bytes];
       bitstream en_data = new bitstream(this.ULP_inst.no_of_bytes);

       /* check if mode is valid */

       if ( (mode < 0) || (mode > 1)) {
           System.out.println("\nERROR - Wrong mode - 0, 1 allowed\n");
       }

       /* do actual decoding of block */
       for (k = 0; k < encoded_data.length; k++) {
     en_data.buffer[2*k+1] = (char) (encoded_data[k] & 0xff); //!!!!
     en_data.buffer[2*k] = (char) ((encoded_data[k] >> 8) & 0xff); //!!!!
// System.out.println("on decode " + (en_data.buffer[2*k]+0) + " et " + (en_data.buffer[2*k+1]+0));
       }
see at the lines marked with // !!!! to see what I mean. This is a typical C code,
not Java. IMHO the code shall use byte[] instead of char[]. I don't know if usage of
char instead of byte causes real problems during runtime (decoding/encoding).

Regards,
Werner

···

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net