1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 11:51:57 +00:00

TS: Support disable audio or video to make mpegts.js happy. v6.0.9 (#465) (#939)

This commit is contained in:
winlin 2022-12-26 19:03:49 +08:00
parent 4b6f1b0fd6
commit d5bf0ba2da
7 changed files with 44 additions and 11 deletions

View file

@ -1460,23 +1460,23 @@ vhost http.remux.srs.com {
drop_if_not_match on;
# Whether stream has audio track, used as default value for stream metadata, for example, FLV header contains
# this flag. Sometimes you might want to force the metadata by disable guess_has_av.
# See https://github.com/ossrs/srs/issues/939#issuecomment-1351385460
# TODO: Only support HTTP-FLV stream right now.
# For HTTP-FLV, use this as default value for FLV header audio flag. See https://github.com/ossrs/srs/issues/939#issuecomment-1351385460
# For HTTP-TS, use this as default value for PMT table. See https://github.com/ossrs/srs/issues/939#issuecomment-1365086204
# Overwrite by env SRS_VHOST_HTTP_REMUX_HAS_AUDIO for all vhosts.
# Default: on
has_audio on;
# Whether stream has video track, used as default value for stream metadata, for example, FLV header contains
# this flag. Sometimes you might want to force the metadata by disable guess_has_av.
# See https://github.com/ossrs/srs/issues/939#issuecomment-1351385460
# TODO: Only support HTTP-FLV stream right now.
# For HTTP-FLV, use this as default value for FLV header video flag. See https://github.com/ossrs/srs/issues/939#issuecomment-1351385460
# For HTTP-TS, use this as default value for PMT table. See https://github.com/ossrs/srs/issues/939#issuecomment-1365086204
# Overwrite by env SRS_VHOST_HTTP_REMUX_HAS_VIDEO for all vhosts.
# Default: on
has_video on;
# Whether guessing stream about audio or video track, used to generate the flags in, such as FLV header. If
# guessing, depends on sequence header and frames in gop cache, so it might be incorrect especially your stream
# is not regular. If not guessing, use the configured default value has_audio and has_video.
# See https://github.com/ossrs/srs/issues/939#issuecomment-1351385460
# TODO: Only support HTTP-FLV stream right now.
# For HTTP-FLV, enable guessing for av header flag, because FLV can't change the header. See https://github.com/ossrs/srs/issues/939#issuecomment-1351385460
# For HTTP-TS, ignore guessing because TS refresh the PMT when codec changed. See https://github.com/ossrs/srs/issues/939#issuecomment-1365086204
# Overwrite by env SRS_VHOST_HTTP_REMUX_GUESS_HAS_AV for all vhosts.
# Default: on
guess_has_av on;

View file

@ -8,6 +8,7 @@ The changelog for SRS.
## SRS 6.0 Changelog
* v5.0, 2022-12-26, For [#465](https://github.com/ossrs/srs/issues/465): TS: Support disable audio or video to make mpegts.js happy. v6.0.9
* v5.0, 2022-12-26, For [#465](https://github.com/ossrs/srs/issues/465): TS: Fix bug for codec detecting for HTTP-TS. v6.0.8
* v5.0, 2022-12-25, For [#296](https://github.com/ossrs/srs/issues/296): Fix [#3338](https://github.com/ossrs/srs/issues/3338): MP3: Support play HTTP-MP3 by H5(srs-player). v6.0.7
* v6.0, 2022-12-17, Merge 5.0: FLV header and SRT bugfix. v6.0.6

View file

@ -234,6 +234,15 @@ srs_error_t SrsTsStreamEncoder::dump_cache(SrsLiveConsumer* /*consumer*/, SrsRtm
return srs_success;
}
void SrsTsStreamEncoder::set_has_audio(bool v)
{
enc->set_has_audio(v);
}
void SrsTsStreamEncoder::set_has_video(bool v)
{
enc->set_has_video(v);
}
SrsFlvStreamEncoder::SrsFlvStreamEncoder()
{
header_written = false;
@ -636,6 +645,8 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
w->header()->set_content_type("video/MP2T");
enc_desc = "TS";
enc = new SrsTsStreamEncoder();
((SrsTsStreamEncoder*)enc)->set_has_audio(has_audio);
((SrsTsStreamEncoder*)enc)->set_has_video(has_video);
} else {
return srs_error_new(ERROR_HTTP_LIVE_STREAM_EXT, "invalid pattern=%s", entry->pattern.c_str());
}

View file

@ -110,6 +110,9 @@ public:
public:
virtual bool has_cache();
virtual srs_error_t dump_cache(SrsLiveConsumer* consumer, SrsRtmpJitterAlgorithm jitter);
public:
void set_has_audio(bool v);
void set_has_video(bool v);
};
// Transmux RTMP with AAC stream to HTTP AAC Streaming.

View file

@ -9,6 +9,6 @@
#define VERSION_MAJOR 6
#define VERSION_MINOR 0
#define VERSION_REVISION 8
#define VERSION_REVISION 9
#endif

View file

@ -3176,6 +3176,7 @@ SrsTsTransmuxer::SrsTsTransmuxer()
tsmc = new SrsTsMessageCache();
context = new SrsTsContext();
tscw = NULL;
has_audio_ = has_video_ = true;
}
SrsTsTransmuxer::~SrsTsTransmuxer()
@ -3186,6 +3187,16 @@ SrsTsTransmuxer::~SrsTsTransmuxer()
srs_freep(context);
}
void SrsTsTransmuxer::set_has_audio(bool v)
{
has_audio_ = v;
}
void SrsTsTransmuxer::set_has_video(bool v)
{
has_video_ = v;
}
srs_error_t SrsTsTransmuxer::initialize(ISrsStreamWriter* fw)
{
srs_error_t err = srs_success;
@ -3198,9 +3209,11 @@ srs_error_t SrsTsTransmuxer::initialize(ISrsStreamWriter* fw)
writer = fw;
SrsAudioCodecId acodec = has_audio_ ? SrsAudioCodecIdAAC : SrsAudioCodecIdForbidden;
SrsVideoCodecId vcodec = has_video_ ? SrsVideoCodecIdAVC : SrsVideoCodecIdForbidden;
srs_freep(tscw);
// TODO: FIXME: Support config the codec.
tscw = new SrsTsContextWriter(fw, context, SrsAudioCodecIdAAC, SrsVideoCodecIdAVC);
tscw = new SrsTsContextWriter(fw, context, acodec, vcodec);
return err;
}

View file

@ -1332,6 +1332,8 @@ class SrsTsTransmuxer
{
private:
ISrsStreamWriter* writer;
bool has_audio_;
bool has_video_;
private:
SrsFormat* format;
SrsTsMessageCache* tsmc;
@ -1340,6 +1342,9 @@ private:
public:
SrsTsTransmuxer();
virtual ~SrsTsTransmuxer();
public:
void set_has_audio(bool v);
void set_has_video(bool v);
public:
// Initialize the underlayer file stream.
// @param fw the writer to use for ts encoder, user must free it.