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