Lost shoutcast server implementation, reorganise some code
This commit is contained in:
@@ -11,11 +11,11 @@ import javazoom.jl.decoder.Bitstream;
|
|||||||
import javazoom.jl.decoder.BitstreamException;
|
import javazoom.jl.decoder.BitstreamException;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.worker.Worker;
|
import base.worker.ThreadWorker;
|
||||||
|
|
||||||
import com.Ostermiller.util.CircularByteBuffer;
|
import com.Ostermiller.util.CircularByteBuffer;
|
||||||
|
|
||||||
public class Converter extends Worker {
|
public class Converter extends ThreadWorker {
|
||||||
public static final String COMMAND = "lame --mp3input --cbr %s - - --quiet";
|
public static final String COMMAND = "lame --mp3input --cbr %s - - --quiet";
|
||||||
public static final int BYTES = 4096; // bytes
|
public static final int BYTES = 4096; // bytes
|
||||||
public static final int BUFFER = 30000; // milliseconds
|
public static final int BUFFER = 30000; // milliseconds
|
||||||
@@ -156,7 +156,7 @@ public class Converter extends Worker {
|
|||||||
this.inputStream = inputStream;
|
this.inputStream = inputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
class BufferWorker extends Worker {
|
class BufferWorker extends ThreadWorker {
|
||||||
protected void work() {
|
protected void work() {
|
||||||
byte[] bytes = new byte[BYTES];
|
byte[] bytes = new byte[BYTES];
|
||||||
int read = 0;
|
int read = 0;
|
||||||
|
|||||||
@@ -8,14 +8,15 @@ import java.io.OutputStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import sound.consumer.Shoutcast;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.worker.Worker;
|
import base.worker.ThreadWorker;
|
||||||
|
|
||||||
import com.Ostermiller.util.BufferOverflowException;
|
import com.Ostermiller.util.BufferOverflowException;
|
||||||
import com.Ostermiller.util.CircularByteBuffer;
|
import com.Ostermiller.util.CircularByteBuffer;
|
||||||
import com.Ostermiller.util.CircularObjectBuffer;
|
import com.Ostermiller.util.CircularObjectBuffer;
|
||||||
|
|
||||||
public class List extends Worker {
|
public class List extends ThreadWorker {
|
||||||
public static final int STEP = 80; // milliseconds
|
public static final int STEP = 80; // milliseconds
|
||||||
public static final int RATE = 192; // kbps
|
public static final int RATE = 192; // kbps
|
||||||
public static final int OVERLAP = 20000; // milliseconds
|
public static final int OVERLAP = 20000; // milliseconds
|
||||||
@@ -184,10 +185,10 @@ public class List extends Worker {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int rate = 192;
|
int rate = 192;
|
||||||
List list = new List(new File("mp3"), rate);
|
List list = new List(new File("mp3"), rate);
|
||||||
/*Shoutcast shoutcast = new Shoutcast(null, rate, 9876);
|
Shoutcast shoutcast = new Shoutcast(rate, 9876);
|
||||||
shoutcast.start();
|
shoutcast.start();
|
||||||
shoutcast.setInputStream(list.getInputStream());
|
shoutcast.setInputStream(list.getInputStream());
|
||||||
shoutcast.setMetaBuffer(list.getMetaBuffer());*/
|
shoutcast.setMetaBuffer(list.getMetaBuffer());
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(15000);
|
Thread.sleep(15000);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import sound.util.Tool;
|
import sound.util.Tool;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.worker.Worker;
|
import base.worker.ThreadWorker;
|
||||||
|
|
||||||
public class Source implements Consumer {
|
public class Source implements Consumer {
|
||||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
@@ -27,7 +27,7 @@ public class Source implements Consumer {
|
|||||||
protected String name;
|
protected String name;
|
||||||
protected Producer producer;
|
protected Producer producer;
|
||||||
protected InputStream producerInputStream;
|
protected InputStream producerInputStream;
|
||||||
protected Worker worker;
|
protected ThreadWorker worker;
|
||||||
|
|
||||||
public Source(String name) throws LineUnavailableException {
|
public Source(String name) throws LineUnavailableException {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -67,7 +67,7 @@ public class Source implements Consumer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class DefaultWorker extends Worker {
|
protected class DefaultWorker extends ThreadWorker {
|
||||||
protected Format.Standard format;
|
protected Format.Standard format;
|
||||||
protected SourceDataLine line;
|
protected SourceDataLine line;
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ public class Source implements Consumer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class Mp3Worker extends Worker {
|
protected class Mp3Worker extends ThreadWorker {
|
||||||
protected Format.Mp3 format;
|
protected Format.Mp3 format;
|
||||||
protected Player player;
|
protected Player player;
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import sound.util.SoxBuilder.File.Type;
|
|||||||
import sound.util.SoxBuilder.Option;
|
import sound.util.SoxBuilder.Option;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.worker.Worker;
|
import base.worker.ThreadWorker;
|
||||||
|
|
||||||
public class Port extends Worker implements Consumer {
|
public class Port extends ThreadWorker implements Consumer {
|
||||||
protected static final int BUFFER_SIZE = 1024 * 4; // in bytes
|
protected static final int BUFFER_SIZE = 1024 * 4; // in bytes
|
||||||
|
|
||||||
protected String device;
|
protected String device;
|
||||||
|
|||||||
72
java/sound/src/main/java/sound/consumer/Shoutcast.java
Normal file
72
java/sound/src/main/java/sound/consumer/Shoutcast.java
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package sound.consumer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
import base.server.TcpServer;
|
||||||
|
|
||||||
|
import com.Ostermiller.util.CircularObjectBuffer;
|
||||||
|
|
||||||
|
public class Shoutcast extends TcpServer {
|
||||||
|
protected int metadataInterval = 8192;
|
||||||
|
protected int rate;
|
||||||
|
protected CircularObjectBuffer<String> metaBuffer;
|
||||||
|
protected InputStream inputStream;
|
||||||
|
|
||||||
|
public Shoutcast(int rate, int port) {
|
||||||
|
super(port, ShoutcastClient.class);
|
||||||
|
this.rate = rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void x() {
|
||||||
|
// Accept new clients
|
||||||
|
// Transfer buffer
|
||||||
|
|
||||||
|
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
response.append("HTTP/1.1 200 OK\r\nContent-Type: audio/mpeg\r\n");
|
||||||
|
|
||||||
|
// add the stream name
|
||||||
|
response.append("icy-name: " + "hallo" + "\r\n");
|
||||||
|
|
||||||
|
// add metadata information
|
||||||
|
response.append("icy-metadata:1\r\n");
|
||||||
|
response.append("icy-metaint:");
|
||||||
|
response.append(metadataInterval );
|
||||||
|
response.append("\r\n");
|
||||||
|
|
||||||
|
response.append("\r\n");
|
||||||
|
|
||||||
|
//out.write(response.toString().getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInputStream(InputStream inputStream) {
|
||||||
|
this.inputStream = inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetaBuffer(CircularObjectBuffer<String> metaBuffer) {
|
||||||
|
this.metaBuffer = metaBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ShoutcastClient extends TcpServer.Client {
|
||||||
|
int untilMeta = 0;
|
||||||
|
|
||||||
|
public ShoutcastClient(Socket socket) {
|
||||||
|
super(socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void work() {
|
||||||
|
//
|
||||||
|
byte[] buffer = new byte[123];
|
||||||
|
try {
|
||||||
|
outputStream.write(buffer);
|
||||||
|
// Write some meta
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,12 +12,12 @@ import sound.Producer;
|
|||||||
import sound.stream.HoardedInputStream;
|
import sound.stream.HoardedInputStream;
|
||||||
import base.exception.worker.ActivateException;
|
import base.exception.worker.ActivateException;
|
||||||
import base.exception.worker.DeactivateException;
|
import base.exception.worker.DeactivateException;
|
||||||
import base.worker.Worker;
|
import base.worker.ThreadWorker;
|
||||||
|
|
||||||
import com.Ostermiller.util.CircularByteBuffer;
|
import com.Ostermiller.util.CircularByteBuffer;
|
||||||
import com.Ostermiller.util.CircularObjectBuffer;
|
import com.Ostermiller.util.CircularObjectBuffer;
|
||||||
|
|
||||||
public class Stream extends Worker implements Producer, Format.Mp3 {
|
public class Stream extends ThreadWorker implements Producer, Format.Mp3 {
|
||||||
public static final int STEP = 80; // in milliseconds
|
public static final int STEP = 80; // in milliseconds
|
||||||
|
|
||||||
protected String http;
|
protected String http;
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.sound.sampled.AudioFormat;
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
|
||||||
import sound.Consumer;
|
import sound.Consumer;
|
||||||
import sound.Producer;
|
import sound.Producer;
|
||||||
import sound.Source;
|
import sound.Source;
|
||||||
import sound.consumer.Player;
|
|
||||||
import sound.consumer.Port;
|
import sound.consumer.Port;
|
||||||
import sound.consumer.Shoutcast;
|
|
||||||
import sound.consumer.Writer;
|
|
||||||
import sound.producer.Stream;
|
import sound.producer.Stream;
|
||||||
import sound.producer.Target;
|
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -26,13 +20,13 @@ public class Test {
|
|||||||
|
|
||||||
Consumer c1 = new Source("Java Sound Audio Engine");
|
Consumer c1 = new Source("Java Sound Audio Engine");
|
||||||
Consumer c2 = new Port("Speakers (Creative SB X-Fi)");
|
Consumer c2 = new Port("Speakers (Creative SB X-Fi)");
|
||||||
Consumer c3 = new Shoutcast();
|
//Consumer c3 = new Shoutcast();
|
||||||
Consumer c4 = new Player();
|
//Consumer c4 = new Player();
|
||||||
Consumer c5 = new Writer(new File("stream.out"));
|
//Consumer c5 = new Writer(new File("stream.out"));
|
||||||
|
|
||||||
//Utils.write(p3.getInputStream(), new File("stream.out"));
|
//Utils.write(p3.getInputStream(), new File("stream.out"));
|
||||||
//Utils.play(p3.getInputStream());
|
//Utils.play(p3.getInputStream());
|
||||||
c4.start(p3);
|
c1.start(p3);
|
||||||
|
|
||||||
//while (true) {
|
//while (true) {
|
||||||
//Thread.sleep(300000);
|
//Thread.sleep(300000);
|
||||||
|
|||||||
Reference in New Issue
Block a user