OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 // |camera| for null to account for having possibly waited for stopCapture() to | 69 // |camera| for null to account for having possibly waited for stopCapture() to |
70 // complete. | 70 // complete. |
71 @SuppressWarnings("deprecation") | 71 @SuppressWarnings("deprecation") |
72 public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba ck { | 72 public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba ck { |
73 private final static String TAG = "VideoCapturerAndroid"; | 73 private final static String TAG = "VideoCapturerAndroid"; |
74 private final static int CAMERA_OBSERVER_PERIOD_MS = 5000; | 74 private final static int CAMERA_OBSERVER_PERIOD_MS = 5000; |
75 | 75 |
76 private Camera camera; // Only non-null while capturing. | 76 private Camera camera; // Only non-null while capturing. |
77 private CameraThread cameraThread; | 77 private CameraThread cameraThread; |
78 private Handler cameraThreadHandler; | 78 private Handler cameraThreadHandler; |
79 // |cameraSurfaceTexture| is used with setPreviewTexture. Must be a member, se e issue webrtc:5021. | |
80 private SurfaceTexture cameraSurfaceTexture; | |
magjed_webrtc
2015/09/21 11:55:32
This is very strange. I hope we are not missing a
| |
79 private Context applicationContext; | 81 private Context applicationContext; |
80 private int id; | 82 private int id; |
81 private Camera.CameraInfo info; | 83 private Camera.CameraInfo info; |
82 private int cameraGlTexture = 0; | 84 private int cameraGlTexture = 0; |
83 private final FramePool videoBuffers = new FramePool(); | 85 private final FramePool videoBuffers = new FramePool(); |
84 // Remember the requested format in case we want to switch cameras. | 86 // Remember the requested format in case we want to switch cameras. |
85 private int requestedWidth; | 87 private int requestedWidth; |
86 private int requestedHeight; | 88 private int requestedHeight; |
87 private int requestedFramerate; | 89 private int requestedFramerate; |
88 // The capture format will be the closest supported format to the requested fo rmat. | 90 // The capture format will be the closest supported format to the requested fo rmat. |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 camera = Camera.open(id); | 316 camera = Camera.open(id); |
315 info = new Camera.CameraInfo(); | 317 info = new Camera.CameraInfo(); |
316 Camera.getCameraInfo(id, info); | 318 Camera.getCameraInfo(id, info); |
317 // No local renderer (we only care about onPreviewFrame() buffers, not a | 319 // No local renderer (we only care about onPreviewFrame() buffers, not a |
318 // directly-displayed UI element). Camera won't capture without | 320 // directly-displayed UI element). Camera won't capture without |
319 // setPreview{Texture,Display}, so we create a SurfaceTexture and hand | 321 // setPreview{Texture,Display}, so we create a SurfaceTexture and hand |
320 // it over to Camera, but never listen for frame-ready callbacks, | 322 // it over to Camera, but never listen for frame-ready callbacks, |
321 // and never call updateTexImage on it. | 323 // and never call updateTexImage on it. |
322 try { | 324 try { |
323 cameraGlTexture = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_O ES); | 325 cameraGlTexture = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_O ES); |
324 SurfaceTexture cameraSurfaceTexture = new SurfaceTexture(cameraGlTexture ); | 326 cameraSurfaceTexture = new SurfaceTexture(cameraGlTexture); |
325 cameraSurfaceTexture.setOnFrameAvailableListener(null); | 327 cameraSurfaceTexture.setOnFrameAvailableListener(null); |
326 | |
327 camera.setPreviewTexture(cameraSurfaceTexture); | 328 camera.setPreviewTexture(cameraSurfaceTexture); |
328 } catch (IOException e) { | 329 } catch (IOException e) { |
329 Logging.e(TAG, "setPreviewTexture failed", error); | 330 Logging.e(TAG, "setPreviewTexture failed", error); |
330 throw new RuntimeException(e); | 331 throw new RuntimeException(e); |
331 } | 332 } |
332 | 333 |
333 Logging.d(TAG, "Camera orientation: " + info.orientation + | 334 Logging.d(TAG, "Camera orientation: " + info.orientation + |
334 " .Device orientation: " + getDeviceOrientation()); | 335 " .Device orientation: " + getDeviceOrientation()); |
335 camera.setErrorCallback(cameraErrorCallback); | 336 camera.setErrorCallback(cameraErrorCallback); |
336 startPreviewOnCameraThread(width, height, framerate); | 337 startPreviewOnCameraThread(width, height, framerate); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 videoBuffers.stopReturnBuffersToCamera(); | 455 videoBuffers.stopReturnBuffersToCamera(); |
455 captureFormat = null; | 456 captureFormat = null; |
456 | 457 |
457 if (cameraGlTexture != 0) { | 458 if (cameraGlTexture != 0) { |
458 GLES20.glDeleteTextures(1, new int[] {cameraGlTexture}, 0); | 459 GLES20.glDeleteTextures(1, new int[] {cameraGlTexture}, 0); |
459 cameraGlTexture = 0; | 460 cameraGlTexture = 0; |
460 } | 461 } |
461 Logging.d(TAG, "Release camera."); | 462 Logging.d(TAG, "Release camera."); |
462 camera.release(); | 463 camera.release(); |
463 camera = null; | 464 camera = null; |
465 cameraSurfaceTexture = null; | |
464 } | 466 } |
465 | 467 |
466 private void switchCameraOnCameraThread(Runnable switchDoneEvent) { | 468 private void switchCameraOnCameraThread(Runnable switchDoneEvent) { |
467 Logging.d(TAG, "switchCameraOnCameraThread"); | 469 Logging.d(TAG, "switchCameraOnCameraThread"); |
468 | 470 |
469 doStopCaptureOnCameraThread(); | 471 doStopCaptureOnCameraThread(); |
470 startCaptureOnCameraThread(requestedWidth, requestedHeight, requestedFramera te, frameObserver, | 472 startCaptureOnCameraThread(requestedWidth, requestedHeight, requestedFramera te, frameObserver, |
471 applicationContext); | 473 applicationContext); |
472 pendingCameraSwitch = false; | 474 pendingCameraSwitch = false; |
473 Logging.d(TAG, "switchCameraOnCameraThread done"); | 475 Logging.d(TAG, "switchCameraOnCameraThread done"); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 } | 729 } |
728 | 730 |
729 private native void nativeCapturerStarted(long nativeCapturer, | 731 private native void nativeCapturerStarted(long nativeCapturer, |
730 boolean success); | 732 boolean success); |
731 private native void nativeOnFrameCaptured(long nativeCapturer, | 733 private native void nativeOnFrameCaptured(long nativeCapturer, |
732 byte[] data, int length, int width, int height, int rotation, long timeS tamp); | 734 byte[] data, int length, int width, int height, int rotation, long timeS tamp); |
733 private native void nativeOnOutputFormatRequest(long nativeCapturer, | 735 private native void nativeOnOutputFormatRequest(long nativeCapturer, |
734 int width, int height, int fps); | 736 int width, int height, int fps); |
735 } | 737 } |
736 } | 738 } |
OLD | NEW |