FrameProcessorBase.h revision 215bb3499c7eeea6303e55fac66452f2574c022a
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 27namespace android { 28 29class CameraDeviceBase; 30 31namespace camera2 { 32 33/* Output frame metadata processing thread. This thread waits for new 34 * frames from the device, and analyzes them as necessary. 35 */ 36class FrameProcessorBase: public Thread { 37 public: 38 FrameProcessorBase(wp<CameraDeviceBase> device); 39 virtual ~FrameProcessorBase(); 40 41 struct FilteredListener: virtual public RefBase { 42 virtual void onFrameAvailable(int32_t requestId, 43 const CameraMetadata &frame) = 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 status_t registerListener(int32_t minId, int32_t maxId, 49 wp<FilteredListener> listener); 50 status_t removeListener(int32_t minId, int32_t maxId, 51 wp<FilteredListener> listener); 52 53 void dump(int fd, const Vector<String16>& args); 54 protected: 55 static const nsecs_t kWaitDuration = 10000000; // 10 ms 56 wp<CameraDeviceBase> mDevice; 57 58 virtual bool threadLoop(); 59 60 Mutex mInputMutex; 61 Mutex mLastFrameMutex; 62 63 struct RangeListener { 64 int32_t minId; 65 int32_t maxId; 66 wp<FilteredListener> listener; 67 }; 68 List<RangeListener> mRangeListeners; 69 70 void processNewFrames(const sp<CameraDeviceBase> &device); 71 72 virtual bool processSingleFrame(CameraMetadata &frame, 73 const sp<CameraDeviceBase> &device); 74 75 status_t processListeners(const CameraMetadata &frame, 76 const sp<CameraDeviceBase> &device); 77 78 CameraMetadata mLastFrame; 79}; 80 81 82}; //namespace camera2 83}; //namespace android 84 85#endif 86