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 video track info, contains mimeType, bitRate, width, height, frameRata. 270 * 271 * @param video track info vec. 272 * @return Returns {@link MSERR_OK} if the track info 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 GetVideoTrackInfo(std::vector<Format> &videoTrack) = 0; 278 279 /** 280 * @brief Obtains playbackInfo, contains server_ip_address, average_download_rate, 281 * download_rate, is_downloading, buffer_duration. 282 * 283 * @param playbackInfo. 284 * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined 285 * in {@link media_errors.h} otherwise. 286 * @since 1.0 287 * @version 1.0 288 */ 289 virtual int32_t GetPlaybackInfo(Format &playbackInfo) = 0; 290 291 /** 292 * @brief Obtains the audio track info, contains mimeType, bitRate, sampleRate, channels, language. 293 * 294 * @param audio track info vec. 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 GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0; 301 302 /** 303 * @brief get the video width. 304 * 305 * @return Returns width if success; else returns 0 306 * @since 1.0 307 * @version 1.0 308 */ 309 virtual int32_t GetVideoWidth() = 0; 310 311 /** 312 * @brief get the video height. 313 * 314 * @return Returns height if success; else returns 0 315 * @since 1.0 316 * @version 1.0 317 */ 318 virtual int32_t GetVideoHeight() = 0; 319 320 /** 321 * @brief Obtains the total duration of media files, accurate to milliseconds. 322 * 323 * @param duration Indicates the total duration of media files. 324 * @return Returns {@link MSERR_OK} if the current duration is get; returns an error code defined 325 * in {@link media_errors.h} otherwise. 326 * @since 1.0 327 * @version 1.0 328 */ 329 virtual int32_t GetDuration(int32_t &duration) = 0; 330 331 /** 332 * @brief set the player playback rate 333 * 334 * @param mode the rate mode {@link PlaybackRateMode} which can set. 335 * @return Returns {@link MSERR_OK} if the playback rate is set successfully; 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 SetPlaybackSpeed(PlaybackRateMode mode) = 0; 341 342 virtual int32_t SetMediaSource(const std::shared_ptr<AVMediaSource> &mediaSource, AVPlayStrategy strategy) = 0; 343 /** 344 * @brief set the bit rate use for hls player 345 * 346 * @param bitRate the bit rate. 347 * @return Returns {@link MSERR_OK} if the bit rate is set successfully; returns an error code defined 348 * in {@link media_errors.h} otherwise. 349 * @since 1.0 350 * @version 1.0 351 */ 352 virtual int32_t SelectBitRate(uint32_t bitRate) = 0; 353 354 /** 355 * @brief get the current player playback rate 356 * 357 * @param mode the rate mode {@link PlaybackRateMode} which can get. 358 * @return Returns {@link MSERR_OK} if the current player playback rate is get; 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 GetPlaybackSpeed(PlaybackRateMode &mode) = 0; 364 365 /** 366 * @brief add for drm, set decrypt module 367 * 368 * @param keySessionProxy is the sptr will be setted to playerserver. 369 * @param svp bool. 370 * @return Returns {@link MSERR_OK} if set successfully; returns an error code defined 371 * in {@link media_errors.h} otherwise. 372 * @since 373 * @version 374 */ 375 virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySessionProxy, 376 bool svp) = 0; 377 378 #ifdef SUPPORT_VIDEO 379 /** 380 * @brief Method to set the surface. 381 * 382 * @param surface pointer of the surface. 383 * @return Returns {@link MSERR_OK} if the surface is set; returns an error code defined 384 * in {@link media_errors.h} otherwise. 385 * @since 1.0 386 * @version 1.0 387 */ 388 virtual int32_t SetVideoSurface(sptr<Surface> surface) = 0; 389 #endif 390 391 /** 392 * @brief Checks whether the player is playing. 393 * 394 * @return Returns true if the playback is playing; false otherwise. 395 * @since 1.0 396 * @version 1.0 397 */ 398 virtual bool IsPlaying() = 0; 399 400 /** 401 * @brief Returns the value whether single looping is enabled or not . 402 * 403 * @return Returns true if the playback is single looping; false otherwise. 404 * @since 1.0 405 * @version 1.0 406 */ 407 virtual bool IsLooping() = 0; 408 409 /** 410 * @brief Enables single looping of the media playback. 411 * 412 * @return Returns {@link MSERR_OK} if the single looping is set; 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 SetLooping(bool loop) = 0; 418 419 /** 420 * @brief Enables setting the renderer descriptor for the current media 421 * 422 * @return Returns {@link MSERR_OK} if the renderer descriptor is set; 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 SetParameter(const Format ¶m) = 0; 428 429 /** 430 * @brief Method to set player callback. 431 * 432 * @param callback object pointer. 433 * @return Returns {@link MSERR_OK} if the playercallback is set; returns an error code defined 434 * in {@link media_errors.h} otherwise. 435 * @since 1.0 436 * @version 1.0 437 */ 438 virtual int32_t SetPlayerCallback(const std::shared_ptr<PlayerCallback> &callback) = 0; 439 440 /** 441 * @brief Select audio or subtitle track. 442 * By default, the first audio stream with data is played, and the subtitle track is not played. 443 * After the settings take effect, the original track will become invalid. 444 * Please set it in the prepared/playing/paused/completed state. 445 * 446 * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. 447 * @return Returns {@link MSERR_OK} if selected successfully; returns an error code defined 448 * in {@link media_errors.h} otherwise. 449 * @since 1.0 450 * @version 1.0 451 */ 452 virtual int32_t SelectTrack(int32_t index, PlayerSwitchMode mode = PlayerSwitchMode::SWITCH_SMOOTH) = 0; 453 454 /** 455 * @brief Deselect the current audio or subtitle track. 456 * After audio is deselected, the default track will be played, and after subtitles are deselected, 457 * they will not be played. Please set it in the prepared/playing/paused/completed state. 458 * 459 * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. 460 * @return Returns {@link MSERR_OK} if selected successfully; returns an error code defined 461 * in {@link media_errors.h} otherwise. 462 * @since 1.0 463 * @version 1.0 464 */ 465 virtual int32_t DeselectTrack(int32_t index) = 0; 466 467 /** 468 * @brief Obtain the currently effective track index. 469 * 470 * @param trackType Media type. 471 * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. 472 * @return Returns {@link MSERR_OK} if the track index is get; returns an error code defined 473 * in {@link media_errors.h} otherwise. 474 * @since 1.0 475 * @version 1.0 476 */ 477 virtual int32_t GetCurrentTrack(int32_t trackType, int32_t &index) = 0; 478 479 /** 480 * @brief Obtains the subtitle track info, contains mimeType, type, language. 481 * 482 * @param subtitle track info vec. 483 * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined 484 * in {@link media_errors.h} otherwise. 485 * @since 1.0 486 * @version 1.0 487 */ 488 virtual int32_t GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack) = 0; 489 490 /** 491 * @brief set the playback strategy 492 * the playback strategy includes five fileds: 493 * preferredWidth: Preferred width, which is of the int type, for example, 1080. 494 * preferredHeight: Preferred height, which is of the int type, for example, 1920. 495 * preferredBufferDuration: Preferred buffer duration, in seconds. The value ranges from 1 to 20. 496 * preferredHdr: Whether HDR is preferred. The value true means that HDR is preferred, and false means the opposite. 497 * mutedMediaType: The mediaType to be muted before play, which is of the MediaType type, 498 * for example, MediaType::MEDIA_TYPE_AUD. 499 * @param playbackStrategy the playback strategy. 500 * @return Returns {@link MSERR_OK} if the playback strategy is set successfully; returns an error code defined 501 * in {@link media_errors.h} otherwise. 502 * @since 1.0 503 * @version 1.0 504 */ SetPlaybackStrategy(AVPlayStrategy playbackStrategy)505 virtual int32_t SetPlaybackStrategy(AVPlayStrategy playbackStrategy) 506 { 507 (void)playbackStrategy; 508 return 0; 509 } 510 SetMediaMuted(MediaType mediaType,bool isMuted)511 virtual int32_t SetMediaMuted(MediaType mediaType, bool isMuted) 512 { 513 (void)mediaType; 514 (void)isMuted; 515 return 0; 516 } 517 518 /** 519 * @brief Set get max ampliutude callback status. 520 * 521 * @param status callback status. 522 * @return Returns {@link MSERR_OK} if the callback status is set; returns an error code defined 523 * in {@link media_errors.h} otherwise. 524 * @since 1.0 525 * @version 1.0 526 */ SetMaxAmplitudeCbStatus(bool status)527 virtual int32_t SetMaxAmplitudeCbStatus(bool status) 528 { 529 (void)status; 530 return 0; 531 } 532 533 /** 534 * @brief set get device change callback status. 535 * 536 * @return Returns {@link MSERR_OK} if the single display is set; returns an error code defined 537 * in {@link media_errors.h} otherwise. 538 * @since 1.0 539 * @version 1.0 540 */ SetDeviceChangeCbStatus(bool status)541 virtual int32_t SetDeviceChangeCbStatus(bool status) 542 { 543 (void)status; 544 return 0; 545 } 546 /** 547 * @brief Obtain the api version of application. 548 * 549 * @return Returns {@link MSERR_OK} if the current api version is get; returns an error code defined 550 * in {@link media_errors.h} otherwise. 551 * @since 1.0 552 * @version 1.0 553 */ GetApiVersion(int32_t & apiVersion)554 virtual int32_t GetApiVersion(int32_t &apiVersion) 555 { 556 (void)apiVersion; 557 return 0; 558 } 559 560 /** 561 * @brief Checks whether the player supports SeekContinuous. 562 * 563 * @return Returns true if the player supports SeekContinuous; false otherwise. 564 * @since 1.0 565 * @version 1.0 566 */ 567 virtual bool IsSeekContinuousSupported() = 0; 568 }; 569 } // namespace Media 570 } // namespace OHOS 571 #endif // I_PLAYER_SERVICE_H 572