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 avcall status infos. 38 * 39 * @param state Current avcall status infos {@link AVCallState}. 40 * @return Returns check whether the system permissions are supported 41 * @since 11 42 */ 43 virtual int32_t GetAVCallState(AVCallState& avCallState) = 0; 44 45 /** 46 * @brief Get current avcall meta data infos. 47 * 48 * @param state Current avcall meta data infos {@link AVCallMetaData}. 49 * @return Returns check whether the system permissions are supported 50 * @since 11 51 */ 52 virtual int32_t GetAVCallMetaData(AVCallMetaData& avCallMetaData) = 0; 53 /** 54 * @brief Get current playing status infos. 55 * 56 * @param state Current playing status infos {@link AVPlaybackState}. 57 * @return Returns check whether the system permissions are supported 58 * @since 9 59 */ 60 virtual int32_t GetAVPlaybackState(AVPlaybackState& state) = 0; 61 62 /** 63 * @brief Get current playing status infos. 64 * 65 * @param state Current playing status infos {@link AVPlaybackState}. 66 * @return Returns check whether the system permissions are supported 67 * @since 9 68 */ 69 virtual int32_t GetAVMetaData(AVMetaData& data) = 0; 70 71 /** 72 * Send key events to the corresponding session of the controller. 73 * 74 * @param keyEvent key event. 75 * @return int32_t Return whether sending succeeded. 76 * @since 9 77 */ 78 virtual int32_t SendAVKeyEvent(const MMI::KeyEvent& keyEvent) = 0; 79 80 /** 81 * Get the WantAgent object saved by the application in the session. 82 * 83 * @param ability Objects saved in setLaunchAbility. 84 * @return int32_t Successfully obtained. 85 * @since 9 86 */ 87 virtual int32_t GetLaunchAbility(AbilityRuntime::WantAgent::WantAgent& ability) = 0; 88 89 /** 90 * Get the WantAgent object saved by the application in the session. 91 * 92 * @param ability Objects saved in setLaunchAbility. 93 * @return int32_t Successfully obtained. 94 * @since 9 95 */ GetLaunchAbilityInner(AbilityRuntime::WantAgent::WantAgent * & ability)96 virtual int32_t GetLaunchAbilityInner(AbilityRuntime::WantAgent::WantAgent*& ability) 97 { 98 return 0; 99 }; 100 101 /** 102 * Get valid commands supported by the session. 103 * 104 * @param cmds Returns a collection of valid commands. 105 * @return int32_t Whether the valid commands supported by the session are obtained successfully. 106 * @since 9 107 */ 108 virtual int32_t GetValidCommands(std::vector<int32_t>& cmds) = 0; 109 110 /** 111 * Whether the session is active. 112 * 113 * @param isActive Whether the session is active. 114 * @return int32_t Returns whether the status was obtained successfully. 115 * @since 9 116 */ 117 virtual int32_t IsSessionActive(bool& isActive) = 0; 118 119 /** 120 * Send commands to its corresponding session through the controller. 121 * 122 * @param cmd Commands and parameters related to the session {@link AVControlCommand}. 123 * @return int32_t Return whether sending succeeded. 124 * @since 9 125 */ 126 virtual int32_t SendControlCommand(const AVControlCommand& cmd) = 0; 127 128 /** 129 * Send common commands to its corresponding session through the controller. 130 * 131 * @param commonCommand The name of the command to be sent. 132 * @param commandArgs Command packets to be sent 133 * @return int32_t Return whether sending succeeded. 134 * @since 10 135 */ 136 virtual int32_t SendCommonCommand(const std::string& commonCommand, const AAFwk::WantParams& commandArgs) = 0; 137 138 /** 139 * @brief Listen for AVController Callback event. 140 * 141 * @param callback Listen for AVController Callback event{@link AVControllerCallback}. 142 * @return Returns whether the return is successful. 143 * @since 9 144 */ 145 virtual int32_t RegisterCallback(const std::shared_ptr<AVControllerCallback>& callback) = 0; 146 147 /** 148 * @brief Set avcall meta filter. 149 * 150 * @param filter AVCall Meta filter{@link AVCallMetaMaskType}. 151 * @return Returns whether set successful. 152 * @since 9 153 */ 154 virtual int32_t SetAVCallMetaFilter(const AVCallMetaData::AVCallMetaMaskType& filter) = 0; 155 156 /** 157 * @brief Set avcall state filter. 158 * 159 * @param filter AVCall State {@link AVCallStateMaskType}. 160 * @return Returns whether set successful. 161 * @since 9 162 */ 163 virtual int32_t SetAVCallStateFilter(const AVCallState::AVCallStateMaskType& filter) = 0; 164 165 /** 166 * @brief Set meta filter. 167 * 168 * @param filter Meta filter{@link MetaMaskType}. 169 * @return Returns whether set successful. 170 * @since 9 171 */ 172 virtual int32_t SetMetaFilter(const AVMetaData::MetaMaskType& filter) = 0; 173 174 /** 175 * @brief Set Playback filter. 176 * 177 * @param filter Playback State {@link MetaMaskType}. 178 * @return Returns whether set successful. 179 * @since 9 180 */ 181 virtual int32_t SetPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter) = 0; 182 183 /** 184 * @brief Get the playlist. Which is the content of the playlist presented by this session. 185 * 186 * @param items An array of the AVQueueItem. 187 * @return Return whether the obtain is successful. 188 * @since 10 189 */ 190 virtual int32_t GetAVQueueItems(std::vector<AVQueueItem>& items) = 0; 191 192 /** 193 * @brief Get the name of the playlist presented by this session. 194 * 195 * @param title The name of the playlist. 196 * @return Return whether the get is successful. 197 * @since 10 198 */ 199 virtual int32_t GetAVQueueTitle(std::string& title) = 0; 200 201 /** 202 * @brief Set the item in the playlist to be played. 203 * 204 * @param itemId The serial number of the item to be played. 205 * @return Return whether the operation is successful. 206 * @since 10 207 */ 208 virtual int32_t SkipToQueueItem(int32_t& itemId) = 0; 209 210 /** 211 * @brief Get custom media packet. 212 * 213 * @param extras Custom media packet key-value pairs 214 * @return Return whether the operation is successful 215 * @since 10 216 */ 217 virtual int32_t GetExtras(AAFwk::WantParams& extras) = 0; 218 219 /** 220 * @brief Get extra information for remote device, such as volume level, connected devices. 221 * 222 * @param extraEvent The event name to get 223 * @param extras Custom media packet key-value pairs 224 * @return Return whether the operation is successful 225 * @since 16 226 */ 227 virtual int32_t GetExtrasWithEvent(const std::string& extraEvent, AAFwk::WantParams& extras) = 0; 228 229 /** 230 * @brief Destroy session. 231 * 232 * @return Returns whether destroy successful. 233 * @since 9 234 */ 235 virtual int32_t Destroy() = 0; 236 237 /** 238 * @brief Get session id. 239 * 240 * @return Returns session id. 241 * @since 9 242 */ 243 virtual std::string GetSessionId() = 0; 244 245 /** 246 * @brief Get current playback position. 247 * 248 * @return Returns current playback position. 249 * @since 9 250 */ 251 virtual int64_t GetRealPlaybackPosition() = 0; 252 253 /** 254 * @brief Controller is or not destroy. 255 * 256 * @return Returns controller is or not destroy. 257 * @since 9 258 */ 259 virtual bool IsDestroy() = 0; 260 261 /** 262 * @brief Deconstruct AVSessionController. 263 * @since 9 264 */ 265 virtual ~AVSessionController() = default; 266 }; 267 } // namespace OHOS::AVSession 268 269 #endif // OHOS_AVSESSION_CONTROLLER_H 270