1 /* 2 * Copyright (C) 2021-2025 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 #ifndef I_PLAYER_ENGINE_H 16 #define I_PLAYER_ENGINE_H 17 18 #include <map> 19 #include <vector> 20 #include <cstdint> 21 #include <string> 22 #include <refbase.h> 23 #include "player.h" 24 #include "meta/video_types.h" 25 #include "nocopyable.h" 26 27 #include "i_keysession_service.h" 28 29 namespace OHOS { 30 class Surface; 31 32 namespace Media { 33 class IPlayerEngineObs : public std::enable_shared_from_this<IPlayerEngineObs> { 34 public: 35 virtual ~IPlayerEngineObs() = default; 36 virtual void OnError(PlayerErrorType errorType, int32_t errorCode) = 0; OnErrorMessage(int32_t errorCode,const std::string & errorMsg)37 virtual void OnErrorMessage(int32_t errorCode, const std::string &errorMsg) 38 { 39 (void)errorCode; 40 (void)errorMsg; 41 } 42 virtual void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) = 0; 43 virtual void OnSystemOperation(PlayerOnSystemOperationType type, PlayerOperationReason reason) = 0; 44 }; 45 46 class IPlayerEngine { 47 public: 48 virtual ~IPlayerEngine() = default; 49 50 virtual int32_t SetSource(const std::string &url) = 0; 51 virtual int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) = 0; 52 virtual int32_t SetObs(const std::weak_ptr<IPlayerEngineObs> &obs) = 0; AddSubSource(const std::string & url)53 virtual int32_t AddSubSource(const std::string &url) 54 { 55 (void)url; 56 return 0; 57 } 58 virtual int32_t Play() = 0; Prepare()59 virtual int32_t Prepare() 60 { 61 return 0; 62 } SetRenderFirstFrame(bool display)63 virtual int32_t SetRenderFirstFrame(bool display) 64 { 65 (void)display; 66 return 0; 67 } SetPlayRange(int64_t start,int64_t end)68 virtual int32_t SetPlayRange(int64_t start, int64_t end) 69 { 70 (void)start; 71 (void)end; 72 return 0; 73 } SetPlayRangeWithMode(int64_t start,int64_t end,PlayerSeekMode mode)74 virtual int32_t SetPlayRangeWithMode(int64_t start, int64_t end, PlayerSeekMode mode) 75 { 76 (void)start; 77 (void)end; 78 (void)mode; 79 return 0; 80 } SetIsCalledBySystemApp(bool isCalledBySystemApp)81 virtual int32_t SetIsCalledBySystemApp(bool isCalledBySystemApp) 82 { 83 (void)isCalledBySystemApp; 84 return 0; 85 } 86 virtual int32_t PrepareAsync() = 0; 87 virtual int32_t Pause(bool isSystemOperation) = 0; 88 virtual int32_t Stop() = 0; 89 virtual int32_t Reset() = 0; 90 virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0; 91 virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0; 92 virtual int32_t GetCurrentTime(int32_t ¤tTime) = 0; 93 virtual int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack) = 0; 94 virtual int32_t GetPlaybackInfo(Format &playbackInfo) = 0; 95 virtual int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0; GetSubtitleTrackInfo(std::vector<Format> & subtitleTrack)96 virtual int32_t GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack) 97 { 98 (void)subtitleTrack; 99 return 0; 100 } 101 virtual int32_t GetVideoWidth() = 0; 102 virtual int32_t GetVideoHeight() = 0; 103 virtual int32_t GetDuration(int32_t &duration) = 0; 104 virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0; 105 virtual int32_t GetPlaybackSpeed(PlaybackRateMode &mode) = 0; 106 virtual int32_t SetMediaSource(const std::shared_ptr<AVMediaSource> &mediaSource, AVPlayStrategy strategy) = 0; 107 virtual int32_t SetVideoSurface(sptr<Surface> surface) = 0; 108 virtual float GetMaxAmplitude() = 0; 109 SetDecryptConfig(const sptr<OHOS::DrmStandard::IMediaKeySessionService> & keySessionProxy,bool svp)110 virtual int32_t SetDecryptConfig(const sptr<OHOS::DrmStandard::IMediaKeySessionService> &keySessionProxy, 111 bool svp) 112 { 113 (void)keySessionProxy; 114 (void)svp; 115 return 0; 116 } 117 118 virtual int32_t SetLooping(bool loop) = 0; 119 virtual int32_t SetParameter(const Format ¶m) = 0; SelectBitRate(uint32_t bitRate)120 virtual int32_t SelectBitRate(uint32_t bitRate) 121 { 122 (void)bitRate; 123 return 0; 124 } SetVideoScaleType(Plugins::VideoScaleType videoScaleType)125 virtual int32_t SetVideoScaleType(Plugins::VideoScaleType videoScaleType) 126 { 127 (void)videoScaleType; 128 return 0; 129 } SetAudioRendererInfo(const int32_t contentType,const int32_t streamUsage,const int32_t rendererFlag)130 virtual int32_t SetAudioRendererInfo(const int32_t contentType, const int32_t streamUsage, 131 const int32_t rendererFlag) 132 { 133 (void)contentType; 134 (void)streamUsage; 135 (void)rendererFlag; 136 return 0; 137 } SetAudioInterruptMode(const int32_t interruptMode)138 virtual int32_t SetAudioInterruptMode(const int32_t interruptMode) 139 { 140 (void)interruptMode; 141 return 0; 142 } 143 144 virtual int32_t SelectTrack(int32_t index, PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SMOOTH) 145 { 146 (void)index; 147 (void)mode; 148 return 0; 149 } DeselectTrack(int32_t index)150 virtual int32_t DeselectTrack(int32_t index) 151 { 152 (void)index; 153 return 0; 154 } GetCurrentTrack(int32_t trackType,int32_t & index)155 virtual int32_t GetCurrentTrack(int32_t trackType, int32_t &index) 156 { 157 (void)trackType; 158 (void)index; 159 return 0; 160 } SetAudioEffectMode(const int32_t effectMode)161 virtual int32_t SetAudioEffectMode(const int32_t effectMode) 162 { 163 (void)effectMode; 164 return 0; 165 } GetAudioEffectMode(int32_t & effectMode)166 virtual int32_t GetAudioEffectMode(int32_t &effectMode) 167 { 168 (void)effectMode; 169 return 0; 170 } GetHEBCMode()171 virtual int32_t GetHEBCMode() 172 { 173 return 0; 174 } HandleCodecBuffers(bool enable)175 virtual int32_t HandleCodecBuffers(bool enable) 176 { 177 (void)enable; 178 return 0; 179 } SeekToCurrentTime(int32_t mSeconds,PlayerSeekMode mode)180 virtual int32_t SeekToCurrentTime(int32_t mSeconds, PlayerSeekMode mode) 181 { 182 (void)mSeconds; 183 (void)mode; 184 return 0; 185 } SetInterruptState(bool isInterruptNeeded)186 virtual void SetInterruptState(bool isInterruptNeeded) 187 { 188 (void)isInterruptNeeded; 189 } OnDumpInfo(int32_t fd)190 virtual void OnDumpInfo(int32_t fd) 191 { 192 (void)fd; 193 } SetInstancdId(uint64_t instanceId)194 virtual void SetInstancdId(uint64_t instanceId) 195 { 196 (void)instanceId; 197 } SetApiVersion(int32_t apiVersion)198 virtual void SetApiVersion(int32_t apiVersion) 199 { 200 (void)apiVersion; 201 } 202 GetPlayRangeStartTime()203 virtual int64_t GetPlayRangeStartTime() 204 { 205 return 0; 206 } 207 GetPlayRangeEndTime()208 virtual int64_t GetPlayRangeEndTime() 209 { 210 return 0; 211 } 212 GetPlayRangeSeekMode()213 virtual int32_t GetPlayRangeSeekMode() 214 { 215 return 0; 216 } 217 PauseDemuxer()218 virtual int32_t PauseDemuxer() 219 { 220 return 0; 221 } ResumeDemuxer()222 virtual int32_t ResumeDemuxer() 223 { 224 return 0; 225 } SetMediaMuted(OHOS::Media::MediaType mediaType,bool isMuted)226 virtual int32_t SetMediaMuted(OHOS::Media::MediaType mediaType, bool isMuted) 227 { 228 return 0; 229 } 230 SetPlaybackStrategy(AVPlayStrategy playbackStrategy)231 virtual int32_t SetPlaybackStrategy(AVPlayStrategy playbackStrategy) 232 { 233 return 0; 234 } SeekContinous(int32_t mSeconds,int64_t seekContinousBatchNo)235 virtual int32_t SeekContinous(int32_t mSeconds, int64_t seekContinousBatchNo) 236 { 237 (void)mSeconds; 238 (void)seekContinousBatchNo; 239 return 0; 240 } ExitSeekContinous(bool align,int64_t seekContinousBatchNo)241 virtual int32_t ExitSeekContinous(bool align, int64_t seekContinousBatchNo) 242 { 243 (void)align; 244 (void)seekContinousBatchNo; 245 return 0; 246 } 247 SetMaxAmplitudeCbStatus(bool status)248 virtual int32_t SetMaxAmplitudeCbStatus(bool status) 249 { 250 return 0; 251 } 252 HandleEosPlay()253 virtual int32_t HandleEosPlay() 254 { 255 return 0; 256 } 257 IsSeekContinuousSupported(bool & IsSeekContinuousSupported)258 virtual int32_t IsSeekContinuousSupported(bool &IsSeekContinuousSupported) 259 { 260 (void)IsSeekContinuousSupported; 261 return 0; 262 } 263 SetPerfRecEnabled(bool isPerfRecEnabled)264 virtual void SetPerfRecEnabled(bool isPerfRecEnabled) 265 { 266 (void)isPerfRecEnabled; 267 } 268 }; 269 } // namespace Media 270 } // namespace OHOS 271 #endif // I_PLAYER_ENGINE_H 272