• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef I_PLAYER_SERVICE_H
17 #define I_PLAYER_SERVICE_H
18 
19 #include "player.h"
20 #include "refbase.h"
21 
22 namespace OHOS {
23 namespace Media {
24 class IPlayerService {
25 public:
26     virtual ~IPlayerService() = default;
27 
28     /**
29      * @brief Sets the playback source for the player. The corresponding source can be local file url.
30      *
31      * @param url Indicates the playback source.
32      * @return Returns {@link MSERR_OK} if the url is set successfully; returns an error code defined
33      * in {@link media_errors.h} otherwise.
34      * @since 1.0
35      * @version 1.0
36      */
37     virtual int32_t SetSource(const std::string &url) = 0;
38     /**
39      * @brief Sets the playback media data source for the player.
40      *
41      * @param dataSrc Indicates the media data source. in {@link media_data_source.h}
42      * @return Returns {@link MSERR_OK} if the dataSrc is set successfully; returns an error code defined
43      * in {@link media_errors.h} otherwise.
44      * @since 1.0
45      * @version 1.0
46      */
47     virtual int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) = 0;
48     /**
49      * @brief Sets the playback media file descriptor source for the player.
50      *
51      * @param fd Indicates the file descriptor of media source.
52      * @param offset Indicates the offset of media source in file descriptor.
53      * @param size Indicates the size of media source.
54      * @return Returns {@link MSERR_OK} if the fd source is set successfully; returns an error code defined
55      * in {@link media_errors.h} otherwise.
56      * @since 1.0
57      * @version 1.0
58      */
59     virtual int32_t SetSource(int32_t fd, int64_t offset, int64_t size) = 0;
60     /**
61      * @brief Add a subtitle source for the player. The corresponding source can be local file url.
62      *
63      * @param url Indicates the subtitle source.
64      * @return Returns {@link MSERR_OK} if the url is set successfully; returns an error code defined
65      * in {@link media_errors.h} otherwise.
66      * @since 1.0
67      * @version 1.0
68      */
69     virtual int32_t AddSubSource(const std::string &url) = 0;
70     /**
71      * @brief Add a playback subtitle file descriptor source for the player.
72      *
73      * @param fd Indicates the file descriptor of subtitle source.
74      * @param offset Indicates the offset of subtitle source in file descriptor.
75      * @param size Indicates the size of subtitle source.
76      * @return Returns {@link MSERR_OK} if the fd source is set successfully; returns an error code defined
77      * in {@link media_errors.h} otherwise.
78      * @since 1.0
79      * @version 1.0
80      */
81     virtual int32_t AddSubSource(int32_t fd, int64_t offset, int64_t size) = 0;
82     /**
83      * @brief Start playback.
84      *
85      * This function must be called after {@link Prepare}. If the player state is <b>Prepared</b>,
86      * this function is called to start playback.
87      *
88      * @return Returns {@link MSERR_OK} if the playback is started; otherwise returns an error code defined
89      * in {@link media_errors.h} otherwise.
90      * @since 1.0
91      * @version 1.0
92      */
93     virtual int32_t Play() = 0;
94 
95     /**
96      * @brief Prepares the playback environment and buffers media data asynchronous.
97      *
98      * This function must be called after {@link SetSource}.
99      *
100      * @return Returns {@link MSERR_OK} if {@link Prepare} is successfully added to the task queue;
101      * returns an error code defined in {@link media_errors.h} otherwise.
102      * @since 1.0
103      * @version 1.0
104      */
105     virtual int32_t Prepare() = 0;
106 
107     /**
108      * @brief Enables render video first frame of the media playback.
109      *
110      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
111      * in {@link media_errors.h} otherwise.
112      * @since 1.0
113      * @version 1.0
114      */
SetRenderFirstFrame(bool display)115     virtual int32_t SetRenderFirstFrame(bool display)
116     {
117         (void)display;
118         return 0;
119     }
120 
121     /**
122      * @brief Specify the start and end time to play
123      * This function must be called after {@link SetSource}.
124      * This function is called to set start and end time
125      *
126      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
127      * in {@link media_errors.h} otherwise.
128      * @since 1.0
129      * @version 1.0
130      */
SetPlayRange(int64_t start,int64_t end)131     virtual int32_t SetPlayRange(int64_t start, int64_t end)
132     {
133         (void)start;
134         (void)end;
135         return 0;
136     }
137 
138     /**
139      * @brief Set playback start position and end position.
140      * Use the specified seek mode to jump to the playback start position,
141      * currently support SEEK_PREVIOUS_SYNC and SEEK_CLOSEST, other values are invalid,
142      * This function must be called after {@link SetSource}.
143      *
144      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
145      * in {@link media_errors.h} otherwise.
146      * @since 1.0
147      * @version 1.0
148      */
SetPlayRangeWithMode(int64_t start,int64_t end,PlayerSeekMode mode)149     virtual int32_t SetPlayRangeWithMode(int64_t start, int64_t end, PlayerSeekMode mode)
150     {
151         (void)start;
152         (void)end;
153         (void)mode;
154         return 0;
155     }
156 
157     /**
158      * @brief Prepares the playback environment and buffers media data asynchronous.
159      *
160      * This function must be called after {@link SetSource}.
161      *
162      * @return Returns {@link MSERR_OK} if {@link PrepareAsync} is successfully added to the task queue;
163      * returns an error code defined in {@link media_errors.h} otherwise.
164      * @since 1.0
165      * @version 1.0
166      */
167     virtual int32_t PrepareAsync() = 0;
168 
169     /**
170      * @brief Pauses playback.
171      *
172      * @return Returns {@link MSERR_OK} if {@link Pause} is successfully added to the task queue;
173      * returns an error code defined in {@link media_errors.h} otherwise.
174      * @since 1.0
175      * @version 1.0
176      */
177     virtual int32_t Pause() = 0;
178 
179     /**
180      * @brief Stop playback.
181      *
182      * @return Returns {@link MSERR_OK} if {@link Stop} is successfully added to the task queue;
183      * returns an error code defined in {@link media_errors.h} otherwise.
184      * @since 1.0
185      * @version 1.0
186      */
187     virtual int32_t Stop() = 0;
188 
189     /**
190      * @brief Restores the player to the initial state.
191      *
192      * After the function is called, add a playback source by calling {@link SetSource},
193      * call {@link Play} to start playback again after {@link Prepare} is called.
194      *
195      * @return Returns {@link MSERR_OK} if {@link Reset} is successfully added to the task queue;
196      * returns an error code defined in {@link media_errors.h} otherwise.
197      * @since 1.0
198      * @version 1.0
199      */
200     virtual int32_t Reset() = 0;
201 
202     /**
203      * @brief Releases player resources async
204      *
205      * @return Returns {@link MSERR_OK} if {@link Release} is successfully added to the task queue;
206      * returns an error code defined in {@link media_errors.h} otherwise.
207      * @since 1.0
208      * @version 1.0
209      */
210     virtual int32_t Release() = 0;
211 
212     /**
213      * @brief Releases player resources sync
214      *
215      * @return Returns {@link MSERR_OK} if the playback is released; returns an error code defined
216      * in {@link media_errors.h} otherwise.
217      * @since 1.0
218      * @version 1.0
219      */
ReleaseSync()220     virtual int32_t ReleaseSync()
221     {
222         return ERR_OK;
223     }
224 
225     /**
226      * @brief Sets the volume of the player.
227      *
228      * This function can be used during playback or pause. The value <b>0</b> indicates no sound,
229      * and <b>1</b> indicates the original volume. If no audio device is started or no audio
230      * stream exists, the value <b>-1</b> is returned.
231      *
232      * @param leftVolume Indicates the target volume of the left audio channel to set,
233      *        ranging from 0 to 1. each step is 0.01.
234      * @param rightVolume Indicates the target volume of the right audio channel to set,
235      *        ranging from 0 to 1. each step is 0.01.
236      * @return Returns {@link MSERR_OK} if the volume is set; returns an error code defined
237      * in {@link media_errors.h} otherwise.
238      * @since 1.0
239      * @version 1.0
240      */
241     virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0;
242 
243     virtual int32_t SetVolumeMode(int32_t mode) = 0;
244 
245     /**
246      * @brief Changes the playback position.
247      *
248      * This function can be used during play or pause.
249      *
250      * @param mSeconds Indicates the target playback position, accurate to second.
251      * @param mode Indicates the player seek mode. For details, see {@link PlayerSeekMode}.
252      * @return Returns {@link MSERR_OK} if the seek is done; returns an error code defined
253      * in {@link media_errors.h} otherwise.
254      * @since 1.0
255      * @version 1.0
256     */
257     virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0;
258 
259     /**
260      * @brief Obtains the playback position, accurate to millisecond.
261      *
262      * @param currentTime Indicates the playback position.
263      * @return Returns {@link MSERR_OK} if the current position is get; returns an error code defined
264      * in {@link media_errors.h} otherwise.
265      * @since 1.0
266      * @version 1.0
267      */
268     virtual int32_t GetCurrentTime(int32_t &currentTime) = 0;
269 
270     /**
271      * @brief Obtains the playback position, accurate to millisecond.
272      *
273      * @param playbackPosition Indicates the playback position.
274      * @return Returns {@link MSERR_OK} if the current position is get; returns an error code defined
275      * in {@link media_errors.h} otherwise.
276      * @since 1.0
277      * @version 1.0
278      */
279     virtual int32_t GetPlaybackPosition(int32_t &playbackPosition) = 0;
280 
281     /**
282      * @brief Obtains the video track info, contains mimeType, bitRate, width, height, frameRata.
283      *
284      * @param video track info vec.
285      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
286      * in {@link media_errors.h} otherwise.
287      * @since 1.0
288      * @version 1.0
289      */
290     virtual int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack) = 0;
291 
292     /**
293      * @brief Obtains playbackInfo, contains server_ip_address, average_download_rate,
294      * download_rate, is_downloading, buffer_duration.
295      *
296      * @param playbackInfo.
297      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
298      * in {@link media_errors.h} otherwise.
299      * @since 1.0
300      * @version 1.0
301      */
302     virtual int32_t GetPlaybackInfo(Format &playbackInfo) = 0;
303 
304     /**
305      * @brief Obtains the audio track info, contains mimeType, bitRate, sampleRate, channels, language.
306      *
307      * @param audio track info vec.
308      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
309      * in {@link media_errors.h} otherwise.
310      * @since 1.0
311      * @version 1.0
312      */
313     virtual int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0;
314 
315     /**
316      * @brief get the video width.
317      *
318      * @return Returns width if success; else returns 0
319      * @since 1.0
320      * @version 1.0
321      */
322     virtual int32_t GetVideoWidth() = 0;
323 
324     /**
325      * @brief get the video height.
326      *
327      * @return Returns height if success; else returns 0
328      * @since 1.0
329      * @version 1.0
330      */
331     virtual int32_t GetVideoHeight() = 0;
332 
333     /**
334      * @brief Obtains the total duration of media files, accurate to milliseconds.
335      *
336      * @param duration Indicates the total duration of media files.
337      * @return Returns {@link MSERR_OK} if the current duration is get; returns an error code defined
338      * in {@link media_errors.h} otherwise.
339      * @since 1.0
340      * @version 1.0
341      */
342     virtual int32_t GetDuration(int32_t &duration) = 0;
343 
344     /**
345      * @brief set the player playback rate
346      *
347      * @param mode the rate mode {@link PlaybackRateMode} which can set.
348      * @return Returns {@link MSERR_OK} if the playback rate is set successfully; returns an error code defined
349      * in {@link media_errors.h} otherwise.
350      * @since 1.0
351      * @version 1.0
352      */
353     virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0;
354 
355     virtual int32_t SetMediaSource(const std::shared_ptr<AVMediaSource> &mediaSource, AVPlayStrategy strategy) = 0;
356     /**
357      * @brief set the bit rate use for hls player
358      *
359      * @param bitRate the bit rate.
360      * @return Returns {@link MSERR_OK} if the bit rate is set successfully; returns an error code defined
361      * in {@link media_errors.h} otherwise.
362      * @since 1.0
363      * @version 1.0
364      */
365     virtual int32_t SelectBitRate(uint32_t bitRate) = 0;
366 
367     /**
368      * @brief get the current player playback rate
369      *
370      * @param mode the rate mode {@link PlaybackRateMode} which can get.
371      * @return Returns {@link MSERR_OK} if the current player playback rate is get; returns an error code defined
372      * in {@link media_errors.h} otherwise.
373      * @since 1.0
374      * @version 1.0
375      */
376     virtual int32_t GetPlaybackSpeed(PlaybackRateMode &mode) = 0;
377 
378     /**
379      * @brief add for drm, set decrypt module
380      *
381      * @param keySessionProxy is the sptr will be setted to playerserver.
382      * @param svp bool.
383      * @return Returns {@link MSERR_OK} if set successfully; returns an error code defined
384      * in {@link media_errors.h} otherwise.
385      * @since
386      * @version
387      */
388     virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySessionProxy,
389         bool svp) = 0;
390 
391 #ifdef SUPPORT_VIDEO
392     /**
393      * @brief Method to set the surface.
394      *
395      * @param surface pointer of the surface.
396      * @return Returns {@link MSERR_OK} if the surface is set; returns an error code defined
397      * in {@link media_errors.h} otherwise.
398      * @since 1.0
399      * @version 1.0
400      */
401     virtual int32_t SetVideoSurface(sptr<Surface> surface) = 0;
402 #endif
403 
404     /**
405      * @brief Checks whether the player is playing.
406      *
407      * @return Returns true if the playback is playing; false otherwise.
408      * @since 1.0
409      * @version 1.0
410      */
411     virtual bool IsPlaying() = 0;
412 
413     /**
414      * @brief Returns the value whether single looping is enabled or not .
415      *
416      * @return Returns true if the playback is single looping; false otherwise.
417      * @since 1.0
418      * @version 1.0
419      */
420     virtual bool IsLooping() = 0;
421 
422     /**
423      * @brief Enables single looping of the media playback.
424      *
425      * @return Returns {@link MSERR_OK} if the single looping is set; returns an error code defined
426      * in {@link media_errors.h} otherwise.
427      * @since 1.0
428      * @version 1.0
429      */
430     virtual int32_t SetLooping(bool loop) = 0;
431 
432     /**
433      * @brief Enables setting the renderer descriptor for the current media
434      *
435      * @return Returns {@link MSERR_OK} if the renderer descriptor is set; returns an error code defined
436      * in {@link media_errors.h} otherwise.
437      * @since 1.0
438      * @version 1.0
439      */
440     virtual int32_t SetParameter(const Format &param) = 0;
441 
442     /**
443      * @brief Method to set player callback.
444      *
445      * @param callback object pointer.
446      * @return Returns {@link MSERR_OK} if the playercallback is set; returns an error code defined
447      * in {@link media_errors.h} otherwise.
448      * @since 1.0
449      * @version 1.0
450      */
451     virtual int32_t SetPlayerCallback(const std::shared_ptr<PlayerCallback> &callback) = 0;
452 
453     /**
454      * @brief Select audio or subtitle track.
455      * By default, the first audio stream with data is played, and the subtitle track is not played.
456      * After the settings take effect, the original track will become invalid.
457      * Please set it in the prepared/playing/paused/completed state.
458      *
459      * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}.
460      * @return Returns {@link MSERR_OK} if selected successfully; returns an error code defined
461      * in {@link media_errors.h} otherwise.
462      * @since 1.0
463      * @version 1.0
464     */
465     virtual int32_t SelectTrack(int32_t index, PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SMOOTH) = 0;
466 
467     /**
468      * @brief Deselect the current audio or subtitle track.
469      * After audio is deselected, the default track will be played, and after subtitles are deselected,
470      * they will not be played. Please set it in the prepared/playing/paused/completed state.
471      *
472      * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}.
473      * @return Returns {@link MSERR_OK} if selected successfully; returns an error code defined
474      * in {@link media_errors.h} otherwise.
475      * @since 1.0
476      * @version 1.0
477     */
478     virtual int32_t DeselectTrack(int32_t index) = 0;
479 
480     /**
481      * @brief Obtain the currently effective track index.
482      *
483      * @param trackType Media type.
484      * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}.
485      * @return Returns {@link MSERR_OK} if the track index is get; returns an error code defined
486      * in {@link media_errors.h} otherwise.
487      * @since 1.0
488      * @version 1.0
489      */
490     virtual int32_t GetCurrentTrack(int32_t trackType, int32_t &index) = 0;
491 
492     /**
493      * @brief Obtains the subtitle track info, contains mimeType, type, language.
494      *
495      * @param subtitle track info vec.
496      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
497      * in {@link media_errors.h} otherwise.
498      * @since 1.0
499      * @version 1.0
500      */
501     virtual int32_t GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack) = 0;
502 
503     /**
504      * @brief set the playback strategy
505      * the playback strategy includes five fileds:
506      * preferredWidth: Preferred width, which is of the int type, for example, 1080.
507      * preferredHeight: Preferred height, which is of the int type, for example, 1920.
508      * preferredBufferDuration: Preferred buffer duration, in seconds. The value ranges from 1 to 20.
509      * preferredHdr: Whether HDR is preferred. The value true means that HDR is preferred, and false means the opposite.
510      * mutedMediaType: The mediaType to be muted before play, which is of the MediaType type,
511      * for example, MediaType::MEDIA_TYPE_AUD.
512      * @param playbackStrategy the playback strategy.
513      * @return Returns {@link MSERR_OK} if the playback strategy is set successfully; returns an error code defined
514      * in {@link media_errors.h} otherwise.
515      * @since 1.0
516      * @version 1.0
517      */
SetPlaybackStrategy(AVPlayStrategy playbackStrategy)518     virtual int32_t SetPlaybackStrategy(AVPlayStrategy playbackStrategy)
519     {
520         (void)playbackStrategy;
521         return 0;
522     }
523 
SetMediaMuted(MediaType mediaType,bool isMuted)524     virtual int32_t SetMediaMuted(MediaType mediaType, bool isMuted)
525     {
526         (void)mediaType;
527         (void)isMuted;
528         return 0;
529     }
530 
531     /**
532      * @brief Enable or disable super resolution.
533      *
534      * @return Returns {@link MSERR_OK} if super resolution is set; returns an error code defined
535      * in {@link media_errors.h} otherwise.
536      * @since 1.0
537      * @version 1.0
538      */
SetSuperResolution(bool enabled)539     virtual int32_t SetSuperResolution(bool enabled)
540     {
541         (void)enabled;
542         return 0;
543     }
544 
545     /**
546      * @brief Set video window size for super-resolution.
547      *
548      * @return Returns {@link MSERR_OK} if video window size is set; returns an error code defined
549      * in {@link media_errors.h} otherwise.
550      * @since 1.0
551      * @version 1.0
552      */
SetVideoWindowSize(int32_t width,int32_t height)553     virtual int32_t SetVideoWindowSize(int32_t width, int32_t height)
554     {
555         (void)width;
556         (void)height;
557         return 0;
558     }
559 
560     /**
561      * @brief Set get max ampliutude callback status.
562      *
563      * @param status callback status.
564      * @return Returns {@link MSERR_OK} if the callback status is set; returns an error code defined
565      * in {@link media_errors.h} otherwise.
566      * @since 1.0
567      * @version 1.0
568      */
SetMaxAmplitudeCbStatus(bool status)569     virtual int32_t SetMaxAmplitudeCbStatus(bool status)
570     {
571         (void)status;
572         return 0;
573     }
574 
575     /**
576      * @brief set get device change callback status.
577      *
578      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
579      * in {@link media_errors.h} otherwise.
580      * @since 1.0
581      * @version 1.0
582      */
SetDeviceChangeCbStatus(bool status)583     virtual int32_t SetDeviceChangeCbStatus(bool status)
584     {
585         (void)status;
586         return 0;
587     }
588     /**
589      * @brief Obtain the api version of application.
590      *
591      * @return Returns {@link MSERR_OK} if the current api version is get; returns an error code defined
592      * in {@link media_errors.h} otherwise.
593      * @since 1.0
594      * @version 1.0
595      */
GetApiVersion(int32_t & apiVersion)596     virtual int32_t GetApiVersion(int32_t &apiVersion)
597     {
598         (void)apiVersion;
599         return 0;
600     }
601 
602     /**
603      * @brief Checks whether the player supports SeekContinuous.
604      *
605      * @return Returns true if the player supports SeekContinuous; false otherwise.
606      * @since 1.0
607      * @version 1.0
608      */
609     virtual bool IsSeekContinuousSupported() = 0;
610 
611     /**
612      * @brief Set get sei message callback status.
613      *
614      * @param status callback status.
615      * @return Returns {@link MSERR_OK} if the callback status is set; returns an error code defined
616      * in {@link media_errors.h} otherwise.
617      * @since 1.0
618      * @version 1.0
619      */
SetSeiMessageCbStatus(bool status,const std::vector<int32_t> & payloadTypes)620     virtual int32_t SetSeiMessageCbStatus(bool status, const std::vector<int32_t> &payloadTypes)
621     {
622         (void)status;
623         (void)payloadTypes;
624         return 0;
625     }
626 };
627 } // namespace Media
628 } // namespace OHOS
629 #endif // I_PLAYER_SERVICE_H
630