codec2_talkie/codec2talkie/src/main/java/com/radio/codec2talkie/protocol/Raw.java

41 wiersze
988 B
Java
Czysty Zwykły widok Historia

2021-01-28 14:12:16 +00:00
package com.radio.codec2talkie.protocol;
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];
}
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) {
callback.onReceiveAudioFrames(Arrays.copyOf(_rxDataBuffer, bytesRead));
2021-01-28 14:12:16 +00:00
return true;
}
return false;
}
public void flush() {
}
}