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