AppRTCDemo(android): support boolean value for MediaStreamConstraints.{audio,video}.

Previously it was assumed that these values were always MediaTrackConstraints but
http://dev.w3.org/2011/webrtc/editor/getusermedia.html#idl-def-MediaStreamConstraints
allows them to be boolean, too.

R=andrew@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4918 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org 2013-10-03 22:34:10 +00:00
parent a7266ca134
commit 4446134757
2 changed files with 26 additions and 11 deletions

View File

@ -272,6 +272,7 @@ public class AppRTCClient {
MediaConstraints videoConstraints = constraintsFromJSON(
getVideoConstraints(
getVarValue(roomHtml, "mediaConstraints", false)));
Log.d(TAG, "videoConstraints: " + videoConstraints);
return new AppRTCSignalingParameters(
@ -282,17 +283,28 @@ public class AppRTCClient {
private String getVideoConstraints(String mediaConstraintsString) {
try {
JSONObject json = new JSONObject(mediaConstraintsString);
JSONObject videoJson = json.optJSONObject("video");
if (videoJson == null) {
return "";
// 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.
return null;
}
return videoJson.toString();
if (json.optBoolean("video", false)) {
// Case 2: "video" is an explicit "true" boolean.
return "{\"mandatory\": {}, \"optional\": []}";
}
// Case 3: "video" is an object.
return json.getJSONObject("video").toString();
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
private MediaConstraints constraintsFromJSON(String jsonString) {
if (jsonString == null) {
return null;
}
try {
MediaConstraints constraints = new MediaConstraints();
JSONObject json = new JSONObject(jsonString);

View File

@ -214,14 +214,17 @@ public class AppRTCDemoActivity extends Activity
{
logAndToast("Creating local video source...");
VideoCapturer capturer = getVideoCapturer();
videoSource = factory.createVideoSource(
capturer, appRtcClient.videoConstraints());
MediaStream lMS = factory.createLocalMediaStream("ARDAMS");
VideoTrack videoTrack = factory.createVideoTrack("ARDAMSv0", videoSource);
videoTrack.addRenderer(new VideoRenderer(new VideoCallbacks(
vsv, VideoStreamsView.Endpoint.LOCAL)));
lMS.addTrack(videoTrack);
if (appRtcClient.videoConstraints() != null) {
VideoCapturer capturer = getVideoCapturer();
videoSource = factory.createVideoSource(
capturer, appRtcClient.videoConstraints());
VideoTrack videoTrack =
factory.createVideoTrack("ARDAMSv0", videoSource);
videoTrack.addRenderer(new VideoRenderer(new VideoCallbacks(
vsv, VideoStreamsView.Endpoint.LOCAL)));
lMS.addTrack(videoTrack);
}
lMS.addTrack(factory.createAudioTrack("ARDAMSa0"));
pc.addStream(lMS, new MediaConstraints());
}