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 Boucher 268ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport java.util.Arrays; 278ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport java.util.LinkedList; 288ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucherimport java.util.List; 298ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 308ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher/** 31bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala * Junction that allows notifying multiple {@link CaptureCallback}s whenever 328ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * the {@link CameraCaptureSession} posts a capture-related update. 338ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher */ 34bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvalapublic class Camera2CaptureCallbackSplitter extends CaptureCallback { 35bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala private final List<CaptureCallback> mRecipients = new LinkedList<>(); 368ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 378ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher /** 388ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * @param recipients The listeners to notify. Any {@code null} passed here 398ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher * will be completely ignored. 408ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher */ 41bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala public Camera2CaptureCallbackSplitter(CaptureCallback... recipients) { 42bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala for (CaptureCallback listener : recipients) { 438ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher if (listener != null) { 448ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher mRecipients.add(listener); 458ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 468ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 478ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 488ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 498ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 508ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, 518ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher TotalCaptureResult result) { 52bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala for (CaptureCallback target : mRecipients) { 538ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher target.onCaptureCompleted(session, request, result); 548ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 558ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 568ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 578ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 588ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, 598ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher CaptureFailure failure) { 60bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala for (CaptureCallback target : mRecipients) { 618ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher target.onCaptureFailed(session, request, failure); 628ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 638ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 648ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 658ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 668ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request, 678ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher CaptureResult partialResult) { 68bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala for (CaptureCallback target : mRecipients) { 698ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher target.onCaptureProgressed(session, request, partialResult); 708ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 718ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 728ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 738ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 748ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureSequenceAborted(CameraCaptureSession session, int sequenceId) { 75bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala for (CaptureCallback target : mRecipients) { 768ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher target.onCaptureSequenceAborted(session, sequenceId); 778ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 788ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 798ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 808ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 818ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, 828ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher long frameNumber) { 83bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala for (CaptureCallback target : mRecipients) { 848ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher target.onCaptureSequenceCompleted(session, sequenceId, frameNumber); 858ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 868ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 878ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher 888ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher @Override 898ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, 90171362f843c1e7623f29db1781176f85b1f74815Eino-Ville Talvala long timestamp, long frameNumber) { 91bb013aa3e197e881756be5ad13e6ad30bfb4aeffEino-Ville Talvala for (CaptureCallback target : mRecipients) { 92171362f843c1e7623f29db1781176f85b1f74815Eino-Ville Talvala target.onCaptureStarted(session, request, timestamp, frameNumber); 938ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 948ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher } 958ba391e3f88936557ad6d44bbef32cb08f4ca310Sol Boucher} 96