Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java

Issue 1452783002: Fix VP9 support in AppRTCDemo. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 * Peer connection client implementation. 48 * Peer connection client implementation.
49 * 49 *
50 * <p>All public methods are routed to local looper thread. 50 * <p>All public methods are routed to local looper thread.
51 * All PeerConnectionEvents callbacks are invoked from the same looper thread. 51 * All PeerConnectionEvents callbacks are invoked from the same looper thread.
52 * This class is a singleton. 52 * This class is a singleton.
53 */ 53 */
54 public class PeerConnectionClient { 54 public class PeerConnectionClient {
55 public static final String VIDEO_TRACK_ID = "ARDAMSv0"; 55 public static final String VIDEO_TRACK_ID = "ARDAMSv0";
56 public static final String AUDIO_TRACK_ID = "ARDAMSa0"; 56 public static final String AUDIO_TRACK_ID = "ARDAMSa0";
57 private static final String TAG = "PCRTCClient"; 57 private static final String TAG = "PCRTCClient";
58 private static final String FIELD_TRIAL_VP9 = "WebRTC-SupportVP9/Enabled/";
59 private static final String FIELD_TRIAL_AUTOMATIC_RESIZE = 58 private static final String FIELD_TRIAL_AUTOMATIC_RESIZE =
60 "WebRTC-MediaCodecVideoEncoder-AutomaticResize/Enabled/"; 59 "WebRTC-MediaCodecVideoEncoder-AutomaticResize/Enabled/";
61 private static final String VIDEO_CODEC_VP8 = "VP8"; 60 private static final String VIDEO_CODEC_VP8 = "VP8";
62 private static final String VIDEO_CODEC_VP9 = "VP9"; 61 private static final String VIDEO_CODEC_VP9 = "VP9";
63 private static final String VIDEO_CODEC_H264 = "H264"; 62 private static final String VIDEO_CODEC_H264 = "H264";
64 private static final String AUDIO_CODEC_OPUS = "opus"; 63 private static final String AUDIO_CODEC_OPUS = "opus";
65 private static final String AUDIO_CODEC_ISAC = "ISAC"; 64 private static final String AUDIO_CODEC_ISAC = "ISAC";
66 private static final String VIDEO_CODEC_PARAM_START_BITRATE = 65 private static final String VIDEO_CODEC_PARAM_START_BITRATE =
67 "x-google-start-bitrate"; 66 "x-google-start-bitrate";
68 private static final String AUDIO_CODEC_PARAM_BITRATE = "maxaveragebitrate"; 67 private static final String AUDIO_CODEC_PARAM_BITRATE = "maxaveragebitrate";
(...skipping 18 matching lines...) Expand all
87 private final PCObserver pcObserver = new PCObserver(); 86 private final PCObserver pcObserver = new PCObserver();
88 private final SDPObserver sdpObserver = new SDPObserver(); 87 private final SDPObserver sdpObserver = new SDPObserver();
89 private final LooperExecutor executor; 88 private final LooperExecutor executor;
90 89
91 private PeerConnectionFactory factory; 90 private PeerConnectionFactory factory;
92 private PeerConnection peerConnection; 91 private PeerConnection peerConnection;
93 PeerConnectionFactory.Options options = null; 92 PeerConnectionFactory.Options options = null;
94 private VideoSource videoSource; 93 private VideoSource videoSource;
95 private boolean videoCallEnabled; 94 private boolean videoCallEnabled;
96 private boolean preferIsac; 95 private boolean preferIsac;
97 private boolean preferH264; 96 private String preferredVideoCodec;
98 private boolean videoSourceStopped; 97 private boolean videoSourceStopped;
99 private boolean isError; 98 private boolean isError;
100 private Timer statsTimer; 99 private Timer statsTimer;
101 private VideoRenderer.Callbacks localRender; 100 private VideoRenderer.Callbacks localRender;
102 private VideoRenderer.Callbacks remoteRender; 101 private VideoRenderer.Callbacks remoteRender;
103 private SignalingParameters signalingParameters; 102 private SignalingParameters signalingParameters;
104 private MediaConstraints pcConstraints; 103 private MediaConstraints pcConstraints;
105 private MediaConstraints videoConstraints; 104 private MediaConstraints videoConstraints;
106 private MediaConstraints audioConstraints; 105 private MediaConstraints audioConstraints;
107 private MediaConstraints sdpMediaConstraints; 106 private MediaConstraints sdpMediaConstraints;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 final Context context, 220 final Context context,
222 final PeerConnectionParameters peerConnectionParameters, 221 final PeerConnectionParameters peerConnectionParameters,
223 final PeerConnectionEvents events) { 222 final PeerConnectionEvents events) {
224 this.peerConnectionParameters = peerConnectionParameters; 223 this.peerConnectionParameters = peerConnectionParameters;
225 this.events = events; 224 this.events = events;
226 videoCallEnabled = peerConnectionParameters.videoCallEnabled; 225 videoCallEnabled = peerConnectionParameters.videoCallEnabled;
227 // Reset variables to initial states. 226 // Reset variables to initial states.
228 factory = null; 227 factory = null;
229 peerConnection = null; 228 peerConnection = null;
230 preferIsac = false; 229 preferIsac = false;
231 preferH264 = false;
232 videoSourceStopped = false; 230 videoSourceStopped = false;
233 isError = false; 231 isError = false;
234 queuedRemoteCandidates = null; 232 queuedRemoteCandidates = null;
235 localSdp = null; // either offer or answer SDP 233 localSdp = null; // either offer or answer SDP
236 mediaStream = null; 234 mediaStream = null;
237 videoCapturer = null; 235 videoCapturer = null;
238 renderVideo = true; 236 renderVideo = true;
239 localVideoTrack = null; 237 localVideoTrack = null;
240 remoteVideoTrack = null; 238 remoteVideoTrack = null;
241 statsTimer = new Timer(); 239 statsTimer = new Timer();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 public boolean isVideoCallEnabled() { 279 public boolean isVideoCallEnabled() {
282 return videoCallEnabled; 280 return videoCallEnabled;
283 } 281 }
284 282
285 private void createPeerConnectionFactoryInternal(Context context) { 283 private void createPeerConnectionFactoryInternal(Context context) {
286 Log.d(TAG, "Create peer connection factory. Use video: " + 284 Log.d(TAG, "Create peer connection factory. Use video: " +
287 peerConnectionParameters.videoCallEnabled); 285 peerConnectionParameters.videoCallEnabled);
288 isError = false; 286 isError = false;
289 287
290 // Initialize field trials. 288 // Initialize field trials.
291 String field_trials = FIELD_TRIAL_AUTOMATIC_RESIZE; 289 PeerConnectionFactory.initializeFieldTrials(FIELD_TRIAL_AUTOMATIC_RESIZE);
292 // Check if VP9 is used by default. 290
293 if (videoCallEnabled && peerConnectionParameters.videoCodec != null 291 // Check preferred video codec.
294 && peerConnectionParameters.videoCodec.equals(VIDEO_CODEC_VP9)) { 292 preferredVideoCodec = VIDEO_CODEC_VP8;
295 field_trials += FIELD_TRIAL_VP9; 293 if (videoCallEnabled && peerConnectionParameters.videoCodec != null) {
294 if (peerConnectionParameters.videoCodec.equals(VIDEO_CODEC_VP9)) {
295 preferredVideoCodec = VIDEO_CODEC_VP9;
296 } else if (peerConnectionParameters.videoCodec.equals(VIDEO_CODEC_H264)) {
297 preferredVideoCodec = VIDEO_CODEC_H264;
298 }
296 } 299 }
297 PeerConnectionFactory.initializeFieldTrials(field_trials); 300 Log.d(TAG, "Pereferred video codec: " + preferredVideoCodec);
298 301
299 // Check if H.264 is used by default.
300 preferH264 = false;
301 if (videoCallEnabled && peerConnectionParameters.videoCodec != null
302 && peerConnectionParameters.videoCodec.equals(VIDEO_CODEC_H264)) {
303 preferH264 = true;
304 }
305 // Check if ISAC is used by default. 302 // Check if ISAC is used by default.
306 preferIsac = false; 303 preferIsac = false;
307 if (peerConnectionParameters.audioCodec != null 304 if (peerConnectionParameters.audioCodec != null
308 && peerConnectionParameters.audioCodec.equals(AUDIO_CODEC_ISAC)) { 305 && peerConnectionParameters.audioCodec.equals(AUDIO_CODEC_ISAC)) {
309 preferIsac = true; 306 preferIsac = true;
310 } 307 }
311 if (!PeerConnectionFactory.initializeAndroidGlobals(context, true, true, 308 if (!PeerConnectionFactory.initializeAndroidGlobals(context, true, true,
312 peerConnectionParameters.videoCodecHwAcceleration)) { 309 peerConnectionParameters.videoCodecHwAcceleration)) {
313 events.onPeerConnectionError("Failed to initializeAndroidGlobals"); 310 events.onPeerConnectionError("Failed to initializeAndroidGlobals");
314 } 311 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 executor.execute(new Runnable() { 613 executor.execute(new Runnable() {
617 @Override 614 @Override
618 public void run() { 615 public void run() {
619 if (peerConnection == null || isError) { 616 if (peerConnection == null || isError) {
620 return; 617 return;
621 } 618 }
622 String sdpDescription = sdp.description; 619 String sdpDescription = sdp.description;
623 if (preferIsac) { 620 if (preferIsac) {
624 sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true); 621 sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
625 } 622 }
626 if (videoCallEnabled && preferH264) { 623 if (videoCallEnabled) {
627 sdpDescription = preferCodec(sdpDescription, VIDEO_CODEC_H264, false); 624 sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, fals e);
628 } 625 }
629 if (videoCallEnabled && peerConnectionParameters.videoStartBitrate > 0) { 626 if (videoCallEnabled && peerConnectionParameters.videoStartBitrate > 0) {
630 sdpDescription = setStartBitrate(VIDEO_CODEC_VP8, true, 627 sdpDescription = setStartBitrate(VIDEO_CODEC_VP8, true,
631 sdpDescription, peerConnectionParameters.videoStartBitrate); 628 sdpDescription, peerConnectionParameters.videoStartBitrate);
632 sdpDescription = setStartBitrate(VIDEO_CODEC_VP9, true, 629 sdpDescription = setStartBitrate(VIDEO_CODEC_VP9, true,
633 sdpDescription, peerConnectionParameters.videoStartBitrate); 630 sdpDescription, peerConnectionParameters.videoStartBitrate);
634 sdpDescription = setStartBitrate(VIDEO_CODEC_H264, true, 631 sdpDescription = setStartBitrate(VIDEO_CODEC_H264, true,
635 sdpDescription, peerConnectionParameters.videoStartBitrate); 632 sdpDescription, peerConnectionParameters.videoStartBitrate);
636 } 633 }
637 if (peerConnectionParameters.audioStartBitrate > 0) { 634 if (peerConnectionParameters.audioStartBitrate > 0) {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 @Override 962 @Override
966 public void onCreateSuccess(final SessionDescription origSdp) { 963 public void onCreateSuccess(final SessionDescription origSdp) {
967 if (localSdp != null) { 964 if (localSdp != null) {
968 reportError("Multiple SDP create."); 965 reportError("Multiple SDP create.");
969 return; 966 return;
970 } 967 }
971 String sdpDescription = origSdp.description; 968 String sdpDescription = origSdp.description;
972 if (preferIsac) { 969 if (preferIsac) {
973 sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true); 970 sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
974 } 971 }
975 if (videoCallEnabled && preferH264) { 972 if (videoCallEnabled) {
976 sdpDescription = preferCodec(sdpDescription, VIDEO_CODEC_H264, false); 973 sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, false) ;
977 } 974 }
978 final SessionDescription sdp = new SessionDescription( 975 final SessionDescription sdp = new SessionDescription(
979 origSdp.type, sdpDescription); 976 origSdp.type, sdpDescription);
980 localSdp = sdp; 977 localSdp = sdp;
981 executor.execute(new Runnable() { 978 executor.execute(new Runnable() {
982 @Override 979 @Override
983 public void run() { 980 public void run() {
984 if (peerConnection != null && !isError) { 981 if (peerConnection != null && !isError) {
985 Log.d(TAG, "Set local SDP from " + sdp.type); 982 Log.d(TAG, "Set local SDP from " + sdp.type);
986 peerConnection.setLocalDescription(sdpObserver, sdp); 983 peerConnection.setLocalDescription(sdpObserver, sdp);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 public void onCreateFailure(final String error) { 1030 public void onCreateFailure(final String error) {
1034 reportError("createSDP error: " + error); 1031 reportError("createSDP error: " + error);
1035 } 1032 }
1036 1033
1037 @Override 1034 @Override
1038 public void onSetFailure(final String error) { 1035 public void onSetFailure(final String error) {
1039 reportError("setSDP error: " + error); 1036 reportError("setSDP error: " + error);
1040 } 1037 }
1041 } 1038 }
1042 } 1039 }
OLDNEW
« no previous file with comments | « webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698