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