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