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_HIRECORDER_RECORDING_SETTING_STATE_H 17 #define HISTREAMER_HIRECORDER_RECORDING_SETTING_STATE_H 18 19 #include "foundation/osal/thread/mutex.h" 20 #include "pipeline/core/error_code.h" 21 #include "recorder_executor.h" 22 #include "state.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace Record { 27 class RecordingSettingState : public State { 28 public: RecordingSettingState(StateId stateId,RecorderExecutor & executor)29 explicit RecordingSettingState(StateId stateId, RecorderExecutor& executor) 30 : State(stateId, "RecordingSettingState", executor) 31 { 32 } 33 34 ~RecordingSettingState() override = default; 35 SetVideoSource(const Plugin::Any & param)36 std::tuple<ErrorCode, Action> SetVideoSource(const Plugin::Any& param) override 37 { 38 auto ret = executor_.DoSetVideoSource(param); 39 Action action = (ret == ErrorCode::SUCCESS) ? Action::TRANS_TO_RECORDING_SETTING : Action::ACTION_BUTT; 40 return {ret, action}; 41 } 42 SetAudioSource(const Plugin::Any & param)43 std::tuple<ErrorCode, Action> SetAudioSource(const Plugin::Any& param) override 44 { 45 auto ret = executor_.DoSetAudioSource(param); 46 Action action = (ret == ErrorCode::SUCCESS) ? Action::TRANS_TO_RECORDING_SETTING : Action::ACTION_BUTT; 47 return {ret, action}; 48 } 49 Configure(const Plugin::Any & param)50 std::tuple<ErrorCode, Action> Configure(const Plugin::Any& param) override 51 { 52 auto ret = executor_.DoConfigure(param); 53 Action action = (ret == ErrorCode::SUCCESS) ? Action::TRANS_TO_RECORDING_SETTING : Action::ACTION_BUTT; 54 return {ret, action}; 55 } 56 SetOutputFormat(const Plugin::Any & param)57 std::tuple<ErrorCode, Action> SetOutputFormat(const Plugin::Any& param) override 58 { 59 auto ret = executor_.DoSetOutputFormat(param); 60 Action action = (ret == ErrorCode::SUCCESS) ? Action::TRANS_TO_RECORDING_SETTING : Action::ACTION_BUTT; 61 return {ret, action}; 62 } 63 Prepare()64 std::tuple<ErrorCode, Action> Prepare() override 65 { 66 auto rtv = executor_.DoPrepare(); 67 if (rtv == ErrorCode::SUCCESS) { 68 return {rtv, Action::ACTION_BUTT}; 69 } else { 70 return {rtv, Action::TRANS_TO_ERROR}; 71 } 72 } 73 Start()74 std::tuple<ErrorCode, Action> Start() override 75 { 76 return {ErrorCode::SUCCESS, Action::ACTION_PENDING}; 77 } 78 Stop(const Plugin::Any & param)79 std::tuple<ErrorCode, Action> Stop(const Plugin::Any& param) override 80 { 81 auto ret = executor_.DoStop(param); 82 Action action = (ret == ErrorCode::SUCCESS) ? Action::TRANS_TO_INIT : Action::TRANS_TO_ERROR; 83 return {ret, action}; 84 } 85 OnReady()86 std::tuple<ErrorCode, Action> OnReady() override 87 { 88 return {ErrorCode::SUCCESS, Action::TRANS_TO_READY}; 89 } 90 }; 91 } // namespace Record 92 } // namespace Media 93 } // namespace OHOS 94 #endif // HISTREAMER_HIRECORDER_RECORDING_SETTING_STATE_H 95