1 /*
2  * Copyright (C) 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 #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     }
81     virtual int32_t PrepareAsync() = 0;
82     virtual int32_t Pause(bool isSystemOperation) = 0;
83     virtual int32_t Stop() = 0;
84     virtual int32_t Reset() = 0;
85     virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0;
86     virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0;
87     virtual int32_t GetCurrentTime(int32_t &currentTime) = 0;
88     virtual int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack) = 0;
89     virtual int32_t GetPlaybackInfo(Format &playbackInfo) = 0;
90     virtual int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0;
GetSubtitleTrackInfo(std::vector<Format> & subtitleTrack)91     virtual int32_t GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack)
92     {
93         (void)subtitleTrack;
94         return 0;
95     }
96     virtual int32_t GetVideoWidth() = 0;
97     virtual int32_t GetVideoHeight() = 0;
98     virtual int32_t GetDuration(int32_t &duration) = 0;
99     virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0;
100     virtual int32_t GetPlaybackSpeed(PlaybackRateMode &mode) = 0;
101     virtual int32_t SetMediaSource(const std::shared_ptr<AVMediaSource> &mediaSource, AVPlayStrategy strategy) = 0;
102     virtual int32_t SetVideoSurface(sptr<Surface> surface) = 0;
103     virtual float GetMaxAmplitude() = 0;
104 
SetDecryptConfig(const sptr<OHOS::DrmStandard::IMediaKeySessionService> & keySessionProxy,bool svp)105     virtual int32_t SetDecryptConfig(const sptr<OHOS::DrmStandard::IMediaKeySessionService> &keySessionProxy,
106         bool svp)
107     {
108         (void)keySessionProxy;
109         (void)svp;
110         return 0;
111     }
112 
113     virtual int32_t SetLooping(bool loop) = 0;
114     virtual int32_t SetParameter(const Format &param) = 0;
SelectBitRate(uint32_t bitRate)115     virtual int32_t SelectBitRate(uint32_t bitRate)
116     {
117         (void)bitRate;
118         return 0;
119     }
SetVideoScaleType(Plugins::VideoScaleType videoScaleType)120     virtual int32_t SetVideoScaleType(Plugins::VideoScaleType videoScaleType)
121     {
122         (void)videoScaleType;
123         return 0;
124     }
SetAudioRendererInfo(const int32_t contentType,const int32_t streamUsage,const int32_t rendererFlag)125     virtual int32_t SetAudioRendererInfo(const int32_t contentType, const int32_t streamUsage,
126         const int32_t rendererFlag)
127     {
128         (void)contentType;
129         (void)streamUsage;
130         (void)rendererFlag;
131         return 0;
132     }
SetAudioInterruptMode(const int32_t interruptMode)133     virtual int32_t SetAudioInterruptMode(const int32_t interruptMode)
134     {
135         (void)interruptMode;
136         return 0;
137     }
138 
139     virtual int32_t SelectTrack(int32_t index, PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SMOOTH)
140     {
141         (void)index;
142         (void)mode;
143         return 0;
144     }
DeselectTrack(int32_t index)145     virtual int32_t DeselectTrack(int32_t index)
146     {
147         (void)index;
148         return 0;
149     }
GetCurrentTrack(int32_t trackType,int32_t & index)150     virtual int32_t GetCurrentTrack(int32_t trackType, int32_t &index)
151     {
152         (void)trackType;
153         (void)index;
154         return 0;
155     }
SetAudioEffectMode(const int32_t effectMode)156     virtual int32_t SetAudioEffectMode(const int32_t effectMode)
157     {
158         (void)effectMode;
159         return 0;
160     }
GetAudioEffectMode(int32_t & effectMode)161     virtual int32_t GetAudioEffectMode(int32_t &effectMode)
162     {
163         (void)effectMode;
164         return 0;
165     }
GetHEBCMode()166     virtual int32_t GetHEBCMode()
167     {
168         return 0;
169     }
HandleCodecBuffers(bool enable)170     virtual int32_t HandleCodecBuffers(bool enable)
171     {
172         (void)enable;
173         return 0;
174     }
SeekToCurrentTime(int32_t mSeconds,PlayerSeekMode mode)175     virtual int32_t SeekToCurrentTime(int32_t mSeconds, PlayerSeekMode mode)
176     {
177         (void)mSeconds;
178         (void)mode;
179         return 0;
180     }
SetInterruptState(bool isInterruptNeeded)181     virtual void SetInterruptState(bool isInterruptNeeded)
182     {
183         (void)isInterruptNeeded;
184     }
OnDumpInfo(int32_t fd)185     virtual void OnDumpInfo(int32_t fd)
186     {
187         (void)fd;
188     }
SetInstancdId(uint64_t instanceId)189     virtual void SetInstancdId(uint64_t instanceId)
190     {
191         (void)instanceId;
192     }
193 
GetPlayRangeStartTime()194         virtual int64_t GetPlayRangeStartTime()
195     {
196         return 0;
197     }
198 
GetPlayRangeEndTime()199     virtual int64_t GetPlayRangeEndTime()
200     {
201         return 0;
202     }
203 
GetPlayRangeSeekMode()204     virtual int32_t GetPlayRangeSeekMode()
205     {
206         return 0;
207     }
208 
PauseDemuxer()209     virtual int32_t PauseDemuxer()
210     {
211         return 0;
212     }
ResumeDemuxer()213     virtual int32_t ResumeDemuxer()
214     {
215         return 0;
216     }
SetMediaMuted(OHOS::Media::MediaType mediaType,bool isMuted)217         virtual int32_t SetMediaMuted(OHOS::Media::MediaType mediaType, bool isMuted)
218     {
219         return 0;
220     }
221 
SetPlaybackStrategy(AVPlayStrategy playbackStrategy)222     virtual int32_t SetPlaybackStrategy(AVPlayStrategy playbackStrategy)
223     {
224         return 0;
225     }
SeekContinous(int32_t mSeconds,int64_t seekContinousBatchNo)226     virtual int32_t SeekContinous(int32_t mSeconds, int64_t seekContinousBatchNo)
227     {
228         (void)mSeconds;
229         (void)seekContinousBatchNo;
230         return 0;
231     }
ExitSeekContinous(bool align,int64_t seekContinousBatchNo)232     virtual int32_t ExitSeekContinous(bool align, int64_t seekContinousBatchNo)
233     {
234         (void)align;
235         (void)seekContinousBatchNo;
236         return 0;
237     }
238 
SetMaxAmplitudeCbStatus(bool status)239     virtual int32_t SetMaxAmplitudeCbStatus(bool status)
240     {
241         return 0;
242     }
243 
HandleEosPlay()244     virtual int32_t HandleEosPlay()
245     {
246         return 0;
247     }
248 
IsSeekContinuousSupported(bool & IsSeekContinuousSupported)249     virtual int32_t IsSeekContinuousSupported(bool &IsSeekContinuousSupported)
250     {
251         (void)IsSeekContinuousSupported;
252         return 0;
253     }
254 };
255 } // namespace Media
256 } // namespace OHOS
257 #endif // I_PLAYER_ENGINE_H
258