Permalink
Browse files

Added some comments and created PCMPlayer class.

The "communication" and "decryption" parts are finished. "Just" need to play the PCM data.
  • Loading branch information...
1 parent 3125d00 commit e058638152759b91e3308121b1a0e362c7776160 @bencall committed Apr 28, 2011
Showing with 82 additions and 13 deletions.
  1. +4 −1 .gitignore
  2. +56 −10 src/AudioServer.java
  3. +1 −0 src/BonjourEmitter.java
  4. +13 −0 src/PCMPlayer.java
  5. +2 −1 src/RTSPPacket.java
  6. +1 −0 src/Rplay.java
  7. +5 −1 src/UDPDelegate.java
View
@@ -3,4 +3,7 @@
/bin/UDPListener.class
*.class
/bin/RTSPResponder.class
-/bin/BonjourEmitter.class
+/bin/BonjourEmitter.class
+/bin/RTSPPacket.class
+/bin/Rplay.class
+/bin/UDPDelegate.class
View
@@ -44,6 +44,14 @@
private final Lock lock = new ReentrantLock();
+ /**
+ * Constructor. Initiate instances vars
+ * @param aesiv
+ * @param aeskey
+ * @param fmtp
+ * @param controlPort
+ * @param timingPort
+ */
public AudioServer(byte[] aesiv, byte[] aeskey, int[] fmtp, int controlPort, int timingPort){
// Init instance var
this.fmtp = fmtp;
@@ -56,21 +64,34 @@ public AudioServer(byte[] aesiv, byte[] aeskey, int[] fmtp, int controlPort, int
// Init functions
this.initDecoder();
this.initBuffer();
- this.initRTP();
+ this.initRTP();
+
+ @SuppressWarnings("unused")
+ PCMPlayer player = new PCMPlayer(audioBuffer);
}
+ /**
+ * Sets the packets as not ready. Audio thread will only listen to ready packets.
+ * No audio more.
+ */
public void flush(){
for (int i = 0; i< BUFFER_FRAMES; i++){
audioBuffer[i].ready = false;
synced = false;
}
}
+ /**
+ * Return the server port for the bonjour service
+ * @return
+ */
public int getServerPort() {
return sock.getLocalPort();
}
-
+ /**
+ * Opens the sockets and begin listening
+ */
private void initRTP(){
int port = 6000;
while(true){
@@ -90,7 +111,9 @@ private void initRTP(){
UDPListener l2 = new UDPListener(csock, this);
}
-
+ /**
+ * Initiate the decoder
+ */
private void initDecoder(){
frameSize = fmtp[1];
@@ -118,7 +141,9 @@ private void initDecoder(){
alac.setinfo_8a_rate = fmtp[11];
}
-
+ /**
+ * Initiate the ring buffer
+ */
private void initBuffer(){
audioBuffer = new AudioData[BUFFER_FRAMES];
for (int i = 0; i< BUFFER_FRAMES; i++){
@@ -127,7 +152,9 @@ private void initBuffer(){
}
}
-
+ /**
+ * When udpListener gets a packet
+ */
public void packetReceived(DatagramSocket socket, DatagramPacket packet) {
this.rtpClient = packet.getAddress(); // The client address
@@ -152,7 +179,11 @@ public void packetReceived(DatagramSocket socket, DatagramPacket packet) {
}
}
-
+ /**
+ * Adds packet into the buffer
+ * @param seqno seqno of the given packet. Used as index
+ * @param data
+ */
private void putPacketInBuffer(int seqno, byte[] data){
// Ring buffer may be implemented in a Hashtable in java (simplier), but is it fast enough?
// We lock the thread
@@ -168,6 +199,7 @@ private void putPacketInBuffer(int seqno, byte[] data){
if((seqno % BUFFER_FRAMES) == 100){
this.request_resend(seqno, seqno);
}
+ @SuppressWarnings("unused")
int outputSize = 0;
if (seqno == writeIndex){ // Packet we expected
outputSize = this.alac_decode(data, audioBuffer[(seqno % BUFFER_FRAMES)].data); // With (seqno % BUFFER_FRAMES) we loop from 0 to BUFFER_FRAMES
@@ -200,7 +232,6 @@ private void putPacketInBuffer(int seqno, byte[] data){
}
-
/**
* Ask iTunes to resend packet
* FUNCTIONAL??? NO PROOFS
@@ -234,7 +265,12 @@ private void request_resend(int first, int last) {
}
-
+ /**
+ * Decrypt and decode the packet.
+ * @param data
+ * @param outbuffer the result
+ * @return
+ */
private int alac_decode(byte[] data, int[] outbuffer){
byte[] packet = new byte[MAX_PACKET];
@@ -260,7 +296,9 @@ private int alac_decode(byte[] data, int[] outbuffer){
return outputsize;
}
-
+ /**
+ * Initiate the cipher
+ */
private void initAES(){
// Init AES encryption
try {
@@ -272,7 +310,15 @@ private void initAES(){
}
}
-
+ /**
+ * Decrypt array from input offset with a length of inputlen and puts it in output at outputoffsest
+ * @param array
+ * @param inputOffset
+ * @param inputLen
+ * @param output
+ * @param outputOffset
+ * @return
+ */
private int decryptAES(byte[] array, int inputOffset, int inputLen, byte[] output, int outputOffset){
try{
return c.update(array, inputOffset, inputLen, output, outputOffset);
View
@@ -12,6 +12,7 @@
*
*/
+//
public class BonjourEmitter implements RegisterListener{
DNSSDRegistration r;
View
@@ -0,0 +1,13 @@
+
+
+/**
+ * Will create a new thread and play packets added to the ring buffer and set as ready
+ * @author bencall
+ *
+ */
+public class PCMPlayer extends Thread{
+ public PCMPlayer(AudioData[] audioBuffer){
+ super();
+
+ }
+}
View
@@ -3,10 +3,11 @@
import java.util.regex.Pattern;
/**
- * Extracts informations from RTSP Header
+ * Extract informations from RTSP Header
* @author bencall
*
*/
+//
public class RTSPPacket {
private String req;
private String directory;
View
@@ -8,6 +8,7 @@
*
*/
+//
public class Rplay {
/**
View
@@ -1,7 +1,11 @@
import java.net.DatagramPacket;
import java.net.DatagramSocket;
-
+/**
+ * Interface for receiving packets
+ * @author bencall
+ *
+ */
public interface UDPDelegate {
public void packetReceived(DatagramSocket socket, DatagramPacket packet);
}

0 comments on commit e058638

Please sign in to comment.