From 454c83a2bd9893583d66e1d4ea05384fb74451f9 Mon Sep 17 00:00:00 2001 From: LongestDistance Date: Thu, 21 Nov 2024 10:24:20 +0800 Subject: [PATCH] =?UTF-8?q?TicketNo:#IB5J11=20Description:=E6=96=B0?= =?UTF-8?q?=E9=9C=80=E6=B1=82=EF=BC=9ARTSP=E7=89=B9=E6=80=A7=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA(UWB=E6=94=AF=E6=8C=81=E5=92=8CStream=20Capability?= =?UTF-8?q?=E7=AD=89)=20Signed-off-by:=20LongestDistance=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session/src/cast_session_listeners.cpp | 1 + .../src/channel/src/channel_manager.cpp | 3 +- .../channel/src/softbus/softbus_connection.h | 3 +- .../channel/src/softbus/softbus_wrapper.cpp | 2 +- .../src/channel/src/tcp/tcp_connection.cpp | 42 +++++-- .../src/rtsp/include/i_rtsp_controller.h | 1 + .../session/src/rtsp/include/rtsp_basetype.h | 8 ++ .../src/rtsp/include/rtsp_param_info.h | 17 +++ .../session/src/rtsp/src/rtsp_controller.cpp | 114 +++++++++++++----- .../session/src/rtsp/src/rtsp_controller.h | 15 ++- .../src/session/src/rtsp/src/rtsp_package.cpp | 2 + .../session/src/rtsp/src/rtsp_param_info.cpp | 21 ++++ .../src/session/src/rtsp/src/rtsp_parse.cpp | 2 +- .../include/cast_stream_player_common.h | 8 +- 14 files changed, 193 insertions(+), 46 deletions(-) diff --git a/service/src/session/src/cast_session_listeners.cpp b/service/src/session/src/cast_session_listeners.cpp index 66ac8cb..6401b05 100644 --- a/service/src/session/src/cast_session_listeners.cpp +++ b/service/src/session/src/cast_session_listeners.cpp @@ -287,6 +287,7 @@ void CastSessionImpl::RtspListenerImpl::NotifyModuleCustomParamsNegotiation(cons if (session->property_.endType == EndType::CAST_SOURCE) { session->rtspControl_->ModuleCustomParamsNegotiationDone(); + session->rtspControl_->SetNegotiatedStreamCapability(controllerParams); std::string negotiationParams = session->streamManager_->HandleCustomNegotiationParams(controllerParams); session->rtspControl_->SetNegotiatedPlayerControllerCapability(negotiationParams); } diff --git a/service/src/session/src/channel/src/channel_manager.cpp b/service/src/session/src/channel/src/channel_manager.cpp index 527a55f..4d03c54 100644 --- a/service/src/session/src/channel/src/channel_manager.cpp +++ b/service/src/session/src/channel/src/channel_manager.cpp @@ -20,6 +20,7 @@ #include "cast_engine_log.h" #include "softbus/softbus_connection.h" #include "tcp/tcp_connection.h" +#include "utils.h" namespace OHOS { namespace CastEngine { @@ -150,7 +151,7 @@ bool ChannelManager::IsRequestValid(const ChannelRequest &request) const CLOGE("linkType is SoftBus and remoteDeviceId is empty."); return false; } - CLOGD("IsRequestValid In, remoteDeviceId = %{public}s.", request.remoteDeviceInfo.deviceId.c_str()); + CLOGD("IsRequestValid In, remoteDeviceId = %{public}s.", Utils::Mask(request.remoteDeviceInfo.deviceId).c_str()); return true; } diff --git a/service/src/session/src/channel/src/softbus/softbus_connection.h b/service/src/session/src/channel/src/softbus/softbus_connection.h index f4a5947..38a0e1f 100644 --- a/service/src/session/src/channel/src/softbus/softbus_connection.h +++ b/service/src/session/src/channel/src/softbus/softbus_connection.h @@ -46,11 +46,12 @@ public: int StartListen(const ChannelRequest &request, std::shared_ptr channelListener) override; bool Send(const uint8_t *buf, int bufLen) override; - SoftBusWrapper &GetSoftBus(); + bool GetActivelyOpenFlag() const; void SetActivelyOpenFlag(bool isActivelyOpen); bool GetPassiveCloseFlag() const; void SetPassiveCloseFlag(bool isPassiveClose); + SoftBusWrapper &GetSoftBus(); std::string GetType() override { return "SOFTBUS"; diff --git a/service/src/session/src/channel/src/softbus/softbus_wrapper.cpp b/service/src/session/src/channel/src/softbus/softbus_wrapper.cpp index 72b0fc8..cbf25b1 100644 --- a/service/src/session/src/channel/src/softbus/softbus_wrapper.cpp +++ b/service/src/session/src/channel/src/softbus/softbus_wrapper.cpp @@ -104,7 +104,7 @@ int SoftBusWrapper::OpenSoftBusSession(const std::string &peerNetworkId, const s CLOGD("OpenSoftBusSession In, MySessionName = %{public}s, peerNetworkId = %{public}s, GroupId = %{public}s," "attribute_.dataType = %{public}d, streamType = %{public}d.", - mySessionName_.c_str(), peerNetworkId.c_str(), groupId.c_str(), attribute_.dataType, + mySessionName_.c_str(), Utils::Mask(peerNetworkId).c_str(), groupId.c_str(), attribute_.dataType, attribute_.attr.streamAttr.streamType); int sessionId = OpenSession(mySessionName_.c_str(), peerSessionName.c_str(), peerNetworkId.c_str(), diff --git a/service/src/session/src/channel/src/tcp/tcp_connection.cpp b/service/src/session/src/channel/src/tcp/tcp_connection.cpp index 9886de7..9b61c5b 100644 --- a/service/src/session/src/channel/src/tcp/tcp_connection.cpp +++ b/service/src/session/src/channel/src/tcp/tcp_connection.cpp @@ -41,8 +41,12 @@ int TcpConnection::StartConnection(const ChannelRequest &request, std::shared_pt StashRequest(request); SetRequest(request); SetListener(channelListener); - - std::thread(&TcpConnection::Connect, shared_from_this()).detach(); + auto tcpConnection = shared_from_this(); + std::thread([tcpConnection] { + Utils::SetThreadName("TcpConnect"); + tcpConnection->Connect(); + }).detach(); + return RET_OK; } @@ -79,19 +83,30 @@ void TcpConnection::Connect() int TcpConnection::StartListen(const ChannelRequest &request, std::shared_ptr channelListener) { CLOGD("Tcp Start Listen Enter."); + ConfigSocket(); StashRequest(request); SetRequest(request); SetListener(channelListener); - + int port = socket_.Bind(request.localDeviceInfo.ipAddress, request.localPort); - CLOGD("Start server socket, localIp:%s, bindPort:%{public}d", request.localDeviceInfo.ipAddress.c_str(), port); + CLOGI("Start server socket, localIp:%s, bindPort:%{public}s", + request.localDeviceInfo.ipAddress.c_str(), Utils::Mask(std::to_string(port)).c_str()); socket_.Listen(SOMAXCONN); + + auto tcpConnection = shared_from_this(); if (request.moduleType == ModuleType::VIDEO && request.remoteDeviceInfo.deviceType != DeviceType::DEVICE_HICAR) { - std::thread(&TcpConnection::AcceptVideoAndAudio, shared_from_this()).detach(); + std::thread([tcpConnection] { + Utils::SetThreadName("TcpAcceptVideoAndAudio"); + tcpConnection->AcceptVideoAndAudio(); + }).detach(); } else { - std::thread(&TcpConnection::Accept, shared_from_this()).detach(); + std::thread([tcpConnection] { + Utils::SetThreadName("TcpAccept"); + tcpConnection->Accept(); + }).detach(); } + return port; } @@ -305,15 +320,22 @@ bool TcpConnection::Send(const uint8_t *buf, int bufLen) CLOGE("Data or length is illegal."); return false; } - uint8_t sendBuf[bufLen + PACKET_HEADER_LEN]; - Utils::IntToByteArray(bufLen, PACKET_HEADER_LEN, sendBuf); - errno_t cpyRet = memcpy_s(sendBuf + PACKET_HEADER_LEN, bufLen, buf, bufLen); + + std::unique_ptr sendBuf = std::make_unique(bufLen + PACKET_HEADER_LEN); + Utils::IntToByteArray(bufLen, PACKET_HEADER_LEN, sendBuf.get()); + errno_t cpyRet = memcpy_s(sendBuf.get() + PACKET_HEADER_LEN, bufLen, buf, bufLen); if (cpyRet != RET_OK) { return false; } + CLOGD("Tcp Send, socket = %{public}d, moduleType = %{public}d", remoteSocket_, channelRequest_.moduleType); int sockfd = remoteSocket_ == INVALID_SOCKET ? socket_.GetSocketFd() : remoteSocket_; - return socket_.Send(sockfd, sendBuf, bufLen + PACKET_HEADER_LEN) > RET_OK ? true : false; + int ret = socket_.Send(sockfd, sendBuf.get(), bufLen + PACKET_HEADER_LEN); + if (ret <= RET_OK && listener_) { + listener_->OnConnectionError(shared_from_this(), ret); + } + + return ret > RET_OK; } } // namespace CastEngineService } // namespace CastEngine diff --git a/service/src/session/src/rtsp/include/i_rtsp_controller.h b/service/src/session/src/rtsp/include/i_rtsp_controller.h index b2a9fd5..c814fd0 100644 --- a/service/src/session/src/rtsp/include/i_rtsp_controller.h +++ b/service/src/session/src/rtsp/include/i_rtsp_controller.h @@ -56,6 +56,7 @@ public: virtual void SetNegotiatedMediaCapability(const std::string &negotiationMediaParams) = 0; virtual void SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams) = 0; + virtual void SetNegotiatedStreamCapability(const std::string &controllerParams) = 0; virtual const std::set &GetNegotiatedFeatureSet() = 0; }; } // namespace CastSessionRtsp diff --git a/service/src/session/src/rtsp/include/rtsp_basetype.h b/service/src/session/src/rtsp/include/rtsp_basetype.h index b880df6..7341104 100644 --- a/service/src/session/src/rtsp/include/rtsp_basetype.h +++ b/service/src/session/src/rtsp/include/rtsp_basetype.h @@ -70,6 +70,14 @@ static const std::string MODULE_ID = "module_id"; static const std::string EVENT = "event"; static const std::string PARAM = "param"; +static const std::string KEY_DPI = "dpi"; +static const std::string KEY_SCREEN_HEIGHT = "screenHeight"; +static const std::string KEY_SCREEN_WIDTH = "screenWidth"; +static const std::string KEY_BEFORE_VIDEO_WIDTH = "beforeVideoWidth"; +static const std::string KEY_BEFORE_VIDEO_HEIGHT = "beforeVideoHeight"; +static const std::string KEY_AFTER_VIDEO_WIDTH = "afterVideoWidth"; +static const std::string KEY_AFTER_VIDEO_HEIGHT = "afterVideoHeight"; + static const int MIN_LINE_LENGTH = 3; static const int MIN_SPLIT_LENGTH = 1; static const int DEFAULT_LEN = 1; diff --git a/service/src/session/src/rtsp/include/rtsp_param_info.h b/service/src/session/src/rtsp/include/rtsp_param_info.h index 48ed15a..4041f48 100644 --- a/service/src/session/src/rtsp/include/rtsp_param_info.h +++ b/service/src/session/src/rtsp/include/rtsp_param_info.h @@ -101,6 +101,17 @@ public: void SetMediaCapability(const std::string &capability); ProjectionMode GetProjectionMode(); void SetProjectionMode(ProjectionMode projectionMode); + bool IsSupportUWB(); + void SetSupportUWB(bool isSupport); + const std::string GetStreamCapability(); + void SetStreamCapability(const std::string &capability); + + /** + * Feature: Base + * Feature number rule: + * 1xx: public module. eg: HisightSession capability + * 2xx: Controller capability + */ // channel feature static const int FEATURE_BASE = 0; @@ -108,17 +119,22 @@ public: static const int FEATURE_STOP_VTP = FEATURE_BASE + 101; static const int FEATURE_KEEP_ALIVE = FEATURE_BASE + 102; static const int FEATURE_SEND_EVENT_CHANGE = FEATURE_BASE + 103; + static const int FEATURE_STOP_CHANNEL = FEATURE_BASE + 104; + static const int FEATURE_AGGR_SEND = FEATURE_BASE + 105; + static const int FEATURE_MIRROR_STREAM_SWITCH = FEATURE_BASE + 106; // remote control feature static const int FEATURE_FINE_STYLUS = FEATURE_BASE + 201; static const int FEATURE_SOURCE_MOUSE = FEATURE_BASE + 202; static const int FEATURE_SOURCE_MOUSE_HISTORY = FEATURE_BASE + 203; + static const int FEATURE_PC_KEY_EVENT_MULTI_SESSION = FEATURE_BASE + 204; private: double version_ = 1.0; VtpType supportVtpOpt_{ VtpType::VTP_NOT_SUPPORT_VIDEO }; std::string playerControllerCapability_; std::string mediaCapability_; + std::string streamCapability_; std::set featureSet_; AudioProperty audioProperty_{}; VideoProperty videoProperty_; @@ -128,6 +144,7 @@ private: TransferParamInfo transferParamInfo_{}; RemoteControlParamInfo remoteControlParamInfo_{}; ProjectionMode projectionMode_{ ProjectionMode::MIRROR }; + bool mIsSupportUWB = false; }; } // namespace CastSessionRtsp } // namespace CastEngineService diff --git a/service/src/session/src/rtsp/src/rtsp_controller.cpp b/service/src/session/src/rtsp/src/rtsp_controller.cpp index b7abb11..e6775db 100644 --- a/service/src/session/src/rtsp/src/rtsp_controller.cpp +++ b/service/src/session/src/rtsp/src/rtsp_controller.cpp @@ -35,7 +35,14 @@ DEFINE_CAST_ENGINE_LABEL("Cast-Rtsp-Controller"); std::shared_ptr IRtspController::GetInstance(std::shared_ptr listener, ProtocolType protocolType, EndType endType) { - return std::static_pointer_cast(std::make_shared(listener, protocolType, endType)); + auto rtspController = std::make_shared(listener, protocolType, endType); + if (!rtspController) { + CLOGE("rtspController is nullptr"); + return nullptr; + } + rtspController->Init(); + + return std::static_pointer_cast(rtspController); } RtspController::RtspController(std::shared_ptr listener, ProtocolType protocolType, EndType endType) @@ -49,6 +56,13 @@ RtspController::~RtspController() CLOGI("~RtspController in."); } +void RtspController::Init() +{ + rtspNetManager_ = std::make_shared(shared_from_this(), protocolType_); + ResponseFuncMapInit(); + RequestFuncMapInit(); +} + std::shared_ptr RtspController::GetChannelListener() { CLOGD("In, get channel listener."); @@ -59,7 +73,8 @@ void RtspController::AddChannel(std::shared_ptr channel, const CastInne { rtspNetManager_->AddChannel(channel, device); deviceId_ = device.deviceId; - CLOGD("Out, deviceId %{public}s", deviceId_.c_str()); + + CLOGD("Out, deviceId %{public}s", Utils::Mask(deviceId_).c_str()); } void RtspController::RemoveChannel(std::shared_ptr channel) @@ -171,6 +186,7 @@ void RtspController::OnPeerReady(bool isSoftbus) } if (!isSendSuccess) { + CLOGE("Send rtsp data failed"); listener_->OnError(ERROR_CODE_DEFAULT); } } @@ -223,7 +239,7 @@ bool RtspController::OnResponse(RtspParse &response) } if (!isSuccess && (listener_ != nullptr)) { - CLOGD("OnResponse error in State %{public}d", waitRsp_); + CLOGE("OnResponse error in State %{public}d", waitRsp_); listener_->OnError(ERROR_CODE_DEFAULT); } return isSuccess; @@ -236,8 +252,7 @@ void RtspController::DetectKeepAliveFeature() const void RtspController::SetupPort(int serverPort, int remotectlPort, int cpPort) { - CLOGD("SetupPort: server port %{public}d remotectlPort %{public}d cpPort %{public}d", - serverPort, remotectlPort, cpPort); + CLOGD("SetupPort"); std::string rsp = RtspEncap::EncapSetupResponse(paramInfo_, currentSetUpSeq_, serverPort, remotectlPort, cpPort); bool isSuccess = rtspNetManager_->SendRtspData(rsp); state_ = RtspEngineState::STATE_ESTABLISHED; @@ -245,6 +260,7 @@ void RtspController::SetupPort(int serverPort, int remotectlPort, int cpPort) CLOGE("Send setup response error."); listener_->OnError(ERROR_CODE_DEFAULT); } + return; } @@ -266,18 +282,12 @@ bool RtspController::DealAnnounceRequest(RtspParse &response) if (endType_ != EndType::CAST_SOURCE) { return true; } - - auto remote = CastDeviceDataManager::GetInstance().GetDeviceByDeviceId(deviceId_); - if (remote == std::nullopt) { - CLOGE("Get remote device is empty"); - return false; - } rtspNetManager_->SetNegAlgorithmId(negotiatedParamInfo_.GetEncryptionParamInfo().controlChannelAlgId); SendOptionM1M2(); waitRsp_ = WaitResponse::WAITING_RSP_OPT_M1; - CLOGD("Out, SendOptionM1M2."); + CLOGI("Out, SendOptionM1M2."); return true; } @@ -333,21 +343,21 @@ bool RtspController::ProcessAnnounceRequest(RtspParse &request) std::string content = request.GetHeader()["encrypt_description"]; if (content.empty() && (listener_ != nullptr)) { CLOGE("ProcessAnnounceRequest No encrypt_description."); - listener_->OnError(ERROR_CODE_DEFAULT); + return false; } std::string encryptStr = RtspParse::GetTargetStr(content, "encrypt_list=", COMMON_SEPARATOR); if (encryptStr.empty() && (listener_ != nullptr)) { CLOGE("Get encrypt str fail."); - listener_->OnError(ERROR_CODE_DEFAULT); + return false; } // only support ctr EncryptDecrypt &instance = EncryptDecrypt::GetInstance(); int version = instance.GetVersion(); - CLOGD("AuthNeg: Get algStr is %{public}s version %{public}d", encryptStr.c_str(), version); + CLOGI("AuthNeg: Get algStr is %{public}s version %{public}d", encryptStr.c_str(), version); std::set cipherList = ParseCipherItem(encryptStr); if (cipherList.empty() && (listener_ != nullptr)) { @@ -516,7 +526,8 @@ bool RtspController::ProcessPauseRequest(RtspParse &request) bool RtspController::ProcessTearDownRequest(RtspParse &request) { - CLOGD("Receive sink teardown request."); + CLOGI("Receive sink teardown request."); + if (!Utils::StartWith(request.GetFirstLine(), "Teardown")) { CLOGE("Process teardown request error"); if (listener_ != nullptr) { @@ -586,6 +597,7 @@ void RtspController::ProcessTriggerMethod(RtspParse &request, const std::string } else if (triggerMethod == ACTION_TYPE_STR[static_cast(ActionType::PAUSE)]) { listener_->OnPause(); } else if (triggerMethod == ACTION_TYPE_STR[static_cast(ActionType::TEARDOWN)]) { + CLOGI("Receive teardown trigger method"); listener_->OnTearDown(); } else if (triggerMethod == ACTION_TYPE_STR[static_cast(ActionType::SEND_EVENT_CHANGE)]) { ProcessEventChangeRequest(request); @@ -703,13 +715,15 @@ bool RtspController::ProcessGetParamM3Response(RtspParse &response) } negotiatedParamInfo_.SetVersion(RtspParse::ParseDoubleSafe(response.GetHeader()["his_version"])); CLOGD("Sink HiSight version is %.2f", negotiatedParamInfo_.GetVersion()); - + negotiatedParamInfo_.SetSupportUWB(RtspParse::ParseDoubleSafe(response.GetHeader()["his_support_uwb"]) == 1); + // 考虑向前兼容性,需要先解析device type if (response.GetHeader()["his_device_type"].empty()) { ProcessSinkDeviceType(""); } else { ProcessSinkDeviceType((*(response.GetHeader().find("his_device_type"))).second); } + std::string content = response.GetHeader()["his_video_formats"]; if (content.empty()) { CLOGE("Process M3 Rsp Error, sink not have his_video_formats."); @@ -811,8 +825,9 @@ bool RtspController::ProcessPlayM7Response(RtspParse &response) bool RtspController::ProcessTearDownM8Response(RtspParse &response) { - CLOGD("WaitRsp state %{public}d receive teardown response, status %{public}d.", waitRsp_, response.GetStatusCode()); + CLOGI("WaitRsp state %{public}d receive teardown response, status %{public}d.", waitRsp_, response.GetStatusCode()); listener_->OnTearDown(); + return true; } @@ -872,11 +887,14 @@ void RtspController::ProcessUibc(const std::string &content) CLOGE("No generic_cap_list."); return; } + if (paramInfo_.GetRemoteControlParamInfo().genericList.size() <= 0) { CLOGE("Local genericList is empty."); return; } - ProcessUibcDetermine(genericStr, remoteControlParamInfo.genericList); + + ProcessUibcDetermine(genericStr, remoteControlParamInfo.genericList, + paramInfo_.GetRemoteControlParamInfo().genericList); remoteControlParamInfo.isSupportGeneric = true; } @@ -886,13 +904,17 @@ void RtspController::ProcessUibc(const std::string &content) CLOGE("No hidc_cap_list."); return; } + if (paramInfo_.GetRemoteControlParamInfo().hidcList.size() <= 0) { CLOGE("Local hidcList is empty."); return; } - ProcessUibcDetermine(hidcStr, remoteControlParamInfo.hidcList); + + ProcessUibcDetermine(hidcStr, remoteControlParamInfo.hidcList, + paramInfo_.GetRemoteControlParamInfo().hidcList); remoteControlParamInfo.isSupportHidc = true; } + ProcessUibcVendor(content, remoteControlParamInfo); negotiatedParamInfo_.SetRemoteControlParamInfo(remoteControlParamInfo); @@ -908,23 +930,33 @@ void RtspController::ProcessUibcVendor(const std::string &content, RemoteControl CLOGE("No vendor_cap_list."); return; } + if (paramInfo_.GetRemoteControlParamInfo().vendorList.size() <= 0) { CLOGE("Local vendor_list is empty."); return; } - ProcessUibcDetermine(vendorStr, remoteControlParamInfo.vendorList); + + ProcessUibcDetermine(vendorStr, remoteControlParamInfo.vendorList, + paramInfo_.GetRemoteControlParamInfo().vendorList); remoteControlParamInfo.isSupportVendor = true; } } -void RtspController::ProcessUibcDetermine(const std::string &givenStr, std::vector &list) +void RtspController::ProcessUibcDetermine(const std::string &givenStr, std::vector &intersection, + const std::vector &localList) { CLOGD("In, %{public}s.", givenStr.c_str()); + std::vector splitStrings; Utils::SplitString(givenStr, splitStrings, ", "); - list.clear(); + intersection.clear(); for (auto &iter : splitStrings) { - list.push_back(iter); + auto it = std::find(localList.begin(), localList.end(), iter); + if (it == localList.end()) { + CLOGI("local not support event:%{public}s", iter.c_str()); + continue; + } + intersection.push_back(iter); } } @@ -966,10 +998,12 @@ void RtspController::ProcessSinkBitrate(const std::string &content, VideoPropert void RtspController::ProcessSinkVideoForResolution(const std::string &content, VideoProperty &videoProperty) { CLOGD("In, %{public}s.", content.c_str()); - std::string strHeight = RtspParse::GetTargetStr(content, "height", ""); + std::string strHeight = RtspParse::GetTargetStr(content, "height", COMMON_SEPARATOR); std::string strWidth = RtspParse::GetTargetStr(content, "width", COMMON_SEPARATOR); uint32_t height = (!strHeight.empty()) ? RtspParse::ParseUint32Safe(strHeight) : 0; uint32_t width = (!strWidth.empty()) ? RtspParse::ParseUint32Safe(strWidth) : 0; + screenParam_[KEY_BEFORE_VIDEO_HEIGHT] = height; + screenParam_[KEY_BEFORE_VIDEO_WIDTH] = width; if ((height > 0) && (width > 0)) { videoProperty.videoHeight = height; videoProperty.videoWidth = width; @@ -1027,6 +1061,20 @@ void RtspController::ProcessVideoInfo(const std::string &content) negotiatedParamInfo_.GetVideoProperty().videoWidth, negotiatedParamInfo_.GetVideoProperty().videoHeight, negotiatedParamInfo_.GetVideoProperty().fps, negotiatedParamInfo_.GetVideoProperty().codecType, negotiatedParamInfo_.GetVideoProperty().gop); + AddScreenParam(); +} + +void RtspController::AddScreenParam() +{ + CLOGI("AddScreenParam"); + + screenParam_[KEY_SCREEN_HEIGHT] = negotiatedParamInfo_.GetVideoProperty().screenHeight; + screenParam_[KEY_SCREEN_WIDTH] = negotiatedParamInfo_.GetVideoProperty().screenWidth; + screenParam_[KEY_DPI] = negotiatedParamInfo_.GetVideoProperty().dpi; + screenParam_[KEY_AFTER_VIDEO_HEIGHT] = negotiatedParamInfo_.GetVideoProperty().videoHeight; + screenParam_[KEY_AFTER_VIDEO_WIDTH] = negotiatedParamInfo_.GetVideoProperty().videoWidth; + std::string data = screenParam_.dump(); + listener_->NotifyScreenParam(data); } void RtspController::ProcessAudioExpandInfo(const std::string &content, AudioProperty &audioProperty) @@ -1203,13 +1251,20 @@ void RtspController::ProcessModuleCustomParams(const std::string &mediaParams, c if (strPos != std::string::npos) { controllerParamsProcessed = controllerParams.substr(0, strPos); } - CLOGD("In, mediaParams:%{public}s controllerParams:%{public}s.", mediaParams.c_str(), + + auto mediaParamsProcessed = mediaParams; + auto mediaStrPos = mediaParams.find(COMMON_SEPARATOR); + if (strPos != std::string::npos) { + mediaParamsProcessed = mediaParams.substr(0, mediaStrPos); + } + CLOGD("In, mediaParams:%{public}s controllerParams:%{public}s.", mediaParamsProcessed.c_str(), controllerParamsProcessed.c_str()); + if (listener_ == nullptr) { CLOGE("Listener is null."); return; } - listener_->NotifyModuleCustomParamsNegotiation(mediaParams, controllerParamsProcessed); + listener_->NotifyModuleCustomParamsNegotiation(mediaParamsProcessed, controllerParamsProcessed); } bool RtspController::SendOptionM1M2() @@ -1303,6 +1358,11 @@ void RtspController::SetNegotiatedMediaCapability(const std::string &negotiation negotiatedParamInfo_.SetMediaCapability(negotiationMediaParams); } +void RtspController::SetNegotiatedStreamCapability(const std::string &controllerParams) +{ + negotiatedParamInfo_.SetStreamCapability(controllerParams); +} + void RtspController::SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams) { negotiatedParamInfo_.SetPlayerControllerCapability(negotiationParams); diff --git a/service/src/session/src/rtsp/src/rtsp_controller.h b/service/src/session/src/rtsp/src/rtsp_controller.h index 88397e2..ada20d9 100644 --- a/service/src/session/src/rtsp/src/rtsp_controller.h +++ b/service/src/session/src/rtsp/src/rtsp_controller.h @@ -18,17 +18,21 @@ #ifndef LIBCASTENGINE_RTSP_CONTROLLER_H #define LIBCASTENGINE_RTSP_CONTROLLER_H +#include #include "channel.h" #include "rtsp_listener.h" #include "rtsp_listener_inner.h" #include "rtsp_channel_manager.h" #include "i_rtsp_controller.h" +#include "nlohmann/json.hpp" namespace OHOS { namespace CastEngine { namespace CastEngineService { namespace CastSessionRtsp { -class RtspController : public IRtspController, public RtspListenerInner { +class RtspController : public IRtspController, + public RtspListenerInner, + public std::enable_shared_from_this { public: RtspController(std::shared_ptr listener, ProtocolType protocolType, EndType endType); ~RtspController() override; @@ -52,6 +56,8 @@ public: void ModuleCustomParamsNegotiationDone() override; void SetNegotiatedMediaCapability(const std::string &negotiationMediaParams) override; void SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams) override; + void SetNegotiatedStreamCapability(const std::string &controllerParams) override; + void Init(); private: enum class RtspEngineState { @@ -92,7 +98,8 @@ private: void ProcessUibc(const std::string &content); bool PreProcessUibc(const std::string &content, std::string &categoryList); void ProcessUibcVendor(const std::string &content, RemoteControlParamInfo &remoteControlParamInfo); - void ProcessUibcDetermine(const std::string &givenStr, std::vector &list); + void ProcessUibcDetermine(const std::string &givenStr, std::vector &intersection, + const std::vector &localList); void ProcessSinkBitrate(const std::string &content, VideoProperty &videoProperty); void ProcessVideoInfo(const std::string &content); void ProcessAudioInfo(RtspParse &parseInfo); @@ -113,6 +120,7 @@ private: void ProcessTriggerMethod(RtspParse &request, const std::string &triggerMethod); void ResponseFuncMapInit(); void RequestFuncMapInit(); + void AddScreenParam(); const ProtocolType protocolType_; std::shared_ptr listener_; @@ -121,13 +129,14 @@ private: int currentSetUpSeq_{ 0 }; int currentKeepAliveCseq_{ 0 }; WaitResponse waitRsp_{ WaitResponse::WAITING_RSP_NONE }; - std::unique_ptr rtspNetManager_; + std::shared_ptr rtspNetManager_; ParamInfo paramInfo_{}; ParamInfo negotiatedParamInfo_{}; RtspEngineState state_{ RtspEngineState::STATE_STOPPED }; std::string deviceId_; std::map responseFuncMap_; std::map requestFuncMap_; + nlohmann::json screenParam_; }; } // namespace CastSessionRtsp } // namespace CastEngineService diff --git a/service/src/session/src/rtsp/src/rtsp_package.cpp b/service/src/session/src/rtsp/src/rtsp_package.cpp index c271b74..39ba374 100644 --- a/service/src/session/src/rtsp/src/rtsp_package.cpp +++ b/service/src/session/src/rtsp/src/rtsp_package.cpp @@ -393,6 +393,8 @@ std::string RtspEncap::EncapSetParameterM4Request(ParamInfo &negParam, double ve std::string body; body.append(SetVideoAndAudioCodecsParameter(negParam)); body.append(SetAudioParameter(negParam)); + body.append("his_support_uwb: ") + .append(std::to_string(negParam.IsSupportUWB())).append(MSG_SEPARATOR); SetAnotherParameter(negParam, version, ip, body); diff --git a/service/src/session/src/rtsp/src/rtsp_param_info.cpp b/service/src/session/src/rtsp/src/rtsp_param_info.cpp index 03c0c4a..8f600fb 100644 --- a/service/src/session/src/rtsp/src/rtsp_param_info.cpp +++ b/service/src/session/src/rtsp/src/rtsp_param_info.cpp @@ -141,6 +141,16 @@ void ParamInfo::SetMediaCapability(const std::string &capability) this->mediaCapability_ = capability; } +const std::string ParamInfo::GetStreamCapability() +{ + return streamCapability_; +} + +void ParamInfo::SetStreamCapability(const std::string &capability) +{ + this->streamCapability_ = capability; +} + ProjectionMode ParamInfo::GetProjectionMode() { return projectionMode_; @@ -150,6 +160,17 @@ void ParamInfo::SetProjectionMode(ProjectionMode projectionMode) { this->projectionMode_ = projectionMode; } + +bool ParamInfo::IsSupportUWB() +{ + return mIsSupportUWB; +} + +void ParamInfo::SetSupportUWB(bool isSupport) +{ + mIsSupportUWB = isSupport; +} + } // namespace CastSessionRtsp } // namespace CastEngineService } // namespace CastEngine diff --git a/service/src/session/src/rtsp/src/rtsp_parse.cpp b/service/src/session/src/rtsp/src/rtsp_parse.cpp index 34af344..40d650f 100644 --- a/service/src/session/src/rtsp/src/rtsp_parse.cpp +++ b/service/src/session/src/rtsp/src/rtsp_parse.cpp @@ -127,7 +127,7 @@ double RtspParse::ParseDoubleSafe(const std::string &str) } char *nextPtr = nullptr; - double result = strtod(str.c_str(), nullptr); + double result = strtod(str.c_str(), &nextPtr); if (errno == ERANGE) { CLOGE("Parse double out of range"); return INVALID_VALUE; diff --git a/service/src/session/src/stream/src/player/include/cast_stream_player_common.h b/service/src/session/src/stream/src/player/include/cast_stream_player_common.h index 9f9f6d4..0760b6d 100644 --- a/service/src/session/src/stream/src/player/include/cast_stream_player_common.h +++ b/service/src/session/src/stream/src/player/include/cast_stream_player_common.h @@ -28,14 +28,18 @@ static std::map g_mediaSpeedToPlaybackSp { Media::SPEED_FORWARD_1_00_X, PlaybackSpeed::SPEED_FORWARD_1_00_X }, { Media::SPEED_FORWARD_1_25_X, PlaybackSpeed::SPEED_FORWARD_1_25_X }, { Media::SPEED_FORWARD_1_75_X, PlaybackSpeed::SPEED_FORWARD_1_75_X }, - { Media::SPEED_FORWARD_2_00_X, PlaybackSpeed::SPEED_FORWARD_2_00_X } + { Media::SPEED_FORWARD_2_00_X, PlaybackSpeed::SPEED_FORWARD_2_00_X }, + { Media::SPEED_FORWARD_0_50_X, PlaybackSpeed::SPEED_FORWARD_0_50_X }, + { Media::SPEED_FORWARD_1_50_X, PlaybackSpeed::SPEED_FORWARD_1_50_X } }; static std::map g_doubleToModeTypeMap = { { PlaybackSpeed::SPEED_FORWARD_0_75_X, Media::SPEED_FORWARD_0_75_X }, { PlaybackSpeed::SPEED_FORWARD_1_00_X, Media::SPEED_FORWARD_1_00_X }, { PlaybackSpeed::SPEED_FORWARD_1_25_X, Media::SPEED_FORWARD_1_25_X }, { PlaybackSpeed::SPEED_FORWARD_1_75_X, Media::SPEED_FORWARD_1_75_X }, - { PlaybackSpeed::SPEED_FORWARD_2_00_X, Media::SPEED_FORWARD_2_00_X } + { PlaybackSpeed::SPEED_FORWARD_2_00_X, Media::SPEED_FORWARD_2_00_X }, + { PlaybackSpeed::SPEED_FORWARD_0_50_X, Media::SPEED_FORWARD_0_50_X }, + { PlaybackSpeed::SPEED_FORWARD_1_50_X, Media::SPEED_FORWARD_1_50_X } }; } // namespace CastEngine } // namespace OHOS