• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CALLBACKPROCESSOR_H
18 #define ANDROID_SERVERS_CAMERA_CAMERA2_CALLBACKPROCESSOR_H
19 
20 #include <atomic>
21 
22 #include <utils/Thread.h>
23 #include <utils/String16.h>
24 #include <utils/Vector.h>
25 #include <utils/Mutex.h>
26 #include <utils/Condition.h>
27 #include <gui/CpuConsumer.h>
28 
29 #include "api1/client2/Camera2Heap.h"
30 
31 namespace android {
32 
33 class Camera2Client;
34 class CameraDeviceBase;
35 
36 namespace camera2 {
37 
38 struct Parameters;
39 
40 /***
41  * Still image capture output image processing
42  */
43 class CallbackProcessor:
44             public Thread, public CpuConsumer::FrameAvailableListener {
45   public:
46     explicit CallbackProcessor(sp<Camera2Client> client);
47     ~CallbackProcessor();
48 
49     void onFrameAvailable(const BufferItem& item);
50 
51     // Set to NULL to disable the direct-to-app callback window
52     status_t setCallbackWindow(const sp<Surface>& callbackWindow);
53     status_t updateStream(const Parameters &params);
54     status_t deleteStream();
55     int getStreamId() const;
56 
57     void unpauseCallback();
58     void pauseCallback();
59 
60     void dump(int fd, const Vector<String16>& args) const;
61   private:
62     static const nsecs_t kWaitDuration = 10000000; // 10 ms
63     wp<Camera2Client> mClient;
64     wp<CameraDeviceBase> mDevice;
65     int mId;
66 
67     mutable Mutex mInputMutex;
68     bool mCallbackAvailable;
69     Condition mCallbackAvailableSignal;
70 
71     enum {
72         NO_STREAM = -1
73     };
74 
75     std::atomic<bool> mCallbackPaused;
76 
77     // True if mCallbackWindow is a remote consumer, false if just the local
78     // mCallbackConsumer
79     bool mCallbackToApp;
80     int mCallbackStreamId;
81     static const size_t kCallbackHeapCount = 6;
82     sp<CpuConsumer>    mCallbackConsumer;
83     sp<Surface>        mCallbackWindow;
84     sp<Camera2Heap>    mCallbackHeap;
85     size_t mCallbackHeapHead, mCallbackHeapFree;
86 
87     virtual bool threadLoop();
88 
89     status_t processNewCallback(sp<Camera2Client> &client);
90     // Used when shutting down
91     status_t discardNewCallback();
92 
93     // Convert from flexible YUV to NV21 or YV12
94     status_t convertFromFlexibleYuv(int32_t previewFormat,
95             uint8_t *dst,
96             const CpuConsumer::LockedBuffer &src,
97             uint32_t dstYStride,
98             uint32_t dstCStride) const;
99 };
100 
101 
102 }; //namespace camera2
103 }; //namespace android
104 
105 #endif
106