mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-15 10:07:26 -05:00
Resolves #336. Updates audio recorder to use a *.tmp file extension
while the file is open/in-use and change the file extension to *.wav when the recording is closed.
This commit is contained in:
@@ -93,6 +93,7 @@ public class RecorderManager implements Listener<AudioPacket>
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary ingest point for audio packets from all decoding channels
|
* Primary ingest point for audio packets from all decoding channels
|
||||||
|
*
|
||||||
* @param audioPacket to process
|
* @param audioPacket to process
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -115,7 +116,7 @@ public class RecorderManager implements Listener<AudioPacket>
|
|||||||
|
|
||||||
while(!audioPackets.isEmpty())
|
while(!audioPackets.isEmpty())
|
||||||
{
|
{
|
||||||
for(AudioPacket audioPacket: audioPackets)
|
for(AudioPacket audioPacket : audioPackets)
|
||||||
{
|
{
|
||||||
String identifier = audioPacket.getMetadata().getUniqueIdentifier();
|
String identifier = audioPacket.getMetadata().getUniqueIdentifier();
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class AudioPacketWaveRecorder extends Module implements Listener<AudioPac
|
|||||||
sb.append(mFilePrefix);
|
sb.append(mFilePrefix);
|
||||||
sb.append("_");
|
sb.append("_");
|
||||||
sb.append(TimeStamp.getLongTimeStamp("_"));
|
sb.append(TimeStamp.getLongTimeStamp("_"));
|
||||||
sb.append(".wav");
|
sb.append(".tmp");
|
||||||
|
|
||||||
mFile = Paths.get(sb.toString());
|
mFile = Paths.get(sb.toString());
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class WaveWriter implements AutoCloseable
|
|||||||
|
|
||||||
public static final String DATA_CHUNK_ID = "data";
|
public static final String DATA_CHUNK_ID = "data";
|
||||||
|
|
||||||
private static final Pattern FILENAME_PATTERN = Pattern.compile("(.*_)(\\d+)(\\.wav)");
|
private static final Pattern FILENAME_PATTERN = Pattern.compile("(.*_)(\\d+)(\\.tmp)");
|
||||||
public static final long MAX_WAVE_SIZE = 2l * (long)Integer.MAX_VALUE;
|
public static final long MAX_WAVE_SIZE = 2l * (long)Integer.MAX_VALUE;
|
||||||
|
|
||||||
private AudioFormat mAudioFormat;
|
private AudioFormat mAudioFormat;
|
||||||
@@ -112,7 +112,7 @@ public class WaveWriter implements AutoCloseable
|
|||||||
|
|
||||||
while(Files.exists(mFile))
|
while(Files.exists(mFile))
|
||||||
{
|
{
|
||||||
mFile = Paths.get(mFile.toFile().getAbsolutePath().replace(".wav", "_" + version + ".wav"));
|
mFile = Paths.get(mFile.toFile().getAbsolutePath().replace(".tmp", "_" + version + ".tmp"));
|
||||||
version++;
|
version++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +134,35 @@ public class WaveWriter implements AutoCloseable
|
|||||||
mFileChannel.force(true);
|
mFileChannel.force(true);
|
||||||
mFileChannel.close();
|
mFileChannel.close();
|
||||||
mFileChannel = null;
|
mFileChannel = null;
|
||||||
|
|
||||||
|
rename();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames the file from *.tmp to *.wav after file has been closed.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private void rename() throws IOException
|
||||||
|
{
|
||||||
|
if(mFile != null && Files.exists(mFile))
|
||||||
|
{
|
||||||
|
String renamed = mFile.getFileName().toString();
|
||||||
|
renamed = renamed.replace(".tmp", ".wav");
|
||||||
|
Path renamedPath = mFile.resolveSibling(renamed);
|
||||||
|
|
||||||
|
int suffix = 1;
|
||||||
|
|
||||||
|
while(Files.exists(renamedPath))
|
||||||
|
{
|
||||||
|
String renamedWithSuffix = mFile.getFileName().toString();
|
||||||
|
renamedWithSuffix = renamedWithSuffix.replace(".tmp", "_" + suffix + ".wav");
|
||||||
|
Path renamedWithSuffixPath = mFile.resolveSibling(renamedWithSuffix);
|
||||||
|
renamedPath = mFile.resolveSibling(renamedWithSuffixPath);
|
||||||
|
suffix++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Files.move(mFile, renamedPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -379,7 +408,7 @@ public class WaveWriter implements AutoCloseable
|
|||||||
|
|
||||||
if(mFileRolloverCounter == 2)
|
if(mFileRolloverCounter == 2)
|
||||||
{
|
{
|
||||||
filename = filename.replace(".wav", "_2.wav");
|
filename = filename.replace(".tmp", "_2.tmp");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user