提交 2e75da78 authored 作者: José Luis Millán's avatar José Luis Millán

use consistent type2String method

上级 4d1e2554
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#include "common.h" #include "common.h"
#include "map"
#include "string"
namespace RTC namespace RTC
{ {
namespace RTCP namespace RTCP
...@@ -20,6 +23,21 @@ namespace RTCP ...@@ -20,6 +23,21 @@ namespace RTCP
PSFB = 206 PSFB = 206
}; };
static std::map<Type, std::string> type2String =
{
{ Type::FIR, "FIR" },
{ Type::NACK, "NACK" },
{ Type::SR, "SR" },
{ Type::RR, "RR" },
{ Type::SDES, "SDES" },
{ Type::BYE, "BYE" },
{ Type::APP, "APP" },
{ Type::RTPFB, "RTPFB" },
{ Type::PSFB, "PSBF" }
};
const std::string& Type2String(Type type);
class Packet class Packet
{ {
public: public:
...@@ -42,7 +60,7 @@ namespace RTCP ...@@ -42,7 +60,7 @@ namespace RTCP
public: public:
static bool IsRtcp(const uint8_t* data, size_t len); static bool IsRtcp(const uint8_t* data, size_t len);
static Packet* Parse(const uint8_t* data, size_t len); static Packet* Parse(const uint8_t* data, size_t len);
static const char* TypeString(Type type);
public: public:
Packet(Type type); Packet(Type type);
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "RTC/RTCP/Packet.h" #include "RTC/RTCP/Packet.h"
#include <vector> #include <vector>
#include <map>
#include <string>
namespace RTC { namespace RTCP namespace RTC { namespace RTCP
{ {
...@@ -13,8 +15,6 @@ namespace RTC { namespace RTCP ...@@ -13,8 +15,6 @@ namespace RTC { namespace RTCP
class SdesItem class SdesItem
{ {
static const char* _TypeString [];
public: public:
typedef enum Type : uint8_t typedef enum Type : uint8_t
{ {
...@@ -39,7 +39,7 @@ namespace RTC { namespace RTCP ...@@ -39,7 +39,7 @@ namespace RTC { namespace RTCP
public: public:
static SdesItem* Parse(const uint8_t* data, size_t len); static SdesItem* Parse(const uint8_t* data, size_t len);
static const char* TypeString(uint8_t type); static const std::string& Type2String(Type type);
public: public:
SdesItem(Header* header); SdesItem(Header* header);
...@@ -60,6 +60,9 @@ namespace RTC { namespace RTCP ...@@ -60,6 +60,9 @@ namespace RTC { namespace RTCP
// Passed by argument. // Passed by argument.
Header* header = nullptr; Header* header = nullptr;
uint8_t* raw = nullptr; uint8_t* raw = nullptr;
private:
static std::map<SdesItem::Type, std::string> type2String;
}; };
class SdesChunk class SdesChunk
......
...@@ -11,6 +11,17 @@ namespace RTC ...@@ -11,6 +11,17 @@ namespace RTC
{ {
namespace RTCP namespace RTCP
{ {
/* Namespace methods */
const std::string& Type2String(Type type)
{
static const std::string unknown("UNKNOWN");
if (type2String.find(type) == type2String.end())
return unknown;
return type2String[type];
}
/* Class methods. */ /* Class methods. */
Packet* Packet::Parse(const uint8_t* data, size_t len) Packet* Packet::Parse(const uint8_t* data, size_t len)
...@@ -91,7 +102,7 @@ namespace RTCP ...@@ -91,7 +102,7 @@ namespace RTCP
} }
if (!current) { if (!current) {
MS_WARN("error parsing %s Packet", TypeString(RTCP::Type(header->packet_type))); MS_WARN("error parsing %s Packet", Type2String(Type(header->packet_type)).c_str());
return first; return first;
} }
...@@ -111,33 +122,6 @@ namespace RTCP ...@@ -111,33 +122,6 @@ namespace RTCP
return first; return first;
} }
const char* Packet::TypeString(Type type)
{
switch (type)
{
case Type::FIR:
return "FIR";
case Type::NACK:
return "NACK";
case Type::SR:
return "SR";
case Type::RR:
return "RR";
case Type::SDES:
return "SDES";
case Type::BYE:
return "BYE";
case Type::APP:
return "APP";
case Type::RTPFB:
return "RTPFB";
case Type::PSFB:
return "PSFB";
default:
return "UNKNOWN";
}
}
/* Instance methods. */ /* Instance methods. */
Packet::Packet(Type type) Packet::Packet(Type type)
......
...@@ -10,17 +10,19 @@ namespace RTC ...@@ -10,17 +10,19 @@ namespace RTC
namespace RTCP namespace RTCP
{ {
const char* SdesItem::_TypeString [] /* Sdes Item Class variables. */
std::map<SdesItem::Type, std::string> SdesItem::type2String =
{ {
"END", { END, "END" },
"CNAME", { CNAME, "CNAME" },
"NAME", { NAME, "NAME" },
"EMAIL", { EMAIL, "EMAIL" },
"PHONE", { PHONE, "PHONE" },
"LOC", { LOC, "LOC" },
"TOOL", { TOOL, "TOOL" },
"NOTE", { NOTE, "NOTE" },
"PRIV" { PRIV, "PRIV" },
}; };
/* SDES Item Class methods. */ /* SDES Item Class methods. */
...@@ -43,13 +45,14 @@ namespace RTCP ...@@ -43,13 +45,14 @@ namespace RTCP
return new SdesItem(header); return new SdesItem(header);
} }
const char* SdesItem::TypeString(uint8_t type) const std::string& SdesItem::Type2String(Type type)
{ {
if (type < sizeof(_TypeString)) static const std::string unknown("UNKNOWN");
return _TypeString[type];
if (type2String.find(type) == type2String.end())
return unknown;
else return type2String[type];
return "UNKNOWN";
} }
/* SDES Item Instance methods. */ /* SDES Item Instance methods. */
...@@ -79,7 +82,7 @@ namespace RTCP ...@@ -79,7 +82,7 @@ namespace RTCP
return; return;
MS_WARN("\t\t<Sdes Item>"); MS_WARN("\t\t<Sdes Item>");
MS_WARN("\t\t\ttype: %s", TypeString(this->GetType())); MS_WARN("\t\t\ttype: %s", Type2String(this->GetType()).c_str());
MS_WARN("\t\t\tlength: %u", this->header->length); MS_WARN("\t\t\tlength: %u", this->header->length);
MS_WARN("\t\t\tvalue: %.*s", this->header->length, this->header->value); MS_WARN("\t\t\tvalue: %.*s", this->header->length, this->header->value);
MS_WARN("\t\t</Sdes Item>"); MS_WARN("\t\t</Sdes Item>");
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论