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_PREPARE_STATE_H
17 #define HISTREAMER_HIPLAYER_PREPARE_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 PreparingState : public State {
28 public:
PreparingState(StateId stateId,PlayExecutor & executor)29     explicit PreparingState(StateId stateId, PlayExecutor& executor) : State(stateId, "PreparingState", executor)
30     {
31     }
32 
33     ~PreparingState() override = default;
34 
Enter(Intent)35     std::tuple<ErrorCode, Action> Enter(Intent) override
36     {
37         Action nextAction = Action::ACTION_BUTT;
38         auto rtv = executor_.PrepareFilters();
39         if (rtv != ErrorCode::SUCCESS) {
40             nextAction = Action::TRANS_TO_INIT;
41         }
42         return {rtv, nextAction};
43     }
44 
Play()45     std::tuple<ErrorCode, Action> Play() override
46     {
47         MEDIA_LOG_W("Play received in preparing state.");
48         return {ErrorCode::SUCCESS, Action::ACTION_PENDING};
49     }
50 
Stop()51     std::tuple<ErrorCode, Action> Stop() override
52     {
53         return {ErrorCode::SUCCESS, Action::TRANS_TO_STOPPED};
54     }
55 
OnReady()56     std::tuple<ErrorCode, Action> OnReady() override
57     {
58         return {ErrorCode::SUCCESS, Action::TRANS_TO_READY};
59     }
60 };
61 } // namespace Media
62 } // namespace OHOS
63 #endif
64