diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/android/AndroidManifest.xml | 4 | ||||
-rw-r--r-- | examples/android/res/values-v21/styles.xml | 8 | ||||
-rw-r--r-- | examples/android/res/values/styles.xml | 8 | ||||
-rw-r--r-- | examples/android/src/org/appspot/apprtc/AppRTCAudioManager.java | 108 | ||||
-rw-r--r-- | examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java | 24 | ||||
-rw-r--r-- | examples/objc/AppRTCDemo/ios/APPRTCViewController.m | 21 | ||||
-rw-r--r-- | examples/objc/AppRTCDemo/mac/APPRTCViewController.m | 12 |
7 files changed, 166 insertions, 19 deletions
diff --git a/examples/android/AndroidManifest.xml b/examples/android/AndroidManifest.xml index 30fd46c..e24942a 100644 --- a/examples/android/AndroidManifest.xml +++ b/examples/android/AndroidManifest.xml @@ -7,7 +7,7 @@ <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> - <uses-sdk android:minSdkVersion="13" android:targetSdkVersion="19" /> + <uses-sdk android:minSdkVersion="13" android:targetSdkVersion="21" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> @@ -43,7 +43,7 @@ android:label="@string/app_name" android:screenOrientation="fullUser" android:configChanges="orientation|screenSize" - android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> + android:theme="@style/AppRTCDemoActivityTheme"> </activity> </application> </manifest> diff --git a/examples/android/res/values-v21/styles.xml b/examples/android/res/values-v21/styles.xml new file mode 100644 index 0000000..95f1ac6 --- /dev/null +++ b/examples/android/res/values-v21/styles.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <style name="AppRTCDemoActivityTheme" parent="android:Theme.Material"> + <item name="android:windowActionBar">false</item> + <item name="android:windowFullscreen">true</item> + <item name="android:windowNoTitle">true</item> + </style> +</resources> diff --git a/examples/android/res/values/styles.xml b/examples/android/res/values/styles.xml new file mode 100644 index 0000000..7f809a6 --- /dev/null +++ b/examples/android/res/values/styles.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <style name="AppRTCDemoActivityTheme" parent="android:Theme.Black"> + <item name="android:windowActionBar">false</item> + <item name="android:windowFullscreen">true</item> + <item name="android:windowNoTitle">true</item> + </style> +</resources> diff --git a/examples/android/src/org/appspot/apprtc/AppRTCAudioManager.java b/examples/android/src/org/appspot/apprtc/AppRTCAudioManager.java new file mode 100644 index 0000000..b2a1a44 --- /dev/null +++ b/examples/android/src/org/appspot/apprtc/AppRTCAudioManager.java @@ -0,0 +1,108 @@ +/* + * libjingle + * Copyright 2013, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.appspot.apprtc; + +import android.content.Context; +import android.media.AudioManager; +import android.util.Log; + +/** + * AppRTCAudioManager manages all audio related parts of the AppRTC demo. + * TODO(henrika): add support for device enumeration, device selection etc. + */ +public class AppRTCAudioManager { + private static final String TAG = "AppRTCAudioManager"; + + private boolean initialized = false; + private AudioManager audioManager; + private int savedAudioMode = AudioManager.MODE_INVALID; + private boolean savedIsSpeakerPhoneOn = false; + private boolean savedIsMicrophoneMute = false; + + /** Construction */ + static AppRTCAudioManager create(Context context) { + return new AppRTCAudioManager(context); + } + + private AppRTCAudioManager(Context context) { + Log.d(TAG, "AppRTCAudioManager"); + audioManager = ((AudioManager) context.getSystemService( + Context.AUDIO_SERVICE)); + } + + public void init() { + Log.d(TAG, "init"); + if (initialized) { + return; + } + + // Store current audio state so we can restore it when close() is called. + savedAudioMode = audioManager.getMode(); + savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn(); + savedIsMicrophoneMute = audioManager.isMicrophoneMute(); + + // The AppRTC demo shall always run in COMMUNICATION mode since it will + // result in best possible "VoIP settings", like audio routing, volume + // control etc. + audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); + + initialized = true; + } + + public void close() { + Log.d(TAG, "close"); + if (!initialized) { + return; + } + + // Restore previously stored audio states. + setSpeakerphoneOn(savedIsSpeakerPhoneOn); + setMicrophoneMute(savedIsMicrophoneMute); + audioManager.setMode(savedAudioMode); + + initialized = false; + } + + /** Sets the speaker phone mode. */ + private void setSpeakerphoneOn(boolean on) { + boolean wasOn = audioManager.isSpeakerphoneOn(); + if (wasOn == on) { + return; + } + audioManager.setSpeakerphoneOn(on); + } + + /** Sets the microphone mute state. */ + private void setMicrophoneMute(boolean on) { + boolean wasMuted = audioManager.isMicrophoneMute(); + if (wasMuted == on) { + return; + } + audioManager.setMicrophoneMute(on); + } +} diff --git a/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java b/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java index ad0e2d5..3ad26af 100644 --- a/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java +++ b/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java @@ -34,7 +34,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ActivityInfo; import android.graphics.Color; -import android.media.AudioManager; import android.net.Uri; import android.opengl.GLSurfaceView; import android.os.Bundle; @@ -72,6 +71,7 @@ public class AppRTCDemoActivity extends Activity private PeerConnectionClient pc; private AppRTCClient appRtcClient = new GAERTCClient(this, this); private AppRTCSignalingParameters appRtcParameters; + private AppRTCAudioManager audioManager = null; private View rootView; private View menuBar; private GLSurfaceView videoView; @@ -187,15 +187,9 @@ public class AppRTCDemoActivity extends Activity hudView.setVisibility(View.INVISIBLE); addContentView(hudView, hudLayout); - AudioManager audioManager = - ((AudioManager) getSystemService(AUDIO_SERVICE)); - // TODO(fischman): figure out how to do this Right(tm) and remove the - // suppression. - @SuppressWarnings("deprecation") - boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn(); - audioManager.setMode(isWiredHeadsetOn ? - AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION); - audioManager.setSpeakerphoneOn(!isWiredHeadsetOn); + // Create and audio manager that will take care of audio routing, + // audio modes, audio device enumeration etc. + audioManager = AppRTCAudioManager.create(this); final Intent intent = getIntent(); Uri url = intent.getData(); @@ -253,6 +247,10 @@ public class AppRTCDemoActivity extends Activity @Override protected void onDestroy() { disconnect(); + if (audioManager != null) { + audioManager.close(); + audioManager = null; + } super.onDestroy(); } @@ -360,6 +358,12 @@ public class AppRTCDemoActivity extends Activity // All events are called from UI thread. @Override public void onConnectedToRoom(final AppRTCSignalingParameters params) { + if (audioManager != null) { + // Store existing audio settings and change audio mode to + // MODE_IN_COMMUNICATION for best possible VoIP performance. + logAndToast("Initializing the audio manager..."); + audioManager.init(); + } appRtcParameters = params; abortUnless(PeerConnectionFactory.initializeAndroidGlobals( this, true, true, VideoRendererGui.getEGLContext()), diff --git a/examples/objc/AppRTCDemo/ios/APPRTCViewController.m b/examples/objc/AppRTCDemo/ios/APPRTCViewController.m index 8042762..d8d9714 100644 --- a/examples/objc/AppRTCDemo/ios/APPRTCViewController.m +++ b/examples/objc/AppRTCDemo/ios/APPRTCViewController.m @@ -34,6 +34,7 @@ #import <AVFoundation/AVFoundation.h> #import "APPRTCConnectionManager.h" #import "RTCEAGLVideoView.h" +#import "RTCVideoTrack.h" // Padding space for local video view with its parent. static CGFloat const kLocalViewPadding = 20; @@ -47,6 +48,8 @@ static CGFloat const kLocalViewPadding = 20; @implementation APPRTCViewController { APPRTCConnectionManager* _connectionManager; + RTCVideoTrack* _localVideoTrack; + RTCVideoTrack* _remoteVideoTrack; CGSize _localVideoSize; CGSize _remoteVideoSize; } @@ -101,13 +104,15 @@ static CGFloat const kLocalViewPadding = 20; - (void)connectionManager:(APPRTCConnectionManager*)manager didReceiveLocalVideoTrack:(RTCVideoTrack*)localVideoTrack { + _localVideoTrack = localVideoTrack; + [_localVideoTrack addRenderer:self.localVideoView]; self.localVideoView.hidden = NO; - self.localVideoView.videoTrack = localVideoTrack; } - (void)connectionManager:(APPRTCConnectionManager*)manager didReceiveRemoteVideoTrack:(RTCVideoTrack*)remoteVideoTrack { - self.remoteVideoView.videoTrack = remoteVideoTrack; + _remoteVideoTrack = remoteVideoTrack; + [_remoteVideoTrack addRenderer:self.remoteVideoView]; } - (void)connectionManagerDidReceiveHangup:(APPRTCConnectionManager*)manager { @@ -193,8 +198,16 @@ static CGFloat const kLocalViewPadding = 20; self.instructionsView.hidden = NO; self.logView.hidden = YES; self.logView.text = nil; - self.localVideoView.videoTrack = nil; - self.remoteVideoView.videoTrack = nil; + if (_localVideoTrack) { + [_localVideoTrack removeRenderer:self.localVideoView]; + _localVideoTrack = nil; + [self.localVideoView renderFrame:nil]; + } + if (_remoteVideoTrack) { + [_remoteVideoTrack removeRenderer:self.remoteVideoView]; + _remoteVideoTrack = nil; + [self.remoteVideoView renderFrame:nil]; + } self.blackView.hidden = YES; } diff --git a/examples/objc/AppRTCDemo/mac/APPRTCViewController.m b/examples/objc/AppRTCDemo/mac/APPRTCViewController.m index cf5b836..08acac9 100644 --- a/examples/objc/AppRTCDemo/mac/APPRTCViewController.m +++ b/examples/objc/AppRTCDemo/mac/APPRTCViewController.m @@ -30,6 +30,7 @@ #import <AVFoundation/AVFoundation.h> #import "APPRTCConnectionManager.h" #import "RTCNSGLVideoView.h" +#import "RTCVideoTrack.h" static NSUInteger const kContentWidth = 1280; static NSUInteger const kContentHeight = 720; @@ -227,6 +228,8 @@ static NSUInteger const kLogViewHeight = 280; @implementation APPRTCViewController { APPRTCConnectionManager* _connectionManager; + RTCVideoTrack* _localVideoTrack; + RTCVideoTrack* _remoteVideoTrack; } - (instancetype)initWithNibName:(NSString*)nibName @@ -258,12 +261,13 @@ static NSUInteger const kLogViewHeight = 280; - (void)connectionManager:(APPRTCConnectionManager*)manager didReceiveLocalVideoTrack:(RTCVideoTrack*)localVideoTrack { - self.mainView.localVideoView.videoTrack = localVideoTrack; + _localVideoTrack = localVideoTrack; } - (void)connectionManager:(APPRTCConnectionManager*)manager didReceiveRemoteVideoTrack:(RTCVideoTrack*)remoteVideoTrack { - self.mainView.remoteVideoView.videoTrack = remoteVideoTrack; + _remoteVideoTrack = remoteVideoTrack; + [_remoteVideoTrack addRenderer:self.mainView.remoteVideoView]; } - (void)connectionManagerDidReceiveHangup:(APPRTCConnectionManager*)manager { @@ -305,7 +309,9 @@ static NSUInteger const kLogViewHeight = 280; } - (void)disconnect { - self.mainView.remoteVideoView.videoTrack = nil; + [_remoteVideoTrack removeRenderer:self.mainView.remoteVideoView]; + _remoteVideoTrack = nil; + [self.mainView.remoteVideoView renderFrame:nil]; [_connectionManager disconnect]; } |