Home | History | Annotate | Download | only in client2
      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 <camera/CameraMetadata.h>
     27 #include <camera/CaptureResult.h>
     28 
     29 #include "common/CameraDeviceBase.h"
     30 #include "api1/client2/ZslProcessorInterface.h"
     31 #include "api1/client2/FrameProcessor.h"
     32 
     33 namespace android {
     34 
     35 class Camera2Client;
     36 
     37 namespace camera2 {
     38 
     39 class CaptureSequencer;
     40 class Parameters;
     41 
     42 /***
     43  * ZSL queue processing
     44  */
     45 class ZslProcessor:
     46             virtual public Thread,
     47             virtual public BufferItemConsumer::FrameAvailableListener,
     48             virtual public FrameProcessor::FilteredListener,
     49             virtual public CameraDeviceBase::BufferReleasedListener,
     50                     public ZslProcessorInterface {
     51   public:
     52     ZslProcessor(sp<Camera2Client> client, wp<CaptureSequencer> sequencer);
     53     ~ZslProcessor();
     54 
     55     // From mZslConsumer
     56     virtual void onFrameAvailable(const BufferItem& item);
     57     // From FrameProcessor
     58     virtual void onResultAvailable(const CaptureResult &result);
     59 
     60     virtual void onBufferReleased(buffer_handle_t *handle);
     61 
     62     /**
     63      ****************************************
     64      * ZslProcessorInterface implementation *
     65      ****************************************
     66      */
     67 
     68     status_t updateStream(const Parameters &params);
     69     status_t deleteStream();
     70     status_t disconnect();
     71     int getStreamId() const;
     72 
     73     status_t pushToReprocess(int32_t requestId);
     74     status_t clearZslQueue();
     75 
     76     void dump(int fd, const Vector<String16>& args) const;
     77   private:
     78     static const nsecs_t kWaitDuration = 10000000; // 10 ms
     79 
     80     enum {
     81         RUNNING,
     82         LOCKED
     83     } mState;
     84 
     85     wp<Camera2Client> mClient;
     86     wp<CameraDeviceBase> mDevice;
     87     wp<CaptureSequencer> mSequencer;
     88     int mId;
     89 
     90     bool mDeleted;
     91 
     92     mutable Mutex mInputMutex;
     93     bool mZslBufferAvailable;
     94     Condition mZslBufferAvailableSignal;
     95 
     96     enum {
     97         NO_STREAM = -1
     98     };
     99 
    100     int mZslStreamId;
    101     int mZslReprocessStreamId;
    102     sp<BufferItemConsumer> mZslConsumer;
    103     sp<ANativeWindow>      mZslWindow;
    104 
    105     struct ZslPair {
    106         BufferItemConsumer::BufferItem buffer;
    107         CameraMetadata frame;
    108     };
    109 
    110     static const size_t kZslBufferDepth = 4;
    111     static const size_t kFrameListDepth = kZslBufferDepth * 2;
    112     Vector<CameraMetadata> mFrameList;
    113     size_t mFrameListHead;
    114 
    115     ZslPair mNextPair;
    116 
    117     Vector<ZslPair> mZslQueue;
    118     size_t mZslQueueHead;
    119     size_t mZslQueueTail;
    120 
    121     CameraMetadata mLatestCapturedRequest;
    122 
    123     virtual bool threadLoop();
    124 
    125     status_t processNewZslBuffer();
    126 
    127     // Match up entries from frame list to buffers in ZSL queue
    128     void findMatchesLocked();
    129 
    130     status_t clearZslQueueLocked();
    131 
    132     void dumpZslQueue(int id) const;
    133 };
    134 
    135 
    136 }; //namespace camera2
    137 }; //namespace android
    138 
    139 #endif
    140