PeerConnection(java): Add OnRenegotiationNeeded support

Also:
- Make PeerConnectionObserver::OnRenegotiationNeeded() pure virtual to avoid
  this sort of mistake in the future.
- Sprinkle @Override annotations on some callback definitions that were missing
  them.
- Fix a JNI method-signature-lookup typo (s/(V)V/()V/) in PCOJava::OnError()
- Add an explicit ScopedLocalFrameRef to PCOJava::OnError() to match all other
  C++-fired callbacks, for consistency.

BUG=2771
R=wu@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/6829004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5376 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org 2014-01-13 22:04:12 +00:00
parent ad1863de74
commit d7568a08c3
5 changed files with 38 additions and 2 deletions

View File

@ -515,7 +515,8 @@ class PCOJava : public PeerConnectionObserver {
} }
virtual void OnError() OVERRIDE { virtual void OnError() OVERRIDE {
jmethodID m = GetMethodID(jni(), *j_observer_class_, "onError", "(V)V"); ScopedLocalRefFrame local_ref_frame(jni());
jmethodID m = GetMethodID(jni(), *j_observer_class_, "onError", "()V");
jni()->CallVoidMethod(*j_observer_global_, m); jni()->CallVoidMethod(*j_observer_global_, m);
CHECK_EXCEPTION(jni(), "error during CallVoidMethod"); CHECK_EXCEPTION(jni(), "error during CallVoidMethod");
} }
@ -648,6 +649,14 @@ class PCOJava : public PeerConnectionObserver {
CHECK_EXCEPTION(jni(), "error during CallVoidMethod"); CHECK_EXCEPTION(jni(), "error during CallVoidMethod");
} }
virtual void OnRenegotiationNeeded() OVERRIDE {
ScopedLocalRefFrame local_ref_frame(jni());
jmethodID m =
GetMethodID(jni(), *j_observer_class_, "onRenegotiationNeeded", "()V");
jni()->CallVoidMethod(*j_observer_global_, m);
CHECK_EXCEPTION(jni(), "error during CallVoidMethod");
}
void SetConstraints(ConstraintsWrapper* constraints) { void SetConstraints(ConstraintsWrapper* constraints) {
CHECK(!constraints_.get(), "constraints already set!"); CHECK(!constraints_.get(), "constraints already set!");
constraints_.reset(constraints); constraints_.reset(constraints);

View File

@ -82,6 +82,9 @@ public class PeerConnection {
/** Triggered when a remote peer opens a DataChannel. */ /** Triggered when a remote peer opens a DataChannel. */
public void onDataChannel(DataChannel dataChannel); public void onDataChannel(DataChannel dataChannel);
/** Triggered when renegotiation is necessary. */
public void onRenegotiationNeeded();
} }
/** Java version of PeerConnectionInterface.IceServer. */ /** Java version of PeerConnectionInterface.IceServer. */

View File

@ -59,6 +59,7 @@ public class PeerConnectionTest extends TestCase {
private final String name; private final String name;
private int expectedIceCandidates = 0; private int expectedIceCandidates = 0;
private int expectedErrors = 0; private int expectedErrors = 0;
private int expectedRenegotiations = 0;
private int expectedSetSize = 0; private int expectedSetSize = 0;
private int previouslySeenWidth = 0; private int previouslySeenWidth = 0;
private int previouslySeenHeight = 0; private int previouslySeenHeight = 0;
@ -103,6 +104,7 @@ public class PeerConnectionTest extends TestCase {
expectedIceCandidates += count; expectedIceCandidates += count;
} }
@Override
public synchronized void onIceCandidate(IceCandidate candidate) { public synchronized void onIceCandidate(IceCandidate candidate) {
--expectedIceCandidates; --expectedIceCandidates;
// We don't assert expectedIceCandidates >= 0 because it's hard to know // We don't assert expectedIceCandidates >= 0 because it's hard to know
@ -115,6 +117,7 @@ public class PeerConnectionTest extends TestCase {
++expectedErrors; ++expectedErrors;
} }
@Override
public synchronized void onError() { public synchronized void onError() {
assertTrue(--expectedErrors >= 0); assertTrue(--expectedErrors >= 0);
} }
@ -236,6 +239,15 @@ public class PeerConnectionTest extends TestCase {
assertEquals(DataChannel.State.CONNECTING, dataChannel.state()); assertEquals(DataChannel.State.CONNECTING, dataChannel.state());
} }
public synchronized void expectRenegotiationNeeded() {
++expectedRenegotiations;
}
@Override
public synchronized void onRenegotiationNeeded() {
assertTrue(--expectedRenegotiations >= 0);
}
public synchronized void expectMessage(ByteBuffer expectedBuffer, public synchronized void expectMessage(ByteBuffer expectedBuffer,
boolean expectedBinary) { boolean expectedBinary) {
expectedBuffers.add( expectedBuffers.add(
@ -375,20 +387,24 @@ public class PeerConnectionTest extends TestCase {
public SdpObserverLatch() {} public SdpObserverLatch() {}
@Override
public void onCreateSuccess(SessionDescription sdp) { public void onCreateSuccess(SessionDescription sdp) {
this.sdp = sdp; this.sdp = sdp;
onSetSuccess(); onSetSuccess();
} }
@Override
public void onSetSuccess() { public void onSetSuccess() {
success = true; success = true;
latch.countDown(); latch.countDown();
} }
@Override
public void onCreateFailure(String error) { public void onCreateFailure(String error) {
onSetFailure(error); onSetFailure(error);
} }
@Override
public void onSetFailure(String error) { public void onSetFailure(String error) {
this.error = error; this.error = error;
latch.countDown(); latch.countDown();
@ -529,10 +545,12 @@ public class PeerConnectionTest extends TestCase {
// Drop |label| params from {Audio,Video}Track-related APIs once // Drop |label| params from {Audio,Video}Track-related APIs once
// https://code.google.com/p/webrtc/issues/detail?id=1253 is fixed. // https://code.google.com/p/webrtc/issues/detail?id=1253 is fixed.
offeringExpectations.expectSetSize(); offeringExpectations.expectSetSize();
offeringExpectations.expectRenegotiationNeeded();
WeakReference<MediaStream> oLMS = addTracksToPC( WeakReference<MediaStream> oLMS = addTracksToPC(
factory, offeringPC, videoSource, "oLMS", "oLMSv0", "oLMSa0", factory, offeringPC, videoSource, "oLMS", "oLMSv0", "oLMSa0",
offeringExpectations); offeringExpectations);
offeringExpectations.expectRenegotiationNeeded();
DataChannel offeringDC = offeringPC.createDataChannel( DataChannel offeringDC = offeringPC.createDataChannel(
"offeringDC", new DataChannel.Init()); "offeringDC", new DataChannel.Init());
assertEquals("offeringDC", offeringDC.label()); assertEquals("offeringDC", offeringDC.label());
@ -557,6 +575,7 @@ public class PeerConnectionTest extends TestCase {
assertNull(sdpLatch.getSdp()); assertNull(sdpLatch.getSdp());
answeringExpectations.expectSetSize(); answeringExpectations.expectSetSize();
answeringExpectations.expectRenegotiationNeeded();
WeakReference<MediaStream> aLMS = addTracksToPC( WeakReference<MediaStream> aLMS = addTracksToPC(
factory, answeringPC, videoSource, "aLMS", "aLMSv0", "aLMSa0", factory, answeringPC, videoSource, "aLMS", "aLMSv0", "aLMSa0",
answeringExpectations); answeringExpectations);

View File

@ -277,7 +277,7 @@ class PeerConnectionObserver {
virtual void OnDataChannel(DataChannelInterface* data_channel) {} virtual void OnDataChannel(DataChannelInterface* data_channel) {}
// Triggered when renegotation is needed, for example the ICE has restarted. // Triggered when renegotation is needed, for example the ICE has restarted.
virtual void OnRenegotiationNeeded() {} virtual void OnRenegotiationNeeded() = 0;
// Called any time the IceConnectionState changes // Called any time the IceConnectionState changes
virtual void OnIceConnectionChange( virtual void OnIceConnectionChange(

View File

@ -419,6 +419,11 @@ public class AppRTCDemoActivity extends Activity
} }
}); });
} }
@Override public void onRenegotiationNeeded() {
// No need to do anything; AppRTC follows a pre-agreed-upon
// signaling/negotiation protocol.
}
} }
// Implementation detail: handle offer creation/signaling and answer setting, // Implementation detail: handle offer creation/signaling and answer setting,