ZslProcessor.h revision cb0652e5a850b2fcd919e977247e87239efaf70e
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 33namespace android { 34 35class Camera2Client; 36 37namespace camera2 { 38 39class CaptureSequencer; 40class Parameters; 41 42/*** 43 * ZSL queue processing 44 */ 45class 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(); 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 ¶ms); 69 status_t deleteStream(); 70 int getStreamId() const; 71 72 status_t pushToReprocess(int32_t requestId); 73 status_t clearZslQueue(); 74 75 void dump(int fd, const Vector<String16>& args) const; 76 private: 77 static const nsecs_t kWaitDuration = 10000000; // 10 ms 78 79 enum { 80 RUNNING, 81 LOCKED 82 } mState; 83 84 wp<Camera2Client> mClient; 85 wp<CameraDeviceBase> mDevice; 86 wp<CaptureSequencer> mSequencer; 87 int mId; 88 89 mutable Mutex mInputMutex; 90 bool mZslBufferAvailable; 91 Condition mZslBufferAvailableSignal; 92 93 enum { 94 NO_STREAM = -1 95 }; 96 97 int mZslStreamId; 98 int mZslReprocessStreamId; 99 sp<BufferItemConsumer> mZslConsumer; 100 sp<ANativeWindow> mZslWindow; 101 102 struct ZslPair { 103 BufferItemConsumer::BufferItem buffer; 104 CameraMetadata frame; 105 }; 106 107 static const size_t kZslBufferDepth = 4; 108 static const size_t kFrameListDepth = kZslBufferDepth * 2; 109 Vector<CameraMetadata> mFrameList; 110 size_t mFrameListHead; 111 112 ZslPair mNextPair; 113 114 Vector<ZslPair> mZslQueue; 115 size_t mZslQueueHead; 116 size_t mZslQueueTail; 117 118 CameraMetadata mLatestCapturedRequest; 119 120 virtual bool threadLoop(); 121 122 status_t processNewZslBuffer(); 123 124 // Match up entries from frame list to buffers in ZSL queue 125 void findMatchesLocked(); 126 127 status_t clearZslQueueLocked(); 128 129 void dumpZslQueue(int id) const; 130}; 131 132 133}; //namespace camera2 134}; //namespace android 135 136#endif 137