universal7580: setup-makefiles: disable ELF check for mali
[GitHub/LineageOS/android_device_samsung_universal7580-common.git] / camera / CallbackWorkerThread.h
1 /*
2 * Copyright (C) 2019, The LineageOS 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 _THREAD_STD_H
18 #define _THREAD_STD_H
19
20 #include <thread>
21 #include <queue>
22 #include <mutex>
23 #include <atomic>
24 #include <condition_variable>
25
26 #include <sys/time.h>
27
28 #include <hardware/camera.h>
29 #include <hardware/camera2.h>
30
31 #define CB_TYPE_NONE 0
32 #define CB_TYPE_NOTIFY 1
33 #define CB_TYPE_DATA 2
34
35 struct WorkerMessage {
36 /* Worker callback type */
37 int32_t CbType;
38
39 /* Callback data */
40 int32_t msg_type;
41 const camera_memory_t *data;
42 unsigned int index;
43 camera_frame_metadata_t *metadata;
44 void *user;
45 int32_t ext1;
46 int32_t ext2;
47 };
48
49 struct CallbackData {
50 camera_notify_callback NewUserNotifyCb;
51 camera_data_callback NewUserDataCb;
52 };
53
54 struct ThreadMsg;
55
56 class CallbackWorkerThread {
57 public:
58 CallbackWorkerThread();
59 ~CallbackWorkerThread();
60
61 /* Creates our worker, returns true on success */
62 bool CreateThread();
63
64 /* Exits the worker thread */
65 void ExitThread();
66
67 /* Sends a new callback to our worker thread */
68 void AddCallback(const WorkerMessage* data);
69
70 /* Sets the callback function pointers for our worker to call */
71 void SetCallbacks(const CallbackData* data);
72
73 /* Clears the worker message queue */
74 void ClearCallbacks(void);
75
76 private:
77 CallbackWorkerThread(const CallbackWorkerThread&);
78 CallbackWorkerThread& operator=(const CallbackWorkerThread&);
79
80 long long GetTimestamp();
81
82 /* Entry point for the worker thread */
83 void Process();
84
85 std::thread* m_thread;
86 std::queue<ThreadMsg*> m_queue;
87 std::mutex m_mutex;
88 std::condition_variable m_cv;
89 const char* m_name;
90 };
91
92 #endif
93