Skip to content

Commit

Permalink
Merge pull request #3 from jblezoray/master
Browse files Browse the repository at this point in the history
The famous changes we talk some time ago.
  • Loading branch information
bencall committed Jun 30, 2011
2 parents f9596e0 + c12870b commit 7840a6d
Show file tree
Hide file tree
Showing 45 changed files with 243 additions and 2,964 deletions.
Binary file modified Binaries/Rplay.jar
Binary file not shown.
Binary file added Binaries/Rplay_lib/jald.jar
Binary file not shown.
Binary file removed Binaries/Rplay_lib/jmdns.jar
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/AlacContext.class
Binary file not shown.
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/AlacFile.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/AlacInputStream.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/AlacUtils.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/ChunkInfo.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/DecodeResult.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/Defines.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/DemuxResT.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/DemuxUtils.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/LeadingZeros.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/MyStream.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/QTMovieT.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/SampleDuration.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/SampleInfo.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/StreamUtils.class
Binary file not shown.
Binary file removed bin/com/beatofthedrum/alacdecoder/WavWriter.class
Binary file not shown.
59 changes: 59 additions & 0 deletions build.xml
@@ -0,0 +1,59 @@
<project name="ShairPort" default="dist" basedir=".">

<property name="src" location="src" />
<property name="lib" location="libs" />
<property name="bin" location="bin" />
<property name="dist" location="Binaries" />
<property name="dist_lib" location="${dist}/Rplay_lib" />
<property name="dist_jar" location="${dist}/Rplay.jar" />

<path id="lib_cp">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>

<target name="build">
<mkdir dir="${bin}"/>
<javac srcdir="${src}" destdir="${bin}"
classpathref="lib_cp" includeantruntime="false"
verbose="true" debug="true"
source="1.6" target="1.6" />
</target>

<target name="dist" depends="build">
<mkdir dir="${dist}"/>
<manifestclasspath property="jar_cp" jarfile="${dist_jar}">
<classpath>
<fileset dir="${dist_lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</manifestclasspath>
<jar destfile="${dist_jar}">
<fileset dir="${bin}"/>
<manifest>
<attribute name="Main-Class" value="Rplay"/>
<attribute name="Class-Path" value="${jar_cp}" />
</manifest>
</jar>

<mkdir dir="${dist_lib}"/>
<copy todir="${dist_lib}" flatten="true">
<path refid="lib_cp" />
</copy>
</target>

<target name="run">
<!--
<java fork="true" classname="RPlayNoGui">
<classpath path="${dist_jar}"/>
<arg value="myAirport"/>
</java>
-->
<java fork="true" classname="Rplay">
<classpath path="${dist_jar}"/>
</java>
</target>

</project>
Binary file added libs/Java-Apple-Lossless-decoder/jald.jar
Binary file not shown.
81 changes: 58 additions & 23 deletions src/LaunchThread.java
@@ -1,19 +1,24 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import com.apple.dnssd.DNSSDException;


/**
* LaunchThread class which starts services
* @author bencall
*
*/
public class LaunchThread extends Thread{
private RTSPResponder repondeur;
private BonjourEmitter emetteur;
private BonjourEmitter emitter;
private String name;
private boolean stopThread = false;

/**
* Constructor
Expand All @@ -24,9 +29,7 @@ public LaunchThread(String name){
this.name = name;
}


public void run(){
int port = 5000;
private byte[] getHardwareAdress() {
byte[] hwAddr = null;

InetAddress local;
Expand All @@ -36,38 +39,70 @@ public void run(){
if (ni != null) {
hwAddr = ni.getHardwareAddress();
}
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
}

return hwAddr;
}


private String getStringHardwareAdress(byte[] hwAddr) {
StringBuilder sb = new StringBuilder();
for (byte b : hwAddr) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}


public void run(){
System.out.println("service started.");
int port = 5000;

ServerSocket servSock = null;
try {
// DNS Emitter (Bonjour)
repondeur = new RTSPResponder(port, hwAddr);
emetteur = new BonjourEmitter(name, sb.toString(), repondeur.getPort());

repondeur.start();
// We listen for new connections
try {
servSock = new ServerSocket(port);
} catch (IOException e) {
servSock = new ServerSocket();
}

// DNS Emitter (Bonjour)
byte[] hwAddr = getHardwareAdress();
emitter = new BonjourEmitter(name, getStringHardwareAdress(hwAddr), port);

servSock.setSoTimeout(1000);
while (!stopThread) {
try {
Socket socket = servSock.accept();
System.out.println("got connection from " + socket.toString());
new RTSPResponder(hwAddr, socket).start();
} catch(SocketTimeoutException e) {
// ignore
}
}

} catch (Exception e) {
// Bonjour error
e.printStackTrace();
} catch (DNSSDException e) {
throw new RuntimeException(e);

} catch (IOException e) {
throw new RuntimeException(e);

} finally {
try {
servSock.close(); // will stop all RTSPResponders.
emitter.stop();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("service stopped");
}

public synchronized void stopThread(){
emetteur.stop();

try {
repondeur.stopThread();
} catch (IOException e) {
e.printStackTrace();
}
stopThread = true;
}
}
19 changes: 19 additions & 0 deletions src/RPlayNoGui.java
@@ -0,0 +1,19 @@

public class RPlayNoGui {


private static final void usage() {
System.err.println("Java port of shairport.");
System.err.println("usage : ");
System.err.println(" java "+RPlayNoGui.class.getCanonicalName()+" <AP_name>");
}

public static void main(String[] args) {
if (args.length != 1 && args[1].length()>1) {
usage();
System.exit(-1);
}
new LaunchThread(args[0]).start();
}

}
6 changes: 5 additions & 1 deletion src/RTSPPacket.java
Expand Up @@ -73,7 +73,6 @@ public String getDirectory(){
}

public int getCode(){

return 200;
}

Expand All @@ -84,4 +83,9 @@ public String valueOfHeader(String headerName){
}
return headerContent.elementAt(i);
}

@Override
public String toString() {
return " < " + rawPacket.replaceAll("\r\n", "\r\n < ");
}
}

0 comments on commit 7840a6d

Please sign in to comment.