• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "common/event.h"
25 #include "meta/video_types.h"
26 #include "nocopyable.h"
27 
28 #ifdef SUPPORT_AVPLAYER_DRM
29 #include "imedia_key_session_service.h"
30 #endif
31 
32 namespace OHOS {
33 class Surface;
34 
35 namespace Media {
36 class IPlayerEngineObs : public std::enable_shared_from_this<IPlayerEngineObs> {
37 public:
38     virtual ~IPlayerEngineObs() = default;
39     virtual void OnError(PlayerErrorType errorType, int32_t errorCode) = 0;
OnErrorMessage(int32_t errorCode,const std::string & errorMsg)40     virtual void OnErrorMessage(int32_t errorCode, const std::string &errorMsg)
41     {
42         (void)errorCode;
43         (void)errorMsg;
44     }
45     virtual void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) = 0;
46     virtual void OnSystemOperation(PlayerOnSystemOperationType type, PlayerOperationReason reason) = 0;
OnDfxInfo(const DfxEvent & event)47     virtual void OnDfxInfo(const DfxEvent &event)
48     {
49         (void)event;
50     }
51 };
52 
53 class IPlayerEngine {
54 public:
55     virtual ~IPlayerEngine() = default;
56 
57     virtual int32_t SetSource(const std::string &url) = 0;
58     virtual int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) = 0;
59     virtual int32_t SetObs(const std::weak_ptr<IPlayerEngineObs> &obs) = 0;
AddSubSource(const std::string & url)60     virtual int32_t AddSubSource(const std::string &url)
61     {
62         (void)url;
63         return 0;
64     }
65     virtual int32_t Play() = 0;
Prepare()66     virtual int32_t Prepare()
67     {
68         return 0;
69     }
SetRenderFirstFrame(bool display)70     virtual int32_t SetRenderFirstFrame(bool display)
71     {
72         (void)display;
73         return 0;
74     }
SetPlayRange(int64_t start,int64_t end)75     virtual int32_t SetPlayRange(int64_t start, int64_t end)
76     {
77         (void)start;
78         (void)end;
79         return 0;
80     }
SetPlayRangeWithMode(int64_t start,int64_t end,PlayerSeekMode mode)81     virtual int32_t SetPlayRangeWithMode(int64_t start, int64_t end, PlayerSeekMode mode)
82     {
83         (void)start;
84         (void)end;
85         (void)mode;
86         return 0;
87     }
SetIsCalledBySystemApp(bool isCalledBySystemApp)88     virtual int32_t SetIsCalledBySystemApp(bool isCalledBySystemApp)
89     {
90         (void)isCalledBySystemApp;
91         return 0;
92     }
93     virtual int32_t PrepareAsync() = 0;
94     virtual int32_t Pause(bool isSystemOperation) = 0;
95     virtual int32_t Stop() = 0;
96     virtual int32_t Reset() = 0;
97     virtual int32_t Freeze(bool &isNoNeedToFreeze) = 0;
98     virtual int32_t UnFreeze() = 0;
PauseSourceDownload()99     virtual int32_t PauseSourceDownload()
100     {
101         return 0;
102     }
ResumeSourceDownload()103     virtual int32_t ResumeSourceDownload()
104     {
105         return 0;
106     }
107     virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0;
108     virtual int32_t SetVolumeMode(int32_t mode) = 0;
109     virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0;
110     virtual int32_t GetCurrentTime(int32_t &currentTime) = 0;
111     virtual int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack) = 0;
112     virtual int32_t GetPlaybackInfo(Format &playbackInfo) = 0;
113     virtual int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0;
GetSubtitleTrackInfo(std::vector<Format> & subtitleTrack)114     virtual int32_t GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack)
115     {
116         (void)subtitleTrack;
117         return 0;
118     }
119     virtual int32_t GetVideoWidth() = 0;
120     virtual int32_t GetVideoHeight() = 0;
121     virtual int32_t GetDuration(int32_t &duration) = 0;
122     virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0;
123     virtual int32_t SetPlaybackRate(float rate) = 0;
124     virtual int32_t GetPlaybackSpeed(PlaybackRateMode &mode) = 0;
125     virtual int32_t SetMediaSource(const std::shared_ptr<AVMediaSource> &mediaSource, AVPlayStrategy strategy) = 0;
126     virtual int32_t SetVideoSurface(sptr<Surface> surface) = 0;
127     virtual float GetMaxAmplitude() = 0;
128 
SetDecryptConfig(const sptr<OHOS::DrmStandard::IMediaKeySessionService> & keySessionProxy,bool svp)129     virtual int32_t SetDecryptConfig(const sptr<OHOS::DrmStandard::IMediaKeySessionService> &keySessionProxy,
130         bool svp)
131     {
132         (void)keySessionProxy;
133         (void)svp;
134         return 0;
135     }
136 
137     virtual int32_t SetLooping(bool loop) = 0;
138     virtual int32_t SetParameter(const Format &param) = 0;
SelectBitRate(uint32_t bitRate,bool isAutoSelect)139     virtual int32_t SelectBitRate(uint32_t bitRate, bool isAutoSelect)
140     {
141         (void)bitRate;
142         (void)isAutoSelect;
143         return 0;
144     }
SetVideoScaleType(Plugins::VideoScaleType videoScaleType)145     virtual int32_t SetVideoScaleType(Plugins::VideoScaleType videoScaleType)
146     {
147         (void)videoScaleType;
148         return 0;
149     }
SetAudioRendererInfo(const int32_t contentType,const int32_t streamUsage,const int32_t rendererFlag,const int32_t volumeMode)150     virtual int32_t SetAudioRendererInfo(const int32_t contentType, const int32_t streamUsage,
151         const int32_t rendererFlag, const int32_t volumeMode)
152     {
153         (void)contentType;
154         (void)streamUsage;
155         (void)rendererFlag;
156         (void)volumeMode;
157         return 0;
158     }
SetAudioInterruptMode(const int32_t interruptMode)159     virtual int32_t SetAudioInterruptMode(const int32_t interruptMode)
160     {
161         (void)interruptMode;
162         return 0;
163     }
164 
165     virtual int32_t SelectTrack(int32_t index, PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SMOOTH)
166     {
167         (void)index;
168         (void)mode;
169         return 0;
170     }
DeselectTrack(int32_t index)171     virtual int32_t DeselectTrack(int32_t index)
172     {
173         (void)index;
174         return 0;
175     }
GetCurrentTrack(int32_t trackType,int32_t & index)176     virtual int32_t GetCurrentTrack(int32_t trackType, int32_t &index)
177     {
178         (void)trackType;
179         (void)index;
180         return 0;
181     }
SetAudioEffectMode(const int32_t effectMode)182     virtual int32_t SetAudioEffectMode(const int32_t effectMode)
183     {
184         (void)effectMode;
185         return 0;
186     }
GetAudioEffectMode(int32_t & effectMode)187     virtual int32_t GetAudioEffectMode(int32_t &effectMode)
188     {
189         (void)effectMode;
190         return 0;
191     }
GetHEBCMode()192     virtual int32_t GetHEBCMode()
193     {
194         return 0;
195     }
HandleCodecBuffers(bool enable)196     virtual int32_t HandleCodecBuffers(bool enable)
197     {
198         (void)enable;
199         return 0;
200     }
SeekToCurrentTime(int32_t mSeconds,PlayerSeekMode mode)201     virtual int32_t SeekToCurrentTime(int32_t mSeconds, PlayerSeekMode mode)
202     {
203         (void)mSeconds;
204         (void)mode;
205         return 0;
206     }
SetInterruptState(bool isInterruptNeeded)207     virtual void SetInterruptState(bool isInterruptNeeded)
208     {
209         (void)isInterruptNeeded;
210     }
OnDumpInfo(int32_t fd)211     virtual void OnDumpInfo(int32_t fd)
212     {
213         (void)fd;
214     }
SetInstancdId(uint64_t instanceId)215     virtual void SetInstancdId(uint64_t instanceId)
216     {
217         (void)instanceId;
218     }
SetApiVersion(int32_t apiVersion)219     virtual void SetApiVersion(int32_t apiVersion)
220     {
221         (void)apiVersion;
222     }
223 
GetPlayRangeStartTime()224     virtual int64_t GetPlayRangeStartTime()
225     {
226         return 0;
227     }
228 
GetPlayRangeEndTime()229     virtual int64_t GetPlayRangeEndTime()
230     {
231         return 0;
232     }
233 
GetPlayRangeSeekMode()234     virtual int32_t GetPlayRangeSeekMode()
235     {
236         return 0;
237     }
238 
PauseDemuxer()239     virtual int32_t PauseDemuxer()
240     {
241         return 0;
242     }
ResumeDemuxer()243     virtual int32_t ResumeDemuxer()
244     {
245         return 0;
246     }
SetMediaMuted(OHOS::Media::MediaType mediaType,bool isMuted)247     virtual int32_t SetMediaMuted(OHOS::Media::MediaType mediaType, bool isMuted)
248     {
249         return 0;
250     }
251 
SetSuperResolution(bool enabled)252     virtual int32_t SetSuperResolution(bool enabled)
253     {
254         return 0;
255     }
256 
SetVideoWindowSize(int32_t width,int32_t height)257     virtual int32_t SetVideoWindowSize(int32_t width, int32_t height)
258     {
259         return 0;
260     }
261 
SetPlaybackStrategy(AVPlayStrategy playbackStrategy)262     virtual int32_t SetPlaybackStrategy(AVPlayStrategy playbackStrategy)
263     {
264         return 0;
265     }
SeekContinous(int32_t mSeconds,int64_t seekContinousBatchNo)266     virtual int32_t SeekContinous(int32_t mSeconds, int64_t seekContinousBatchNo)
267     {
268         (void)mSeconds;
269         (void)seekContinousBatchNo;
270         return 0;
271     }
ExitSeekContinous(bool align,int64_t seekContinousBatchNo)272     virtual int32_t ExitSeekContinous(bool align, int64_t seekContinousBatchNo)
273     {
274         (void)align;
275         (void)seekContinousBatchNo;
276         return 0;
277     }
278 
SetMaxAmplitudeCbStatus(bool status)279     virtual int32_t SetMaxAmplitudeCbStatus(bool status)
280     {
281         return 0;
282     }
283 
IsSeekContinuousSupported(bool & IsSeekContinuousSupported)284     virtual int32_t IsSeekContinuousSupported(bool &IsSeekContinuousSupported)
285     {
286         (void)IsSeekContinuousSupported;
287         return 0;
288     }
289 
GetPlaybackPosition(int32_t & playbackPosition)290     virtual int32_t GetPlaybackPosition(int32_t &playbackPosition)
291     {
292         (void)playbackPosition;
293         return 0;
294     }
295 
SetSeiMessageCbStatus(bool status,const std::vector<int32_t> & payloadTypes)296     virtual int32_t SetSeiMessageCbStatus(bool status, const std::vector<int32_t> &payloadTypes)
297     {
298         return 0;
299     }
300 
IsNeedChangePlaySpeed(PlaybackRateMode & mode,bool & isXSpeedPlay)301     virtual bool IsNeedChangePlaySpeed(PlaybackRateMode &mode, bool &isXSpeedPlay)
302     {
303         (void)mode;
304         (void)isXSpeedPlay;
305         return false;
306     }
307 
IsPauseForTooLong(int64_t pauseTime)308     virtual bool IsPauseForTooLong(int64_t pauseTime)
309     {
310         (void)pauseTime;
311         return false;
312     }
313 
DoRestartLiveLink()314     virtual void DoRestartLiveLink()
315     {
316     }
317 
SetPerfRecEnabled(bool isPerfRecEnabled)318     virtual void SetPerfRecEnabled(bool isPerfRecEnabled)
319     {
320         (void)isPerfRecEnabled;
321     }
322 
IsLivingMaxDelayTimeValid()323     virtual bool IsLivingMaxDelayTimeValid()
324     {
325         return false;
326     }
327 
IsFlvLive()328     virtual bool IsFlvLive()
329     {
330         return false;
331     }
332 
EnableReportMediaProgress(bool enable)333     virtual int32_t EnableReportMediaProgress(bool enable)
334     {
335         (void)enable;
336         return 0;
337     }
338 
SetStartFrameRateOptEnabled(bool enabled)339     virtual int32_t SetStartFrameRateOptEnabled(bool enabled)
340     {
341         (void)enabled;
342         return 0;
343     }
344 
SetReopenFd(int32_t fd)345     virtual int32_t SetReopenFd(int32_t fd)
346     {
347         (void)fd;
348         return 0;
349     }
350 
EnableCameraPostprocessing()351     virtual int32_t EnableCameraPostprocessing()
352     {
353         return 0;
354     }
355 
SetCameraPostprocessing(bool isOpen)356     virtual int32_t SetCameraPostprocessing(bool isOpen)
357     {
358         (void)isOpen;
359         return 0;
360     }
361 
ForceLoadVideo(bool)362     virtual int32_t ForceLoadVideo(bool /* enabled */)
363     {
364         return 0;
365     }
366 
NotifyMemoryExchange(bool)367     virtual int32_t NotifyMemoryExchange(bool /* status */)
368     {
369         return 0;
370     }
SetEosInLoopForFrozen(bool)371     virtual void SetEosInLoopForFrozen(bool /* status */)
372     {
373         return ;
374     }
375 };
376 } // namespace Media
377 } // namespace OHOS
378 #endif // I_PLAYER_ENGINE_H
379