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

FLV: Drop packet if header flag is not matched. v5.0.109 (#3306)

1. Ignore audo or video packets if FLV header disable it.
2. Run: Add regression test config and run for IDEA.
3. Test: Refine regression test to allow no audio/video for FLV
4. Config: Whether drop packet if not match header.
This commit is contained in:
Winlin 2022-12-14 21:07:14 +08:00 committed by GitHub
parent 35185cf844
commit 4551200e95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 191 additions and 42 deletions

View file

@ -2600,7 +2600,7 @@ srs_error_t SrsConfig::check_normal_config()
} else if (n == "http_remux") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "enabled" && m != "mount" && m != "fast_cache") {
if (m != "enabled" && m != "mount" && m != "fast_cache" && m != "drop_if_not_match") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.http_remux.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
@ -8241,6 +8241,30 @@ srs_utime_t SrsConfig::get_vhost_http_remux_fast_cache(string vhost)
return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
}
bool SrsConfig::get_vhost_http_remux_drop_if_not_match(string vhost)
{
SRS_OVERWRITE_BY_ENV_BOOL2("srs.vhost.http_remux.drop_if_not_match"); // SRS_VHOST_HTTP_REMUX_DROP_IF_NOT_MATCH
static bool DEFAULT = true;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("http_remux");
if (!conf) {
return DEFAULT;
}
conf = conf->get("drop_if_not_match");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
string SrsConfig::get_vhost_http_remux_mount(string vhost)
{
SRS_OVERWRITE_BY_ENV_STRING("srs.vhost.http_remux.mount"); // SRS_VHOST_HTTP_REMUX_MOUNT

View file

@ -1064,6 +1064,8 @@ public:
virtual bool get_vhost_http_remux_enabled(SrsConfDirective* vhost);
// Get the fast cache duration for http audio live stream.
virtual srs_utime_t get_vhost_http_remux_fast_cache(std::string vhost);
// Whether drop packet if not match header.
bool get_vhost_http_remux_drop_if_not_match(std::string vhost);
// Get the http flv live stream mount point for vhost.
// used to generate the flv stream mount path.
virtual std::string get_vhost_http_remux_mount(std::string vhost);

View file

@ -289,6 +289,11 @@ srs_error_t SrsFlvStreamEncoder::write_metadata(int64_t timestamp, char* data, i
return enc->write_metadata(SrsFrameTypeScript, data, size);
}
void SrsFlvStreamEncoder::set_drop_if_not_match(bool v)
{
enc->set_drop_if_not_match(v);
}
bool SrsFlvStreamEncoder::has_cache()
{
// for flv stream, use gop cache of SrsLiveSource is ok.
@ -356,7 +361,7 @@ srs_error_t SrsFlvStreamEncoder::write_header(bool has_video, bool has_audio)
return srs_error_wrap(err, "write header");
}
srs_trace("FLV: write header audio=%d, video=%d", has_audio, has_video);
srs_trace("FLV: write header audio=%d, video=%d, dinm=%d", has_audio, has_video, enc->drop_if_not_match());
}
return err;
@ -576,12 +581,15 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
string enc_desc;
ISrsBufferEncoder* enc = NULL;
srs_assert(entry);
bool drop_if_not_match = _srs_config->get_vhost_http_remux_drop_if_not_match(req->vhost);
if (srs_string_ends_with(entry->pattern, ".flv")) {
w->header()->set_content_type("video/x-flv");
enc_desc = "FLV";
enc = new SrsFlvStreamEncoder();
((SrsFlvStreamEncoder*)enc)->set_drop_if_not_match(drop_if_not_match);
} else if (srs_string_ends_with(entry->pattern, ".aac")) {
w->header()->set_content_type("audio/x-aac");
enc_desc = "AAC";
@ -651,8 +659,8 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
}
srs_utime_t mw_sleep = _srs_config->get_mw_sleep(req->vhost);
srs_trace("FLV %s, encoder=%s, mw_sleep=%dms, cache=%d, msgs=%d", entry->pattern.c_str(), enc_desc.c_str(),
srsu2msi(mw_sleep), enc->has_cache(), msgs.max);
srs_trace("FLV %s, encoder=%s, mw_sleep=%dms, cache=%d, msgs=%d, dinm=%d", entry->pattern.c_str(), enc_desc.c_str(),
srsu2msi(mw_sleep), enc->has_cache(), msgs.max, drop_if_not_match);
// TODO: free and erase the disabled entry after all related connections is closed.
// TODO: FXIME: Support timeout for player, quit infinite-loop.

View file

@ -77,6 +77,7 @@ public:
virtual srs_error_t write_video(int64_t timestamp, char* data, int size);
virtual srs_error_t write_metadata(int64_t timestamp, char* data, int size);
public:
void set_drop_if_not_match(bool v);
virtual bool has_cache();
virtual srs_error_t dump_cache(SrsLiveConsumer* consumer, SrsRtmpJitterAlgorithm jitter);
public: