2021-01-28 14:12:16 +00:00
|
|
|
package com.radio.codec2talkie.protocol;
|
|
|
|
|
2021-02-06 16:08:33 +00:00
|
|
|
import android.content.Context;
|
|
|
|
|
2021-01-28 14:12:16 +00:00
|
|
|
import com.radio.codec2talkie.transport.Transport;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
public class Raw implements Protocol {
|
|
|
|
|
|
|
|
private final int RX_BUFFER_SIZE = 8192;
|
|
|
|
|
|
|
|
protected Transport _transport;
|
|
|
|
protected final byte[] _rxDataBuffer;
|
|
|
|
|
|
|
|
public Raw() {
|
|
|
|
_rxDataBuffer = new byte[RX_BUFFER_SIZE];
|
|
|
|
}
|
|
|
|
|
2021-02-06 16:08:33 +00:00
|
|
|
public void initialize(Transport transport, Context context) {
|
2021-01-28 14:12:16 +00:00
|
|
|
_transport = transport;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void send(byte [] frame) throws IOException {
|
|
|
|
_transport.write(Arrays.copyOf(frame, frame.length));
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean receive(Callback callback) throws IOException {
|
|
|
|
int bytesRead = _transport.read(_rxDataBuffer);
|
|
|
|
if (bytesRead > 0) {
|
2021-01-31 12:03:18 +00:00
|
|
|
callback.onReceiveAudioFrames(Arrays.copyOf(_rxDataBuffer, bytesRead));
|
2021-01-28 14:12:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void flush() {
|
|
|
|
}
|
|
|
|
}
|