/* * 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_HIPLAYER_STATE_H #define HISTREAMER_HIPLAYER_STATE_H #include #include #include #include #include "foundation/log.h" #include "pipeline/core/error_code.h" #include "play_executor.h" #include "plugin/common/any.h" namespace OHOS { namespace Media { enum class StateId { IDLE = 0, INIT = 1, PREPARING = 2, READY = 3, PAUSE = 4, PLAYING = 5, STOPPED = 6, EOS = 7, BUTT, }; enum class Intent { SET_SOURCE, SEEK, PREPARE, PLAY, PAUSE, RESUME, STOP, RESET, SET_ATTRIBUTE, NOTIFY_READY, NOTIFY_COMPLETE, NOTIFY_ERROR, INTENT_BUTT }; enum class Action { TRANS_TO_IDLE, TRANS_TO_INIT, TRANS_TO_PREPARING, TRANS_TO_READY, TRANS_TO_PLAYING, TRANS_TO_PAUSE, TRANS_TO_STOPPED, TRANS_TO_EOS, ACTION_PENDING, ACTION_BUTT }; class State { public: State(StateId stateId, std::string name, PlayExecutor& 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 SetSource(const Plugin::Any& param); virtual std::tuple Prepare(); virtual std::tuple Play(); virtual std::tuple Stop(); virtual std::tuple Reset(); virtual std::tuple Pause(); virtual std::tuple Resume(); virtual std::tuple Seek(const Plugin::Any& param); virtual std::tuple SetAttribute(); virtual std::tuple OnReady(); virtual std::tuple OnError(const Plugin::Any& param) final; virtual std::tuple OnComplete(); static const char* GetStateName(StateId state); static const char* GetIntentName(Intent intent); static const char* GetActionName(Action action); protected: std::tuple DispatchIntent(Intent intent, const Plugin::Any& param); const StateId stateId_; const std::string name_; PlayExecutor& executor_; }; } // namespace Media } // namespace OHOS #endif