ZslProcessor.h revision 97b38a81ac989ccba02d726011a82541f14166df
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_ZSLPROCESSOR_H
18#define ANDROID_SERVERS_CAMERA_CAMERA2_ZSLPROCESSOR_H
19
20#include <utils/Thread.h>
21#include <utils/String16.h>
22#include <utils/Vector.h>
23#include <utils/Mutex.h>
24#include <utils/Condition.h>
25#include <gui/BufferItemConsumer.h>
26#include "Parameters.h"
27#include "FrameProcessor.h"
28#include "CameraMetadata.h"
29#include "Camera2Heap.h"
30#include "../Camera2Device.h"
31
32namespace android {
33
34class Camera2Client;
35
36namespace camera2 {
37
38class CaptureSequencer;
39
40/***
41 * ZSL queue processing
42 */
43class ZslProcessor:
44            virtual public Thread,
45            virtual public BufferItemConsumer::FrameAvailableListener,
46            virtual public FrameProcessor::FilteredListener,
47            virtual public Camera2Device::BufferReleasedListener {
48  public:
49    ZslProcessor(wp<Camera2Client> client, wp<CaptureSequencer> sequencer);
50    ~ZslProcessor();
51
52    // From mZslConsumer
53    virtual void onFrameAvailable();
54    // From FrameProcessor
55    virtual void onFrameAvailable(int32_t frameId, CameraMetadata &frame);
56
57    virtual void onBufferReleased(buffer_handle_t *handle);
58
59    status_t updateStream(const Parameters &params);
60    status_t deleteStream();
61    int getStreamId() const;
62    int getReprocessStreamId() const;
63
64    status_t pushToReprocess(int32_t requestId);
65
66    void dump(int fd, const Vector<String16>& args) const;
67  private:
68    static const nsecs_t kWaitDuration = 10000000; // 10 ms
69
70    enum {
71        RUNNING,
72        LOCKED
73    } mState;
74
75    wp<Camera2Client> mClient;
76    wp<CaptureSequencer> mSequencer;
77
78    mutable Mutex mInputMutex;
79    bool mZslBufferAvailable;
80    Condition mZslBufferAvailableSignal;
81
82    enum {
83        NO_STREAM = -1
84    };
85
86    int mZslStreamId;
87    int mZslReprocessStreamId;
88    sp<BufferItemConsumer> mZslConsumer;
89    sp<ANativeWindow>      mZslWindow;
90
91    struct ZslPair {
92        BufferItemConsumer::BufferItem buffer;
93        CameraMetadata frame;
94    };
95
96    static const size_t kZslBufferDepth = 4;
97    static const size_t kFrameListDepth = kZslBufferDepth * 2;
98    Vector<CameraMetadata> mFrameList;
99    size_t mFrameListHead;
100
101    ZslPair mNextPair;
102
103    Vector<ZslPair> mZslQueue;
104    size_t mZslQueueHead;
105    size_t mZslQueueTail;
106
107    virtual bool threadLoop();
108
109    status_t processNewZslBuffer(sp<Camera2Client> &client);
110
111    // Match up entries from frame list to buffers in ZSL queue
112    void findMatchesLocked();
113
114    void dumpZslQueue(int id) const;
115};
116
117
118}; //namespace camera2
119}; //namespace android
120
121#endif
122