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 Prepares the playback environment and buffers media data asynchronous. 109 * 110 * This function must be called after {@link SetSource}. 111 * 112 * @return Returns {@link MSERR_OK} if {@link PrepareAsync} is successfully added to the task queue; 113 * returns an error code defined in {@link media_errors.h} otherwise. 114 * @since 1.0 115 * @version 1.0 116 */ 117 virtual int32_t PrepareAsync() = 0; 118 119 /** 120 * @brief Pauses playback. 121 * 122 * @return Returns {@link MSERR_OK} if {@link Pause} is successfully added to the task queue; 123 * returns an error code defined in {@link media_errors.h} otherwise. 124 * @since 1.0 125 * @version 1.0 126 */ 127 virtual int32_t Pause() = 0; 128 129 /** 130 * @brief Stop playback. 131 * 132 * @return Returns {@link MSERR_OK} if {@link Stop} is successfully added to the task queue; 133 * returns an error code defined in {@link media_errors.h} otherwise. 134 * @since 1.0 135 * @version 1.0 136 */ 137 virtual int32_t Stop() = 0; 138 139 /** 140 * @brief Restores the player to the initial state. 141 * 142 * After the function is called, add a playback source by calling {@link SetSource}, 143 * call {@link Play} to start playback again after {@link Prepare} is called. 144 * 145 * @return Returns {@link MSERR_OK} if {@link Reset} is successfully added to the task queue; 146 * returns an error code defined in {@link media_errors.h} otherwise. 147 * @since 1.0 148 * @version 1.0 149 */ 150 virtual int32_t Reset() = 0; 151 152 /** 153 * @brief Releases player resources async 154 * 155 * @return Returns {@link MSERR_OK} if {@link Release} is successfully added to the task queue; 156 * returns an error code defined in {@link media_errors.h} otherwise. 157 * @since 1.0 158 * @version 1.0 159 */ 160 virtual int32_t Release() = 0; 161 162 /** 163 * @brief Releases player resources sync 164 * 165 * @return Returns {@link MSERR_OK} if the playback is released; returns an error code defined 166 * in {@link media_errors.h} otherwise. 167 * @since 1.0 168 * @version 1.0 169 */ ReleaseSync()170 virtual int32_t ReleaseSync() 171 { 172 return ERR_OK; 173 } 174 175 /** 176 * @brief Sets the volume of the player. 177 * 178 * This function can be used during playback or pause. The value <b>0</b> indicates no sound, 179 * and <b>1</b> indicates the original volume. If no audio device is started or no audio 180 * stream exists, the value <b>-1</b> is returned. 181 * 182 * @param leftVolume Indicates the target volume of the left audio channel to set, 183 * ranging from 0 to 1. each step is 0.01. 184 * @param rightVolume Indicates the target volume of the right audio channel to set, 185 * ranging from 0 to 1. each step is 0.01. 186 * @return Returns {@link MSERR_OK} if the volume is set; returns an error code defined 187 * in {@link media_errors.h} otherwise. 188 * @since 1.0 189 * @version 1.0 190 */ 191 virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0; 192 193 /** 194 * @brief Changes the playback position. 195 * 196 * This function can be used during play or pause. 197 * 198 * @param mSeconds Indicates the target playback position, accurate to second. 199 * @param mode Indicates the player seek mode. For details, see {@link PlayerSeekMode}. 200 * @return Returns {@link MSERR_OK} if the seek is done; returns an error code defined 201 * in {@link media_errors.h} otherwise. 202 * @since 1.0 203 * @version 1.0 204 */ 205 virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0; 206 207 /** 208 * @brief Obtains the playback position, accurate to millisecond. 209 * 210 * @param currentTime Indicates the playback position. 211 * @return Returns {@link MSERR_OK} if the current position is get; returns an error code defined 212 * in {@link media_errors.h} otherwise. 213 * @since 1.0 214 * @version 1.0 215 */ 216 virtual int32_t GetCurrentTime(int32_t ¤tTime) = 0; 217 218 /** 219 * @brief Obtains the video track info, contains mimeType, bitRate, width, height, frameRata. 220 * 221 * @param video track info vec. 222 * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined 223 * in {@link media_errors.h} otherwise. 224 * @since 1.0 225 * @version 1.0 226 */ 227 virtual int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack) = 0; 228 229 /** 230 * @brief Obtains the audio track info, contains mimeType, bitRate, sampleRate, channels, language. 231 * 232 * @param audio track info vec. 233 * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined 234 * in {@link media_errors.h} otherwise. 235 * @since 1.0 236 * @version 1.0 237 */ 238 virtual int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0; 239 240 /** 241 * @brief get the video width. 242 * 243 * @return Returns width if success; else returns 0 244 * @since 1.0 245 * @version 1.0 246 */ 247 virtual int32_t GetVideoWidth() = 0; 248 249 /** 250 * @brief get the video height. 251 * 252 * @return Returns height if success; else returns 0 253 * @since 1.0 254 * @version 1.0 255 */ 256 virtual int32_t GetVideoHeight() = 0; 257 258 /** 259 * @brief Obtains the total duration of media files, accurate to milliseconds. 260 * 261 * @param duration Indicates the total duration of media files. 262 * @return Returns {@link MSERR_OK} if the current duration is get; returns an error code defined 263 * in {@link media_errors.h} otherwise. 264 * @since 1.0 265 * @version 1.0 266 */ 267 virtual int32_t GetDuration(int32_t &duration) = 0; 268 269 /** 270 * @brief set the player playback rate 271 * 272 * @param mode the rate mode {@link PlaybackRateMode} which can set. 273 * @return Returns {@link MSERR_OK} if the playback rate is set successfully; returns an error code defined 274 * in {@link media_errors.h} otherwise. 275 * @since 1.0 276 * @version 1.0 277 */ 278 virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0; 279 280 /** 281 * @brief set the bit rate use for hls player 282 * 283 * @param bitRate the bit rate. 284 * @return Returns {@link MSERR_OK} if the bit rate is set successfully; 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 SelectBitRate(uint32_t bitRate) = 0; 290 291 /** 292 * @brief get the current player playback rate 293 * 294 * @param mode the rate mode {@link PlaybackRateMode} which can get. 295 * @return Returns {@link MSERR_OK} if the current player playback rate 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 GetPlaybackSpeed(PlaybackRateMode &mode) = 0; 301 302 /** 303 * @brief add for drm, set decrypt module 304 * 305 * @param keySessionProxy is the sptr will be setted to playerserver. 306 * @param svp bool. 307 * @return Returns {@link MSERR_OK} if set successfully; returns an error code defined 308 * in {@link media_errors.h} otherwise. 309 * @since 310 * @version 311 */ 312 virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySessionProxy, 313 bool svp) = 0; 314 315 #ifdef SUPPORT_VIDEO 316 /** 317 * @brief Method to set the surface. 318 * 319 * @param surface pointer of the surface. 320 * @return Returns {@link MSERR_OK} if the surface is set; returns an error code defined 321 * in {@link media_errors.h} otherwise. 322 * @since 1.0 323 * @version 1.0 324 */ 325 virtual int32_t SetVideoSurface(sptr<Surface> surface) = 0; 326 #endif 327 328 /** 329 * @brief Checks whether the player is playing. 330 * 331 * @return Returns true if the playback is playing; false otherwise. 332 * @since 1.0 333 * @version 1.0 334 */ 335 virtual bool IsPlaying() = 0; 336 337 /** 338 * @brief Returns the value whether single looping is enabled or not . 339 * 340 * @return Returns true if the playback is single looping; false otherwise. 341 * @since 1.0 342 * @version 1.0 343 */ 344 virtual bool IsLooping() = 0; 345 346 /** 347 * @brief Enables single looping of the media playback. 348 * 349 * @return Returns {@link MSERR_OK} if the single looping is set; 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 SetLooping(bool loop) = 0; 355 356 /** 357 * @brief Enables setting the renderer descriptor for the current media 358 * 359 * @return Returns {@link MSERR_OK} if the renderer descriptor is set; returns an error code defined 360 * in {@link media_errors.h} otherwise. 361 * @since 1.0 362 * @version 1.0 363 */ 364 virtual int32_t SetParameter(const Format ¶m) = 0; 365 366 /** 367 * @brief Method to set player callback. 368 * 369 * @param callback object pointer. 370 * @return Returns {@link MSERR_OK} if the playercallback is set; returns an error code defined 371 * in {@link media_errors.h} otherwise. 372 * @since 1.0 373 * @version 1.0 374 */ 375 virtual int32_t SetPlayerCallback(const std::shared_ptr<PlayerCallback> &callback) = 0; 376 377 /** 378 * @brief Select audio or subtitle track. 379 * By default, the first audio stream with data is played, and the subtitle track is not played. 380 * After the settings take effect, the original track will become invalid. 381 * Please set it in the prepared/playing/paused/completed state. 382 * 383 * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. 384 * @return Returns {@link MSERR_OK} if selected successfully; returns an error code defined 385 * in {@link media_errors.h} otherwise. 386 * @since 1.0 387 * @version 1.0 388 */ 389 virtual int32_t SelectTrack(int32_t index) = 0; 390 391 /** 392 * @brief Deselect the current audio or subtitle track. 393 * After audio is deselected, the default track will be played, and after subtitles are deselected, 394 * they will not be played. Please set it in the prepared/playing/paused/completed state. 395 * 396 * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. 397 * @return Returns {@link MSERR_OK} if selected successfully; returns an error code defined 398 * in {@link media_errors.h} otherwise. 399 * @since 1.0 400 * @version 1.0 401 */ 402 virtual int32_t DeselectTrack(int32_t index) = 0; 403 404 /** 405 * @brief Obtain the currently effective track index. 406 * 407 * @param trackType Media type. 408 * @param index Track index, reference {@link #GetAudioTrackInfo} and {@link #GetVideoTrackInfo}. 409 * @return Returns {@link MSERR_OK} if the track index is get; 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 GetCurrentTrack(int32_t trackType, int32_t &index) = 0; 415 416 /** 417 * @brief Obtains the subtitle track info, contains mimeType, type, language. 418 * 419 * @param subtitle track info vec. 420 * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined 421 * in {@link media_errors.h} otherwise. 422 * @since 1.0 423 * @version 1.0 424 */ 425 virtual int32_t GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack) = 0; 426 }; 427 } // namespace Media 428 } // namespace OHOS 429 #endif // I_PLAYER_SERVICE_H 430