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