Prepare to remove this branch

This commit is contained in:
2014-10-13 22:34:27 +01:00
parent d903be9897
commit 0a9ba6d684
15 changed files with 93 additions and 74 deletions

Binary file not shown.

View File

@@ -2,7 +2,8 @@ dependencies {
compile project(':base') compile project(':base')
compile 'commons-io:commons-io:2.+' compile 'commons-io:commons-io:2.+'
compile 'commons-cli:commons-cli:1.+' compile 'commons-cli:commons-cli:1.+'
compile 'commons-pool:commons-pool:1.+'
compile 'org.slf4j:slf4j-api:1.+' compile 'org.slf4j:slf4j-api:1.+'
compile 'org.slf4j:slf4j-log4j12:1.7.5' compile 'org.slf4j:slf4j-log4j12:1.7.5'
compile 'org.ostermiller:utils:1.+' compile 'org.ostermiller:utils:1.+'

View File

@@ -1,7 +1,10 @@
package sound; package old;
import java.io.InputStream; import java.io.InputStream;
import sound.Consumer;
import sound.Producer;
public class Transducer implements Consumer, Producer { public class Transducer implements Consumer, Producer {
public int rate; public int rate;

View File

@@ -8,8 +8,10 @@ public class Client {
// Connect to the pipe // Connect to the pipe
RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\detest", "rw"); RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\detest", "rw");
String echoText = "Hello word\n"; String echoText = "Hello word\n";
// write to pipe // write to pipe
pipe.write(echoText.getBytes()); pipe.write(echoText.getBytes());
// read response // read response
String echoResponse = pipe.readLine(); String echoResponse = pipe.readLine();
System.out.println(echoResponse); System.out.println(echoResponse);

View File

@@ -1,40 +1,54 @@
package pipe; package pipe;
/** /**
*
* @author Vikram S Khatri vikram.khatri@us.ibm.com * @author Vikram S Khatri vikram.khatri@us.ibm.com
*
*/ */
public class Pipe public class Pipe {
{
static final int ERROR_PIPE_CONNECTED = 535; static final int ERROR_PIPE_CONNECTED = 535;
static final int ERROR_BROKEN_PIPE = 109; static final int ERROR_BROKEN_PIPE = 109;
static final int PIPE_ACCESS_DUPLEX = 0x00000003; static final int PIPE_ACCESS_DUPLEX = 0x00000003;
static final int PIPE_WAIT = 0x00000000; static final int PIPE_WAIT = 0x00000000;
static
{ static {
System.loadLibrary("pipe"); System.loadLibrary("pipe");
} }
public static final native int CreateNamedPipe(String pipeName, public static final native int CreateNamedPipe(
int ppenMode, int pipeMode, int maxInstances, String pipeName,
int outBufferSize, int inBufferSize, int defaultTimeOut, int ppenMode,
int pipeMode,
int maxInstances,
int outBufferSize,
int inBufferSize,
int defaultTimeOut,
int securityAttributes); int securityAttributes);
public static final native boolean ConnectNamedPipe(int namedPipeHandle, public static final native boolean ConnectNamedPipe(int namedPipeHandle, int overlapped);
int overlapped);
public static final native int GetLastError(); public static final native int GetLastError();
public static final native boolean CloseHandle(int bbject); public static final native boolean CloseHandle(int bbject);
public static final native byte[] ReadFile(int file, int numberOfBytesToRead); public static final native byte[] ReadFile(int file, int numberOfBytesToRead);
public static final native int WriteFile(int file, byte[] buffer,
int numberOfBytesToWrite); public static final native int WriteFile(int file, byte[] buffer, int numberOfBytesToWrite);
public static final native boolean FlushFileBuffers(int file); public static final native boolean FlushFileBuffers(int file);
public static final native boolean DisconnectNamedPipe(int namedPipeHandle); public static final native boolean DisconnectNamedPipe(int namedPipeHandle);
public static final native int CreateFile(String fileName,
int desiredAccess, int shareMode, int securityAttributes, public static final native int CreateFile(
int creationDisposition, int flagsAndAttributes, String fileName,
int desiredAccess,
int shareMode,
int securityAttributes,
int creationDisposition,
int flagsAndAttributes,
int templateFile); int templateFile);
public static final native boolean WaitNamedPipe(String namedPipeName, int timeOut); public static final native boolean WaitNamedPipe(String namedPipeName, int timeOut);
public static final native String FormatMessage(int errorCode); public static final native String FormatMessage(int errorCode);
public static final native void Print(String message); public static final native void Print(String message);
} }

View File

@@ -20,14 +20,19 @@ public class TestPipe {
} }
private boolean createPipe() { private boolean createPipe() {
namedPipeHandle = Pipe.CreateNamedPipe(pipeName, Pipe.PIPE_ACCESS_DUPLEX, namedPipeHandle = Pipe.CreateNamedPipe(
Pipe.PIPE_WAIT, 5, pipeBuffer, pipeBuffer, 0xffffffff, 0); pipeName,
Pipe.PIPE_ACCESS_DUPLEX,
Pipe.PIPE_WAIT,
5,
pipeBuffer,
pipeBuffer,
0xffffffff,
0);
if (namedPipeHandle == -1) { if (namedPipeHandle == -1) {
log("CreateNamedPipe failed for " + pipeName + " for error " log("CreateNamedPipe failed for " + pipeName + " for error Message " + Pipe.FormatMessage(Pipe.GetLastError()));
+ " Message " + Pipe.FormatMessage(Pipe.GetLastError()));
} else { } else {
log("Named Pipe " + pipeName + " created successfully Handle=" log("Named Pipe " + pipeName + " created successfully Handle=" + namedPipeHandle);
+ namedPipeHandle);
} }
return namedPipeHandle != -1; return namedPipeHandle != -1;
} }
@@ -40,8 +45,7 @@ public class TestPipe {
if (lastError == Pipe.ERROR_PIPE_CONNECTED) if (lastError == Pipe.ERROR_PIPE_CONNECTED)
connected = true; connected = true;
} }
log((connected ? "Connected to the pipe " log((connected ? "Connected to the pipe " : "Falied to connect to the pipe ") + pipeName);
: "Falied to connect to the pipe ") + pipeName);
return connected; return connected;
} }
@@ -56,12 +60,10 @@ public class TestPipe {
int len, bytesWritten; int len, bytesWritten;
while ((len = in.read(buf)) > 0) { while ((len = in.read(buf)) > 0) {
bytesWritten = Pipe.WriteFile(namedPipeHandle, buf, len); bytesWritten = Pipe.WriteFile(namedPipeHandle, buf, len);
log("Sent " + len + "/" + bytesWritten log("Sent " + len + "/" + bytesWritten + " bytes to the pipe");
+ " bytes to the pipe");
if (bytesWritten == -1) { if (bytesWritten == -1) {
int errorNumber = Pipe.GetLastError(); int errorNumber = Pipe.GetLastError();
log("Error Writing to pipe " log("Error Writing to pipe " + Pipe.FormatMessage(errorNumber));
+ Pipe.FormatMessage(errorNumber));
} }
} }
in.close(); in.close();
@@ -77,8 +79,8 @@ public class TestPipe {
public static void main(String[] args) { public static void main(String[] args) {
String pipeName = "\\\\.\\pipe\\detest"; String pipeName = "\\\\.\\pipe\\detest";
String fileName = "bla.txt"; String fileName = "txt/bla.txt";
fileName = "C:\\Users\\Rik\\Music\\Artists\\+44\\When Your Heart Stops Beating\\+44 - 155.mp3"; //fileName = "C:\\Users\\Rik\\Music\\Artists\\+44\\When Your Heart Stops Beating\\+44 - 155.mp3";
TestPipe testPipe = new TestPipe(pipeName, fileName); TestPipe testPipe = new TestPipe(pipeName, fileName);
testPipe.runPipe(); testPipe.runPipe();
} }

View File

@@ -2,7 +2,6 @@ package sound;
public interface Consumer { public interface Consumer {
public void start(Producer producer); public void start(Producer producer);
public void start();
public void stop(); public void stop();
public void exit(); public void exit();
} }

View File

@@ -22,7 +22,7 @@ public class Source implements Consumer {
protected Logger logger = LoggerFactory.getLogger(getClass()); protected Logger logger = LoggerFactory.getLogger(getClass());
protected static final int BUFFER_SIZE = 1024 * 4; // in bytes protected static final int BUFFER_SIZE = 1024 * 4; // in bytes
protected static final int PLAY_FRAMES = 10; // count protected static final int FRAMES = 10; // count
protected String name; protected String name;
protected Producer producer; protected Producer producer;
@@ -147,9 +147,9 @@ public class Source implements Consumer {
try { try {
if (player == null) { if (player == null) {
player = new Player(producerInputStream); player = new Player(producerInputStream);
sleep(500); sleep(SLEEP);
} }
player.play(PLAY_FRAMES); player.play(FRAMES);
} catch (JavaLayerException e) { } catch (JavaLayerException e) {
logger.error("", e); logger.error("", e);
} }

View File

@@ -36,8 +36,12 @@ public class Port extends Worker implements Consumer {
this.device = device; this.device = device;
} }
@SuppressWarnings("static-access")
public void start(Producer producer) { public void start(Producer producer) {
start(producer, THREAD);
}
@SuppressWarnings("static-access")
public void start(Producer producer, boolean thread) {
this.producer = producer; this.producer = producer;
producerInputStream = producer.getInputStream(); producerInputStream = producer.getInputStream();
@@ -57,7 +61,7 @@ public class Port extends Worker implements Consumer {
processBuilder = new ProcessBuilder(command.split(" ")); processBuilder = new ProcessBuilder(command.split(" "));
processBuilder.environment().put("AUDIODEV", device); processBuilder.environment().put("AUDIODEV", device);
start(true); start(thread);
} }
protected void activate() throws ActivateException { protected void activate() throws ActivateException {
@@ -114,16 +118,4 @@ public class Port extends Worker implements Consumer {
exit(); exit();
} }
} }
@Override
public void start() {
// TODO Auto-generated method stub
}
@Override
public void stop() {
// TODO Auto-generated method stub
}
} }

View File

@@ -8,8 +8,8 @@ import java.net.Socket;
import java.net.URL; import java.net.URL;
import sound.Format; import sound.Format;
import sound.GreedyInputStream;
import sound.Producer; import sound.Producer;
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.Worker;
@@ -24,7 +24,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
protected Socket socket; protected Socket socket;
protected InputStream socketInputStream; protected InputStream socketInputStream;
protected OutputStreamWriter socketOutputStreamWriter; protected OutputStreamWriter socketOutputStreamWriter;
protected GreedyInputStream greedyInputStream; protected HoardedInputStream hoardedInputStream;
protected int meta; protected int meta;
protected int rate; protected int rate;
protected int chunk; protected int chunk;
@@ -115,7 +115,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
audioCircularByteBuffer.clear(); audioCircularByteBuffer.clear();
metaCircularObjectBuffer.clear(); metaCircularObjectBuffer.clear();
try { try {
greedyInputStream.clear(); hoardedInputStream.clear();
} catch (IOException e) { } catch (IOException e) {
logger.error("", e); logger.error("", e);
throw new DeactivateException(); throw new DeactivateException();
@@ -183,10 +183,10 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
} }
public InputStream getInputStream() { public InputStream getInputStream() {
if (greedyInputStream == null) { if (hoardedInputStream == null) {
greedyInputStream = new GreedyInputStream(audioCircularByteBuffer.getInputStream()); hoardedInputStream = new HoardedInputStream(audioCircularByteBuffer.getInputStream());
} }
return greedyInputStream; return hoardedInputStream;
} }
public CircularObjectBuffer<String> getMetaBufferStream() { public CircularObjectBuffer<String> getMetaBufferStream() {

View File

@@ -1,4 +1,4 @@
package sound; package sound.producer;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -10,6 +10,9 @@ import javax.sound.sampled.TargetDataLine;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import sound.Format;
import sound.Producer;
import sound.stream.HoardedInputStream;
import sound.util.Tool; import sound.util.Tool;
public class Target implements Producer, Format.Standard { public class Target implements Producer, Format.Standard {
@@ -19,6 +22,7 @@ public class Target implements Producer, Format.Standard {
protected TargetDataLine line; protected TargetDataLine line;
protected InputStream targetInputStream; protected InputStream targetInputStream;
protected HoardedInputStream hoardedInputStream;
protected AudioFormat audioFormat; protected AudioFormat audioFormat;

View File

@@ -1,4 +1,4 @@
package sound; package sound.stream;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
@@ -7,7 +7,7 @@ import java.io.InputStream;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class GreedyInputStream extends BufferedInputStream { public class HoardedInputStream extends BufferedInputStream {
protected Logger logger = LoggerFactory.getLogger(getClass()); protected Logger logger = LoggerFactory.getLogger(getClass());
protected static final int SLEEP = 500; // in milliseconds protected static final int SLEEP = 500; // in milliseconds
@@ -18,17 +18,17 @@ public class GreedyInputStream extends BufferedInputStream {
protected int minimumSize; protected int minimumSize;
protected boolean hoard; protected boolean hoard;
public GreedyInputStream(InputStream inputStream) { public HoardedInputStream(InputStream inputStream) {
this(inputStream, BUFFER_SIZE, MINIMUM_SIZE); this(inputStream, BUFFER_SIZE, MINIMUM_SIZE);
} }
public GreedyInputStream(InputStream inputStream, int bufferSize) { public HoardedInputStream(InputStream inputStream, int bufferSize) {
super(inputStream, bufferSize); super(inputStream, bufferSize);
this.bufferSize = bufferSize; this.bufferSize = bufferSize;
hoard = true; hoard = true;
} }
public GreedyInputStream(InputStream inputStream, int bufferSize, int minimumSize) { public HoardedInputStream(InputStream inputStream, int bufferSize, int minimumSize) {
this(inputStream, bufferSize); this(inputStream, bufferSize);
this.minimumSize = minimumSize; this.minimumSize = minimumSize;
} }
@@ -63,7 +63,7 @@ public class GreedyInputStream extends BufferedInputStream {
public void clear() throws IOException { public void clear() throws IOException {
this.buf = new byte[buf.length]; this.buf = new byte[buf.length];
reset(); reset();
} }
public void drain() { public void drain() {

View File

@@ -29,7 +29,7 @@ public class Tool {
static { static {
Tool tool = new Tool(); Tool tool = new Tool();
targetMap = new HashMap<String, Device<TargetDataLine>>(); targetMap = new HashMap<String, Device<TargetDataLine>>();
sourceMap = new HashMap<String, Device<SourceDataLine>>(); sourceMap = new HashMap<String, Device<SourceDataLine>>();
targetList = new ArrayList<String>(); targetList = new ArrayList<String>();

View File

@@ -15,12 +15,9 @@ public class Utils {
public static void play(InputStream inputStream) { public static void play(InputStream inputStream) {
try { try {
Thread.sleep(5000);
new Player(new BufferedInputStream(inputStream)).play(); new Player(new BufferedInputStream(inputStream)).play();
} catch (JavaLayerException e) { } catch (JavaLayerException e) {
e.printStackTrace(); e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} }
} }

View File

@@ -1,14 +1,18 @@
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.Target; import sound.consumer.Player;
import sound.consumer.Port; import sound.consumer.Port;
import sound.consumer.Shoutcast; 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) {
@@ -16,23 +20,24 @@ public class Test {
try { try {
//Producer p1 = new Target("Line-In (Creative SB X-Fi)"); //Producer p1 = new Target("Line-In (Creative SB X-Fi)");
Producer p2 = new Target("Line 1 (Virtual Audio Cable)", audioFormat); Producer p2 = new Target("Line 1 (Virtual Audio Cable)", audioFormat);
p2.start();
Producer p3 = new Stream("http://ics2gss.omroep.nl:80/3fm-bb-mp3"); Producer p3 = new Stream("http://ics2gss.omroep.nl:80/3fm-bb-mp3");
Producer p4 = new Stream("http://sc7.mystreamserver.com:8004"); Producer p4 = new Stream("http://sc7.mystreamserver.com:8004");
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 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());
c3.start(p3); c3.start(p3);
while (true) { //while (true) {
Thread.sleep(3000); //Thread.sleep(300000);
c2.stop(); //c1.stop();
Thread.sleep(1000); //}
c2.start();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }