@@ -48,29 +48,32 @@ public boolean isInOrder(char newSeq)
4848 @ Override
4949 public short [] decode (@ Nullable AudioPacket decryptedPacket )
5050 {
51- if (opusDecoder == null )
52- throw new IllegalStateException ("Decoder is closed." );
53-
5451 int result ;
5552 ShortBuffer decoded = ShortBuffer .allocate (4096 );
56- if (decryptedPacket == null ) //Flag for packet-loss
57- {
58- result = Opus .INSTANCE .opus_decode (opusDecoder , null , 0 , decoded , OpusPacket .OPUS_FRAME_SIZE , 0 );
59- lastSeq = (char ) -1 ;
60- lastTimestamp = -1 ;
61- }
62- else
53+ synchronized (this )
6354 {
64- this .lastSeq = decryptedPacket .getSequence ();
65- this .lastTimestamp = decryptedPacket .getTimestamp ();
55+ if (opusDecoder == null )
56+ throw new IllegalStateException ("Decoder is closed." );
57+
58+ if (decryptedPacket == null ) //Flag for packet-loss
59+ {
60+ result = Opus .INSTANCE .opus_decode (opusDecoder , null , 0 , decoded , OpusPacket .OPUS_FRAME_SIZE , 0 );
61+ lastSeq = (char ) -1 ;
62+ lastTimestamp = -1 ;
63+ }
64+ else
65+ {
66+ this .lastSeq = decryptedPacket .getSequence ();
67+ this .lastTimestamp = decryptedPacket .getTimestamp ();
6668
67- ByteBuffer encodedAudio = decryptedPacket .getEncodedAudio ();
68- int length = encodedAudio .remaining ();
69- int offset = encodedAudio .arrayOffset () + encodedAudio .position ();
70- byte [] buf = new byte [length ];
71- byte [] data = encodedAudio .array ();
72- System .arraycopy (data , offset , buf , 0 , length );
73- result = Opus .INSTANCE .opus_decode (opusDecoder , buf , buf .length , decoded , OpusPacket .OPUS_FRAME_SIZE , 0 );
69+ ByteBuffer encodedAudio = decryptedPacket .getEncodedAudio ();
70+ int length = encodedAudio .remaining ();
71+ int offset = encodedAudio .arrayOffset () + encodedAudio .position ();
72+ byte [] buf = new byte [length ];
73+ byte [] data = encodedAudio .array ();
74+ System .arraycopy (data , offset , buf , 0 , length );
75+ result = Opus .INSTANCE .opus_decode (opusDecoder , buf , buf .length , decoded , OpusPacket .OPUS_FRAME_SIZE , 0 );
76+ }
7477 }
7578
7679 //If we get a result that is less than 0, then there was an error. Return null as a signifier.
0 commit comments