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