1 /* 2 * Copyright (c) 2022-2022 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_IDLE_STATE_H 17 #define HISTREAMER_HIPLAYER_IDLE_STATE_H 18 #include "state.h" 19 namespace OHOS { 20 namespace Media { 21 // idle --setSource--> init anyState --reset--> idle 22 class IdleState : public State { 23 public: IdleState(StateId stateId,PlayExecutor & executor)24 explicit IdleState(StateId stateId, PlayExecutor& executor) : State(stateId, "IdleState", executor) {} 25 26 ~IdleState() override = default; 27 SetSource(const Plugin::Any & param)28 std::tuple<ErrorCode, Action> SetSource(const Plugin::Any& param) override 29 { 30 std::shared_ptr<MediaSource> source; 31 if (!Plugin::Any::IsSameTypeWith<std::shared_ptr<MediaSource>>(param) || 32 !(source = Plugin::AnyCast<std::shared_ptr<MediaSource>>(param))) { 33 return {ErrorCode::ERROR_INVALID_PARAMETER_TYPE, Action::ACTION_BUTT}; 34 } 35 auto ret = executor_.DoSetSource(source); 36 Action action = ret == ErrorCode::SUCCESS ? Action::TRANS_TO_INIT : Action::ACTION_BUTT; 37 return {ret, action}; 38 } 39 Enter(Intent)40 std::tuple<ErrorCode, Action> Enter(Intent) override 41 { 42 return {executor_.DoReset(), Action::ACTION_BUTT}; 43 } 44 }; 45 } // namespace Media 46 } // namespace OHOS 47 #endif // HISTREAMER_HIPLAYER_IDLE_STATE_H 48