Commit 33d2e713 by ziyue

合并代码,去除冗余代码

parents 1978748f a328520c
......@@ -108,10 +108,17 @@ void Process::run(const string &cmd, const string &log_file_tmp) {
}
fprintf(stderr, "\r\n\r\n#### pid=%d,cmd=%s #####\r\n\r\n", getpid(), cmd.data());
#ifndef ANDROID
//关闭父进程继承的fd
for (int i = 3; i < getdtablesize(); i++) {
::close(i);
}
#else
//关闭父进程继承的fd
for (int i = 3; i < 1024; i++) {
::close(i);
}
#endif
auto params = split(cmd, " ");
// memory leak in child process, it's ok.
......
......@@ -22,7 +22,7 @@ namespace mediakit{
class G711Track : public AudioTrackImp{
public:
using Ptr = std::shared_ptr<G711Track>;
G711Track(CodecId codecId,int sample_rate, int channels, int sample_bit) : AudioTrackImp(codecId,sample_rate,channels,sample_bit){}
G711Track(CodecId codecId, int sample_rate, int channels, int sample_bit) : AudioTrackImp(codecId, 8000, 1, 16) {}
private:
Sdp::Ptr getSdp() override;
......
......@@ -415,17 +415,11 @@ void RtmpSession::onCmd_pause(AMFDecoder &dec) {
}
void RtmpSession::setMetaData(AMFDecoder &dec) {
if (!_publisher_src) {
throw std::runtime_error("not a publisher");
}
std::string type = dec.load<std::string>();
if (type != "onMetaData") {
throw std::runtime_error("can only set metadata");
}
auto metadata = dec.load<AMFValue>();
// dumpMetadata(metadata);
_publisher_src->setMetaData(metadata);
_set_meta_data = true;
_publisher_metadata = dec.load<AMFValue>();
}
void RtmpSession::onProcessCmd(AMFDecoder &dec) {
......@@ -478,7 +472,8 @@ void RtmpSession::onRtmpChunk(RtmpPacket::Ptr packet) {
case MSG_AUDIO:
case MSG_VIDEO: {
if (!_publisher_src) {
throw std::runtime_error("Not a rtmp publisher!");
WarnL << "Not a rtmp publisher!";
return;
}
GET_CONFIG(bool, rtmp_modify_stamp, Rtmp::kModifyStamp);
if (rtmp_modify_stamp) {
......@@ -487,9 +482,9 @@ void RtmpSession::onRtmpChunk(RtmpPacket::Ptr packet) {
chunk_data.time_stamp = (uint32_t)dts_out;
}
if (!_set_meta_data && !chunk_data.isCfgFrame()) {
if (!_set_meta_data) {
_set_meta_data = true;
_publisher_src->setMetaData(TitleMeta().getMetadata());
_publisher_src->setMetaData(_publisher_metadata ? _publisher_metadata : TitleMeta().getMetadata());
}
_publisher_src->onWrite(std::move(packet));
break;
......
......@@ -98,8 +98,8 @@ private:
//数据接收超时计时器
Ticker _ticker;
MediaInfo _media_info;
std::weak_ptr<RtmpMediaSource> _player_src;
AMFValue _publisher_metadata;
std::shared_ptr<RtmpMediaSourceImp> _publisher_src;
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
};
......
......@@ -145,6 +145,9 @@ bool RtpProcess::alive() {
void RtpProcess::setStopCheckRtp(bool is_check){
_stop_rtp_check = is_check;
if (!is_check) {
_last_frame_time.resetTime();
}
}
void RtpProcess::onDetach() {
......
......@@ -1150,11 +1150,9 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
rtcp_mux = true;
rtcp_rsize = false;
group_bundle = true;
unified_plan = false;
support_rtx = true;
support_red = false;
support_ulpfec = false;
support_simulcast = false;
ice_lite = true;
ice_trickle = true;
ice_renomination = false;
......@@ -1226,26 +1224,19 @@ void RtcConfigure::addCandidate(const SdpAttrCandidate &candidate, TrackType typ
}
}
shared_ptr<RtcSession> RtcConfigure::createOffer(){
shared_ptr<RtcSession> ret = std::make_shared<RtcSession>();
ret->version = 0;
ret->origin.parse("- 0 0 IN IP4 0.0.0.0");
ret->session_name = "zlmediakit_webrtc_session";
ret->session_info = "zlmediakit_webrtc_session";
ret->connection.parse("IN IP4 0.0.0.0");
ret->msid_semantic.parse("WMS *");
return nullptr;
}
shared_ptr<RtcSession> RtcConfigure::createAnswer(const RtcSession &offer){
shared_ptr<RtcSession> ret = std::make_shared<RtcSession>();
ret->version = offer.version;
//todo 此处设置会话id与会话地址,貌似没什么作用
ret->origin = offer.origin;
ret->session_name = offer.session_name;
ret->msid_semantic = offer.msid_semantic;
matchMedia(ret, TrackAudio, offer.media, audio);
matchMedia(ret, TrackVideo, offer.media, video);
matchMedia(ret, TrackApplication, offer.media, application);
if (ret->media.empty()) {
throw std::invalid_argument("生成的answer sdp中媒体个数为0");
}
return ret;
}
......@@ -1259,7 +1250,7 @@ void RtcConfigure::matchMedia(shared_ptr<RtcSession> &ret, TrackType type, const
continue;
}
if (offer_media.ice_lite && configure.ice_lite) {
WarnL << "offer sdp开启了ice_lite模式,但是answer sdp配置为不支持";
WarnL << "answer sdp配置为ice_lite模式,与offer sdp中的ice_lite模式冲突";
continue;
}
const RtcCodecPlan *offer_plan_ptr = nullptr;
......@@ -1283,16 +1274,21 @@ void RtcConfigure::matchMedia(shared_ptr<RtcSession> &ret, TrackType type, const
answer_media.type = offer_media.type;
answer_media.mid = offer_media.mid;
answer_media.proto = offer_media.proto;
//todo(此处设置rtp端口,貌似没什么作用)
answer_media.port = offer_media.port;
//todo(此处设置rtp的ip地址,貌似没什么作用)
answer_media.addr = offer_media.addr;
//todo(此处设置rtcp地址,貌似没什么作用)
answer_media.rtcp_addr = offer_media.rtcp_addr;
answer_media.rtcp_mux = offer_media.rtcp_mux && configure.rtcp_mux;
answer_media.rtcp_rsize = offer_media.rtcp_rsize && configure.rtcp_rsize;
answer_media.rtcp_addr = offer_media.rtcp_addr;
answer_media.ice_trickle = offer_media.ice_trickle && configure.ice_trickle;
answer_media.ice_renomination = offer_media.ice_renomination && configure.ice_renomination;
answer_media.ice_ufrag = configure.ice_ufrag;
answer_media.ice_pwd = configure.ice_pwd;
answer_media.fingerprint = configure.fingerprint;
answer_media.ice_lite = configure.ice_lite;
answer_media.candidate = configure.candidate;
switch (offer_media.role) {
case DtlsRole::actpass :
case DtlsRole::active : {
......@@ -1332,7 +1328,11 @@ void RtcConfigure::matchMedia(shared_ptr<RtcSession> &ret, TrackType type, const
}
default: continue;
}
//添加媒体plan
answer_media.plan.emplace_back(*offer_plan_ptr);
//添加rtx,red,ulpfec plan
if (configure.support_red || configure.support_rtx || configure.support_ulpfec) {
for (auto &plan : offer_media.plan) {
if (!strcasecmp(plan.codec.data(), "rtx")) {
......@@ -1382,6 +1382,8 @@ void RtcConfigure::matchMedia(shared_ptr<RtcSession> &ret, TrackType type, const
offer_rtcp_fb.emplace_back(fp);
}
}
//修改为我们支持的rtcp-fb类型
answer_media.plan[0].rtcp_fb.swap(offer_rtcp_fb);
ret->media.emplace_back(answer_media);
return;
......
......@@ -599,7 +599,6 @@ public:
RtcSSRC rtx_ssrc;
//////// simulcast ////////
bool simulcast{false};
RtcSSRC rtp_ssrc_low;
RtcSSRC rtp_ssrc_mid;
RtcSSRC rtp_ssrc_high;
......@@ -663,12 +662,9 @@ public:
bool rtcp_mux;
bool rtcp_rsize;
bool group_bundle;
bool unified_plan;
bool support_rtx;
bool support_red;
bool support_ulpfec;
bool support_simulcast;
bool ice_lite;
bool ice_trickle;
bool ice_renomination;
......@@ -696,7 +692,6 @@ public:
const SdpAttrFingerprint &fingerprint);
void addCandidate(const SdpAttrCandidate &candidate, TrackType type = TrackInvalid);
shared_ptr<RtcSession> createOffer();
shared_ptr<RtcSession> createAnswer(const RtcSession &offer);
private:
......
......@@ -88,6 +88,17 @@ std::string WebRtcTransport::getAnswerSdp(const string &offer){
RtcConfigure configure;
configure.setDefaultSetting(ice_server_->GetUsernameFragment(), ice_server_->GetPassword(), RtpDirection::recvonly, fingerprint);
SdpAttrCandidate candidate;
candidate.foundation = "udpcandidate";
candidate.component = 1;
candidate.transport = "udp";
candidate.priority = getSSRC();
candidate.address = getIP();
candidate.port = getPort();
candidate.type = "host";
configure.addCandidate(candidate);
_answer_sdp = configure.createAnswer(*_offer_sdp);
//设置远端dtls签名
......@@ -104,23 +115,6 @@ std::string WebRtcTransport::getAnswerSdp(const string &offer){
throw std::invalid_argument("支持group BUNDLE模式");
}
SdpAttrCandidate candidate;
candidate.foundation = "udpcandidate";
candidate.component = 1;
candidate.transport = "udp";
candidate.priority = getSSRC();
candidate.address = getIP();
candidate.port = getPort();
candidate.type = "host";
for (auto &m :_answer_sdp->media) {
m.candidate.emplace_back(candidate);
m.port = getPort();
m.rtcp_addr.address = getIP();
m.rtcp_addr.port = getPort();
m.addr.address = getIP();
}
_answer_sdp->connection.address = getIP();
auto str = _answer_sdp->toString();
InfoL << "\r\n" << str;
return str;
......@@ -156,12 +150,10 @@ void WebRtcTransport::OnInputDataPacket(char *buf, size_t len, RTC::TransportTup
}
if (is_rtp(buf)) {
RtpHeader *header = (RtpHeader *) buf;
InfoL << "rtp:" << header->dumpString(len);
return;
}
if (is_rtcp(buf)) {
RtcpHeader *header = (RtcpHeader *) buf;
// InfoL << "rtcp:" << header->dumpString();
return;
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论