mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
sdp相关的代码移动到主目录
This commit is contained in:
parent
a3d0d3b7ad
commit
a7a94f0885
@ -205,7 +205,7 @@ public:
|
||||
if (bitrate) {
|
||||
_printer << "b=AS:" << bitrate << "\r\n";
|
||||
}
|
||||
_printer << "a=rtpmap:" << payload_type << " MPEG4-GENERIC/" << sample_rate << "/" << channels << "\r\n";
|
||||
_printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << sample_rate << "/" << channels << "\r\n";
|
||||
|
||||
string configStr;
|
||||
char buf[4] = {0};
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "Frame.h"
|
||||
#include "H264.h"
|
||||
#include "H265.h"
|
||||
|
||||
#include "Common/Parser.h"
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
@ -106,22 +106,10 @@ Frame::Ptr Frame::getCacheAbleFrame(const Frame::Ptr &frame){
|
||||
return std::make_shared<FrameCacheAble>(frame);
|
||||
}
|
||||
|
||||
#define SWITCH_CASE(codec_id) case codec_id : return #codec_id
|
||||
const char *getCodecName(CodecId codecId) {
|
||||
switch (codecId) {
|
||||
SWITCH_CASE(CodecH264);
|
||||
SWITCH_CASE(CodecH265);
|
||||
SWITCH_CASE(CodecAAC);
|
||||
SWITCH_CASE(CodecG711A);
|
||||
SWITCH_CASE(CodecG711U);
|
||||
SWITCH_CASE(CodecOpus);
|
||||
SWITCH_CASE(CodecL16);
|
||||
default : return "unknown codec";
|
||||
}
|
||||
}
|
||||
|
||||
TrackType getTrackType(CodecId codecId){
|
||||
switch (codecId){
|
||||
case CodecVP8:
|
||||
case CodecVP9:
|
||||
case CodecH264:
|
||||
case CodecH265: return TrackVideo;
|
||||
case CodecAAC:
|
||||
@ -133,6 +121,58 @@ TrackType getTrackType(CodecId codecId){
|
||||
}
|
||||
}
|
||||
|
||||
const char* getCodecName(CodecId codec){
|
||||
switch (codec) {
|
||||
case CodecH264 : return "H264";
|
||||
case CodecH265 : return "H265";
|
||||
case CodecAAC : return "mpeg4-generic";
|
||||
case CodecG711A : return "PCMA";
|
||||
case CodecG711U : return "PCMU";
|
||||
case CodecOpus : return "opus";
|
||||
case CodecVP8 : return "VP8";
|
||||
case CodecVP9 : return "VP9";
|
||||
case CodecL16 : return "L16";
|
||||
default: return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
static map<string, CodecId, StrCaseCompare> codec_map = {
|
||||
{"H264", CodecH264},
|
||||
{"H265", CodecH265},
|
||||
{"mpeg4-generic", CodecAAC},
|
||||
{"PCMA", CodecG711A},
|
||||
{"PCMU", CodecG711U},
|
||||
{"opus", CodecOpus},
|
||||
{"VP8", CodecVP8},
|
||||
{"VP9", CodecVP9},
|
||||
{"L16", CodecL16}
|
||||
};
|
||||
|
||||
CodecId getCodecId(const string &str){
|
||||
auto it = codec_map.find(str);
|
||||
return it == codec_map.end() ? CodecInvalid : it->second;
|
||||
}
|
||||
|
||||
static map<string, TrackType, StrCaseCompare> track_str_map = {
|
||||
{"video", TrackVideo},
|
||||
{"audio", TrackAudio},
|
||||
{"application", TrackApplication}
|
||||
};
|
||||
|
||||
TrackType getTrackType(const string &str) {
|
||||
auto it = track_str_map.find(str);
|
||||
return it == track_str_map.end() ? TrackInvalid : it->second;
|
||||
}
|
||||
|
||||
const char* getTrackString(TrackType type){
|
||||
switch (type) {
|
||||
case TrackVideo : return "video";
|
||||
case TrackAudio : return "audio";
|
||||
case TrackApplication : return "application";
|
||||
default: return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
const char *CodecInfo::getCodecName() {
|
||||
return mediakit::getCodecName(getCodecId());
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ typedef enum {
|
||||
CodecG711U,
|
||||
CodecOpus,
|
||||
CodecL16,
|
||||
CodecVP8,
|
||||
CodecVP9,
|
||||
CodecMax = 0x7FFF
|
||||
} CodecId;
|
||||
|
||||
@ -42,6 +44,23 @@ typedef enum {
|
||||
TrackMax = 4
|
||||
} TrackType;
|
||||
|
||||
/**
|
||||
* 字符串转媒体类型转
|
||||
*/
|
||||
TrackType getTrackType(const string &str);
|
||||
|
||||
/**
|
||||
* 媒体类型转字符串
|
||||
*/
|
||||
const char* getTrackString(TrackType type);
|
||||
|
||||
/**
|
||||
* 根据SDP中描述获取codec_id
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
CodecId getCodecId(const string &str);
|
||||
|
||||
/**
|
||||
* 获取编码器名称
|
||||
*/
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
if (bitrate) {
|
||||
_printer << "b=AS:" << bitrate << "\r\n";
|
||||
}
|
||||
_printer << "a=rtpmap:" << payload_type << (codecId == CodecG711A ? " PCMA/" : " PCMU/") << sample_rate << "/" << channels << "\r\n";
|
||||
_printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << sample_rate << "/" << channels << "\r\n";
|
||||
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ public:
|
||||
if (bitrate) {
|
||||
_printer << "b=AS:" << bitrate << "\r\n";
|
||||
}
|
||||
_printer << "a=rtpmap:" << payload_type << " H264/" << 90000 << "\r\n";
|
||||
_printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << 90000 << "\r\n";
|
||||
_printer << "a=fmtp:" << payload_type << " packetization-mode=1; profile-level-id=";
|
||||
|
||||
char strTemp[1024];
|
||||
|
@ -252,7 +252,7 @@ public:
|
||||
if (bitrate) {
|
||||
_printer << "b=AS:" << bitrate << "\r\n";
|
||||
}
|
||||
_printer << "a=rtpmap:" << payload_type << " H265/" << 90000 << "\r\n";
|
||||
_printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << 90000 << "\r\n";
|
||||
_printer << "a=fmtp:" << payload_type << " ";
|
||||
_printer << "sprop-vps=";
|
||||
_printer << encodeBase64(strVPS) << "; ";
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
if (bitrate) {
|
||||
_printer << "b=AS:" << bitrate << "\r\n";
|
||||
}
|
||||
_printer << "a=rtpmap:" << payload_type << " L16/" << sample_rate << "/" << channels << "\r\n";
|
||||
_printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << sample_rate << "/" << channels << "\r\n";
|
||||
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
if (bitrate) {
|
||||
_printer << "b=AS:" << bitrate << "\r\n";
|
||||
}
|
||||
_printer << "a=rtpmap:" << payload_type << " opus/" << sample_rate << "/" << channels << "\r\n";
|
||||
_printer << "a=rtpmap:" << payload_type << " " << getCodecName() << "/" << sample_rate << "/" << channels << "\r\n";
|
||||
_printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
|
||||
}
|
||||
|
||||
|
@ -93,26 +93,6 @@ static bool registerAllItem(){
|
||||
return true;
|
||||
}
|
||||
|
||||
static map<string, TrackType, StrCaseCompare> track_str_map = {
|
||||
{"video", TrackVideo},
|
||||
{"audio", TrackAudio},
|
||||
{"application", TrackApplication}
|
||||
};
|
||||
|
||||
TrackType getTrackType(const string &str) {
|
||||
auto it = track_str_map.find(str);
|
||||
return it == track_str_map.end() ? TrackInvalid : it->second;
|
||||
}
|
||||
|
||||
const char* getTrackString(TrackType type){
|
||||
switch (type) {
|
||||
case TrackVideo : return "video";
|
||||
case TrackAudio : return "audio";
|
||||
case TrackApplication : return "application";
|
||||
default: return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
static map<string, DtlsRole, StrCaseCompare> dtls_role_map = {
|
||||
{"active", DtlsRole::active},
|
||||
{"passive", DtlsRole::passive},
|
||||
@ -1059,6 +1039,18 @@ const RtcCodecPlan *RtcMedia::getPlan(const char *codec) const{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const RtcCodecPlan *RtcMedia::getRelatedRtxPlan(uint8_t pt) const{
|
||||
for (auto &item : plan) {
|
||||
if (strcasecmp(item.codec.data(), "rtx") == 0) {
|
||||
auto apt = atoi(item.getFmtp("apt").data());
|
||||
if (pt == apt) {
|
||||
return &item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RtcMedia::checkValid() const{
|
||||
CHECK(type != TrackInvalid);
|
||||
CHECK(!mid.empty());
|
||||
@ -1071,9 +1063,6 @@ void RtcMedia::checkValid() const{
|
||||
if (rtx_plan) {
|
||||
//开启rtx后必须指定rtx_ssrc
|
||||
CHECK(!rtx_ssrc.empty() || !send_rtp);
|
||||
auto apt = atoi(rtx_plan->getFmtp("apt").data());
|
||||
//开启rtx后必须指定其关联的其他的plan
|
||||
CHECK(getPlan(apt));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,8 +72,6 @@ enum class SdpType {
|
||||
answer
|
||||
};
|
||||
|
||||
TrackType getTrackType(const string &str);
|
||||
const char* getTrackString(TrackType type);
|
||||
DtlsRole getDtlsRole(const string &str);
|
||||
const char* getDtlsRoleString(DtlsRole role);
|
||||
RtpDirection getRtpDirection(const string &str);
|
||||
@ -591,6 +589,7 @@ public:
|
||||
void checkValid() const;
|
||||
const RtcCodecPlan *getPlan(uint8_t pt) const;
|
||||
const RtcCodecPlan *getPlan(const char *codec) const;
|
||||
const RtcCodecPlan *getRelatedRtxPlan(uint8_t pt) const;
|
||||
};
|
||||
|
||||
class RtcSession{
|
||||
|
Loading…
Reference in New Issue
Block a user