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 CONNECTED_SESSION_EXISTS = 0, 63 PEER_APP_REJECTED = 1, 64 LOCAL_WIFI_NOT_OPEN = 2, 65 PEER_WIFI_NOT_OPEN = 3, 66 PEER_ABILITY_NO_ONCOLLABORATE = 4, 67 SYSTEM_INTERNAL_ERROR = 5 68 }; 69 70 struct StreamParams { 71 std::string name = ""; 72 StreamRole role = StreamRole::SOURCE; 73 int32_t bitrate = 80000; 74 }; 75 76 struct SurfaceParams { 77 int32_t width = 0; 78 int32_t height = 0; 79 VideoPixelFormat format = VideoPixelFormat::NV21; 80 int32_t rotation = 0; 81 FlipOptions flip = FlipOptions::UNKNOWN; 82 }; 83 84 struct EventCallbackInfo { 85 int32_t sessionId = -1; 86 std::string eventType = ""; 87 DisconnectReason reason = DisconnectReason::UNKNOW; 88 std::string msg = ""; 89 std::shared_ptr<AVTransDataBuffer> data = nullptr; 90 std::shared_ptr<Media::PixelMap> image = nullptr; 91 }; 92 93 enum class CollaborateEventType : int32_t { 94 SEND_FAILURE = 0, 95 COLOR_SPACE_CONVERSION_FAILURE = 1, 96 }; 97 98 struct CollaborateEventInfo { 99 int32_t sessionId = -1; 100 CollaborateEventType eventType = CollaborateEventType::SEND_FAILURE; 101 std::string eventMsg = ""; 102 }; 103 104 struct PeerInfo : public Parcelable { 105 std::string deviceId; 106 std::string bundleName; 107 std::string moduleName; 108 std::string abilityName; 109 std::string serverId; 110 // keep compatibility, both serviceName 111 std::string serviceName; 112 113 PeerInfo() = default; PeerInfoPeerInfo114 PeerInfo(const std::string& deviceId, const std::string& bundleName, 115 const std::string& moduleName, const std::string& abilityName, const std::string& serverId) 116 : deviceId(deviceId), bundleName(bundleName), moduleName(moduleName), 117 abilityName(abilityName), serverId(serverId), serviceName(serverId) {} 118 119 bool ReadFromParcel(Parcel &parcel); 120 bool Marshalling(Parcel &parcel) const override; 121 static PeerInfo *Unmarshalling(Parcel &parcel); 122 123 bool operator == (const PeerInfo &index) const 124 { 125 std::string compareInfo = this->deviceId + this->bundleName + this->moduleName + 126 this->abilityName + this->serverId; 127 std::string otherCompareInfo = index.deviceId + index.bundleName + index.moduleName + 128 index.abilityName + index.serverId; 129 return compareInfo.compare(otherCompareInfo) == 0; 130 } 131 132 bool operator < (const PeerInfo &index) const 133 { 134 std::string compareInfo = this->deviceId + this->bundleName + this->moduleName + 135 this->abilityName + this->serverId; 136 std::string otherCompareInfo = index.deviceId + index.bundleName + index.moduleName + 137 index.abilityName + index.serverId; 138 return compareInfo < otherCompareInfo; 139 } 140 toStringPeerInfo141 std::string toString() const 142 { 143 return "deviceId: " + DistributedSchedule::GetAnonymStr(deviceId) + " " + 144 "bundleName: " + bundleName + " " + 145 "moduleName: "+ moduleName + " " + 146 "abilityName: " + abilityName + " " + 147 "serverId: " + serverId; 148 } 149 }; 150 151 struct ConnectOption : public Parcelable { 152 bool needSendData = false; 153 bool needSendStream = false; 154 bool needReceiveStream = false; 155 bool needSendFile = false; 156 bool needReceiveFile = false; 157 AAFwk::WantParams options; 158 AAFwk::WantParams parameters; 159 bool ReadFromParcel(Parcel &parcel); 160 bool Marshalling(Parcel &parcel) const override; 161 static ConnectOption *Unmarshalling(Parcel &parcel); 162 HasFileTransferConnectOption163 bool HasFileTransfer() const 164 { 165 return needSendFile || needReceiveFile; 166 } 167 }; 168 169 struct ConnectResult { 170 bool isConnected = false; 171 ConnectErrorCode errorCode = ConnectErrorCode::SYSTEM_INTERNAL_ERROR; 172 int32_t sessionId = -1; 173 std::string reason = ""; 174 175 ConnectResult() = default; ConnectResultConnectResult176 ConnectResult(const bool isConnected) : isConnected(isConnected) {} ConnectResultConnectResult177 ConnectResult(bool isConnected, const ConnectErrorCode errorCode, const std::string& reason) 178 : isConnected(isConnected), errorCode(errorCode), reason(reason) {} 179 }; 180 } // namespace DistributedCollab 181 } // namespace OHOS 182 #endif //OHOS_DSCHED_ABILITY_CONNECTION_INFO_H