修正SDES rtcp对象命名

This commit is contained in:
ziyue 2021-07-15 17:38:04 +08:00
parent c25da5a222
commit 8548753c28
6 changed files with 33 additions and 33 deletions

View File

@ -422,19 +422,19 @@ vector<ReportItem*> RtcpRR::getItemList() {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
void SdesItem::net2Host() { void SdesChunk::net2Host() {
ssrc = ntohl(ssrc); ssrc = ntohl(ssrc);
} }
size_t SdesItem::totalBytes() const{ size_t SdesChunk::totalBytes() const{
return alignSize(minSize() + txt_len); return alignSize(minSize() + txt_len);
} }
size_t SdesItem::minSize() { size_t SdesChunk::minSize() {
return sizeof(SdesItem) - sizeof(text); return sizeof(SdesChunk) - sizeof(text);
} }
string SdesItem::dumpString() const{ string SdesChunk::dumpString() const{
_StrPrinter printer; _StrPrinter printer;
printer << "ssrc:" << ssrc << "\r\n"; printer << "ssrc:" << ssrc << "\r\n";
printer << "type:" << sdesTypeToStr((SdesType) type) << "\r\n"; printer << "type:" << sdesTypeToStr((SdesType) type) << "\r\n";
@ -448,18 +448,18 @@ string SdesItem::dumpString() const{
std::shared_ptr<RtcpSdes> RtcpSdes::create(const std::vector<string> &item_text) { std::shared_ptr<RtcpSdes> RtcpSdes::create(const std::vector<string> &item_text) {
size_t item_total_size = 0; size_t item_total_size = 0;
for (auto &text : item_text) { for (auto &text : item_text) {
//统计所有SdesItem对象占用的空间 //统计所有SdesChunk对象占用的空间
item_total_size += alignSize(SdesItem::minSize() + (0xFF & text.size())); 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 bytes = alignSize(real_size);
auto ptr = (RtcpSdes *) new char[bytes]; auto ptr = (RtcpSdes *) new char[bytes];
auto item_ptr = &ptr->items; auto item_ptr = &ptr->chunks;
for (auto &text : item_text) { for (auto &text : item_text) {
item_ptr->txt_len = (0xFF & text.size()); item_ptr->txt_len = (0xFF & text.size());
//确保赋值\0为RTCP_SDES_END //确保赋值\0为RTCP_SDES_END
memcpy(item_ptr->text, text.data(), item_ptr->txt_len + 1); 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); setupHeader(ptr, RtcpType::RTCP_SDES, item_text.size(), bytes);
@ -472,7 +472,7 @@ std::shared_ptr<RtcpSdes> RtcpSdes::create(const std::vector<string> &item_text)
string RtcpSdes::dumpString() const { string RtcpSdes::dumpString() const {
_StrPrinter printer; _StrPrinter printer;
printer << RtcpHeader::dumpHeader(); printer << RtcpHeader::dumpHeader();
auto items = ((RtcpSdes *)this)->getItemList(); auto items = ((RtcpSdes *) this)->getChunkList();
auto i = 0; auto i = 0;
for (auto &item : items) { for (auto &item : items) {
printer << "---- item:" << i++ << " ----\r\n"; printer << "---- item:" << i++ << " ----\r\n";
@ -482,24 +482,24 @@ string RtcpSdes::dumpString() const {
} }
void RtcpSdes::net2Host(size_t size) { 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); CHECK_MIN_SIZE(size, kMinSize);
SdesItem *ptr = &items; SdesChunk *ptr = &chunks;
int item_count = 0; 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->net2Host();
ptr = (SdesItem *) ((char *) ptr + ptr->totalBytes()); ptr = (SdesChunk *) ((char *) ptr + ptr->totalBytes());
++item_count; ++item_count;
} }
CHECK_REPORT_COUNT(item_count); CHECK_REPORT_COUNT(item_count);
} }
vector<SdesItem *> RtcpSdes::getItemList() { vector<SdesChunk *> RtcpSdes::getChunkList() {
vector<SdesItem *> ret; vector<SdesChunk *> ret;
SdesItem *ptr = &items; SdesChunk *ptr = &chunks;
for (int i = 0; i < (int) report_count; ++i) { for (int i = 0; i < (int) report_count; ++i) {
ret.emplace_back(ptr); ret.emplace_back(ptr);
ptr = (SdesItem *) ((char *) ptr + ptr->totalBytes()); ptr = (SdesChunk *) ((char *) ptr + ptr->totalBytes());
} }
return ret; return ret;
} }

View File

@ -477,8 +477,8 @@ SDES items 定义
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
//Source description item //Source description Chunk
class SdesItem { class SdesChunk {
public: public:
friend class RtcpSdes; friend class RtcpSdes;
@ -523,21 +523,21 @@ public:
friend class RtcpHeader; friend class RtcpHeader;
//可能有很多个 //可能有很多个
SdesItem items; SdesChunk chunks;
public: public:
/** /**
* SDES包RtcpHeader以及SdesItem对象的length和text部分 * SDES包RtcpHeader以及SdesChunk对象的length和text部分
* @param item_text SdesItem列表length和text部分 * @param item_text SdesChunk列表length和text部分
* @return SDES包 * @return SDES包
*/ */
static std::shared_ptr<RtcpSdes> create(const std::vector<string> &item_text); static std::shared_ptr<RtcpSdes> create(const std::vector<string> &item_text);
/** /**
* SdesItem对象指针列表 * SdesChunk对象指针列表
* 使net2Host转换成主机字节序后才可使用此函数 * 使net2Host转换成主机字节序后才可使用此函数
*/ */
vector<SdesItem*> getItemList(); vector<SdesChunk*> getChunkList();
private: private:
/** /**

View File

@ -633,8 +633,8 @@ void RtspPlayer::onBeforeRtpSorted(const RtpPacket::Ptr &rtp, int track_idx){
auto ssrc = rtp->getSSRC(); auto ssrc = rtp->getSSRC();
auto rtcp = rtcp_ctx->createRtcpRR(ssrc + 1, ssrc); auto rtcp = rtcp_ctx->createRtcpRR(ssrc + 1, ssrc);
auto rtcp_sdes = RtcpSdes::create({SERVER_NAME}); auto rtcp_sdes = RtcpSdes::create({SERVER_NAME});
rtcp_sdes->items.type = (uint8_t) SdesType::RTCP_SDES_CNAME; rtcp_sdes->chunks.type = (uint8_t) SdesType::RTCP_SDES_CNAME;
rtcp_sdes->items.ssrc = htonl(ssrc); rtcp_sdes->chunks.ssrc = htonl(ssrc);
send_rtcp(this, track_idx, std::move(rtcp)); send_rtcp(this, track_idx, std::move(rtcp));
send_rtcp(this, track_idx, RtcpHeader::toBuffer(rtcp_sdes)); send_rtcp(this, track_idx, RtcpHeader::toBuffer(rtcp_sdes));
ticker.resetTime(); ticker.resetTime();

View File

@ -378,8 +378,8 @@ void RtspPusher::updateRtcpContext(const RtpPacket::Ptr &rtp){
auto ssrc = rtp->getSSRC(); auto ssrc = rtp->getSSRC();
auto rtcp = rtcp_ctx->createRtcpSR(ssrc + 1); auto rtcp = rtcp_ctx->createRtcpSR(ssrc + 1);
auto rtcp_sdes = RtcpSdes::create({SERVER_NAME}); auto rtcp_sdes = RtcpSdes::create({SERVER_NAME});
rtcp_sdes->items.type = (uint8_t) SdesType::RTCP_SDES_CNAME; rtcp_sdes->chunks.type = (uint8_t) SdesType::RTCP_SDES_CNAME;
rtcp_sdes->items.ssrc = htonl(ssrc); rtcp_sdes->chunks.ssrc = htonl(ssrc);
send_rtcp(this, track_index, std::move(rtcp)); send_rtcp(this, track_index, std::move(rtcp));
send_rtcp(this, track_index, RtcpHeader::toBuffer(rtcp_sdes)); send_rtcp(this, track_index, RtcpHeader::toBuffer(rtcp_sdes));
} }

View File

@ -1153,8 +1153,8 @@ void RtspSession::updateRtcpContext(const RtpPacket::Ptr &rtp){
auto ssrc = rtp->getSSRC(); auto ssrc = rtp->getSSRC();
auto rtcp = _push_src ? rtcp_ctx->createRtcpRR(ssrc + 1, ssrc) : rtcp_ctx->createRtcpSR(ssrc); auto rtcp = _push_src ? rtcp_ctx->createRtcpRR(ssrc + 1, ssrc) : rtcp_ctx->createRtcpSR(ssrc);
auto rtcp_sdes = RtcpSdes::create({SERVER_NAME}); auto rtcp_sdes = RtcpSdes::create({SERVER_NAME});
rtcp_sdes->items.type = (uint8_t)SdesType::RTCP_SDES_CNAME; rtcp_sdes->chunks.type = (uint8_t)SdesType::RTCP_SDES_CNAME;
rtcp_sdes->items.ssrc = htonl(ssrc); rtcp_sdes->chunks.ssrc = htonl(ssrc);
send_rtcp(this, track_index, std::move(rtcp)); send_rtcp(this, track_index, std::move(rtcp));
send_rtcp(this, track_index, RtcpHeader::toBuffer(rtcp_sdes)); send_rtcp(this, track_index, RtcpHeader::toBuffer(rtcp_sdes));
} }

View File

@ -67,7 +67,7 @@ std::shared_ptr<Buffer> makeRtcpRR() {
std::shared_ptr<Buffer> makeRtcpSDES() { std::shared_ptr<Buffer> makeRtcpSDES() {
auto rtcp = RtcpSdes::create({"zlmediakit", "", "https://github.com/xia-chu/ZLMediaKit", "1213642868@qq.com", "123456789012345678"}); auto rtcp = RtcpSdes::create({"zlmediakit", "", "https://github.com/xia-chu/ZLMediaKit", "1213642868@qq.com", "123456789012345678"});
auto i = 5; auto i = 5;
auto items = rtcp->getItemList(); auto items = rtcp->getChunkList();
items[0]->type = (uint8_t)SdesType::RTCP_SDES_CNAME; items[0]->type = (uint8_t)SdesType::RTCP_SDES_CNAME;
items[0]->ssrc = htonl(i++); items[0]->ssrc = htonl(i++);