1 /* 2 * Copyright (C) 2016 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 */ 16 package com.android.devcamera; 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.util.Log; 25 26 /** 27 * Static utility class that logs various camera2 callbacks. 28 * 29 * The only reason this exists as a separate class is void cluttering up Api2Camera. 30 */ 31 32 public class LoggingCallbacks { 33 private static final String TAG = "DevCamera_LOG2"; 34 private static final Boolean LOG_EVERY_FRAME = false; 35 private static final Boolean LOG_NON_ERRORS = false; 36 37 public static class DeviceStateCallback extends CameraDevice.StateCallback { 38 @Override onOpened(CameraDevice camera)39 public void onOpened(CameraDevice camera) { 40 if (LOG_NON_ERRORS) { 41 Log.v(TAG, "Camera opened."); 42 } 43 } 44 45 @Override onClosed(CameraDevice camera)46 public void onClosed(CameraDevice camera) { 47 if (LOG_NON_ERRORS) { 48 Log.v(TAG, "Camera closed."); 49 } 50 } 51 52 @Override onDisconnected(CameraDevice camera)53 public void onDisconnected(CameraDevice camera) { 54 Log.v(TAG, "Camera disconnected."); 55 } 56 57 @Override onError(CameraDevice camera, int error)58 public void onError(CameraDevice camera, int error) { 59 Log.v(TAG, "Camera error: " + error); 60 } 61 } 62 63 public static class SessionStateCallback extends CameraCaptureSession.StateCallback { 64 @Override onConfigured(CameraCaptureSession session)65 public void onConfigured(CameraCaptureSession session) { 66 if (LOG_NON_ERRORS) { 67 Log.v(TAG, "Capture session callback onConfigured("+session+")"); 68 } 69 } 70 71 @Override onConfigureFailed(CameraCaptureSession session)72 public void onConfigureFailed(CameraCaptureSession session) { 73 Log.v(TAG, "Capture session callback onConfigureFailed("+session+")"); 74 super.onReady(session); 75 } 76 77 @Override onReady(CameraCaptureSession session)78 public void onReady(CameraCaptureSession session) { 79 if (LOG_NON_ERRORS) { 80 Log.v(TAG, "Capture session callback onReady("+session+")"); 81 } 82 super.onReady(session); 83 } 84 85 @Override onActive(CameraCaptureSession session)86 public void onActive(CameraCaptureSession session) { 87 if (LOG_NON_ERRORS) { 88 Log.v(TAG, "Capture session callback onActive("+session+")"); 89 } 90 super.onActive(session); 91 } 92 93 @Override onClosed(CameraCaptureSession session)94 public void onClosed(CameraCaptureSession session) { 95 if (LOG_NON_ERRORS) { 96 Log.v(TAG, "Capture session callback onClosed("+session+")"); 97 } 98 super.onClosed(session); 99 } 100 } 101 102 public static class SessionCaptureCallback extends CameraCaptureSession.CaptureCallback { 103 @Override onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber)104 public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber) { 105 if (LOG_EVERY_FRAME) { 106 Log.v(TAG, "Capture started."); 107 } 108 super.onCaptureStarted(session, request, timestamp, frameNumber); 109 } 110 111 @Override onCaptureProgressed(CameraCaptureSession session, CaptureRequest request, CaptureResult partialResult)112 public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request, CaptureResult partialResult) { 113 if (LOG_EVERY_FRAME) { 114 Log.v(TAG, "Capture progressed."); 115 } 116 super.onCaptureProgressed(session, request, partialResult); 117 } 118 119 @Override onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)120 public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { 121 if (LOG_EVERY_FRAME) { 122 Log.v(TAG, "Capture completed."); 123 } 124 super.onCaptureCompleted(session, request, result); 125 } 126 127 @Override onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure)128 public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure) { 129 super.onCaptureFailed(session, request, failure); 130 } 131 132 @Override onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, long frameNumber)133 public void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, long frameNumber) { 134 super.onCaptureSequenceCompleted(session, sequenceId, frameNumber); 135 } 136 137 } 138 } 139