1 /*
2  * Copyright (C) 2012 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 
17 #ifndef ANDROID_SERVERS_CAMERA_CAMERA2_FRAMEPROCESSOR_H
18 #define ANDROID_SERVERS_CAMERA_CAMERA2_FRAMEPROCESSOR_H
19 
20 #include <utils/Thread.h>
21 #include <utils/String16.h>
22 #include <utils/Vector.h>
23 #include <utils/KeyedVector.h>
24 #include <utils/List.h>
25 #include <camera/CameraMetadata.h>
26 
27 #include "common/CameraDeviceBase.h"
28 #include "common/FrameProcessorBase.h"
29 
30 struct camera_frame_metadata;
31 
32 namespace android {
33 
34 class Camera2Client;
35 
36 namespace camera2 {
37 
38 /* Output frame metadata processing thread.  This thread waits for new
39  * frames from the device, and analyzes them as necessary.
40  */
41 class FrameProcessor : public FrameProcessorBase {
42   public:
43     FrameProcessor(wp<CameraDeviceBase> device, sp<Camera2Client> client);
44     ~FrameProcessor();
45 
46   private:
47     static const int32_t NOT_SET = -1;
48 
49     wp<Camera2Client> mClient;
50 
51     bool mSynthesize3ANotify;
52 
53     int mLastFrameNumberOfFaces;
54 
55     void processNewFrames(const sp<Camera2Client> &client);
56 
57     virtual bool processSingleFrame(CaptureResult &frame,
58                                     const sp<FrameProducer> &device);
59 
60     status_t processFaceDetect(const CameraMetadata &frame,
61             const sp<Camera2Client> &client);
62 
63     // Send 3A state change notifications to client based on frame metadata
64     status_t process3aState(const CaptureResult &frame,
65             const sp<Camera2Client> &client);
66 
67     // Helper for process3aState
68     template<typename Src, typename T>
69     bool updatePendingState(const CameraMetadata& result, int32_t tag, T* value,
70             int32_t frameNumber, int cameraId);
71 
72 
73     struct AlgState {
74         // TODO: also track AE mode
75         camera_metadata_enum_android_control_af_mode   afMode;
76         camera_metadata_enum_android_control_awb_mode  awbMode;
77 
78         camera_metadata_enum_android_control_ae_state  aeState;
79         camera_metadata_enum_android_control_af_state  afState;
80         camera_metadata_enum_android_control_awb_state awbState;
81 
82         int32_t                                        afTriggerId;
83         int32_t                                        aeTriggerId;
84 
85         // These defaults need to match those in Parameters.cpp
AlgStateAlgState86         AlgState() :
87                 afMode((camera_metadata_enum_android_control_af_mode)NOT_SET),
88                 awbMode((camera_metadata_enum_android_control_awb_mode)NOT_SET),
89                 aeState((camera_metadata_enum_android_control_ae_state)NOT_SET),
90                 afState((camera_metadata_enum_android_control_af_state)NOT_SET),
91                 awbState((camera_metadata_enum_android_control_awb_state)NOT_SET),
92                 afTriggerId(NOT_SET),
93                 aeTriggerId(NOT_SET) {
94         }
95     };
96 
97     AlgState m3aState;
98     int32_t mCurrentRequestId = -1;
99 
100     // frame number -> pending 3A states that not all data are received yet.
101     KeyedVector<int32_t, AlgState> mPending3AStates;
102 
103     // Whether the partial result is enabled for this device
104     bool mUsePartialResult;
105 
106     // Track most recent frame number for which 3A notifications were sent for.
107     // Used to filter against sending 3A notifications for the same frame
108     // several times.
109     int32_t mLast3AFrameNumber, mLastAEFrameNumber, mLastAFrameNumber, mLastAWBFrameNumber;
110     // Emit FaceDetection event to java if faces changed
111     void callbackFaceDetection(const sp<Camera2Client>& client,
112                                const camera_frame_metadata &metadata);
113 };
114 
115 
116 }; //namespace camera2
117 }; //namespace android
118 
119 #endif
120