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

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

Issue 1820113003: Add Mic Toggle button to AppRTCDemo (Android). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comment Created 4 years, 9 months 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/CallFragment.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
11 package org.appspot.apprtc; 11 package org.appspot.apprtc;
12 12
13 import android.content.Context; 13 import android.content.Context;
14 import android.os.ParcelFileDescriptor; 14 import android.os.ParcelFileDescriptor;
15 import android.os.Environment; 15 import android.os.Environment;
16 import android.util.Log; 16 import android.util.Log;
17 17
18 import org.appspot.apprtc.AppRTCClient.SignalingParameters; 18 import org.appspot.apprtc.AppRTCClient.SignalingParameters;
19 import org.appspot.apprtc.util.LooperExecutor; 19 import org.appspot.apprtc.util.LooperExecutor;
20 import org.webrtc.AudioTrack;
20 import org.webrtc.CameraEnumerationAndroid; 21 import org.webrtc.CameraEnumerationAndroid;
21 import org.webrtc.DataChannel; 22 import org.webrtc.DataChannel;
22 import org.webrtc.EglBase; 23 import org.webrtc.EglBase;
23 import org.webrtc.IceCandidate; 24 import org.webrtc.IceCandidate;
24 import org.webrtc.Logging; 25 import org.webrtc.Logging;
25 import org.webrtc.MediaCodecVideoEncoder; 26 import org.webrtc.MediaCodecVideoEncoder;
26 import org.webrtc.MediaConstraints; 27 import org.webrtc.MediaConstraints;
27 import org.webrtc.MediaConstraints.KeyValuePair; 28 import org.webrtc.MediaConstraints.KeyValuePair;
28 import org.webrtc.MediaStream; 29 import org.webrtc.MediaStream;
29 import org.webrtc.PeerConnection; 30 import org.webrtc.PeerConnection;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 private PeerConnectionEvents events; 118 private PeerConnectionEvents events;
118 private boolean isInitiator; 119 private boolean isInitiator;
119 private SessionDescription localSdp; // either offer or answer SDP 120 private SessionDescription localSdp; // either offer or answer SDP
120 private MediaStream mediaStream; 121 private MediaStream mediaStream;
121 private int numberOfCameras; 122 private int numberOfCameras;
122 private VideoCapturerAndroid videoCapturer; 123 private VideoCapturerAndroid videoCapturer;
123 // enableVideo is set to true if video should be rendered and sent. 124 // enableVideo is set to true if video should be rendered and sent.
124 private boolean renderVideo; 125 private boolean renderVideo;
125 private VideoTrack localVideoTrack; 126 private VideoTrack localVideoTrack;
126 private VideoTrack remoteVideoTrack; 127 private VideoTrack remoteVideoTrack;
128 // enableAudio is set to true if audio should be sent.
129 private boolean enableAudio;
130 private AudioTrack localAudioTrack;
127 131
128 /** 132 /**
129 * Peer connection parameters. 133 * Peer connection parameters.
130 */ 134 */
131 public static class PeerConnectionParameters { 135 public static class PeerConnectionParameters {
132 public final boolean videoCallEnabled; 136 public final boolean videoCallEnabled;
133 public final boolean loopback; 137 public final boolean loopback;
134 public final boolean tracing; 138 public final boolean tracing;
135 public final int videoWidth; 139 public final int videoWidth;
136 public final int videoHeight; 140 public final int videoHeight;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 preferIsac = false; 249 preferIsac = false;
246 videoSourceStopped = false; 250 videoSourceStopped = false;
247 isError = false; 251 isError = false;
248 queuedRemoteCandidates = null; 252 queuedRemoteCandidates = null;
249 localSdp = null; // either offer or answer SDP 253 localSdp = null; // either offer or answer SDP
250 mediaStream = null; 254 mediaStream = null;
251 videoCapturer = null; 255 videoCapturer = null;
252 renderVideo = true; 256 renderVideo = true;
253 localVideoTrack = null; 257 localVideoTrack = null;
254 remoteVideoTrack = null; 258 remoteVideoTrack = null;
259 enableAudio = true;
260 localAudioTrack = null;
255 statsTimer = new Timer(); 261 statsTimer = new Timer();
256 262
257 executor.execute(new Runnable() { 263 executor.execute(new Runnable() {
258 @Override 264 @Override
259 public void run() { 265 public void run() {
260 createPeerConnectionFactoryInternal(context); 266 createPeerConnectionFactoryInternal(context);
261 } 267 }
262 }); 268 });
263 } 269 }
264 270
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 Log.d(TAG, "Opening camera: " + cameraDeviceName); 491 Log.d(TAG, "Opening camera: " + cameraDeviceName);
486 videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null, 492 videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null,
487 peerConnectionParameters.captureToTexture ? renderEGLContext : null); 493 peerConnectionParameters.captureToTexture ? renderEGLContext : null);
488 if (videoCapturer == null) { 494 if (videoCapturer == null) {
489 reportError("Failed to open camera"); 495 reportError("Failed to open camera");
490 return; 496 return;
491 } 497 }
492 mediaStream.addTrack(createVideoTrack(videoCapturer)); 498 mediaStream.addTrack(createVideoTrack(videoCapturer));
493 } 499 }
494 500
495 mediaStream.addTrack(factory.createAudioTrack( 501 mediaStream.addTrack(createAudioTrack());
496 AUDIO_TRACK_ID,
497 factory.createAudioSource(audioConstraints)));
498 peerConnection.addStream(mediaStream); 502 peerConnection.addStream(mediaStream);
499 503
500 if (peerConnectionParameters.aecDump) { 504 if (peerConnectionParameters.aecDump) {
501 try { 505 try {
502 aecDumpFileDescriptor = ParcelFileDescriptor.open( 506 aecDumpFileDescriptor = ParcelFileDescriptor.open(
503 new File("/sdcard/Download/audio.aecdump"), 507 new File("/sdcard/Download/audio.aecdump"),
504 ParcelFileDescriptor.MODE_READ_WRITE | 508 ParcelFileDescriptor.MODE_READ_WRITE |
505 ParcelFileDescriptor.MODE_CREATE | 509 ParcelFileDescriptor.MODE_CREATE |
506 ParcelFileDescriptor.MODE_TRUNCATE); 510 ParcelFileDescriptor.MODE_TRUNCATE);
507 factory.startAecDump(aecDumpFileDescriptor.getFd(), -1); 511 factory.startAecDump(aecDumpFileDescriptor.getFd(), -1);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 602 }
599 }, 0, periodMs); 603 }, 0, periodMs);
600 } catch (Exception e) { 604 } catch (Exception e) {
601 Log.e(TAG, "Can not schedule statistics timer", e); 605 Log.e(TAG, "Can not schedule statistics timer", e);
602 } 606 }
603 } else { 607 } else {
604 statsTimer.cancel(); 608 statsTimer.cancel();
605 } 609 }
606 } 610 }
607 611
612 public void setAudioEnabled(final boolean enable) {
613 executor.execute(new Runnable() {
614 @Override
615 public void run() {
616 enableAudio = enable;
617 if (localAudioTrack != null) {
618 localAudioTrack.setEnabled(enableAudio);
619 }
620 }
621 });
622 }
623
608 public void setVideoEnabled(final boolean enable) { 624 public void setVideoEnabled(final boolean enable) {
609 executor.execute(new Runnable() { 625 executor.execute(new Runnable() {
610 @Override 626 @Override
611 public void run() { 627 public void run() {
612 renderVideo = enable; 628 renderVideo = enable;
613 if (localVideoTrack != null) { 629 if (localVideoTrack != null) {
614 localVideoTrack.setEnabled(renderVideo); 630 localVideoTrack.setEnabled(renderVideo);
615 } 631 }
616 if (remoteVideoTrack != null) { 632 if (remoteVideoTrack != null) {
617 remoteVideoTrack.setEnabled(renderVideo); 633 remoteVideoTrack.setEnabled(renderVideo);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 @Override 758 @Override
743 public void run() { 759 public void run() {
744 if (!isError) { 760 if (!isError) {
745 events.onPeerConnectionError(errorMessage); 761 events.onPeerConnectionError(errorMessage);
746 isError = true; 762 isError = true;
747 } 763 }
748 } 764 }
749 }); 765 });
750 } 766 }
751 767
768 private AudioTrack createAudioTrack() {
769 localAudioTrack = factory.createAudioTrack(
770 AUDIO_TRACK_ID,
771 factory.createAudioSource(audioConstraints));
772 localAudioTrack.setEnabled(enableAudio);
773 return localAudioTrack;
774 }
775
752 private VideoTrack createVideoTrack(VideoCapturerAndroid capturer) { 776 private VideoTrack createVideoTrack(VideoCapturerAndroid capturer) {
753 videoSource = factory.createVideoSource(capturer, videoConstraints); 777 videoSource = factory.createVideoSource(capturer, videoConstraints);
754 778
755 localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource); 779 localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
756 localVideoTrack.setEnabled(renderVideo); 780 localVideoTrack.setEnabled(renderVideo);
757 localVideoTrack.addRenderer(new VideoRenderer(localRender)); 781 localVideoTrack.addRenderer(new VideoRenderer(localRender));
758 return localVideoTrack; 782 return localVideoTrack;
759 } 783 }
760 784
761 private static String setStartBitrate(String codec, boolean isVideoCodec, 785 private static String setStartBitrate(String codec, boolean isVideoCodec,
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 public void onCreateFailure(final String error) { 1132 public void onCreateFailure(final String error) {
1109 reportError("createSDP error: " + error); 1133 reportError("createSDP error: " + error);
1110 } 1134 }
1111 1135
1112 @Override 1136 @Override
1113 public void onSetFailure(final String error) { 1137 public void onSetFailure(final String error) {
1114 reportError("setSDP error: " + error); 1138 reportError("setSDP error: " + error);
1115 } 1139 }
1116 } 1140 }
1117 } 1141 }
OLDNEW
« no previous file with comments | « webrtc/examples/androidapp/src/org/appspot/apprtc/CallFragment.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698