Home | History | Annotate | Download | only in client2
      1 /*
      2  * Copyright (C) 2013 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_ZSLPROCESSOR3_H
     18 #define ANDROID_SERVERS_CAMERA_CAMERA2_ZSLPROCESSOR3_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 "api1/client2/FrameProcessor.h"
     29 #include "api1/client2/ZslProcessorInterface.h"
     30 #include "device3/Camera3ZslStream.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 ZslProcessor3 :
     45                     public ZslProcessorInterface,
     46                     public camera3::Camera3StreamBufferListener,
     47             virtual public Thread,
     48             virtual public FrameProcessor::FilteredListener {
     49   public:
     50     ZslProcessor3(sp<Camera2Client> client, wp<CaptureSequencer> sequencer);
     51     ~ZslProcessor3();
     52 
     53     // From FrameProcessor::FilteredListener
     54     virtual void onResultAvailable(const CaptureResult &result);
     55 
     56     /**
     57      ****************************************
     58      * ZslProcessorInterface implementation *
     59      ****************************************
     60      */
     61 
     62     virtual status_t updateStream(const Parameters &params);
     63     virtual status_t deleteStream();
     64     virtual int getStreamId() const;
     65 
     66     virtual status_t pushToReprocess(int32_t requestId);
     67     virtual status_t clearZslQueue();
     68 
     69     void dump(int fd, const Vector<String16>& args) const;
     70 
     71   protected:
     72     /**
     73      **********************************************
     74      * Camera3StreamBufferListener implementation *
     75      **********************************************
     76      */
     77     typedef camera3::Camera3StreamBufferListener::BufferInfo BufferInfo;
     78     // Buffer was acquired by the HAL
     79     virtual void onBufferAcquired(const BufferInfo& bufferInfo);
     80     // Buffer was released by the HAL
     81     virtual void onBufferReleased(const BufferInfo& bufferInfo);
     82 
     83   private:
     84     static const nsecs_t kWaitDuration = 10000000; // 10 ms
     85     nsecs_t mLatestClearedBufferTimestamp;
     86 
     87     enum {
     88         RUNNING,
     89         LOCKED
     90     } mState;
     91 
     92     wp<Camera2Client> mClient;
     93     wp<CaptureSequencer> mSequencer;
     94 
     95     const int mId;
     96 
     97     mutable Mutex mInputMutex;
     98 
     99     enum {
    100         NO_STREAM = -1
    101     };
    102 
    103     int mZslStreamId;
    104     sp<camera3::Camera3ZslStream> mZslStream;
    105 
    106     struct ZslPair {
    107         BufferItemConsumer::BufferItem buffer;
    108         CameraMetadata frame;
    109     };
    110 
    111     static const int32_t kDefaultMaxPipelineDepth = 4;
    112     size_t mBufferQueueDepth;
    113     size_t mFrameListDepth;
    114     Vector<CameraMetadata> mFrameList;
    115     size_t mFrameListHead;
    116 
    117     ZslPair mNextPair;
    118 
    119     Vector<ZslPair> mZslQueue;
    120     size_t mZslQueueHead;
    121     size_t mZslQueueTail;
    122 
    123     CameraMetadata mLatestCapturedRequest;
    124 
    125     bool mHasFocuser;
    126 
    127     virtual bool threadLoop();
    128 
    129     status_t clearZslQueueLocked();
    130 
    131     void clearZslResultQueueLocked();
    132 
    133     void dumpZslQueue(int id) const;
    134 
    135     nsecs_t getCandidateTimestampLocked(size_t* metadataIdx) const;
    136 
    137     bool isFixedFocusMode(uint8_t afMode) const;
    138 
    139     // Update the post-processing metadata with the default still capture request template
    140     status_t updateRequestWithDefaultStillRequest(CameraMetadata &request) const;
    141 };
    142 
    143 
    144 }; //namespace camera2
    145 }; //namespace android
    146 
    147 #endif
    148