TicketNo:#IB5J11 Description:新需求:RTSP特性增强(UWB支持和Stream Capability等)

Signed-off-by: LongestDistance <cdwango@isoftstone.com>
This commit is contained in:
LongestDistance 2024-11-21 10:24:20 +08:00
parent 96469408c6
commit 454c83a2bd
14 changed files with 193 additions and 46 deletions

View File

@ -287,6 +287,7 @@ void CastSessionImpl::RtspListenerImpl::NotifyModuleCustomParamsNegotiation(cons
if (session->property_.endType == EndType::CAST_SOURCE) { if (session->property_.endType == EndType::CAST_SOURCE) {
session->rtspControl_->ModuleCustomParamsNegotiationDone(); session->rtspControl_->ModuleCustomParamsNegotiationDone();
session->rtspControl_->SetNegotiatedStreamCapability(controllerParams);
std::string negotiationParams = session->streamManager_->HandleCustomNegotiationParams(controllerParams); std::string negotiationParams = session->streamManager_->HandleCustomNegotiationParams(controllerParams);
session->rtspControl_->SetNegotiatedPlayerControllerCapability(negotiationParams); session->rtspControl_->SetNegotiatedPlayerControllerCapability(negotiationParams);
} }

View File

@ -20,6 +20,7 @@
#include "cast_engine_log.h" #include "cast_engine_log.h"
#include "softbus/softbus_connection.h" #include "softbus/softbus_connection.h"
#include "tcp/tcp_connection.h" #include "tcp/tcp_connection.h"
#include "utils.h"
namespace OHOS { namespace OHOS {
namespace CastEngine { namespace CastEngine {
@ -150,7 +151,7 @@ bool ChannelManager::IsRequestValid(const ChannelRequest &request) const
CLOGE("linkType is SoftBus and remoteDeviceId is empty."); CLOGE("linkType is SoftBus and remoteDeviceId is empty.");
return false; 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; return true;
} }

View File

@ -46,11 +46,12 @@ public:
int StartListen(const ChannelRequest &request, std::shared_ptr<IChannelListener> channelListener) override; int StartListen(const ChannelRequest &request, std::shared_ptr<IChannelListener> channelListener) override;
bool Send(const uint8_t *buf, int bufLen) override; bool Send(const uint8_t *buf, int bufLen) override;
SoftBusWrapper &GetSoftBus();
bool GetActivelyOpenFlag() const; bool GetActivelyOpenFlag() const;
void SetActivelyOpenFlag(bool isActivelyOpen); void SetActivelyOpenFlag(bool isActivelyOpen);
bool GetPassiveCloseFlag() const; bool GetPassiveCloseFlag() const;
void SetPassiveCloseFlag(bool isPassiveClose); void SetPassiveCloseFlag(bool isPassiveClose);
SoftBusWrapper &GetSoftBus();
std::string GetType() override std::string GetType() override
{ {
return "SOFTBUS"; return "SOFTBUS";

View File

@ -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," CLOGD("OpenSoftBusSession In, MySessionName = %{public}s, peerNetworkId = %{public}s, GroupId = %{public}s,"
"attribute_.dataType = %{public}d, streamType = %{public}d.", "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); attribute_.attr.streamAttr.streamType);
int sessionId = OpenSession(mySessionName_.c_str(), peerSessionName.c_str(), peerNetworkId.c_str(), int sessionId = OpenSession(mySessionName_.c_str(), peerSessionName.c_str(), peerNetworkId.c_str(),

View File

@ -41,8 +41,12 @@ int TcpConnection::StartConnection(const ChannelRequest &request, std::shared_pt
StashRequest(request); StashRequest(request);
SetRequest(request); SetRequest(request);
SetListener(channelListener); SetListener(channelListener);
auto tcpConnection = shared_from_this();
std::thread(&TcpConnection::Connect, shared_from_this()).detach(); std::thread([tcpConnection] {
Utils::SetThreadName("TcpConnect");
tcpConnection->Connect();
}).detach();
return RET_OK; return RET_OK;
} }
@ -79,19 +83,30 @@ void TcpConnection::Connect()
int TcpConnection::StartListen(const ChannelRequest &request, std::shared_ptr<IChannelListener> channelListener) int TcpConnection::StartListen(const ChannelRequest &request, std::shared_ptr<IChannelListener> channelListener)
{ {
CLOGD("Tcp Start Listen Enter."); CLOGD("Tcp Start Listen Enter.");
ConfigSocket(); ConfigSocket();
StashRequest(request); StashRequest(request);
SetRequest(request); SetRequest(request);
SetListener(channelListener); SetListener(channelListener);
int port = socket_.Bind(request.localDeviceInfo.ipAddress, request.localPort); 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); socket_.Listen(SOMAXCONN);
auto tcpConnection = shared_from_this();
if (request.moduleType == ModuleType::VIDEO && request.remoteDeviceInfo.deviceType != DeviceType::DEVICE_HICAR) { 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 { } else {
std::thread(&TcpConnection::Accept, shared_from_this()).detach(); std::thread([tcpConnection] {
Utils::SetThreadName("TcpAccept");
tcpConnection->Accept();
}).detach();
} }
return port; return port;
} }
@ -305,15 +320,22 @@ bool TcpConnection::Send(const uint8_t *buf, int bufLen)
CLOGE("Data or length is illegal."); CLOGE("Data or length is illegal.");
return false; return false;
} }
uint8_t sendBuf[bufLen + PACKET_HEADER_LEN];
Utils::IntToByteArray(bufLen, PACKET_HEADER_LEN, sendBuf); std::unique_ptr<uint8_t[]> sendBuf = std::make_unique<uint8_t[]>(bufLen + PACKET_HEADER_LEN);
errno_t cpyRet = memcpy_s(sendBuf + PACKET_HEADER_LEN, bufLen, buf, bufLen); 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) { if (cpyRet != RET_OK) {
return false; return false;
} }
CLOGD("Tcp Send, socket = %{public}d, moduleType = %{public}d", remoteSocket_, channelRequest_.moduleType); CLOGD("Tcp Send, socket = %{public}d, moduleType = %{public}d", remoteSocket_, channelRequest_.moduleType);
int sockfd = remoteSocket_ == INVALID_SOCKET ? socket_.GetSocketFd() : remoteSocket_; 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 CastEngineService
} // namespace CastEngine } // namespace CastEngine

View File

@ -56,6 +56,7 @@ public:
virtual void SetNegotiatedMediaCapability(const std::string &negotiationMediaParams) = 0; virtual void SetNegotiatedMediaCapability(const std::string &negotiationMediaParams) = 0;
virtual void SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams) = 0; virtual void SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams) = 0;
virtual void SetNegotiatedStreamCapability(const std::string &controllerParams) = 0;
virtual const std::set<int> &GetNegotiatedFeatureSet() = 0; virtual const std::set<int> &GetNegotiatedFeatureSet() = 0;
}; };
} // namespace CastSessionRtsp } // namespace CastSessionRtsp

View File

@ -70,6 +70,14 @@ static const std::string MODULE_ID = "module_id";
static const std::string EVENT = "event"; static const std::string EVENT = "event";
static const std::string PARAM = "param"; 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_LINE_LENGTH = 3;
static const int MIN_SPLIT_LENGTH = 1; static const int MIN_SPLIT_LENGTH = 1;
static const int DEFAULT_LEN = 1; static const int DEFAULT_LEN = 1;

View File

@ -101,6 +101,17 @@ public:
void SetMediaCapability(const std::string &capability); void SetMediaCapability(const std::string &capability);
ProjectionMode GetProjectionMode(); ProjectionMode GetProjectionMode();
void SetProjectionMode(ProjectionMode projectionMode); 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 // channel feature
static const int FEATURE_BASE = 0; static const int FEATURE_BASE = 0;
@ -108,17 +119,22 @@ public:
static const int FEATURE_STOP_VTP = FEATURE_BASE + 101; static const int FEATURE_STOP_VTP = FEATURE_BASE + 101;
static const int FEATURE_KEEP_ALIVE = FEATURE_BASE + 102; static const int FEATURE_KEEP_ALIVE = FEATURE_BASE + 102;
static const int FEATURE_SEND_EVENT_CHANGE = FEATURE_BASE + 103; 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 // remote control feature
static const int FEATURE_FINE_STYLUS = FEATURE_BASE + 201; static const int FEATURE_FINE_STYLUS = FEATURE_BASE + 201;
static const int FEATURE_SOURCE_MOUSE = FEATURE_BASE + 202; static const int FEATURE_SOURCE_MOUSE = FEATURE_BASE + 202;
static const int FEATURE_SOURCE_MOUSE_HISTORY = FEATURE_BASE + 203; static const int FEATURE_SOURCE_MOUSE_HISTORY = FEATURE_BASE + 203;
static const int FEATURE_PC_KEY_EVENT_MULTI_SESSION = FEATURE_BASE + 204;
private: private:
double version_ = 1.0; double version_ = 1.0;
VtpType supportVtpOpt_{ VtpType::VTP_NOT_SUPPORT_VIDEO }; VtpType supportVtpOpt_{ VtpType::VTP_NOT_SUPPORT_VIDEO };
std::string playerControllerCapability_; std::string playerControllerCapability_;
std::string mediaCapability_; std::string mediaCapability_;
std::string streamCapability_;
std::set<int> featureSet_; std::set<int> featureSet_;
AudioProperty audioProperty_{}; AudioProperty audioProperty_{};
VideoProperty videoProperty_; VideoProperty videoProperty_;
@ -128,6 +144,7 @@ private:
TransferParamInfo transferParamInfo_{}; TransferParamInfo transferParamInfo_{};
RemoteControlParamInfo remoteControlParamInfo_{}; RemoteControlParamInfo remoteControlParamInfo_{};
ProjectionMode projectionMode_{ ProjectionMode::MIRROR }; ProjectionMode projectionMode_{ ProjectionMode::MIRROR };
bool mIsSupportUWB = false;
}; };
} // namespace CastSessionRtsp } // namespace CastSessionRtsp
} // namespace CastEngineService } // namespace CastEngineService

View File

@ -35,7 +35,14 @@ DEFINE_CAST_ENGINE_LABEL("Cast-Rtsp-Controller");
std::shared_ptr<IRtspController> IRtspController::GetInstance(std::shared_ptr<IRtspListener> listener, std::shared_ptr<IRtspController> IRtspController::GetInstance(std::shared_ptr<IRtspListener> listener,
ProtocolType protocolType, EndType endType) ProtocolType protocolType, EndType endType)
{ {
return std::static_pointer_cast<IRtspController>(std::make_shared<RtspController>(listener, protocolType, endType)); auto rtspController = std::make_shared<RtspController>(listener, protocolType, endType);
if (!rtspController) {
CLOGE("rtspController is nullptr");
return nullptr;
}
rtspController->Init();
return std::static_pointer_cast<IRtspController>(rtspController);
} }
RtspController::RtspController(std::shared_ptr<IRtspListener> listener, ProtocolType protocolType, EndType endType) RtspController::RtspController(std::shared_ptr<IRtspListener> listener, ProtocolType protocolType, EndType endType)
@ -49,6 +56,13 @@ RtspController::~RtspController()
CLOGI("~RtspController in."); CLOGI("~RtspController in.");
} }
void RtspController::Init()
{
rtspNetManager_ = std::make_shared<RtspChannelManager>(shared_from_this(), protocolType_);
ResponseFuncMapInit();
RequestFuncMapInit();
}
std::shared_ptr<IChannelListener> RtspController::GetChannelListener() std::shared_ptr<IChannelListener> RtspController::GetChannelListener()
{ {
CLOGD("In, get channel listener."); CLOGD("In, get channel listener.");
@ -59,7 +73,8 @@ void RtspController::AddChannel(std::shared_ptr<Channel> channel, const CastInne
{ {
rtspNetManager_->AddChannel(channel, device); rtspNetManager_->AddChannel(channel, device);
deviceId_ = device.deviceId; 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> channel) void RtspController::RemoveChannel(std::shared_ptr<Channel> channel)
@ -171,6 +186,7 @@ void RtspController::OnPeerReady(bool isSoftbus)
} }
if (!isSendSuccess) { if (!isSendSuccess) {
CLOGE("Send rtsp data failed");
listener_->OnError(ERROR_CODE_DEFAULT); listener_->OnError(ERROR_CODE_DEFAULT);
} }
} }
@ -223,7 +239,7 @@ bool RtspController::OnResponse(RtspParse &response)
} }
if (!isSuccess && (listener_ != nullptr)) { 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); listener_->OnError(ERROR_CODE_DEFAULT);
} }
return isSuccess; return isSuccess;
@ -236,8 +252,7 @@ void RtspController::DetectKeepAliveFeature() const
void RtspController::SetupPort(int serverPort, int remotectlPort, int cpPort) void RtspController::SetupPort(int serverPort, int remotectlPort, int cpPort)
{ {
CLOGD("SetupPort: server port %{public}d remotectlPort %{public}d cpPort %{public}d", CLOGD("SetupPort");
serverPort, remotectlPort, cpPort);
std::string rsp = RtspEncap::EncapSetupResponse(paramInfo_, currentSetUpSeq_, serverPort, remotectlPort, cpPort); std::string rsp = RtspEncap::EncapSetupResponse(paramInfo_, currentSetUpSeq_, serverPort, remotectlPort, cpPort);
bool isSuccess = rtspNetManager_->SendRtspData(rsp); bool isSuccess = rtspNetManager_->SendRtspData(rsp);
state_ = RtspEngineState::STATE_ESTABLISHED; state_ = RtspEngineState::STATE_ESTABLISHED;
@ -245,6 +260,7 @@ void RtspController::SetupPort(int serverPort, int remotectlPort, int cpPort)
CLOGE("Send setup response error."); CLOGE("Send setup response error.");
listener_->OnError(ERROR_CODE_DEFAULT); listener_->OnError(ERROR_CODE_DEFAULT);
} }
return; return;
} }
@ -266,18 +282,12 @@ bool RtspController::DealAnnounceRequest(RtspParse &response)
if (endType_ != EndType::CAST_SOURCE) { if (endType_ != EndType::CAST_SOURCE) {
return true; 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); rtspNetManager_->SetNegAlgorithmId(negotiatedParamInfo_.GetEncryptionParamInfo().controlChannelAlgId);
SendOptionM1M2(); SendOptionM1M2();
waitRsp_ = WaitResponse::WAITING_RSP_OPT_M1; waitRsp_ = WaitResponse::WAITING_RSP_OPT_M1;
CLOGD("Out, SendOptionM1M2.");
CLOGI("Out, SendOptionM1M2.");
return true; return true;
} }
@ -333,21 +343,21 @@ bool RtspController::ProcessAnnounceRequest(RtspParse &request)
std::string content = request.GetHeader()["encrypt_description"]; std::string content = request.GetHeader()["encrypt_description"];
if (content.empty() && (listener_ != nullptr)) { if (content.empty() && (listener_ != nullptr)) {
CLOGE("ProcessAnnounceRequest No encrypt_description."); CLOGE("ProcessAnnounceRequest No encrypt_description.");
listener_->OnError(ERROR_CODE_DEFAULT);
return false; return false;
} }
std::string encryptStr = RtspParse::GetTargetStr(content, "encrypt_list=", COMMON_SEPARATOR); std::string encryptStr = RtspParse::GetTargetStr(content, "encrypt_list=", COMMON_SEPARATOR);
if (encryptStr.empty() && (listener_ != nullptr)) { if (encryptStr.empty() && (listener_ != nullptr)) {
CLOGE("Get encrypt str fail."); CLOGE("Get encrypt str fail.");
listener_->OnError(ERROR_CODE_DEFAULT);
return false; return false;
} }
// only support ctr // only support ctr
EncryptDecrypt &instance = EncryptDecrypt::GetInstance(); EncryptDecrypt &instance = EncryptDecrypt::GetInstance();
int version = instance.GetVersion(); 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<std::string> cipherList = ParseCipherItem(encryptStr); std::set<std::string> cipherList = ParseCipherItem(encryptStr);
if (cipherList.empty() && (listener_ != nullptr)) { if (cipherList.empty() && (listener_ != nullptr)) {
@ -516,7 +526,8 @@ bool RtspController::ProcessPauseRequest(RtspParse &request)
bool RtspController::ProcessTearDownRequest(RtspParse &request) bool RtspController::ProcessTearDownRequest(RtspParse &request)
{ {
CLOGD("Receive sink teardown request."); CLOGI("Receive sink teardown request.");
if (!Utils::StartWith(request.GetFirstLine(), "Teardown")) { if (!Utils::StartWith(request.GetFirstLine(), "Teardown")) {
CLOGE("Process teardown request error"); CLOGE("Process teardown request error");
if (listener_ != nullptr) { if (listener_ != nullptr) {
@ -586,6 +597,7 @@ void RtspController::ProcessTriggerMethod(RtspParse &request, const std::string
} else if (triggerMethod == ACTION_TYPE_STR[static_cast<int>(ActionType::PAUSE)]) { } else if (triggerMethod == ACTION_TYPE_STR[static_cast<int>(ActionType::PAUSE)]) {
listener_->OnPause(); listener_->OnPause();
} else if (triggerMethod == ACTION_TYPE_STR[static_cast<int>(ActionType::TEARDOWN)]) { } else if (triggerMethod == ACTION_TYPE_STR[static_cast<int>(ActionType::TEARDOWN)]) {
CLOGI("Receive teardown trigger method");
listener_->OnTearDown(); listener_->OnTearDown();
} else if (triggerMethod == ACTION_TYPE_STR[static_cast<int>(ActionType::SEND_EVENT_CHANGE)]) { } else if (triggerMethod == ACTION_TYPE_STR[static_cast<int>(ActionType::SEND_EVENT_CHANGE)]) {
ProcessEventChangeRequest(request); ProcessEventChangeRequest(request);
@ -703,13 +715,15 @@ bool RtspController::ProcessGetParamM3Response(RtspParse &response)
} }
negotiatedParamInfo_.SetVersion(RtspParse::ParseDoubleSafe(response.GetHeader()["his_version"])); negotiatedParamInfo_.SetVersion(RtspParse::ParseDoubleSafe(response.GetHeader()["his_version"]));
CLOGD("Sink HiSight version is %.2f", negotiatedParamInfo_.GetVersion()); CLOGD("Sink HiSight version is %.2f", negotiatedParamInfo_.GetVersion());
negotiatedParamInfo_.SetSupportUWB(RtspParse::ParseDoubleSafe(response.GetHeader()["his_support_uwb"]) == 1);
// 考虑向前兼容性需要先解析device type // 考虑向前兼容性需要先解析device type
if (response.GetHeader()["his_device_type"].empty()) { if (response.GetHeader()["his_device_type"].empty()) {
ProcessSinkDeviceType(""); ProcessSinkDeviceType("");
} else { } else {
ProcessSinkDeviceType((*(response.GetHeader().find("his_device_type"))).second); ProcessSinkDeviceType((*(response.GetHeader().find("his_device_type"))).second);
} }
std::string content = response.GetHeader()["his_video_formats"]; std::string content = response.GetHeader()["his_video_formats"];
if (content.empty()) { if (content.empty()) {
CLOGE("Process M3 Rsp Error, sink not have his_video_formats."); 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) 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(); listener_->OnTearDown();
return true; return true;
} }
@ -872,11 +887,14 @@ void RtspController::ProcessUibc(const std::string &content)
CLOGE("No generic_cap_list."); CLOGE("No generic_cap_list.");
return; return;
} }
if (paramInfo_.GetRemoteControlParamInfo().genericList.size() <= 0) { if (paramInfo_.GetRemoteControlParamInfo().genericList.size() <= 0) {
CLOGE("Local genericList is empty."); CLOGE("Local genericList is empty.");
return; return;
} }
ProcessUibcDetermine(genericStr, remoteControlParamInfo.genericList);
ProcessUibcDetermine(genericStr, remoteControlParamInfo.genericList,
paramInfo_.GetRemoteControlParamInfo().genericList);
remoteControlParamInfo.isSupportGeneric = true; remoteControlParamInfo.isSupportGeneric = true;
} }
@ -886,13 +904,17 @@ void RtspController::ProcessUibc(const std::string &content)
CLOGE("No hidc_cap_list."); CLOGE("No hidc_cap_list.");
return; return;
} }
if (paramInfo_.GetRemoteControlParamInfo().hidcList.size() <= 0) { if (paramInfo_.GetRemoteControlParamInfo().hidcList.size() <= 0) {
CLOGE("Local hidcList is empty."); CLOGE("Local hidcList is empty.");
return; return;
} }
ProcessUibcDetermine(hidcStr, remoteControlParamInfo.hidcList);
ProcessUibcDetermine(hidcStr, remoteControlParamInfo.hidcList,
paramInfo_.GetRemoteControlParamInfo().hidcList);
remoteControlParamInfo.isSupportHidc = true; remoteControlParamInfo.isSupportHidc = true;
} }
ProcessUibcVendor(content, remoteControlParamInfo); ProcessUibcVendor(content, remoteControlParamInfo);
negotiatedParamInfo_.SetRemoteControlParamInfo(remoteControlParamInfo); negotiatedParamInfo_.SetRemoteControlParamInfo(remoteControlParamInfo);
@ -908,23 +930,33 @@ void RtspController::ProcessUibcVendor(const std::string &content, RemoteControl
CLOGE("No vendor_cap_list."); CLOGE("No vendor_cap_list.");
return; return;
} }
if (paramInfo_.GetRemoteControlParamInfo().vendorList.size() <= 0) { if (paramInfo_.GetRemoteControlParamInfo().vendorList.size() <= 0) {
CLOGE("Local vendor_list is empty."); CLOGE("Local vendor_list is empty.");
return; return;
} }
ProcessUibcDetermine(vendorStr, remoteControlParamInfo.vendorList);
ProcessUibcDetermine(vendorStr, remoteControlParamInfo.vendorList,
paramInfo_.GetRemoteControlParamInfo().vendorList);
remoteControlParamInfo.isSupportVendor = true; remoteControlParamInfo.isSupportVendor = true;
} }
} }
void RtspController::ProcessUibcDetermine(const std::string &givenStr, std::vector<std::string> &list) void RtspController::ProcessUibcDetermine(const std::string &givenStr, std::vector<std::string> &intersection,
const std::vector<std::string> &localList)
{ {
CLOGD("In, %{public}s.", givenStr.c_str()); CLOGD("In, %{public}s.", givenStr.c_str());
std::vector<std::string> splitStrings; std::vector<std::string> splitStrings;
Utils::SplitString(givenStr, splitStrings, ", "); Utils::SplitString(givenStr, splitStrings, ", ");
list.clear(); intersection.clear();
for (auto &iter : splitStrings) { 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) void RtspController::ProcessSinkVideoForResolution(const std::string &content, VideoProperty &videoProperty)
{ {
CLOGD("In, %{public}s.", content.c_str()); 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); std::string strWidth = RtspParse::GetTargetStr(content, "width", COMMON_SEPARATOR);
uint32_t height = (!strHeight.empty()) ? RtspParse::ParseUint32Safe(strHeight) : 0; uint32_t height = (!strHeight.empty()) ? RtspParse::ParseUint32Safe(strHeight) : 0;
uint32_t width = (!strWidth.empty()) ? RtspParse::ParseUint32Safe(strWidth) : 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)) { if ((height > 0) && (width > 0)) {
videoProperty.videoHeight = height; videoProperty.videoHeight = height;
videoProperty.videoWidth = width; videoProperty.videoWidth = width;
@ -1027,6 +1061,20 @@ void RtspController::ProcessVideoInfo(const std::string &content)
negotiatedParamInfo_.GetVideoProperty().videoWidth, negotiatedParamInfo_.GetVideoProperty().videoHeight, negotiatedParamInfo_.GetVideoProperty().videoWidth, negotiatedParamInfo_.GetVideoProperty().videoHeight,
negotiatedParamInfo_.GetVideoProperty().fps, negotiatedParamInfo_.GetVideoProperty().codecType, negotiatedParamInfo_.GetVideoProperty().fps, negotiatedParamInfo_.GetVideoProperty().codecType,
negotiatedParamInfo_.GetVideoProperty().gop); 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) 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) { if (strPos != std::string::npos) {
controllerParamsProcessed = controllerParams.substr(0, strPos); 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()); controllerParamsProcessed.c_str());
if (listener_ == nullptr) { if (listener_ == nullptr) {
CLOGE("Listener is null."); CLOGE("Listener is null.");
return; return;
} }
listener_->NotifyModuleCustomParamsNegotiation(mediaParams, controllerParamsProcessed); listener_->NotifyModuleCustomParamsNegotiation(mediaParamsProcessed, controllerParamsProcessed);
} }
bool RtspController::SendOptionM1M2() bool RtspController::SendOptionM1M2()
@ -1303,6 +1358,11 @@ void RtspController::SetNegotiatedMediaCapability(const std::string &negotiation
negotiatedParamInfo_.SetMediaCapability(negotiationMediaParams); negotiatedParamInfo_.SetMediaCapability(negotiationMediaParams);
} }
void RtspController::SetNegotiatedStreamCapability(const std::string &controllerParams)
{
negotiatedParamInfo_.SetStreamCapability(controllerParams);
}
void RtspController::SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams) void RtspController::SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams)
{ {
negotiatedParamInfo_.SetPlayerControllerCapability(negotiationParams); negotiatedParamInfo_.SetPlayerControllerCapability(negotiationParams);

View File

@ -18,17 +18,21 @@
#ifndef LIBCASTENGINE_RTSP_CONTROLLER_H #ifndef LIBCASTENGINE_RTSP_CONTROLLER_H
#define LIBCASTENGINE_RTSP_CONTROLLER_H #define LIBCASTENGINE_RTSP_CONTROLLER_H
#include <list>
#include "channel.h" #include "channel.h"
#include "rtsp_listener.h" #include "rtsp_listener.h"
#include "rtsp_listener_inner.h" #include "rtsp_listener_inner.h"
#include "rtsp_channel_manager.h" #include "rtsp_channel_manager.h"
#include "i_rtsp_controller.h" #include "i_rtsp_controller.h"
#include "nlohmann/json.hpp"
namespace OHOS { namespace OHOS {
namespace CastEngine { namespace CastEngine {
namespace CastEngineService { namespace CastEngineService {
namespace CastSessionRtsp { namespace CastSessionRtsp {
class RtspController : public IRtspController, public RtspListenerInner { class RtspController : public IRtspController,
public RtspListenerInner,
public std::enable_shared_from_this<RtspController> {
public: public:
RtspController(std::shared_ptr<IRtspListener> listener, ProtocolType protocolType, EndType endType); RtspController(std::shared_ptr<IRtspListener> listener, ProtocolType protocolType, EndType endType);
~RtspController() override; ~RtspController() override;
@ -52,6 +56,8 @@ public:
void ModuleCustomParamsNegotiationDone() override; void ModuleCustomParamsNegotiationDone() override;
void SetNegotiatedMediaCapability(const std::string &negotiationMediaParams) override; void SetNegotiatedMediaCapability(const std::string &negotiationMediaParams) override;
void SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams) override; void SetNegotiatedPlayerControllerCapability(const std::string &negotiationParams) override;
void SetNegotiatedStreamCapability(const std::string &controllerParams) override;
void Init();
private: private:
enum class RtspEngineState { enum class RtspEngineState {
@ -92,7 +98,8 @@ private:
void ProcessUibc(const std::string &content); void ProcessUibc(const std::string &content);
bool PreProcessUibc(const std::string &content, std::string &categoryList); bool PreProcessUibc(const std::string &content, std::string &categoryList);
void ProcessUibcVendor(const std::string &content, RemoteControlParamInfo &remoteControlParamInfo); void ProcessUibcVendor(const std::string &content, RemoteControlParamInfo &remoteControlParamInfo);
void ProcessUibcDetermine(const std::string &givenStr, std::vector<std::string> &list); void ProcessUibcDetermine(const std::string &givenStr, std::vector<std::string> &intersection,
const std::vector<std::string> &localList);
void ProcessSinkBitrate(const std::string &content, VideoProperty &videoProperty); void ProcessSinkBitrate(const std::string &content, VideoProperty &videoProperty);
void ProcessVideoInfo(const std::string &content); void ProcessVideoInfo(const std::string &content);
void ProcessAudioInfo(RtspParse &parseInfo); void ProcessAudioInfo(RtspParse &parseInfo);
@ -113,6 +120,7 @@ private:
void ProcessTriggerMethod(RtspParse &request, const std::string &triggerMethod); void ProcessTriggerMethod(RtspParse &request, const std::string &triggerMethod);
void ResponseFuncMapInit(); void ResponseFuncMapInit();
void RequestFuncMapInit(); void RequestFuncMapInit();
void AddScreenParam();
const ProtocolType protocolType_; const ProtocolType protocolType_;
std::shared_ptr<IRtspListener> listener_; std::shared_ptr<IRtspListener> listener_;
@ -121,13 +129,14 @@ private:
int currentSetUpSeq_{ 0 }; int currentSetUpSeq_{ 0 };
int currentKeepAliveCseq_{ 0 }; int currentKeepAliveCseq_{ 0 };
WaitResponse waitRsp_{ WaitResponse::WAITING_RSP_NONE }; WaitResponse waitRsp_{ WaitResponse::WAITING_RSP_NONE };
std::unique_ptr<RtspChannelManager> rtspNetManager_; std::shared_ptr<RtspChannelManager> rtspNetManager_;
ParamInfo paramInfo_{}; ParamInfo paramInfo_{};
ParamInfo negotiatedParamInfo_{}; ParamInfo negotiatedParamInfo_{};
RtspEngineState state_{ RtspEngineState::STATE_STOPPED }; RtspEngineState state_{ RtspEngineState::STATE_STOPPED };
std::string deviceId_; std::string deviceId_;
std::map<WaitResponse, ResponseFunc> responseFuncMap_; std::map<WaitResponse, ResponseFunc> responseFuncMap_;
std::map<std::string, RequestFunc> requestFuncMap_; std::map<std::string, RequestFunc> requestFuncMap_;
nlohmann::json screenParam_;
}; };
} // namespace CastSessionRtsp } // namespace CastSessionRtsp
} // namespace CastEngineService } // namespace CastEngineService

View File

@ -393,6 +393,8 @@ std::string RtspEncap::EncapSetParameterM4Request(ParamInfo &negParam, double ve
std::string body; std::string body;
body.append(SetVideoAndAudioCodecsParameter(negParam)); body.append(SetVideoAndAudioCodecsParameter(negParam));
body.append(SetAudioParameter(negParam)); body.append(SetAudioParameter(negParam));
body.append("his_support_uwb: ")
.append(std::to_string(negParam.IsSupportUWB())).append(MSG_SEPARATOR);
SetAnotherParameter(negParam, version, ip, body); SetAnotherParameter(negParam, version, ip, body);

View File

@ -141,6 +141,16 @@ void ParamInfo::SetMediaCapability(const std::string &capability)
this->mediaCapability_ = capability; this->mediaCapability_ = capability;
} }
const std::string ParamInfo::GetStreamCapability()
{
return streamCapability_;
}
void ParamInfo::SetStreamCapability(const std::string &capability)
{
this->streamCapability_ = capability;
}
ProjectionMode ParamInfo::GetProjectionMode() ProjectionMode ParamInfo::GetProjectionMode()
{ {
return projectionMode_; return projectionMode_;
@ -150,6 +160,17 @@ void ParamInfo::SetProjectionMode(ProjectionMode projectionMode)
{ {
this->projectionMode_ = projectionMode; this->projectionMode_ = projectionMode;
} }
bool ParamInfo::IsSupportUWB()
{
return mIsSupportUWB;
}
void ParamInfo::SetSupportUWB(bool isSupport)
{
mIsSupportUWB = isSupport;
}
} // namespace CastSessionRtsp } // namespace CastSessionRtsp
} // namespace CastEngineService } // namespace CastEngineService
} // namespace CastEngine } // namespace CastEngine

View File

@ -127,7 +127,7 @@ double RtspParse::ParseDoubleSafe(const std::string &str)
} }
char *nextPtr = nullptr; char *nextPtr = nullptr;
double result = strtod(str.c_str(), nullptr); double result = strtod(str.c_str(), &nextPtr);
if (errno == ERANGE) { if (errno == ERANGE) {
CLOGE("Parse double out of range"); CLOGE("Parse double out of range");
return INVALID_VALUE; return INVALID_VALUE;

View File

@ -28,14 +28,18 @@ static std::map<Media::PlaybackRateMode, PlaybackSpeed> g_mediaSpeedToPlaybackSp
{ Media::SPEED_FORWARD_1_00_X, PlaybackSpeed::SPEED_FORWARD_1_00_X }, { 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_25_X, PlaybackSpeed::SPEED_FORWARD_1_25_X },
{ Media::SPEED_FORWARD_1_75_X, PlaybackSpeed::SPEED_FORWARD_1_75_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<PlaybackSpeed, Media::PlaybackRateMode> g_doubleToModeTypeMap = { static std::map<PlaybackSpeed, Media::PlaybackRateMode> g_doubleToModeTypeMap = {
{ PlaybackSpeed::SPEED_FORWARD_0_75_X, Media::SPEED_FORWARD_0_75_X }, { 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_00_X, Media::SPEED_FORWARD_1_00_X },
{ PlaybackSpeed::SPEED_FORWARD_1_25_X, Media::SPEED_FORWARD_1_25_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_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 CastEngine
} // namespace OHOS } // namespace OHOS