1 /* 2 * Copyright (C) 2024 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 ITRANSCODER_ENGINE_H 17 #define ITRANSCODER_ENGINE_H 18 19 #include <cstdint> 20 #include <string> 21 #include <memory> 22 #include <refbase.h> 23 #include "nocopyable.h" 24 #include "transcoder.h" 25 #include "transcoder_param.h" 26 27 namespace OHOS { 28 class Surface; 29 30 namespace Media { 31 32 /** 33 * TransCoder Engine Observer. This is a abstract class, engine's user need to implement it and register 34 * its instance into engine. The transCoder engine will report itself's information or error asynchronously 35 * to observer. 36 */ 37 class ITransCoderEngineObs : public std::enable_shared_from_this<ITransCoderEngineObs> { 38 public: 39 virtual ~ITransCoderEngineObs() = default; 40 virtual void OnError(TransCoderErrorType errorType, int32_t errorCode) = 0; 41 virtual void OnInfo(TransCoderOnInfoType type, int32_t extra) = 0; 42 }; 43 44 /** 45 * TransCoder Engine Interface. 46 */ 47 class ITransCoderEngine { 48 public: 49 virtual ~ITransCoderEngine() = default; 50 SetInstanceId(uint64_t instanceId)51 virtual void SetInstanceId(uint64_t instanceId) 52 { 53 (void)instanceId; 54 } 55 56 /** 57 * Sets the input file. The function must be called before Prepare. 58 * After this interface called, the engine will not accept any source setting interface call. 59 * Return MSERR_OK indicates success, or others indicate failed. 60 */ 61 virtual int32_t SetInputFile(const std::string &url) = 0; 62 63 /** 64 * Sets the output file. The function must be called before Prepare. 65 * After this interface called, the engine will not accept any destination setting interface call. 66 * Return MSERR_OK indicates success, or others indicate failed. 67 */ 68 virtual int32_t SetOutputFile(const int32_t fd) = 0; 69 70 /** 71 * Sets the output file format. The function must be called after SetVideoSource or SetAudioSource, and before 72 * Prepare. After this interface called, the engine will not accept any source setting interface call. 73 * Return MSERR_OK indicates success, or others indicate failed. 74 */ 75 virtual int32_t SetOutputFormat(OutputFormatType format) = 0; 76 77 /** 78 * Register a transCodering observer. 79 * Return MSERR_OK indicates success, or others indicate failed. 80 */ 81 virtual int32_t SetObs(const std::weak_ptr<ITransCoderEngineObs> &obs) = 0; 82 83 /** 84 * Configure static transCoder parameters before calling the Prepare interface. The interface must be called after 85 * SetOutputFormat. The sourceId indicates the source ID, which can be obtained from SetVideoSource 86 * or SetAudioSource. Use the DUMMY_SOURCE_ID to configure the source-independent parameters. 87 * Return MSERR_OK indicates success, or others indicate failed. 88 */ 89 virtual int32_t Configure(const TransCoderParam &recParam) = 0; 90 91 /** 92 * Prepares for transCodering. This function must be called before Start. Ensure all required transCoder parameter 93 * have already been set, or this call will be failed. 94 * Return MSERR_OK indicates success, or others indicate failed. 95 */ 96 virtual int32_t Prepare() = 0; 97 98 /** 99 * Starts transCodering. This function must be called after Prepare. 100 * Return MSERR_OK indicates success, or others indicate failed. 101 */ 102 virtual int32_t Start() = 0; 103 104 /** 105 * Pause transCodering. This function must be called during transCodering. 106 * Return MSERR_OK indicates success, or others indicate failed. 107 */ 108 virtual int32_t Pause() = 0; 109 110 /** 111 * Resume transCodering. This function must be called during transCodering. After called, the paused 112 * transCodering willbe resumed. 113 * Return MSERR_OK indicates success, or others indicate failed. 114 */ 115 virtual int32_t Resume() = 0; 116 117 /** 118 * Resets the transCodering. After this interface called, anything need to be reconfigured. 119 * Return MSERR_OK indicates success, or others indicate failed. 120 */ 121 virtual int32_t Cancel() = 0; 122 123 /** 124 * Get current transcodering time. 125 * Return MSERR_OK indicates success, or others indicate failed. 126 */ 127 virtual int32_t GetCurrentTime(int32_t ¤tTime) = 0; 128 129 /** 130 * Get the input file duration. 131 * Return MSERR_OK indicates success, or others indicate failed. 132 */ 133 virtual int32_t GetDuration(int32_t &duration) = 0; 134 }; 135 } // namespace Media 136 } // namespace OHOS 137 #endif 138