• 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 
29 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
30 #include "avcast_controller.h"
31 #endif
32 
33 namespace OHOS::AVSession {
34 class AVSessionManager {
35 public:
36     /**
37      * Get AVSessionManager instance.
38      *
39      * @return AVSessionManager instance.
40      * @since 7
41     */
42     static AVSessionManager& GetInstance();
43 
44     /**
45      * Create Session Object.
46      *
47      * @param tag Custom name of the session
48      * @param type Session type
49      * @param elementName element Name
50      * @return Returns Session Object
51      * @since 7
52     */
53     virtual std::shared_ptr<AVSession> CreateSession(const std::string& tag, int32_t type,
54                                                      const AppExecFwk::ElementName& elementName) = 0;
55     /**
56      * Send the key command to get the descriptor of all sessions.
57      *
58      * @param descriptors Get relevant descriptions of all sessions
59      * @return Whether the relevant descriptions of all sessions are obtained successfully
60      * @since 9
61     */
62     virtual int32_t GetAllSessionDescriptors(std::vector<AVSessionDescriptor>& descriptors) = 0;
63 
64     /**
65      * Send the key command to get the descriptor of activated sessions.
66      *
67      * @param activatedSessions Get relevant descriptions of activated sessions
68      * @return Returns whether the relevant descriptions of activated sessions are obtained successfully
69      * @since 9
70     */
71     virtual int32_t GetActivatedSessionDescriptors(std::vector<AVSessionDescriptor>& activatedSessions) = 0;
72 
73     /**
74      * Get SessionDescriptors By SessionId.
75      *
76      * @param sessionId current session id.
77      * @param descriptor obtain SessionDescriptors {@link AVSessionDescriptor}.
78      * @return Returns whether to obtain SessionDescriptors successfully.
79      * @since 9
80     */
81     virtual int32_t GetSessionDescriptorsBySessionId(const std::string& sessionId, AVSessionDescriptor& descriptor) = 0;
82 
83     /**
84      * Get historical session Descriptors.
85      *
86      * @param maxSize data write maxSize.
87      * @param descriptors obtain SessionDescriptors {@link AVSessionDescriptor}.
88      * @return Returns whether to obtain SessionDescriptors successfully.
89      * @since 9
90     */
91     virtual int32_t GetHistoricalSessionDescriptors(int32_t maxSize, std::vector<AVSessionDescriptor>& descriptors) = 0;
92 
93     /**
94      * Create a session controller based on the session ID.
95      *
96      * @param sessionId Current session id.
97      * @param controller Session controller{@link AVSessionController}
98      * @return Whether the session controller was successfully created
99      * @since 9
100     */
101     virtual int32_t CreateController(const std::string& sessionId,
102         std::shared_ptr<AVSessionController>& controller) = 0;
103 
104     /**
105      * @brief Listen for sessionListener callback event.
106      *
107      * @param listener Listen for sessionListener Callback event{@link SessionListener}.
108      * @return Whether to return successful Listener.
109      * @since 9
110     */
111     virtual int32_t RegisterSessionListener(const std::shared_ptr<SessionListener>& listener) = 0;
112 
113     /**
114      * @brief Listen for service death callback event.
115      *
116      * @param callback Listen for death callback event{@link DeathCallback}.
117      * @return Whether to return successful callback.
118      * @since 9
119     */
120     virtual int32_t RegisterServiceDeathCallback(const DeathCallback& callback) = 0;
121 
122     /**
123      * @brief Listen for service death callback event.
124      *
125      * @param callback Listen for death callback event{@link DeathCallback}.
126      * @return Whether to return successful callback.
127      * @since 9
128     */
129     virtual int32_t UnregisterServiceDeathCallback() = 0;
130 
131     /**
132      * Send system key command.
133      *
134      * @param keyEvent Key event {@linkKeyEvent}
135      * @return Returns whether the key event was successfully sent to the top session.
136      * @since 9
137     */
138     virtual int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) = 0;
139 
140     /**
141      * Send system control command.
142      *
143      * @param command Relevant commands and parameters of AVSession {@AVControlCommand}
144      * @return Returns whether send control command to the top session.
145      * @since 9
146     */
147     virtual int32_t SendSystemControlCommand(const AVControlCommand& command) = 0;
148 
149     /**
150      * Cast the session to the specified device list.
151      *
152      * @param token Session token
153      * @param descriptors Media device list {@link AudioDeviceDescriptor}
154      * @return Returns whether the session was successfully cast to the specified device list
155      * @since 9
156     */
157     virtual int32_t CastAudio(const SessionToken& token,
158                               const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) = 0;
159 
160     /**
161      * Cast all sessions to the specified device list.
162      *
163      * @param descriptors Media device list {@link AudioDeviceDescriptor}
164      * @return Returns whether the session was successfully cast to the specified device list
165      * @since 9
166     */
167     virtual int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors) = 0;
168 
169 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
170     virtual int32_t GetAVCastController(const std::string& sessionId,
171         std::shared_ptr<AVCastController>& castController) = 0;
172 
173     /**
174      * Discovery nearby devices that can be cast.
175      *
176      * @param castDeviceCapability Device capability to filter device list
177      * @return Returns whether the device was successfully found
178      * @since 10
179     */
180     virtual int32_t StartCastDiscovery(int32_t castDeviceCapability) = 0;
181 
182     /**
183      * Stop cast process.
184      *
185      * @return Returns
186      * @since 10
187     */
188     virtual int32_t StopCastDiscovery() = 0;
189 
190     /**
191      * Start cast process.
192      *
193      * @param sessionToken Session token
194      * @param outputDeviceInfo outputdeviceInfo
195      * @return Returns whether the device was successfully found
196      * @since 10
197     */
198     virtual int32_t StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo) = 0;
199 
200     /**
201      * Start cast process.
202      *
203      * @param sessionToken Session token
204      * @param outputDeviceInfo outputdeviceInfo
205      * @return Returns whether the device was successfully found
206      * @since 10
207     */
208     virtual int32_t StopCast(const SessionToken& sessionToken) = 0;
209 
210     virtual int32_t SetDiscoverable(const bool enable) = 0;
211 #endif
212 };
213 } // namespace OHOS::AVSession
214 #endif // OHOS_AVSESSION_MANAGER_H
215