格式化代码

This commit is contained in:
ziyue 2022-08-05 17:55:48 +08:00
parent ba947cb6b5
commit 663d167837

View File

@ -22,48 +22,40 @@ namespace mediakit {
const char *rtcpTypeToStr(RtcpType type) { const char *rtcpTypeToStr(RtcpType type) {
switch (type) { switch (type) {
#define SWITCH_CASE(key, value) \ #define SWITCH_CASE(key, value) \
case RtcpType::key: \ case RtcpType::key: return #value "(" #key ")";
return #value "(" #key ")";
RTCP_PT_MAP(SWITCH_CASE) RTCP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return "unknown rtcp pt";
return "unknown rtcp pt";
} }
} }
const char *sdesTypeToStr(SdesType type) { const char *sdesTypeToStr(SdesType type) {
switch (type) { switch (type) {
#define SWITCH_CASE(key, value) \ #define SWITCH_CASE(key, value) \
case SdesType::key: \ case SdesType::key: return #value "(" #key ")";
return #value "(" #key ")";
SDES_TYPE_MAP(SWITCH_CASE) SDES_TYPE_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return "unknown source description type";
return "unknown source description type";
} }
} }
const char *psfbTypeToStr(PSFBType type) { const char *psfbTypeToStr(PSFBType type) {
switch (type) { switch (type) {
#define SWITCH_CASE(key, value) \ #define SWITCH_CASE(key, value) \
case PSFBType::key: \ case PSFBType::key: return #value "(" #key ")";
return #value "(" #key ")";
PSFB_TYPE_MAP(SWITCH_CASE) PSFB_TYPE_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return "unknown payload-specific fb message fmt type";
return "unknown payload-specific fb message fmt type";
} }
} }
const char *rtpfbTypeToStr(RTPFBType type) { const char *rtpfbTypeToStr(RTPFBType type) {
switch (type) { switch (type) {
#define SWITCH_CASE(key, value) \ #define SWITCH_CASE(key, value) \
case RTPFBType::key: \ case RTPFBType::key: return #value "(" #key ")";
return #value "(" #key ")";
RTPFB_TYPE_MAP(SWITCH_CASE) RTPFB_TYPE_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return "unknown transport layer feedback messages fmt type";
return "unknown transport layer feedback messages fmt type";
} }
} }
@ -152,8 +144,7 @@ string RtcpHeader::dumpString() const {
return rtcp->dumpString(); return rtcp->dumpString();
} }
default: default: return StrPrinter << dumpHeader() << hexdump((char *)this + sizeof(*this), getSize() - sizeof(*this));
return StrPrinter << dumpHeader() << hexdump((char *)this + sizeof(*this), getSize() - sizeof(*this));
} }
} }
@ -220,8 +211,7 @@ void RtcpHeader::net2Host(size_t len) {
} }
break; break;
} }
default: default: throw std::runtime_error(StrPrinter << "未处理的rtcp包:" << rtcpTypeToStr((RtcpType)this->pt));
throw std::runtime_error(StrPrinter << "未处理的rtcp包:" << rtcpTypeToStr((RtcpType)this->pt));
} }
} }
@ -275,7 +265,7 @@ std::shared_ptr<RtcpSR> RtcpSR::create(size_t item_count) {
auto ptr = (RtcpSR *)new char[bytes]; auto ptr = (RtcpSR *)new char[bytes];
setupHeader(ptr, RtcpType::RTCP_SR, item_count, bytes); setupHeader(ptr, RtcpType::RTCP_SR, item_count, bytes);
setupPadding(ptr, bytes - real_size); setupPadding(ptr, bytes - real_size);
return std::shared_ptr<RtcpSR>(ptr, [](RtcpSR *ptr) { delete[] (char *)ptr; }); return std::shared_ptr<RtcpSR>(ptr, [](RtcpSR *ptr) { delete[](char *) ptr; });
} }
string RtcpSR::getNtpStamp() const { string RtcpSR::getNtpStamp() const {
@ -406,7 +396,7 @@ std::shared_ptr<RtcpRR> RtcpRR::create(size_t item_count) {
auto ptr = (RtcpRR *)new char[bytes]; auto ptr = (RtcpRR *)new char[bytes];
setupHeader(ptr, RtcpType::RTCP_RR, item_count, bytes); setupHeader(ptr, RtcpType::RTCP_RR, item_count, bytes);
setupPadding(ptr, bytes - real_size); setupPadding(ptr, bytes - real_size);
return std::shared_ptr<RtcpRR>(ptr, [](RtcpRR *ptr) { delete[] (char *)ptr; }); return std::shared_ptr<RtcpRR>(ptr, [](RtcpRR *ptr) { delete[](char *) ptr; });
} }
string RtcpRR::dumpString() const { string RtcpRR::dumpString() const {
@ -492,7 +482,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) { delete[] (char *)ptr; }); return std::shared_ptr<RtcpSdes>(ptr, [](RtcpSdes *ptr) { delete[](char *) ptr; });
} }
string RtcpSdes::dumpString() const { string RtcpSdes::dumpString() const {
@ -544,7 +534,7 @@ std::shared_ptr<RtcpFB> RtcpFB::create_l(RtcpType type, int fmt, const void *fci
} }
setupHeader(ptr, type, fmt, bytes); setupHeader(ptr, type, fmt, bytes);
setupPadding(ptr, bytes - real_size); setupPadding(ptr, bytes - real_size);
return std::shared_ptr<RtcpFB>((RtcpFB *)ptr, [](RtcpFB *ptr) { delete[] (char *)ptr; }); return std::shared_ptr<RtcpFB>((RtcpFB *)ptr, [](RtcpFB *ptr) { delete[](char *) ptr; });
} }
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) {
@ -596,7 +586,8 @@ string RtcpFB::dumpString() const {
break; break;
} }
default: { default: {
printer << "fci:" << psfbTypeToStr((PSFBType)report_count) << " " << hexdump(getFciPtr(), getFciSize()); printer << "fci:" << psfbTypeToStr((PSFBType)report_count) << " "
<< hexdump(getFciPtr(), getFciSize());
break; break;
} }
} }
@ -615,15 +606,14 @@ string RtcpFB::dumpString() const {
break; break;
} }
default: { default: {
printer << "fci:" << rtpfbTypeToStr((RTPFBType)report_count) << " " << hexdump(getFciPtr(), getFciSize()); printer << "fci:" << rtpfbTypeToStr((RTPFBType)report_count) << " "
<< hexdump(getFciPtr(), getFciSize());
break; break;
} }
} }
break; break;
} }
default: /*不可达*/ default: /*不可达*/ assert(0); break;
assert(0);
break;
} }
return std::move(printer); return std::move(printer);
} }
@ -656,7 +646,7 @@ std::shared_ptr<RtcpBye> RtcpBye::create(const std::vector<uint32_t> &ssrcs, con
memcpy(reason_len_ptr + 1, reason.data(), *reason_len_ptr); memcpy(reason_len_ptr + 1, reason.data(), *reason_len_ptr);
} }
return std::shared_ptr<RtcpBye>(ptr, [](RtcpBye *ptr) { delete[] (char *)ptr; }); return std::shared_ptr<RtcpBye>(ptr, [](RtcpBye *ptr) { delete[](char *) ptr; });
} }
vector<uint32_t *> RtcpBye::getSSRC() { vector<uint32_t *> RtcpBye::getSSRC() {
@ -794,7 +784,7 @@ std::shared_ptr<RtcpXRDLRR> RtcpXRDLRR::create(size_t item_count) {
auto ptr = (RtcpXRDLRR *)new char[bytes]; auto ptr = (RtcpXRDLRR *)new char[bytes];
setupHeader(ptr, RtcpType::RTCP_XR, 0, bytes); setupHeader(ptr, RtcpType::RTCP_XR, 0, bytes);
setupPadding(ptr, bytes - real_size); setupPadding(ptr, bytes - real_size);
return std::shared_ptr<RtcpXRDLRR>(ptr, [](RtcpXRDLRR *ptr) { delete[] (char *)ptr; }); return std::shared_ptr<RtcpXRDLRR>(ptr, [](RtcpXRDLRR *ptr) { delete[](char *) ptr; });
} }
#if 0 #if 0