1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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_SHARING_ADPATER_H 17 #define OHOS_SHARING_ADPATER_H 18 19 #include "common/event_comm.h" 20 21 namespace OHOS { 22 namespace Sharing { 23 24 class ISharingAdapter { 25 public: 26 virtual ~ISharingAdapter() = default; 27 28 /** 29 * @brief Notify framework to release the scene. 30 * 31 * @param sceneId Indicates the scene ID. 32 */ 33 virtual void ReleaseScene(uint32_t sceneId) = 0; 34 virtual void OnSceneNotifyDestroyed(uint32_t sceneId) = 0; 35 36 /** 37 * @brief Forward events synchronously or asynchronously. 38 * 39 * @param contextId Indicates the context ID. 40 * @param agentId Indicates the agent ID. 41 * @param event Event struct. 42 * @param isSync Indicates whether synchronous mode is used. 43 * @return Returns 0 if forward the event successfully; returns -1 otherwise. 44 */ 45 virtual int32_t ForwardEvent(uint32_t contextId, uint32_t agentId, SharingEvent &event, bool isSync) = 0; 46 47 /** 48 * @brief Forward the domain msg to the interaction manager. 49 * 50 * @param msg msg to forward. 51 */ 52 virtual void ForwardDomainMsg(std::shared_ptr<BaseDomainMsg> &msg) = 0; 53 54 /** 55 * @brief Create a context to contain agents. 56 * 57 * @param contextId Indicates the context ID. The value <b>0</b> indicates an invalid ID and the creation fails. 58 * @return Returns 0 if the context is created; returns -1 otherwise. 59 */ 60 virtual int32_t CreateContext(uint32_t &contextId) = 0; 61 62 /** 63 * @brief Create an agent in the context by specifying a business implementation class. 64 * 65 * @param contextId Indicates the context ID. If contextId is 0, a new context will be created with an agent. 66 * @param agentId Indicates the created agent ID. The value <b>0</b> indicates an invalid ID and the creation fails. 67 * @param agentType Indicates the agent type {@link AgentType} defined in {@link agent_def.h}. 68 * @param sessionName Indicates the business implementation class's name. 69 * @return Returns 0 if the agent is created; returns -1 otherwise. 70 */ 71 virtual int32_t CreateAgent(uint32_t &contextId, uint32_t &agentId, AgentType agentType, 72 std::string sessionName) = 0; 73 74 /** 75 * @brief Delete all agents in this context, then delete the context. 76 * 77 * @param contextId Indicates context ID. 78 * @return Returns 0 if the context is destroyed; returns -1 otherwise. 79 */ 80 virtual int32_t DestroyContext(uint32_t contextId) = 0; 81 82 /** 83 * @brief Delete the agent. 84 * 85 * @param contextId Indicates the context ID. 86 * @param agentId Indicates the agent ID. 87 * @return Returns 0 if the agent is destroyed; returns -1 otherwise. 88 */ 89 virtual int32_t DestroyAgent(uint32_t contextId, uint32_t agentId) = 0; 90 91 /** 92 * @brief Stop operating business agent. 93 * 94 * @param contextId Indicates the context ID. 95 * @param agentId Indicates the agent ID. 96 * @return Returns 0 if stop sending or receiving streams; returns -1 otherwise. 97 */ 98 virtual int32_t Stop(uint32_t contextId, uint32_t agentId) = 0; 99 100 /** 101 * @brief Start operating business agent. 102 * 103 * @param contextId Indicates the context ID. 104 * @param agentId Indicates the agent ID. 105 * @return Returns 0 if the interaction starts; returns -1 otherwise. 106 */ 107 virtual int32_t Start(uint32_t contextId, uint32_t agentId) = 0; 108 109 /** 110 * @brief Pause operating business agent. 111 * 112 * @param contextId Indicates the context ID. 113 * @param agentId Indicates the agent ID. 114 * @param mediaType the media type {@link MediaType} defined in {@link const_def.h}. 115 * @return Returns 0 if the stream is paused; returns -1 otherwise. 116 */ 117 virtual int32_t Pause(uint32_t contextId, uint32_t agentId, MediaType mediaType) = 0; 118 119 /** 120 * @brief Resume operating business agent. 121 * 122 * @param contextId Indicates the context ID. 123 * @param agentId Indicates the agent ID. 124 * @param mediaType the media type {@link MediaType} defined in {@link const_def.h}. 125 * @return Returns 0 if the stream is resumed; returns -1 otherwise. 126 */ 127 virtual int32_t Resume(uint32_t contextId, uint32_t agentId, MediaType mediaType) = 0; 128 129 /** 130 * @brief Preview Media Resources. 131 * 132 * @param contextId Indicates the context ID. 133 * @param agentId Indicates the agent ID. 134 * @return Returns 0 if starts playing; returns -1 otherwise. 135 */ 136 virtual int32_t Play(uint32_t contextId, uint32_t agentId) = 0; 137 138 /** 139 * @brief Close the window for previewing media sources. 140 * 141 * @param contextId Indicates the context ID. 142 * @param agentId Indicates the agent ID. 143 * @return Returns 0 if stops playing; returns -1 otherwise. 144 */ 145 virtual int32_t Close(uint32_t contextId, uint32_t agentId) = 0; 146 147 /** 148 * @brief Set the keyframe playback mode. 149 * 150 * @param contextId Indicates the context ID. 151 * @param agentId Indicates the agent ID. 152 * @param surfaceId Indicates the surface ID. 153 * @param keyFrame Indicates whether it is keyframe playback mode. 154 * @return Returns 0 if keyframe mode is set; returns -1 otherwise. 155 */ 156 virtual int32_t SetKeyPlay(uint32_t contextId, uint32_t agentId, uint64_t surfaceId, bool keyFrame) = 0; 157 158 /** 159 * @brief Set the keyframe playback mode. 160 * 161 * @param contextId Indicates the context ID. 162 * @param agentId Indicates the agent ID. 163 * @param surfaceId Indicates the surface ID. 164 * @param keyRedirect Indicates whether it is keyframe rapid redirect. 165 * @return Returns 0 if keyframe mode is set; returns -1 otherwise. 166 */ 167 virtual int32_t SetKeyRedirect(uint32_t contextId, uint32_t agentId, uint64_t surfaceId, bool keyRedirect) = 0; 168 169 /** 170 * @brief Set the playback volume of audio resources. 171 * 172 * @param contextId Indicates the context ID. 173 * @param agentId Indicates the agent ID. 174 * @param volume Indicates the target volume of the audio to set, ranging from 0 to 1. 175 * @return Returns 0 if the volume is set; returns -1 otherwise. 176 */ 177 virtual int32_t SetVolume(uint32_t contextId, uint32_t agentId, float volume) = 0; 178 179 /** 180 * @brief Append the surface for the preview window. 181 * 182 * @param contextId Indicates the context ID. 183 * @param agentId Indicates the agent ID. 184 * @param surface Pointer of the surface. 185 * @return Returns 0 if the surface is set; returns -1 otherwise. 186 */ 187 virtual int32_t AppendSurface(uint32_t contextId, uint32_t agentId, sptr<Surface> surface, 188 SceneType sceneType = FOREGROUND) = 0; 189 190 /** 191 * @brief del the surface for the preview window. 192 * 193 * @param contextId Indicates the context ID. 194 * @param agentId Indicates the agent ID. 195 * @param surfaceId Indicates the surface ID. 196 * @return Returns 0 if the surface is del; returns -1 otherwise. 197 */ 198 virtual int32_t RemoveSurface(uint32_t contextId, uint32_t agentId, uint64_t surfaceId) = 0; 199 200 /** 201 * @brief Destroy the window. 202 * 203 * @param windowId Indicates the window ID. 204 * @return Returns 0 if the window is destroyed; returns -1 otherwise. 205 */ 206 virtual int32_t DestroyWindow(int32_t windowId) = 0; 207 208 /** 209 * @brief Create a preview window inside the framework. 210 * 211 * @param windowId Indicates the window ID. The value <b>-1</b> indicates an invalid ID and the creation fails. 212 * @param windowProperty Indicated initialization for window. For details, see {@link windowProperty} defined in 213 * {@link event_comm.h}. 214 * @return Returns 0 if the window is created; returns -1 otherwise. 215 */ 216 virtual int32_t CreateWindow(int32_t &windowId, WindowProperty &windowProperty) = 0; 217 218 /** 219 * @brief Hide the window. 220 * 221 * @param windowId Indicates the window ID. 222 * @return Returns 0 if the window is hidden; returns -1 otherwise. 223 */ 224 virtual int32_t Hide(int32_t windowId) = 0; 225 226 /** 227 * @brief Show the window. 228 * 229 * @param windowId Indicates the window ID. 230 * @return Returns 0 if the window is shown; returns -1 otherwise. 231 */ 232 virtual int32_t Show(int32_t windowId) = 0; 233 234 /** 235 * @brief Set the full-screen property of the window. 236 * 237 * @param windowId Indicates the window ID. 238 * @return Returns 0 if the window is to be full screen; returns -1 otherwise. 239 */ 240 virtual int32_t SetFullScreen(int32_t windowId, bool isFull) = 0; 241 242 /** 243 * @brief Move the window to the specified coordinates. 244 * 245 * @param windowId Indicates the window ID. 246 * @param x The starting x-axis position of the window 247 * @param y The starting y-axis position of the window 248 * @return Returns 0 if the window is moved successfully; returns -1 otherwise. 249 */ 250 virtual int32_t MoveTo(int32_t windowId, int32_t x, int32_t y) = 0; 251 252 /** 253 * @brief Get surface of the window. 254 * 255 * @param windowId Indicates the window ID. 256 * @param surface Pointer of surface. 257 * @return Returns 0 if gets the surface successfully; returns -1 otherwise. 258 */ 259 virtual int32_t GetSurface(int32_t windowId, sptr<Surface> &surface) = 0; 260 261 /** 262 * @brief Resize the window. 263 * 264 * @param windowId Indicates the window ID. 265 * @param width Indicates the windows'width you set. 266 * @param height Indicates the window's height you set. 267 * @return Returns 0 if the window is resized; returns -1 otherwise. 268 */ 269 virtual int32_t ReSize(int32_t windowId, int32_t width, int32_t height) = 0; 270 }; 271 272 } // namespace Sharing 273 } // namespace OHOS 274 #endif