diff --git a/src/main/java/io/github/dsheirer/audio/AudioSegment.java b/src/main/java/io/github/dsheirer/audio/AudioSegment.java index a4b89a41..3d6fed49 100644 --- a/src/main/java/io/github/dsheirer/audio/AudioSegment.java +++ b/src/main/java/io/github/dsheirer/audio/AudioSegment.java @@ -75,6 +75,7 @@ public class AudioSegment implements Listener private long mStartTimestamp = System.currentTimeMillis(); private boolean mDisposing = false; private AudioSegment mLinkedAudioSegment; + private int mTimeslot; /** * Constructs an instance @@ -84,9 +85,18 @@ public class AudioSegment implements Listener public AudioSegment(AliasList aliasList, int timeslot) { mAliasList = aliasList; + mTimeslot = timeslot; mIdentifierCollection.setTimeslot(timeslot); } + /** + * Timeslot for this audio segment + */ + public int getTimeslot() + { + return mTimeslot; + } + /** * Creation timestamp for this audio segment * @return long milliseconds since epoch @@ -211,7 +221,7 @@ public class AudioSegment implements Listener } /** - * Identifier collection for this audio segment + * Immutable identifier collection for this audio segment */ public IdentifierCollection getIdentifierCollection() { @@ -226,7 +236,7 @@ public class AudioSegment implements Listener { for(Identifier identifier: identifiers) { - mIdentifierCollection.update(identifier); + addIdentifier(identifier); } } @@ -354,6 +364,40 @@ public class AudioSegment implements Listener mIdentifierUpdateNotificationBroadcaster.removeListener(listener); } + /** + * Adds the identifier to this audio segment and updates record, priority and streaming properties. + * + * Note: identifiers pass to this method must be checked for timeslot match. + */ + public void addIdentifier(Identifier identifier) + { + mIdentifierCollection.update(identifier); + + List aliases = mAliasList.getAliases(identifier); + + for(Alias alias: aliases) + { + if(alias.isRecordable()) + { + mRecordAudio.set(true); + } + + //Add all broadcast channels for the alias ... let the set handle duplication. + for(BroadcastChannel broadcastChannel: alias.getBroadcastChannels()) + { + mBroadcastChannels.add(broadcastChannel); + } + + //Only assign a playback priority if it is lower priority than the current setting. + int playbackPriority = alias.getPlaybackPriority(); + + if(playbackPriority < mMonitorPriority.get()) + { + mMonitorPriority.set(playbackPriority); + } + } + } + /** * Processes identifier update notifications and updates audio segment properties using the associated aliases * from the alias list. @@ -363,38 +407,11 @@ public class AudioSegment implements Listener @Override public void receive(IdentifierUpdateNotification identifierUpdateNotification) { - IdentifierUpdateNotification.Operation operation = identifierUpdateNotification.getOperation(); - - //Only process ADD updates. Ignore REMOVE to preserve the full metadata set - if(operation == IdentifierUpdateNotification.Operation.ADD || - operation == IdentifierUpdateNotification.Operation.SILENT_ADD) + //Only process add updates that match this timeslot + if(identifierUpdateNotification.getTimeslot() == getTimeslot() && + (identifierUpdateNotification.isAdd() || identifierUpdateNotification.isSilentAdd())) { - mIdentifierCollection.receive(identifierUpdateNotification); - - List aliases = mAliasList.getAliases(identifierUpdateNotification.getIdentifier()); - - for(Alias alias: aliases) - { - if(alias.isRecordable()) - { - mRecordAudio.set(true); - } - - //Add all broadcast channels for the alias ... let the set handle duplication. - for(BroadcastChannel broadcastChannel: alias.getBroadcastChannels()) - { - mBroadcastChannels.add(broadcastChannel); - } - - //Only assign a playback priority if it is lower priority than the current setting. - int playbackPriority = alias.getPlaybackPriority(); - - if(playbackPriority < mMonitorPriority.get()) - { - mMonitorPriority.set(playbackPriority); - } - } - + addIdentifier(identifierUpdateNotification.getIdentifier()); mIdentifierUpdateNotificationBroadcaster.broadcast(identifierUpdateNotification); } }