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

82 wiersze
2.2 KiB
Java
Czysty Zwykły widok Historia

2021-01-28 14:12:16 +00:00
package com.radio.codec2talkie.protocol;
import android.content.Context;
2022-08-13 17:48:45 +00:00
import android.util.Log;
2022-07-18 17:17:40 +00:00
import com.radio.codec2talkie.protocol.message.TextMessage;
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];
}
@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
}
@Override
2022-08-13 17:48:45 +00:00
public int getPcmAudioRecordBufferSize() {
Log.w(TAG, "getPcmAudioBufferSize() is not supported");
return -1;
}
@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
}
@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");
}
@Override
public void sendData(String src, String dst, String path, byte[] dataPacket) throws IOException {
_transport.write(Arrays.copyOf(dataPacket, dataPacket.length));
}
@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
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
}
@Override
2021-01-28 14:12:16 +00:00
public void flush() {
}
@Override
public void close() {
}
2021-01-28 14:12:16 +00:00
}