• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 namespace android {
29 
30 class FrameProducer;
31 
32 namespace camera2 {
33 
34 /* Output frame metadata processing thread.  This thread waits for new
35  * frames from the frame producer, and analyzes them as necessary.
36  */
37 class FrameProcessorBase: public Thread {
38   public:
39     explicit FrameProcessorBase(wp<FrameProducer> device);
40     virtual ~FrameProcessorBase();
41 
42     struct FilteredListener: virtual public RefBase {
43         virtual void onResultAvailable(const CaptureResult &result) = 0;
44     };
45 
46     static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0;
47     static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
48 
49     // Register a listener for a range of IDs [minId, maxId). Multiple listeners
50     // can be listening to the same range. Registering the same listener with
51     // the same range of IDs has no effect.
52     // sendPartials controls whether partial results will be sent.
53     status_t registerListener(int32_t minId, int32_t maxId,
54                               const wp<FilteredListener>& listener,
55                               bool sendPartials = true);
56     status_t removeListener(int32_t minId, int32_t maxId,
57                             const wp<FilteredListener>& listener);
58 
59     void dump(int fd, const Vector<String16>& args);
60   protected:
61     static const nsecs_t kWaitDuration = 10000000; // 10 ms
62     wp<FrameProducer> mDevice;
63 
64     virtual bool threadLoop();
65 
66     Mutex mInputMutex;
67     Mutex mLastFrameMutex;
68 
69     struct RangeListener {
70         int32_t minId;
71         int32_t maxId;
72         wp<FilteredListener> listener;
73         bool sendPartials;
74     };
75     List<RangeListener> mRangeListeners;
76 
77     // Number of partial result the HAL will potentially send.
78     int32_t mNumPartialResults;
79 
80     void processNewFrames(const sp<FrameProducer> &device);
81 
82     virtual bool processSingleFrame(CaptureResult &result,
83                                     const sp<FrameProducer> &device);
84 
85     status_t processListeners(const CaptureResult &result,
86                               const sp<FrameProducer> &device);
87 
88     CameraMetadata mLastFrame;
89     std::vector<PhysicalCaptureResultInfo> mLastPhysicalFrames;
90 
91 };
92 
93 
94 }; //namespace camera2
95 }; //namespace android
96 
97 #endif
98