• 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_MANAGER_H
17 #define OHOS_AVSESSION_MANAGER_H
18 
19 #include <functional>
20 #include <string>
21 #include <memory>
22 
23 #include "audio_system_manager.h"
24 #include "av_session.h"
25 #include "avsession_controller.h"
26 #include "avsession_info.h"
27 #include "key_event.h"
28 #include "avqueue_info.h"
29 
30 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
31 #include "avcast_controller.h"
32 #endif
33 
34 namespace OHOS::AVSession {
35 class AVSessionManager {
36 public:
37     /**
38      * Get AVSessionManager instance.
39      *
40      * @return AVSessionManager instance.
41      * @since 7
42     */
43     static AVSessionManager& GetInstance();
44 
45     /**
46      * Create Session Object.
47      *
48      * @param tag Custom name of the session
49      * @param type Session type
50      * @param elementName element Name
51      * @return Returns Session Object
52      * @since 7
53     */
54     virtual std::shared_ptr<AVSession> CreateSession(const std::string& tag, int32_t type,
55                                                      const AppExecFwk::ElementName& elementName) = 0;
56 
57     /**
58      * Create Session Object.
59      *
60      * @param tag Custom name of the session
61      * @param type Session type
62      * @param elementName element Name
63      * @param session Created session {@link AVSession}
64      * @return Returns result of creating session
65      * @since 12
66     */
67     virtual int32_t CreateSession(const std::string& tag, int32_t type, const AppExecFwk::ElementName& elementName,
68                                   std::shared_ptr<AVSession>& session) = 0;
69 
70     /**
71      * Create Session Object.
72      *
73      * @param tag Custom name of the session
74      * @param type Session type
75      * @param extraInfo extra info
76      * @param elementName element Name
77      * @param session Created session {@link AVSession}
78      * @return Returns result of creating session
79      * @since 20
80     */
81     virtual int32_t CreateSessionWithExtra(const std::string& tag, int32_t type, const std::string& extraInfo,
82                                           const AppExecFwk::ElementName& elementName,
83                                           std::shared_ptr<AVSession>& session) = 0;
84 
85     /**
86      * Send the key command to get the descriptor of all sessions.
87      *
88      * @param descriptors Get relevant descriptions of all sessions
89      * @return Whether the relevant descriptions of all sessions are obtained successfully
90      * @since 9
91     */
92     virtual int32_t GetAllSessionDescriptors(std::vector<AVSessionDescriptor>& descriptors) = 0;
93 
94     /**
95      * Send the key command to get the descriptor of activated sessions.
96      *
97      * @param activatedSessions Get relevant descriptions of activated sessions
98      * @return Returns whether the relevant descriptions of activated sessions are obtained successfully
99      * @since 9
100     */
101     virtual int32_t GetActivatedSessionDescriptors(std::vector<AVSessionDescriptor>& activatedSessions) = 0;
102 
103     /**
104      * Get SessionDescriptors By SessionId.
105      *
106      * @param sessionId current session id.
107      * @param descriptor obtain SessionDescriptors {@link AVSessionDescriptor}.
108      * @return Returns whether to obtain SessionDescriptors successfully.
109      * @since 9
110     */
111     virtual int32_t GetSessionDescriptorsBySessionId(const std::string& sessionId, AVSessionDescriptor& descriptor) = 0;
112 
113     /**
114      * Get historical session Descriptors.
115      *
116      * @param maxSize data write maxSize.
117      * @param descriptors obtain SessionDescriptors {@link AVSessionDescriptor}.
118      * @return Returns whether to obtain SessionDescriptors successfully.
119      * @since 9
120     */
121     virtual int32_t GetHistoricalSessionDescriptors(int32_t maxSize, std::vector<AVSessionDescriptor>& descriptors) = 0;
122 
123     /**
124      * Get historical AVQueueInfo.
125      *
126      * @param maxSize data write maxSize.
127      * @param maxAppSize max app count.
128      * @param avQueueInfo obtain history play avqueue {@link AVQueueInfo}.
129      * @return Returns whether to obtain AVQueueInfo successfully.
130      * @since 11
131     */
132     virtual int32_t GetHistoricalAVQueueInfos(int32_t maxSize, int32_t maxAppSize,
133         std::vector<AVQueueInfo>& avQueueInfo) = 0;
134 
135     /**
136      * Create a session controller based on the session ID.
137      *
138      * @param sessionId Current session id.
139      * @param controller Session controller{@link AVSessionController}
140      * @return Whether the session controller was successfully created
141      * @since 9
142     */
143     virtual int32_t CreateController(const std::string& sessionId,
144         std::shared_ptr<AVSessionController>& controller) = 0;
145 
146     /**
147      * @brief Listen for sessionListener callback event for current user.
148      *
149      * @param listener Listen for sessionListener Callback event{@link SessionListener}.
150      * @return Whether to return successful Listener.
151      * @since 9
152     */
153     virtual int32_t RegisterSessionListener(const std::shared_ptr<SessionListener>& listener) = 0;
154 
155     /**
156      * @brief Listen for sessionListener callback event for all users.
157      *
158      * @param listener Listen for sessionListener Callback event{@link SessionListener}.
159      * @return Whether to return successful Listener.
160      * @since 9
161     */
162     virtual int32_t RegisterSessionListenerForAllUsers(const std::shared_ptr<SessionListener>& listener) = 0;
163 
164     /**
165      * @brief Listen for service death callback event.
166      *
167      * @param callback Listen for death callback event{@link DeathCallback}.
168      * @return Whether to return successful callback.
169      * @since 9
170     */
171     virtual int32_t RegisterServiceDeathCallback(const DeathCallback& callback) = 0;
172 
173     /**
174      * @brief Listen for service death callback event.
175      *
176      * @param callback Listen for death callback event{@link DeathCallback}.
177      * @return Whether to return successful callback.
178      * @since 9
179     */
180     virtual int32_t UnregisterServiceDeathCallback() = 0;
181 
182     /**
183      * @brief Listen for service start callback event.
184      *
185      * @param callback Listen for service start event.
186      * @return Whether to return successful callback.
187      * @since 9
188     */
189     virtual int32_t RegisterServiceStartCallback(const std::function<void()> serviceStartCallback) = 0;
190 
191     /**
192      * @brief Listen for service startcallback event.
193      *
194      * @return Whether to return successful callback.
195      * @since 9
196     */
197     virtual int32_t UnregisterServiceStartCallback() = 0;
198 
199     /**
200      * Send system key command.
201      *
202      * @param keyEvent Key event {@linkKeyEvent}
203      * @return Returns whether the key event was successfully sent to the top session.
204      * @since 9
205     */
206     virtual int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) = 0;
207 
208     /**
209      * Send system key command.
210      *
211      * @param keyEvent Key event {@linkKeyEvent}
212      * @param wantParam The wantParam
213      * @return Returns whether the key event was successfully sent to the top session.
214      * @since 18
215     */
216     virtual int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent, const AAFwk::Want &wantParam) = 0;
217 
218     /**
219      * Send system control command.
220      *
221      * @param command Relevant commands and parameters of AVSession {@AVControlCommand}
222      * @return Returns whether send control command to the top session.
223      * @since 9
224     */
225     virtual int32_t SendSystemControlCommand(const AVControlCommand& command) = 0;
226 
227     /**
228      * Cast the session to the specified device list.
229      *
230      * @param token Session token
231      * @param descriptors Media device list {@link AudioDeviceDescriptor}
232      * @return Returns whether the session was successfully cast to the specified device list
233      * @since 9
234     */
235     virtual int32_t CastAudio(const SessionToken& token,
236                               const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) = 0;
237 
238     /**
239      * Cast all sessions to the specified device list.
240      *
241      * @param descriptors Media device list {@link AudioDeviceDescriptor}
242      * @return Returns whether the session was successfully cast to the specified device list
243      * @since 9
244     */
245     virtual int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) = 0;
246 
247     /**
248      * Start media playback
249      *
250      * @param bundleName bundleName.
251      * @param assetId assetId of media for playback.
252      * @return Returns whether to Start media playback successfully.
253      * @since 11
254     */
255     virtual int32_t StartAVPlayback(const std::string& bundleName, const std::string& assetId) = 0;
256 
257     /**
258      * Close avsession manager, clear resources.
259      *
260      * @return Returns whether close the avsession manager.
261      */
262     virtual int32_t Close(void) = 0;
263 
264 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
265     virtual int32_t GetAVCastController(const std::string& sessionId,
266         std::shared_ptr<AVCastController>& castController) = 0;
267 
268     /**
269      * Discovery nearby devices that can be cast.
270      *
271      * @param castDeviceCapability Device capability to filter device list
272      * @return Returns whether the device was successfully found
273      * @since 10
274     */
275     virtual int32_t StartCastDiscovery(int32_t castDeviceCapability, std::vector<std::string> drmSchemes) = 0;
276 
277     /**
278      * Stop cast process.
279      *
280      * @return Returns
281      * @since 10
282     */
283     virtual int32_t StopCastDiscovery() = 0;
284 
285     /**
286      * Transmission fd
287      *
288      * @param fd file descriptor
289      * @param maxSize file max size
290      * @return Returns whether the fd was transport successfully
291      * @since 13
292     */
293     virtual int32_t StartDeviceLogging(int32_t fd, uint32_t maxSize) = 0;
294 
295     /**
296      * Stop transmission fd
297      *
298      * @return Returns whether stop transport successfully
299      * @since 13
300     */
301     virtual int32_t StopDeviceLogging() = 0;
302 
303     /**
304      * Start cast process.
305      *
306      * @param sessionToken Session token
307      * @param outputDeviceInfo outputdeviceInfo
308      * @return Returns whether the device was successfully found
309      * @since 10
310     */
311     virtual int32_t StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo) = 0;
312 
313     /**
314      * Start cast process.
315      *
316      * @param sessionToken Session token
317      * @param outputDeviceInfo outputdeviceInfo
318      * @return Returns whether the device was successfully found
319      * @since 10
320     */
321     virtual int32_t StopCast(const SessionToken& sessionToken) = 0;
322 
323     virtual int32_t SetDiscoverable(const bool enable) = 0;
324 #endif
325 
326     /**
327      * Get distributed session controllers.
328      *
329      * @param sessionType sessionType
330      * @param sessionControllers sessionControllers
331      * @return Returns whether get distributed session controller successfully.
332      * @since 16
333     */
334     virtual int32_t GetDistributedSessionControllers(const DistributedSessionType& sessionType,
335         std::vector<std::shared_ptr<AVSessionController>>& sessionControllers) = 0;
336 };
337 } // namespace OHOS::AVSession
338 #endif // OHOS_AVSESSION_MANAGER_H
339