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

Squash: Merge SRS 4.0, regression test for RTMP.

This commit is contained in:
winlin 2021-10-12 08:36:24 +08:00
parent a81aa2edc5
commit b874d9c9ba
32 changed files with 9977 additions and 131 deletions

View file

@ -521,6 +521,32 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root)
srs_freep(conf);
continue;
}
// SRS3.0, change the forward.
// SRS1/2:
// vhost { rtc { aac; } }
// SRS3+:
// vhost { rtc { rtmp_to_rtc; } }
if (n == "rtc") {
SrsConfDirective* aac = conf->get("aac");
if (aac) {
string v = aac->arg0() == "transcode" ? "on" : "off";
conf->get_or_create("rtmp_to_rtc")->set_arg0(v);
conf->remove(aac); srs_freep(aac);
srs_warn("transform: vhost.rtc.aac to vhost.rtc.rtmp_to_rtc %s", v.c_str());
}
SrsConfDirective* bframe = conf->get("bframe");
if (bframe) {
string v = bframe->arg0() == "keep" ? "on" : "off";
conf->get_or_create("keep_bframe")->set_arg0(v);
conf->remove(bframe); srs_freep(bframe);
srs_warn("transform: vhost.rtc.bframe to vhost.rtc.keep_bframe %s", v.c_str());
}
++it;
continue;
}
++it;
}
@ -2782,7 +2808,7 @@ srs_error_t SrsConfig::check_normal_config()
if (m != "enabled" && m != "nack" && m != "twcc" && m != "nack_no_copy"
&& m != "bframe" && m != "aac" && m != "stun_timeout" && m != "stun_strict_check"
&& m != "dtls_role" && m != "dtls_version" && m != "drop_for_pt" && m != "rtc_to_rtmp"
&& m != "pli_for_rtmp") {
&& m != "pli_for_rtmp" && m != "rtmp_to_rtc" && m != "keep_bframe") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.rtc.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
@ -3641,25 +3667,7 @@ bool SrsConfig::get_rtc_enabled(string vhost)
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_rtc_bframe_discard(string vhost)
{
static bool DEFAULT = true;
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("bframe");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0() != "keep";
}
bool SrsConfig::get_rtc_aac_discard(string vhost)
bool SrsConfig::get_rtc_keep_bframe(string vhost)
{
static bool DEFAULT = false;
@ -3669,12 +3677,30 @@ bool SrsConfig::get_rtc_aac_discard(string vhost)
return DEFAULT;
}
conf = conf->get("aac");
conf = conf->get("keep_bframe");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0() == "discard";
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_rtc_from_rtmp(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("rtmp_to_rtc");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
srs_utime_t SrsConfig::get_rtc_stun_timeout(string vhost)

View file

@ -481,8 +481,8 @@ private:
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);
bool get_rtc_keep_bframe(std::string vhost);
bool get_rtc_from_rtmp(std::string vhost);
srs_utime_t get_rtc_stun_timeout(std::string vhost);
bool get_rtc_stun_strict_check(std::string vhost);
std::string get_rtc_dtls_role(std::string vhost);

View file

@ -707,8 +707,8 @@ SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcSource* source)
source_ = source;
format = new SrsRtmpFormat();
codec_ = new SrsAudioTranscoder();
discard_aac = false;
discard_bframe = false;
rtmp_to_rtc = false;
keep_bframe = false;
merge_nalus = false;
meta = new SrsMetaCache();
audio_sequence = 0;
@ -743,22 +743,24 @@ srs_error_t SrsRtcFromRtmpBridger::initialize(SrsRequest* r)
srs_error_t err = srs_success;
req = r;
rtmp_to_rtc = _srs_config->get_rtc_from_rtmp(req->vhost);
if ((err = format->initialize()) != srs_success) {
return srs_error_wrap(err, "format initialize");
if (rtmp_to_rtc) {
if ((err = format->initialize()) != srs_success) {
return srs_error_wrap(err, "format initialize");
}
int bitrate = 48000; // The output bitrate in bps.
if ((err = codec_->initialize(SrsAudioCodecIdAAC, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate,
bitrate)) != srs_success) {
return srs_error_wrap(err, "init codec");
}
}
int bitrate = 48000; // The output bitrate in bps.
if ((err = codec_->initialize(SrsAudioCodecIdAAC, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate, bitrate)) != srs_success) {
return srs_error_wrap(err, "init codec");
}
// TODO: FIXME: Support reload.
discard_aac = _srs_config->get_rtc_aac_discard(req->vhost);
discard_bframe = _srs_config->get_rtc_bframe_discard(req->vhost);
keep_bframe = _srs_config->get_rtc_keep_bframe(req->vhost);
merge_nalus = _srs_config->get_rtc_server_merge_nalus();
srs_trace("RTC bridge from RTMP, discard_aac=%d, discard_bframe=%d, merge_nalus=%d",
discard_aac, discard_bframe, merge_nalus);
srs_trace("RTC bridge from RTMP, rtmp2rtc=%d, keep_bframe=%d, merge_nalus=%d",
rtmp_to_rtc, keep_bframe, merge_nalus);
return err;
}
@ -767,6 +769,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_publish()
{
srs_error_t err = srs_success;
if (!rtmp_to_rtc) {
return err;
}
// TODO: FIXME: Should sync with bridger?
if ((err = source_->on_publish()) != srs_success) {
return srs_error_wrap(err, "source publish");
@ -781,6 +787,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_publish()
void SrsRtcFromRtmpBridger::on_unpublish()
{
if (!rtmp_to_rtc) {
return;
}
// Reset the metadata cache, to make VLC happy when disable/enable stream.
// @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448
meta->update_previous_vsh();
@ -795,6 +805,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg)
{
srs_error_t err = srs_success;
if (!rtmp_to_rtc) {
return err;
}
// TODO: FIXME: Support parsing OPUS for RTC.
if ((err = format->on_audio(msg)) != srs_success) {
return srs_error_wrap(err, "format consume audio");
@ -813,7 +827,7 @@ srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg)
}
// When drop aac audio packet, never transcode.
if (discard_aac && acodec == SrsAudioCodecIdAAC) {
if (acodec != SrsAudioCodecIdAAC) {
return err;
}
@ -905,6 +919,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_video(SrsSharedPtrMessage* msg)
{
srs_error_t err = srs_success;
if (!rtmp_to_rtc) {
return err;
}
// cache the sequence header if h264
bool is_sequence_header = SrsFlvVideo::sh(msg->payload, msg->size);
if (is_sequence_header && (err = meta->update_vsh(msg)) != srs_success) {
@ -993,7 +1011,7 @@ srs_error_t SrsRtcFromRtmpBridger::filter(SrsSharedPtrMessage* msg, SrsFormat* f
// Because RTC does not support B-frame, so we will drop them.
// TODO: Drop B-frame in better way, which not cause picture corruption.
if (discard_bframe) {
if (!keep_bframe) {
if ((err = sample->parse_bframe()) != srs_success) {
return srs_error_wrap(err, "parse bframe");
}

View file

@ -254,9 +254,9 @@ private:
// The metadata cache.
SrsMetaCache* meta;
private:
bool discard_aac;
bool rtmp_to_rtc;
SrsAudioTranscoder* codec_;
bool discard_bframe;
bool keep_bframe;
bool merge_nalus;
uint16_t audio_sequence;
uint16_t video_sequence;

View file

@ -863,6 +863,7 @@ srs_error_t SrsRtmpConn::do_publishing(SrsLiveSource* source, SrsPublishRecvThre
SrsAutoFree(SrsPithyPrint, pprint);
// start isolate recv thread.
// TODO: FIXME: Pass the callback here.
if ((err = rtrd->start()) != srs_success) {
return srs_error_wrap(err, "rtmp: receive thread");
}

View file

@ -9,6 +9,6 @@
#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_REVISION 171
#define VERSION_REVISION 175
#endif

View file

@ -818,10 +818,6 @@ srs_error_t SrsFormat::avc_demux_sps_pps(SrsBuffer* stream)
if (!stream->require(sequenceParameterSetLength)) {
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode SPS data");
}
if (vcodec->sequenceParameterSetNALUnit.size() > 0) {
stream->skip(sequenceParameterSetLength);
continue;
}
if (sequenceParameterSetLength > 0) {
vcodec->sequenceParameterSetNALUnit.resize(sequenceParameterSetLength);
stream->read_bytes(&vcodec->sequenceParameterSetNALUnit[0], sequenceParameterSetLength);
@ -846,10 +842,6 @@ srs_error_t SrsFormat::avc_demux_sps_pps(SrsBuffer* stream)
if (!stream->require(pictureParameterSetLength)) {
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode PPS data");
}
if (vcodec->pictureParameterSetNALUnit.size() > 0) {
stream->skip(pictureParameterSetLength);
continue;
}
if (pictureParameterSetLength > 0) {
vcodec->pictureParameterSetNALUnit.resize(pictureParameterSetLength);
stream->read_bytes(&vcodec->pictureParameterSetNALUnit[0], pictureParameterSetLength);

View file

@ -3575,8 +3575,8 @@ VOID TEST(ConfigMainTest, CheckVhostConfig5)
EXPECT_FALSE(conf.get_http_api_crossdomain());
EXPECT_TRUE(conf.get_raw_api());
EXPECT_TRUE(conf.get_raw_api_allow_reload());
EXPECT_TRUE(conf.get_raw_api_allow_query());
EXPECT_TRUE(conf.get_raw_api_allow_update());
EXPECT_FALSE(conf.get_raw_api_allow_query()); // Always disabled
EXPECT_FALSE(conf.get_raw_api_allow_update()); // Always disabled
}
if (true) {