summaryrefslogtreecommitdiffstats
path: root/voip/java
diff options
context:
space:
mode:
authorChia-chi Yeh <chiachi@android.com>2012-03-30 13:25:19 -0700
committerChia-chi Yeh <chiachi@android.com>2012-03-30 13:32:16 -0700
commite66950506c473e660f2e5762d7a71e13808be387 (patch)
tree9ca2791a39e5b0f4a2c1fb59373225b766ff5b1d /voip/java
parent54e1553df69350130df5e4518abf14a9a64931bb (diff)
downloadframeworks_base-e66950506c473e660f2e5762d7a71e13808be387.zip
frameworks_base-e66950506c473e660f2e5762d7a71e13808be387.tar.gz
frameworks_base-e66950506c473e660f2e5762d7a71e13808be387.tar.bz2
RTP: refactor a little bit and fix few minor bugs.
Change-Id: I063644507f26996ded462972afcb550a4528dac8
Diffstat (limited to 'voip/java')
-rw-r--r--voip/java/android/net/rtp/AudioGroup.java27
-rw-r--r--voip/java/android/net/rtp/AudioStream.java2
-rw-r--r--voip/java/android/net/rtp/RtpStream.java16
3 files changed, 24 insertions, 21 deletions
diff --git a/voip/java/android/net/rtp/AudioGroup.java b/voip/java/android/net/rtp/AudioGroup.java
index 3e7ace8..8c19062 100644
--- a/voip/java/android/net/rtp/AudioGroup.java
+++ b/voip/java/android/net/rtp/AudioGroup.java
@@ -142,34 +142,34 @@ public class AudioGroup {
private native void nativeSetMode(int mode);
// Package-private method used by AudioStream.join().
- synchronized void add(AudioStream stream, AudioCodec codec, int dtmfType) {
+ synchronized void add(AudioStream stream) {
if (!mStreams.containsKey(stream)) {
try {
- int socket = stream.dup();
+ AudioCodec codec = stream.getCodec();
String codecSpec = String.format("%d %s %s", codec.type,
codec.rtpmap, codec.fmtp);
- nativeAdd(stream.getMode(), socket,
+ int id = nativeAdd(stream.getMode(), stream.getSocket(),
stream.getRemoteAddress().getHostAddress(),
- stream.getRemotePort(), codecSpec, dtmfType);
- mStreams.put(stream, socket);
+ stream.getRemotePort(), codecSpec, stream.getDtmfType());
+ mStreams.put(stream, id);
} catch (NullPointerException e) {
throw new IllegalStateException(e);
}
}
}
- private native void nativeAdd(int mode, int socket, String remoteAddress,
+ private native int nativeAdd(int mode, int socket, String remoteAddress,
int remotePort, String codecSpec, int dtmfType);
// Package-private method used by AudioStream.join().
synchronized void remove(AudioStream stream) {
- Integer socket = mStreams.remove(stream);
- if (socket != null) {
- nativeRemove(socket);
+ Integer id = mStreams.remove(stream);
+ if (id != null) {
+ nativeRemove(id);
}
}
- private native void nativeRemove(int socket);
+ private native void nativeRemove(int id);
/**
* Sends a DTMF digit to every {@link AudioStream} in this group. Currently
@@ -192,15 +192,14 @@ public class AudioGroup {
* Removes every {@link AudioStream} in this group.
*/
public void clear() {
- synchronized (this) {
- mStreams.clear();
- nativeRemove(-1);
+ for (AudioStream stream : getStreams()) {
+ stream.join(null);
}
}
@Override
protected void finalize() throws Throwable {
- clear();
+ nativeRemove(0);
super.finalize();
}
}
diff --git a/voip/java/android/net/rtp/AudioStream.java b/voip/java/android/net/rtp/AudioStream.java
index b7874f7..5cd1abc 100644
--- a/voip/java/android/net/rtp/AudioStream.java
+++ b/voip/java/android/net/rtp/AudioStream.java
@@ -94,7 +94,7 @@ public class AudioStream extends RtpStream {
mGroup = null;
}
if (group != null) {
- group.add(this, mCodec, mDtmfType);
+ group.add(this);
mGroup = group;
}
}
diff --git a/voip/java/android/net/rtp/RtpStream.java b/voip/java/android/net/rtp/RtpStream.java
index e94ac42..b9d75cd 100644
--- a/voip/java/android/net/rtp/RtpStream.java
+++ b/voip/java/android/net/rtp/RtpStream.java
@@ -54,7 +54,7 @@ public class RtpStream {
private int mRemotePort = -1;
private int mMode = MODE_NORMAL;
- private int mNative;
+ private int mSocket = -1;
static {
System.loadLibrary("rtp_jni");
}
@@ -165,7 +165,9 @@ public class RtpStream {
mRemotePort = port;
}
- synchronized native int dup();
+ int getSocket() {
+ return mSocket;
+ }
/**
* Releases allocated resources. The stream becomes inoperable after calling
@@ -175,13 +177,15 @@ public class RtpStream {
* @see #isBusy()
*/
public void release() {
- if (isBusy()) {
- throw new IllegalStateException("Busy");
+ synchronized (this) {
+ if (isBusy()) {
+ throw new IllegalStateException("Busy");
+ }
+ close();
}
- close();
}
- private synchronized native void close();
+ private native void close();
@Override
protected void finalize() throws Throwable {