Bug 1264596 - GeckoApp: Remove mCameraView and related code. r?sebastian draft
authorTushar Saini (:shatur) <tushar.saini1285@gmail.com>
Thu, 20 Oct 2016 19:27:59 +0530
changeset 427574 0d6dd85bb98a85671b7dfd5e7f14eec8559d3017
parent 427338 99a239e1866a57f987b08dad796528e4ea30e622
child 534501 3cd226034f6b9299db0314e453ec24b3a2e75520
push id33053
push userbmo:tushar.saini1285@gmail.com
push dateThu, 20 Oct 2016 15:46:15 +0000
reviewerssebastian
bugs1264596
milestone52.0a1
Bug 1264596 - GeckoApp: Remove mCameraView and related code. r?sebastian MozReview-Commit-ID: ACgp4iIAigw
media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java
media/webrtc/trunk/webrtc/modules/video_render/android/java/src/org/webrtc/videoengine/ViERenderer.java
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/resources/layout/gecko_app.xml
mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
--- 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
@@ -44,17 +44,16 @@ import org.mozilla.gecko.GeckoAppShell.A
 // a performance bottleneck because only onPreviewFrame() is called more than
 // once (and is called serially on a single thread), so the lock should be
 // uncontended.  Note that each of these synchronized methods must check
 // |camera| for null to account for having possibly waited for stopCapture() to
 // complete.
 public class VideoCaptureAndroid implements PreviewCallback, Callback, AppStateListener {
   private final static String TAG = "WEBRTC-JC";
 
-  private static SurfaceHolder localPreview;
   // Only non-null while capturing, accessed exclusively from synchronized methods.
   Camera camera;
   private Camera.CameraInfo info;
   private CameraThread cameraThread;
   private Handler cameraThreadHandler;
   private Context context;
   private final int id;
   private volatile long native_capturer;  // |VideoCaptureAndroid*| in C++.
@@ -76,24 +75,16 @@ public class VideoCaptureAndroid impleme
   // due to the application being backgrounded.
   boolean mResumeCapture;
 
   private double averageDurationMs;
   private long lastCaptureTimeMs;
   private int frameCount;
   private int frameDropRatio;
 
-  // Requests future capturers to send their frames to |localPreview| directly.
-  public static void setLocalPreview(SurfaceHolder localPreview) {
-    // It is a gross hack that this is a class-static.  Doing it right would
-    // mean plumbing this through the C++ API and using it from
-    // webrtc/examples/android/media_demo's MediaEngine class.
-    VideoCaptureAndroid.localPreview = localPreview;
-  }
-
   @WebRTCJNITarget
   public VideoCaptureAndroid(int id, long native_capturer) {
     this.id = id;
     this.native_capturer = native_capturer;
     this.context = GetContext();
     if(android.os.Build.VERSION.SDK_INT>8) {
       this.info = new Camera.CameraInfo();
       Camera.getCameraInfo(id, info);
@@ -204,55 +195,42 @@ public class VideoCaptureAndroid impleme
     Throwable error = null;
     try {
       if(android.os.Build.VERSION.SDK_INT>8) {
         camera = Camera.open(id);
       } else {
         camera = Camera.open();
       }
 
-      localPreview = ViERenderer.GetLocalRenderer();
-      if (localPreview != null) {
-        localPreview.addCallback(this);
-        if (localPreview.getSurface() != null &&
-            localPreview.getSurface().isValid()) {
-          camera.setPreviewDisplay(localPreview);
-        }
-      } else {
-        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 SurfaceTexture and hand
-          // it over to Camera, but never listen for frame-ready callbacks,
-          // and never call updateTexImage on it.
-          try {
-            cameraGlTextures = new int[1];
+      // 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 SurfaceTexture and hand
+      // it over to Camera, but never listen for frame-ready callbacks,
+      // and never call updateTexImage on it.
+      try {
+        cameraGlTextures = new int[1];
 
-            // Generate one texture pointer and bind it as an external texture.
-            GLES20.glGenTextures(1, cameraGlTextures, 0);
-            GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                                 cameraGlTextures[0]);
-            GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                                   GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
-            GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                                   GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
-            GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                                   GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
-            GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                                   GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
+        // Generate one texture pointer and bind it as an external texture.
+        GLES20.glGenTextures(1, cameraGlTextures, 0);
+        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                               cameraGlTextures[0]);
+        GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                               GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
+        GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                               GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
+        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                               GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
+        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                               GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
 
-            cameraSurfaceTexture = new SurfaceTexture(cameraGlTextures[0]);
-            cameraSurfaceTexture.setOnFrameAvailableListener(null);
-            camera.setPreviewTexture(cameraSurfaceTexture);
-          } catch (IOException e) {
-            throw new RuntimeException(e);
-          }
-        } else {
-          throw new RuntimeException("No preview surface for Camera.");
-        }
+        cameraSurfaceTexture = new SurfaceTexture(cameraGlTextures[0]);
+        cameraSurfaceTexture.setOnFrameAvailableListener(null);
+        camera.setPreviewTexture(cameraSurfaceTexture);
+      } catch (IOException e) {
+        throw new RuntimeException(e);
       }
 
       Log.d(TAG, "Camera orientation: " + info.orientation +
           ". Device orientation: " + getDeviceOrientation());
       Camera.Parameters parameters = camera.getParameters();
       // This wasn't added until ICS MR1.
       if(android.os.Build.VERSION.SDK_INT>14) {
         Log.d(TAG, "isVideoStabilizationSupported: " +
@@ -331,18 +309,16 @@ public class VideoCaptureAndroid impleme
       mCaptureMinFPS = min_mfps;
       mCaptureMaxFPS = max_mfps;
       // If we are resuming a paused capture, the listener is already active.
       if (!mResumeCapture) {
         GeckoAppShell.getGeckoInterface().addAppStateListener(this);
       }
       exchange(result, true);
       return;
-    } catch (IOException e) {
-      error = e;
     } catch (RuntimeException e) {
       error = e;
     }
     Log.e(TAG, "startCapture failed", error);
     if (camera != null) {
       Exchanger<Boolean> resultDropper = new Exchanger<Boolean>();
       stopCaptureOnCameraThread(resultDropper);
       exchange(resultDropper, false);
@@ -396,28 +372,21 @@ public class VideoCaptureAndroid impleme
         return;
       }
       throw new RuntimeException("Camera is already stopped!");
     }
     Throwable error = null;
     try {
       camera.setPreviewCallbackWithBuffer(null);
       camera.stopPreview();
-      if (localPreview != null) {
-        localPreview.removeCallback(this);
-        camera.setPreviewDisplay(null);
-      } else {
-        if(android.os.Build.VERSION.SDK_INT>10) {
-          camera.setPreviewTexture(null);
-          cameraSurfaceTexture = null;
-          if (cameraGlTextures != null) {
-            GLES20.glDeleteTextures(1, cameraGlTextures, 0);
-            cameraGlTextures = null;
-          }
-        }
+      camera.setPreviewTexture(null);
+      cameraSurfaceTexture = null;
+      if (cameraGlTextures != null) {
+        GLES20.glDeleteTextures(1, cameraGlTextures, 0);
+        cameraGlTextures = null;
       }
       camera.release();
       camera = null;
       // If we want to resume after onResume, keep the listener in place.
       if (!mResumeCapture) {
         GeckoAppShell.getGeckoInterface().removeAppStateListener(this);
         ViERenderer.DestroyLocalRenderer();
       }
--- 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
@@ -19,80 +19,46 @@ 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;
-
-    public static SurfaceView CreateRenderer(Context context) {
-        return CreateRenderer(context, false);
-    }
-
-    public static SurfaceView CreateRenderer(Context context,
-            boolean useOpenGLES2) {
-        if(useOpenGLES2 == true && ViEAndroidGLES20.IsSupported(context))
-            return new ViEAndroidGLES20(context);
-        else
-            return new SurfaceView(context);
-    }
-
-    // Creates a SurfaceView to be used by Android Camera
-    // service to display a local preview.
-    // This needs to be used on Android prior to version 2.1
-    // in order to run the camera.
     // Call this function before ViECapture::StartCapture.
     // The created view needs to be added to a visible layout
     // after a camera has been allocated
     // (with the call ViECapture::AllocateCaptureDevice).
     // IE.
     // CreateLocalRenderer
     // ViECapture::AllocateCaptureDevice
     // LinearLayout.addview
     // ViECapture::StartCapture
     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();
+                    GeckoAppShell.getGeckoInterface().enableOrientationListener();
                 } catch (Exception e) {
-                    Log.e(TAG, "CreateLocalRenderer enableCameraView exception: "
+                    Log.e(TAG, "enableOrientationListener 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());
-                    }
+        ThreadUtils.getUiHandler().post(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    GeckoAppShell.getGeckoInterface().disableOrientationListener();
+                } catch (Exception e) {
+                    Log.e(TAG,
+                          "disableOrientationListener exception: " +
+                          e.getLocalizedMessage());
                 }
-            });
-        }
+            }
+        });
     }
-
-    public static SurfaceHolder GetLocalRenderer() {
-        return g_localRenderer;
-    }
-
 }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -166,17 +166,16 @@ public abstract class GeckoApp
     private static final int CLEANUP_DEFERRAL_SECONDS = 15;
 
     private static boolean sAlreadyLoaded;
 
     protected RelativeLayout mRootLayout;
     protected RelativeLayout mMainLayout;
 
     protected RelativeLayout mGeckoLayout;
-    private View mCameraView;
     private OrientationEventListener mCameraOrientationEventListener;
     public List<GeckoAppShell.AppStateListener> mAppStateListeners = new LinkedList<GeckoAppShell.AppStateListener>();
     protected MenuPanel mMenuPanel;
     protected Menu mMenu;
     protected boolean mIsRestoringActivity;
 
     /** Tells if we're aborting app launch, e.g. if this is an unsupported device configuration. */
     protected boolean mIsAbortingAppLaunch;
@@ -329,21 +328,16 @@ public abstract class GeckoApp
     }
 
     @Override
     public Activity getActivity() {
         return this;
     }
 
     @Override
-    public View getCameraView() {
-        return mCameraView;
-    }
-
-    @Override
     public void addAppStateListener(GeckoAppShell.AppStateListener listener) {
         mAppStateListeners.add(listener);
     }
 
     @Override
     public void removeAppStateListener(GeckoAppShell.AppStateListener listener) {
         mAppStateListeners.remove(listener);
     }
@@ -1846,50 +1840,37 @@ public abstract class GeckoApp
 
         StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                                .detectAll()
                                .penaltyLog()
                                .build());
     }
 
     @Override
-    public void enableCameraView() {
+    public void enableOrientationListener() {
         // Start listening for orientation events
         mCameraOrientationEventListener = new OrientationEventListener(this) {
             @Override
             public void onOrientationChanged(int orientation) {
                 if (mAppStateListeners != null) {
                     for (GeckoAppShell.AppStateListener listener: mAppStateListeners) {
                         listener.onOrientationChanged();
                     }
                 }
             }
         };
         mCameraOrientationEventListener.enable();
-
-        // Try to make it fully transparent.
-        if (mCameraView instanceof SurfaceView) {
-            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));
-        }
     }
 
     @Override
-    public void disableCameraView() {
+    public void disableOrientationListener() {
         if (mCameraOrientationEventListener != null) {
             mCameraOrientationEventListener.disable();
             mCameraOrientationEventListener = null;
         }
-        if (mCameraView != null) {
-          ViewGroup mCameraLayout = (ViewGroup) findViewById(R.id.camera_layout);
-          mCameraLayout.removeView(mCameraView);
-        }
     }
 
     @Override
     public String getDefaultUAString() {
         return HardwareUtils.isTablet() ? AppConstants.USER_AGENT_FENNEC_TABLET :
                                           AppConstants.USER_AGENT_FENNEC_MOBILE;
     }
 
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -37,23 +37,16 @@
                             android:layout_width="match_parent"
                             android:layout_height="match_parent"/>
 
             <org.mozilla.gecko.FormAssistPopup android:id="@+id/form_assist_popup"
                                                android:layout_width="match_parent"
                                                android:layout_height="match_parent"
                                                android:visibility="gone"/>
 
-            <FrameLayout android:id="@+id/camera_layout"
-                         android:layout_height="wrap_content"
-                         android:layout_width="wrap_content"
-                         android:layout_alignParentRight="true"
-                         android:layout_alignParentBottom="true">
-            </FrameLayout>
-
             <view class="org.mozilla.gecko.media.VideoPlayer" android:id="@+id/video_player"
                          android:layout_height="match_parent"
                          android:layout_width="match_parent">
             </view>
 
             <ViewStub android:id="@+id/zoomed_view_stub"
                       android:inflatedId="@+id/zoomed_view"
                       android:layout="@layout/zoomed_view"
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
@@ -75,38 +75,30 @@ public class BaseGeckoInterface implemen
     // Bug 908779: Implement this
     @Override
     public void addPluginView(final View view) {}
 
     // Bug 908781: Implement this
     @Override
     public void removePluginView(final View view) {}
 
-    // Bug 908783: Implement this
     @Override
-    public void enableCameraView() {}
+    public void enableOrientationListener() {}
 
-    // Bug 908785: Implement this
     @Override
-    public void disableCameraView() {}
+    public void disableOrientationListener() {}
 
     // Bug 908786: Implement this
     @Override
     public void addAppStateListener(GeckoAppShell.AppStateListener listener) {}
 
     // Bug 908787: Implement this
     @Override
     public void removeAppStateListener(GeckoAppShell.AppStateListener listener) {}
 
-    // Bug 908788: Implement this
-    @Override
-    public View getCameraView() {
-        return null;
-    }
-
     // Bug 908789: Implement this
     @Override
     public void notifyWakeLockChanged(String topic, String state) {}
 
     @Override
     public boolean areTabsShown() {
         return false;
     }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -1710,21 +1710,20 @@ public class GeckoAppShell
         public EventDispatcher getAppEventDispatcher();
         public GeckoProfile getProfile();
         public Activity getActivity();
         public String getDefaultUAString();
         public void doRestart();
         public void setFullScreen(boolean fullscreen);
         public void addPluginView(View view);
         public void removePluginView(final View view);
-        public void enableCameraView();
-        public void disableCameraView();
+        public void enableOrientationListener();
+        public void disableOrientationListener();
         public void addAppStateListener(AppStateListener listener);
         public void removeAppStateListener(AppStateListener listener);
-        public View getCameraView();
         public void notifyWakeLockChanged(String topic, String state);
         public boolean areTabsShown();
         public AbsoluteLayout getPluginContainer();
         public void notifyCheckUpdateResult(String result);
         public void invalidateOptionsMenu();
 
         /**
          * Create a shortcut -- generally a home-screen icon -- linking the given title to the given URI.
@@ -1824,17 +1823,17 @@ public class GeckoAppShell
 
     @WrapForJNI(calledFrom = "gecko")
     private static int[] initCamera(String aContentType, int aCamera, int aWidth, int aHeight) {
         ThreadUtils.postToUiThread(new Runnable() {
                 @Override
                 public void run() {
                     try {
                         if (getGeckoInterface() != null)
-                            getGeckoInterface().enableCameraView();
+                            getGeckoInterface().enableOrientationListener();
                     } catch (Exception e) { }
                 }
             });
 
         // [0] = 0|1 (failure/success)
         // [1] = width
         // [2] = height
         // [3] = fps
@@ -1874,29 +1873,16 @@ public class GeckoAppShell
                 Camera.Size size = sit.next();
                 if (Math.abs(size.width * size.height - aWidth * aHeight) < sizeDelta) {
                     sizeDelta = Math.abs(size.width * size.height - aWidth * aHeight);
                     params.setPreviewSize(size.width, size.height);
                     bufferSize = size.width * size.height;
                 }
             }
 
-            try {
-                if (getGeckoInterface() != null) {
-                    View cameraView = getGeckoInterface().getCameraView();
-                    if (cameraView instanceof SurfaceView) {
-                        sCamera.setPreviewDisplay(((SurfaceView)cameraView).getHolder());
-                    } else if (cameraView instanceof TextureView) {
-                        sCamera.setPreviewTexture(((TextureView)cameraView).getSurfaceTexture());
-                    }
-                }
-            } catch (IOException | RuntimeException e) {
-                Log.w(LOGTAG, "Error setPreviewXXX:", e);
-            }
-
             sCamera.setParameters(params);
             sCameraBuffer = new byte[(bufferSize * 12) / 8];
             sCamera.addCallbackBuffer(sCameraBuffer);
             sCamera.setPreviewCallbackWithBuffer(new CameraCallback(aCamera));
             sCamera.startPreview();
             params = sCamera.getParameters();
             result[0] = 1;
             result[1] = params.getPreviewSize().width;
@@ -1911,17 +1897,17 @@ public class GeckoAppShell
 
     @WrapForJNI(calledFrom = "gecko")
     private static synchronized void closeCamera() {
         ThreadUtils.postToUiThread(new Runnable() {
                 @Override
                 public void run() {
                     try {
                         if (getGeckoInterface() != null)
-                            getGeckoInterface().disableCameraView();
+                            getGeckoInterface().disableOrientationListener();
                     } catch (Exception e) { }
                 }
             });
         if (sCamera != null) {
             sCamera.stopPreview();
             sCamera.release();
             sCamera = null;
             sCameraBuffer = null;