Skip to content

Commit

Permalink
#1723 WIP resolves issue with to/from values and registering leases o…
Browse files Browse the repository at this point in the history
…n audio segments across the lifecycle.
  • Loading branch information
Dennis Sheirer committed Dec 4, 2023
1 parent f1a6415 commit 8d33be8
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected void closeAudioSegment()
{
mAudioSegment.completeProperty().set(true);
mIdentifierUpdateNotificationBroadcaster.removeListener(mAudioSegment);
mAudioSegment.decrementConsumerCount();
mAudioSegment.removeLease(getClass().toString());
mAudioSegment = null;
}
}
Expand All @@ -99,6 +99,10 @@ protected void closeAudioSegment()
@Override
public void stop()
{
if(getAudioSegment().isDuplicate())
{
mLog.warn("Audio Module [" + getClass() + "] stop() invoked AND DUPLICATE=TRUE is detected");
}
closeAudioSegment();
}

Expand All @@ -113,7 +117,7 @@ public AudioSegment getAudioSegment()
if(mAudioSegment == null)
{
mAudioSegment = new AudioSegment(mAliasList, getTimeslot());
mAudioSegment.incrementConsumerCount();
mAudioSegment.addLease(getClass().toString());
mAudioSegment.addIdentifiers(mIdentifierCollection.getIdentifiers());
mIdentifierUpdateNotificationBroadcaster.addListener(mAudioSegment);

Expand All @@ -124,7 +128,6 @@ public AudioSegment getAudioSegment()

if(mAudioSegmentListener != null)
{
mAudioSegment.incrementConsumerCount();
mAudioSegmentListener.receive(mAudioSegment);
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/io/github/dsheirer/audio/AudioManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ public void remove(ICallEventListener listener)
public void receive(AudioSegment audioSegment)
{
//Let the duplicate call detector process the segment first to detect duplicates.
audioSegment.addLease(mDuplicateCallDetector.getClass().toString());
mDuplicateCallDetector.receive(audioSegment);
audioSegment.addLease(mProcessor.getClass().toString());
mProcessor.add(audioSegment);
//TODO: redesign audio playback manager to work with Call entities instead of audio segments.
audioSegment.addLease(mAudioPlaybackManager.getClass().toString());
mAudioPlaybackManager.receive(audioSegment);
audioSegment.addLease(mAudioRecordingManager.getClass().toString());
mAudioRecordingManager.receive(audioSegment);
audioSegment.addLease(mAudioStreamingManager.getClass().toString());
mAudioStreamingManager.receive(audioSegment);
}

Expand Down Expand Up @@ -210,7 +214,7 @@ public void shutdown()

for(AudioSegment audioSegment: mQueuedAudioSegments)
{
audioSegment.decrementConsumerCount();
audioSegment.removeLease(getClass().toString());
}
mQueuedAudioSegments.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public void receive(AudioSegment audioSegment)
mDetectorMap.put(system, detector);
}

audioSegment.addLease(detector.getClass().toString());
detector.add(audioSegment);
audioSegment.removeLease(getClass().toString());
}
}
}
Expand Down Expand Up @@ -256,7 +258,7 @@ private void process()

if(complete)
{
audioSegment.decrementConsumerCount();
audioSegment.removeLease(getClass().toString());
}

return complete;
Expand Down Expand Up @@ -285,7 +287,7 @@ private void process()
if(isDuplicate(current, toCheck))
{
toCheck.setDuplicate(true);
toCheck.decrementConsumerCount();
toCheck.removeLease(getClass().toString());
duplicates.add(toCheck);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public void stop()

for(AudioSegment audioSegment: mNewAudioSegments)
{
audioSegment.decrementConsumerCount();
audioSegment.removeLease(getClass().toString());
}

mNewAudioSegments.clear();

for(AudioSegment audioSegment: mAudioSegments)
{
audioSegment.decrementConsumerCount();
audioSegment.removeLease(getClass().toString());
}

mAudioSegments.clear();
Expand Down Expand Up @@ -132,7 +132,7 @@ private void processAudioSegments()
if(audioSegment.isDuplicate() && mUserPreferences.getDuplicateCallDetectionPreference().isDuplicateStreamingSuppressionEnabled())
{
it.remove();
audioSegment.decrementConsumerCount();
audioSegment.removeLease(getClass().toString());
}
else if(audioSegment.completeProperty().get())
{
Expand Down Expand Up @@ -166,7 +166,7 @@ else if(audioSegment.completeProperty().get())
}
}

audioSegment.decrementConsumerCount();
audioSegment.removeLease(getClass().toString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
import io.github.dsheirer.identifier.configuration.SiteConfigurationIdentifier;
import io.github.dsheirer.identifier.configuration.SystemConfigurationIdentifier;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Manages an active audio segment through to completion and provides options for refreshing the associated call
* object.
*/
public class ActiveAudioSegment
{
private static final Logger LOGGER = LoggerFactory.getLogger(ActiveAudioSegment.class);
private AudioSegment mAudioSegment;
private Call mCall;

Expand All @@ -50,6 +53,7 @@ public class ActiveAudioSegment
public ActiveAudioSegment(AudioSegment audioSegment, Call call)
{
mAudioSegment = audioSegment;
mAudioSegment.addLease(getClass().toString());
mCall = call;
}

Expand All @@ -59,7 +63,7 @@ public ActiveAudioSegment(AudioSegment audioSegment, Call call)
public void dispose()
{
//TODO: perform disposal operations
mAudioSegment.decrementConsumerCount();
mAudioSegment.removeLease(getClass().toString());
mAudioSegment = null;
mCall = null;
}
Expand Down Expand Up @@ -102,6 +106,7 @@ public boolean update()
updated |= updateTo(mCall, mAudioSegment.getIdentifierCollection().getToIdentifier(), getAudioSegment().getAliasList());
updated |= updateFrom(mCall, mAudioSegment.getIdentifierCollection().getFromIdentifier(), getAudioSegment().getAliasList());
updated |= updateDuration(mCall, mAudioSegment.getDuration());
updated |= updateFlags(mCall, mAudioSegment);
return updated;
}

Expand Down Expand Up @@ -164,12 +169,50 @@ public static Call create(AudioSegment audioSegment)
}

updateFrom(call, audioSegment.getIdentifierCollection().getFromIdentifier(), audioSegment.getAliasList());
updateTo(call, audioSegment.getIdentifierCollection().getFromIdentifier(), audioSegment.getAliasList());
updateTo(call, audioSegment.getIdentifierCollection().getToIdentifier(), audioSegment.getAliasList());
updateDuration(call, audioSegment.getDuration());
updateFlags(call, audioSegment);

return call;
}

/**
* Updates the duplicate, record, stream and other call flags/info
* @param call to update
* @param audioSegment containing flags/info
* @return true if the call is updated.
*/
private static boolean updateFlags(Call call, AudioSegment audioSegment)
{
boolean updated = false;

if(call.isDuplicate() ^ audioSegment.isDuplicate())
{
call.setDuplicate(true);
updated = true;
}

if(call.isRecord() ^ audioSegment.recordAudioProperty().get())
{
call.setRecord(true);
updated = true;
}

if(call.isStream() ^ audioSegment.hasBroadcastChannels())
{
call.setStream(true);
updated = true;
}

if(call.getMonitor() != audioSegment.monitorPriorityProperty().get())
{
call.setMonitor(audioSegment.monitorPriorityProperty().get());
updated = true;
}

return updated;
}

/**
* Updates the call duration field
* @param call to update
Expand Down Expand Up @@ -253,7 +296,11 @@ private static boolean updateTo(Call call, Identifier toIdentifier, AliasList al
switch(toIdentifier.getForm())
{
case TALKGROUP -> call.setCallType("Talk Group");
case RADIO -> call.setCallType("Private");
case RADIO ->
{
LOGGER.info("Private Call detected - TO identifier: " + toIdentifier);
call.setCallType("Private");
}
case PATCH_GROUP -> call.setCallType("Patch Group");
default -> call.setCallType(toIdentifier.getForm().toString());
}
Expand Down
Loading

0 comments on commit 8d33be8

Please sign in to comment.