mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-23 08:49:59 +00:00
!8376 Performance problem rectification
Merge pull request !8376 from Zhangzi/master
This commit is contained in:
commit
d15a20c8bc
@ -46,13 +46,15 @@ static inline void ConvertStreamFrameInfo(const StreamFrameInfo *inFrameInfo,
|
||||
outFrameInfo->bitrate = 0;
|
||||
}
|
||||
|
||||
static int32_t CreateRawStream(const std::shared_ptr<StreamAdaptor> &adaptor, const char *buf, ssize_t bufLen,
|
||||
std::unique_ptr<IStream> &stream)
|
||||
static int32_t CreateRawStream(const StreamFrameInfo *param, const std::shared_ptr<StreamAdaptor> &adaptor,
|
||||
const char *buf, ssize_t bufLen, std::unique_ptr<IStream> &stream)
|
||||
{
|
||||
bool isEncrypt = adaptor->IsEncryptedRawStream();
|
||||
Communication::SoftBus::StreamFrameInfo outFrameInfo;
|
||||
ConvertStreamFrameInfo(param, &outFrameInfo);
|
||||
if (!isEncrypt) {
|
||||
TRANS_LOGD(TRANS_STREAM, "isEncrypt=%{public}d, bufLen=%{public}zd", isEncrypt, bufLen);
|
||||
stream = IStream::MakeRawStream(buf, bufLen, {}, Communication::SoftBus::Scene::SOFTBUS_SCENE);
|
||||
TRANS_LOGI(TRANS_STREAM, "isEncrypt=%{public}d, bufLen=%{public}zd", isEncrypt, bufLen);
|
||||
stream = IStream::MakeRawStream(buf, bufLen, outFrameInfo, Communication::SoftBus::Scene::SOFTBUS_SCENE);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
@ -65,7 +67,7 @@ static int32_t CreateRawStream(const std::shared_ptr<StreamAdaptor> &adaptor, co
|
||||
TRANS_LOGE(TRANS_STREAM, "encrypted failed, dataLen=%{public}zd, encLen=%{public}zd", dataLen, encLen);
|
||||
return SOFTBUS_TRANS_ENCRYPT_ERR;
|
||||
}
|
||||
stream = IStream::MakeRawStream(data.get(), dataLen, {}, Communication::SoftBus::Scene::SOFTBUS_SCENE);
|
||||
stream = IStream::MakeRawStream(data.get(), dataLen, outFrameInfo, Communication::SoftBus::Scene::SOFTBUS_SCENE);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
@ -73,7 +75,7 @@ static int32_t ProcessAdaptorAndEncrypt(const StreamFrameInfo *param, const Stre
|
||||
std::shared_ptr<StreamAdaptor> &adaptor, std::unique_ptr<IStream> &stream, const StreamData *ext)
|
||||
{
|
||||
if (adaptor->GetStreamType() == RAW_STREAM) {
|
||||
int32_t ret = CreateRawStream(adaptor, inData->buf, inData->bufLen, stream);
|
||||
int32_t ret = CreateRawStream(param, adaptor, inData->buf, inData->bufLen, stream);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_STREAM, "failed to create raw stream, ret=%{public}d", ret);
|
||||
return ret;
|
||||
|
@ -23,10 +23,14 @@
|
||||
|
||||
namespace Communication {
|
||||
namespace SoftBus {
|
||||
RawStreamData::RawStreamData(const StreamFrameInfo& frameInfo)
|
||||
{
|
||||
streamFrameInfo_ = frameInfo;
|
||||
}
|
||||
|
||||
std::unique_ptr<IStream> IStream::MakeRawStream(StreamData &data, const StreamFrameInfo &info)
|
||||
{
|
||||
static_cast<void>(info);
|
||||
auto raw = std::make_unique<RawStreamData>();
|
||||
auto raw = std::make_unique<RawStreamData>(info);
|
||||
raw->InitStreamData(std::move(data.buffer), data.bufLen, std::move(data.extBuffer), data.extLen);
|
||||
|
||||
return raw;
|
||||
|
@ -27,6 +27,7 @@ namespace SoftBus {
|
||||
class RawStreamData : public IStream {
|
||||
public:
|
||||
RawStreamData() = default;
|
||||
explicit RawStreamData(const StreamFrameInfo &frameInfo);
|
||||
~RawStreamData() override = default;
|
||||
static constexpr int BYTE_TO_BIT = 8;
|
||||
static constexpr int INT_TO_BYTE = 0xff;
|
||||
@ -72,11 +73,12 @@ private:
|
||||
|
||||
const StreamFrameInfo* GetStreamFrameInfo() const override
|
||||
{
|
||||
return nullptr;
|
||||
return &streamFrameInfo_;
|
||||
}
|
||||
|
||||
std::unique_ptr<char[]> streamData_ = nullptr;
|
||||
ssize_t streamLen_ = 0;
|
||||
StreamFrameInfo streamFrameInfo_;
|
||||
};
|
||||
} // namespace SoftBus
|
||||
} // namespace Communication
|
||||
|
@ -628,20 +628,20 @@ bool VtpStreamSocket::Send(std::unique_ptr<IStream> stream)
|
||||
std::unique_ptr<char[]> data = nullptr;
|
||||
ssize_t len = 0;
|
||||
|
||||
if (streamType_ == RAW_STREAM) {
|
||||
data = stream->GetBuffer();
|
||||
len = stream->GetBufferLen();
|
||||
|
||||
ret = FtSend(streamFd_, data.get(), len, 0);
|
||||
} else if (streamType_ == COMMON_VIDEO_STREAM || streamType_ == COMMON_AUDIO_STREAM) {
|
||||
const Communication::SoftBus::StreamFrameInfo *streamFrameInfo = stream->GetStreamFrameInfo();
|
||||
if (streamFrameInfo == nullptr) {
|
||||
TRANS_LOGE(TRANS_STREAM, "streamFrameInfo is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
FrameInfo frameInfo;
|
||||
ConvertStreamFrameInfo2FrameInfo(&frameInfo, streamFrameInfo);
|
||||
|
||||
if (streamType_ == RAW_STREAM) {
|
||||
data = stream->GetBuffer();
|
||||
len = stream->GetBufferLen();
|
||||
|
||||
ret = FtSendFrame(streamFd_, data.get(), len, 0, &frameInfo);
|
||||
} else if (streamType_ == COMMON_VIDEO_STREAM || streamType_ == COMMON_AUDIO_STREAM) {
|
||||
if (!EncryptStreamPacket(std::move(stream), data, len)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ HWTEST_F(RawStreamDataTest, GetStreamFrameInfo001, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<RawStreamData> rRawStreamData = std::make_shared<RawStreamData>();
|
||||
|
||||
EXPECT_EQ(nullptr, rRawStreamData->GetStreamFrameInfo());
|
||||
EXPECT_NE(nullptr, rRawStreamData->GetStreamFrameInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user