• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void processLensState(const CameraMetadata &frame,
61             const sp<Camera2Client> &client);
62 
63     status_t processFaceDetect(const CameraMetadata &frame,
64             const sp<Camera2Client> &client);
65 
66     // Send 3A state change notifications to client based on frame metadata
67     status_t process3aState(const CaptureResult &frame,
68             const sp<Camera2Client> &client);
69 
70     // Helper for process3aState
71     template<typename Src, typename T>
72     bool updatePendingState(const CameraMetadata& result, int32_t tag, T* value,
73             int32_t frameNumber, int cameraId);
74 
75 
76     struct AlgState {
77         // TODO: also track AE mode
78         camera_metadata_enum_android_control_af_mode   afMode;
79         camera_metadata_enum_android_control_awb_mode  awbMode;
80 
81         camera_metadata_enum_android_control_ae_state  aeState;
82         camera_metadata_enum_android_control_af_state  afState;
83         camera_metadata_enum_android_control_awb_state awbState;
84 
85         int32_t                                        afTriggerId;
86         int32_t                                        aeTriggerId;
87 
88         // These defaults need to match those in Parameters.cpp
AlgStateAlgState89         AlgState() :
90                 afMode((camera_metadata_enum_android_control_af_mode)NOT_SET),
91                 awbMode((camera_metadata_enum_android_control_awb_mode)NOT_SET),
92                 aeState((camera_metadata_enum_android_control_ae_state)NOT_SET),
93                 afState((camera_metadata_enum_android_control_af_state)NOT_SET),
94                 awbState((camera_metadata_enum_android_control_awb_state)NOT_SET),
95                 afTriggerId(NOT_SET),
96                 aeTriggerId(NOT_SET) {
97         }
98     };
99 
100     AlgState m3aState;
101     int32_t mCurrentRequestId = -1;
102 
103     // frame number -> pending 3A states that not all data are received yet.
104     KeyedVector<int32_t, AlgState> mPending3AStates;
105 
106     // Whether the partial result is enabled for this device
107     bool mUsePartialResult;
108 
109     // Track most recent frame number for which 3A notifications were sent for.
110     // Used to filter against sending 3A notifications for the same frame
111     // several times.
112     int32_t mLast3AFrameNumber, mLastAEFrameNumber, mLastAFrameNumber, mLastAWBFrameNumber;
113     // Emit FaceDetection event to java if faces changed
114     void callbackFaceDetection(const sp<Camera2Client>& client,
115                                const camera_frame_metadata &metadata);
116 
117     // Track most recent focal length sent by the camera device
118     float mLastFocalLength;
119 };
120 
121 
122 }; //namespace camera2
123 }; //namespace android
124 
125 #endif
126