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