• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2021 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_HIRECORDER_STATE_H
17 #define HISTREAMER_HIRECORDER_STATE_H
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <tuple>
23 #include "foundation/log.h"
24 #include "pipeline/core/error_code.h"
25 #include "plugin/common/any.h"
26 #include "recorder_executor.h"
27 
28 namespace OHOS {
29 namespace Media {
30 namespace Record {
31 enum class StateId {
32     INIT,
33     RECORDING_SETTING,
34     READY,
35     PAUSE,
36     RECORDING,
37     ERROR,
38     BUTT,
39 };
40 
41 enum class Intent {
42     SET_OBS,
43     SET_VIDEO_SOURCE,
44     SET_AUDIO_SOURCE,
45     SET_OUTPUT_FORMAT,
46     CONFIGURE,
47     PREPARE,
48     START,
49     PAUSE,
50     RESUME,
51     STOP,
52     RESET,
53     NOTIFY_READY,
54     NOTIFY_COMPLETE,
55     NOTIFY_ERROR,
56     INTENT_BUTT
57 };
58 
59 enum class Action {
60     TRANS_TO_INIT,
61     TRANS_TO_RECORDING_SETTING,
62     TRANS_TO_READY,
63     TRANS_TO_RECORDING,
64     TRANS_TO_PAUSE,
65     TRANS_TO_ERROR,
66     ACTION_PENDING,
67     ACTION_BUTT
68 };
69 
70 class State {
71 public:
72     State(StateId stateId, std::string name, RecorderExecutor& executor);
73     virtual ~State() = default;
74     virtual std::tuple<ErrorCode, Action> Enter(Intent intent);
75     virtual void Exit();
76     std::tuple<ErrorCode, Action> Execute(Intent intent, const Plugin::Any& param);
77     const std::string &GetName();
78     StateId GetStateId();
79 
80     virtual std::tuple<ErrorCode, Action> SetVideoSource(const Plugin::Any& param);
81     virtual std::tuple<ErrorCode, Action> SetAudioSource(const Plugin::Any& param);
82     virtual std::tuple<ErrorCode, Action> Configure(const Plugin::Any& param);
83     virtual std::tuple<ErrorCode, Action> SetOutputFormat(const Plugin::Any& param);
84     virtual std::tuple<ErrorCode, Action> SetObs();
85     virtual std::tuple<ErrorCode, Action> GetSurface();
86     virtual std::tuple<ErrorCode, Action> Prepare();
87     virtual std::tuple<ErrorCode, Action> Start();
88     virtual std::tuple<ErrorCode, Action> Stop(const Plugin::Any& param);
89     virtual std::tuple<ErrorCode, Action> Pause();
90     virtual std::tuple<ErrorCode, Action> Resume();
91     virtual std::tuple<ErrorCode, Action> Reset();
92     virtual std::tuple<ErrorCode, Action> OnReady();
93     virtual std::tuple<ErrorCode, Action> OnError(const Plugin::Any& param) final;
94     virtual std::tuple<ErrorCode, Action> OnComplete();
95 
96 protected:
97     std::tuple<ErrorCode, Action> DispatchIntent(Intent intent, const Plugin::Any& param);
98 
99     const StateId stateId_;
100     const std::string name_;
101     RecorderExecutor &executor_;
102     const std::map<Intent, std::string> intentDesc_ = {
103         {Intent::SET_OBS, "SET_OBS"},
104         {Intent::SET_VIDEO_SOURCE, "SET_VIDEO_SOURCE"},
105         {Intent::SET_AUDIO_SOURCE, "SET_AUDIO_SOURCE"},
106         {Intent::SET_OUTPUT_FORMAT, "SET_OUTPUT_FORMAT"},
107         {Intent::CONFIGURE, "CONFIGURE"},
108         {Intent::PREPARE, "PREPARE"},
109         {Intent::START, "START"},
110         {Intent::PAUSE, "PAUSE"},
111         {Intent::RESUME, "RESUME"},
112         {Intent::STOP, "STOP"},
113         {Intent::RESET, "RESET"},
114         {Intent::NOTIFY_READY, "NOTIFY_READY"},
115         {Intent::NOTIFY_COMPLETE, "NOTIFY_COMPLETE"},
116         {Intent::NOTIFY_ERROR, "NOTIFY_ERROR"},
117         {Intent::INTENT_BUTT, "INTENT_BUTT"}};
118     const std::map<Action, std::string> actionDesc_ = {
119         {Action::TRANS_TO_INIT, "TRANS_TO_INIT"},
120         {Action::TRANS_TO_RECORDING_SETTING, "TRANS_TO_RECORDING_SETTING"},
121         {Action::TRANS_TO_READY, "TRANS_TO_READY"},
122         {Action::TRANS_TO_RECORDING, "TRANS_TO_RECORDING"},
123         {Action::TRANS_TO_PAUSE, "TRANS_TO_PAUSE"},
124         {Action::TRANS_TO_ERROR, "TRANS_TO_ERROR"},
125         {Action::ACTION_PENDING, "ACTION_PENDING"},
126         {Action::ACTION_BUTT, "ACTION_BUTT"}};
127 };
128 } // namespace Record
129 } // namespace Media
130 } // namespace OHOS
131 #endif
132