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 54 virtual void onFrameAvailable(int32_t requestId, const CameraMetadata &frame); 55 56 /** 57 **************************************** 58 * ZslProcessorInterface implementation * 59 **************************************** 60 */ 61 62 virtual status_t updateStream(const Parameters ¶ms); 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 86 enum { 87 RUNNING, 88 LOCKED 89 } mState; 90 91 wp<Camera2Client> mClient; 92 wp<CaptureSequencer> mSequencer; 93 94 const int mId; 95 96 mutable Mutex mInputMutex; 97 98 enum { 99 NO_STREAM = -1 100 }; 101 102 int mZslStreamId; 103 sp<camera3::Camera3ZslStream> mZslStream; 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 clearZslQueueLocked(); 126 127 void dumpZslQueue(int id) const; 128 129 nsecs_t getCandidateTimestampLocked(size_t* metadataIdx) const; 130 }; 131 132 133 }; //namespace camera2 134 }; //namespace android 135 136 #endif 137