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