• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_CONTROLLER_H
17 #define OHOS_AVSESSION_CONTROLLER_H
18 
19 #include <bitset>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "avcontrol_command.h"
25 #include "avsession_info.h"
26 #include "key_event.h"
27 #include "want_agent.h"
28 
29 /**
30  * @brief Session controller instance.
31  * @since 9
32  */
33 namespace OHOS::AVSession {
34 class AVSessionController {
35 public:
36     /**
37      * @brief Get current playing status infos.
38      *
39      * @param state Current playing status infos {@link AVPlaybackState}.
40      * @return Returns check whether the system permissions are supported
41      * @since 9
42     */
43     virtual int32_t GetAVPlaybackState(AVPlaybackState& state) = 0;
44 
45     /**
46      * @brief Get current playing status infos.
47      *
48      * @param state Current playing status infos {@link AVPlaybackState}.
49      * @return Returns check whether the system permissions are supported
50      * @since 9
51     */
52     virtual int32_t GetAVMetaData(AVMetaData& data) = 0;
53 
54     /**
55      * Send key events to the corresponding session of the controller.
56      *
57      * @param keyEvent key event.
58      * @return int32_t Return whether sending succeeded.
59      * @since 9
60     */
61     virtual int32_t SendAVKeyEvent(const MMI::KeyEvent& keyEvent) = 0;
62 
63     /**
64      * Get the WantAgent object saved by the application in the session.
65      *
66      * @param ability Objects saved in setLaunchAbility.
67      * @return int32_t Successfully obtained.
68      * @since 9
69     */
70     virtual int32_t GetLaunchAbility(AbilityRuntime::WantAgent::WantAgent& ability) = 0;
71 
72     /**
73      * Get valid commands supported by the session.
74      *
75      * @param cmds Returns a collection of valid commands.
76      * @return int32_t Whether the valid commands supported by the session are obtained successfully.
77      * @since 9
78     */
79     virtual int32_t GetValidCommands(std::vector<int32_t>& cmds) = 0;
80 
81     /**
82      * Whether the session is active.
83      *
84      * @param isActive Whether the session is active.
85      * @return int32_t Returns whether the status was obtained successfully.
86      * @since 9
87     */
88     virtual int32_t IsSessionActive(bool& isActive) = 0;
89 
90     /**
91      * Send commands to its corresponding session through the controller.
92      *
93      * @param cmd Commands and parameters related to the session {@link AVControlCommand}.
94      * @return int32_t Return whether sending succeeded.
95      * @since 9
96     */
97     virtual int32_t SendControlCommand(const AVControlCommand& cmd) = 0;
98 
99     /**
100      * Send common commands to its corresponding session through the controller.
101      *
102      * @param commonCommand The name of the command to be sent.
103      * @param commandArgs Command packets to be sent
104      * @return int32_t Return whether sending succeeded.
105      * @since 10
106     */
107     virtual int32_t SendCommonCommand(const std::string& commonCommand, const AAFwk::WantParams& commandArgs) = 0;
108 
109     /**
110      * @brief Listen for AVController Callback event.
111      *
112      * @param callback Listen for AVController Callback event{@link AVControllerCallback}.
113      * @return Returns whether the return is successful.
114      * @since 9
115     */
116     virtual int32_t RegisterCallback(const std::shared_ptr<AVControllerCallback>& callback) = 0;
117 
118     /**
119      * @brief Set meta filter.
120      *
121      * @param filter Meta filter{@link MetaMaskType}.
122      * @return Returns whether set successful.
123      * @since 9
124     */
125     virtual int32_t SetMetaFilter(const AVMetaData::MetaMaskType& filter) = 0;
126 
127     /**
128      * @brief Set Playback filter.
129      *
130      * @param filter Playback State {@link MetaMaskType}.
131      * @return Returns whether set successful.
132      * @since 9
133     */
134     virtual int32_t SetPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter) = 0;
135 
136     /**
137      * @brief Get the playlist. Which is the content of the playlist presented by this session.
138      *
139      * @param items An array of the AVQueueItem.
140      * @return Return whether the obtain is successful.
141      * @since 10
142     */
143     virtual int32_t GetAVQueueItems(std::vector<AVQueueItem>& items) = 0;
144 
145     /**
146      * @brief Get the name of the playlist presented by this session.
147      *
148      * @param title The name of the playlist.
149      * @return Return whether the get is successful.
150      * @since 10
151      */
152     virtual int32_t GetAVQueueTitle(std::string& title) = 0;
153 
154     /**
155      * @brief Set the item in the playlist to be played.
156      *
157      * @param itemId The serial number of the item to be played.
158      * @return Return whether the operation is successful.
159      * @since 10
160      */
161     virtual int32_t SkipToQueueItem(int32_t& itemId) = 0;
162 
163     /**
164      * @brief Get custom media packet.
165      *
166      * @param extras Custom media packet key-value pairs
167      * @return Return whether the operation is successful
168      * @since 10
169     */
170     virtual int32_t GetExtras(AAFwk::WantParams& extras) = 0;
171 
172     /**
173      * @brief Destroy session.
174      *
175      * @return Returns whether destroy successful.
176      * @since 9
177     */
178     virtual int32_t Destroy() = 0;
179 
180     /**
181      * @brief Get session id.
182      *
183      * @return Returns session id.
184      * @since 9
185     */
186     virtual std::string GetSessionId() = 0;
187 
188     /**
189      * @brief Get current playback position.
190      *
191      * @return Returns current playback position.
192      * @since 9
193     */
194     virtual int64_t GetRealPlaybackPosition() = 0;
195 
196     /**
197      * @brief Controller is or not destroy.
198      *
199      * @return Returns controller is or not destroy.
200      * @since 9
201     */
202     virtual bool IsDestroy() = 0;
203 
204     /**
205      * @brief Deconstruct AVSessionController.
206      * @since 9
207     */
208     virtual ~AVSessionController() = default;
209 };
210 } // namespace OHOS::AVSession
211 
212 #endif // OHOS_AVSESSION_CONTROLLER_H
213