From d65b42fede592b23476b7046d806552b19ad7578 Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Thu, 29 May 2014 17:05:16 -0400 Subject: [PATCH] Bug 987979: Patch 11 - Add webrtc 3.50 support for Froyo/Gingerbread/Ice Cream Sandwich. r=blassey --- .../webrtc/voiceengine/WebRtcAudioRecord.java | 8 ++- .../webrtc/voiceengine/WebRtcAudioTrack.java | 2 +- .../videoengine/VideoCaptureAndroid.java | 57 +++++++++++++------ .../org/webrtc/videoengine/ViERenderer.java | 51 +++++++++++++++-- mobile/android/base/GeckoApp.java | 21 ++++--- 5 files changed, 102 insertions(+), 37 deletions(-) diff --git a/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java b/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java index 9167af02a5d..a7d422a25eb 100644 --- a/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java +++ b/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java @@ -48,7 +48,11 @@ class WebRtcAudioRecord { @SuppressWarnings("unused") private int InitRecording(int audioSource, int sampleRate) { - audioSource = AudioSource.VOICE_COMMUNICATION; + if(android.os.Build.VERSION.SDK_INT>=11) { + audioSource = AudioSource.VOICE_COMMUNICATION; + } else { + audioSource = AudioSource.DEFAULT; + } // get the minimum buffer size that can be used int minRecBufSize = AudioRecord.getMinBufferSize( sampleRate, @@ -185,7 +189,7 @@ class WebRtcAudioRecord { return _bufferedRecSamples; } - final String logTag = "WebRTC AD java"; + final String logTag = "WebRTC AR java"; private void DoLog(String msg) { Log.d(logTag, msg); diff --git a/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java b/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java index 273d03f3524..f5c4131a3e3 100644 --- a/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java +++ b/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java @@ -297,7 +297,7 @@ class WebRtcAudioTrack { return level; } - final String logTag = "WebRTC AD java"; + final String logTag = "WebRTC AT java"; private void DoLog(String msg) { Log.d(logTag, msg); diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java b/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java index 5bbcbbaee43..5e794713807 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java +++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java @@ -139,7 +139,11 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback { } Throwable error = null; try { - camera = Camera.open(id); + if(android.os.Build.VERSION.SDK_INT>8) { + camera = Camera.open(id); + } else { + camera = Camera.open(); + } localPreview = ViERenderer.GetLocalRenderer(); if (localPreview != null) { @@ -149,28 +153,43 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback { camera.setPreviewDisplay(localPreview); } } else { - // No local renderer (we only care about onPreviewFrame() buffers, not a - // directly-displayed UI element). Camera won't capture without - // setPreview{Texture,Display}, so we create a dummy SurfaceTexture and - // hand it over to Camera, but never listen for frame-ready callbacks, - // and never call updateTexImage on it. - try { - // "42" because http://goo.gl/KaEn8 - dummySurfaceTexture = new SurfaceTexture(42); - camera.setPreviewTexture(dummySurfaceTexture); - } catch (IOException e) { - throw new RuntimeException(e); + if(android.os.Build.VERSION.SDK_INT>10) { + // No local renderer (we only care about onPreviewFrame() buffers, not a + // directly-displayed UI element). Camera won't capture without + // setPreview{Texture,Display}, so we create a dummy SurfaceTexture and + // hand it over to Camera, but never listen for frame-ready callbacks, + // and never call updateTexImage on it. + try { + // "42" because http://goo.gl/KaEn8 + dummySurfaceTexture = new SurfaceTexture(42); + camera.setPreviewTexture(dummySurfaceTexture); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + throw new RuntimeException("No preview surface for Camera."); } } Camera.Parameters parameters = camera.getParameters(); - Log.d(TAG, "isVideoStabilizationSupported: " + - parameters.isVideoStabilizationSupported()); - if (parameters.isVideoStabilizationSupported()) { - parameters.setVideoStabilization(true); + // This wasn't added until ICS MR1. + if(android.os.Build.VERSION.SDK_INT>14) { + Log.d(TAG, "isVideoStabilizationSupported: " + + parameters.isVideoStabilizationSupported()); + if (parameters.isVideoStabilizationSupported()) { + parameters.setVideoStabilization(true); + } + } + List focusModeList = parameters.getSupportedFocusModes(); + if (focusModeList.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { + parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); } parameters.setPreviewSize(width, height); - parameters.setPreviewFpsRange(min_mfps, max_mfps); + if (android.os.Build.VERSION.SDK_INT>8) { + parameters.setPreviewFpsRange(min_mfps, max_mfps); + } else { + parameters.setPreviewFrameRate(max_mfps / 1000); + } int format = ImageFormat.NV21; parameters.setPreviewFormat(format); camera.setParameters(parameters); @@ -216,7 +235,9 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback { localPreview.removeCallback(this); camera.setPreviewDisplay(null); } else { - camera.setPreviewTexture(null); + if(android.os.Build.VERSION.SDK_INT>10) { + camera.setPreviewTexture(null); + } } camera.release(); camera = null; diff --git a/media/webrtc/trunk/webrtc/modules/video_render/android/java/src/org/webrtc/videoengine/ViERenderer.java b/media/webrtc/trunk/webrtc/modules/video_render/android/java/src/org/webrtc/videoengine/ViERenderer.java index 578bfa2d46b..9e832ae2d6e 100644 --- a/media/webrtc/trunk/webrtc/modules/video_render/android/java/src/org/webrtc/videoengine/ViERenderer.java +++ b/media/webrtc/trunk/webrtc/modules/video_render/android/java/src/org/webrtc/videoengine/ViERenderer.java @@ -11,13 +11,21 @@ package org.webrtc.videoengine; import android.content.Context; +import android.util.Log; +import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceView; +import android.view.View; + +import org.mozilla.gecko.GeckoApp; +import org.mozilla.gecko.GeckoAppShell; +import org.mozilla.gecko.util.ThreadUtils; public class ViERenderer { + private final static String TAG = "WEBRTC-ViEREnderer"; // View used for local rendering that Cameras can use for Video Overlay. - private static SurfaceHolder g_localRenderer; + private static SurfaceHolder g_localRenderer = null; public static SurfaceView CreateRenderer(Context context) { return CreateRenderer(context, false); @@ -44,10 +52,43 @@ public class ViERenderer { // ViECapture::AllocateCaptureDevice // LinearLayout.addview // ViECapture::StartCapture - public static SurfaceView CreateLocalRenderer(Context context) { - SurfaceView localRender = new SurfaceView(context); - g_localRenderer = localRender.getHolder(); - return localRender; + public static void CreateLocalRenderer() { + View cameraView = GeckoAppShell.getGeckoInterface().getCameraView(); + if (cameraView != null && (cameraView instanceof SurfaceView)) { + SurfaceView localRender = (SurfaceView)cameraView; + g_localRenderer = localRender.getHolder(); + } + + ThreadUtils.getUiHandler().post(new Runnable() { + @Override + public void run() { + try { + GeckoAppShell.getGeckoInterface().enableCameraView(); + } catch (Exception e) { + Log.e(TAG, "CreateLocalRenderer enableCameraView exception: " + + e.getLocalizedMessage()); + } + } + }); + } + + public static void DestroyLocalRenderer() { + if (g_localRenderer != null) { + g_localRenderer = null; + + ThreadUtils.getUiHandler().post(new Runnable() { + @Override + public void run() { + try { + GeckoAppShell.getGeckoInterface().disableCameraView(); + } catch (Exception e) { + Log.e(TAG, + "DestroyLocalRenderer disableCameraView exception: " + + e.getLocalizedMessage()); + } + } + }); + } } public static SurfaceHolder GetLocalRenderer() { diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index d30874ba363..bafca1b2147 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1381,11 +1381,10 @@ public abstract class GeckoApp mFormAssistPopup = (FormAssistPopup) findViewById(R.id.form_assist_popup); if (mCameraView == null) { + // Pre-ICS devices need the camera surface in a visible layout. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mCameraView = new SurfaceView(this); ((SurfaceView)mCameraView).getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); - } else { - mCameraView = new TextureView(this); } } @@ -1790,17 +1789,15 @@ public abstract class GeckoApp mCameraOrientationEventListener.enable(); // Try to make it fully transparent. - if (mCameraView instanceof SurfaceView) { + if (mCameraView != null && (mCameraView instanceof SurfaceView)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mCameraView.setAlpha(0.0f); } - } else if (mCameraView instanceof TextureView) { - mCameraView.setAlpha(0.0f); + ViewGroup mCameraLayout = (ViewGroup) findViewById(R.id.camera_layout); + // Some phones (eg. nexus S) need at least a 8x16 preview size + mCameraLayout.addView(mCameraView, + new AbsoluteLayout.LayoutParams(8, 16, 0, 0)); } - ViewGroup mCameraLayout = (ViewGroup) findViewById(R.id.camera_layout); - // Some phones (eg. nexus S) need at least a 8x16 preview size - mCameraLayout.addView(mCameraView, - new AbsoluteLayout.LayoutParams(8, 16, 0, 0)); } public void disableCameraView() { @@ -1808,8 +1805,10 @@ public abstract class GeckoApp mCameraOrientationEventListener.disable(); mCameraOrientationEventListener = null; } - ViewGroup mCameraLayout = (ViewGroup) findViewById(R.id.camera_layout); - mCameraLayout.removeView(mCameraView); + if (mCameraView != null) { + ViewGroup mCameraLayout = (ViewGroup) findViewById(R.id.camera_layout); + mCameraLayout.removeView(mCameraView); + } } public String getDefaultUAString() {