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_PLAYER_READY_STATE_H
17 #define HISTREAMER_PLAYER_READY_STATE_H
18 
19 #include <memory>
20 #include "foundation/log.h"
21 #include "pipeline/core/error_code.h"
22 #include "play_executor.h"
23 #include "state.h"
24 
25 namespace OHOS {
26 namespace Media {
27 class ReadyState : public State {
28 public:
ReadyState(StateId stateId,PlayExecutor & executor)29     explicit ReadyState(StateId stateId, PlayExecutor& executor) : State(stateId, "ReadyState", executor)
30     {
31     }
32 
33     ~ReadyState() override = default;
34 
Enter(Intent intent)35     std::tuple<ErrorCode, Action> Enter(Intent intent) override
36     {
37         (void)intent;
38         auto rtv = executor_.DoOnReady();
39         if (rtv == ErrorCode::SUCCESS) {
40             return {rtv, Action::ACTION_BUTT};
41         } else {
42             return {rtv, Action::TRANS_TO_INIT};
43         }
44     }
45 
Seek(const Plugin::Any & param)46     std::tuple<ErrorCode, Action> Seek(const Plugin::Any& param) override
47     {
48         MEDIA_LOG_D("Seek in ready state.");
49         std::tuple<ErrorCode, Action> err {ErrorCode::ERROR_INVALID_PARAMETER_TYPE, Action::ACTION_BUTT};
50         FALSE_RETURN_V(Plugin::Any::IsSameTypeWith<SeekInfo>(param), err);
51         auto info = Plugin::AnyCast<SeekInfo>(param);
52         auto ret = executor_.DoSeek(info.hstTime, info.mode, true);
53         return {ret, Action::ACTION_BUTT};
54     }
55 
Play()56     std::tuple<ErrorCode, Action> Play() override
57     {
58         MEDIA_LOG_D("Play in ready state.");
59         return {ErrorCode::SUCCESS, Action::TRANS_TO_PLAYING};
60     }
61 
Stop()62     std::tuple<ErrorCode, Action> Stop() override
63     {
64         MEDIA_LOG_D("Stop in ready state.");
65         return {ErrorCode::SUCCESS, Action::TRANS_TO_STOPPED};
66     }
67 };
68 } // namespace Media
69 } // namespace OHOS
70 #endif
71