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

Merge branch v5.0.116 into develop

1. MP3: Fix bug for TS or HLS with mp3 codec. v4.0.269 (#296) (#3333)
2. MP3: Add config examples for MP3. #296
3. Script: Refine GitHub actions.
This commit is contained in:
winlin 2022-12-25 16:23:23 +08:00
commit b5aaf67c93
16 changed files with 212 additions and 55 deletions

View file

@ -1851,11 +1851,11 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
}
if (show_version) {
fprintf(stderr, "%s\n", RTMP_SIG_SRS_VERSION);
fprintf(stdout, "%s\n", RTMP_SIG_SRS_VERSION);
exit(0);
}
if (show_signature) {
fprintf(stderr, "%s\n", RTMP_SIG_SRS_SERVER);
fprintf(stdout, "%s\n", RTMP_SIG_SRS_SERVER);
exit(0);
}

View file

@ -202,6 +202,7 @@ SrsHlsMuxer::SrsHlsMuxer()
async = new SrsAsyncCallWorker();
context = new SrsTsContext();
segments = new SrsFragmentWindow();
latest_acodec_ = SrsAudioCodecIdForbidden;
memset(key, 0, 16);
memset(iv, 0, 16);
@ -263,6 +264,24 @@ int SrsHlsMuxer::deviation()
return deviation_ts;
}
SrsAudioCodecId SrsHlsMuxer::latest_acodec()
{
// If current context writer exists, we query from it.
if (current && current->tscw) return current->tscw->acodec();
// Get the configured or updated config.
return latest_acodec_;
}
void SrsHlsMuxer::set_latest_acodec(SrsAudioCodecId v)
{
// Refresh the codec in context writer for current segment.
if (current && current->tscw) current->tscw->set_acodec(v);
// Refresh the codec for future segments.
latest_acodec_ = v;
}
srs_error_t SrsHlsMuxer::initialize()
{
return srs_success;
@ -371,6 +390,8 @@ srs_error_t SrsHlsMuxer::segment_open()
srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str());
}
}
// Now that we know the latest audio codec in stream, use it.
if (latest_acodec_ != SrsAudioCodecIdForbidden) default_acodec = latest_acodec_;
// load the default vcodec from config.
SrsVideoCodecId default_vcodec = SrsVideoCodecIdAVC;
@ -969,6 +990,13 @@ srs_error_t SrsHlsController::on_sequence_header()
srs_error_t SrsHlsController::write_audio(SrsAudioFrame* frame, int64_t pts)
{
srs_error_t err = srs_success;
// Refresh the codec ASAP.
if (muxer->latest_acodec() != frame->acodec()->id) {
srs_trace("HLS: Switch audio codec %d(%s) to %d(%s)", muxer->latest_acodec(), srs_audio_codec_id2str(muxer->latest_acodec()).c_str(),
frame->acodec()->id, srs_audio_codec_id2str(frame->acodec()->id).c_str());
muxer->set_latest_acodec(frame->acodec()->id);
}
// write audio to cache.
if ((err = tsmc->cache_audio(frame, pts)) != srs_success) {

View file

@ -156,6 +156,9 @@ private:
SrsHlsSegment* current;
// The ts context, to keep cc continous between ts.
SrsTsContext* context;
private:
// Latest audio codec, parsed from stream.
SrsAudioCodecId latest_acodec_;
public:
SrsHlsMuxer();
virtual ~SrsHlsMuxer();
@ -166,6 +169,9 @@ public:
virtual std::string ts_url();
virtual srs_utime_t duration();
virtual int deviation();
public:
SrsAudioCodecId latest_acodec();
void set_latest_acodec(SrsAudioCodecId v);
public:
// Initialize the hls muxer.
virtual srs_error_t initialize();

View file

@ -829,7 +829,9 @@ void SrsLiveStream::http_hooks_on_stop(ISrsHttpMessage* r)
srs_error_t SrsLiveStream::streaming_send_messages(ISrsBufferEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs)
{
srs_error_t err = srs_success;
// TODO: In gop cache, we know both the audio and video codec, so we should notice the encoder, which might depends
// on setting the correct codec information, for example, HTTP-TS or HLS will write PMT.
for (int i = 0; i < nb_msgs; i++) {
SrsSharedPtrMessage* msg = msgs[i];