diff --git a/src/Rtcp/Rtcp.cpp b/src/Rtcp/Rtcp.cpp index b734052e..027fabc7 100644 --- a/src/Rtcp/Rtcp.cpp +++ b/src/Rtcp/Rtcp.cpp @@ -422,19 +422,19 @@ vector RtcpRR::getItemList() { ///////////////////////////////////////////////////////////////////////////// -void SdesItem::net2Host() { +void SdesChunk::net2Host() { ssrc = ntohl(ssrc); } -size_t SdesItem::totalBytes() const{ +size_t SdesChunk::totalBytes() const{ return alignSize(minSize() + txt_len); } -size_t SdesItem::minSize() { - return sizeof(SdesItem) - sizeof(text); +size_t SdesChunk::minSize() { + return sizeof(SdesChunk) - sizeof(text); } -string SdesItem::dumpString() const{ +string SdesChunk::dumpString() const{ _StrPrinter printer; printer << "ssrc:" << ssrc << "\r\n"; printer << "type:" << sdesTypeToStr((SdesType) type) << "\r\n"; @@ -448,18 +448,18 @@ string SdesItem::dumpString() const{ std::shared_ptr RtcpSdes::create(const std::vector &item_text) { size_t item_total_size = 0; for (auto &text : item_text) { - //统计所有SdesItem对象占用的空间 - item_total_size += alignSize(SdesItem::minSize() + (0xFF & text.size())); + //统计所有SdesChunk对象占用的空间 + item_total_size += alignSize(SdesChunk::minSize() + (0xFF & text.size())); } - auto real_size = sizeof(RtcpSdes) - sizeof(SdesItem) + item_total_size; + auto real_size = sizeof(RtcpSdes) - sizeof(SdesChunk) + item_total_size; auto bytes = alignSize(real_size); auto ptr = (RtcpSdes *) new char[bytes]; - auto item_ptr = &ptr->items; + auto item_ptr = &ptr->chunks; for (auto &text : item_text) { item_ptr->txt_len = (0xFF & text.size()); //确保赋值\0为RTCP_SDES_END memcpy(item_ptr->text, text.data(), item_ptr->txt_len + 1); - item_ptr = (SdesItem *) ((char *) item_ptr + item_ptr->totalBytes()); + item_ptr = (SdesChunk *) ((char *) item_ptr + item_ptr->totalBytes()); } setupHeader(ptr, RtcpType::RTCP_SDES, item_text.size(), bytes); @@ -472,7 +472,7 @@ std::shared_ptr RtcpSdes::create(const std::vector &item_text) string RtcpSdes::dumpString() const { _StrPrinter printer; printer << RtcpHeader::dumpHeader(); - auto items = ((RtcpSdes *)this)->getItemList(); + auto items = ((RtcpSdes *) this)->getChunkList(); auto i = 0; for (auto &item : items) { printer << "---- item:" << i++ << " ----\r\n"; @@ -482,24 +482,24 @@ string RtcpSdes::dumpString() const { } void RtcpSdes::net2Host(size_t size) { - static const size_t kMinSize = sizeof(RtcpSdes) - sizeof(items); + static const size_t kMinSize = sizeof(RtcpSdes) - sizeof(chunks); CHECK_MIN_SIZE(size, kMinSize); - SdesItem *ptr = &items; + SdesChunk *ptr = &chunks; int item_count = 0; - for(int i = 0; i < (int)report_count && (char *)(ptr) + SdesItem::minSize() <= (char *)(this) + size; ++i){ + for(int i = 0; i < (int)report_count && (char *)(ptr) + SdesChunk::minSize() <= (char *)(this) + size; ++i){ ptr->net2Host(); - ptr = (SdesItem *) ((char *) ptr + ptr->totalBytes()); + ptr = (SdesChunk *) ((char *) ptr + ptr->totalBytes()); ++item_count; } CHECK_REPORT_COUNT(item_count); } -vector RtcpSdes::getItemList() { - vector ret; - SdesItem *ptr = &items; +vector RtcpSdes::getChunkList() { + vector ret; + SdesChunk *ptr = &chunks; for (int i = 0; i < (int) report_count; ++i) { ret.emplace_back(ptr); - ptr = (SdesItem *) ((char *) ptr + ptr->totalBytes()); + ptr = (SdesChunk *) ((char *) ptr + ptr->totalBytes()); } return ret; } diff --git a/src/Rtcp/Rtcp.h b/src/Rtcp/Rtcp.h index 8f74ecc4..c94ce064 100644 --- a/src/Rtcp/Rtcp.h +++ b/src/Rtcp/Rtcp.h @@ -477,8 +477,8 @@ SDES items 定义 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -//Source description item -class SdesItem { +//Source description Chunk +class SdesChunk { public: friend class RtcpSdes; @@ -523,21 +523,21 @@ public: friend class RtcpHeader; //可能有很多个 - SdesItem items; + SdesChunk chunks; public: /** - * 创建SDES包,只赋值了RtcpHeader以及SdesItem对象的length和text部分 - * @param item_text SdesItem列表,只赋值length和text部分 + * 创建SDES包,只赋值了RtcpHeader以及SdesChunk对象的length和text部分 + * @param item_text SdesChunk列表,只赋值length和text部分 * @return SDES包 */ static std::shared_ptr create(const std::vector &item_text); /** - * 获取SdesItem对象指针列表 + * 获取SdesChunk对象指针列表 * 使用net2Host转换成主机字节序后才可使用此函数 */ - vector getItemList(); + vector getChunkList(); private: /** diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index d997f02d..a1926503 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -633,8 +633,8 @@ void RtspPlayer::onBeforeRtpSorted(const RtpPacket::Ptr &rtp, int track_idx){ auto ssrc = rtp->getSSRC(); auto rtcp = rtcp_ctx->createRtcpRR(ssrc + 1, ssrc); auto rtcp_sdes = RtcpSdes::create({SERVER_NAME}); - rtcp_sdes->items.type = (uint8_t) SdesType::RTCP_SDES_CNAME; - rtcp_sdes->items.ssrc = htonl(ssrc); + rtcp_sdes->chunks.type = (uint8_t) SdesType::RTCP_SDES_CNAME; + rtcp_sdes->chunks.ssrc = htonl(ssrc); send_rtcp(this, track_idx, std::move(rtcp)); send_rtcp(this, track_idx, RtcpHeader::toBuffer(rtcp_sdes)); ticker.resetTime(); diff --git a/src/Rtsp/RtspPusher.cpp b/src/Rtsp/RtspPusher.cpp index 80314600..257526bb 100644 --- a/src/Rtsp/RtspPusher.cpp +++ b/src/Rtsp/RtspPusher.cpp @@ -378,8 +378,8 @@ void RtspPusher::updateRtcpContext(const RtpPacket::Ptr &rtp){ auto ssrc = rtp->getSSRC(); auto rtcp = rtcp_ctx->createRtcpSR(ssrc + 1); auto rtcp_sdes = RtcpSdes::create({SERVER_NAME}); - rtcp_sdes->items.type = (uint8_t) SdesType::RTCP_SDES_CNAME; - rtcp_sdes->items.ssrc = htonl(ssrc); + rtcp_sdes->chunks.type = (uint8_t) SdesType::RTCP_SDES_CNAME; + rtcp_sdes->chunks.ssrc = htonl(ssrc); send_rtcp(this, track_index, std::move(rtcp)); send_rtcp(this, track_index, RtcpHeader::toBuffer(rtcp_sdes)); } diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index eb34d958..3ab758c6 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -1153,8 +1153,8 @@ void RtspSession::updateRtcpContext(const RtpPacket::Ptr &rtp){ auto ssrc = rtp->getSSRC(); auto rtcp = _push_src ? rtcp_ctx->createRtcpRR(ssrc + 1, ssrc) : rtcp_ctx->createRtcpSR(ssrc); auto rtcp_sdes = RtcpSdes::create({SERVER_NAME}); - rtcp_sdes->items.type = (uint8_t)SdesType::RTCP_SDES_CNAME; - rtcp_sdes->items.ssrc = htonl(ssrc); + rtcp_sdes->chunks.type = (uint8_t)SdesType::RTCP_SDES_CNAME; + rtcp_sdes->chunks.ssrc = htonl(ssrc); send_rtcp(this, track_index, std::move(rtcp)); send_rtcp(this, track_index, RtcpHeader::toBuffer(rtcp_sdes)); } diff --git a/tests/test_rtcp.cpp b/tests/test_rtcp.cpp index 9399ebb9..e535d677 100644 --- a/tests/test_rtcp.cpp +++ b/tests/test_rtcp.cpp @@ -67,7 +67,7 @@ std::shared_ptr makeRtcpRR() { std::shared_ptr makeRtcpSDES() { auto rtcp = RtcpSdes::create({"zlmediakit", "", "https://github.com/xia-chu/ZLMediaKit", "1213642868@qq.com", "123456789012345678"}); auto i = 5; - auto items = rtcp->getItemList(); + auto items = rtcp->getChunkList(); items[0]->type = (uint8_t)SdesType::RTCP_SDES_CNAME; items[0]->ssrc = htonl(i++);