OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 surfaceHelper.startListening(this); | 460 surfaceHelper.startListening(this); |
461 } | 461 } |
462 | 462 |
463 // Start camera observer. | 463 // Start camera observer. |
464 maybePostDelayedOnCameraThread(CAMERA_OBSERVER_PERIOD_MS, cameraObserver); | 464 maybePostDelayedOnCameraThread(CAMERA_OBSERVER_PERIOD_MS, cameraObserver); |
465 return; | 465 return; |
466 } catch (RuntimeException e) { | 466 } catch (RuntimeException e) { |
467 error = e; | 467 error = e; |
468 } | 468 } |
469 Logging.e(TAG, "startCapture failed", error); | 469 Logging.e(TAG, "startCapture failed", error); |
470 if (camera != null) { | 470 // Make sure the camera is released. |
471 // Make sure the camera is released. | 471 stopCaptureOnCameraThread(); |
472 stopCaptureOnCameraThread(); | |
473 } | |
474 synchronized (handlerLock) { | 472 synchronized (handlerLock) { |
475 // Remove all pending Runnables posted from |this|. | 473 // Remove all pending Runnables posted from |this|. |
476 cameraThreadHandler.removeCallbacksAndMessages(this /* token */); | 474 cameraThreadHandler.removeCallbacksAndMessages(this /* token */); |
477 cameraThreadHandler = null; | 475 cameraThreadHandler = null; |
478 } | 476 } |
479 frameObserver.onCapturerStarted(false); | 477 frameObserver.onCapturerStarted(false); |
480 if (eventsHandler != null) { | 478 if (eventsHandler != null) { |
481 eventsHandler.onCameraError("Camera can not be started."); | 479 eventsHandler.onCameraError("Camera can not be started."); |
482 } | 480 } |
483 return; | 481 return; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 if (eventsHandler != null) { | 598 if (eventsHandler != null) { |
601 eventsHandler.onCameraError("Camera stop timeout"); | 599 eventsHandler.onCameraError("Camera stop timeout"); |
602 } | 600 } |
603 } | 601 } |
604 Logging.d(TAG, "stopCapture done"); | 602 Logging.d(TAG, "stopCapture done"); |
605 } | 603 } |
606 | 604 |
607 private void stopCaptureOnCameraThread() { | 605 private void stopCaptureOnCameraThread() { |
608 checkIsOnCameraThread(); | 606 checkIsOnCameraThread(); |
609 Logging.d(TAG, "stopCaptureOnCameraThread"); | 607 Logging.d(TAG, "stopCaptureOnCameraThread"); |
| 608 // Note that the camera might still not be started here if startCaptureOnCam
eraThread failed |
| 609 // and we posted a retry. |
610 | 610 |
611 // Make sure onTextureFrameAvailable() is not called anymore. | 611 // Make sure onTextureFrameAvailable() is not called anymore. |
612 surfaceHelper.stopListening(); | 612 if (surfaceHelper != null) { |
| 613 surfaceHelper.stopListening(); |
| 614 } |
613 cameraThreadHandler.removeCallbacks(cameraObserver); | 615 cameraThreadHandler.removeCallbacks(cameraObserver); |
614 cameraStatistics.getAndResetFrameCount(); | 616 cameraStatistics.getAndResetFrameCount(); |
615 Logging.d(TAG, "Stop preview."); | 617 Logging.d(TAG, "Stop preview."); |
616 camera.stopPreview(); | 618 if (camera != null) { |
617 camera.setPreviewCallbackWithBuffer(null); | 619 camera.stopPreview(); |
| 620 camera.setPreviewCallbackWithBuffer(null); |
| 621 } |
618 queuedBuffers.clear(); | 622 queuedBuffers.clear(); |
619 captureFormat = null; | 623 captureFormat = null; |
620 | 624 |
621 Logging.d(TAG, "Release camera."); | 625 Logging.d(TAG, "Release camera."); |
622 camera.release(); | 626 if (camera != null) { |
623 camera = null; | 627 camera.release(); |
| 628 camera = null; |
| 629 } |
624 if (eventsHandler != null) { | 630 if (eventsHandler != null) { |
625 eventsHandler.onCameraClosed(); | 631 eventsHandler.onCameraClosed(); |
626 } | 632 } |
627 Logging.d(TAG, "stopCaptureOnCameraThread done"); | 633 Logging.d(TAG, "stopCaptureOnCameraThread done"); |
628 } | 634 } |
629 | 635 |
630 private void switchCameraOnCameraThread() { | 636 private void switchCameraOnCameraThread() { |
631 checkIsOnCameraThread(); | 637 checkIsOnCameraThread(); |
632 Logging.d(TAG, "switchCameraOnCameraThread"); | 638 Logging.d(TAG, "switchCameraOnCameraThread"); |
633 stopCaptureOnCameraThread(); | 639 stopCaptureOnCameraThread(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 // Undo the mirror that the OS "helps" us with. | 745 // Undo the mirror that the OS "helps" us with. |
740 // http://developer.android.com/reference/android/hardware/Camera.html#set
DisplayOrientation(int) | 746 // http://developer.android.com/reference/android/hardware/Camera.html#set
DisplayOrientation(int) |
741 transformMatrix = | 747 transformMatrix = |
742 RendererCommon.multiplyMatrices(transformMatrix, RendererCommon.horizo
ntalFlipMatrix()); | 748 RendererCommon.multiplyMatrices(transformMatrix, RendererCommon.horizo
ntalFlipMatrix()); |
743 } | 749 } |
744 cameraStatistics.addFrame(); | 750 cameraStatistics.addFrame(); |
745 frameObserver.onTextureFrameCaptured(captureFormat.width, captureFormat.heig
ht, oesTextureId, | 751 frameObserver.onTextureFrameCaptured(captureFormat.width, captureFormat.heig
ht, oesTextureId, |
746 transformMatrix, rotation, timestampNs); | 752 transformMatrix, rotation, timestampNs); |
747 } | 753 } |
748 } | 754 } |
OLD | NEW |