1 /*
2  * Copyright (c) 2022 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 OHOS_AVSESSION_CONTROLLER_H
17 #define OHOS_AVSESSION_CONTROLLER_H
18 
19 #include <bitset>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "avcontrol_command.h"
25 #include "avsession_info.h"
26 #include "key_event.h"
27 #include "want_agent.h"
28 
29 /**
30  * @brief Session controller instance.
31  * @since 9
32  */
33 namespace OHOS::AVSession {
34 class AVSessionController {
35 public:
36     /**
37      * @brief Get current avcall status infos.
38      *
39      * @param state Current avcall status infos {@link AVCallState}.
40      * @return Returns check whether the system permissions are supported
41      * @since 11
42     */
43     virtual int32_t GetAVCallState(AVCallState& avCallState) = 0;
44 
45     /**
46      * @brief Get current avcall meta data infos.
47      *
48      * @param state Current avcall meta data infos {@link AVCallMetaData}.
49      * @return Returns check whether the system permissions are supported
50      * @since 11
51     */
52     virtual int32_t GetAVCallMetaData(AVCallMetaData& avCallMetaData) = 0;
53     /**
54      * @brief Get current playing status infos.
55      *
56      * @param state Current playing status infos {@link AVPlaybackState}.
57      * @return Returns check whether the system permissions are supported
58      * @since 9
59     */
60     virtual int32_t GetAVPlaybackState(AVPlaybackState& state) = 0;
61 
62     /**
63      * @brief Get current playing status infos.
64      *
65      * @param state Current playing status infos {@link AVPlaybackState}.
66      * @return Returns check whether the system permissions are supported
67      * @since 9
68     */
69     virtual int32_t GetAVMetaData(AVMetaData& data) = 0;
70 
71     /**
72      * Send key events to the corresponding session of the controller.
73      *
74      * @param keyEvent key event.
75      * @return int32_t Return whether sending succeeded.
76      * @since 9
77     */
78     virtual int32_t SendAVKeyEvent(const MMI::KeyEvent& keyEvent) = 0;
79 
80     /**
81      * Get the WantAgent object saved by the application in the session.
82      *
83      * @param ability Objects saved in setLaunchAbility.
84      * @return int32_t Successfully obtained.
85      * @since 9
86     */
87     virtual int32_t GetLaunchAbility(AbilityRuntime::WantAgent::WantAgent& ability) = 0;
88 
89     /**
90      * Get valid commands supported by the session.
91      *
92      * @param cmds Returns a collection of valid commands.
93      * @return int32_t Whether the valid commands supported by the session are obtained successfully.
94      * @since 9
95     */
96     virtual int32_t GetValidCommands(std::vector<int32_t>& cmds) = 0;
97 
98     /**
99      * Whether the session is active.
100      *
101      * @param isActive Whether the session is active.
102      * @return int32_t Returns whether the status was obtained successfully.
103      * @since 9
104     */
105     virtual int32_t IsSessionActive(bool& isActive) = 0;
106 
107     /**
108      * Send commands to its corresponding session through the controller.
109      *
110      * @param cmd Commands and parameters related to the session {@link AVControlCommand}.
111      * @return int32_t Return whether sending succeeded.
112      * @since 9
113     */
114     virtual int32_t SendControlCommand(const AVControlCommand& cmd) = 0;
115 
116     /**
117      * Send common commands to its corresponding session through the controller.
118      *
119      * @param commonCommand The name of the command to be sent.
120      * @param commandArgs Command packets to be sent
121      * @return int32_t Return whether sending succeeded.
122      * @since 10
123     */
124     virtual int32_t SendCommonCommand(const std::string& commonCommand, const AAFwk::WantParams& commandArgs) = 0;
125 
126     /**
127      * @brief Listen for AVController Callback event.
128      *
129      * @param callback Listen for AVController Callback event{@link AVControllerCallback}.
130      * @return Returns whether the return is successful.
131      * @since 9
132     */
133     virtual int32_t RegisterCallback(const std::shared_ptr<AVControllerCallback>& callback) = 0;
134 
135     /**
136      * @brief Set avcall meta filter.
137      *
138      * @param filter AVCall Meta filter{@link AVCallMetaMaskType}.
139      * @return Returns whether set successful.
140      * @since 9
141     */
142     virtual int32_t SetAVCallMetaFilter(const AVCallMetaData::AVCallMetaMaskType& filter) = 0;
143 
144     /**
145      * @brief Set avcall state filter.
146      *
147      * @param filter AVCall State {@link AVCallStateMaskType}.
148      * @return Returns whether set successful.
149      * @since 9
150     */
151     virtual int32_t SetAVCallStateFilter(const AVCallState::AVCallStateMaskType& filter) = 0;
152 
153     /**
154      * @brief Set meta filter.
155      *
156      * @param filter Meta filter{@link MetaMaskType}.
157      * @return Returns whether set successful.
158      * @since 9
159     */
160     virtual int32_t SetMetaFilter(const AVMetaData::MetaMaskType& filter) = 0;
161 
162     /**
163      * @brief Set Playback filter.
164      *
165      * @param filter Playback State {@link MetaMaskType}.
166      * @return Returns whether set successful.
167      * @since 9
168     */
169     virtual int32_t SetPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter) = 0;
170 
171     /**
172      * @brief Get the playlist. Which is the content of the playlist presented by this session.
173      *
174      * @param items An array of the AVQueueItem.
175      * @return Return whether the obtain is successful.
176      * @since 10
177     */
178     virtual int32_t GetAVQueueItems(std::vector<AVQueueItem>& items) = 0;
179 
180     /**
181      * @brief Get the name of the playlist presented by this session.
182      *
183      * @param title The name of the playlist.
184      * @return Return whether the get is successful.
185      * @since 10
186      */
187     virtual int32_t GetAVQueueTitle(std::string& title) = 0;
188 
189     /**
190      * @brief Set the item in the playlist to be played.
191      *
192      * @param itemId The serial number of the item to be played.
193      * @return Return whether the operation is successful.
194      * @since 10
195      */
196     virtual int32_t SkipToQueueItem(int32_t& itemId) = 0;
197 
198     /**
199      * @brief Get custom media packet.
200      *
201      * @param extras Custom media packet key-value pairs
202      * @return Return whether the operation is successful
203      * @since 10
204     */
205     virtual int32_t GetExtras(AAFwk::WantParams& extras) = 0;
206 
207     /**
208      * @brief Destroy session.
209      *
210      * @return Returns whether destroy successful.
211      * @since 9
212     */
213     virtual int32_t Destroy() = 0;
214 
215     /**
216      * @brief Get session id.
217      *
218      * @return Returns session id.
219      * @since 9
220     */
221     virtual std::string GetSessionId() = 0;
222 
223     /**
224      * @brief Get current playback position.
225      *
226      * @return Returns current playback position.
227      * @since 9
228     */
229     virtual int64_t GetRealPlaybackPosition() = 0;
230 
231     /**
232      * @brief Controller is or not destroy.
233      *
234      * @return Returns controller is or not destroy.
235      * @since 9
236     */
237     virtual bool IsDestroy() = 0;
238 
239     /**
240      * @brief Deconstruct AVSessionController.
241      * @since 9
242     */
243     virtual ~AVSessionController() = default;
244 };
245 } // namespace OHOS::AVSession
246 
247 #endif // OHOS_AVSESSION_CONTROLLER_H
248