• 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_HIPLAYER_STATE_H
17 #define HISTREAMER_HIPLAYER_STATE_H
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <tuple>
23 #include "common/any.h"
24 #include "foundation/error_code.h"
25 #include "foundation/log.h"
26 #include "play_executor.h"
27 
28 namespace OHOS {
29 namespace Media {
30 enum class StateId {
31     INIT,
32     PREPARING,
33     READY,
34     PAUSE,
35     PLAYING,
36     BUTT,
37 };
38 
39 enum class Intent {
40     SET_SOURCE,
41     SEEK,
42     PLAY,
43     PAUSE,
44     RESUME,
45     STOP,
46     SET_ATTRIBUTE,
47     NOTIFY_READY,
48     NOTIFY_COMPLETE,
49     NOTIFY_ERROR,
50     INTENT_BUTT
51 };
52 
53 enum class Action {
54     TRANS_TO_INIT,
55     TRANS_TO_PREPARING,
56     TRANS_TO_READY,
57     TRANS_TO_PLAYING,
58     TRANS_TO_PAUSE,
59     ACTION_PENDING,
60     ACTION_BUTT
61 };
62 
63 class State {
64 public:
65     State(StateId stateId, std::string name, PlayExecutor& executor);
66     virtual ~State() = default;
67     virtual std::tuple<ErrorCode, Action> Enter(Intent intent);
68     virtual void Exit();
69     std::tuple<ErrorCode, Action> Execute(Intent intent, const Plugin::Any& param);
70     const std::string& GetName();
71     StateId GetStateId();
72     virtual std::tuple<ErrorCode, Action> SetSource(const Plugin::Any& param);
73     virtual std::tuple<ErrorCode, Action> Play();
74     virtual std::tuple<ErrorCode, Action> Stop();
75     virtual std::tuple<ErrorCode, Action> Pause();
76     virtual std::tuple<ErrorCode, Action> Resume();
77     virtual std::tuple<ErrorCode, Action> Seek(const Plugin::Any& param);
78     virtual std::tuple<ErrorCode, Action> SetAttribute();
79     virtual std::tuple<ErrorCode, Action> OnReady();
80     virtual std::tuple<ErrorCode, Action> OnError(const Plugin::Any& param) final;
81     virtual std::tuple<ErrorCode, Action> OnComplete();
82 
83 protected:
84     std::tuple<ErrorCode, Action> DispatchIntent(Intent intent, const Plugin::Any& param);
85 
86     const StateId stateId_;
87     const std::string name_;
88     PlayExecutor& executor_;
89     const std::map<Intent, std::string> intentDesc_ = {{Intent::SET_SOURCE, "SET_SOURCE"},
90                                                        {Intent::SEEK, "SEEK"},
91                                                        {Intent::PLAY, "PLAY"},
92                                                        {Intent::PAUSE, "PAUSE"},
93                                                        {Intent::RESUME, "RESUME"},
94                                                        {Intent::STOP, "STOP"},
95                                                        {Intent::SET_ATTRIBUTE, "SET_ATTRIBUTE"},
96                                                        {Intent::NOTIFY_READY, "NOTIFY_READY"},
97                                                        {Intent::NOTIFY_COMPLETE, "NOTIFY_COMPLETE"},
98                                                        {Intent::NOTIFY_ERROR, "NOTIFY_ERROR"},
99                                                        {Intent::INTENT_BUTT, "INTENT_BUTT"}};
100     const std::map<Action, std::string> actionDesc_ = {
101         {Action::TRANS_TO_INIT, "TRANS_TO_INIT"},   {Action::TRANS_TO_PREPARING, "TRANS_TO_PREPARING"},
102         {Action::TRANS_TO_READY, "TRANS_TO_READY"}, {Action::TRANS_TO_PLAYING, "TRANS_TO_PLAYING"},
103         {Action::TRANS_TO_PAUSE, "TRANS_TO_PAUSE"}, {Action::ACTION_PENDING, "ACTION_PENDING"},
104         {Action::ACTION_BUTT, "ACTION_BUTT"}};
105 };
106 } // namespace Media
107 } // namespace OHOS
108 #endif
109