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