Bug 1264596 - GeckoApp: Remove mCameraView and related code. r=gcp,sebastian

MozReview-Commit-ID: ACgp4iIAigw

--HG--
extra : rebase_source : e0c92b6d8e68d82b7db3c195e22a457dbc43d95d
This commit is contained in:
Tushar Saini (:shatur) 2016-10-20 19:27:59 +05:30
Родитель 63cb3d50d0
Коммит 84a83b607a
6 изменённых файлов: 50 добавлений и 163 удалений

Просмотреть файл

@ -49,7 +49,6 @@ import org.mozilla.gecko.GeckoAppShell.AppStateListener;
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;
@ -81,14 +80,6 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback, AppStateL
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;
@ -209,45 +200,32 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback, AppStateL
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 +
@ -336,8 +314,6 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback, AppStateL
}
exchange(result, true);
return;
} catch (IOException e) {
error = e;
} catch (RuntimeException e) {
error = e;
}
@ -401,18 +377,11 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback, AppStateL
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;

Просмотреть файл

@ -24,25 +24,6 @@ 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
@ -53,19 +34,13 @@ public class ViERenderer {
// 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());
}
}
@ -73,26 +48,17 @@ public class ViERenderer {
}
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;
}
}

Просмотреть файл

@ -171,7 +171,6 @@ public abstract class GeckoApp
protected RelativeLayout mMainLayout;
protected RelativeLayout mGeckoLayout;
private View mCameraView;
private OrientationEventListener mCameraOrientationEventListener;
public List<GeckoAppShell.AppStateListener> mAppStateListeners = new LinkedList<GeckoAppShell.AppStateListener>();
protected MenuPanel mMenuPanel;
@ -333,11 +332,6 @@ public abstract class GeckoApp
return this;
}
@Override
public View getCameraView() {
return mCameraView;
}
@Override
public void addAppStateListener(GeckoAppShell.AppStateListener listener) {
mAppStateListeners.add(listener);
@ -1847,7 +1841,7 @@ public abstract class GeckoApp
}
@Override
public void enableCameraView() {
public void enableOrientationListener() {
// Start listening for orientation events
mCameraOrientationEventListener = new OrientationEventListener(this) {
@Override
@ -1860,27 +1854,14 @@ public abstract class GeckoApp
}
};
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

Просмотреть файл

@ -42,13 +42,6 @@
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">

Просмотреть файл

@ -80,13 +80,11 @@ public class BaseGeckoInterface implements GeckoAppShell.GeckoInterface {
@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
@ -96,12 +94,6 @@ public class BaseGeckoInterface implements GeckoAppShell.GeckoInterface {
@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) {}

Просмотреть файл

@ -1715,11 +1715,10 @@ public class GeckoAppShell
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();
@ -1829,7 +1828,7 @@ public class GeckoAppShell
public void run() {
try {
if (getGeckoInterface() != null)
getGeckoInterface().enableCameraView();
getGeckoInterface().enableOrientationListener();
} catch (Exception e) { }
}
});
@ -1879,19 +1878,6 @@ public class GeckoAppShell
}
}
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);
@ -1916,7 +1902,7 @@ public class GeckoAppShell
public void run() {
try {
if (getGeckoInterface() != null)
getGeckoInterface().disableCameraView();
getGeckoInterface().disableOrientationListener();
} catch (Exception e) { }
}
});