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