| /* |
| * Copyright (C) 2019, The LineageOS Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #ifndef _THREAD_STD_H |
| #define _THREAD_STD_H |
| |
| #include <thread> |
| #include <queue> |
| #include <mutex> |
| #include <atomic> |
| #include <condition_variable> |
| |
| #include <sys/time.h> |
| |
| #include <hardware/camera.h> |
| #include <hardware/camera2.h> |
| |
| #define CB_TYPE_NONE 0 |
| #define CB_TYPE_NOTIFY 1 |
| #define CB_TYPE_DATA 2 |
| |
| struct WorkerMessage { |
| /* Worker callback type */ |
| int32_t CbType; |
| |
| /* Callback data */ |
| int32_t msg_type; |
| const camera_memory_t *data; |
| unsigned int index; |
| camera_frame_metadata_t *metadata; |
| void *user; |
| int32_t ext1; |
| int32_t ext2; |
| }; |
| |
| struct CallbackData { |
| camera_notify_callback NewUserNotifyCb; |
| camera_data_callback NewUserDataCb; |
| }; |
| |
| struct ThreadMsg; |
| |
| class CallbackWorkerThread { |
| public: |
| CallbackWorkerThread(); |
| ~CallbackWorkerThread(); |
| |
| /* Creates our worker, returns true on success */ |
| bool CreateThread(); |
| |
| /* Exits the worker thread */ |
| void ExitThread(); |
| |
| /* Sends a new callback to our worker thread */ |
| void AddCallback(const WorkerMessage* data); |
| |
| /* Sets the callback function pointers for our worker to call */ |
| void SetCallbacks(const CallbackData* data); |
| |
| /* Clears the worker message queue */ |
| void ClearCallbacks(void); |
| |
| private: |
| CallbackWorkerThread(const CallbackWorkerThread&); |
| CallbackWorkerThread& operator=(const CallbackWorkerThread&); |
| |
| long long GetTimestamp(); |
| |
| /* Entry point for the worker thread */ |
| void Process(); |
| |
| std::thread* m_thread; |
| std::queue<ThreadMsg*> m_queue; |
| std::mutex m_mutex; |
| std::condition_variable m_cv; |
| const char* m_name; |
| }; |
| |
| #endif |
| |