OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.media; | 5 package org.chromium.media; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.graphics.ImageFormat; | 9 import android.graphics.ImageFormat; |
10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // notified of capture events, instead, CrImageReaderListener wi
ll trigger every | 90 // notified of capture events, instead, CrImageReaderListener wi
ll trigger every |
91 // time a downloaded image is ready. Since |handler| is null, we
'll work on the | 91 // time a downloaded image is ready. Since |handler| is null, we
'll work on the |
92 // current Thread Looper. | 92 // current Thread Looper. |
93 mPreviewSession.setRepeatingRequest(mPreviewRequest, null, null)
; | 93 mPreviewSession.setRepeatingRequest(mPreviewRequest, null, null)
; |
94 } catch (CameraAccessException | SecurityException | IllegalStateExc
eption | 94 } catch (CameraAccessException | SecurityException | IllegalStateExc
eption |
95 | IllegalArgumentException ex) { | 95 | IllegalArgumentException ex) { |
96 Log.e(TAG, "setRepeatingRequest: ", ex); | 96 Log.e(TAG, "setRepeatingRequest: ", ex); |
97 return; | 97 return; |
98 } | 98 } |
99 // Now wait for trigger on CrImageReaderListener.onImageAvailable(); | 99 // Now wait for trigger on CrImageReaderListener.onImageAvailable(); |
| 100 nativeOnStarted(mNativeVideoCaptureDeviceAndroid); |
100 changeCameraStateAndNotify(CameraState.STARTED); | 101 changeCameraStateAndNotify(CameraState.STARTED); |
101 } | 102 } |
102 | 103 |
103 @Override | 104 @Override |
104 public void onConfigureFailed(CameraCaptureSession cameraCaptureSession)
{ | 105 public void onConfigureFailed(CameraCaptureSession cameraCaptureSession)
{ |
105 // TODO(mcasas): When signalling error, C++ will tear us down. Is th
ere need for | 106 // TODO(mcasas): When signalling error, C++ will tear us down. Is th
ere need for |
106 // cleanup? | 107 // cleanup? |
107 changeCameraStateAndNotify(CameraState.STOPPED); | 108 changeCameraStateAndNotify(CameraState.STOPPED); |
108 nativeOnError(mNativeVideoCaptureDeviceAndroid, "Camera session conf
iguration error"); | 109 nativeOnError(mNativeVideoCaptureDeviceAndroid, "Camera session conf
iguration error"); |
109 } | 110 } |
110 }; | 111 }; |
111 | 112 |
112 // Internal class implementing an ImageReader listener for Preview frames. G
ets pinged when a | 113 // Internal class implementing an ImageReader listener for Preview frames. G
ets pinged when a |
113 // new frame is been captured and downloads it to memory-backed buffers. | 114 // new frame is been captured and downloads it to memory-backed buffers. |
114 private class CrImageReaderListener implements ImageReader.OnImageAvailableL
istener { | 115 private class CrImageReaderListener implements ImageReader.OnImageAvailableL
istener { |
115 @Override | 116 @Override |
116 public void onImageAvailable(ImageReader reader) { | 117 public void onImageAvailable(ImageReader reader) { |
| 118 synchronized (mCameraStateLock) { |
| 119 if (mCameraState != CameraState.STARTED) return; |
| 120 } |
| 121 |
117 try (Image image = reader.acquireLatestImage()) { | 122 try (Image image = reader.acquireLatestImage()) { |
118 if (image == null) return; | 123 if (image == null) return; |
119 | 124 |
120 if (image.getFormat() != ImageFormat.YUV_420_888 || image.getPla
nes().length != 3) { | 125 if (image.getFormat() != ImageFormat.YUV_420_888 || image.getPla
nes().length != 3) { |
121 nativeOnError(mNativeVideoCaptureDeviceAndroid, "Unexpected
image format: " | 126 nativeOnError(mNativeVideoCaptureDeviceAndroid, "Unexpected
image format: " |
122 + image.getFormat() + " or #planes: " + image.getPla
nes().length); | 127 + image.getFormat() + " or #planes: " + image.getPla
nes().length); |
123 throw new IllegalStateException(); | 128 throw new IllegalStateException(); |
124 } | 129 } |
125 | 130 |
126 if (reader.getWidth() != image.getWidth() | 131 if (reader.getWidth() != image.getWidth() |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 return false; | 974 return false; |
970 } | 975 } |
971 return true; | 976 return true; |
972 } | 977 } |
973 | 978 |
974 @Override | 979 @Override |
975 public void deallocate() { | 980 public void deallocate() { |
976 Log.d(TAG, "deallocate"); | 981 Log.d(TAG, "deallocate"); |
977 } | 982 } |
978 } | 983 } |
OLD | NEW |