1 /*
2  * Copyright (c) 2022-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 OHOS_AVSESSION_H
17 #define OHOS_AVSESSION_H
18 
19 #include <string>
20 #include <memory>
21 
22 #include "avsession_info.h"
23 #include "want_agent.h"
24 #include "want_params.h"
25 #include "avsession_controller.h"
26 
27 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
28 #include "avcast_controller.h"
29 #endif
30 
31 /**
32  * @brief Session, which can be used to set metadata, play status information and other operations.
33  * @since 9
34  */
35 namespace OHOS::AVSession {
36 class AVSession {
37 public:
38     enum {
39         SESSION_TYPE_INVALID = -1,
40         SESSION_TYPE_AUDIO = 0,
41         SESSION_TYPE_VIDEO = 1,
42         SESSION_TYPE_VOICE_CALL = 2,
43         SESSION_TYPE_VIDEO_CALL = 3
44     };
45 
46     /**
47      * @brief Get current session id.
48      *
49      * @return Returns current session id.
50      * @since 9
51     */
52     virtual std::string GetSessionId() = 0;
53 
54     /**
55      * @brief Get current session id.
56      *
57      * @return Returns current session id.
58      * @since 9
59     */
60     virtual std::string GetSessionType() = 0;
61 
62     /**
63      * Get the metadata of the current session.
64      * @param AVMetadata Session metadata {@link AVMetadata}.
65      * @since 9
66     */
67     virtual int32_t GetAVMetaData(AVMetaData& meta) = 0;
68 
69     /**
70      * Set session metadata.
71      * @param AVMetadata Session metadata {@link AVMetadata}.
72      * @since 9
73     */
74     virtual int32_t SetAVMetaData(const AVMetaData& meta) = 0;
75 
76     /**
77      * Set the metadata related with current call.
78      * @param { AVCallMetadata } data {@link AVCallMetadata}
79      * @since 11
80      */
81     virtual int32_t SetAVCallMetaData(const AVCallMetaData& meta) = 0;
82 
83     /**
84      * @brief Set session avcall status information.
85      *
86      * @param state Current avcall status infos {@link AVCallState}.
87      * @return Return whether the setting is successful.
88      * @since 11
89     */
90     virtual int32_t SetAVCallState(const AVCallState& avCallState) = 0;
91 
92     /**
93      * @brief Get current playing status infos.
94      *
95      * @param state Current playing status infos {@link AVPlaybackState}.
96      * @return Returns check whether the system permissions are supported.
97      * @since 9
98     */
99     virtual int32_t GetAVPlaybackState(AVPlaybackState& state) = 0;
100 
101     /**
102      * @brief Set session playback status information.
103      *
104      * @param state Current playing status infos {@link AVPlaybackState}.
105      * @return Return whether the setting is successful.
106      * @since 9
107     */
108     virtual int32_t SetAVPlaybackState(const AVPlaybackState& state) = 0;
109 
110     /**
111      * @brief Get the playlist. Which is the content of the playlist presented by this session.
112      *
113      * @param items An array of the AVQueueItem.
114      * @return Return whether the obtain is successful.
115      * @since 10
116     */
117     virtual int32_t GetAVQueueItems(std::vector<AVQueueItem>& items) = 0;
118 
119     /**
120      * @brief Set the playlist. Identifies the content of the playlist presented by this session.
121      *
122      * @param items An array of the AVQueueItem.
123      * @return Return whether the setting is successful.
124      * @since 10
125     */
126     virtual int32_t SetAVQueueItems(const std::vector<AVQueueItem>& items) = 0;
127 
128     /**
129      * @brief Get the name of the playlist presented by this session.
130 
131      * @param title The name of the playlist.
132      * @return Return whether the get is successful.
133      * @since 10
134      */
135     virtual int32_t GetAVQueueTitle(std::string& title) = 0;
136 
137     /**
138      * @brief Set the name of the playlist presented by this session.
139 
140      * @param title The name of the playlist.
141      * @return Return whether the set is successful.
142      * @since 10
143      */
144     virtual int32_t SetAVQueueTitle(const std::string& title) = 0;
145 
146     /**
147      * @brief Set a WantAgent's ability to pull up the session.
148      *
149      * @param ability Relevant attribute information of the application{@link WantAgent}.
150      * @return Return whether the setting is successful.
151      * @since 9
152     */
153     virtual int32_t SetLaunchAbility(const AbilityRuntime::WantAgent::WantAgent& ability) = 0;
154 
155     /**
156      * @brief Get custom media packet.
157      *
158      * @param extras Custom media packet key-value pairs passed
159      * @return Return whether the getting is successful
160      * @since 10
161     */
162     virtual int32_t GetExtras(AAFwk::WantParams& extras) = 0;
163 
164     /**
165      * @brief Set custom media packet.
166      *
167      * @param extras Custom media packet key-value pairs passed
168      * @return Return whether the setting is successful
169      * @since 10
170     */
171     virtual int32_t SetExtras(const AAFwk::WantParams& extras) = 0;
172 
173     /**
174      * @brief Get the controller corresponding to this session.
175      *
176      * @return Return to session controller{@link AVSessionController}.
177      * @since 9
178     */
179     virtual std::shared_ptr<AVSessionController> GetController() = 0;
180 
181     /**
182      * @brief Listen for AVSession Callback event.
183      *
184      * @param callback Listen for AVSession Callback event{@link AVSessionCallback}.
185      * @return Returns whether the return is successful.
186      * @since 9
187     */
188     virtual int32_t RegisterCallback(const std::shared_ptr<AVSessionCallback>& callback) = 0;
189 
190     /**
191      * @brief Activate session.
192      *
193      * @return Return whether the setting is successful
194      * @since 9
195     */
196     virtual int32_t Activate() = 0;
197 
198     /**
199      * @brief Disable the function of the current session.
200      *
201      * @return Return whether the setting is successful
202      * @since 9
203     */
204     virtual int32_t Deactivate() = 0;
205 
206     /**
207      * @brief Get whether the session is activated.
208      *
209      * @return Return whether the setting is successful
210      * @since 9
211     */
212     virtual bool IsActive() = 0;
213 
214     /**
215      * @brief Destroy session.
216      *
217      * @return Return whether the setting is successful
218      * @since 9
219     */
220     virtual int32_t Destroy() = 0;
221 
222     /**
223      * @brief Add Support Command.
224      *
225      * @param cmd Commands to be added.
226      * @return Return whether the addition was successful.
227      * @since 9
228     */
229     virtual int32_t AddSupportCommand(const int32_t cmd) = 0;
230 
231     /**
232      * @brief Delete Support Command.
233      *
234      * @param cmd Commands to be deleted.
235      * @return Return whether the deletion was successful.
236      * @since 9
237     */
238     virtual int32_t DeleteSupportCommand(const int32_t cmd) = 0;
239 
240     /**
241      * @brief Set session events.
242      *
243      * @param event Name of the session event set
244      * @param args Session event key-value pairs passed
245      * @return Return whether the setting is successful
246      * @since 9
247     */
248     virtual int32_t SetSessionEvent(const std::string& event, const AAFwk::WantParams& args) = 0;
249 
250 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
251     /**
252      * @brief Get the controller corresponding to this session.
253      *
254      * @return { std::shared_ptr<AVCastController> } Return AVCast controller.
255      * @since 10
256     */
257     virtual std::shared_ptr<AVCastController> GetAVCastController() = 0;
258 
259     /**
260      * @brief Release cast process.
261      *
262      * @return { int32_t } Return whether the release is successful
263      * @since 10
264     */
265     virtual int32_t ReleaseCast() = 0;
266 
267     /**
268      * @brief Start to listen castDisplay event.
269      *
270      * @return { int32_t } Return whether the StartCastDisplayListener is successful
271      * @since 10
272     */
273     virtual int32_t StartCastDisplayListener() = 0;
274 
275     /**
276      * @brief Stop to listen castDisplay event.
277      *
278      * @return { int32_t } Return whether the StartCastDisplayListener is successful
279      * @since 10
280     */
281     virtual int32_t StopCastDisplayListener() = 0;
282 
283     /**
284      * @brief Get all castDisplays.
285      *
286      * @param CastDisplay array.
287      * @return { int32_t } Return whether the GetAllCastDisplays is successful
288      * @since 10
289     */
290     virtual int32_t GetAllCastDisplays(std::vector<CastDisplayInfo>& castDisplays) = 0;
291 #endif
292 
293     /**
294      * @brief Deconstruct AVSession object.
295      *
296      * @since 9
297     */
298     virtual ~AVSession() = default;
299 };
300 } // namespace OHOS::AVSession
301 #endif // OHOS_AVSESSION_H
302