kopia lustrzana https://github.com/sh123/codec2_talkie
Refactor send interface to supply src and dst callsigns
rodzic
9a467962c6
commit
ac99442ba3
|
@ -229,7 +229,7 @@ public class AudioProcessor extends Thread {
|
|||
for (int i = 0; i < _recordAudioEncodedBuffer.length; i++) {
|
||||
frame[i] = (byte)_recordAudioEncodedBuffer[i];
|
||||
}
|
||||
_protocol.sendAudio(frame);
|
||||
_protocol.sendAudio(null, null, frame);
|
||||
}
|
||||
|
||||
private void decodeAndPlayAudioFrame(byte[] audioFrame) {
|
||||
|
|
|
@ -26,6 +26,9 @@ public class AudioFrameAggregator implements Protocol {
|
|||
|
||||
private final int _codec2FrameSize;
|
||||
|
||||
private String _lastSrc;
|
||||
private String _lastDst;
|
||||
|
||||
public AudioFrameAggregator(Protocol childProtocol, int codec2ModeId) {
|
||||
_childProtocol = childProtocol;
|
||||
|
||||
|
@ -44,9 +47,11 @@ public class AudioFrameAggregator implements Protocol {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendAudio(byte[] frame) throws IOException {
|
||||
public void sendAudio(String src, String dst, byte[] frame) throws IOException {
|
||||
if ( _outputBufferPos + frame.length >= _outputBufferSize) {
|
||||
_childProtocol.sendAudio(Arrays.copyOf(_outputBuffer, _outputBufferPos));
|
||||
_childProtocol.sendAudio(src, dst, Arrays.copyOf(_outputBuffer, _outputBufferPos));
|
||||
_lastSrc = src;
|
||||
_lastDst = dst;
|
||||
_outputBufferPos = 0;
|
||||
}
|
||||
System.arraycopy(frame, 0, _outputBuffer, _outputBufferPos, frame.length);
|
||||
|
@ -54,8 +59,8 @@ public class AudioFrameAggregator implements Protocol {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendData(byte[] dataPacket) throws IOException {
|
||||
_childProtocol.sendData(dataPacket);
|
||||
public void sendData(String src, String dst, byte[] dataPacket) throws IOException {
|
||||
_childProtocol.sendData(src, dst, dataPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +98,7 @@ public class AudioFrameAggregator implements Protocol {
|
|||
@Override
|
||||
public void flush() throws IOException {
|
||||
if (_outputBufferPos > 0) {
|
||||
_childProtocol.sendAudio(Arrays.copyOf(_outputBuffer, _outputBufferPos));
|
||||
_childProtocol.sendAudio(_lastSrc, _lastDst, Arrays.copyOf(_outputBuffer, _outputBufferPos));
|
||||
_outputBufferPos = 0;
|
||||
}
|
||||
_childProtocol.flush();
|
||||
|
|
|
@ -191,12 +191,12 @@ public class Kiss implements Protocol {
|
|||
};
|
||||
|
||||
@Override
|
||||
public void sendAudio(byte [] frame) throws IOException {
|
||||
public void sendAudio(String src, String dst, byte [] frame) throws IOException {
|
||||
send(frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(byte[] dataPacket) throws IOException {
|
||||
public void sendData(String src, String dst, byte[] dataPacket) throws IOException {
|
||||
send(dataPacket);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ import java.io.IOException;
|
|||
|
||||
public interface Protocol {
|
||||
void initialize(Transport transport, Context context) throws IOException;
|
||||
void sendAudio(byte[] frame) throws IOException;
|
||||
void sendData(byte[] dataPacket) throws IOException;
|
||||
void sendAudio(String src, String dst, byte[] frame) throws IOException;
|
||||
void sendData(String src, String dst, byte[] dataPacket) throws IOException;
|
||||
boolean receive(Callback callback) throws IOException;
|
||||
void flush() throws IOException;
|
||||
void close();
|
||||
|
|
|
@ -24,12 +24,12 @@ public class Raw implements Protocol {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendAudio(byte [] frame) throws IOException {
|
||||
public void sendAudio(String src, String dst, byte [] frame) throws IOException {
|
||||
_transport.write(Arrays.copyOf(frame, frame.length));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(byte[] dataPacket) throws IOException {
|
||||
public void sendData(String src, String dst, byte[] dataPacket) throws IOException {
|
||||
_transport.write(Arrays.copyOf(dataPacket, dataPacket.length));
|
||||
}
|
||||
|
||||
|
|
|
@ -44,14 +44,14 @@ public class RecorderPipe implements Protocol {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendAudio(byte[] frame) throws IOException {
|
||||
_childProtocol.sendAudio(frame);
|
||||
writeToFile(frame);
|
||||
public void sendAudio(String src, String dst, byte[] frame) throws IOException {
|
||||
_childProtocol.sendAudio(src, dst, frame);
|
||||
writeToFile(src, dst, frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(byte[] dataPacket) throws IOException {
|
||||
_childProtocol.sendData(dataPacket);
|
||||
public void sendData(String src, String dst, byte[] dataPacket) throws IOException {
|
||||
_childProtocol.sendData(src, dst, dataPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +60,7 @@ public class RecorderPipe implements Protocol {
|
|||
@Override
|
||||
protected void onReceiveAudioFrames(byte[] audioFrames) {
|
||||
callback.onReceiveAudioFrames(audioFrames);
|
||||
writeToFile(audioFrames);
|
||||
writeToFile(null, null, audioFrames);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,9 +85,9 @@ public class RecorderPipe implements Protocol {
|
|||
_childProtocol.close();
|
||||
}
|
||||
|
||||
private void writeToFile(byte[] rawData) {
|
||||
private void writeToFile(String src, String dst, byte[] rawData) {
|
||||
stopRotationTimer();
|
||||
createStreamIfNotExists();
|
||||
createStreamIfNotExists(src, dst);
|
||||
writeToStream(rawData);
|
||||
startRotationTimer();
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class RecorderPipe implements Protocol {
|
|||
}
|
||||
}
|
||||
|
||||
private void createStreamIfNotExists() {
|
||||
private void createStreamIfNotExists(String src, String dst) {
|
||||
if (_activeStream == null) {
|
||||
try {
|
||||
Date date = new Date();
|
||||
|
@ -110,7 +110,7 @@ public class RecorderPipe implements Protocol {
|
|||
if (!newDirectory.exists() && !newDirectory.mkdirs()) {
|
||||
Log.e(TAG, "Failed to create directory for voicemails");
|
||||
}
|
||||
File newAudioFile = new File(newDirectory, getNewFileName(date));
|
||||
File newAudioFile = new File(newDirectory, getNewFileName(date, src, dst));
|
||||
_activeStream = new FileOutputStream(newAudioFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -123,10 +123,15 @@ public class RecorderPipe implements Protocol {
|
|||
return df.format(date);
|
||||
}
|
||||
|
||||
private String getNewFileName(Date date) {
|
||||
private String getNewFileName(Date date, String src, String dst) {
|
||||
SimpleDateFormat tf = new SimpleDateFormat("HHmmss", Locale.ENGLISH);
|
||||
String codec2mode = String.format(Locale.ENGLISH, "%02d", _codec2ModeId);
|
||||
return codec2mode + "_" + tf.format(date) + ".c2";
|
||||
String fileName = codec2mode + "_" + tf.format(date);
|
||||
if (src != null && dst != null) {
|
||||
fileName += "_" + src + "_" + dst;
|
||||
}
|
||||
fileName += ".c2";
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private void startRotationTimer() {
|
||||
|
|
|
@ -42,18 +42,18 @@ public class ScramblerPipe implements Protocol {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendAudio(byte[] audioFrame) throws IOException {
|
||||
public void sendAudio(String src, String dst, byte[] audioFrame) throws IOException {
|
||||
byte[] result = scramble(audioFrame);
|
||||
if (result != null) {
|
||||
_childProtocol.sendData(result);
|
||||
_childProtocol.sendData(src, dst, result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(byte[] dataPacket) throws IOException {
|
||||
public void sendData(String src, String dst, byte[] dataPacket) throws IOException {
|
||||
byte[] result = scramble(dataPacket);
|
||||
if (result != null) {
|
||||
_childProtocol.sendData(result);
|
||||
_childProtocol.sendData(src, dst, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue