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