mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix bug of hls muxer, support close/open/flush even muxer is closed.
This commit is contained in:
parent
6207a2f19e
commit
8c5661b9ff
2 changed files with 26 additions and 22 deletions
|
@ -503,7 +503,6 @@ SrsM3u8Muxer::SrsM3u8Muxer()
|
||||||
video_stream_dts = 0;
|
video_stream_dts = 0;
|
||||||
file_index = 0;
|
file_index = 0;
|
||||||
current = NULL;
|
current = NULL;
|
||||||
_is_open = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsM3u8Muxer::~SrsM3u8Muxer()
|
SrsM3u8Muxer::~SrsM3u8Muxer()
|
||||||
|
@ -518,11 +517,6 @@ SrsM3u8Muxer::~SrsM3u8Muxer()
|
||||||
srs_freep(current);
|
srs_freep(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsM3u8Muxer::is_open()
|
|
||||||
{
|
|
||||||
return _is_open;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SrsM3u8Muxer::update_config(
|
int SrsM3u8Muxer::update_config(
|
||||||
std::string _app, std::string _stream,
|
std::string _app, std::string _stream,
|
||||||
std::string path, int fragment, int window
|
std::string path, int fragment, int window
|
||||||
|
@ -542,6 +536,11 @@ int SrsM3u8Muxer::segment_open()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
if (current) {
|
||||||
|
srs_warn("ignore the segment open, for segment is already open.");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: create all parents dirs.
|
// TODO: create all parents dirs.
|
||||||
// create dir for app.
|
// create dir for app.
|
||||||
if ((ret = create_dir()) != ERROR_SUCCESS) {
|
if ((ret = create_dir()) != ERROR_SUCCESS) {
|
||||||
|
@ -578,8 +577,6 @@ int SrsM3u8Muxer::segment_open()
|
||||||
srs_info("open HLS muxer success. vhost=%s, path=%s",
|
srs_info("open HLS muxer success. vhost=%s, path=%s",
|
||||||
vhost.c_str(), current->full_path.c_str());
|
vhost.c_str(), current->full_path.c_str());
|
||||||
|
|
||||||
_is_open = true;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,7 +584,11 @@ int SrsM3u8Muxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
srs_assert(current);
|
// if current is NULL, segment is not open, ignore the flush event.
|
||||||
|
if (!current) {
|
||||||
|
srs_warn("flush audio ignored, for segment is not open.");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (ab->size <= 0) {
|
if (ab->size <= 0) {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -609,10 +610,15 @@ int SrsM3u8Muxer::flush_video(
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
srs_assert(current);
|
// if current is NULL, segment is not open, ignore the flush event.
|
||||||
|
if (!current) {
|
||||||
|
srs_warn("flush video ignored, for segment is not open.");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
video_stream_dts = vf->dts;
|
video_stream_dts = vf->dts;
|
||||||
|
|
||||||
|
srs_assert(current);
|
||||||
// reopen the muxer for a gop
|
// reopen the muxer for a gop
|
||||||
if (vf->key && current->duration >= hls_fragment) {
|
if (vf->key && current->duration >= hls_fragment) {
|
||||||
// TODO: flush audio before or after segment?
|
// TODO: flush audio before or after segment?
|
||||||
|
@ -643,7 +649,6 @@ int SrsM3u8Muxer::flush_video(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(current);
|
|
||||||
// update the duration of segment.
|
// update the duration of segment.
|
||||||
current->update_duration(video_stream_dts);
|
current->update_duration(video_stream_dts);
|
||||||
|
|
||||||
|
@ -661,6 +666,11 @@ int SrsM3u8Muxer::segment_close()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
if (!current) {
|
||||||
|
srs_warn("ignore the segment close, for segment is not open.");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// when close current segment, the current segment must not be NULL.
|
// when close current segment, the current segment must not be NULL.
|
||||||
srs_assert(current);
|
srs_assert(current);
|
||||||
|
|
||||||
|
@ -718,8 +728,6 @@ int SrsM3u8Muxer::segment_close()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
_is_open = false;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1186,14 +1194,12 @@ void SrsHls::on_unpublish()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (muxer->is_open()) {
|
// close muxer when unpublish.
|
||||||
// close muxer when unpublish.
|
ret = ts_cache->flush_audio(muxer);
|
||||||
ret = ts_cache->flush_audio(muxer);
|
ret += muxer->segment_close();
|
||||||
ret += muxer->segment_close();
|
|
||||||
|
|
||||||
if (ret != ERROR_SUCCESS) {
|
if (ret != ERROR_SUCCESS) {
|
||||||
srs_error("ignore m3u8 muxer flush/close audio failed. ret=%d", ret);
|
srs_error("ignore m3u8 muxer flush/close audio failed. ret=%d", ret);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hls_enabled = false;
|
hls_enabled = false;
|
||||||
|
|
|
@ -132,7 +132,6 @@ private:
|
||||||
int hls_fragment;
|
int hls_fragment;
|
||||||
int hls_window;
|
int hls_window;
|
||||||
private:
|
private:
|
||||||
bool _is_open;
|
|
||||||
int file_index;
|
int file_index;
|
||||||
std::string m3u8;
|
std::string m3u8;
|
||||||
private:
|
private:
|
||||||
|
@ -150,7 +149,6 @@ public:
|
||||||
SrsM3u8Muxer();
|
SrsM3u8Muxer();
|
||||||
virtual ~SrsM3u8Muxer();
|
virtual ~SrsM3u8Muxer();
|
||||||
public:
|
public:
|
||||||
virtual bool is_open();
|
|
||||||
virtual int update_config(std::string _app, std::string _stream, std::string path, int fragment, int window);
|
virtual int update_config(std::string _app, std::string _stream, std::string path, int fragment, int window);
|
||||||
virtual int segment_open();
|
virtual int segment_open();
|
||||||
virtual int flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab);
|
virtual int flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue