Commit 3efda8fd by xiongziliang

根据playload type生成track

parent bacf8f10
...@@ -84,6 +84,14 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) { ...@@ -84,6 +84,14 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
return std::make_shared<H265Track>(vps,sps,pps,0,0,0); 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(); WarnL << "暂不支持该sdp:" << track->getName();
return nullptr; return nullptr;
} }
......
...@@ -16,7 +16,7 @@ namespace mediakit{ ...@@ -16,7 +16,7 @@ namespace mediakit{
int RtpPayload::getClockRate(int pt){ int RtpPayload::getClockRate(int pt){
switch (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) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: return 90000; default: return 90000;
...@@ -25,7 +25,7 @@ int RtpPayload::getClockRate(int pt){ ...@@ -25,7 +25,7 @@ int RtpPayload::getClockRate(int pt){
TrackType RtpPayload::getTrackType(int pt){ TrackType RtpPayload::getTrackType(int pt){
switch (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) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: return TrackInvalid; default: return TrackInvalid;
...@@ -34,7 +34,7 @@ TrackType RtpPayload::getTrackType(int pt){ ...@@ -34,7 +34,7 @@ TrackType RtpPayload::getTrackType(int pt){
int RtpPayload::getAudioChannel(int pt){ int RtpPayload::getAudioChannel(int pt){
switch (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) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: return 1; default: return 1;
...@@ -43,13 +43,22 @@ int RtpPayload::getAudioChannel(int pt){ ...@@ -43,13 +43,22 @@ int RtpPayload::getAudioChannel(int pt){
const char * RtpPayload::getName(int pt){ const char * RtpPayload::getName(int pt){
switch (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) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: return "unknown payload type"; 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){ static void getAttrSdp(const map<string, string> &attr, _StrPrinter &printer){
const map<string, string>::value_type *ptr = nullptr; const map<string, string>::value_type *ptr = nullptr;
for(auto &pr : attr){ for(auto &pr : attr){
...@@ -70,7 +79,7 @@ static void getAttrSdp(const map<string, string> &attr, _StrPrinter &printer){ ...@@ -70,7 +79,7 @@ static void getAttrSdp(const map<string, string> &attr, _StrPrinter &printer){
string SdpTrack::getName() const{ string SdpTrack::getName() const{
switch (_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) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: return _codec; default: return _codec;
......
...@@ -34,33 +34,33 @@ typedef enum { ...@@ -34,33 +34,33 @@ typedef enum {
} eRtpType; } eRtpType;
#define RTP_PT_MAP(XX) \ #define RTP_PT_MAP(XX) \
XX(PCMU, TrackAudio, 0, 8000, 1) \ XX(PCMU, TrackAudio, 0, 8000, 1, CodecG711U) \
XX(GSM, TrackAudio , 3, 8000, 1) \ XX(GSM, TrackAudio , 3, 8000, 1, CodecInvalid) \
XX(G723, TrackAudio, 4, 8000, 1) \ XX(G723, TrackAudio, 4, 8000, 1, CodecInvalid) \
XX(DVI4_8000, TrackAudio, 5, 8000, 1) \ XX(DVI4_8000, TrackAudio, 5, 8000, 1, CodecInvalid) \
XX(DVI4_16000, TrackAudio, 6, 16000, 1) \ XX(DVI4_16000, TrackAudio, 6, 16000, 1, CodecInvalid) \
XX(LPC, TrackAudio, 7, 8000, 1) \ XX(LPC, TrackAudio, 7, 8000, 1, CodecInvalid) \
XX(PCMA, TrackAudio, 8, 8000, 1) \ XX(PCMA, TrackAudio, 8, 8000, 1, CodecG711A) \
XX(G722, TrackAudio, 9, 8000, 1) \ XX(G722, TrackAudio, 9, 8000, 1, CodecInvalid) \
XX(L16_Stereo, TrackAudio, 10, 44100, 2) \ XX(L16_Stereo, TrackAudio, 10, 44100, 2, CodecInvalid) \
XX(L16_Mono, TrackAudio, 11, 44100, 1) \ XX(L16_Mono, TrackAudio, 11, 44100, 1, CodecInvalid) \
XX(QCELP, TrackAudio, 12, 8000, 1) \ XX(QCELP, TrackAudio, 12, 8000, 1, CodecInvalid) \
XX(CN, TrackAudio, 13, 8000, 1) \ XX(CN, TrackAudio, 13, 8000, 1, CodecInvalid) \
XX(MPA, TrackAudio, 14, 90000, 1) \ XX(MPA, TrackAudio, 14, 90000, 1, CodecInvalid) \
XX(G728, TrackAudio, 15, 8000, 1) \ XX(G728, TrackAudio, 15, 8000, 1, CodecInvalid) \
XX(DVI4_11025, TrackAudio, 16, 11025, 1) \ XX(DVI4_11025, TrackAudio, 16, 11025, 1, CodecInvalid) \
XX(DVI4_22050, TrackAudio, 17, 22050, 1) \ XX(DVI4_22050, TrackAudio, 17, 22050, 1, CodecInvalid) \
XX(G729, TrackAudio, 18, 8000, 1) \ XX(G729, TrackAudio, 18, 8000, 1, CodecInvalid) \
XX(CelB, TrackVideo, 25, 90000, 1) \ XX(CelB, TrackVideo, 25, 90000, 1, CodecInvalid) \
XX(JPEG, TrackVideo, 26, 90000, 1) \ XX(JPEG, TrackVideo, 26, 90000, 1, CodecInvalid) \
XX(nv, TrackVideo, 28, 90000, 1) \ XX(nv, TrackVideo, 28, 90000, 1, CodecInvalid) \
XX(H261, TrackVideo, 31, 90000, 1) \ XX(H261, TrackVideo, 31, 90000, 1, CodecInvalid) \
XX(MPV, TrackVideo, 32, 90000, 1) \ XX(MPV, TrackVideo, 32, 90000, 1, CodecInvalid) \
XX(MP2T, TrackVideo, 33, 90000, 1) \ XX(MP2T, TrackVideo, 33, 90000, 1, CodecInvalid) \
XX(H263, TrackVideo, 34, 90000, 1) \ XX(H263, TrackVideo, 34, 90000, 1, CodecInvalid) \
typedef enum { 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) RTP_PT_MAP(ENUM_DEF)
#undef ENUM_DEF #undef ENUM_DEF
PT_MAX = 128 PT_MAX = 128
...@@ -88,6 +88,7 @@ public: ...@@ -88,6 +88,7 @@ public:
static TrackType getTrackType(int pt); static TrackType getTrackType(int pt);
static int getAudioChannel(int pt); static int getAudioChannel(int pt);
static const char *getName(int pt); static const char *getName(int pt);
static CodecId getCodecId(int pt);
private: private:
RtpPayload() = delete; RtpPayload() = delete;
~RtpPayload() = delete; ~RtpPayload() = delete;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论