根据playload type生成track

This commit is contained in:
xiongziliang 2020-04-18 23:00:48 +08:00
parent bacf8f100b
commit 3efda8fd0b
3 changed files with 48 additions and 30 deletions

View File

@ -84,6 +84,14 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
return std::make_shared<H265Track>(vps,sps,pps,0,0,0);
}
//可以根据传统的payload type 获取编码类型以及采样率等信息
CodecId codec_id = RtpPayload::getCodecId(track->_pt);
switch (codec_id){
case CodecG711A :
case CodecG711U : return std::make_shared<G711Track>(codec_id, track->_samplerate, track->_channel, 16);
default : break;
}
WarnL << "暂不支持该sdp:" << track->getName();
return nullptr;
}

View File

@ -16,7 +16,7 @@ namespace mediakit{
int RtpPayload::getClockRate(int pt){
switch (pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return clock_rate;
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return clock_rate;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return 90000;
@ -25,7 +25,7 @@ int RtpPayload::getClockRate(int pt){
TrackType RtpPayload::getTrackType(int pt){
switch (pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return type;
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return type;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return TrackInvalid;
@ -34,7 +34,7 @@ TrackType RtpPayload::getTrackType(int pt){
int RtpPayload::getAudioChannel(int pt){
switch (pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return channel;
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return channel;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return 1;
@ -43,13 +43,22 @@ int RtpPayload::getAudioChannel(int pt){
const char * RtpPayload::getName(int pt){
switch (pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return #name;
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return #name;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return "unknown payload type";
}
}
CodecId RtpPayload::getCodecId(int pt) {
switch (pt) {
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return codec_id;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default : return CodecInvalid;
}
}
static void getAttrSdp(const map<string, string> &attr, _StrPrinter &printer){
const map<string, string>::value_type *ptr = nullptr;
for(auto &pr : attr){
@ -70,7 +79,7 @@ static void getAttrSdp(const map<string, string> &attr, _StrPrinter &printer){
string SdpTrack::getName() const{
switch (_pt){
#define SWITCH_CASE(name, type, value, clock_rate, channel) case value : return #name;
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return #name;
RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE
default: return _codec;

View File

@ -34,33 +34,33 @@ typedef enum {
} 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) \
XX(PCMU, TrackAudio, 0, 8000, 1, CodecG711U) \
XX(GSM, TrackAudio , 3, 8000, 1, CodecInvalid) \
XX(G723, TrackAudio, 4, 8000, 1, CodecInvalid) \
XX(DVI4_8000, TrackAudio, 5, 8000, 1, CodecInvalid) \
XX(DVI4_16000, TrackAudio, 6, 16000, 1, CodecInvalid) \
XX(LPC, TrackAudio, 7, 8000, 1, CodecInvalid) \
XX(PCMA, TrackAudio, 8, 8000, 1, CodecG711A) \
XX(G722, TrackAudio, 9, 8000, 1, CodecInvalid) \
XX(L16_Stereo, TrackAudio, 10, 44100, 2, CodecInvalid) \
XX(L16_Mono, TrackAudio, 11, 44100, 1, CodecInvalid) \
XX(QCELP, TrackAudio, 12, 8000, 1, CodecInvalid) \
XX(CN, TrackAudio, 13, 8000, 1, CodecInvalid) \
XX(MPA, TrackAudio, 14, 90000, 1, CodecInvalid) \
XX(G728, TrackAudio, 15, 8000, 1, CodecInvalid) \
XX(DVI4_11025, TrackAudio, 16, 11025, 1, CodecInvalid) \
XX(DVI4_22050, TrackAudio, 17, 22050, 1, CodecInvalid) \
XX(G729, TrackAudio, 18, 8000, 1, CodecInvalid) \
XX(CelB, TrackVideo, 25, 90000, 1, CodecInvalid) \
XX(JPEG, TrackVideo, 26, 90000, 1, CodecInvalid) \
XX(nv, TrackVideo, 28, 90000, 1, CodecInvalid) \
XX(H261, TrackVideo, 31, 90000, 1, CodecInvalid) \
XX(MPV, TrackVideo, 32, 90000, 1, CodecInvalid) \
XX(MP2T, TrackVideo, 33, 90000, 1, CodecInvalid) \
XX(H263, TrackVideo, 34, 90000, 1, CodecInvalid) \
typedef enum {
#define ENUM_DEF(name, type, value, clock_rate, channel) PT_ ## name = value,
#define ENUM_DEF(name, type, value, clock_rate, channel, codec_id) PT_ ## name = value,
RTP_PT_MAP(ENUM_DEF)
#undef ENUM_DEF
PT_MAX = 128
@ -88,6 +88,7 @@ public:
static TrackType getTrackType(int pt);
static int getAudioChannel(int pt);
static const char *getName(int pt);
static CodecId getCodecId(int pt);
private:
RtpPayload() = delete;
~RtpPayload() = delete;