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_WFD_MESSAGE_H 17 #define OHOS_SHARING_WFD_MESSAGE_H 18 19 #include <sstream> 20 #include "protocol/rtsp/include/rtsp_request.h" 21 #include "protocol/rtsp/include/rtsp_response.h" 22 #include "wfd_session_def.h" 23 24 namespace OHOS { 25 namespace Sharing { 26 27 struct WfdVideoFormatsInfo { 28 uint16_t native = 0; 29 uint16_t preferredDisplayMode = 0; 30 uint16_t profile = 0; 31 uint16_t level = 0; 32 uint32_t ceaMask = 0; 33 uint32_t veaMask = 0; 34 uint32_t hhMask = 0; 35 uint16_t latency = 0; 36 uint16_t minSlice = 0; 37 uint16_t sliceEncParam = 0; 38 uint16_t frameRateCtlSupport = 0; 39 }; 40 41 // WfdRtspM1Request 42 class WfdRtspM1Request : public RtspRequestOptions { 43 public: WfdRtspM1Request(int32_t cseq)44 explicit WfdRtspM1Request(int32_t cseq) : RtspRequestOptions(cseq, "*") { SetRequire(RTSP_METHOD_WFD); } 45 }; 46 47 class WfdRtspM1Response : public RtspResponseOptions { 48 public: 49 WfdRtspM1Response(int32_t cseq, int32_t status); 50 }; 51 52 class WfdRtspM2Request : public RtspRequestOptions { 53 public: WfdRtspM2Request(int32_t cseq)54 explicit WfdRtspM2Request(int32_t cseq) : RtspRequestOptions(cseq, "*") { SetRequire(RTSP_METHOD_WFD); } 55 }; 56 57 // WfdRtspM2Response 58 class WfdRtspM2Response : public RtspResponseOptions { 59 public: WfdRtspM2Response(int32_t cseq,int32_t status)60 WfdRtspM2Response(int32_t cseq, int32_t status) : RtspResponseOptions(cseq, status) 61 { 62 std::stringstream ss; 63 ss << RTSP_METHOD_WFD << "," << RTSP_SP << RTSP_METHOD_SETUP << "," << RTSP_SP << RTSP_METHOD_TEARDOWN << "," 64 << RTSP_SP << RTSP_METHOD_PLAY << "," << RTSP_SP << RTSP_METHOD_PAUSE << "," << RTSP_SP 65 << RTSP_METHOD_GET_PARAMETER << "," << RTSP_SP << RTSP_METHOD_SET_PARAMETER; 66 SetPublicItems(ss.str()); 67 } 68 }; 69 70 // WfdRtspM3Request 71 class WfdRtspM3Request : public RtspRequestParameter { 72 public: WfdRtspM3Request(int32_t cseq,const std::string & url)73 WfdRtspM3Request(int32_t cseq, const std::string &url) : RtspRequestParameter(RTSP_METHOD_GET_PARAMETER, cseq, url) 74 { 75 AddBodyItem(WFD_PARAM_CONTENT_PROTECTION); 76 AddBodyItem(WFD_PARAM_VIDEO_FORMATS); 77 AddBodyItem(WFD_PARAM_AUDIO_CODECS); 78 AddBodyItem(WFD_PARAM_RTP_PORTS); 79 } 80 }; 81 82 class WfdRtspM3Response : public RtspResponse { 83 public: 84 WfdRtspM3Response() = default; 85 ~WfdRtspM3Response() override = default; WfdRtspM3Response(int32_t cseq,int32_t status)86 WfdRtspM3Response(int32_t cseq, int32_t status) : RtspResponse(cseq, status) {} 87 88 void SetClientRtpPorts(int32_t port); 89 void SetUibcCapability(const std::string &value = "none"); 90 void SetAudioCodecs(AudioFormat format = AUDIO_48000_16_2); 91 void SetCoupledSink(const std::string &value = "00 none"); 92 void SetContentProtection(const std::string &value = "none"); 93 void SetVideoFormats(VideoFormat format = VIDEO_1920X1080_30); 94 void SetStandbyResumeCapability(const std::string &value = "none"); 95 void SetCustomParam(const std::string &key, const std::string &value = "none"); 96 97 int32_t GetClientRtpPorts(); 98 std::string GetUibcCapability(); 99 AudioFormat GetAudioCodecs(); 100 std::string GetCoupledSink(); 101 std::string GetContentProtection(); 102 VideoFormat GetVideoFormats(); 103 std::string GetStandbyResumeCapability(); 104 std::string GetCustomParam(const std::string &key); 105 VideoFormat GetVideoFormatsByCea(int index); 106 std::string Stringify() override; 107 108 RtspError Parse(const std::string &response) override; GetWfdVideoFormatsInfo()109 WfdVideoFormatsInfo GetWfdVideoFormatsInfo() { return vWfdVideoFormatsInfo_[0]; } 110 111 private: 112 std::list<std::pair<std::string, std::string>> params_; 113 std::vector<WfdVideoFormatsInfo> vWfdVideoFormatsInfo_; 114 }; 115 116 class WfdRtspM4Request : public RtspRequestParameter { 117 public: 118 WfdRtspM4Request() = default; 119 ~WfdRtspM4Request() override = default; WfdRtspM4Request(int32_t cseq,const std::string & url)120 WfdRtspM4Request(int32_t cseq, const std::string &url) : RtspRequestParameter(RTSP_METHOD_SET_PARAMETER, cseq, url) 121 { 122 } 123 124 void SetClientRtpPorts(int32_t port); 125 void SetAudioCodecs(AudioFormat format = AUDIO_48000_16_2); 126 void SetPresentationUrl(const std::string &ip); 127 void SetVideoFormats(const WfdVideoFormatsInfo &wfdVideoFormatsInfo, VideoFormat format = VIDEO_1920X1080_30); 128 129 int32_t GetRtpPort(); 130 131 std::string GetPresentationUrl(); 132 std::string GetParameterValue(const std::string ¶m); 133 134 RtspError Parse(const std::string &request) override; 135 136 private: 137 std::list<std::pair<std::string, std::string>> params_; 138 }; 139 140 using WfdRtspM4Response = RtspResponse; 141 142 // WfdRtspM5Request 143 class WfdRtspM5Request : public RtspRequestParameter { 144 public: 145 WfdRtspM5Request() = default; WfdRtspM5Request(int32_t cseq)146 explicit WfdRtspM5Request(int32_t cseq) : RtspRequestParameter(RTSP_METHOD_SET_PARAMETER, 147 cseq, WFD_RTSP_URL_DEFAULT) {} 148 149 void SetTriggerMethod(const std::string &method); 150 std::string GetTriggerMethod(); 151 }; 152 153 using WfdRtspM5Response = RtspResponse; 154 using WfdRtspM6Request = RtspRequestSetup; 155 156 // WfdRtspM6Response 157 class WfdRtspM6Response : public RtspResponse { 158 public: 159 WfdRtspM6Response() = default; WfdRtspM6Response(int32_t cseq,int32_t status,std::string sessionID,int32_t timeOut)160 WfdRtspM6Response(int32_t cseq, int32_t status, std::string sessionID, int32_t timeOut) : RtspResponse(cseq, status) 161 { 162 SetSession(sessionID); 163 SetTimeout(timeOut); 164 } 165 std::string StringifyEx(); 166 int32_t GetClientPort(); 167 int32_t GetServerPort(); 168 void SetClientPort(int port); 169 void SetServerPort(int port); 170 171 private: 172 int32_t clientPort_ = 0; 173 int32_t serverPort_ = 0; 174 }; 175 176 using WfdRtspM7Request = RtspRequestPlay; 177 using WfdRtspM8Request = RtspRequestTeardown; 178 179 class WfdRtspIDRRequest : public RtspRequestParameter { 180 public: 181 WfdRtspIDRRequest() = default; WfdRtspIDRRequest(int32_t cseq,const std::string & url)182 explicit WfdRtspIDRRequest(int32_t cseq, const std::string &url) 183 : RtspRequestParameter(RTSP_METHOD_SET_PARAMETER, cseq, url) 184 { 185 AddBodyItem(WFD_PARAM_IDR_REQUEST); 186 } 187 }; 188 189 // WfdRtspM7Response 190 class WfdRtspM7Response : public RtspResponse { 191 public: 192 WfdRtspM7Response() = default; WfdRtspM7Response(int32_t cseq,int32_t status,std::string sessionID)193 WfdRtspM7Response(int32_t cseq, int32_t status, std::string sessionID) : RtspResponse(cseq, status) 194 { 195 SetSession(sessionID); 196 } 197 std::string StringifyEx(); 198 }; 199 200 using WfdRtspM8Response = RtspResponse; 201 202 class WfdRtspM16Request : public RtspRequestParameter { 203 public: WfdRtspM16Request(int32_t cseq,const std::string & url,std::string sessionID)204 WfdRtspM16Request(int32_t cseq, const std::string &url, std::string sessionID) 205 : RtspRequestParameter(RTSP_METHOD_GET_PARAMETER, cseq, url) 206 { 207 SetSession(sessionID); 208 } 209 }; 210 211 using WfdRtspM16Response = RtspResponse; 212 213 } // namespace Sharing 214 } // namespace OHOS 215 #endif 216