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