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:
parent
a7266ca134
commit
4446134757
@ -272,6 +272,7 @@ public class AppRTCClient {
|
|||||||
MediaConstraints videoConstraints = constraintsFromJSON(
|
MediaConstraints videoConstraints = constraintsFromJSON(
|
||||||
getVideoConstraints(
|
getVideoConstraints(
|
||||||
getVarValue(roomHtml, "mediaConstraints", false)));
|
getVarValue(roomHtml, "mediaConstraints", false)));
|
||||||
|
|
||||||
Log.d(TAG, "videoConstraints: " + videoConstraints);
|
Log.d(TAG, "videoConstraints: " + videoConstraints);
|
||||||
|
|
||||||
return new AppRTCSignalingParameters(
|
return new AppRTCSignalingParameters(
|
||||||
@ -282,17 +283,28 @@ public class AppRTCClient {
|
|||||||
private String getVideoConstraints(String mediaConstraintsString) {
|
private String getVideoConstraints(String mediaConstraintsString) {
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(mediaConstraintsString);
|
JSONObject json = new JSONObject(mediaConstraintsString);
|
||||||
JSONObject videoJson = json.optJSONObject("video");
|
// Tricksy handling of values that are allowed to be (boolean or
|
||||||
if (videoJson == null) {
|
// MediaTrackConstraints) by the getUserMedia() spec. There are three
|
||||||
return "";
|
// 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) {
|
} catch (JSONException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MediaConstraints constraintsFromJSON(String jsonString) {
|
private MediaConstraints constraintsFromJSON(String jsonString) {
|
||||||
|
if (jsonString == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
MediaConstraints constraints = new MediaConstraints();
|
MediaConstraints constraints = new MediaConstraints();
|
||||||
JSONObject json = new JSONObject(jsonString);
|
JSONObject json = new JSONObject(jsonString);
|
||||||
|
@ -214,14 +214,17 @@ public class AppRTCDemoActivity extends Activity
|
|||||||
|
|
||||||
{
|
{
|
||||||
logAndToast("Creating local video source...");
|
logAndToast("Creating local video source...");
|
||||||
VideoCapturer capturer = getVideoCapturer();
|
|
||||||
videoSource = factory.createVideoSource(
|
|
||||||
capturer, appRtcClient.videoConstraints());
|
|
||||||
MediaStream lMS = factory.createLocalMediaStream("ARDAMS");
|
MediaStream lMS = factory.createLocalMediaStream("ARDAMS");
|
||||||
VideoTrack videoTrack = factory.createVideoTrack("ARDAMSv0", videoSource);
|
if (appRtcClient.videoConstraints() != null) {
|
||||||
videoTrack.addRenderer(new VideoRenderer(new VideoCallbacks(
|
VideoCapturer capturer = getVideoCapturer();
|
||||||
vsv, VideoStreamsView.Endpoint.LOCAL)));
|
videoSource = factory.createVideoSource(
|
||||||
lMS.addTrack(videoTrack);
|
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"));
|
lMS.addTrack(factory.createAudioTrack("ARDAMSa0"));
|
||||||
pc.addStream(lMS, new MediaConstraints());
|
pc.addStream(lMS, new MediaConstraints());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user