migrated sound branch to gradle project structure
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?>
|
||||
|
||||
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="cdt.managedbuild.config.gnu.mingw.so.debug.1813551917">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.mingw.so.debug.1813551917" moduleId="org.eclipse.cdt.core.settings" name="Debug">
|
||||
@@ -92,7 +90,7 @@
|
||||
<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.so.release.1271980283" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.so.release">
|
||||
<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.so.release.368721242" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.so.release"/>
|
||||
<builder buildPath="${workspace_loc:/Pipe/Release}" id="cdt.managedbuild.tool.gnu.builder.mingw.base.2065732021" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.assembler.mingw.so.release.109377381" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.so.release">
|
||||
<tool command="as" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.assembler.mingw.so.release.109377381" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.so.release">
|
||||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.689046683" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.1183393349" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
|
||||
|
||||
27
cpp/pipe/.project
Normal file
27
cpp/pipe/.project
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>pipe library</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
Binary file not shown.
BIN
cpp/pipe/Release/src/pipe.o
Normal file
BIN
cpp/pipe/Release/src/pipe.o
Normal file
Binary file not shown.
6611
cpp/pipe/include/strsafe.h
Normal file
6611
cpp/pipe/include/strsafe.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
java/pipe.dll
Normal file
BIN
java/pipe.dll
Normal file
Binary file not shown.
@@ -1 +1 @@
|
||||
include "mimis", "wiiusej", "wiigee", "itunescontroller"
|
||||
include "mimis", "wiiusej", "wiigee", "itunescontroller", "sound"
|
||||
@@ -1,11 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="lib" path="lib/jl1.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ostermillerutils-1.08.01.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-io-2.4.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-cli-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jid3lib-0.5.4.jar"/>
|
||||
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/mimis"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Sound</name>
|
||||
<name>sound</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
@@ -12,6 +12,10 @@
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
|
||||
</linkedResources>
|
||||
</projectDescription>
|
||||
|
||||
11
java/sound/build.gradle
Normal file
11
java/sound/build.gradle
Normal file
@@ -0,0 +1,11 @@
|
||||
dependencies {
|
||||
compile project(':mimis')
|
||||
|
||||
compile 'commons-io:commons-io:2.+'
|
||||
compile 'commons-cli:commons-cli:1.+'
|
||||
compile 'org.slf4j:slf4j-api:1.+'
|
||||
compile 'org.slf4j:slf4j-log4j12:1.7.5'
|
||||
compile 'org.ostermiller:utils:1.+'
|
||||
compile 'com.googlecode.soundlibs:jlayer:1.+'
|
||||
compile 'net.sf.javamusictag:jid3lib:0.+'
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -55,19 +55,19 @@ public class Converter extends Worker {
|
||||
rate = bitStream.readFrame().bitrate() / 1000;
|
||||
buffer = BUFFER * rate / 8;
|
||||
} catch (BitstreamException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
|
||||
/* Check for need to convert */
|
||||
if (targetRate < 0 || rate == targetRate) {
|
||||
log.debug("No conversion required");
|
||||
logger.debug("No conversion required");
|
||||
inputStream = sourceInputStream;
|
||||
} else {
|
||||
log.debug("Converting from " + rate + "kbps to " + targetRate + "kbps");
|
||||
logger.debug("Converting from " + rate + "kbps to " + targetRate + "kbps");
|
||||
try {
|
||||
String command = String.format(COMMAND, rate > targetRate ? "-B " + targetRate : "-F -b " + targetRate);
|
||||
log.debug("Starting process: " + command);
|
||||
logger.debug("Starting process: " + command);
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
processInputStream = process.getInputStream();
|
||||
processOutputStream = process.getOutputStream();
|
||||
@@ -78,7 +78,7 @@ public class Converter extends Worker {
|
||||
bufferWorker.start();
|
||||
convert = true;
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class Converter extends Worker {
|
||||
}
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
throw new DeactivateException();
|
||||
}
|
||||
}
|
||||
@@ -109,30 +109,30 @@ public class Converter extends Worker {
|
||||
wait();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
byte[] bytes = new byte[BYTES];
|
||||
int read = 0;
|
||||
try {
|
||||
log.debug("Writing input to process");
|
||||
logger.debug("Writing input to process");
|
||||
while ((read = sourceInputStream.read(bytes)) > 0 && !deactivate) {
|
||||
/* Limit buffer size */
|
||||
while (inputStream.available() > buffer) {
|
||||
int progress = (int) ((1 - (inputStream.available() - buffer) / (float) buffer) * 100);
|
||||
log.trace("Waiting for buffer to empty: " + progress + "%");
|
||||
logger.trace("Waiting for buffer to empty: " + progress + "%");
|
||||
sleep(BUFFERING);
|
||||
}
|
||||
processOutputStream.write(bytes, 0, read);
|
||||
}
|
||||
processOutputStream.close();
|
||||
log.debug("Stopped writing input to process");
|
||||
logger.debug("Stopped writing input to process");
|
||||
process.waitFor();
|
||||
log.debug("Process finished");
|
||||
logger.debug("Process finished");
|
||||
} catch (IOException e) {
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
stop();
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public class Converter extends Worker {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
return inputStream;
|
||||
@@ -161,11 +161,11 @@ public class Converter extends Worker {
|
||||
int read = 0;
|
||||
try {
|
||||
OutputStream bufferOutputStream = circularByteBuffer.getOutputStream();
|
||||
log.debug("Start buffering process output");
|
||||
logger.debug("Start buffering process output");
|
||||
while ((read = processInputStream.read(bytes, 0, BYTES)) > 0) {
|
||||
bufferOutputStream.write(bytes, 0, read);
|
||||
}
|
||||
log.debug("Finished buffering process output");
|
||||
logger.debug("Finished buffering process output");
|
||||
bufferOutputStream.close();
|
||||
} catch (IOException e) {}
|
||||
stop();
|
||||
@@ -78,7 +78,7 @@ public class List extends Worker {
|
||||
return;
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
throw new ActivateException();
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class List extends Worker {
|
||||
setNext();
|
||||
swap();
|
||||
} catch (IllegalStateException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
sleep(STEP);
|
||||
}
|
||||
@@ -124,21 +124,21 @@ public class List extends Worker {
|
||||
|
||||
public synchronized void setNext() {
|
||||
if (nextMp3 == null) {
|
||||
log.debug("Initialize next mp3");
|
||||
logger.debug("Initialize next mp3");
|
||||
nextMp3 = new Mp3(getRandomFile(), rate);
|
||||
} else if (next) {
|
||||
log.debug("Load next mp3");
|
||||
logger.debug("Load next mp3");
|
||||
nextMp3.setFile(getRandomFile());
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void next() {
|
||||
log.debug("Stop current mp3");
|
||||
logger.debug("Stop current mp3");
|
||||
mp3.stop();
|
||||
}
|
||||
|
||||
public void swap() {
|
||||
log.debug("Swap to next mp3");
|
||||
logger.debug("Swap to next mp3");
|
||||
Mp3 swapMp3 = mp3;
|
||||
mp3 = nextMp3;
|
||||
nextMp3 = swapMp3;
|
||||
@@ -149,11 +149,11 @@ public class List extends Worker {
|
||||
try {
|
||||
circularStringBuffer.write(mp3.getTitle());
|
||||
} catch (BufferOverflowException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
} catch (IllegalStateException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class List extends Worker {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
return circularByteBuffer.getInputStream();
|
||||
@@ -175,7 +175,7 @@ public class List extends Worker {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
return circularStringBuffer;
|
||||
@@ -29,7 +29,7 @@ public class Mp3 extends Converter {
|
||||
try {
|
||||
sourceInputStream = new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ public class Mp3 extends Converter {
|
||||
} else {
|
||||
title = String.format("%s - %s {%s}", artist, track, album);
|
||||
}
|
||||
log.debug("Title: " + title);
|
||||
logger.debug("Title: " + title);
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
} catch (TagException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
try {
|
||||
sourceInputStream.skip(100000);
|
||||
22
java/sound/src/main/java/pipe/Client.java
Normal file
22
java/sound/src/main/java/pipe/Client.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package pipe;
|
||||
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
public class Client {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Connect to the pipe
|
||||
RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\detest", "rw");
|
||||
String echoText = "Hello word\n";
|
||||
// write to pipe
|
||||
pipe.write(echoText.getBytes());
|
||||
// read response
|
||||
String echoResponse = pipe.readLine();
|
||||
System.out.println(echoResponse);
|
||||
pipe.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
40
java/sound/src/main/java/pipe/Pipe.java
Normal file
40
java/sound/src/main/java/pipe/Pipe.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package pipe;
|
||||
/**
|
||||
*
|
||||
* @author Vikram S Khatri vikram.khatri@us.ibm.com
|
||||
*
|
||||
*/
|
||||
public class Pipe
|
||||
{
|
||||
static final int ERROR_PIPE_CONNECTED = 535;
|
||||
static final int ERROR_BROKEN_PIPE = 109;
|
||||
static final int PIPE_ACCESS_DUPLEX = 0x00000003;
|
||||
static final int PIPE_WAIT = 0x00000000;
|
||||
static
|
||||
{
|
||||
System.loadLibrary("pipe");
|
||||
}
|
||||
|
||||
public static final native int CreateNamedPipe(String pipeName,
|
||||
int ppenMode, int pipeMode, int maxInstances,
|
||||
int outBufferSize, int inBufferSize, int defaultTimeOut,
|
||||
int securityAttributes);
|
||||
|
||||
public static final native boolean ConnectNamedPipe(int namedPipeHandle,
|
||||
int overlapped);
|
||||
public static final native int GetLastError();
|
||||
public static final native boolean CloseHandle(int bbject);
|
||||
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 boolean FlushFileBuffers(int file);
|
||||
public static final native boolean DisconnectNamedPipe(int namedPipeHandle);
|
||||
public static final native int CreateFile(String fileName,
|
||||
int desiredAccess, int shareMode, int securityAttributes,
|
||||
int creationDisposition, int flagsAndAttributes,
|
||||
int templateFile);
|
||||
|
||||
public static final native boolean WaitNamedPipe(String namedPipeName, int timeOut);
|
||||
public static final native String FormatMessage(int errorCode);
|
||||
public static final native void Print(String message);
|
||||
}
|
||||
85
java/sound/src/main/java/pipe/TestPipe.java
Normal file
85
java/sound/src/main/java/pipe/TestPipe.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package pipe;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class TestPipe {
|
||||
|
||||
private int namedPipeHandle;
|
||||
private String pipeName, srcFile;
|
||||
private int pipeBuffer = 131072, fileBuffer = 8192;
|
||||
|
||||
public TestPipe(String pipeName, String srcFile) {
|
||||
this.pipeName = pipeName;
|
||||
this.srcFile = srcFile;
|
||||
}
|
||||
|
||||
private void log(String message) {
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
private boolean createPipe() {
|
||||
namedPipeHandle = Pipe.CreateNamedPipe(pipeName, Pipe.PIPE_ACCESS_DUPLEX,
|
||||
Pipe.PIPE_WAIT, 5, pipeBuffer, pipeBuffer, 0xffffffff, 0);
|
||||
if (namedPipeHandle == -1) {
|
||||
log("CreateNamedPipe failed for " + pipeName + " for error "
|
||||
+ " Message " + Pipe.FormatMessage(Pipe.GetLastError()));
|
||||
} else {
|
||||
log("Named Pipe " + pipeName + " created successfully Handle="
|
||||
+ namedPipeHandle);
|
||||
}
|
||||
return namedPipeHandle != -1;
|
||||
}
|
||||
|
||||
private boolean connectToPipe() {
|
||||
log("Waiting for a client to connect to pipe " + pipeName);
|
||||
boolean connected = Pipe.ConnectNamedPipe(namedPipeHandle, 0);
|
||||
if (!connected) {
|
||||
int lastError = Pipe.GetLastError();
|
||||
if (lastError == Pipe.ERROR_PIPE_CONNECTED)
|
||||
connected = true;
|
||||
}
|
||||
log((connected ? "Connected to the pipe "
|
||||
: "Falied to connect to the pipe ") + pipeName);
|
||||
return connected;
|
||||
}
|
||||
|
||||
public void runPipe() {
|
||||
if (createPipe() && connectToPipe()) {
|
||||
log("Client connected.");
|
||||
try {
|
||||
File f1 = new File(this.srcFile);
|
||||
InputStream in = new FileInputStream(f1);
|
||||
log("Sending data to the pipe");
|
||||
byte[] buf = new byte[fileBuffer];
|
||||
int len, bytesWritten;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
bytesWritten = Pipe.WriteFile(namedPipeHandle, buf, len);
|
||||
log("Sent " + len + "/" + bytesWritten
|
||||
+ " bytes to the pipe");
|
||||
if (bytesWritten == -1) {
|
||||
int errorNumber = Pipe.GetLastError();
|
||||
log("Error Writing to pipe "
|
||||
+ Pipe.FormatMessage(errorNumber));
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
Pipe.FlushFileBuffers(namedPipeHandle);
|
||||
Pipe.CloseHandle(namedPipeHandle);
|
||||
Pipe.DisconnectNamedPipe(namedPipeHandle);
|
||||
log("Writing to the pipe completed.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String pipeName = "\\\\.\\pipe\\detest";
|
||||
String fileName = "bla.txt";
|
||||
fileName = "C:\\Users\\Rik\\Music\\Artists\\+44\\When Your Heart Stops Beating\\+44 - 155.mp3";
|
||||
TestPipe testPipe = new TestPipe(pipeName, fileName);
|
||||
testPipe.runPipe();
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GreedyInputStream extends BufferedInputStream {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected static final int SLEEP = 500;
|
||||
protected static final int BUFFER_SIZE = 30000; // in bytes
|
||||
@@ -54,10 +54,10 @@ public class GreedyInputStream extends BufferedInputStream {
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
} catch (InterruptedException e) {
|
||||
log.warn(e);
|
||||
logger.warn("", e);
|
||||
}
|
||||
} while (available() < BUFFER_SIZE);
|
||||
log.debug(String.format("Buffered %d bytes in %s milliseconds", BUFFER_SIZE - available, System.currentTimeMillis() - time));
|
||||
logger.debug(String.format("Buffered %d bytes in %s milliseconds", BUFFER_SIZE - available, System.currentTimeMillis() - time));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,18 +9,12 @@ import javax.sound.sampled.AudioFormat;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import sound.Format.Standard;
|
||||
import sound.SoxBuilder.File;
|
||||
import sound.SoxBuilder.Option;
|
||||
import sound.SoxBuilder.File.Type;
|
||||
import sound.SoxBuilder.Option;
|
||||
|
||||
public class Port extends Worker implements Consumer {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
protected static final int BUFFER_SIZE = 1024 * 4; // in bytes
|
||||
|
||||
protected String device;
|
||||
@@ -55,7 +49,7 @@ public class Port extends Worker implements Consumer {
|
||||
.addFile(File.setType(Type.DEVICE))
|
||||
.build();
|
||||
|
||||
log.debug(String.format("Build process (\"%s\")", command));
|
||||
logger.debug(String.format("Build process (\"%s\")", command));
|
||||
processBuilder = new ProcessBuilder(command.split(" "));
|
||||
processBuilder.environment().put("AUDIODEV", device);
|
||||
|
||||
@@ -68,7 +62,7 @@ public class Port extends Worker implements Consumer {
|
||||
try {
|
||||
process = processBuilder.start();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
processOutputStream = process.getOutputStream();
|
||||
@@ -81,22 +75,22 @@ public class Port extends Worker implements Consumer {
|
||||
try {
|
||||
processOutputStream.flush();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
throw new DeactivateException();
|
||||
}
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
try {
|
||||
log.debug("close process output stream");
|
||||
logger.debug("close process output stream");
|
||||
processOutputStream.close();
|
||||
|
||||
log.debug("wait for process to terminate");
|
||||
logger.debug("wait for process to terminate");
|
||||
process.waitFor();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
} finally {
|
||||
process = null;
|
||||
}
|
||||
@@ -112,8 +106,20 @@ public class Port extends Worker implements Consumer {
|
||||
exit();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,11 @@ import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Source implements Consumer {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected static final int BUFFER_SIZE = 1024 * 4; // in bytes
|
||||
protected static final int PLAY_FRAMES = 10; // count
|
||||
@@ -44,10 +44,10 @@ public class Source implements Consumer {
|
||||
worker.exit();
|
||||
}
|
||||
if (producer instanceof Format.Standard) {
|
||||
log.debug("Format.Standard");
|
||||
logger.debug("Format.Standard");
|
||||
worker = new DefaultWorker((Format.Standard) producer);
|
||||
} else if (producer instanceof Format.Mp3) {
|
||||
log.debug("Format.Mp3");
|
||||
logger.debug("Format.Mp3");
|
||||
worker = new Mp3Worker((Format.Mp3) producer);
|
||||
}
|
||||
start();
|
||||
@@ -83,7 +83,7 @@ public class Source implements Consumer {
|
||||
line.open();
|
||||
}
|
||||
} catch (LineUnavailableException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
if (!line.isRunning()) {
|
||||
@@ -112,7 +112,7 @@ public class Source implements Consumer {
|
||||
exit();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class Source implements Consumer {
|
||||
}
|
||||
player.play(PLAY_FRAMES);
|
||||
} catch (JavaLayerException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
if (player.isComplete()) {
|
||||
stop();
|
||||
@@ -116,7 +116,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
|
||||
try {
|
||||
greedyInputStream.clear();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
throw new DeactivateException();
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
|
||||
audioCircularByteBuffer.getOutputStream().write(bytes);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
stop();
|
||||
}
|
||||
}
|
||||
@@ -167,15 +167,15 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
|
||||
if (!newMetaData.isEmpty() && !newMetaData.equals(metaData)) {
|
||||
metaData = newMetaData;
|
||||
metaCircularObjectBuffer.write(new String(data));
|
||||
log.debug("data: " + metaData);
|
||||
logger.debug("data: " + metaData);
|
||||
}
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
} catch (IllegalStateException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
stop();
|
||||
}
|
||||
@@ -7,11 +7,11 @@ import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.TargetDataLine;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Target implements Producer, Format.Standard {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected Standard format;
|
||||
|
||||
@@ -21,14 +21,14 @@ public class Target implements Producer, Format.Standard {
|
||||
protected AudioFormat audioFormat;
|
||||
|
||||
public Target(String name) throws LineUnavailableException {
|
||||
log.debug(String.format("Target \"%s\" without format", name));
|
||||
logger.debug(String.format("Target \"%s\" without format", name));
|
||||
line = Tool.getTargetDataLine(name);
|
||||
audioFormat = line.getFormat();
|
||||
targetInputStream = new TargetInputStream();
|
||||
}
|
||||
|
||||
public Target(String name, AudioFormat audioFormat) throws LineUnavailableException {
|
||||
log.debug(String.format("Target \"%s\" with format: %s", name, audioFormat));
|
||||
logger.debug(String.format("Target \"%s\" with format: %s", name, audioFormat));
|
||||
this.audioFormat = audioFormat;
|
||||
line = Tool.getTargetDataLine(name, audioFormat);
|
||||
targetInputStream = new TargetInputStream();
|
||||
@@ -73,7 +73,7 @@ public class Target implements Producer, Format.Standard {
|
||||
try {
|
||||
line.open();
|
||||
} catch (LineUnavailableException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
if (!line.isRunning()) {
|
||||
@@ -14,11 +14,11 @@ import javax.sound.sampled.Port.Info;
|
||||
import javax.sound.sampled.SourceDataLine;
|
||||
import javax.sound.sampled.TargetDataLine;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Tool {
|
||||
protected static Log log = LogFactory.getLog(Tool.class);
|
||||
protected static Logger logger = LoggerFactory.getLogger(Tool.class);
|
||||
|
||||
protected static HashMap<String, Device<TargetDataLine>> targetMap;
|
||||
protected static HashMap<String, Device<SourceDataLine>> sourceMap;
|
||||
@@ -44,7 +44,7 @@ public class Tool {
|
||||
String lineClassName = lineInfo.getLineClass().getName();
|
||||
if (lineClassName.equals("javax.sound.sampled.SourceDataLine")) {
|
||||
if (mixer.isLineSupported(lineInfo)) {
|
||||
log.debug("<Source> " + name);
|
||||
logger.debug("<Source> " + name);
|
||||
sourceMap.put(name, tool.new Device<SourceDataLine>(mixer, lineInfo));
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class Tool {
|
||||
String lineClassName = lineInfo.getLineClass().getName();
|
||||
if (lineClassName.equals("javax.sound.sampled.TargetDataLine")) {
|
||||
if (mixer.isLineSupported(lineInfo)) {
|
||||
log.debug("<Target> " + name);
|
||||
logger.debug("<Target> " + name);
|
||||
targetMap.put(name, tool.new Device<TargetDataLine>(mixer, lineInfo));
|
||||
}
|
||||
} else if (lineClassName.equals("javax.sound.sampled.Port")) {
|
||||
@@ -62,11 +62,11 @@ public class Tool {
|
||||
Port port = (Port) mixer.getLine(lineInfo);
|
||||
Port.Info portInfo = (Info) port.getLineInfo();
|
||||
if (!targetMap.containsKey(name) || portInfo.equals(Port.Info.LINE_OUT) || portInfo.equals(Port.Info.SPEAKER)) {
|
||||
log.debug("<Port> " + name);
|
||||
logger.debug("<Port> " + name);
|
||||
portList.add(name);
|
||||
}
|
||||
} catch (LineUnavailableException e) {
|
||||
log.error(e);
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user