FrameProcessorBase.h revision cb0652e5a850b2fcd919e977247e87239efaf70e
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_PROFRAMEPROCESSOR_H 18#define ANDROID_SERVERS_CAMERA_CAMERA2_PROFRAMEPROCESSOR_H 19 20#include <utils/Thread.h> 21#include <utils/String16.h> 22#include <utils/Vector.h> 23#include <utils/KeyedVector.h> 24#include <utils/List.h> 25#include <camera/CameraMetadata.h> 26#include <camera/CaptureResult.h> 27 28namespace android { 29 30class CameraDeviceBase; 31 32namespace camera2 { 33 34/* Output frame metadata processing thread. This thread waits for new 35 * frames from the device, and analyzes them as necessary. 36 */ 37class FrameProcessorBase: public Thread { 38 public: 39 FrameProcessorBase(wp<CameraDeviceBase> device); 40 virtual ~FrameProcessorBase(); 41 42 struct FilteredListener: virtual public RefBase { 43 virtual void onResultAvailable(const CaptureResult &result) = 0; 44 }; 45 46 // Register a listener for a range of IDs [minId, maxId). Multiple listeners 47 // can be listening to the same range. 48 // QUIRK: sendPartials controls whether partial results will be sent. 49 status_t registerListener(int32_t minId, int32_t maxId, 50 wp<FilteredListener> listener, 51 bool quirkSendPartials = true); 52 status_t removeListener(int32_t minId, int32_t maxId, 53 wp<FilteredListener> listener); 54 55 void dump(int fd, const Vector<String16>& args); 56 protected: 57 static const nsecs_t kWaitDuration = 10000000; // 10 ms 58 wp<CameraDeviceBase> mDevice; 59 60 virtual bool threadLoop(); 61 62 Mutex mInputMutex; 63 Mutex mLastFrameMutex; 64 65 struct RangeListener { 66 int32_t minId; 67 int32_t maxId; 68 wp<FilteredListener> listener; 69 bool quirkSendPartials; 70 }; 71 List<RangeListener> mRangeListeners; 72 73 void processNewFrames(const sp<CameraDeviceBase> &device); 74 75 virtual bool processSingleFrame(CaptureResult &result, 76 const sp<CameraDeviceBase> &device); 77 78 status_t processListeners(const CaptureResult &result, 79 const sp<CameraDeviceBase> &device); 80 81 CameraMetadata mLastFrame; 82}; 83 84 85}; //namespace camera2 86}; //namespace android 87 88#endif 89