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

Fix #1405: Support guessing IBMF first. v5.0.58

This commit is contained in:
winlin 2022-09-01 19:28:16 +08:00
parent e027d28c4d
commit 783aea7ac3
10 changed files with 81 additions and 25 deletions

View file

@ -1049,6 +1049,9 @@ vhost publish.srs.com {
# @remark If disabled, HLS might never update the sps/pps, it depends on this.
# default: on
parse_sps on;
# When parsing SPS/PPS, whether try ANNEXB first. If not, try IBMF first, then ANNEXB.
# default: on
try_annexb_first on;
}
}

View file

@ -7,6 +7,7 @@ The changelog for SRS.
## SRS 5.0 Changelog
* v5.0, 2022-09-01, Fix [#1405](https://github.com/ossrs/srs/issues/1405): Support guessing IBMF first. v5.0.58
* v5.0, 2022-09-01, ST: Define and use a new jmpbuf. v5.0.57
* v5.0, 2022-08-31, Fix URL parsing bug for `__defaultVhost__`. v5.0.56
* v5.0, 2022-08-30, Fix [#2837](https://github.com/ossrs/srs/issues/2837): Callback: Support stream_url and stream_id. v5.0.55

View file

@ -2499,7 +2499,8 @@ srs_error_t SrsConfig::check_normal_config()
} else if (n == "publish") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "mr" && m != "mr_latency" && m != "firstpkt_timeout" && m != "normal_timeout" && m != "parse_sps") {
if (m != "mr" && m != "mr_latency" && m != "firstpkt_timeout" && m != "normal_timeout"
&& m != "parse_sps" && m != "try_annexb_first") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.publish.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
@ -4399,6 +4400,29 @@ bool SrsConfig::get_parse_sps(string vhost)
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
bool SrsConfig::try_annexb_first(string vhost)
{
static bool DEFAULT = true;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("publish");
if (!conf) {
return DEFAULT;
}
conf = conf->get("try_annexb_first");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
bool SrsConfig::get_mr_enabled(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);

View file

@ -593,6 +593,8 @@ public:
virtual int get_chunk_size(std::string vhost);
// Whether parse the sps when publish stream to SRS.
virtual bool get_parse_sps(std::string vhost);
// Whether try ANNEXB first when parsing SPS/PPS.
virtual bool try_annexb_first(std::string vhost);
// Whether mr is enabled for vhost.
// @param vhost, the vhost to get the mr.
virtual bool get_mr_enabled(std::string vhost);

View file

@ -752,6 +752,9 @@ srs_error_t SrsRtcFromRtmpBridge::initialize(SrsRequest* r)
return srs_error_wrap(err, "format initialize");
}
// Setup the SPS/PPS parsing strategy.
format->try_annexb_first = _srs_config->try_annexb_first(r->vhost);
int bitrate = 48000; // The output bitrate in bps.
if ((err = codec_->initialize(SrsAudioCodecIdAAC, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate,
bitrate)) != srs_success) {
@ -1309,6 +1312,9 @@ srs_error_t SrsRtmpFromRtcBridge::initialize(SrsRequest* r)
return srs_error_wrap(err, "format initialize");
}
// Setup the SPS/PPS parsing strategy.
format->try_annexb_first = _srs_config->try_annexb_first(r->vhost);
return err;
}

View file

@ -859,6 +859,9 @@ srs_error_t SrsOriginHub::initialize(SrsLiveSource* s, SrsRequest* r)
return srs_error_wrap(err, "format initialize");
}
// Setup the SPS/PPS parsing strategy.
format->try_annexb_first = _srs_config->try_annexb_first(r->vhost);
if ((err = hls->initialize(this, req_)) != srs_success) {
return srs_error_wrap(err, "hls initialize");
}

View file

@ -9,6 +9,6 @@
#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 57
#define VERSION_REVISION 58
#endif

View file

@ -572,6 +572,7 @@ SrsFormat::SrsFormat()
audio = NULL;
video = NULL;
avc_parse_sps = true;
try_annexb_first = true;
raw = NULL;
nb_raw = 0;
}
@ -1138,23 +1139,34 @@ srs_error_t SrsFormat::video_nalu_demux(SrsBuffer* stream)
// guess for the first time.
if (vcodec->payload_format == SrsAvcPayloadFormatGuess) {
// One or more NALUs (Full frames are required)
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
if ((err = avc_demux_annexb_format(stream)) != srs_success) {
// stop try when system error.
if (srs_error_code(err) != ERROR_HLS_AVC_TRY_OTHERS) {
return srs_error_wrap(err, "avc demux for annexb");
}
srs_freep(err);
if (try_annexb_first) {
// One or more NALUs (Full frames are required)
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
if ((err = avc_demux_annexb_format(stream)) != srs_success) {
srs_freep(err);
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
if ((err = avc_demux_ibmf_format(stream)) != srs_success) {
return srs_error_wrap(err, "avc demux ibmf");
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
if ((err = avc_demux_ibmf_format(stream)) != srs_success) {
return srs_error_wrap(err, "avc demux ibmf");
} else {
vcodec->payload_format = SrsAvcPayloadFormatIbmf;
}
} else {
vcodec->payload_format = SrsAvcPayloadFormatIbmf;
vcodec->payload_format = SrsAvcPayloadFormatAnnexb;
}
} else {
vcodec->payload_format = SrsAvcPayloadFormatAnnexb;
// One or more NALUs (Full frames are required)
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
if ((err = avc_demux_ibmf_format(stream)) == srs_success) {
vcodec->payload_format = SrsAvcPayloadFormatIbmf;
} else {
srs_freep(err);
if ((err = avc_demux_annexb_format(stream)) == srs_success) {
vcodec->payload_format = SrsAvcPayloadFormatAnnexb;
} else {
return srs_error_wrap(err, "avc demux annexb");
}
}
}
} else if (vcodec->payload_format == SrsAvcPayloadFormatIbmf) {
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
@ -1165,10 +1177,6 @@ srs_error_t SrsFormat::video_nalu_demux(SrsBuffer* stream)
// One or more NALUs (Full frames are required)
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
if ((err = avc_demux_annexb_format(stream)) != srs_success) {
// ok, we guess out the payload is annexb, but maybe changed to ibmf.
if (srs_error_code(err) != ERROR_HLS_AVC_TRY_OTHERS) {
return srs_error_wrap(err, "avc demux annexb");
}
srs_freep(err);
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20

View file

@ -724,6 +724,8 @@ public:
// for sequence header, whether parse the h.264 sps.
// TODO: FIXME: Refine it.
bool avc_parse_sps;
// Whether try to parse in ANNEXB, then by IBMF.
bool try_annexb_first;
public:
SrsFormat();
virtual ~SrsFormat();

View file

@ -2928,6 +2928,7 @@ VOID TEST(ConfigMainTest, CheckVhostConfig2)
EXPECT_EQ(2500000, conf.get_out_ack_size("ossrs.net"));
EXPECT_EQ(60000, conf.get_chunk_size("ossrs.net"));
EXPECT_TRUE(conf.get_parse_sps("ossrs.net"));
EXPECT_TRUE(conf.try_annexb_first("ossrs.net"));
EXPECT_FALSE(conf.get_mr_enabled("ossrs.net"));
EXPECT_EQ(350 * SRS_UTIME_MILLISECONDS, conf.get_mr_sleep("ossrs.net"));
EXPECT_EQ(350 * SRS_UTIME_MILLISECONDS, conf.get_mw_sleep("ossrs.net"));
@ -3020,6 +3021,12 @@ VOID TEST(ConfigMainTest, CheckVhostConfig2)
EXPECT_FALSE(conf.get_parse_sps("ossrs.net"));
}
if (true) {
MockSrsConfig conf;
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{publish{try_annexb_first off;}}"));
EXPECT_FALSE(conf.try_annexb_first("ossrs.net"));
}
if (true) {
MockSrsConfig conf;
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{chunk_size 10;}"));