Igor Murashkin | 6c76f58 | 2014-07-15 17:19:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 16 | package android.hardware.camera2.impl; |
| 17 | |
| 18 | import android.hardware.camera2.CameraCaptureSession; |
| 19 | import android.hardware.camera2.CameraDevice; |
| 20 | import android.hardware.camera2.CaptureFailure; |
| 21 | import android.hardware.camera2.CaptureRequest; |
| 22 | import android.hardware.camera2.CaptureResult; |
| 23 | import android.hardware.camera2.TotalCaptureResult; |
| 24 | import android.hardware.camera2.dispatch.Dispatchable; |
| 25 | import android.hardware.camera2.dispatch.MethodNameInvoker; |
| 26 | |
| 27 | import static com.android.internal.util.Preconditions.*; |
| 28 | |
| 29 | /** |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 30 | * Proxy out invocations to the camera2 API callbacks into a {@link Dispatchable}. |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 31 | * |
| 32 | * <p>Since abstract classes do not support Java's dynamic {@code Proxy}, we have to |
| 33 | * to use our own proxy mechanism.</p> |
| 34 | */ |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 35 | public class CallbackProxies { |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 36 | |
| 37 | // TODO: replace with codegen |
| 38 | |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 39 | public static class DeviceStateCallbackProxy extends CameraDeviceImpl.StateCallbackKK { |
| 40 | private final MethodNameInvoker<CameraDeviceImpl.StateCallbackKK> mProxy; |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 41 | |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 42 | public DeviceStateCallbackProxy( |
| 43 | Dispatchable<CameraDeviceImpl.StateCallbackKK> dispatchTarget) { |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 44 | dispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null"); |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 45 | mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDeviceImpl.StateCallbackKK.class); |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void onOpened(CameraDevice camera) { |
| 50 | mProxy.invoke("onOpened", camera); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void onDisconnected(CameraDevice camera) { |
| 55 | mProxy.invoke("onDisconnected", camera); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void onError(CameraDevice camera, int error) { |
| 60 | mProxy.invoke("onError", camera, error); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void onUnconfigured(CameraDevice camera) { |
| 65 | mProxy.invoke("onUnconfigured", camera); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void onActive(CameraDevice camera) { |
| 70 | mProxy.invoke("onActive", camera); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void onBusy(CameraDevice camera) { |
| 75 | mProxy.invoke("onBusy", camera); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void onClosed(CameraDevice camera) { |
| 80 | mProxy.invoke("onClosed", camera); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void onIdle(CameraDevice camera) { |
| 85 | mProxy.invoke("onIdle", camera); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | @SuppressWarnings("deprecation") |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 90 | public static class DeviceCaptureCallbackProxy extends CameraDeviceImpl.CaptureCallback { |
| 91 | private final MethodNameInvoker<CameraDeviceImpl.CaptureCallback> mProxy; |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 92 | |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 93 | public DeviceCaptureCallbackProxy( |
| 94 | Dispatchable<CameraDeviceImpl.CaptureCallback> dispatchTarget) { |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 95 | dispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null"); |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 96 | mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDeviceImpl.CaptureCallback.class); |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void onCaptureStarted(CameraDevice camera, |
Eino-Ville Talvala | e8df309 | 2014-09-08 14:30:50 -0700 | [diff] [blame] | 101 | CaptureRequest request, long timestamp, long frameNumber) { |
| 102 | mProxy.invoke("onCaptureStarted", camera, request, timestamp, frameNumber); |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void onCapturePartial(CameraDevice camera, |
| 107 | CaptureRequest request, CaptureResult result) { |
| 108 | mProxy.invoke("onCapturePartial", camera, request, result); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void onCaptureProgressed(CameraDevice camera, |
| 113 | CaptureRequest request, CaptureResult partialResult) { |
| 114 | mProxy.invoke("onCaptureProgressed", camera, request, partialResult); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void onCaptureCompleted(CameraDevice camera, |
| 119 | CaptureRequest request, TotalCaptureResult result) { |
| 120 | mProxy.invoke("onCaptureCompleted", camera, request, result); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void onCaptureFailed(CameraDevice camera, |
| 125 | CaptureRequest request, CaptureFailure failure) { |
| 126 | mProxy.invoke("onCaptureFailed", camera, request, failure); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void onCaptureSequenceCompleted(CameraDevice camera, |
| 131 | int sequenceId, long frameNumber) { |
| 132 | mProxy.invoke("onCaptureSequenceCompleted", camera, sequenceId, frameNumber); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void onCaptureSequenceAborted(CameraDevice camera, |
| 137 | int sequenceId) { |
| 138 | mProxy.invoke("onCaptureSequenceAborted", camera, sequenceId); |
| 139 | } |
| 140 | } |
| 141 | |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 142 | public static class SessionStateCallbackProxy |
| 143 | extends CameraCaptureSession.StateCallback { |
| 144 | private final MethodNameInvoker<CameraCaptureSession.StateCallback> mProxy; |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 145 | |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 146 | public SessionStateCallbackProxy( |
| 147 | Dispatchable<CameraCaptureSession.StateCallback> dispatchTarget) { |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 148 | dispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null"); |
| 149 | mProxy = new MethodNameInvoker<>(dispatchTarget, |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 150 | CameraCaptureSession.StateCallback.class); |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void onConfigured(CameraCaptureSession session) { |
| 155 | mProxy.invoke("onConfigured", session); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | @Override |
| 160 | public void onConfigureFailed(CameraCaptureSession session) { |
| 161 | mProxy.invoke("onConfigureFailed", session); |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public void onReady(CameraCaptureSession session) { |
| 166 | mProxy.invoke("onReady", session); |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void onActive(CameraCaptureSession session) { |
| 171 | mProxy.invoke("onActive", session); |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public void onClosed(CameraCaptureSession session) { |
| 176 | mProxy.invoke("onClosed", session); |
| 177 | } |
| 178 | } |
| 179 | |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 180 | private CallbackProxies() { |
Igor Murashkin | 0b27d34 | 2014-05-30 09:45:05 -0700 | [diff] [blame] | 181 | throw new AssertionError(); |
| 182 | } |
| 183 | } |