1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #1638, #307, config to discard aac for rtc

This commit is contained in:
winlin 2020-03-22 08:28:51 +08:00
parent e1fe2d1c1d
commit 2da4e0a43e
5 changed files with 37 additions and 2 deletions

View file

@ -335,6 +335,11 @@ vhost rtc.vhost.srs.com {
# discard Discard bframe, maybe cause browser with little problems.
# default: keep
bframe discard;
# The strategy for aac audio.
# transcode Transcode aac to opus.
# discard Discard aac audio packet.
# default: transcode
aac transcode;
}
}

View file

@ -3822,8 +3822,8 @@ srs_error_t SrsConfig::check_normal_config()
} else if (n == "rtc") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "enabled" && m != "bframe") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.bandcheck.%s of %s", m.c_str(), vhost->arg0().c_str());
if (m != "enabled" && m != "bframe" && m != "aac") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.rtc.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
}
@ -4381,6 +4381,24 @@ bool SrsConfig::get_rtc_bframe_discard(string vhost)
return conf->arg0() == "discard";
}
bool SrsConfig::get_rtc_aac_discard(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("aac");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0() == "discard";
}
SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
{
srs_assert(root);

View file

@ -509,6 +509,7 @@ public:
SrsConfDirective* get_rtc(std::string vhost);
bool get_rtc_enabled(std::string vhost);
bool get_rtc_bframe_discard(std::string vhost);
bool get_rtc_aac_discard(std::string vhost);
// vhost specified section
public:

View file

@ -430,6 +430,8 @@ SrsRtc::SrsRtc()
enabled = false;
disposable = false;
last_update_time = 0;
discard_aac = false;
}
SrsRtc::~SrsRtc()
@ -461,6 +463,8 @@ srs_error_t SrsRtc::initialize(SrsOriginHub* h, SrsRequest* r)
rtp_h264_muxer = new SrsRtpMuxer();
rtp_h264_muxer->discard_bframe = _srs_config->get_rtc_bframe_discard(req->vhost);
// TODO: FIXME: Support reload and log it.
discard_aac = _srs_config->get_rtc_aac_discard(req->vhost);
rtp_opus_muxer = new SrsRtpOpusMuxer();
if (rtp_opus_muxer) {
@ -528,6 +532,11 @@ srs_error_t SrsRtc::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma
return err;
}
// When drop aac audio packet, never transcode.
if (discard_aac && acodec == SrsAudioCodecIdAAC) {
return err;
}
// ignore sequence header
srs_assert(format->audio);

View file

@ -82,6 +82,7 @@ private:
srs_error_t packet_stap_a(const std::string &sps, const std::string& pps, SrsSharedPtrMessage* shared_frame, std::vector<SrsRtpSharedPacket*>& rtp_packet_vec);
};
// TODO: FIXME: It's not a muxer, but a transcoder.
class SrsRtpOpusMuxer
{
private:
@ -105,6 +106,7 @@ private:
SrsRequest* req;
bool enabled;
bool disposable;
bool discard_aac;
srs_utime_t last_update_time;
SrsRtpMuxer* rtp_h264_muxer;
SrsRtpOpusMuxer* rtp_opus_muxer;