/* * Copyright (c) 2021-2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HISTREAMER_HIRECORDER_STATE_H #define HISTREAMER_HIRECORDER_STATE_H #include #include #include #include #include #include #include "foundation/log.h" #include "pipeline/core/error_code.h" #include "plugin/common/any.h" #include "recorder_executor.h" namespace OHOS { namespace Media { namespace Record { enum class StateId { INIT, RECORDING_SETTING, READY, PAUSE, RECORDING, ERROR, BUTT, }; enum class Intent { SET_OBS, SET_VIDEO_SOURCE, SET_AUDIO_SOURCE, SET_OUTPUT_FORMAT, CONFIGURE, PREPARE, START, PAUSE, RESUME, STOP, RESET, NOTIFY_READY, NOTIFY_COMPLETE, NOTIFY_ERROR, INTENT_BUTT }; enum class Action { TRANS_TO_INIT, TRANS_TO_RECORDING_SETTING, TRANS_TO_READY, TRANS_TO_RECORDING, TRANS_TO_PAUSE, TRANS_TO_ERROR, ACTION_PENDING, ACTION_BUTT }; class State { public: State(StateId stateId, std::string name, RecorderExecutor& executor); virtual ~State() = default; virtual std::tuple Enter(Intent intent); virtual void Exit(); std::tuple Execute(Intent intent, const Plugin::Any& param); const std::string &GetName(); StateId GetStateId(); virtual std::tuple SetVideoSource(const Plugin::Any& param); virtual std::tuple SetAudioSource(const Plugin::Any& param); virtual std::tuple Configure(const Plugin::Any& param); virtual std::tuple SetOutputFormat(const Plugin::Any& param); virtual std::tuple SetObs(); virtual std::tuple GetSurface(); virtual std::tuple Prepare(); virtual std::tuple Start(); virtual std::tuple Stop(const Plugin::Any& param); virtual std::tuple Pause(); virtual std::tuple Resume(); virtual std::tuple Reset(); virtual std::tuple OnReady(); virtual std::tuple OnError(const Plugin::Any& param) final; virtual std::tuple OnComplete(); protected: std::tuple DispatchIntent(Intent intent, const Plugin::Any& param); const StateId stateId_; const std::string name_; RecorderExecutor &executor_; const std::map intentDesc_ = { {Intent::SET_OBS, "SET_OBS"}, {Intent::SET_VIDEO_SOURCE, "SET_VIDEO_SOURCE"}, {Intent::SET_AUDIO_SOURCE, "SET_AUDIO_SOURCE"}, {Intent::SET_OUTPUT_FORMAT, "SET_OUTPUT_FORMAT"}, {Intent::CONFIGURE, "CONFIGURE"}, {Intent::PREPARE, "PREPARE"}, {Intent::START, "START"}, {Intent::PAUSE, "PAUSE"}, {Intent::RESUME, "RESUME"}, {Intent::STOP, "STOP"}, {Intent::RESET, "RESET"}, {Intent::NOTIFY_READY, "NOTIFY_READY"}, {Intent::NOTIFY_COMPLETE, "NOTIFY_COMPLETE"}, {Intent::NOTIFY_ERROR, "NOTIFY_ERROR"}, {Intent::INTENT_BUTT, "INTENT_BUTT"}}; const std::map actionDesc_ = { {Action::TRANS_TO_INIT, "TRANS_TO_INIT"}, {Action::TRANS_TO_RECORDING_SETTING, "TRANS_TO_RECORDING_SETTING"}, {Action::TRANS_TO_READY, "TRANS_TO_READY"}, {Action::TRANS_TO_RECORDING, "TRANS_TO_RECORDING"}, {Action::TRANS_TO_PAUSE, "TRANS_TO_PAUSE"}, {Action::TRANS_TO_ERROR, "TRANS_TO_ERROR"}, {Action::ACTION_PENDING, "ACTION_PENDING"}, {Action::ACTION_BUTT, "ACTION_BUTT"}}; const std::unordered_map( const Plugin::Any ¶m)>> intentDispatchersMap_ = { {Intent::SET_OBS, [this](const Plugin::Any ¶m) { std::ignore = param; return SetObs(); }}, {Intent::SET_VIDEO_SOURCE, [this](const Plugin::Any ¶m) { return SetVideoSource(param); }}, {Intent::SET_AUDIO_SOURCE, [this](const Plugin::Any ¶m) { return SetAudioSource(param); }}, {Intent::CONFIGURE, [this](const Plugin::Any ¶m) { return Configure(param); }}, {Intent::SET_OUTPUT_FORMAT, [this](const Plugin::Any ¶m) { return SetOutputFormat(param); }}, {Intent::PREPARE, [this](const Plugin::Any ¶m) { std::ignore = param; return Prepare(); }}, {Intent::START, [this](const Plugin::Any ¶m) { std::ignore = param; return Start(); }}, {Intent::PAUSE, [this](const Plugin::Any ¶m) { std::ignore = param; return Pause(); }}, {Intent::RESUME, [this](const Plugin::Any ¶m) { std::ignore = param; return Resume(); }}, {Intent::RESET, [this](const Plugin::Any ¶m) { std::ignore = param; return Reset(); }}, {Intent::STOP, [this](const Plugin::Any ¶m) { return Stop(param); }}, {Intent::NOTIFY_READY, [this](const Plugin::Any ¶m) { std::ignore = param; return OnReady(); }}, {Intent::NOTIFY_COMPLETE, [this](const Plugin::Any ¶m) { std::ignore = param; return OnComplete(); }}, {Intent::NOTIFY_ERROR, [this](const Plugin::Any ¶m) { return OnError(param); }}, }; }; } // namespace Record } // namespace Media } // namespace OHOS #endif