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 #define HST_LOG_TAG "State"
17
18 #include "state.h"
19
20 namespace OHOS {
21 namespace Media {
22 namespace Record {
State(StateId stateId,std::string name,RecorderExecutor & executor)23 State::State(StateId stateId, std::string name, RecorderExecutor& executor)
24 : stateId_(stateId), name_(std::move(name)), executor_(executor)
25 {
26 }
27
Enter(Intent intent)28 std::tuple<ErrorCode, Action> State::Enter(Intent intent)
29 {
30 (void)intent;
31 MEDIA_LOG_D("Enter state: " PUBLIC_LOG_S, name_.c_str());
32 return {ErrorCode::SUCCESS, Action::ACTION_BUTT};
33 }
34
Exit()35 void State::Exit()
36 {
37 MEDIA_LOG_D("Exit state: " PUBLIC_LOG_S, name_.c_str());
38 }
39
Execute(Intent intent,const Plugin::Any & param)40 std::tuple<ErrorCode, Action> State::Execute(Intent intent, const Plugin::Any& param)
41 {
42 return DispatchIntent(intent, param);
43 }
44
GetName()45 const std::string& State::GetName()
46 {
47 return name_;
48 }
49
GetStateId()50 StateId State::GetStateId()
51 {
52 return stateId_;
53 }
54
SetVideoSource(const Plugin::Any & param)55 std::tuple<ErrorCode, Action> State::SetVideoSource(const Plugin::Any& param)
56 {
57 (void)param;
58 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
59 }
60
SetAudioSource(const Plugin::Any & param)61 std::tuple<ErrorCode, Action> State::SetAudioSource(const Plugin::Any& param)
62 {
63 (void)param;
64 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
65 }
66
Configure(const Plugin::Any & param)67 std::tuple<ErrorCode, Action> State::Configure(const Plugin::Any ¶m)
68 {
69 (void)param;
70 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
71 }
72
SetOutputFormat(const Plugin::Any & param)73 std::tuple<ErrorCode, Action> State::SetOutputFormat(const Plugin::Any& param)
74 {
75 (void)param;
76 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
77 }
78
SetObs()79 std::tuple<ErrorCode, Action> State::SetObs()
80 {
81 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
82 }
83
GetSurface()84 std::tuple<ErrorCode, Action> State::GetSurface()
85 {
86 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
87 }
88
Prepare()89 std::tuple<ErrorCode, Action> State::Prepare()
90 {
91 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
92 }
93
Start()94 std::tuple<ErrorCode, Action> State::Start()
95 {
96 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
97 }
98
Stop(const Plugin::Any & param)99 std::tuple<ErrorCode, Action> State::Stop(const Plugin::Any& param)
100 {
101 (void)param;
102 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
103 }
104
Pause()105 std::tuple<ErrorCode, Action> State::Pause()
106 {
107 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
108 }
109
Resume()110 std::tuple<ErrorCode, Action> State::Resume()
111 {
112 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
113 }
114
Reset()115 std::tuple<ErrorCode, Action> State::Reset()
116 {
117 FALSE_LOG(executor_.DoReset() == ErrorCode::SUCCESS);
118 return {ErrorCode::SUCCESS, Action::TRANS_TO_INIT};
119 }
120
OnReady()121 std::tuple<ErrorCode, Action> State::OnReady()
122 {
123 return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
124 }
125
OnError(const Plugin::Any & param)126 std::tuple<ErrorCode, Action> State::OnError(const Plugin::Any& param)
127 {
128 return {ErrorCode::SUCCESS, Action::TRANS_TO_ERROR};
129 }
130
OnComplete()131 std::tuple<ErrorCode, Action> State::OnComplete()
132 {
133 return {ErrorCode::SUCCESS, Action::ACTION_BUTT};
134 }
135
DispatchIntent(Intent intent,const Plugin::Any & param)136 std::tuple<ErrorCode, Action> State::DispatchIntent(Intent intent, const Plugin::Any& param)
137 {
138 ErrorCode rtv = ErrorCode::SUCCESS;
139 Action nextAction = Action::ACTION_BUTT;
140 switch (intent) {
141 case Intent::SET_OBS:
142 std::tie(rtv, nextAction) = SetObs();
143 break;
144 case Intent::SET_VIDEO_SOURCE:
145 std::tie(rtv, nextAction) = SetVideoSource(param);
146 break;
147 case Intent::SET_AUDIO_SOURCE:
148 std::tie(rtv, nextAction) = SetAudioSource(param);
149 break;
150 case Intent::CONFIGURE:
151 std::tie(rtv, nextAction) = Configure(param);
152 break;
153 case Intent::SET_OUTPUT_FORMAT:
154 std::tie(rtv, nextAction) = SetOutputFormat(param);
155 break;
156 case Intent::PREPARE:
157 std::tie(rtv, nextAction) = Prepare();
158 break;
159 case Intent::START:
160 std::tie(rtv, nextAction) = Start();
161 break;
162 case Intent::PAUSE:
163 std::tie(rtv, nextAction) = Pause();
164 break;
165 case Intent::RESUME:
166 std::tie(rtv, nextAction) = Resume();
167 break;
168 case Intent::RESET:
169 std::tie(rtv, nextAction) = Reset();
170 break;
171 case Intent::STOP:
172 std::tie(rtv, nextAction) = Stop(param);
173 break;
174 case Intent::NOTIFY_READY:
175 std::tie(rtv, nextAction) = OnReady();
176 break;
177 case Intent::NOTIFY_COMPLETE:
178 std::tie(rtv, nextAction) = OnComplete();
179 break;
180 case Intent::NOTIFY_ERROR:
181 std::tie(rtv, nextAction) = OnError(param);
182 break;
183 case Intent::INTENT_BUTT:
184 break;
185 default:
186 break;
187 }
188 MEDIA_LOG_D("DispatchIntent " PUBLIC_LOG_S ", curState: " PUBLIC_LOG_S ", nextState: " PUBLIC_LOG_S,
189 intentDesc_.at(intent).c_str(), name_.c_str(), actionDesc_.at(nextAction).c_str());
190 return {rtv, nextAction};
191 }
192 } // namespace Record
193 } // namespace Media
194 } // namespace OHOS