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