mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-16 18:47:33 -05:00
#30 WIP - broadcastify multi-channel streaming is functional.
This commit is contained in:
@@ -19,13 +19,14 @@
|
||||
package audio.broadcast.shoutcast.v1;
|
||||
|
||||
import audio.AudioPacket;
|
||||
import audio.broadcast.Broadcaster;
|
||||
import audio.broadcast.AudioBroadcaster;
|
||||
import audio.broadcast.BroadcastFactory;
|
||||
import audio.broadcast.BroadcastFormat;
|
||||
import audio.broadcast.BroadcastMetadata;
|
||||
import audio.broadcast.BroadcastState;
|
||||
import audio.convert.IAudioConverter;
|
||||
import audio.metadata.AudioMetadata;
|
||||
import controller.ThreadPoolManager;
|
||||
import org.asynchttpclient.DefaultAsyncHttpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import record.wave.AudioPacketMonoWaveReader;
|
||||
@@ -41,9 +42,9 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShoutcastV1Broadcaster extends Broadcaster
|
||||
public class ShoutcastV1AudioBroadcaster extends AudioBroadcaster
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( ShoutcastV1Broadcaster.class );
|
||||
private final static Logger mLog = LoggerFactory.getLogger( ShoutcastV1AudioBroadcaster.class );
|
||||
|
||||
private static final long RECONNECT_INTERVAL_MILLISECONDS = 15000; //15 seconds
|
||||
private long mLastConnectionAttempt = 0;
|
||||
@@ -58,13 +59,10 @@ public class ShoutcastV1Broadcaster extends Broadcaster
|
||||
/**
|
||||
* Creates a Shoutcast Version 1 broadcaster.
|
||||
* @param configuration
|
||||
* @param audioConverter
|
||||
*/
|
||||
public ShoutcastV1Broadcaster(ThreadPoolManager threadPoolManager,
|
||||
ShoutcastV1Configuration configuration,
|
||||
IAudioConverter audioConverter)
|
||||
public ShoutcastV1AudioBroadcaster(ThreadPoolManager threadPoolManager, ShoutcastV1Configuration configuration)
|
||||
{
|
||||
super(threadPoolManager, configuration, audioConverter);
|
||||
super(threadPoolManager, configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,34 +73,29 @@ public class ShoutcastV1Broadcaster extends Broadcaster
|
||||
return (ShoutcastV1Configuration)getBroadcastConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void broadcastMetadata(AudioMetadata metadata)
|
||||
{
|
||||
mLog.debug("Request to send audio metadata to shoutcast v1 server - needs code");
|
||||
}
|
||||
|
||||
/**
|
||||
* Process audio packets using Shoutcast V1 Protocol
|
||||
*/
|
||||
public void broadcast()
|
||||
@Override
|
||||
protected void broadcastAudio(byte[] audio)
|
||||
{
|
||||
//If we're connected, send the audio, otherwise discard it
|
||||
if(connect())
|
||||
{
|
||||
mAudioQueue.drainTo(mPacketsToBroadcast, 5);
|
||||
|
||||
if(!mPacketsToBroadcast.isEmpty())
|
||||
try
|
||||
{
|
||||
byte[] convertedAudio = getAudioConverter().convert(mPacketsToBroadcast);
|
||||
|
||||
mPacketsToBroadcast.clear();
|
||||
|
||||
if(convertedAudio != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
send(convertedAudio);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
mLog.error("Error while dispatching audio", e);
|
||||
setBroadcastState(BroadcastState.BROADCAST_ERROR);
|
||||
}
|
||||
}
|
||||
send(audio);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
mLog.error("Error while dispatching audio", e);
|
||||
setBroadcastState(BroadcastState.BROADCAST_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,8 +342,9 @@ public class ShoutcastV1Broadcaster extends Broadcaster
|
||||
config.setBitRate(16);
|
||||
|
||||
ThreadPoolManager threadPoolManager = new ThreadPoolManager();
|
||||
DefaultAsyncHttpClient httpClient = new DefaultAsyncHttpClient();
|
||||
|
||||
final Broadcaster broadcaster = BroadcastFactory.getBroadcaster(threadPoolManager,config);
|
||||
final AudioBroadcaster audioBroadcaster = BroadcastFactory.getBroadcaster(httpClient, threadPoolManager,config);
|
||||
|
||||
Path path = Paths.get("/home/denny/Music/PCM.wav");
|
||||
mLog.debug("Opening: " + path.toString());
|
||||
@@ -363,7 +357,7 @@ public class ShoutcastV1Broadcaster extends Broadcaster
|
||||
|
||||
try (AudioPacketMonoWaveReader reader = new AudioPacketMonoWaveReader(path, true))
|
||||
{
|
||||
reader.setListener(broadcaster);
|
||||
reader.setListener(audioBroadcaster);
|
||||
reader.read();
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -21,6 +21,7 @@ package audio.broadcast.shoutcast.v1;
|
||||
import audio.broadcast.BroadcastConfiguration;
|
||||
import audio.broadcast.BroadcastFormat;
|
||||
import audio.broadcast.BroadcastServerType;
|
||||
import audio.broadcast.icecast.IcecastTCPConfiguration;
|
||||
|
||||
public class ShoutcastV1Configuration extends BroadcastConfiguration
|
||||
{
|
||||
@@ -31,11 +32,40 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration
|
||||
private int mBitRate;
|
||||
private String mURL;
|
||||
|
||||
public ShoutcastV1Configuration()
|
||||
{
|
||||
//No-arg JAXB constructor
|
||||
}
|
||||
|
||||
public ShoutcastV1Configuration(BroadcastFormat format)
|
||||
{
|
||||
super(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BroadcastConfiguration copyOf()
|
||||
{
|
||||
ShoutcastV1Configuration copy = new ShoutcastV1Configuration(getBroadcastFormat());
|
||||
|
||||
//Broadcast Configuration Parameters
|
||||
copy.setName(getName());
|
||||
copy.setHost(getHost());
|
||||
copy.setPort(getPort());
|
||||
copy.setPassword(getPassword());
|
||||
copy.setDelay(getDelay());
|
||||
copy.setEnabled(false);
|
||||
|
||||
//Icecast Configuration Parameters
|
||||
copy.setStreamName(getStreamName());
|
||||
copy.setGenre(getGenre());
|
||||
copy.setPublic(isPublic());
|
||||
copy.setChannels(getChannels());
|
||||
copy.setBitRate(getBitRate());
|
||||
copy.setURL(getURL());
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BroadcastServerType getBroadcastServerType()
|
||||
{
|
||||
@@ -77,7 +107,7 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Public visibility of the broadcast
|
||||
* Public visibility of the broadcastAudio
|
||||
*/
|
||||
public boolean isPublic()
|
||||
{
|
||||
@@ -85,8 +115,8 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets public visibility of the broadcast
|
||||
* @param isPublic indicates if the broadcast should be visible to the public
|
||||
* Sets public visibility of the broadcastAudio
|
||||
* @param isPublic indicates if the broadcastAudio should be visible to the public
|
||||
*/
|
||||
public void setPublic(boolean isPublic)
|
||||
{
|
||||
@@ -94,7 +124,7 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of audio channels in the broadcast
|
||||
* Number of audio channels in the broadcastAudio
|
||||
*/
|
||||
public int getChannels()
|
||||
{
|
||||
@@ -102,7 +132,7 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of audio channels in the broadcast
|
||||
* Sets the number of audio channels in the broadcastAudio
|
||||
*/
|
||||
public void setChannels(int channels)
|
||||
{
|
||||
@@ -127,7 +157,7 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* URL associated with the broadcast where users can find additional details.
|
||||
* URL associated with the broadcastAudio where users can find additional details.
|
||||
*/
|
||||
public String getURL()
|
||||
{
|
||||
@@ -135,7 +165,7 @@ public class ShoutcastV1Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* URL associated with the broadcast where users can find additional details.
|
||||
* URL associated with the broadcastAudio where users can find additional details.
|
||||
* @param url
|
||||
*/
|
||||
public void setURL(String url)
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
package audio.broadcast.shoutcast.v2;
|
||||
|
||||
import audio.AudioPacket;
|
||||
import audio.broadcast.AudioBroadcaster;
|
||||
import audio.broadcast.BroadcastConfiguration;
|
||||
import audio.broadcast.BroadcastFormat;
|
||||
import audio.broadcast.BroadcastState;
|
||||
import audio.broadcast.Broadcaster;
|
||||
import audio.broadcast.BroadcastFactory;
|
||||
import audio.broadcast.shoutcast.v2.message.AuthenticateBroadcast;
|
||||
import audio.broadcast.shoutcast.v2.message.ConfigureIcyGenre;
|
||||
@@ -39,8 +39,9 @@ import audio.broadcast.shoutcast.v2.message.UltravoxMessageFactory;
|
||||
import audio.broadcast.shoutcast.v2.message.UltravoxMessageType;
|
||||
import audio.broadcast.shoutcast.v2.message.UltravoxMetadata;
|
||||
import audio.broadcast.shoutcast.v2.message.XMLMetadata;
|
||||
import audio.convert.IAudioConverter;
|
||||
import audio.metadata.AudioMetadata;
|
||||
import controller.ThreadPoolManager;
|
||||
import org.asynchttpclient.DefaultAsyncHttpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import properties.SystemProperties;
|
||||
@@ -57,9 +58,9 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShoutcastV2Broadcaster extends Broadcaster
|
||||
public class ShoutcastV2AudioBroadcaster extends AudioBroadcaster
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( ShoutcastV2Broadcaster.class );
|
||||
private final static Logger mLog = LoggerFactory.getLogger( ShoutcastV2AudioBroadcaster.class );
|
||||
|
||||
private static final long RECONNECT_INTERVAL_MILLISECONDS = 15000; //15 seconds
|
||||
private static final boolean GET_RESPONSE = true;
|
||||
@@ -75,13 +76,10 @@ public class ShoutcastV2Broadcaster extends Broadcaster
|
||||
/**
|
||||
* Creates a Shoutcast Version 2 broadcaster.
|
||||
* @param configuration details for shoutcast version 2
|
||||
* @param audioConverter to convert PCM audio
|
||||
*/
|
||||
public ShoutcastV2Broadcaster(ThreadPoolManager threadPoolManager,
|
||||
BroadcastConfiguration configuration,
|
||||
IAudioConverter audioConverter)
|
||||
public ShoutcastV2AudioBroadcaster(ThreadPoolManager threadPoolManager, BroadcastConfiguration configuration)
|
||||
{
|
||||
super(threadPoolManager, configuration, audioConverter);
|
||||
super(threadPoolManager, configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,41 +90,36 @@ public class ShoutcastV2Broadcaster extends Broadcaster
|
||||
return (ShoutcastV2Configuration)getBroadcastConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void broadcastMetadata(AudioMetadata metadata)
|
||||
{
|
||||
mLog.debug("Request to broadcast audio metadata to shoutcast v2 server - needs coding");
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast audio packets
|
||||
* Broadcast audio
|
||||
*/
|
||||
public void broadcast()
|
||||
@Override
|
||||
protected void broadcastAudio(byte[] audio)
|
||||
{
|
||||
//If we're connected, send the audio, otherwise discard it
|
||||
if(connect())
|
||||
{
|
||||
mAudioQueue.drainTo(mPacketsToBroadcast, 5);
|
||||
List<UltravoxMessage> audioMessages = getAudioMessages(audio);
|
||||
|
||||
if(!mPacketsToBroadcast.isEmpty())
|
||||
try
|
||||
{
|
||||
byte[] convertedAudio = getAudioConverter().convert(mPacketsToBroadcast);
|
||||
|
||||
mPacketsToBroadcast.clear();
|
||||
|
||||
if(convertedAudio != null)
|
||||
for(UltravoxMessage audioMessage: audioMessages)
|
||||
{
|
||||
List<UltravoxMessage> audioMessages = getAudioMessages(convertedAudio);
|
||||
|
||||
try
|
||||
{
|
||||
for(UltravoxMessage audioMessage: audioMessages)
|
||||
{
|
||||
send(audioMessage, NO_RESPONSE_EXPECTED);
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
mLog.error("Error while dispatching audio", e);
|
||||
setBroadcastState(BroadcastState.BROADCAST_ERROR);
|
||||
return;
|
||||
}
|
||||
send(audioMessage, NO_RESPONSE_EXPECTED);
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
mLog.error("Error while dispatching audio", e);
|
||||
setBroadcastState(BroadcastState.BROADCAST_ERROR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,13 +363,13 @@ public class ShoutcastV2Broadcaster extends Broadcaster
|
||||
response = send(icyName, NO_RESPONSE_EXPECTED);
|
||||
}
|
||||
|
||||
if (getShoutcastConfiguration().getStreamGenre() != null)
|
||||
if (getShoutcastConfiguration().getGenre() != null)
|
||||
{
|
||||
metadata.add(UltravoxMetadata.GENRE.asXML(getShoutcastConfiguration().getStreamGenre()));
|
||||
metadata.add(UltravoxMetadata.GENRE.asXML(getShoutcastConfiguration().getGenre()));
|
||||
|
||||
ConfigureIcyGenre icyGenre = (ConfigureIcyGenre) UltravoxMessageFactory
|
||||
.getMessage(UltravoxMessageType.CONFIGURE_ICY_GENRE);
|
||||
icyGenre.setGenre(getShoutcastConfiguration().getStreamGenre());
|
||||
icyGenre.setGenre(getShoutcastConfiguration().getGenre());
|
||||
response = send(icyGenre, NO_RESPONSE_EXPECTED);
|
||||
}
|
||||
|
||||
@@ -534,7 +527,7 @@ public class ShoutcastV2Broadcaster extends Broadcaster
|
||||
config.setPort(8000);
|
||||
config.setPassword("denny3");
|
||||
config.setStreamName("Denny's Audio Broadcast Test");
|
||||
config.setStreamGenre("Public Safety");
|
||||
config.setGenre("Public Safety");
|
||||
config.setPublic(true);
|
||||
config.setURL("http://localhost:8000");
|
||||
config.setBitRate(16);
|
||||
@@ -545,8 +538,9 @@ public class ShoutcastV2Broadcaster extends Broadcaster
|
||||
else
|
||||
{
|
||||
ThreadPoolManager threadPoolManager = new ThreadPoolManager();
|
||||
DefaultAsyncHttpClient httpClient = new DefaultAsyncHttpClient();
|
||||
|
||||
final Broadcaster broadcaster = BroadcastFactory.getBroadcaster(threadPoolManager,config);
|
||||
final AudioBroadcaster audioBroadcaster = BroadcastFactory.getBroadcaster(httpClient, threadPoolManager,config);
|
||||
|
||||
Path path = Paths.get("/home/denny/Music/PCM.wav");
|
||||
mLog.debug("Opening: " + path.toString());
|
||||
@@ -559,7 +553,7 @@ public class ShoutcastV2Broadcaster extends Broadcaster
|
||||
|
||||
try (AudioPacketMonoWaveReader reader = new AudioPacketMonoWaveReader(path, true))
|
||||
{
|
||||
reader.setListener(broadcaster);
|
||||
reader.setListener(audioBroadcaster);
|
||||
reader.read();
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -28,16 +28,46 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration
|
||||
private String mUserID;
|
||||
private int mBitRate;
|
||||
private String mStreamName;
|
||||
private String mStreamGenre;
|
||||
private String mGenre;
|
||||
private String mURL;
|
||||
private boolean mPublic = true;
|
||||
|
||||
public ShoutcastV2Configuration()
|
||||
{
|
||||
//No-arg JAXB constructor
|
||||
}
|
||||
|
||||
public ShoutcastV2Configuration(BroadcastFormat format)
|
||||
{
|
||||
super(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BroadcastConfiguration copyOf()
|
||||
{
|
||||
ShoutcastV2Configuration copy = new ShoutcastV2Configuration(getBroadcastFormat());
|
||||
|
||||
//Broadcast Configuration Parameters
|
||||
copy.setName(getName());
|
||||
copy.setHost(getHost());
|
||||
copy.setPort(getPort());
|
||||
copy.setPassword(getPassword());
|
||||
copy.setDelay(getDelay());
|
||||
copy.setEnabled(false);
|
||||
|
||||
//Shoutcast V2 Configuration Parameters
|
||||
copy.setStreamID(getStreamID());
|
||||
copy.setUserID(getUserID());
|
||||
copy.setBitRate(getBitRate());
|
||||
copy.setStreamName(getStreamName());
|
||||
copy.setGenre(getGenre());
|
||||
copy.setURL(getURL());
|
||||
copy.setPublic(isPublic());
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BroadcastServerType getBroadcastServerType()
|
||||
{
|
||||
@@ -117,21 +147,21 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration
|
||||
/**
|
||||
* Stream genre
|
||||
*/
|
||||
public String getStreamGenre()
|
||||
public String getGenre()
|
||||
{
|
||||
return mStreamGenre;
|
||||
return mGenre;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the genre tag for this stream
|
||||
*/
|
||||
public void setStreamGenre(String genre)
|
||||
public void setGenre(String genre)
|
||||
{
|
||||
mStreamGenre = genre;
|
||||
mGenre = genre;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public visibility of the broadcast
|
||||
* Public visibility of the broadcastAudio
|
||||
*/
|
||||
public boolean isPublic()
|
||||
{
|
||||
@@ -139,8 +169,8 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets public visibility of the broadcast
|
||||
* @param isPublic indicates if the broadcast should be visible to the public
|
||||
* Sets public visibility of the broadcastAudio
|
||||
* @param isPublic indicates if the broadcastAudio should be visible to the public
|
||||
*/
|
||||
public void setPublic(boolean isPublic)
|
||||
{
|
||||
@@ -148,7 +178,7 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* URL associated with the broadcast where users can find additional details.
|
||||
* URL associated with the broadcastAudio where users can find additional details.
|
||||
*/
|
||||
public String getURL()
|
||||
{
|
||||
@@ -156,7 +186,7 @@ public class ShoutcastV2Configuration extends BroadcastConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* URL associated with the broadcast where users can find additional details.
|
||||
* URL associated with the broadcastAudio where users can find additional details.
|
||||
* @param url
|
||||
*/
|
||||
public void setURL(String url)
|
||||
|
||||
@@ -45,7 +45,7 @@ public class StreamMimeType extends UltravoxMessage
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the broadcast format or MIME type
|
||||
* Sets the broadcastAudio format or MIME type
|
||||
* @param format of the stream
|
||||
*/
|
||||
public void setFormat(BroadcastFormat format)
|
||||
|
||||
@@ -21,7 +21,7 @@ package audio.broadcast.shoutcast.v2.message;
|
||||
public class TerminateBroadcast extends UltravoxMessage
|
||||
{
|
||||
/**
|
||||
* Client request to server to terminate the broadcast
|
||||
* Client request to server to terminate the broadcastAudio
|
||||
*
|
||||
* Package private constructor. Use the UltravoxMessageFactory for this constructor.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user