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 "CameraMetadata.h"
26
27struct camera_frame_metadata;
28
29namespace android {
30
31class Camera2Client;
32
33namespace camera2 {
34
35/* Output frame metadata processing thread.  This thread waits for new
36 * frames from the device, and analyzes them as necessary.
37 */
38class FrameProcessor: public Thread {
39  public:
40    FrameProcessor(wp<Camera2Client> client);
41    ~FrameProcessor();
42
43    struct FilteredListener: virtual public RefBase {
44        virtual void onFrameAvailable(int32_t frameId,
45                const CameraMetadata &frame) = 0;
46    };
47
48    // Register a listener for a range of IDs [minId, maxId). Multiple listeners
49    // can be listening to the same range
50    status_t registerListener(int32_t minId, int32_t maxId, wp<FilteredListener> listener);
51    status_t removeListener(int32_t minId, int32_t maxId, wp<FilteredListener> listener);
52
53    void dump(int fd, const Vector<String16>& args);
54  private:
55    static const nsecs_t kWaitDuration = 10000000; // 10 ms
56    wp<Camera2Client> mClient;
57
58    virtual bool threadLoop();
59
60    Mutex mInputMutex;
61
62    struct RangeListener {
63        int32_t minId;
64        int32_t maxId;
65        wp<FilteredListener> listener;
66    };
67    List<RangeListener> mRangeListeners;
68
69    void processNewFrames(sp<Camera2Client> &client);
70
71    status_t processFaceDetect(const CameraMetadata &frame,
72            sp<Camera2Client> &client);
73
74    status_t processListeners(const CameraMetadata &frame,
75            sp<Camera2Client> &client);
76
77    CameraMetadata mLastFrame;
78    int mLastFrameNumberOfFaces;
79
80    // Emit FaceDetection event to java if faces changed
81    void callbackFaceDetection(sp<Camera2Client> client,
82                               camera_frame_metadata &metadata);
83};
84
85
86}; //namespace camera2
87}; //namespace android
88
89#endif
90