mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 04:08:57 +08:00
Refine: 消除编译警告
This commit is contained in:
parent
940fe333db
commit
7f6be9e118
@ -1 +1 @@
|
|||||||
Subproject commit f2f79123f23943381009e89b407aa6f8ef683a82
|
Subproject commit 7ede622a3f4e7d3ee9dfe7d61465f1d938873b94
|
@ -65,12 +65,12 @@ API_EXPORT char* API_CALL mk_util_hex_dump(const void *buf, int len);
|
|||||||
API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...);
|
API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...);
|
||||||
|
|
||||||
// 以下宏可以替换printf使用
|
// 以下宏可以替换printf使用
|
||||||
#define log_printf(lev, fmt, ...) mk_log_printf(lev, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
|
#define log_printf(lev, ...) mk_log_printf(lev, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||||
#define log_trace(fmt, ...) log_printf(0, fmt, ##__VA_ARGS__)
|
#define log_trace(...) log_printf(0, ##__VA_ARGS__)
|
||||||
#define log_debug(fmt,...) log_printf(1, fmt, ##__VA_ARGS__)
|
#define log_debug(...) log_printf(1, ##__VA_ARGS__)
|
||||||
#define log_info(fmt, ...) log_printf(2, fmt, ##__VA_ARGS__)
|
#define log_info(...) log_printf(2, ##__VA_ARGS__)
|
||||||
#define log_warn(fmt, ...) log_printf(3, fmt, ##__VA_ARGS__)
|
#define log_warn(...) log_printf(3, ##__VA_ARGS__)
|
||||||
#define log_error(fmt, ...) log_printf(4, fmt, ##__VA_ARGS__)
|
#define log_error(...) log_printf(4, ##__VA_ARGS__)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ const char *rtpfbTypeToStr(RTPFBType type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static size_t alignSize(size_t bytes) {
|
static size_t alignSize(size_t bytes) {
|
||||||
return (size_t)((bytes + 3) >> 2 ) << 2;
|
return (size_t) ((bytes + 3) >> 2) << 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupHeader(RtcpHeader *rtcp, RtcpType type, size_t report_count, size_t total_bytes) {
|
static void setupHeader(RtcpHeader *rtcp, RtcpType type, size_t report_count, size_t total_bytes) {
|
||||||
@ -79,7 +79,7 @@ static void setupPadding(RtcpHeader *rtcp, size_t padding_size) {
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
string RtcpHeader::dumpHeader() const{
|
string RtcpHeader::dumpHeader() const {
|
||||||
_StrPrinter printer;
|
_StrPrinter printer;
|
||||||
printer << "version:" << version << "\r\n";
|
printer << "version:" << version << "\r\n";
|
||||||
if (padding) {
|
if (padding) {
|
||||||
@ -88,7 +88,7 @@ string RtcpHeader::dumpHeader() const{
|
|||||||
printer << "padding:" << padding << "\r\n";
|
printer << "padding:" << padding << "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ((RtcpType)pt) {
|
switch ((RtcpType) pt) {
|
||||||
case RtcpType::RTCP_RTPFB : {
|
case RtcpType::RTCP_RTPFB : {
|
||||||
printer << "report_count:" << rtpfbTypeToStr((RTPFBType) report_count) << "\r\n";
|
printer << "report_count:" << rtpfbTypeToStr((RTPFBType) report_count) << "\r\n";
|
||||||
break;
|
break;
|
||||||
@ -103,37 +103,37 @@ string RtcpHeader::dumpHeader() const{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printer << "pt:" << rtcpTypeToStr((RtcpType)pt) << "\r\n";
|
printer << "pt:" << rtcpTypeToStr((RtcpType) pt) << "\r\n";
|
||||||
printer << "size:" << getSize() << "\r\n";
|
printer << "size:" << getSize() << "\r\n";
|
||||||
printer << "--------\r\n";
|
printer << "--------\r\n";
|
||||||
return std::move(printer);
|
return std::move(printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
string RtcpHeader::dumpString() const {
|
string RtcpHeader::dumpString() const {
|
||||||
switch ((RtcpType)pt) {
|
switch ((RtcpType) pt) {
|
||||||
case RtcpType::RTCP_SR: {
|
case RtcpType::RTCP_SR: {
|
||||||
RtcpSR *rtcp = (RtcpSR *)this;
|
RtcpSR *rtcp = (RtcpSR *) this;
|
||||||
return rtcp->dumpString();
|
return rtcp->dumpString();
|
||||||
}
|
}
|
||||||
|
|
||||||
case RtcpType::RTCP_RR: {
|
case RtcpType::RTCP_RR: {
|
||||||
RtcpRR *rtcp = (RtcpRR *)this;
|
RtcpRR *rtcp = (RtcpRR *) this;
|
||||||
return rtcp->dumpString();
|
return rtcp->dumpString();
|
||||||
}
|
}
|
||||||
|
|
||||||
case RtcpType::RTCP_SDES: {
|
case RtcpType::RTCP_SDES: {
|
||||||
RtcpSdes *rtcp = (RtcpSdes *)this;
|
RtcpSdes *rtcp = (RtcpSdes *) this;
|
||||||
return rtcp->dumpString();
|
return rtcp->dumpString();
|
||||||
}
|
}
|
||||||
|
|
||||||
case RtcpType::RTCP_RTPFB:
|
case RtcpType::RTCP_RTPFB:
|
||||||
case RtcpType::RTCP_PSFB: {
|
case RtcpType::RTCP_PSFB: {
|
||||||
RtcpFB *rtcp = (RtcpFB *)this;
|
RtcpFB *rtcp = (RtcpFB *) this;
|
||||||
return rtcp->dumpString();
|
return rtcp->dumpString();
|
||||||
}
|
}
|
||||||
|
|
||||||
case RtcpType::RTCP_BYE: {
|
case RtcpType::RTCP_BYE: {
|
||||||
RtcpBye *rtcp = (RtcpBye *)this;
|
RtcpBye *rtcp = (RtcpBye *) this;
|
||||||
return rtcp->dumpString();
|
return rtcp->dumpString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,38 +155,38 @@ size_t RtcpHeader::getPaddingSize() const{
|
|||||||
|
|
||||||
void RtcpHeader::setSize(size_t size) {
|
void RtcpHeader::setSize(size_t size) {
|
||||||
//不包含rtcp头的长度
|
//不包含rtcp头的长度
|
||||||
length = htons((uint16_t)((size >> 2) - 1));
|
length = htons((uint16_t) ((size >> 2) - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtcpHeader::net2Host(size_t len){
|
void RtcpHeader::net2Host(size_t len) {
|
||||||
switch ((RtcpType)pt) {
|
switch ((RtcpType) pt) {
|
||||||
case RtcpType::RTCP_SR: {
|
case RtcpType::RTCP_SR: {
|
||||||
RtcpSR *sr = (RtcpSR *)this;
|
RtcpSR *sr = (RtcpSR *) this;
|
||||||
sr->net2Host(len);
|
sr->net2Host(len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RtcpType::RTCP_RR: {
|
case RtcpType::RTCP_RR: {
|
||||||
RtcpRR *rr = (RtcpRR *)this;
|
RtcpRR *rr = (RtcpRR *) this;
|
||||||
rr->net2Host(len);
|
rr->net2Host(len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RtcpType::RTCP_SDES: {
|
case RtcpType::RTCP_SDES: {
|
||||||
RtcpSdes *sdes = (RtcpSdes *)this;
|
RtcpSdes *sdes = (RtcpSdes *) this;
|
||||||
sdes->net2Host(len);
|
sdes->net2Host(len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RtcpType::RTCP_RTPFB:
|
case RtcpType::RTCP_RTPFB:
|
||||||
case RtcpType::RTCP_PSFB: {
|
case RtcpType::RTCP_PSFB: {
|
||||||
RtcpFB *fb = (RtcpFB *)this;
|
RtcpFB *fb = (RtcpFB *) this;
|
||||||
fb->net2Host(len);
|
fb->net2Host(len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RtcpType::RTCP_BYE: {
|
case RtcpType::RTCP_BYE: {
|
||||||
RtcpBye *bye = (RtcpBye *)this;
|
RtcpBye *bye = (RtcpBye *) this;
|
||||||
bye->net2Host(len);
|
bye->net2Host(len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -195,14 +195,14 @@ void RtcpHeader::net2Host(size_t len){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<RtcpHeader *> RtcpHeader::loadFromBytes(char *data, size_t len){
|
vector<RtcpHeader *> RtcpHeader::loadFromBytes(char *data, size_t len) {
|
||||||
vector<RtcpHeader *> ret;
|
vector<RtcpHeader *> ret;
|
||||||
ssize_t remain = len;
|
ssize_t remain = len;
|
||||||
char *ptr = data;
|
char *ptr = data;
|
||||||
while (remain > (ssize_t) sizeof(RtcpHeader)) {
|
while (remain > (ssize_t) sizeof(RtcpHeader)) {
|
||||||
RtcpHeader *rtcp = (RtcpHeader *) ptr;
|
RtcpHeader *rtcp = (RtcpHeader *) ptr;
|
||||||
auto rtcp_len = rtcp->getSize();
|
auto rtcp_len = rtcp->getSize();
|
||||||
if (remain < (ssize_t)rtcp_len) {
|
if (remain < (ssize_t) rtcp_len) {
|
||||||
WarnL << "非法的rtcp包,声明的长度超过实际数据长度";
|
WarnL << "非法的rtcp包,声明的长度超过实际数据长度";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -256,10 +256,10 @@ std::shared_ptr<RtcpSR> RtcpSR::create(size_t item_count) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
string RtcpSR::getNtpStamp() const{
|
string RtcpSR::getNtpStamp() const {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = ntpmsw - 0x83AA7E80;
|
tv.tv_sec = ntpmsw - 0x83AA7E80;
|
||||||
tv.tv_usec = (decltype(tv.tv_usec))(ntplsw / ((double) (((uint64_t) 1) << 32) * 1.0e-6));
|
tv.tv_usec = (decltype(tv.tv_usec)) (ntplsw / ((double) (((uint64_t) 1) << 32) * 1.0e-6));
|
||||||
return LogChannel::printTime(tv);
|
return LogChannel::printTime(tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ void RtcpSR::setNtpStamp(uint64_t unix_stamp_ms) {
|
|||||||
setNtpStamp(tv);
|
setNtpStamp(tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
string RtcpSR::dumpString() const{
|
string RtcpSR::dumpString() const {
|
||||||
_StrPrinter printer;
|
_StrPrinter printer;
|
||||||
printer << RtcpHeader::dumpHeader();
|
printer << RtcpHeader::dumpHeader();
|
||||||
printer << "ssrc:" << ssrc << "\r\n";
|
printer << "ssrc:" << ssrc << "\r\n";
|
||||||
@ -297,7 +297,7 @@ string RtcpSR::dumpString() const{
|
|||||||
printer << "rtpts:" << rtpts << "\r\n";
|
printer << "rtpts:" << rtpts << "\r\n";
|
||||||
printer << "packet_count:" << packet_count << "\r\n";
|
printer << "packet_count:" << packet_count << "\r\n";
|
||||||
printer << "octet_count:" << octet_count << "\r\n";
|
printer << "octet_count:" << octet_count << "\r\n";
|
||||||
auto items = ((RtcpSR *)this)->getItemList();
|
auto items = ((RtcpSR *) this)->getItemList();
|
||||||
auto i = 0;
|
auto i = 0;
|
||||||
for (auto &item : items) {
|
for (auto &item : items) {
|
||||||
printer << "---- item:" << i++ << " ----\r\n";
|
printer << "---- item:" << i++ << " ----\r\n";
|
||||||
@ -331,7 +331,7 @@ void RtcpSR::net2Host(size_t size) {
|
|||||||
|
|
||||||
ReportItem *ptr = &items;
|
ReportItem *ptr = &items;
|
||||||
int item_count = 0;
|
int item_count = 0;
|
||||||
for(int i = 0; i < (int)report_count && (char *)(ptr) + sizeof(ReportItem) <= (char *)(this) + size; ++i){
|
for (int i = 0; i < (int) report_count && (char *) (ptr) + sizeof(ReportItem) <= (char *) (this) + size; ++i) {
|
||||||
ptr->net2Host();
|
ptr->net2Host();
|
||||||
++ptr;
|
++ptr;
|
||||||
++item_count;
|
++item_count;
|
||||||
@ -339,7 +339,7 @@ void RtcpSR::net2Host(size_t size) {
|
|||||||
CHECK_REPORT_COUNT(item_count);
|
CHECK_REPORT_COUNT(item_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<ReportItem*> RtcpSR::getItemList(){
|
vector<ReportItem *> RtcpSR::getItemList() {
|
||||||
vector<ReportItem *> ret;
|
vector<ReportItem *> ret;
|
||||||
ReportItem *ptr = &items;
|
ReportItem *ptr = &items;
|
||||||
for (int i = 0; i < (int) report_count; ++i) {
|
for (int i = 0; i < (int) report_count; ++i) {
|
||||||
@ -351,7 +351,7 @@ vector<ReportItem*> RtcpSR::getItemList(){
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
string ReportItem::dumpString() const{
|
string ReportItem::dumpString() const {
|
||||||
_StrPrinter printer;
|
_StrPrinter printer;
|
||||||
printer << "ssrc:" << ssrc << "\r\n";
|
printer << "ssrc:" << ssrc << "\r\n";
|
||||||
printer << "fraction:" << fraction << "\r\n";
|
printer << "fraction:" << fraction << "\r\n";
|
||||||
@ -366,7 +366,7 @@ string ReportItem::dumpString() const{
|
|||||||
|
|
||||||
void ReportItem::net2Host() {
|
void ReportItem::net2Host() {
|
||||||
ssrc = ntohl(ssrc);
|
ssrc = ntohl(ssrc);
|
||||||
cumulative = ntohl(cumulative ) >> 8;
|
cumulative = ntohl(cumulative) >> 8;
|
||||||
seq_cycles = ntohs(seq_cycles);
|
seq_cycles = ntohs(seq_cycles);
|
||||||
seq_max = ntohs(seq_max);
|
seq_max = ntohs(seq_max);
|
||||||
jitter = ntohl(jitter);
|
jitter = ntohl(jitter);
|
||||||
@ -387,11 +387,11 @@ std::shared_ptr<RtcpRR> RtcpRR::create(size_t item_count) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
string RtcpRR::dumpString() const{
|
string RtcpRR::dumpString() const {
|
||||||
_StrPrinter printer;
|
_StrPrinter printer;
|
||||||
printer << RtcpHeader::dumpHeader();
|
printer << RtcpHeader::dumpHeader();
|
||||||
printer << "ssrc:" << ssrc << "\r\n";
|
printer << "ssrc:" << ssrc << "\r\n";
|
||||||
auto items = ((RtcpRR *)this)->getItemList();
|
auto items = ((RtcpRR *) this)->getItemList();
|
||||||
auto i = 0;
|
auto i = 0;
|
||||||
for (auto &item : items) {
|
for (auto &item : items) {
|
||||||
printer << "---- item:" << i++ << " ----\r\n";
|
printer << "---- item:" << i++ << " ----\r\n";
|
||||||
@ -407,7 +407,7 @@ void RtcpRR::net2Host(size_t size) {
|
|||||||
|
|
||||||
ReportItem *ptr = &items;
|
ReportItem *ptr = &items;
|
||||||
int item_count = 0;
|
int item_count = 0;
|
||||||
for(int i = 0; i < (int)report_count && (char *)(ptr) + sizeof(ReportItem) <= (char *)(this) + size; ++i){
|
for (int i = 0; i < (int) report_count && (char *) (ptr) + sizeof(ReportItem) <= (char *) (this) + size; ++i) {
|
||||||
ptr->net2Host();
|
ptr->net2Host();
|
||||||
++ptr;
|
++ptr;
|
||||||
++item_count;
|
++item_count;
|
||||||
@ -415,7 +415,7 @@ void RtcpRR::net2Host(size_t size) {
|
|||||||
CHECK_REPORT_COUNT(item_count);
|
CHECK_REPORT_COUNT(item_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<ReportItem*> RtcpRR::getItemList() {
|
vector<ReportItem *> RtcpRR::getItemList() {
|
||||||
vector<ReportItem *> ret;
|
vector<ReportItem *> ret;
|
||||||
ReportItem *ptr = &items;
|
ReportItem *ptr = &items;
|
||||||
for (int i = 0; i < (int) report_count; ++i) {
|
for (int i = 0; i < (int) report_count; ++i) {
|
||||||
@ -431,7 +431,7 @@ void SdesChunk::net2Host() {
|
|||||||
ssrc = ntohl(ssrc);
|
ssrc = ntohl(ssrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SdesChunk::totalBytes() const{
|
size_t SdesChunk::totalBytes() const {
|
||||||
return alignSize(minSize() + txt_len);
|
return alignSize(minSize() + txt_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ size_t SdesChunk::minSize() {
|
|||||||
return sizeof(SdesChunk) - sizeof(text);
|
return sizeof(SdesChunk) - sizeof(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
string SdesChunk::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";
|
||||||
@ -471,7 +471,7 @@ std::shared_ptr<RtcpSdes> RtcpSdes::create(const std::vector<string> &item_text)
|
|||||||
setupHeader(ptr, RtcpType::RTCP_SDES, item_text.size(), bytes);
|
setupHeader(ptr, RtcpType::RTCP_SDES, item_text.size(), bytes);
|
||||||
setupPadding(ptr, bytes - real_size);
|
setupPadding(ptr, bytes - real_size);
|
||||||
return std::shared_ptr<RtcpSdes>(ptr, [](RtcpSdes *ptr) {
|
return std::shared_ptr<RtcpSdes>(ptr, [](RtcpSdes *ptr) {
|
||||||
delete [] (char *) ptr;
|
delete[] (char *) ptr;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,7 +492,7 @@ void RtcpSdes::net2Host(size_t size) {
|
|||||||
CHECK_MIN_SIZE(size, kMinSize);
|
CHECK_MIN_SIZE(size, kMinSize);
|
||||||
SdesChunk *ptr = &chunks;
|
SdesChunk *ptr = &chunks;
|
||||||
int item_count = 0;
|
int item_count = 0;
|
||||||
for(int i = 0; i < (int)report_count && (char *)(ptr) + SdesChunk::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 = (SdesChunk *) ((char *) ptr + ptr->totalBytes());
|
ptr = (SdesChunk *) ((char *) ptr + ptr->totalBytes());
|
||||||
++item_count;
|
++item_count;
|
||||||
@ -520,7 +520,7 @@ std::shared_ptr<RtcpFB> RtcpFB::create_l(RtcpType type, int fmt, const void *fci
|
|||||||
auto bytes = alignSize(real_size);
|
auto bytes = alignSize(real_size);
|
||||||
auto ptr = (RtcpFB *) new char[bytes];
|
auto ptr = (RtcpFB *) new char[bytes];
|
||||||
if (fci && fci_len) {
|
if (fci && fci_len) {
|
||||||
memcpy((char *)ptr + sizeof(RtcpFB), fci, fci_len);
|
memcpy((char *) ptr + sizeof(RtcpFB), fci, fci_len);
|
||||||
}
|
}
|
||||||
setupHeader(ptr, type, fmt, bytes);
|
setupHeader(ptr, type, fmt, bytes);
|
||||||
setupPadding(ptr, bytes - real_size);
|
setupPadding(ptr, bytes - real_size);
|
||||||
@ -530,11 +530,11 @@ std::shared_ptr<RtcpFB> RtcpFB::create_l(RtcpType type, int fmt, const void *fci
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<RtcpFB> RtcpFB::create(PSFBType fmt, const void *fci, size_t fci_len) {
|
std::shared_ptr<RtcpFB> RtcpFB::create(PSFBType fmt, const void *fci, size_t fci_len) {
|
||||||
return RtcpFB::create_l(RtcpType::RTCP_PSFB, (int)fmt, fci, fci_len);
|
return RtcpFB::create_l(RtcpType::RTCP_PSFB, (int) fmt, fci, fci_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<RtcpFB> RtcpFB::create(RTPFBType fmt, const void *fci, size_t fci_len) {
|
std::shared_ptr<RtcpFB> RtcpFB::create(RTPFBType fmt, const void *fci, size_t fci_len) {
|
||||||
return RtcpFB::create_l(RtcpType::RTCP_RTPFB, (int)fmt, fci, fci_len);
|
return RtcpFB::create_l(RtcpType::RTCP_RTPFB, (int) fmt, fci, fci_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *RtcpFB::getFciPtr() const {
|
const void *RtcpFB::getFciPtr() const {
|
||||||
@ -625,10 +625,9 @@ std::shared_ptr<RtcpBye> RtcpBye::create(const std::vector<uint32_t> &ssrcs, con
|
|||||||
setupHeader(ptr, RtcpType::RTCP_BYE, ssrcs.size(), bytes);
|
setupHeader(ptr, RtcpType::RTCP_BYE, ssrcs.size(), bytes);
|
||||||
setupPadding(ptr, bytes - real_size);
|
setupPadding(ptr, bytes - real_size);
|
||||||
|
|
||||||
auto ssrc_ptr = ((RtcpBye *) ptr)->ssrc;
|
int i = 0;
|
||||||
for (auto ssrc : ssrcs) {
|
for (auto ssrc : ssrcs) {
|
||||||
*ssrc_ptr = htonl(ssrc);
|
((RtcpBye *) ptr)->ssrc[i++] = htonl(ssrc);
|
||||||
++ssrc_ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reason.empty()) {
|
if (!reason.empty()) {
|
||||||
@ -642,12 +641,10 @@ std::shared_ptr<RtcpBye> RtcpBye::create(const std::vector<uint32_t> &ssrcs, con
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<uint32_t *> RtcpBye::getSSRC() {
|
vector<uint32_t *> RtcpBye::getSSRC() {
|
||||||
vector<uint32_t *> ret;
|
vector<uint32_t *> ret;
|
||||||
auto ssrc_ptr = ssrc;
|
|
||||||
for (size_t i = 0; i < report_count; ++i) {
|
for (size_t i = 0; i < report_count; ++i) {
|
||||||
ret.emplace_back(ssrc_ptr);
|
ret.emplace_back(&(ssrc[i]));
|
||||||
ssrc_ptr += 1;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -663,7 +660,7 @@ string RtcpBye::getReason() const {
|
|||||||
string RtcpBye::dumpString() const {
|
string RtcpBye::dumpString() const {
|
||||||
_StrPrinter printer;
|
_StrPrinter printer;
|
||||||
printer << RtcpHeader::dumpHeader();
|
printer << RtcpHeader::dumpHeader();
|
||||||
for(auto ssrc : ((RtcpBye *)this)->getSSRC()) {
|
for (auto ssrc : ((RtcpBye *) this)->getSSRC()) {
|
||||||
printer << "ssrc:" << *ssrc << "\r\n";
|
printer << "ssrc:" << *ssrc << "\r\n";
|
||||||
}
|
}
|
||||||
printer << "reason:" << getReason();
|
printer << "reason:" << getReason();
|
||||||
@ -673,12 +670,10 @@ string RtcpBye::dumpString() const {
|
|||||||
void RtcpBye::net2Host(size_t size) {
|
void RtcpBye::net2Host(size_t size) {
|
||||||
static const size_t kMinSize = sizeof(RtcpHeader);
|
static const size_t kMinSize = sizeof(RtcpHeader);
|
||||||
CHECK_MIN_SIZE(size, kMinSize);
|
CHECK_MIN_SIZE(size, kMinSize);
|
||||||
auto ssrc_ptr = ssrc;
|
|
||||||
size_t offset = kMinSize;
|
size_t offset = kMinSize;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; i < report_count && offset + sizeof(ssrc) <= size; ++i) {
|
for (; i < report_count && offset + sizeof(ssrc) <= size; ++i) {
|
||||||
*ssrc_ptr = ntohl(*ssrc_ptr);
|
ssrc[i] = ntohl(ssrc[i]);
|
||||||
ssrc_ptr += 1;
|
|
||||||
offset += sizeof(ssrc);
|
offset += sizeof(ssrc);
|
||||||
}
|
}
|
||||||
//修正ssrc个数
|
//修正ssrc个数
|
||||||
|
@ -118,9 +118,9 @@ string FCI_REMB::create(const vector<uint32_t> &ssrcs, uint32_t bitrate) {
|
|||||||
thiz->bitrate[3] = (uint8_t) (mantissa);
|
thiz->bitrate[3] = (uint8_t) (mantissa);
|
||||||
|
|
||||||
//设置ssrc列表
|
//设置ssrc列表
|
||||||
auto ptr = thiz->ssrc_feedback;
|
int i = 0;
|
||||||
for (auto ssrc : ssrcs) {
|
for (auto ssrc : ssrcs) {
|
||||||
*(ptr++) = htonl(ssrc);
|
thiz->ssrc_feedback[i++] = htonl(ssrc);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -136,9 +136,10 @@ uint32_t FCI_REMB::getBitRate() const {
|
|||||||
vector<uint32_t> FCI_REMB::getSSRC() {
|
vector<uint32_t> FCI_REMB::getSSRC() {
|
||||||
vector<uint32_t> ret;
|
vector<uint32_t> ret;
|
||||||
auto num_ssrc = bitrate[0];
|
auto num_ssrc = bitrate[0];
|
||||||
auto ptr = ssrc_feedback;
|
int i = 0;
|
||||||
while (num_ssrc--) {
|
while (num_ssrc--) {
|
||||||
ret.emplace_back(ntohl(*ptr++));
|
ret.emplace_back(ntohl(ssrc_feedback[i]));
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -537,7 +538,7 @@ string FCI_TWCC::create(uint32_t ref_time, uint8_t fb_pkt_count, TwccPacketStatu
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vec.resize(MIN(vec.size(), 14 >> symbol));
|
vec.resize(MIN(vec.size(), (size_t)14 >> symbol));
|
||||||
StatusVecChunk chunk(symbol, vec);
|
StatusVecChunk chunk(symbol, vec);
|
||||||
fci.append((char *)&chunk, StatusVecChunk::kSize);
|
fci.append((char *)&chunk, StatusVecChunk::kSize);
|
||||||
appendDeltaString(delta_str, status, vec.size());
|
appendDeltaString(delta_str, status, vec.size());
|
||||||
|
@ -35,7 +35,8 @@ RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, size_t len, bo
|
|||||||
header->csrc = 0;
|
header->csrc = 0;
|
||||||
header->mark = mark;
|
header->mark = mark;
|
||||||
header->pt = _pt;
|
header->pt = _pt;
|
||||||
header->seq = htons(_seq++);
|
header->seq = htons(_seq);
|
||||||
|
++_seq;
|
||||||
header->stamp = htonl(uint64_t(stamp) * _sample_rate / 1000);
|
header->stamp = htonl(uint64_t(stamp) * _sample_rate / 1000);
|
||||||
header->ssrc = htonl(_ssrc);
|
header->ssrc = htonl(_ssrc);
|
||||||
|
|
||||||
|
@ -1,131 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by MIT license that can be found in the
|
|
||||||
* LICENSE file in the root of the source tree. All contributing project authors
|
|
||||||
* may be found in the AUTHORS file in the root of the source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Rtcp/Rtcp.h"
|
|
||||||
#include "Util/logger.h"
|
|
||||||
using namespace std;
|
|
||||||
using namespace toolkit;
|
|
||||||
using namespace mediakit;
|
|
||||||
|
|
||||||
void printRtcp(const std::shared_ptr<Buffer> &buffer){
|
|
||||||
auto rtcp_arr = RtcpHeader::loadFromBytes(buffer->data(), buffer->size());
|
|
||||||
//转换为主机字节序方可打印
|
|
||||||
InfoL << "\r\n" << rtcp_arr[0]->dumpString();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Buffer> makeRtcpSR() {
|
|
||||||
auto rtcp = RtcpSR::create(3);
|
|
||||||
rtcp->ssrc = htonl(1);
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
rtcp->setNtpStamp(tv);
|
|
||||||
rtcp->rtpts = htonl(2);
|
|
||||||
rtcp->packet_count = htonl(3);
|
|
||||||
rtcp->octet_count = htonl(4);
|
|
||||||
auto i = 5;
|
|
||||||
for (auto &ptr : rtcp->getItemList()) {
|
|
||||||
ReportItem *item = (ReportItem *) ptr;
|
|
||||||
item->ssrc = htonl(i++);
|
|
||||||
item->fraction = i++;
|
|
||||||
item->cumulative = htonl(i++) >> 8;
|
|
||||||
item->seq_cycles = htons(i++);
|
|
||||||
item->seq_max = htons(i++);
|
|
||||||
item->jitter = htonl(i++);
|
|
||||||
item->last_sr_stamp = htonl(i++);
|
|
||||||
item->delay_since_last_sr = htonl(i++);
|
|
||||||
}
|
|
||||||
//返回网络字节序
|
|
||||||
return RtcpHeader::toBuffer(rtcp);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Buffer> makeRtcpRR() {
|
|
||||||
auto rtcp = RtcpRR::create(3);
|
|
||||||
rtcp->ssrc = htonl(1);
|
|
||||||
auto i = 5;
|
|
||||||
for (auto &ptr : rtcp->getItemList()) {
|
|
||||||
ReportItem *item = (ReportItem *) ptr;
|
|
||||||
item->ssrc = htonl(i++);
|
|
||||||
item->fraction = i++;
|
|
||||||
item->cumulative = htonl(i++) >> 8;
|
|
||||||
item->seq_cycles = htons(i++);
|
|
||||||
item->seq_max = htons(i++);
|
|
||||||
item->jitter = htonl(i++);
|
|
||||||
item->last_sr_stamp = htonl(i++);
|
|
||||||
item->delay_since_last_sr = htonl(i++);
|
|
||||||
}
|
|
||||||
//返回网络字节序
|
|
||||||
return RtcpHeader::toBuffer(rtcp);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Buffer> makeRtcpSDES() {
|
|
||||||
auto rtcp = RtcpSdes::create({"zlmediakit", "", "https://github.com/xia-chu/ZLMediaKit", "1213642868@qq.com", "123456789012345678"});
|
|
||||||
auto i = 5;
|
|
||||||
auto items = rtcp->getChunkList();
|
|
||||||
items[0]->type = (uint8_t)SdesType::RTCP_SDES_CNAME;
|
|
||||||
items[0]->ssrc = htonl(i++);
|
|
||||||
|
|
||||||
items[1]->type = (uint8_t)SdesType::RTCP_SDES_NOTE;
|
|
||||||
items[1]->ssrc = htonl(i++);
|
|
||||||
|
|
||||||
items[2]->type = (uint8_t)SdesType::RTCP_SDES_LOC;
|
|
||||||
items[2]->ssrc = htonl(i++);
|
|
||||||
|
|
||||||
items[3]->type = (uint8_t)SdesType::RTCP_SDES_EMAIL;
|
|
||||||
items[3]->ssrc = htonl(i++);
|
|
||||||
|
|
||||||
items[4]->type = (uint8_t)SdesType::RTCP_SDES_PHONE;
|
|
||||||
items[4]->ssrc = htonl(i++);
|
|
||||||
|
|
||||||
//返回网络字节序
|
|
||||||
return RtcpHeader::toBuffer(rtcp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
|
||||||
Logger::Instance().add(std::make_shared<ConsoleChannel>());
|
|
||||||
{
|
|
||||||
static char rtcp_data[] = "\x81\xca\x00\x05\x70\xd8\xac\x1b\x01\x0b\x7a\x73\x68\x50\x43\x40"
|
|
||||||
"\x7a\x73\x68\x50\x43\x00\x00\x00"
|
|
||||||
"\x81\xc9\x00\x07\x70\xd8\xac\x1b\x55\x66\x77\x88\x00\x00\x00\x00"
|
|
||||||
"\x00\x00\x0d\x21\x00\x00\x00\x32\xdd\xf1\x00\x00\x00\x03\x4f\x67"
|
|
||||||
"\x80\xc8\x00\x06\x55\x66\x77\x88\xe3\x70\xdd\xf1\x00\x00\xc2\xb8"
|
|
||||||
"\x00\x21\xe4\x90\x00\x00\x0b\x81\x00\x2f\x6a\x60";
|
|
||||||
auto rtcp_arr = RtcpHeader::loadFromBytes(rtcp_data, sizeof(rtcp_data) - 1);
|
|
||||||
for (auto &rtcp : rtcp_arr) {
|
|
||||||
DebugL << "\r\n" << rtcp->dumpString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
printRtcp(makeRtcpSR());
|
|
||||||
printRtcp(makeRtcpRR());
|
|
||||||
printRtcp(makeRtcpSDES());
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
string str;
|
|
||||||
auto sr = makeRtcpSR();
|
|
||||||
auto rr = makeRtcpRR();
|
|
||||||
auto sdes = makeRtcpSDES();
|
|
||||||
str.append(sr->data(), sr->size());
|
|
||||||
str.append(rr->data(), rr->size());
|
|
||||||
str.append(sdes->data(), sdes->size());
|
|
||||||
//测试内存越界
|
|
||||||
char *data = new char[str.size()];
|
|
||||||
memcpy(data, str.data(), str.size());
|
|
||||||
auto rtcp_arr = RtcpHeader::loadFromBytes(data, str.size());
|
|
||||||
for (auto &rtcp : rtcp_arr) {
|
|
||||||
WarnL << "\r\n" << rtcp->dumpString();
|
|
||||||
}
|
|
||||||
delete [] data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -94,7 +94,7 @@ void NackContext::received(uint16_t seq, bool is_rtx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_seq.size() == diff + 1 && _last_max_seq + 1 == min_seq) {
|
if (_seq.size() == (size_t)diff + 1 && _last_max_seq + 1 == min_seq) {
|
||||||
//都是连续的seq,未丢包
|
//都是连续的seq,未丢包
|
||||||
_seq.clear();
|
_seq.clear();
|
||||||
_last_max_seq = max_seq;
|
_last_max_seq = max_seq;
|
||||||
@ -107,10 +107,10 @@ void NackContext::received(uint16_t seq, bool is_rtx) {
|
|||||||
|
|
||||||
//有丢包,丢包从_last_max_seq开始
|
//有丢包,丢包从_last_max_seq开始
|
||||||
auto nack_rtp_count = FCI_NACK::kBitSize;
|
auto nack_rtp_count = FCI_NACK::kBitSize;
|
||||||
if (max_seq - _last_max_seq > nack_rtp_count) {
|
if (max_seq > nack_rtp_count + _last_max_seq) {
|
||||||
vector<bool> vec;
|
vector<bool> vec;
|
||||||
vec.resize(FCI_NACK::kBitSize, false);
|
vec.resize(FCI_NACK::kBitSize, false);
|
||||||
for (auto i = 0; i < nack_rtp_count; ++i) {
|
for (size_t i = 0; i < nack_rtp_count; ++i) {
|
||||||
vec[i] = _seq.find(_last_max_seq + i + 2) == _seq.end();
|
vec[i] = _seq.find(_last_max_seq + i + 2) == _seq.end();
|
||||||
}
|
}
|
||||||
doNack(FCI_NACK(_last_max_seq + 1, vec), true);
|
doNack(FCI_NACK(_last_max_seq + 1, vec), true);
|
||||||
@ -224,7 +224,7 @@ uint64_t NackContext::reSendNack() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto inc = *it - pid;
|
auto inc = *it - pid;
|
||||||
if (inc > FCI_NACK::kBitSize) {
|
if (inc > (ssize_t)FCI_NACK::kBitSize) {
|
||||||
//新的nack包
|
//新的nack包
|
||||||
doNack(FCI_NACK(pid, vec), false);
|
doNack(FCI_NACK(pid, vec), false);
|
||||||
pid = -1;
|
pid = -1;
|
||||||
|
@ -843,7 +843,9 @@ void WebRtcTransportImp::onBeforeEncryptRtp(const char *buf, int &len, void *ctx
|
|||||||
|
|
||||||
auto origin_seq = ntohs(header->seq);
|
auto origin_seq = ntohs(header->seq);
|
||||||
//seq跟原来的不一样
|
//seq跟原来的不一样
|
||||||
header->seq = htons(_rtx_seq[pr->second->media->type]++);
|
header->seq = htons(_rtx_seq[pr->second->media->type]);
|
||||||
|
++_rtx_seq[pr->second->media->type];
|
||||||
|
|
||||||
auto payload = header->getPayloadData();
|
auto payload = header->getPayloadData();
|
||||||
auto payload_size = header->getPayloadSize(len);
|
auto payload_size = header->getPayloadSize(len);
|
||||||
if (payload_size) {
|
if (payload_size) {
|
||||||
|
Loading…
Reference in New Issue
Block a user