mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-10 23:57:25 -05:00
* WIP on new P25 message framer. * WIP on new P25 message framer. * Adds new 1/2 and 3/4 rate trellis decoders. Still trying to chase down why there is a sync pattern mismatch in the NID buffer queue. * WIP - new p25 message framer works correctly now. PDU's are dectected and decoded using the 1/2 and 3/4 rate trellis decoders. Packet Sequences are assembled. Need to add a new packet sequence message factory that can detect Motorola Auto Registration Service (ARS) formatted UDP/ID packets and SNDCP command packets. * WIP - removes nullify on channel results queue. * WIP - updates message framer for TSBK 1/2/3 processing. * WIP removing P25 sync pattern and nid bits from all message parsers. * WIP - merges identifier framework branch changes into this branch. * WIP on updating link control words to new format and identifier framework. * WIP - implements rest of link control words for extended formats * WIP - initial work on ISP/OSP TSBK message restructuring. * WIP - adds more TSBK ISP and OSP messages * WIP - finished updating most of the TSBK ISP and OSP messages. Converted all messages to no longer include the NID (nac + dataunitID) so that each message can simply hold the parsed values. Removed AliasList as an argument to each message and updated all messges to use the new IIdentifer and IAPCO25Channel interfaces. Removed legacy TDU and LDU link control messages and replaced with a single LinkControlWord class hierarchy. P25 decoder state is not yet updated for the new message structure. PDU message parsing is not fully implemented. * WIP - adds some Multi-Block trunking control messages with Alternate and Unconfirmed formats. * WIP - Fully implements AMBTC and UMBTC PDU message parsers. Some package restructuring. * WIP - Resolves Link control parsing in LDU1 and 2 messages. * WIP - finishes updating TSBK and Link Control messages. Adds support for moto link control messages for patch groups. * WIP - finishes updating TSBK and Link Control messages. Adds support for moto link control messages for patch groups. Adds support for moto ARS service, IPV4 decoding, and UDP/IP packets. * WIP - finishes SNDCP packet data with header parsing. Compressed IP or UDP headers are not yet supported, but are logged as such. * WIP - converts all talkgroup identifiers to integers and updates alias list to create a per-protocol map of talkgroup id's to alias. Inserts a legacy talkgroup (ltr, p25, passport, mpt1327, mdc, etc.) conversion utility to convert existing legacy (string) talkgroups to new integer talkgroup format. Creates an audio packet manager to insert metadata into audio packets before streaming packets for playback, recording, and/or streaming. Creates identifier collection to manage current identifiers in each of the channel and decoder states. Creates simplified channel metadata to maintain the now playing display. Moves channel attributes (alias list, system, site, name) as configuration identifiers in the channel state. Many other refactoring and updates. * WIP - numerous updates to push use of identifier collection throughout the system. Updates the channel metadata and audio packet processing logic. Implements a large portion of the P25 decode state processing. Updates traffic channel management. Adds user preferences for timestamp and identifier formatting, however doesn't add a user interface yet. * WIP - initial implementation of user preferences editor window. * WIP - updates preferences editor window to close and dispose window but retain javafx event thread running. * WIP - fully updates p25 decoder state and traffic channel processing to use the new identifier framework. Cleans up channel event processing and removes channel model as the sole broadcaster of channel events. Channel processing manager now listens for all start/stop events and requestors dispatch event directly to the channel processing manager. Resolves issue in airspy that was causing user interface to lock-up. The issue appears to occur when the dongle is plugged into a usb port that can't fully support the data rate. sdrtrunk now recognizes these errors and warns the user that they should use another usb port. * WIP - updates alias action manager and adds new talkgroup range alias identifier. Updates playlist to incorporate a version number so that the playlist updater only runs when needed, to update a playlist to the correct version format. Updates user preferences to use the google event bus to broadcast preference update notifications to remove the need for listeners to register directly on the user preferences instance. * WIP - updates alias id editors to flag invalid values and moves legacy alias ids to legacy package. Updates event logging configuration to add traffic channel decode events and decoded message logging. Removes binary message logging since that is now replaced with demodulated bitstream recording. * Removes system properties from user preferences. Preferences are stored in the OS-dependent settings store (windows - registry) * Updates MapService to use new PlottableDecodeEvent instead of monitoring all of the decoded messages. Updates Fleetsync decoder and related messages to identifier framework. * Updates LTR-Net, Fleetsync and LJ1200 decoders to new identifier framework and adds support for user preferences for formatting of LTR-Net and fleetsync talkgroup identifiers. Breaks LTR-Net messages into various message types and uses a new message factory. Removes alias list from message processing for ltr-net, fleetsync and lj1200. * Updates LTR-Standard messages to Identifier framework. * Removes Plottable and IPlottable from codebase. * wip * WIP on MPT-1327 messages. * Updates MPT1327 decoder to identifier framework and new traffic channel manager. This decoder still needs to be updated with a new message parser factory and a sync detector like what is now used for P25. * Updates MDC1200 decoder and message to identifier framework. * Updates Tait1200 and Passport decoders to identifier framework. * Merges changes from master branch. * Removes legacy alias support classes. Updates passport message processor to only pass valid messages. Adds support to playlist updater for converting passport mobile ids to become passport talkgroup values. * Updates P25 decoder state and channel state to better track allocated traffic channels. Resolves issue in timestamp manager for trackig message timestamps. Resolves issue in airspy tuner that was causing the tuner to stop sending samples to the application. * Update P25 Decoder state to process SNDCP management messages and PDU messages. Updates P25 activity summary to display network and site details. Resolves issue with overlay panel that prevented enabled channels from rendering correctly when zoomed in. * Creates a new FilePreferences as part of the user preferences to begin the transition of SystemProperties over to user preferences and consolidate file preferences in one location. Updates playlist manager to use the new file preferences and to use default.xml as the new default playlist name, following conversion of a playlist_v2.xml format to the new format. In the near future, the user will be able to edit file locations and to create/use other playlists. Resolved an issue with all decoder states where not all identifiers were being included in decode events.
452 lines
14 KiB
Java
452 lines
14 KiB
Java
/*
|
|
* ******************************************************************************
|
|
* sdrtrunk
|
|
* Copyright (C) 2014-2018 Dennis Sheirer
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
* *****************************************************************************
|
|
*/
|
|
package io.github.dsheirer.audio.playback;
|
|
|
|
import io.github.dsheirer.audio.AudioEvent;
|
|
import io.github.dsheirer.identifier.IdentifierCollection;
|
|
import io.github.dsheirer.sample.Broadcaster;
|
|
import io.github.dsheirer.sample.Listener;
|
|
import io.github.dsheirer.sample.buffer.ReusableAudioPacket;
|
|
import io.github.dsheirer.source.mixer.MixerChannel;
|
|
import io.github.dsheirer.util.ThreadPool;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import javax.sound.sampled.AudioFormat;
|
|
import javax.sound.sampled.BooleanControl;
|
|
import javax.sound.sampled.Control;
|
|
import javax.sound.sampled.FloatControl;
|
|
import javax.sound.sampled.Line;
|
|
import javax.sound.sampled.LineEvent;
|
|
import javax.sound.sampled.LineListener;
|
|
import javax.sound.sampled.LineUnavailableException;
|
|
import javax.sound.sampled.Mixer;
|
|
import javax.sound.sampled.SourceDataLine;
|
|
import java.nio.ByteBuffer;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.concurrent.LinkedTransferQueue;
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
public abstract class AudioOutput implements Listener<ReusableAudioPacket>, LineListener
|
|
{
|
|
private final static Logger mLog = LoggerFactory.getLogger(AudioOutput.class);
|
|
|
|
private LinkedTransferQueue<ReusableAudioPacket> mBuffer = new LinkedTransferQueue<>();
|
|
private int mBufferStartThreshold;
|
|
private int mBufferStopThreshold;
|
|
|
|
private Listener<IdentifierCollection> mIdentifierCollectionListener;
|
|
private Broadcaster<AudioEvent> mAudioEventBroadcaster = new Broadcaster<>();
|
|
|
|
private ScheduledFuture<?> mProcessorTask;
|
|
|
|
private SourceDataLine mOutput;
|
|
private Mixer mMixer;
|
|
private MixerChannel mMixerChannel;
|
|
private FloatControl mGainControl;
|
|
private BooleanControl mMuteControl;
|
|
|
|
private AudioEvent mAudioStartEvent;
|
|
private AudioEvent mAudioStopEvent;
|
|
|
|
private boolean mCanProcessAudio = false;
|
|
private long mLastActivity = System.currentTimeMillis();
|
|
|
|
/**
|
|
* Single audio channel playback with automatic starting and stopping of the
|
|
* underlying sourcedataline specified by the mixer and mixer channel
|
|
* arguments.
|
|
*
|
|
* Maintains an internal non-blocking audio packet queue and processes this
|
|
* queue 25 times a second (every 40 ms).
|
|
*
|
|
* @param mixer to obtain source data line
|
|
* @param mixerChannel either mono or left/right stereo
|
|
* @param audioFormat to use during playback
|
|
* @param lineInfo to use when obtaining the source data line
|
|
* @param requestedBufferSize of approximately 1 second of audio
|
|
*/
|
|
public AudioOutput(Mixer mixer, MixerChannel mixerChannel, AudioFormat audioFormat, Line.Info lineInfo,
|
|
int requestedBufferSize)
|
|
{
|
|
mMixer = mixer;
|
|
mMixerChannel = mixerChannel;
|
|
|
|
try
|
|
{
|
|
mOutput = (SourceDataLine) mMixer.getLine(lineInfo);
|
|
|
|
if(mOutput != null)
|
|
{
|
|
mOutput.open(audioFormat, requestedBufferSize);
|
|
|
|
//Start threshold: buffer is full with 10% or less of capacity remaining
|
|
mBufferStartThreshold = (int) (mOutput.getBufferSize() * 0.10);
|
|
|
|
//Stop threshold: buffer is empty with 90% or more capacity available
|
|
mBufferStopThreshold = (int) (mOutput.getBufferSize() * 0.90);
|
|
|
|
mOutput.addLineListener(this);
|
|
|
|
if(mOutput != null)
|
|
{
|
|
try
|
|
{
|
|
Control gain = mOutput.getControl(FloatControl.Type.MASTER_GAIN);
|
|
mGainControl = (FloatControl) gain;
|
|
}
|
|
catch(IllegalArgumentException iae)
|
|
{
|
|
mLog.warn("Couldn't obtain MASTER GAIN control for stereo line [" +
|
|
mixer.getMixerInfo().getName() + " | " + getChannelName() + "]");
|
|
}
|
|
|
|
try
|
|
{
|
|
Control mute = mOutput.getControl(BooleanControl.Type.MUTE);
|
|
mMuteControl = (BooleanControl) mute;
|
|
}
|
|
catch(IllegalArgumentException iae)
|
|
{
|
|
mLog.warn("Couldn't obtain MUTE control for stereo line [" +
|
|
mixer.getMixerInfo().getName() + " | " + getChannelName() + "]");
|
|
}
|
|
|
|
/* Run the queue processor task every 40 milliseconds or 25 times a second */
|
|
mProcessorTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferProcessor(),
|
|
0, 40, TimeUnit.MILLISECONDS);
|
|
}
|
|
|
|
mAudioStartEvent = new AudioEvent(AudioEvent.Type.AUDIO_STARTED,
|
|
getChannelName());
|
|
mAudioStopEvent = new AudioEvent(AudioEvent.Type.AUDIO_STOPPED,
|
|
getChannelName());
|
|
|
|
mCanProcessAudio = true;
|
|
}
|
|
}
|
|
catch(LineUnavailableException e)
|
|
{
|
|
mLog.error("Couldn't obtain audio source data line for "
|
|
+ "audio output - mixer [" + mMixer.getMixerInfo().getName() + "]");
|
|
}
|
|
}
|
|
|
|
public void reset()
|
|
{
|
|
broadcast(new AudioEvent(AudioEvent.Type.AUDIO_STOPPED, getChannelName()));
|
|
}
|
|
|
|
public void dispose()
|
|
{
|
|
mCanProcessAudio = false;
|
|
|
|
if(mProcessorTask != null)
|
|
{
|
|
mProcessorTask.cancel(true);
|
|
}
|
|
|
|
mProcessorTask = null;
|
|
|
|
mBuffer.clear();
|
|
|
|
mAudioEventBroadcaster.dispose();
|
|
mAudioEventBroadcaster = null;
|
|
mIdentifierCollectionListener = null;
|
|
|
|
if(mOutput != null)
|
|
{
|
|
mOutput.close();
|
|
}
|
|
|
|
mOutput = null;
|
|
mGainControl = null;
|
|
mMuteControl = null;
|
|
}
|
|
|
|
/**
|
|
* Converts the audio packet data into a byte buffer format appropriate for
|
|
* the underlying source data line.
|
|
*/
|
|
protected abstract ByteBuffer convert(ReusableAudioPacket packet);
|
|
|
|
/**
|
|
* Audio output channel name
|
|
*/
|
|
public String getChannelName()
|
|
{
|
|
return mMixerChannel.getLabel();
|
|
}
|
|
|
|
/**
|
|
* Mixer Channel for this audio output
|
|
*/
|
|
protected MixerChannel getMixerChannel()
|
|
{
|
|
return mMixerChannel;
|
|
}
|
|
|
|
/**
|
|
* Registers a single listener to receive audio start and audio stop events
|
|
*/
|
|
public void addAudioEventListener(Listener<AudioEvent> listener)
|
|
{
|
|
mAudioEventBroadcaster.addListener(listener);
|
|
}
|
|
|
|
public void removeAudioEventListener(Listener<AudioEvent> listener)
|
|
{
|
|
mAudioEventBroadcaster.removeListener(listener);
|
|
}
|
|
|
|
/**
|
|
* Broadcasts an audio event to the registered listener
|
|
*/
|
|
private void broadcast(AudioEvent audioEvent)
|
|
{
|
|
mAudioEventBroadcaster.broadcast(audioEvent);
|
|
}
|
|
|
|
/**
|
|
* Registers a single listener to receive the audio metadata from each
|
|
* audio packet
|
|
*/
|
|
public void setIdentifierCollectionListener(Listener<IdentifierCollection> listener)
|
|
{
|
|
mIdentifierCollectionListener = listener;
|
|
}
|
|
|
|
public void removeAudioMetadataListener()
|
|
{
|
|
mIdentifierCollectionListener = null;
|
|
}
|
|
|
|
/**
|
|
* Broadcasts audio identifier collection metadata to the registered listener
|
|
*/
|
|
private void broadcast(IdentifierCollection identifierCollection)
|
|
{
|
|
if(mIdentifierCollectionListener != null)
|
|
{
|
|
mIdentifierCollectionListener.receive(identifierCollection);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Timestamp of either last buffer received or last buffer processed
|
|
*/
|
|
public long getLastActivityTimestamp()
|
|
{
|
|
return mLastActivity;
|
|
}
|
|
|
|
/**
|
|
* Updates the last activity timestamp to current system time
|
|
*/
|
|
public void updateTimestamp()
|
|
{
|
|
mLastActivity = System.currentTimeMillis();
|
|
}
|
|
|
|
@Override
|
|
public void receive(ReusableAudioPacket packet)
|
|
{
|
|
if(mCanProcessAudio)
|
|
{
|
|
//Update the activity timestamp so that this audio output doesn't
|
|
//get disconnected before it starts processing the audio stream
|
|
updateTimestamp();
|
|
|
|
mBuffer.add(packet);
|
|
}
|
|
else
|
|
{
|
|
packet.decrementUserCount();
|
|
}
|
|
}
|
|
|
|
public class BufferProcessor implements Runnable
|
|
{
|
|
private AtomicBoolean mProcessing = new AtomicBoolean();
|
|
private List<ReusableAudioPacket> mAudioPackets = new ArrayList<ReusableAudioPacket>();
|
|
|
|
|
|
public BufferProcessor()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void run()
|
|
{
|
|
try
|
|
{
|
|
/* The processing flag ensures that only one instance of the
|
|
* processor can run at any given time */
|
|
if(mProcessing.compareAndSet(false, true))
|
|
{
|
|
mBuffer.drainTo(mAudioPackets);
|
|
|
|
for(ReusableAudioPacket packet : mAudioPackets)
|
|
{
|
|
if(packet.getType() == ReusableAudioPacket.Type.AUDIO)
|
|
{
|
|
broadcast(packet.getIdentifierCollection());
|
|
|
|
ByteBuffer buffer = convert(packet);
|
|
|
|
int wrote = 0;
|
|
|
|
if(!mOutput.isRunning())
|
|
{
|
|
int toWrite = mOutput.available();
|
|
|
|
if(toWrite > buffer.array().length)
|
|
{
|
|
toWrite = buffer.array().length;
|
|
}
|
|
|
|
//Top off the buffer and check if we can start it
|
|
wrote += mOutput.write(buffer.array(), 0, toWrite);
|
|
|
|
checkStart();
|
|
}
|
|
|
|
if(mOutput.isRunning() && wrote < buffer.array().length)
|
|
{
|
|
//Blocking write
|
|
wrote += mOutput.write(buffer.array(), wrote,
|
|
buffer.array().length - wrote);
|
|
}
|
|
|
|
updateTimestamp();
|
|
}
|
|
else
|
|
{
|
|
packet.decrementUserCount();
|
|
}
|
|
}
|
|
|
|
mAudioPackets.clear();
|
|
|
|
checkStop();
|
|
|
|
mProcessing.set(false);
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
mLog.error("Error while processing audio buffers", e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Starts audio playback once audio buffer is almost full and remaining
|
|
* capacity falls below the start threshold.
|
|
*/
|
|
private void checkStart()
|
|
{
|
|
if(mCanProcessAudio &&
|
|
!mOutput.isRunning() &&
|
|
mOutput.available() <= mBufferStartThreshold)
|
|
{
|
|
mOutput.start();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Stops audio playback and drains the audio buffer to empty when the
|
|
* audio buffer is mostly empty and the available buffer capacity
|
|
* exceeds the stop threshold
|
|
*/
|
|
private void checkStop()
|
|
{
|
|
if(mCanProcessAudio &&
|
|
mOutput.isRunning() &&
|
|
mOutput.available() >= mBufferStopThreshold)
|
|
{
|
|
mOutput.drain();
|
|
mOutput.stop();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sets the mute state for this audio output channel
|
|
*/
|
|
public void setMuted(boolean muted)
|
|
{
|
|
if(mMuteControl != null)
|
|
{
|
|
mMuteControl.setValue(muted);
|
|
|
|
broadcast(new AudioEvent(muted ? AudioEvent.Type.AUDIO_MUTED :
|
|
AudioEvent.Type.AUDIO_UNMUTED, getChannelName()));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Current mute state for this audio output channel
|
|
*/
|
|
public boolean isMuted()
|
|
{
|
|
if(mMuteControl != null)
|
|
{
|
|
return mMuteControl.getValue();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Gain/volume control for this audio output channel, if one is available.
|
|
*/
|
|
public FloatControl getGainControl()
|
|
{
|
|
return mGainControl;
|
|
}
|
|
|
|
public boolean hasGainControl()
|
|
{
|
|
return mGainControl != null;
|
|
}
|
|
|
|
/**
|
|
* Monitors the source data line playback state and broadcasts audio events
|
|
* to the registered listener as the state changes
|
|
*/
|
|
@Override
|
|
public void update(LineEvent event)
|
|
{
|
|
LineEvent.Type type = event.getType();
|
|
|
|
if(type == LineEvent.Type.START)
|
|
{
|
|
mAudioEventBroadcaster.broadcast(mAudioStartEvent);
|
|
}
|
|
else if(type == LineEvent.Type.STOP)
|
|
{
|
|
mAudioEventBroadcaster.broadcast(mAudioStopEvent);
|
|
}
|
|
}
|
|
}
|