18ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher/* 28ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * Copyright (C) 2014 The Android Open Source Project 38ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * 48ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * Licensed under the Apache License, Version 2.0 (the "License"); 58ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * you may not use this file except in compliance with the License. 68ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * You may obtain a copy of the License at 78ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * 88ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * http://www.apache.org/licenses/LICENSE-2.0 98ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * 108ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * Unless required by applicable law or agreed to in writing, software 118ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * distributed under the License is distributed on an "AS IS" BASIS, 128ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * See the License for the specific language governing permissions and 148ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * limitations under the License. 158ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher */ 168ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 178ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherpackage com.android.ex.camera2.utils; 188ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 198ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport android.hardware.camera2.CameraCaptureSession; 20bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvalaimport android.hardware.camera2.CameraCaptureSession.CaptureCallback; 218ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport android.hardware.camera2.CaptureFailure; 228ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport android.hardware.camera2.CaptureRequest; 238ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport android.hardware.camera2.CaptureResult; 248ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport android.hardware.camera2.TotalCaptureResult; 258ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport android.os.Handler; 268ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 278ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher/** 28bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala * Proxy that forwards all updates to another {@link CaptureCallback}, invoking 298ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * its callbacks on a separate {@link Handler}. 308ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher */ 31bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvalapublic class Camera2CaptureCallbackForwarder extends CaptureCallback { 32bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala private CaptureCallback mListener; 338ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher private Handler mHandler; 348ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 35bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala public Camera2CaptureCallbackForwarder(CaptureCallback listener, Handler handler) { 368ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mListener = listener; 378ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mHandler = handler; 388ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 398ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 408ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 418ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureCompleted(final CameraCaptureSession session, final CaptureRequest request, 428ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher final TotalCaptureResult result) { 438ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mHandler.post(new Runnable() { 448ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 458ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void run() { 468ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mListener.onCaptureCompleted(session, request, result); 478ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher }}); 488ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 498ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 508ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 518ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureFailed(final CameraCaptureSession session, final CaptureRequest request, 528ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher final CaptureFailure failure) { 538ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mHandler.post(new Runnable() { 548ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 558ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void run() { 568ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mListener.onCaptureFailed(session, request, failure); 578ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher }}); 588ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 598ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 608ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 618ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureProgressed(final CameraCaptureSession session, 628ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher final CaptureRequest request, 638ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher final CaptureResult partialResult) { 648ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mHandler.post(new Runnable() { 658ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 668ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void run() { 678ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mListener.onCaptureProgressed(session, request, partialResult); 688ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher }}); 698ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 708ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 718ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 728ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureSequenceAborted(final CameraCaptureSession session, final int sequenceId) { 738ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mHandler.post(new Runnable() { 748ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 758ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void run() { 768ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mListener.onCaptureSequenceAborted(session, sequenceId); 778ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher }}); 788ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 798ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 808ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 818ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureSequenceCompleted(final CameraCaptureSession session, final int sequenceId, 828ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher final long frameNumber) { 838ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mHandler.post(new Runnable() { 848ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 858ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void run() { 868ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mListener.onCaptureSequenceCompleted(session, sequenceId, frameNumber); 878ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher }}); 888ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 898ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 908ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 918ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureStarted(final CameraCaptureSession session, final CaptureRequest request, 92171362f843c1e7623f29db1781176f85b1f74815Eino-Ville Talvala final long timestamp, final long frameNumber) { 938ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mHandler.post(new Runnable() { 948ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 958ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void run() { 96171362f843c1e7623f29db1781176f85b1f74815Eino-Ville Talvala mListener.onCaptureStarted(session, request, timestamp, frameNumber); 978ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher }}); 988ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 998ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher} 100