Hi, the demonstration is a good place to start, he was very close to solving it. However, each packet must be sent separately from the encoder to the decoder. Instead of saving everything to a file and then reading them without any relation to running the package.
I changed the code to also record the number of bytes encoded, and when I decode, I first read the number of bytes in each packet, and then the payload.
Here is the modified code in OpusEncoder.java
public void write( short[] buffer ) throws IOException { byte[] encodedBuffer = new byte[buffer.length]; int lenEncodedBytes = this.nativeEncodeBytes( buffer , encodedBuffer); Log.i(TAG,"encoded "+lenEncodedBytes+" bytes"); if (lenEncodedBytes > 0) { this.out.write(lenEncodedBytes); this.out.write( encodedBuffer, 0, lenEncodedBytes ); } else { Log.e( TAG, "Error during Encoding. Error Code: " + lenEncodedBytes); throw new IOException( "Error during Encoding. Error Code: " + lenEncodedBytes ); } }
Here is the modified code in OpusDecoder.java
byte[] encodedBuffer; int bytesEncoded=this.in.read(); int bytesDecoded=0; Log.d( TAG, bytesEncoded + " bytes read from input stream" ); if ( bytesEncoded >= 0 ) { encodedBuffer=new byte[bytesEncoded]; int bytesRead = this.in.read( encodedBuffer ); bytesDecoded = nativeDecodeBytes( encodedBuffer , buffer); Log.d( TAG, bytesEncoded + " bytes decoded" ); }
source share