1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_THREAD_MANAGER_H 17 #define FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_THREAD_MANAGER_H 18 19 #include <queue> 20 #include <thread> 21 #include <mutex> 22 #include <condition_variable> 23 #include <string> 24 25 namespace OHOS { 26 namespace Media { 27 struct CloudEnhancementThreadTask { 28 std::string taskId; 29 int32_t statusCode; 30 uint8_t *addr; 31 uint32_t bytes; 32 bool isSuccessed; CloudEnhancementThreadTaskCloudEnhancementThreadTask33 CloudEnhancementThreadTask(const std::string& taskId, int32_t statusCode, uint8_t *addr, 34 uint32_t bytes, bool isSuccessed) 35 : taskId(taskId), statusCode(statusCode), addr(addr), bytes(bytes), 36 isSuccessed(isSuccessed) {} 37 }; 38 39 class EnhancementThreadManager { 40 public: 41 EnhancementThreadManager(); 42 ~EnhancementThreadManager(); 43 void StartConsumerThread(); 44 void OnProducerCallback(CloudEnhancementThreadTask& task); 45 46 private: 47 std::atomic<bool> stop; 48 std::atomic<bool> isThreadAlive; 49 std::mutex queueMutex_; 50 std::condition_variable condVar_; 51 std::queue<CloudEnhancementThreadTask> taskQueue_; 52 53 void DealWithTasks(); 54 void ExecSuccessedTask(CloudEnhancementThreadTask& task); 55 void ExecFailedTask(CloudEnhancementThreadTask& task); 56 void ExecExtraWork(); 57 }; 58 } // namespace Media 59 } // namespace OHOS 60 #endif // FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_THREAD_MANAGER_H