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