Skip to content

Commit

Permalink
Disable debug log traces
Browse files Browse the repository at this point in the history
Debug log traces made the audio stream jerky.
  • Loading branch information
rom1v committed Mar 10, 2013
1 parent 248c7d2 commit 3fc2fb5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
17 changes: 11 additions & 6 deletions src/org/servalproject/walkietalkie/AudioReceiver.java
Expand Up @@ -147,14 +147,17 @@ public void run() {
| (buf[4] & 0xff) << 8 | buf[5] & 0xff;
int ssrc = (buf[6] & 0xff) << 24 | (buf[7] & 0xff) << 16
| (buf[8] & 0xff) << 8 | buf[9] & 0xff;
Log.i(TAG, "ssrc=" + ssrc + ", " + buf[6] + ":" + buf[7] + ":" + buf[8]
+ ":" + buf[9]);

int writeBufLength = decompress(buf, writeBuf, HEADER_SIZE,
packet.getLength() - HEADER_SIZE);
int written = mixer.write(ssrc, timestamp, writeBuf, 0, writeBufLength);
Log.i(TAG, "(" + ssrc + ") Packet " + seq + "[" + packet.getBuf().length
+ "] " + written);

if (WalkieTalkieService.DEBUG_WALKIE_TALKIE) {
Log.d(TAG, "ssrc=" + ssrc + ", " + buf[6] + ":" + buf[7] + ":" + buf[8]
+ ":" + buf[9]);
Log.d(TAG, "(" + ssrc + ") Packet " + seq + "["
+ packet.getBuf().length + "] " + written);
}

} catch (IOException e) {
if (!stopped) {
Expand Down Expand Up @@ -209,8 +212,10 @@ public void run() {
return;
}

Log.i(TAG, "mixerPlayer.read() : " + SystemClock.elapsedRealtime() + " ["
+ read + "]");
if (WalkieTalkieService.DEBUG_WALKIE_TALKIE) {
Log.d(TAG, "mixerPlayer.read() : " + SystemClock.elapsedRealtime()
+ " [" + read + "]");
}
mixer.move(read);
}
audioTrack.write(buf, 0, read);
Expand Down
27 changes: 16 additions & 11 deletions src/org/servalproject/walkietalkie/AudioSender.java
Expand Up @@ -140,7 +140,9 @@ public void run() {
int fromStartTU = 0; /* in timestamp units (for example 1 TU = 1 sample = 2 bytes) */

while (!stopped) {
Log.i(TAG, "Reading packet " + seq);
if (WalkieTalkieService.DEBUG_WALKIE_TALKIE) {
Log.d(TAG, "Reading packet " + seq);
}

/* dynamic headers */
buf[0] = (byte) (seq >> 8);
Expand All @@ -163,12 +165,12 @@ public void run() {
packet.setSid(to.getSid());
packet.setPort(to.getPort());
try {
Log.i(TAG, "Prepare packet " + seq + " [" + read / 2 + "] to send to "
+ to.getSid() + ":" + to.getPort());
socket.send(packet);
Log.i(TAG,
"Paquet " + seq + " sent to " + to.getSid() + ":"
+ to.getPort());
if (WalkieTalkieService.DEBUG_WALKIE_TALKIE) {
Log.d(TAG,
"Packet " + seq + " [" + read / 2 + " sent to "
+ to.getSid() + ":" + to.getPort());
}
} catch (IOException e) {
Log.e(TAG, "Cannot send data", e);
}
Expand All @@ -180,15 +182,18 @@ public void run() {

if (Math.abs(fromStartTU - timestamp) > 1000) {
/*
* micro does not record exactly at the right rate, we have to correct it
* (here every 1k samples of deviation)
* micro does not record exactly at the right rate on some phones, we have
* to correct it (here every 1k samples of deviation)
*/
Log.i(TAG, "--MICROPHONE DEVIATION CORRECTION-- timestamp was " + timestamp
Log.w(TAG, "--MICROPHONE DEVIATION CORRECTION-- timestamp was " + timestamp
+ ", timestamp = " + fromStartTU);
timestamp = fromStartTU;
}
Log.i(TAG, "theoretical-timestamp(" + fromStartTU + ") - recorded-timestamp("
+ timestamp + ") = " + (fromStartTU - timestamp));
if (WalkieTalkieService.DEBUG_WALKIE_TALKIE) {
Log.d(TAG, "theoretical-timestamp(" + fromStartTU
+ ") - recorded-timestamp(" + timestamp + ") = "
+ (fromStartTU - timestamp));
}

seq++;
timestamp += read / 2; /* 2 bytes per sample */
Expand Down
7 changes: 4 additions & 3 deletions src/org/servalproject/walkietalkie/Mixer.java
Expand Up @@ -119,7 +119,6 @@ private synchronized Source createSource(int ssrc, int sampleOffset) {
sourceIndex = getSourceIndex(ssrc);
}
Source source;
Log.i(TAG, "sourceIndex[" + ssrc + "] = " + sourceIndex);
if (sourceIndex == -1) {
source = new Source(ssrc, sampleOffset);
sources.add(source);
Expand All @@ -134,7 +133,9 @@ private synchronized Source createSource(int ssrc, int sampleOffset) {

public synchronized int write(int ssrc, int sampleOffset, byte[] data, int dataOffset,
int dataLength) {
Log.i(TAG, "write(ssrc=" + ssrc + ", sampleOffset=" + sampleOffset + ", ...)");
if (WalkieTalkieService.DEBUG_WALKIE_TALKIE) {
Log.d(TAG, "write(ssrc=" + ssrc + ", sampleOffset=" + sampleOffset + ", ...)");
}
Source source = createSource(ssrc, sampleOffset - delayInSamples);
source.touch();
return source.streamBuffer.write(2 * sampleOffset, data, dataOffset, dataLength);
Expand Down Expand Up @@ -170,7 +171,7 @@ public synchronized int read(byte[] data, int dataOffset, int dataLength) {
int msToEat = (int) (now - target);
int samplesToEat = toSamples(msToEat, rate);
move(2 * samplesToEat);
Log.i(TAG, "Playing lag: eat " + msToEat + " ms (" + samplesToEat + " samples)");
Log.w(TAG, "Playing lag: eat " + msToEat + " ms (" + samplesToEat + " samples)");
}

dataLength &= ~1; /* make dataLength even */
Expand Down
5 changes: 2 additions & 3 deletions src/org/servalproject/walkietalkie/StreamBuffer.java
Expand Up @@ -33,15 +33,14 @@ public StreamBuffer(int length, int streamOffset) {
public synchronized int write(int streamOffset, byte[] data, int dataOffset, int dataLength) {
int start = streamOffset - this.streamOffset;

Log.i("StreamBuffer", "--> " + (streamOffset - this.streamOffset));
if (start > length) {
Log.i("StreamBuffer", "Buffer overflow : " + this.streamOffset + " - " + streamOffset);
Log.w("StreamBuffer", "Buffer overflow : " + this.streamOffset + " - " + streamOffset);
/* buffer overflow (write too far on the right) */
return 0;
}

if (start < 0) {
Log.i("StreamBuffer", "Buffer underrun : " + this.streamOffset + " - " + streamOffset);
Log.w("StreamBuffer", "Buffer underrun : " + this.streamOffset + " - " + streamOffset);
/* buffer underrun (write too far on the left) */
dataOffset -= start;
dataLength += start;
Expand Down
3 changes: 3 additions & 0 deletions src/org/servalproject/walkietalkie/WalkieTalkieService.java
Expand Up @@ -48,6 +48,9 @@ public class WalkieTalkieService extends Service {
/** Mesh socket client port for walkie-talkie communication. */
public static final int WALKIE_TALKIE_CLIENT_PORT = 5555;

/** Debug traces make the audio stream jerky. */
public static final boolean DEBUG_WALKIE_TALKIE = false;

private AudioSender sender;
private AudioReceiver receiver;

Expand Down

0 comments on commit 3fc2fb5

Please sign in to comment.