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_STATE_H 17 #define HISTREAMER_HIRECORDER_RECORDING_STATE_H 18 19 #include <memory> 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 RecordingState : public State { 28 public: RecordingState(StateId stateId,RecorderExecutor & executor)29 explicit RecordingState(StateId stateId, RecorderExecutor& executor) : State(stateId, "RecordingState", executor) 30 { 31 } 32 33 ~RecordingState() override = default; 34 Enter(Intent intent)35 std::tuple<ErrorCode, Action> Enter(Intent intent) override 36 { 37 MEDIA_LOG_D("Enter state: " PUBLIC_LOG_S, name_.c_str()); 38 ErrorCode ret; 39 if (intent == Intent::RESUME) { 40 ret = executor_.DoResume(); 41 } else { 42 ret = executor_.DoStart(); 43 } 44 return {ret, Action::ACTION_BUTT}; 45 } 46 Start()47 std::tuple<ErrorCode, Action> Start() override 48 { 49 return {ErrorCode::SUCCESS, Action::ACTION_BUTT}; 50 } 51 Resume()52 std::tuple<ErrorCode, Action> Resume() override 53 { 54 return {ErrorCode::SUCCESS, Action::ACTION_BUTT}; 55 } 56 Pause()57 std::tuple<ErrorCode, Action> Pause() override 58 { 59 return {ErrorCode::SUCCESS, Action::TRANS_TO_PAUSE}; 60 } 61 Stop(const Plugin::Any & param)62 std::tuple<ErrorCode, Action> Stop(const Plugin::Any& param) override 63 { 64 auto ret = executor_.DoStop(param); 65 Action action = (ret == ErrorCode::SUCCESS) ? Action::ACTION_BUTT : Action::TRANS_TO_ERROR; 66 return {ret, action}; 67 } 68 OnComplete()69 std::tuple<ErrorCode, Action> OnComplete() override 70 { 71 auto ret = executor_.DoOnComplete(); 72 Action action = (ret == ErrorCode::SUCCESS) ? Action::TRANS_TO_INIT : Action::ACTION_BUTT; 73 return {ret, action}; 74 } 75 }; 76 } // namespace Record 77 } // namespace Media 78 } // namespace OHOS 79 #endif // HISTREAMER_HIRECORDER_RECORDING_STATE_H 80