• 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 
16 #ifndef PLAYER_H
17 #define PLAYER_H
18 
19 #include <cstdint>
20 #include "media_core.h"
21 #ifndef SUPPORT_AUDIO_ONLY
22 #include "surface.h"
23 #endif
24 #include "meta/format.h"
25 #include "media_data_source.h"
26 #include "loading_request.h"
27 #include "media_source.h"
28 
29 namespace OHOS {
30 namespace DrmStandard {
31 class IMediaKeySessionService;
32 }
33 }
34 
35 namespace OHOS {
36 namespace Media {
37 struct AVPlayStrategy;
38 
39 namespace DrmConstant {
40 constexpr uint32_t DRM_MAX_M3U8_DRM_PSSH_LEN = 2048;
41 constexpr uint32_t DRM_MAX_M3U8_DRM_UUID_LEN = 16;
42 constexpr uint32_t DRM_MAX_DRM_INFO_COUNT = 200;
43 }
44 
45 namespace AVPlayStrategyConstant {
46 constexpr double BUFFER_DURATION_FOR_PLAYING_SECONDS = 2; // flv live set default BufferDurationForPlaying 2s
47 constexpr double START_QUICK_PLAY_THRESHOLD_SECONDS = 5; // flv live set default thresholdForAutoQuickPlay 5s
48 }
49 
50 struct AVPlayStrategy {
51     uint32_t preferredWidth = 0;
52     uint32_t preferredHeight = 0;
53     uint32_t preferredBufferDuration = 0;
54     double preferredBufferDurationForPlaying = 0;
55     double thresholdForAutoQuickPlay = -1;
56     bool preferredHdr = false;
57     bool showFirstFrameOnPrepare = false;
58     bool enableSuperResolution = false;
59     bool enableCameraPostprocessing = false;
60     OHOS::Media::MediaType mutedMediaType = OHOS::Media::MediaType::MEDIA_TYPE_MAX_COUNT;
61     std::string preferredAudioLanguage = "";
62     std::string preferredSubtitleLanguage = "";
63     bool keepDecodingOnMute = false;
64 };
65 
66 struct AVPlayMediaStream {
67     std::string url = "";
68     uint32_t width = 0;
69     uint32_t height = 0;
70     uint32_t bitrate = 0;
71 };
72 
73 struct DrmInfoItem {
74     uint8_t uuid[DrmConstant::DRM_MAX_M3U8_DRM_UUID_LEN];
75     uint8_t pssh[DrmConstant::DRM_MAX_M3U8_DRM_PSSH_LEN];
76     uint32_t psshLen;
77 };
78 
79 class AVMediaSource {
80 public:
AVMediaSource(std::string sourceUrl,std::map<std::string,std::string> sourceHeader)81     AVMediaSource(std::string sourceUrl, std::map<std::string, std::string> sourceHeader)
82         : url(sourceUrl), header(sourceHeader)
83     {
84     }
~AVMediaSource()85     ~AVMediaSource()
86     {
87         header.clear();
88     }
SetMimeType(const std::string & mimeType)89     void SetMimeType(const std::string& mimeType)
90     {
91         mimeType_ = mimeType;
92     }
GetMimeType()93     std::string GetMimeType() const
94     {
95         return mimeType_;
96     }
97 
GetAVPlayMediaStreamList()98     const std::vector<AVPlayMediaStream>& GetAVPlayMediaStreamList()
99     {
100         return mediaStreamVec_;
101     }
102 
AddMediaStream(AVPlayMediaStream & mediaStream)103     void AddMediaStream(AVPlayMediaStream& mediaStream)
104     {
105         mediaStreamVec_.push_back(mediaStream);
106     }
107     std::string url {};
108     std::string mimeType_ {};
109     std::map<std::string, std::string> header;
110     std::shared_ptr<LoaderCallback> mediaSourceLoaderCb_ {nullptr};
111     std::shared_ptr<Plugins::IMediaSourceLoader> sourceLoader_ {nullptr};
112 private:
113     std::vector<AVPlayMediaStream> mediaStreamVec_;
114 };
115 
116 class PlayerKeys {
117 public:
118     static constexpr std::string_view PLAYER_MESSAGE_TYPE = "message_type";
119     static constexpr std::string_view PLAYER_IS_LIVE_STREAM = "is_live_stream";
120     static constexpr std::string_view PLAYER_SEEK_POSITION = "seek_done";
121     static constexpr std::string_view PLAYER_PLAYBACK_SPEED = "speed_done";
122     static constexpr std::string_view PLAYER_PLAYBACK_RATE = "rate_done";
123     static constexpr std::string_view PLAYER_BITRATE_DONE = "bitrate_done";
124     static constexpr std::string_view PLAYER_CURRENT_POSITION = "current_position";
125     static constexpr std::string_view PLAYER_DURATION = "duration";
126     static constexpr std::string_view PLAYER_STATE_CHANGE = "player_state_change";
127     static constexpr std::string_view PLAYER_STATE_CHANGED_REASON = "state_changed_reason";
128     static constexpr std::string_view PLAYER_VOLUME_LEVEL = "volume_level";
129     static constexpr std::string_view PLAYER_TRACK_INDEX = "track_index";
130     static constexpr std::string_view PLAYER_TRACK_TYPE = "track_type";
131     static constexpr std::string_view PLAYER_TRACK_INFO = "track_info";
132     static constexpr std::string_view PLAYER_WIDTH = "width";
133     static constexpr std::string_view PLAYER_HEIGHT = "height";
134     static constexpr std::string_view PLAYER_MIME = "codec_mime";
135     static constexpr std::string_view PLAYER_BITRATE = "bitrate";
136     static constexpr std::string_view PLAYER_FRAMERATE = "frame_rate";
137     static constexpr std::string_view PLAYER_LANGUGAE = "language_code";
138     static constexpr std::string_view PLAYER_SAMPLE_RATE = "sample_rate";
139     static constexpr std::string_view PLAYER_CHANNELS = "channel_count";
140     static constexpr std::string_view PLAYER_BUFFERING_TYPE = "buffering_type";
141     static constexpr std::string_view PLAYER_BUFFERING_VALUE = "buffering_value";
142     static constexpr std::string_view PLAYER_BUFFERING_START = "buffering_start";
143     static constexpr std::string_view PLAYER_BUFFERING_END = "buffering_end";
144     static constexpr std::string_view PLAYER_BUFFERING_PERCENT = "buffering_percent";
145     static constexpr std::string_view PLAYER_CACHED_DURATION = "cached_duration";
146     static constexpr std::string_view PLAYER_IS_SELECT = "track_is_select";
147     static constexpr std::string_view PLAYER_ERROR_TYPE = "error_type";
148     static constexpr std::string_view PLAYER_ERROR_MSG = "error_msg";
149     static constexpr std::string_view CONTENT_TYPE = "content_type";
150     static constexpr std::string_view STREAM_USAGE = "stream_usage";
151     static constexpr std::string_view VOLUME_MODE = "volume_mode";
152     static constexpr std::string_view RENDERER_FLAG = "renderer_flag";
153     static constexpr std::string_view VIDEO_SCALE_TYPE = "video_scale_type";
154     static constexpr std::string_view AUDIO_INTERRUPT_MODE = "audio_interrupt_mode";
155     static constexpr std::string_view AUDIO_INTERRUPT_TYPE = "audio_interrupt_type";
156     static constexpr std::string_view AUDIO_INTERRUPT_FORCE = "audio_interrupt_force";
157     static constexpr std::string_view AUDIO_INTERRUPT_HINT = "audio_interrupt_hint";
158     static constexpr std::string_view AUDIO_FIRST_FRAME = "audio_first_frame";
159     static constexpr std::string_view AUDIO_EFFECT_MODE = "audio_effect_mode";
160     static constexpr std::string_view AUDIO_DEVICE_CHANGE = "audio_device_change";
161     static constexpr std::string_view AUDIO_DEVICE_CHANGE_REASON = "audio_device_change_reason";
162     static constexpr std::string_view SUBTITLE_TEXT = "subtitle_text";
163     static constexpr std::string_view SUBTITLE_PTS = "subtitle_pts";
164     static constexpr std::string_view SUBTITLE_DURATION = "subtitle_duration";
165     static constexpr std::string_view PLAYER_DRM_INFO_ADDR = "drm_info_addr";
166     static constexpr std::string_view PLAYER_DRM_INFO_COUNT = "drm_info_count";
167     static constexpr std::string_view PLAYER_AVAILABLE_BITRATES = "available_bitRates";
168     static constexpr std::string_view AUDIO_MAX_AMPLITUDE = "max_amplitude";
169     static constexpr std::string_view SEI_PLAYBACK_POSITION = "sei_playbackPosition";
170     static constexpr std::string_view SUPER_RESOLUTION_ENABLED = "super_resolution_enabled";
171     static constexpr std::string_view PLAYER_AUDIO_HAPTICS_SYNC_ID = "audio_haptic_sync_id";
172 };
173 
174 class PlaybackInfoKey {
175 public:
176     static constexpr std::string_view SERVER_IP_ADDRESS = "server_ip_address";
177     static constexpr std::string_view AVG_DOWNLOAD_RATE = "average_download_rate";
178     static constexpr std::string_view DOWNLOAD_RATE = "download_rate";
179     static constexpr std::string_view IS_DOWNLOADING = "is_downloading";
180     static constexpr std::string_view BUFFER_DURATION = "buffer_duration";
181 };
182 
183 enum PlayerErrorType : int32_t {
184     /* Valid error, error code reference defined in media_errors.h */
185     PLAYER_ERROR,
186     /* Unknown error */
187     PLAYER_ERROR_UNKNOWN,
188     /* extend error type start,The extension error type agreed upon by the plug-in and
189        the application will be transparently transmitted by the service. */
190     PLAYER_ERROR_EXTEND_START = 0X10000,
191 };
192 
193 enum PlayerMessageType : int32_t {
194     /* unknown info */
195     PLAYER_INFO_UNKNOWN = 0,
196     /* first video frame start to render. */
197     PLAYER_INFO_VIDEO_RENDERING_START,
198     /* network bandwidth, uint is KB and passed by "extra"(arg 2). */
199     PLAYER_INFO_NETWORK_BANDWIDTH,
200     /* not fatal errors accured, errorcode see "media_errors.h" and passed by "extra"(arg 2). */
201     PLAYER_INFO_WARNING,
202     /* system new info type should be added here.
203        extend start. App and plugins or PlayerEngine extended info type start. */
204     PLAYER_INFO_EXTEND_START = 0X1000,
205 };
206 
207 enum PlayerOnSystemOperationType : int32_t {
208     OPERATION_TYPE_PLAY = 1,
209     OPERATION_TYPE_PAUSE,
210     OPERATION_TYPE_CHECK_LIVE_DELAY,
211 };
212 
213 enum PlayerOperationReason : int32_t {
214     OPERATION_REASON_AUDIO_INTERRUPT = 1,
215     OPERATION_REASON_USER_BACKGROUND,
216     OPERATION_REASON_CHECK_LIVE_DELAY_TIME,
217 };
218 
219 enum PlayerOnInfoType : int32_t {
220     /* return the message when seeking done. */
221     INFO_TYPE_SEEKDONE = 1,
222     /* return the message when speeding done. */
223     INFO_TYPE_SPEEDDONE,
224     /* return the message when select bitrate done */
225     INFO_TYPE_BITRATEDONE,
226     /* return the message when playback is end of steam. */
227     INFO_TYPE_EOS,
228     /* return the message when PlayerStates changed. */
229     INFO_TYPE_STATE_CHANGE,
230     /* return the current posion of playback automatically. */
231     INFO_TYPE_POSITION_UPDATE,
232     /* return the playback message. */
233     INFO_TYPE_MESSAGE,
234     /* return the message when volume changed. */
235     INFO_TYPE_VOLUME_CHANGE,
236     /* return the message when video size is first known or updated. */
237     INFO_TYPE_RESOLUTION_CHANGE,
238     /* return multiqueue buffering time. */
239     INFO_TYPE_BUFFERING_UPDATE,
240     /* return hls bitrate.
241        Bitrate is to convert data into uint8_t array storage,
242        which needs to be forcibly converted to uint32_t through offset access. */
243     INFO_TYPE_BITRATE_COLLECT,
244     /* return the message when audio focus changed. */
245     INFO_TYPE_INTERRUPT_EVENT,
246     /* return the message when PlayerStates changed by audio. */
247     INFO_TYPE_STATE_CHANGE_BY_AUDIO,
248     /* return the message with extra information in format. */
249     INFO_TYPE_EXTRA_FORMAT,
250     /* return the duration of playback. */
251     INFO_TYPE_DURATION_UPDATE,
252     /* return the playback is live stream. */
253     INFO_TYPE_IS_LIVE_STREAM,
254     /* return the message when track changes. */
255     INFO_TYPE_TRACKCHANGE,
256     /* return the default audio track. */
257     INFO_TYPE_DEFAULTTRACK,
258     /* Return to the end of track processing. */
259     INFO_TYPE_TRACK_DONE,
260     /* Return error message to prompt the user. */
261     INFO_TYPE_ERROR_MSG,
262     /* return the message when subtitle track num updated. */
263     INFO_TYPE_TRACK_NUM_UPDATE,
264     /* return the message when subtitle track info updated. */
265     INFO_TYPE_TRACK_INFO_UPDATE,
266     /* return the subtitle of playback. */
267     INFO_TYPE_SUBTITLE_UPDATE,
268     /* return to the end of adding subtitle processing. */
269     INFO_TYPE_ADD_SUBTITLE_DONE,
270     /* return the message with drminfo. */
271     INFO_TYPE_DRM_INFO_UPDATED,
272     /* return set decrypt done message. */
273     INFO_TYPE_SET_DECRYPT_CONFIG_DONE,
274     /* return the audio latency when the first frame is writing. */
275     INFO_TYPE_AUDIO_FIRST_FRAME,
276     /* audio device change. */
277     INFO_TYPE_AUDIO_DEVICE_CHANGE,
278     /* return the subtitle info */
279     INFO_TYPE_SUBTITLE_UPDATE_INFO,
280     /* return audio uv value */
281     INFO_TYPE_MAX_AMPLITUDE_COLLECT,
282     /* return the sei info */
283     INFO_TYPE_SEI_UPDATE_INFO,
284     /* return the message when super resolution is changed*/
285     INFO_TYPE_SUPER_RESOLUTION_CHANGED,
286     /* return the auto select flv live bitrate. internal info type, not open to northbound interfaces. */
287     INFO_TYPE_FLV_AUTO_SELECT_BITRATE,
288     /* return the message when speeding done. */
289     INFO_TYPE_RATEDONE,
290 };
291 
292 enum PlayerStates : int32_t {
293     /* error states */
294     PLAYER_STATE_ERROR = 0,
295     /* idle states */
296     PLAYER_IDLE = 1,
297     /* initialized states(Internal states) */
298     PLAYER_INITIALIZED = 2,
299     /* preparing states(Internal states) */
300     PLAYER_PREPARING = 3,
301     /* prepared states */
302     PLAYER_PREPARED = 4,
303     /* started states */
304     PLAYER_STARTED = 5,
305     /* paused states */
306     PLAYER_PAUSED = 6,
307     /* stopped states */
308     PLAYER_STOPPED = 7,
309     /* Play to the end states */
310     PLAYER_PLAYBACK_COMPLETE = 8,
311     /* released states */
312     PLAYER_RELEASED = 9,
313     PLAYER_FROZEN = 10,
314 };
315 
316 enum PlaybackRateMode : int32_t {
317     /* Video playback at 0.75x normal speed */
318     SPEED_FORWARD_0_75_X = 0,
319     /* Video playback at normal speed */
320     SPEED_FORWARD_1_00_X = 1,
321     /* Video playback at 1.25x normal speed */
322     SPEED_FORWARD_1_25_X = 2,
323     /* Video playback at 1.75x normal speed */
324     SPEED_FORWARD_1_75_X = 3,
325     /* Video playback at 2.0x normal speed */
326     SPEED_FORWARD_2_00_X = 4,
327     /* Video playback at 0.5x normal speed */
328     SPEED_FORWARD_0_50_X = 5,
329     /* Video playback at 1.5x normal speed */
330     SPEED_FORWARD_1_50_X = 6,
331     /* Video playback at 3.0x normal speed */
332     SPEED_FORWARD_3_00_X = 7,
333     /* Video playback at 0.25x normal speed */
334     SPEED_FORWARD_0_25_X = 8,
335     /* Video playback at 0.125x normal speed */
336     SPEED_FORWARD_0_125_X = 9,
337     /* Video playback at 4.00x normal speed */
338     SPEED_FORWARD_4_00_X = 10,
339     /* Video playback at 1.20x normal speed */
340     SPEED_FORWARD_1_20_X = 100, // flv live quick play, internal value, not open to northbound
341 };
342 
343 enum PlayerProducer : int32_t {
344     INNER = 0,
345     CAPI,
346     NAPI
347 };
348 
349 class PlayerCallback {
350 public:
351     virtual ~PlayerCallback() = default;
352     /**
353      * Called when a player message or alarm is received.
354      *
355      * @param type Indicates the information type. For details, see {@link PlayerOnInfoType}.
356      * @param extra Indicates other information, for example, the start time position of a playing file.
357      * @param infoBody According to the info type, the information carrier passed.Is an optional parameter.
358      */
359     virtual void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) = 0;
360 
361     /**
362      * Called when an error occurred for versions above api9
363      *
364      * @param errorCode Error code.
365      * @param errorMsg Error message.
366      */
367     virtual void OnError(int32_t errorCode, const std::string &errorMsg) = 0;
368 
SetFreezeFlag(bool isFrozen)369     virtual void SetFreezeFlag(bool isFrozen)
370     {
371         (void)isFrozen;
372     }
373 
SetInterruptListenerFlag(bool isRegistered)374     virtual void SetInterruptListenerFlag(bool isRegistered)
375     {
376         (void)isRegistered;
377     }
378 };
379 
380 class Player {
381 public:
382     virtual ~Player() = default;
383 
384     /**
385      * @brief Sets the playback source for the player. The corresponding source can be http url
386      *
387      * @param url Indicates the playback source.
388      * @return Returns {@link MSERR_OK} if the url is set successfully; returns an error code defined
389      * in {@link media_errors.h} otherwise.
390      * @since 1.0
391      * @version 1.0
392      */
393     virtual int32_t SetSource(const std::string &url) = 0;
394 
395     /**
396      * @brief Sets the playback media data source for the player.
397      *
398      * @param dataSrc Indicates the media data source. in {@link media_data_source.h}
399      * @return Returns {@link MSERR_OK} if the mediadatasource is set successfully; returns an error code defined
400      * in {@link media_errors.h} otherwise.
401      * @since 1.0
402      * @version 1.0
403      */
404     virtual int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) = 0;
405 
406     /**
407      * @brief Sets the playback media file descriptor source for the player.
408      *
409      * @param fd Indicates the file descriptor of media source.
410      * @param offset Indicates the offset of media source in file descriptor.
411      * @param size Indicates the size of media source.
412      * @return Returns {@link MSERR_OK} if the fd source is set successfully; returns an error code defined
413      * in {@link media_errors.h} otherwise.
414      * @since 1.0
415      * @version 1.0
416      */
417     virtual int32_t SetSource(int32_t fd, int64_t offset = 0, int64_t size = 0) = 0;
418 
419     /**
420      * @brief Add a subtitle source for the player. The corresponding source can be http url.
421      *
422      * @param url Indicates the subtitle source.
423      * @return Returns {@link MSERR_OK} if the url is set successfully; returns an error code defined
424      * in {@link media_errors.h} otherwise.
425      * @since 1.0
426      * @version 1.0
427      */
428     virtual int32_t AddSubSource(const std::string &url) = 0;
429 
430     /**
431      * @brief Add a playback subtitle file descriptor source for the player.
432      *
433      * @param fd Indicates the file descriptor of subtitle source.
434      * @param offset Indicates the offset of subtitle source in file descriptor.
435      * @param size Indicates the size of subtitle source.
436      * @return Returns {@link MSERR_OK} if the fd source is set successfully; returns an error code defined
437      * in {@link media_errors.h} otherwise.
438      * @since 1.0
439      * @version 1.0
440      */
441     virtual int32_t AddSubSource(int32_t fd, int64_t offset = 0, int64_t size = 0) = 0;
442 
443     /**
444      * @brief Start playback.
445      *
446      * This function must be called after {@link Prepare}. If the player state is <b>Prepared</b>,
447      * this function is called to start playback.
448      *
449      * @return Returns {@link MSERR_OK} if the playback is started; otherwise returns an error code defined
450      * in {@link media_errors.h} otherwise.
451      * @since 1.0
452      * @version 1.0
453      */
454     virtual int32_t Play() = 0;
455 
456     /**
457      * @brief Prepares the playback environment and buffers media data asynchronous.
458      *
459      * This function must be called after {@link SetSource}.
460      *
461      * @return Returns {@link MSERR_OK} if {@link Prepare} is successfully added to the task queue;
462      * returns an error code defined in {@link media_errors.h} otherwise.
463      * @since 1.0
464      * @version 1.0
465      */
466     __attribute__((deprecated)) virtual int32_t Prepare() = 0;
467 
468     /**
469      * @brief Prepares the playback environment and buffers media data asynchronous.
470      *
471      * This function must be called after {@link SetSource}.
472      *
473      * @return Returns {@link MSERR_OK} if {@link PrepareAsync} is successfully added to the task queue;
474      * returns an error code defined in {@link media_errors.h} otherwise.
475      * @since 1.0
476      * @version 1.0
477      */
478     virtual int32_t PrepareAsync() = 0;
479 
480     /**
481      * @brief Pauses playback.
482      *
483      * @return Returns {@link MSERR_OK} if {@link Pause} is successfully added to the task queue;
484      * returns an error code defined in {@link media_errors.h} otherwise.
485      * @since 1.0
486      * @version 1.0
487      */
488     virtual int32_t Pause() = 0;
489 
490     /**
491      * @brief Stop playback.
492      *
493      * @return Returns {@link MSERR_OK} if {@link Stop} is successfully added to the task queue;
494      * returns an error code defined in {@link media_errors.h} otherwise.
495      * @since 1.0
496      * @version 1.0
497      */
498     virtual int32_t Stop() = 0;
499 
500     /**
501      * @brief Restores the player to the initial state.
502      *
503      * After the function is called, add a playback source by calling {@link SetSource},
504      * call {@link Play} to start playback again after {@link Prepare} is called.
505      *
506      * @return Returns {@link MSERR_OK} if {@link Reset} is successfully added to the task queue;
507      * returns an error code defined in {@link media_errors.h} otherwise.
508      * @since 1.0
509      * @version 1.0
510      */
511     virtual int32_t Reset() = 0;
512 
513     /**
514      * @brief Releases player resources async
515      *
516      *  Asynchronous release guarantees the performance
517      *  but cannot ensure whether the surfacebuffer is released.
518      *  The caller needs to ensure the life cycle security of the sufrace
519      *
520      * @return Returns {@link MSERR_OK} if {@link Release} is successfully added to the task queue;
521      * returns an error code defined in {@link media_errors.h} otherwise.
522      * @since 1.0
523      * @version 1.0
524      */
525     virtual int32_t Release() = 0;
526 
527     /**
528      * @brief Sets the volume of the player.
529      *
530      * This function can be used during playback or pause. The value <b>0</b> indicates no sound,
531      * and <b>1</b> indicates the original volume. If no audio device is started or no audio
532      * stream exists, the value <b>-1</b> is returned.
533      *
534      * @param leftVolume Indicates the target volume of the left audio channel to set,
535      *        ranging from 0 to 1. each step is 0.01.
536      * @param rightVolume Indicates the target volume of the right audio channel to set,
537      *        ranging from 0 to 1. each step is 0.01.
538      * @return Returns {@link MSERR_OK} if the volume is set; returns an error code defined
539      * in {@link media_errors.h} otherwise.
540      * @since 1.0
541      * @version 1.0
542      */
543     virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0;
544 
545     virtual int32_t SetVolumeMode(int32_t mode);
546 
547     virtual int32_t SetMediaSource(const std::shared_ptr<AVMediaSource> &mediaSource, AVPlayStrategy strategy) = 0;
548 
549     /**
550      * @brief Changes the playback position.
551      *
552      * This function can be used during play or pause.
553      *
554      * @param mSeconds Indicates the target playback position, accurate to milliseconds.
555      * @param mode Indicates the player seek mode. For details, see {@link PlayerSeekMode}.
556      * @return Returns {@link MSERR_OK} if the seek is done; returns an error code defined
557      * in {@link media_errors.h} otherwise.
558      * @since 1.0
559      * @version 1.0
560     */
561     virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0;
562 
563     /**
564      * @brief Obtains the playback position, accurate to millisecond.
565      *
566      * @param currentTime Indicates the playback position.
567      * @return Returns {@link MSERR_OK} if the current position is get; returns an error code defined
568      * in {@link media_errors.h} otherwise.
569      * @since 1.0
570      * @version 1.0
571      */
572     virtual int32_t GetCurrentTime(int32_t &currentTime) = 0;
573 
574     /**
575      * @brief Obtains the video track info, contains mimeType, bitRate, width, height, frameRata.
576      *
577      * @param video track info vec.
578      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
579      * in {@link media_errors.h} otherwise.
580      * @since 1.0
581      * @version 1.0
582      */
583     virtual int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack) = 0;
584 
585     /**
586      * @brief Obtains the playbackInfo, contains server_ip_address, average_download_rate,
587      * download_rate, is_downloading, buffer_duration.
588      *
589      * @param playbackInfo.
590      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
591      * in {@link media_errors.h} otherwise.
592      * @since 1.0
593      * @version 1.0
594      */
595     virtual int32_t GetPlaybackInfo(Format &playbackInfo) = 0;
596 
597     /**
598      * @brief Obtains the audio track info, contains mimeType, bitRate, sampleRate, channels, language.
599      *
600      * @param audio track info vec.
601      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
602      * in {@link media_errors.h} otherwise.
603      * @since 1.0
604      * @version 1.0
605      */
606     virtual int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0;
607 
608     /**
609      * @brief get the video width.
610      *
611      * @return Returns width if success; else returns 0
612      * @since 1.0
613      * @version 1.0
614      */
615     virtual int32_t GetVideoWidth() = 0;
616 
617     /**
618      * @brief get the video height.
619      *
620      * @return Returns height if success; else returns 0
621      * @since 1.0
622      * @version 1.0
623      */
624     virtual int32_t GetVideoHeight() = 0;
625 
626     /**
627      * @brief Obtains the total duration of media files, accurate to milliseconds.
628      *
629      * @param duration Indicates the total duration of media files.
630      * @return Returns {@link MSERR_OK} if the current duration is get; returns an error code defined
631      * in {@link media_errors.h} otherwise.
632      * @since 1.0
633      * @version 1.0
634      */
635     virtual int32_t GetDuration(int32_t &duration) = 0;
636 
637     /**
638      * @brief set the player playback rate
639      *
640      * @param mode the rate mode {@link PlaybackRateMode} which can set.
641      * @return Returns {@link MSERR_OK} if the playback rate is set successful; returns an error code defined
642      * in {@link media_errors.h} otherwise.
643      * @since 1.0
644      * @version 1.0
645      */
646     virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0;
647 
648     /**
649      * @brief set the player playback rate
650      *
651      * @param rate the rate which can set.
652      * @return Returns {@link MSERR_OK} if the playback rate is set successful; returns an error code defined
653      * in {@link media_errors.h} otherwise.
654      */
655     virtual int32_t SetPlaybackRate(float rate) = 0;
656 
657     /**
658      * @brief get the current player playback rate
659      *
660      * @param mode the rate mode {@link PlaybackRateMode} which can get.
661      * @return Returns {@link MSERR_OK} if the current player playback rate is get; returns an error code defined
662      * in {@link media_errors.h} otherwise.
663      * @since 1.0
664      * @version 1.0
665      */
666     virtual int32_t GetPlaybackSpeed(PlaybackRateMode &mode) = 0;
667 
668     /**
669      * @brief set the bit rate use for hls player
670      * the playback bitrate expressed in bits per second, expressed in bits per second,
671      * which is only valid for HLS protocol network flow. By default,
672      * the player will select the appropriate bit rate and speed according to the network connection.
673      * report the effective bit rate linked list by "INFO_TYPE_BITRATE_COLLECT"
674      * set and select the specified bit rate, and select the bit rate that is less than and closest
675      * to the specified bit rate for playback. When ready, read it to query the currently selected bit rate.
676      * @param bitRate the bit rate, The unit is bps.
677      * @return Returns {@link MSERR_OK} if the bit rate is set successfully; returns an error code defined
678      * in {@link media_errors.h} otherwise.
679      * @since 1.0
680      * @version 1.0
681      */
682     virtual int32_t SelectBitRate(uint32_t bitRate) = 0;
683 
684     /**
685      * @brief set the playback strategy
686      * the playback strategy includes five fileds:
687      * preferredWidth: Preferred width, which is of the int type, for example, 1080.
688      * preferredHeight: Preferred height, which is of the int type, for example, 1920.
689      * preferredBufferDuration: Preferred buffer duration, in seconds. The value ranges from 1 to 20.
690      * preferredHdr: Whether HDR is preferred. The value true means that HDR is preferred, and false means the opposite.
691      * mutedMediaType: The mediaType to be muted before play, which is of the MediaType type,
692      * enableSuperResolution: Whether super resolution is enabled. Must be set before prepare.
693      * for example, MediaType::MEDIA_TYPE_AUD.
694      * @param playbackStrategy the playback strategy.
695      * @return Returns {@link MSERR_OK} if the playback strategy is set successfully; returns an error code defined
696     * in {@link media_errors.h} otherwise.
697      * @since 1.0
698      * @version 1.0
699      */
SetPlaybackStrategy(AVPlayStrategy playbackStrategy)700     virtual int32_t SetPlaybackStrategy(AVPlayStrategy playbackStrategy)
701     {
702         (void)playbackStrategy;
703         return 0;
704     }
705 
SetMediaMuted(OHOS::Media::MediaType type,bool isMuted)706     virtual int32_t SetMediaMuted(OHOS::Media::MediaType type, bool isMuted)
707     {
708         (void)type;
709         (void)isMuted;
710         return 0;
711     }
712 
713 #ifdef SUPPORT_AUDIO_ONLY
714 #else
715     /**
716      * @brief Method to set the surface.
717      *
718      * @param surface pointer of the surface.
719      * @return Returns {@link MSERR_OK} if the surface is set; returns an error code defined
720      * in {@link media_errors.h} otherwise.
721      * @since 1.0
722      * @version 1.0
723      */
724     virtual int32_t SetVideoSurface(sptr<Surface> surface) = 0;
725 #endif
726 
727     /**
728      * @brief Checks whether the player is playing.
729      *
730      * @return Returns true if the playback is playing; false otherwise.
731      * @since 1.0
732      * @version 1.0
733      */
734     virtual bool IsPlaying() = 0;
735 
736     /**
737      * @brief Returns the value whether single looping is enabled or not .
738      *
739      * @return Returns true if the playback is single looping; false otherwise.
740      * @since 1.0
741      * @version 1.0
742      */
743     virtual bool IsLooping() = 0;
744 
745     /**
746      * @brief Enables single looping of the media playback.
747      *
748      * @return Returns {@link MSERR_OK} if the single looping is set; returns an error code defined
749      * in {@link media_errors.h} otherwise.
750      * @since 1.0
751      * @version 1.0
752      */
753     virtual int32_t SetLooping(bool loop) = 0;
754 
755     /**
756      * @brief Method to set player callback.
757      *
758      * @param callback object pointer.
759      * @return Returns {@link MSERR_OK} if the playercallback is set; returns an error code defined
760      * in {@link media_errors.h} otherwise.
761      * @since 1.0
762      * @version 1.0
763      */
764     virtual int32_t SetPlayerCallback(const std::shared_ptr<PlayerCallback> &callback) = 0;
765 
766     /**
767      * @brief Sets an extended parameter for player
768      *
769      * @param format Indicates the string key and value. For details, see {@link Format}
770      * @return Returns {@link MSERR_OK} if the parameters are set; returns an error code defined
771      * in {@link media_errors.h} otherwise.
772      * @since 1.0
773      * @version 1.0
774      */
775     virtual int32_t SetParameter(const Format &param) = 0;
776 
777     /**
778      * @brief Releases player resources sync
779      *
780      * Synchronous release ensures effective release of surfacebuffer
781      * but this interface will take a long time (when the engine is not idle state)
782      * requiring the caller to design an asynchronous mechanism by itself
783      *
784      * @return Returns {@link MSERR_OK} if the playback is released; returns an error code defined
785      * in {@link media_errors.h} otherwise.
786      * @since 1.0
787      * @version 1.0
788      */
789     virtual int32_t ReleaseSync() = 0;
790 
791     /**
792      * @brief Select audio or subtitle track.
793      * By default, the first audio stream with data is played, and the subtitle track is not played.
794      * After the settings take effect, the original track will become invalid. Please set subtitles
795      * in prepared/playing/paused/completed state and set audio tracks in prepared state.
796      *
797      * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}.
798      * @return Returns {@link MSERR_OK} if selected successfully; returns an error code defined
799      * in {@link media_errors.h} otherwise.
800      * @since 1.0
801      * @version 1.0
802     */
803     virtual int32_t SelectTrack(int32_t index, PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SMOOTH) = 0;
804 
805     /**
806      * @brief Deselect the current audio or subtitle track.
807      * After audio is deselected, the default track will be played, and after subtitles are deselected,
808      * they will not be played. Please set subtitles in prepared/playing/paused/completed state and set
809      * audio tracks in prepared state.
810      *
811      * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}.
812      * @return Returns {@link MSERR_OK} if selected successfully; returns an error code defined
813      * in {@link media_errors.h} otherwise.
814      * @since 1.0
815      * @version 1.0
816     */
817     virtual int32_t DeselectTrack(int32_t index) = 0;
818 
819     /**
820      * @brief Obtain the currently effective track index.
821      * Please get it in the prepared/playing/paused/completed state.
822      *
823      * @param trackType Media type.
824      * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}.
825      * @return Returns {@link MSERR_OK} if the track index is get; returns an error code defined
826      * in {@link media_errors.h} otherwise.
827      * @since 1.0
828      * @version 1.0
829      */
830     virtual int32_t GetCurrentTrack(int32_t trackType, int32_t &index) = 0;
831 
832     /**
833      * @brief Obtains the subtitle track info, contains mimeType, type, language.
834      *
835      * @param subtitle track info vec.
836      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
837      * in {@link media_errors.h} otherwise.
838      * @since 1.0
839      * @version 1.0
840      */
841     virtual int32_t GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack) = 0;
842 
SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySessionProxy,bool svp)843     virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySessionProxy,
844         bool svp)
845     {
846         (void)keySessionProxy;
847         (void)svp;
848         return 0;
849     }
850 
851     virtual void ReleaseClientListener() = 0;
852 
853     /**
854      * @brief Enables render video first frame of the media playback.
855      *
856      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
857      * in {@link media_errors.h} otherwise.
858      * @since 1.0
859      * @version 1.0
860      */
SetRenderFirstFrame(bool display)861     virtual int32_t SetRenderFirstFrame(bool display)
862     {
863         (void)display;
864         return 0;
865     }
866 
867     /**
868      * @brief Specify the start and end time to play
869      * This function must be called after {@link SetSource}.
870      * This function is called to set start and end time
871      *
872      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
873      * in {@link media_errors.h} otherwise.
874      * @since 1.0
875      * @version 1.0
876      */
SetPlayRange(int64_t start,int64_t end)877     virtual int32_t SetPlayRange(int64_t start, int64_t end)
878     {
879         (void)start;
880         (void)end;
881         return 0;
882     }
883 
884     /**
885      * @brief set get max amplitude callback status.
886      *
887      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
888      * in {@link media_errors.h} otherwise.
889      * @since 1.0
890      * @version 1.0
891      */
SetMaxAmplitudeCbStatus(bool status)892     virtual int32_t SetMaxAmplitudeCbStatus(bool status)
893     {
894         (void)status;
895         return 0;
896     }
897 
898     /**
899      * @brief Set playback start position and end position.
900      * Use the specified seek mode to jump to the playback start position,
901      * currently support SEEK_PREVIOUS_SYNC and SEEK_CLOSEST,
902      * other values are invalid, the default value is SEEK_PREVIOUS_SYNC.
903      * This function must be called after {@link SetSource}.
904      *
905      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
906      * in {@link media_errors.h} otherwise.
907      * @since 1.0
908      * @version 1.0
909      */
910     virtual int32_t SetPlayRangeWithMode(int64_t start, int64_t end, PlayerSeekMode mode = SEEK_PREVIOUS_SYNC)
911     {
912         (void)start;
913         (void)end;
914         (void)mode;
915         return 0;
916     }
917 
918     /**
919      * @brief Set playback start position and end position.
920      * Use the specified seek mode to jump to the playback start position,
921      * currently support SEEK_PREVIOUS_SYNC and SEEK_CLOSEST,
922      * other values are invalid, the default value is SEEK_PREVIOUS_SYNC.
923      * This function must be called after {@link SetSource}.
924      *
925      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
926      * in {@link media_errors.h} otherwise.
927      * @since 6.0
928      * @version 6.0
929      */
930     virtual int32_t SetPlayRangeUsWithMode(int64_t start, int64_t end, PlayerSeekMode mode = SEEK_PREVIOUS_SYNC)
931     {
932         (void)start;
933         (void)end;
934         (void)mode;
935         return 0;
936     }
937 
938     /**
939      * @brief set get device change callback status.
940      *
941      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
942      * in {@link media_errors.h} otherwise.
943      * @since 1.0
944      * @version 1.0
945      */
SetDeviceChangeCbStatus(bool status)946     virtual int32_t SetDeviceChangeCbStatus(bool status)
947     {
948         (void)status;
949         return 0;
950     }
951 
952     /**
953      * @brief Obtain the api version of application.
954      *
955      * @return Returns {@link MSERR_OK} if the current api version is get; returns an error code defined
956      * in {@link media_errors.h} otherwise.
957      * @since 1.0
958      * @version 1.0
959      */
GetApiVersion(int32_t & apiVersion)960     virtual int32_t GetApiVersion(int32_t &apiVersion)
961     {
962         (void)apiVersion;
963         return 0;
964     }
965 
966     /**
967      * @brief Checks whether the player supports SeekContinuous.
968      *
969      * @return Returns true if the player supports SeekContinuous; false otherwise.
970      * @since 1.0
971      * @version 1.0
972      */
IsSeekContinuousSupported()973     virtual bool IsSeekContinuousSupported()
974     {
975         return false;
976     }
977 
978      /**
979      * @brief Obtains the playback position, accurate to millisecond.
980      *
981      * @param playbackPosition Indicates the playback position.
982      * @return Returns {@link MSERR_OK} if the current position is get; returns an error code defined
983      * in {@link media_errors.h} otherwise.
984      * @since 1.0
985      * @version 1.0
986      */
GetPlaybackPosition(int32_t & playbackPosition)987     virtual int32_t GetPlaybackPosition(int32_t &playbackPosition)
988     {
989         playbackPosition = 0;
990         return 0;
991     }
992 
993     /**
994      * @brief set get sei message callback status.
995      *
996      * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined
997      * in {@link media_errors.h} otherwise.
998      * @since 1.0
999      * @version 1.0
1000      */
SetSeiMessageCbStatus(bool status,const std::vector<int32_t> & payloadTypes)1001     virtual int32_t SetSeiMessageCbStatus(bool status, const std::vector<int32_t> &payloadTypes)
1002     {
1003         (void)status;
1004         (void)payloadTypes;
1005         return 0;
1006     }
1007 
1008     /**
1009      * @brief Enable or disable super-resolution dynamically.
1010      *
1011      * @return Returns {@link MSERR_OK} if super resolution is set; returns an error code defined
1012      * in {@link media_errors.h} otherwise.
1013      * @since 1.0
1014      * @version 1.0
1015      */
SetSuperResolution(bool enabled)1016     virtual int32_t SetSuperResolution(bool enabled)
1017     {
1018         (void)enabled;
1019         return 0;
1020     }
1021 
1022     /**
1023      * @brief Set video window size for super-resolution.
1024      *
1025      * @return Returns {@link MSERR_OK} if video window size is set; returns an error code defined
1026      * in {@link media_errors.h} otherwise.
1027      * @since 1.0
1028      * @version 1.0
1029      */
SetVideoWindowSize(int32_t width,int32_t height)1030     virtual int32_t SetVideoWindowSize(int32_t width, int32_t height)
1031     {
1032         (void)width;
1033         (void)height;
1034         return 0;
1035     }
1036 
1037     /**
1038      * @brief Enables or disables the report of media progress.
1039      *
1040      * @param enable Indicates whether to enable the report of media progress.
1041      * @return Returns {@link MSERR_OK} if the report of media progress is enabled or disabled; returns an error code
1042      * defined in {@link media_errors.h} otherwise.
1043      * @since 1.0
1044      * @version 1.0
1045      */
EnableReportMediaProgress(bool enable)1046     virtual int32_t EnableReportMediaProgress(bool enable)
1047     {
1048         (void)enable;
1049         return 0;
1050     }
1051 
1052     /**
1053      * @brief Enables or disables the report of audio interrupt during frozen state.
1054      *
1055      * @param enable Indicates whether to enable the report of audio interrupt during frozen state.
1056      * @return Returns {@link MSERR_OK} if the report of audio interrupt is enabled or disabled; returns an error code
1057      * defined in {@link media_errors.h} otherwise.
1058      * @since 1.0
1059      * @version 1.0
1060      */
EnableReportAudioInterrupt(bool enable)1061     virtual int32_t EnableReportAudioInterrupt(bool enable)
1062     {
1063         (void)enable;
1064         return 0;
1065     }
1066 
1067     /**
1068      * @brief Set Start Frame Rate Opt Enabled.
1069      *
1070      * @return Returns {@link MSERR_OK} if enabled is set; returns an error code defined
1071      * in {@link media_errors.h} otherwise.
1072      * @since 1.0
1073      * @version 1.0
1074      */
SetStartFrameRateOptEnabled(bool enabled)1075     virtual int32_t SetStartFrameRateOptEnabled(bool enabled)
1076     {
1077         (void)enabled;
1078         return 0;
1079     }
1080 
1081     /**
1082      * @brief Set video reopen fd.
1083      *
1084      * @return Returns {@link MSERR_OK} if video reopen fd is set; returns an error code defined
1085      * in {@link media_errors.h} otherwise.
1086      * @since 1.0
1087      * @version 1.0
1088      */
SetReopenFd(int32_t fd)1089     virtual int32_t SetReopenFd(int32_t fd)
1090     {
1091         (void)fd;
1092         return 0;
1093     }
1094 
1095     /**
1096      * @brief Enable or disable camera post processor.
1097      *
1098      * @return Returns {@link MSERR_OK} if enable camera post processor is set; returns an error code defined
1099      * in {@link media_errors.h} otherwise.
1100      * @since 1.0
1101      * @version 1.0
1102      */
EnableCameraPostprocessing()1103     virtual int32_t EnableCameraPostprocessing()
1104     {
1105         return 0;
1106     }
1107 
SetCameraPostprocessing(bool isOpen)1108     virtual int32_t SetCameraPostprocessing(bool isOpen)
1109     {
1110         (void)isOpen;
1111         return 0;
1112     }
1113 
ForceLoadVideo(bool)1114     virtual int32_t ForceLoadVideo(bool /* status */)
1115     {
1116         return 0;
1117     }
1118 };
1119 
1120 class __attribute__((visibility("default"))) PlayerFactory {
1121 public:
1122 #ifdef UNSUPPORT_PLAYER
CreatePlayer()1123     static std::shared_ptr<Player> CreatePlayer()
1124     {
1125         return nullptr;
1126     }
1127 
CreatePlayer(const PlayerProducer producer)1128     static std::shared_ptr<Player> CreatePlayer(const PlayerProducer producer)
1129     {
1130         return nullptr;
1131     }
1132 #else
1133     static std::shared_ptr<Player> CreatePlayer();
1134 
1135     static std::shared_ptr<Player> CreatePlayer(const PlayerProducer producer);
1136 #endif
1137     static std::vector<pid_t> GetPlayerPids();
1138 private:
1139     PlayerFactory() = default;
1140     ~PlayerFactory() = default;
1141 };
1142 } // namespace Media
1143 } // namespace OHOS
1144 #endif // PLAYER_H
1145