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