1 /* 2 * Copyright (c) 2024 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_DSCHED_ABILITY_CONNECTION_INFO_H 17 #define OHOS_DSCHED_ABILITY_CONNECTION_INFO_H 18 19 #include <map> 20 #include <string> 21 22 #include "ability_connection_manager_listener.h" 23 #include "av_trans_data_buffer.h" 24 #include "distributed_sched_utils.h" 25 #include "parcel.h" 26 #include "pixel_map.h" 27 #include "refbase.h" 28 #include "want_params.h" 29 30 namespace OHOS { 31 namespace DistributedCollab { 32 enum class StreamRole : int32_t { 33 SOURCE = 0, 34 SINK = 1, 35 }; 36 37 enum class FlipOptions : int32_t { 38 UNKNOWN = -1, 39 HORIZONTAL = 0, 40 VERTICAL = 1, 41 }; 42 43 enum class VideoPixelFormat : int32_t { 44 UNKNOWN = -1, 45 NV12 = 0, 46 NV21 = 1, 47 }; 48 49 enum class DisconnectReason : int32_t { 50 UNKNOW = -1, 51 PEER_APP_CLOSE_COLLABORATION = 0, 52 PEER_APP_EXIT = 1, 53 NETWORK_DISCONNECTED = 2, 54 }; 55 56 enum class StartOptionParams : int32_t { 57 START_IN_FOREGROUND = 0, 58 START_IN_BACKGROUND = 1, 59 }; 60 61 enum class ConnectErrorCode : int32_t { 62 INVALID_SESSION_ID = -1, 63 CONNECTED_SESSION_EXISTS = 0, 64 PEER_APP_REJECTED = 1, 65 LOCAL_WIFI_NOT_OPEN = 2, 66 PEER_WIFI_NOT_OPEN = 3, 67 PEER_ABILITY_NO_ONCOLLABORATE = 4, 68 SYSTEM_INTERNAL_ERROR = 5 69 }; 70 71 enum class ColorSpace : int32_t { 72 UNKNOWN = 0, 73 BT709_LIMIT = 16, 74 }; 75 76 struct StreamParams { 77 std::string name = ""; 78 StreamRole role = StreamRole::SOURCE; 79 int32_t bitrate = 80000; 80 ColorSpace colorSpace = ColorSpace::UNKNOWN; 81 }; 82 83 struct SurfaceParams { 84 int32_t width = 0; 85 int32_t height = 0; 86 VideoPixelFormat format = VideoPixelFormat::NV21; 87 int32_t rotation = 0; 88 FlipOptions flip = FlipOptions::UNKNOWN; 89 }; 90 91 struct EventCallbackInfo { 92 int32_t sessionId = -1; 93 std::string eventType = ""; 94 DisconnectReason reason = DisconnectReason::UNKNOW; 95 std::string msg = ""; 96 std::shared_ptr<AVTransDataBuffer> data = nullptr; 97 std::shared_ptr<Media::PixelMap> image = nullptr; 98 }; 99 100 enum class CollaborateEventType : int32_t { 101 SEND_FAILURE = 0, 102 COLOR_SPACE_CONVERSION_FAILURE = 1, 103 }; 104 105 struct CollaborateEventInfo { 106 int32_t sessionId = -1; 107 CollaborateEventType eventType = CollaborateEventType::SEND_FAILURE; 108 std::string eventMsg = ""; 109 }; 110 111 struct PeerInfo : public Parcelable { 112 std::string deviceId; 113 std::string bundleName; 114 std::string moduleName; 115 std::string abilityName; 116 std::string serverId; 117 // keep compatibility, both serviceName 118 std::string serviceName; 119 120 PeerInfo() = default; PeerInfoPeerInfo121 PeerInfo(const std::string& deviceId, const std::string& bundleName, 122 const std::string& moduleName, const std::string& abilityName, const std::string& serverId) 123 : deviceId(deviceId), bundleName(bundleName), moduleName(moduleName), 124 abilityName(abilityName), serverId(serverId), serviceName(serverId) {} 125 126 bool ReadFromParcel(Parcel &parcel); 127 bool Marshalling(Parcel &parcel) const override; 128 static PeerInfo *Unmarshalling(Parcel &parcel); 129 130 bool operator == (const PeerInfo &index) const 131 { 132 std::string compareInfo = this->deviceId + this->bundleName + this->moduleName + 133 this->abilityName + this->serverId; 134 std::string otherCompareInfo = index.deviceId + index.bundleName + index.moduleName + 135 index.abilityName + index.serverId; 136 return compareInfo.compare(otherCompareInfo) == 0; 137 } 138 139 bool operator < (const PeerInfo &index) const 140 { 141 std::string compareInfo = this->deviceId + this->bundleName + this->moduleName + 142 this->abilityName + this->serverId; 143 std::string otherCompareInfo = index.deviceId + index.bundleName + index.moduleName + 144 index.abilityName + index.serverId; 145 return compareInfo < otherCompareInfo; 146 } 147 toStringPeerInfo148 std::string toString() const 149 { 150 return "deviceId: " + DistributedSchedule::GetAnonymStr(deviceId) + " " + 151 "bundleName: " + bundleName + " " + 152 "moduleName: "+ moduleName + " " + 153 "abilityName: " + abilityName + " " + 154 "serverId: " + serverId; 155 } 156 }; 157 158 struct ConnectOption : public Parcelable { 159 bool needSendData = false; 160 bool needSendStream = false; 161 bool needReceiveStream = false; 162 bool needSendFile = false; 163 bool needReceiveFile = false; 164 AAFwk::WantParams options; 165 AAFwk::WantParams parameters; 166 bool ReadFromParcel(Parcel &parcel); 167 bool Marshalling(Parcel &parcel) const override; 168 static ConnectOption *Unmarshalling(Parcel &parcel); 169 HasFileTransferConnectOption170 bool HasFileTransfer() const 171 { 172 return needSendFile || needReceiveFile; 173 } 174 }; 175 176 struct ConnectResult { 177 bool isConnected = false; 178 ConnectErrorCode errorCode = ConnectErrorCode::SYSTEM_INTERNAL_ERROR; 179 int32_t sessionId = -1; 180 std::string reason = ""; 181 182 ConnectResult() = default; ConnectResultConnectResult183 ConnectResult(const bool isConnected) : isConnected(isConnected) {} ConnectResultConnectResult184 ConnectResult(bool isConnected, const ConnectErrorCode errorCode, const std::string& reason) 185 : isConnected(isConnected), errorCode(errorCode), reason(reason) {} 186 }; 187 } // namespace DistributedCollab 188 } // namespace OHOS 189 #endif //OHOS_DSCHED_ABILITY_CONNECTION_INFO_H