• 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      * Send the key command to get the descriptor of all sessions.
58      *
59      * @param descriptors Get relevant descriptions of all sessions
60      * @return Whether the relevant descriptions of all sessions are obtained successfully
61      * @since 9
62     */
63     virtual int32_t GetAllSessionDescriptors(std::vector<AVSessionDescriptor>& descriptors) = 0;
64 
65     /**
66      * Send the key command to get the descriptor of activated sessions.
67      *
68      * @param activatedSessions Get relevant descriptions of activated sessions
69      * @return Returns whether the relevant descriptions of activated sessions are obtained successfully
70      * @since 9
71     */
72     virtual int32_t GetActivatedSessionDescriptors(std::vector<AVSessionDescriptor>& activatedSessions) = 0;
73 
74     /**
75      * Get SessionDescriptors By SessionId.
76      *
77      * @param sessionId current session id.
78      * @param descriptor obtain SessionDescriptors {@link AVSessionDescriptor}.
79      * @return Returns whether to obtain SessionDescriptors successfully.
80      * @since 9
81     */
82     virtual int32_t GetSessionDescriptorsBySessionId(const std::string& sessionId, AVSessionDescriptor& descriptor) = 0;
83 
84     /**
85      * Get historical session Descriptors.
86      *
87      * @param maxSize data write maxSize.
88      * @param descriptors obtain SessionDescriptors {@link AVSessionDescriptor}.
89      * @return Returns whether to obtain SessionDescriptors successfully.
90      * @since 9
91     */
92     virtual int32_t GetHistoricalSessionDescriptors(int32_t maxSize, std::vector<AVSessionDescriptor>& descriptors) = 0;
93 
94     /**
95      * Get historical AVQueueInfo.
96      *
97      * @param maxSize data write maxSize.
98      * @param maxAppSize max app count.
99      * @param avQueueInfo obtain history play avqueue {@link AVQueueInfo}.
100      * @return Returns whether to obtain AVQueueInfo successfully.
101      * @since 11
102     */
103     virtual int32_t GetHistoricalAVQueueInfos(int32_t maxSize, int32_t maxAppSize,
104         std::vector<AVQueueInfo>& avQueueInfo) = 0;
105 
106     /**
107      * Create a session controller based on the session ID.
108      *
109      * @param sessionId Current session id.
110      * @param controller Session controller{@link AVSessionController}
111      * @return Whether the session controller was successfully created
112      * @since 9
113     */
114     virtual int32_t CreateController(const std::string& sessionId,
115         std::shared_ptr<AVSessionController>& controller) = 0;
116 
117     /**
118      * @brief Listen for sessionListener callback event.
119      *
120      * @param listener Listen for sessionListener Callback event{@link SessionListener}.
121      * @return Whether to return successful Listener.
122      * @since 9
123     */
124     virtual int32_t RegisterSessionListener(const std::shared_ptr<SessionListener>& listener) = 0;
125 
126     /**
127      * @brief Listen for service death callback event.
128      *
129      * @param callback Listen for death callback event{@link DeathCallback}.
130      * @return Whether to return successful callback.
131      * @since 9
132     */
133     virtual int32_t RegisterServiceDeathCallback(const DeathCallback& callback) = 0;
134 
135     /**
136      * @brief Listen for service death callback event.
137      *
138      * @param callback Listen for death callback event{@link DeathCallback}.
139      * @return Whether to return successful callback.
140      * @since 9
141     */
142     virtual int32_t UnregisterServiceDeathCallback() = 0;
143 
144     /**
145      * Send system key command.
146      *
147      * @param keyEvent Key event {@linkKeyEvent}
148      * @return Returns whether the key event was successfully sent to the top session.
149      * @since 9
150     */
151     virtual int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) = 0;
152 
153     /**
154      * Send system control command.
155      *
156      * @param command Relevant commands and parameters of AVSession {@AVControlCommand}
157      * @return Returns whether send control command to the top session.
158      * @since 9
159     */
160     virtual int32_t SendSystemControlCommand(const AVControlCommand& command) = 0;
161 
162     /**
163      * Cast the session to the specified device list.
164      *
165      * @param token Session token
166      * @param descriptors Media device list {@link AudioDeviceDescriptor}
167      * @return Returns whether the session was successfully cast to the specified device list
168      * @since 9
169     */
170     virtual int32_t CastAudio(const SessionToken& token,
171                               const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) = 0;
172 
173     /**
174      * Cast all sessions to the specified device list.
175      *
176      * @param descriptors Media device list {@link AudioDeviceDescriptor}
177      * @return Returns whether the session was successfully cast to the specified device list
178      * @since 9
179     */
180     virtual int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) = 0;
181 
182     /**
183      * Start media playback
184      *
185      * @param bundleName bundleName.
186      * @param assetId assetId of media for playback.
187      * @return Returns whether to Start media playback successfully.
188      * @since 11
189     */
190     virtual int32_t StartAVPlayback(const std::string& bundleName, const std::string& assetId) = 0;
191 
192     /**
193      * Close avsession manager, clear resources.
194      *
195      * @return Returns whether close the avsession manager.
196      */
197     virtual int32_t Close(void) = 0;
198 
199 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
200     virtual int32_t GetAVCastController(const std::string& sessionId,
201         std::shared_ptr<AVCastController>& castController) = 0;
202 
203     /**
204      * Discovery nearby devices that can be cast.
205      *
206      * @param castDeviceCapability Device capability to filter device list
207      * @return Returns whether the device was successfully found
208      * @since 10
209     */
210     virtual int32_t StartCastDiscovery(int32_t castDeviceCapability) = 0;
211 
212     /**
213      * Stop cast process.
214      *
215      * @return Returns
216      * @since 10
217     */
218     virtual int32_t StopCastDiscovery() = 0;
219 
220     /**
221      * Start cast process.
222      *
223      * @param sessionToken Session token
224      * @param outputDeviceInfo outputdeviceInfo
225      * @return Returns whether the device was successfully found
226      * @since 10
227     */
228     virtual int32_t StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo) = 0;
229 
230     /**
231      * Start cast process.
232      *
233      * @param sessionToken Session token
234      * @param outputDeviceInfo outputdeviceInfo
235      * @return Returns whether the device was successfully found
236      * @since 10
237     */
238     virtual int32_t StopCast(const SessionToken& sessionToken) = 0;
239 
240     virtual int32_t SetDiscoverable(const bool enable) = 0;
241 #endif
242 };
243 } // namespace OHOS::AVSession
244 #endif // OHOS_AVSESSION_MANAGER_H
245