1 /* 2 * Copyright (c) 2021-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 HISTREAMER_FOUNDATION_OSAL_TASK_H 17 #define HISTREAMER_FOUNDATION_OSAL_TASK_H 18 19 #include <functional> 20 #include <string> 21 22 namespace OHOS { 23 namespace Media { 24 25 enum class TaskPriority : int { 26 LOW, 27 NORMAL, 28 MIDDLE, 29 HIGH, 30 HIGHEST, 31 }; 32 33 enum class TaskType : int { 34 GLOBAL, 35 VIDEO, 36 AUDIO, 37 DEMUXER, 38 DECODER, 39 SUBTITLE, 40 SINGLETON, 41 }; 42 43 class TaskInner; 44 45 class Task { 46 public: 47 explicit Task(const std::string& name, const std::string& groupId = "", TaskType type = TaskType::SINGLETON, 48 TaskPriority priority = TaskPriority::NORMAL, bool singleLoop = true); 49 50 virtual ~Task(); 51 52 virtual void Start(); 53 54 virtual void Stop(); 55 56 virtual void StopAsync(); 57 58 virtual void Pause(); 59 60 virtual void PauseAsync(); 61 62 virtual void RegisterJob(const std::function<int64_t()>& job); 63 64 virtual void SubmitJobOnce(const std::function<void()>& job, int64_t delayUs = 0, bool wait = false); 65 66 virtual void SubmitJob(const std::function<void()>& job, int64_t delayUs = 0, bool wait = false); 67 68 virtual bool IsTaskRunning(); 69 70 virtual void UpdateDelayTime(int64_t delayUs = 0); 71 72 static void SleepInTask(unsigned ms); 73 74 void SetEnableStateChangeLog(bool enable); 75 76 void UpdateThreadPriority(const uint32_t newPriority, const std::string &strBundleName); 77 78 private: 79 std::shared_ptr<TaskInner> taskInner_; 80 }; 81 } // namespace Media 82 } // namespace OHOS 83 #endif // HISTREAMER_FOUNDATION_OSAL_TASK_H 84 85