1 /* 2 * Copyright (c) 2023 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 MEDIA_ADAPTER_H 17 #define MEDIA_ADAPTER_H 18 19 #include <string> 20 21 #include "graphic_adapter.h" 22 23 namespace OHOS::NWeb { 24 enum class PlayerAdapterErrorType : int32_t { 25 INVALID_CODE = -1, 26 UNSUPPORT_TYPE, 27 FATAL_ERROR, 28 }; 29 30 enum class PlayerOnInfoType : int32_t { 31 INFO_TYPE_UNSET = -1, 32 INFO_TYPE_SEEKDONE = 1, 33 INFO_TYPE_EOS = 4, 34 INFO_TYPE_STATE_CHANGE, 35 INFO_TYPE_POSITION_UPDATE, 36 INFO_TYPE_MESSAGE, 37 INFO_TYPE_INTERRUPT_EVENT, 38 }; 39 40 enum class PlayerSeekMode : int32_t { 41 SEEK_NEXT_SYNC = 0, 42 SEEK_PREVIOUS_SYNC, 43 SEEK_CLOSEST_SYNC, 44 SEEK_CLOSEST, 45 }; 46 47 enum class PlaybackRateMode : int32_t { 48 SPEED_FORWARD_0_75_X, 49 SPEED_FORWARD_1_00_X, 50 SPEED_FORWARD_1_25_X, 51 SPEED_FORWARD_1_75_X, 52 SPEED_FORWARD_2_00_X, 53 }; 54 55 class PlayerCallbackAdapter { 56 public: 57 virtual ~PlayerCallbackAdapter() = default; 58 59 virtual void OnInfo(PlayerOnInfoType type, int32_t extra, int32_t value) = 0; 60 61 virtual void OnError(PlayerAdapterErrorType errorType) = 0; 62 }; 63 64 class PlayerAdapter { 65 public: 66 enum PlayerStates : int32_t { 67 PLAYER_STATE_ERROR = 0, 68 PLAYER_IDLE = 1, 69 PLAYER_INITIALIZED = 2, 70 PLAYER_PREPARING = 3, 71 PLAYER_PREPARED = 4, 72 PLAYER_STARTED = 5, 73 PLAYER_PAUSED = 6, 74 PLAYER_STOPPED = 7, 75 PLAYER_PLAYBACK_COMPLETE = 8, 76 PLAYER_RELEASED = 9, 77 }; 78 79 PlayerAdapter() = default; 80 81 virtual ~PlayerAdapter() = default; 82 83 virtual int32_t SetPlayerCallback(std::unique_ptr<PlayerCallbackAdapter> callbackAdapter) = 0; 84 85 virtual int32_t SetSource(const std::string& url) = 0; 86 87 virtual int32_t SetSource(int32_t fd, int64_t offset = 0, int64_t size = 0) = 0; 88 89 virtual int32_t SetVideoSurface(IConsumerSurfaceAdapter* cSurfaceAdapter) = 0; 90 91 virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0; 92 93 virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0; 94 95 virtual int32_t Play() = 0; 96 97 virtual int32_t Pause() = 0; 98 99 virtual int32_t PrepareAsync() = 0; 100 101 virtual int32_t GetCurrentTime(int32_t& currentTime) = 0; 102 103 virtual int32_t GetDuration(int32_t& duration) = 0; 104 105 virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0; 106 }; 107 } // namespace OHOS::NWeb 108 109 #endif // MEDIA_ADAPTER_H 110