修复#247

This commit is contained in:
xiongziliang 2020-03-26 17:12:21 +08:00
parent 402d5f83e5
commit c145f5f8ba
3 changed files with 106 additions and 9 deletions

View File

@ -88,8 +88,7 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
return std::make_shared<H265Track>(vps,sps,pps,0,0,0);
}
WarnL << "暂不支持该sdp:" << track->_codec << " " << track->_fmtp;
WarnL << "暂不支持该sdp:" << track->getName();
return nullptr;
}

View File

@ -30,6 +30,42 @@
namespace mediakit{
int RtpPayload::getClockRate(int pt){
switch (pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return clock_rate;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return 90000;
}
}
TrackType RtpPayload::getTrackType(int pt){
switch (pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return type;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return TrackInvalid;
}
}
int RtpPayload::getAudioChannel(int pt){
switch (pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return channel;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return 1;
}
}
const char * RtpPayload::getName(int pt){
switch (pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return #name;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return "unknown payload type";
}
}
static void getAttrSdp(const map<string, string> &attr, _StrPrinter &printer){
const map<string, string>::value_type *ptr = nullptr;
for(auto &pr : attr){
@ -47,6 +83,16 @@ static void getAttrSdp(const map<string, string> &attr, _StrPrinter &printer){
printer << "a=" << ptr->first << ":" << ptr->second << "\r\n";
}
}
string SdpTrack::getName() const{
switch (_pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return #name;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return _codec;
}
}
string SdpTrack::toString() const {
_StrPrinter _printer;
switch (_type){
@ -105,8 +151,9 @@ static TrackType toTrackType(const string &str) {
void SdpParser::load(const string &sdp) {
{
_track_vec.clear();
string key;
SdpTrack::Ptr track = std::make_shared<SdpTrack>();
track->_type = TrackTitle;
_track_vec.emplace_back(track);
auto lines = split(sdp, "\n");
for (auto &line : lines) {
@ -136,11 +183,17 @@ void SdpParser::load(const string &sdp) {
track->_b = opt_val;
break;
case 'm': {
track->_type = toTrackType(key);
_track_vec.emplace_back(track);
track = std::make_shared<SdpTrack>();
key = FindField(opt_val.data(), nullptr, " ");
track->_m = opt_val;
int pt, port;
char rtp[16] = {0}, type[16];
if (4 == sscanf(opt_val.data(), " %15[^ ] %d %15[^ ] %d", type, &port, rtp, &pt)) {
track->_pt = pt;
track->_samplerate = RtpPayload::getClockRate(pt) ;
track->_type = toTrackType(type);
track->_m = opt_val;
track->_port = port;
_track_vec.emplace_back(track);
}
}
break;
case 'a': {
@ -157,8 +210,6 @@ void SdpParser::load(const string &sdp) {
break;
}
}
track->_type = toTrackType(key);
_track_vec.emplace_back(track);
}
for (auto &track_ptr : _track_vec) {

View File

@ -47,6 +47,40 @@ typedef enum {
RTP_UDP = 1,
RTP_MULTICAST = 2,
} eRtpType;
#define RTP_PT_MAP(XX) \
XX(PCMU, TrackAudio, 0, 8000, 1) \
XX(GSM, TrackAudio , 3, 8000, 1) \
XX(G723, TrackAudio, 4, 8000, 1) \
XX(DVI4_8000, TrackAudio, 5, 8000, 1) \
XX(DVI4_16000, TrackAudio, 6, 16000, 1) \
XX(LPC, TrackAudio, 7, 8000, 1) \
XX(PCMA, TrackAudio, 8, 8000, 1) \
XX(G722, TrackAudio, 9, 8000, 1) \
XX(L16_Stereo, TrackAudio, 10, 44100, 2) \
XX(L16_Mono, TrackAudio, 11, 44100, 1) \
XX(QCELP, TrackAudio, 12, 8000, 1) \
XX(CN, TrackAudio, 13, 8000, 1) \
XX(MPA, TrackAudio, 14, 90000, 1) \
XX(G728, TrackAudio, 15, 8000, 1) \
XX(DVI4_11025, TrackAudio, 16, 11025, 1) \
XX(DVI4_22050, TrackAudio, 17, 22050, 1) \
XX(G729, TrackAudio, 18, 8000, 1) \
XX(CelB, TrackVideo, 25, 90000, 1) \
XX(JPEG, TrackVideo, 26, 90000, 1) \
XX(nv, TrackVideo, 28, 90000, 1) \
XX(H261, TrackVideo, 31, 90000, 1) \
XX(MPV, TrackVideo, 32, 90000, 1) \
XX(MP2T, TrackVideo, 33, 90000, 1) \
XX(H263, TrackVideo, 34, 90000, 1) \
typedef enum {
#define ENUM_DEF(name, type, value, clock_rate, channel) PT_ ## name = value,
RTP_PT_MAP(ENUM_DEF)
#undef ENUM_DEF
PT_MAX = 128
} PayloadType;
};
class RtpPacket : public BufferRaw{
@ -63,6 +97,17 @@ public:
TrackType type;
};
class RtpPayload{
public:
static int getClockRate(int pt);
static TrackType getTrackType(int pt);
static int getAudioChannel(int pt);
static const char *getName(int pt);
private:
RtpPayload() = delete;
~RtpPayload() = delete;
};
class RtcpCounter {
public:
uint32_t pktCnt = 0;
@ -83,6 +128,7 @@ public:
string _c;
string _t;
string _b;
uint16_t _port;
float _duration = 0;
float _start = 0;
@ -92,6 +138,7 @@ public:
map<string, string> _attr;
string toString() const;
string getName() const;
public:
int _pt;
string _codec;