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_INIT_STATE_H 17 #define HISTREAMER_HIPLAYER_INIT_STATE_H 18 19 #include <memory> 20 21 #include "foundation/log.h" 22 #include "foundation/osal/thread/mutex.h" 23 #include "pipeline/core/error_code.h" 24 #include "play_executor.h" 25 #include "state.h" 26 27 namespace OHOS { 28 namespace Media { 29 class InitState : public State { 30 public: InitState(StateId stateId,PlayExecutor & executor)31 explicit InitState(StateId stateId, PlayExecutor &executor) : State(stateId, "InitState", executor) {} 32 33 ~InitState() override = default; 34 SetSource(const Plugin::Any & param)35 std::tuple<ErrorCode, Action> SetSource(const Plugin::Any& param) override 36 { 37 std::shared_ptr<MediaSource> source; 38 if (!Plugin::Any::IsSameTypeWith<std::shared_ptr<MediaSource>>(param) || 39 !(source = Plugin::AnyCast<std::shared_ptr<MediaSource>>(param))) { 40 return {ErrorCode::ERROR_INVALID_PARAMETER_TYPE, Action::ACTION_BUTT}; 41 } 42 auto ret = executor_.DoSetSource(source); 43 Action action = ret == ErrorCode::SUCCESS ? Action::TRANS_TO_INIT : Action::ACTION_BUTT; 44 return {ret, action}; 45 } 46 Prepare()47 std::tuple<ErrorCode, Action> Prepare() override 48 { 49 return {ErrorCode::SUCCESS, Action::TRANS_TO_PREPARING}; 50 } 51 Stop()52 std::tuple<ErrorCode, Action> Stop() override 53 { 54 return {ErrorCode::SUCCESS, Action::TRANS_TO_STOPPED}; 55 } 56 }; 57 } // namespace Media 58 } // namespace OHOS 59 #endif 60