PeerConnection(java): use MediaCodec for HW-accelerated video encode where available.

Still disabled by default until https://code.google.com/p/webrtc/issues/detail?id=2899 is resolved.

Also (because I needed them during development):
- make AppRTCDemo "debuggable" for extra JNI checks
- honor audio constraints served by apprtc.appspot.com
- don't "restart" video when it hasn't been stopped (affects running with the
  screen off)

BUG=2575
R=noahric@google.com

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5539 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org
2014-02-13 03:56:14 +00:00
parent 17342e5092
commit 540acde5b3
6 changed files with 1000 additions and 41 deletions

View File

@@ -131,6 +131,10 @@ public class AppRTCClient {
return appRTCSignalingParameters.videoConstraints;
}
public MediaConstraints audioConstraints() {
return appRTCSignalingParameters.audioConstraints;
}
// Struct holding the signaling parameters of an AppRTC room.
private class AppRTCSignalingParameters {
public final List<PeerConnection.IceServer> iceServers;
@@ -140,12 +144,13 @@ public class AppRTCClient {
public final boolean initiator;
public final MediaConstraints pcConstraints;
public final MediaConstraints videoConstraints;
public final MediaConstraints audioConstraints;
public AppRTCSignalingParameters(
List<PeerConnection.IceServer> iceServers,
String gaeBaseHref, String channelToken, String postMessageUrl,
boolean initiator, MediaConstraints pcConstraints,
MediaConstraints videoConstraints) {
MediaConstraints videoConstraints, MediaConstraints audioConstraints) {
this.iceServers = iceServers;
this.gaeBaseHref = gaeBaseHref;
this.channelToken = channelToken;
@@ -153,6 +158,7 @@ public class AppRTCClient {
this.initiator = initiator;
this.pcConstraints = pcConstraints;
this.videoConstraints = videoConstraints;
this.audioConstraints = audioConstraints;
}
}
@@ -268,34 +274,40 @@ public class AppRTCClient {
MediaConstraints pcConstraints = constraintsFromJSON(
getVarValue(roomHtml, "pcConstraints", false));
Log.d(TAG, "pcConstraints: " + pcConstraints);
MediaConstraints videoConstraints = constraintsFromJSON(
getVideoConstraints(
getAVConstraints("video",
getVarValue(roomHtml, "mediaConstraints", false)));
Log.d(TAG, "videoConstraints: " + videoConstraints);
MediaConstraints audioConstraints = constraintsFromJSON(
getAVConstraints("audio",
getVarValue(roomHtml, "mediaConstraints", false)));
Log.d(TAG, "audioConstraints: " + audioConstraints);
return new AppRTCSignalingParameters(
iceServers, gaeBaseHref, token, postMessageUrl, initiator,
pcConstraints, videoConstraints);
pcConstraints, videoConstraints, audioConstraints);
}
private String getVideoConstraints(String mediaConstraintsString) {
// Return the constraints specified for |type| of "audio" or "video" in
// |mediaConstraintsString|.
private String getAVConstraints(
String type, String mediaConstraintsString) {
try {
JSONObject json = new JSONObject(mediaConstraintsString);
// Tricksy handling of values that are allowed to be (boolean or
// MediaTrackConstraints) by the getUserMedia() spec. There are three
// cases below.
if (!json.has("video") || !json.optBoolean("video", true)) {
// Case 1: "video" is not present, or is an explicit "false" boolean.
if (!json.has(type) || !json.optBoolean(type, true)) {
// Case 1: "audio"/"video" is not present, or is an explicit "false"
// boolean.
return null;
}
if (json.optBoolean("video", false)) {
// Case 2: "video" is an explicit "true" boolean.
if (json.optBoolean(type, false)) {
// Case 2: "audio"/"video" is an explicit "true" boolean.
return "{\"mandatory\": {}, \"optional\": []}";
}
// Case 3: "video" is an object.
return json.getJSONObject("video").toString();
// Case 3: "audio"/"video" is an object.
return json.getJSONObject(type).toString();
} catch (JSONException e) {
throw new RuntimeException(e);
}

View File

@@ -75,6 +75,7 @@ public class AppRTCDemoActivity extends Activity
private static final String TAG = "AppRTCDemoActivity";
private PeerConnectionFactory factory;
private VideoSource videoSource;
private boolean videoSourceStopped;
private PeerConnection pc;
private final PCObserver pcObserver = new PCObserver();
private final SDPObserver sdpObserver = new SDPObserver();
@@ -159,6 +160,7 @@ public class AppRTCDemoActivity extends Activity
vsv.onPause();
if (videoSource != null) {
videoSource.stop();
videoSourceStopped = true;
}
}
@@ -166,7 +168,7 @@ public class AppRTCDemoActivity extends Activity
public void onResume() {
super.onResume();
vsv.onResume();
if (videoSource != null) {
if (videoSource != null && videoSourceStopped) {
videoSource.restart();
}
}
@@ -239,7 +241,9 @@ public class AppRTCDemoActivity extends Activity
vsv, VideoStreamsView.Endpoint.LOCAL)));
lMS.addTrack(videoTrack);
}
lMS.addTrack(factory.createAudioTrack("ARDAMSa0"));
if (appRtcClient.audioConstraints() != null) {
lMS.addTrack(factory.createAudioTrack("ARDAMSa0"));
}
pc.addStream(lMS, new MediaConstraints());
}
logAndToast("Waiting for ICE candidates...");