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;
|
2022-08-13 17:48:45 +00:00
|
|
|
import android.util.Log;
|
2021-02-06 16:08:33 +00:00
|
|
|
|
2022-07-18 17:17:40 +00:00
|
|
|
import com.radio.codec2talkie.protocol.message.TextMessage;
|
2022-07-02 09:12:07 +00:00
|
|
|
import com.radio.codec2talkie.protocol.position.Position;
|
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 {
|
2022-08-13 17:48:45 +00:00
|
|
|
private static final String TAG = Raw.class.getSimpleName();
|
2021-01-28 14:12:16 +00:00
|
|
|
|
2022-07-09 11:33:27 +00:00
|
|
|
private static final int RX_BUFFER_SIZE = 8192;
|
2021-01-28 14:12:16 +00:00
|
|
|
|
|
|
|
protected Transport _transport;
|
|
|
|
protected final byte[] _rxDataBuffer;
|
|
|
|
|
2022-07-03 09:05:00 +00:00
|
|
|
private ProtocolCallback _parentProtocolCallback;
|
2022-07-01 14:18:37 +00:00
|
|
|
|
2021-01-28 14:12:16 +00:00
|
|
|
public Raw() {
|
|
|
|
_rxDataBuffer = new byte[RX_BUFFER_SIZE];
|
|
|
|
}
|
|
|
|
|
2021-10-19 18:06:32 +00:00
|
|
|
@Override
|
2022-07-03 09:05:00 +00:00
|
|
|
public void initialize(Transport transport, Context context, ProtocolCallback protocolCallback) {
|
2021-01-28 14:12:16 +00:00
|
|
|
_transport = transport;
|
2022-07-03 09:05:00 +00:00
|
|
|
_parentProtocolCallback = protocolCallback;
|
2021-01-28 14:12:16 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 18:06:32 +00:00
|
|
|
@Override
|
2022-08-13 17:48:45 +00:00
|
|
|
public int getPcmAudioRecordBufferSize() {
|
|
|
|
Log.w(TAG, "getPcmAudioBufferSize() is not supported");
|
|
|
|
return -1;
|
2022-06-29 12:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-12-09 12:27:49 +00:00
|
|
|
public void sendCompressedAudio(String src, String dst, byte[] frame) throws IOException {
|
2021-01-28 14:12:16 +00:00
|
|
|
_transport.write(Arrays.copyOf(frame, frame.length));
|
|
|
|
}
|
|
|
|
|
2022-07-18 17:17:40 +00:00
|
|
|
@Override
|
|
|
|
public void sendTextMessage(TextMessage textMessage) throws IOException {
|
2022-08-13 17:48:45 +00:00
|
|
|
Log.w(TAG, "sendTextMessage() is not supported");
|
2022-07-18 17:17:40 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 12:16:05 +00:00
|
|
|
@Override
|
2023-12-09 12:27:49 +00:00
|
|
|
public void sendPcmAudio(String src, String dst, short[] pcmFrame) {
|
2022-08-13 17:48:45 +00:00
|
|
|
Log.w(TAG, "sendPcmAudio() is not supported");
|
2022-06-29 12:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 14:42:44 +00:00
|
|
|
@Override
|
2022-08-19 16:53:43 +00:00
|
|
|
public void sendData(String src, String dst, String path, byte[] dataPacket) throws IOException {
|
2022-06-24 14:42:44 +00:00
|
|
|
_transport.write(Arrays.copyOf(dataPacket, dataPacket.length));
|
|
|
|
}
|
|
|
|
|
2021-10-19 18:06:32 +00:00
|
|
|
@Override
|
2022-07-01 14:18:37 +00:00
|
|
|
public boolean receive() throws IOException {
|
2021-01-28 14:12:16 +00:00
|
|
|
int bytesRead = _transport.read(_rxDataBuffer);
|
|
|
|
if (bytesRead > 0) {
|
2023-12-09 12:27:49 +00:00
|
|
|
_parentProtocolCallback.onReceiveCompressedAudio(null, null, Arrays.copyOf(_rxDataBuffer, bytesRead));
|
2021-01-28 14:12:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:23:02 +00:00
|
|
|
@Override
|
2022-07-02 09:12:07 +00:00
|
|
|
public void sendPosition(Position position) {
|
2022-08-13 17:48:45 +00:00
|
|
|
Log.w(TAG, "sendPosition() is not supported");
|
2022-06-29 19:23:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 18:06:32 +00:00
|
|
|
@Override
|
2021-01-28 14:12:16 +00:00
|
|
|
public void flush() {
|
|
|
|
}
|
2021-10-19 18:06:32 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close() {
|
|
|
|
}
|
2021-01-28 14:12:16 +00:00
|
|
|
}
|