fix bug of hls muxer, support close/open/flush even muxer is closed.
正在显示
2 个修改的文件
包含
26 行增加
和
22 行删除
@@ -503,7 +503,6 @@ SrsM3u8Muxer::SrsM3u8Muxer() | @@ -503,7 +503,6 @@ SrsM3u8Muxer::SrsM3u8Muxer() | ||
503 | video_stream_dts = 0; | 503 | video_stream_dts = 0; |
504 | file_index = 0; | 504 | file_index = 0; |
505 | current = NULL; | 505 | current = NULL; |
506 | - _is_open = false; | ||
507 | } | 506 | } |
508 | 507 | ||
509 | SrsM3u8Muxer::~SrsM3u8Muxer() | 508 | SrsM3u8Muxer::~SrsM3u8Muxer() |
@@ -518,11 +517,6 @@ SrsM3u8Muxer::~SrsM3u8Muxer() | @@ -518,11 +517,6 @@ SrsM3u8Muxer::~SrsM3u8Muxer() | ||
518 | srs_freep(current); | 517 | srs_freep(current); |
519 | } | 518 | } |
520 | 519 | ||
521 | -bool SrsM3u8Muxer::is_open() | ||
522 | -{ | ||
523 | - return _is_open; | ||
524 | -} | ||
525 | - | ||
526 | int SrsM3u8Muxer::update_config( | 520 | int SrsM3u8Muxer::update_config( |
527 | std::string _app, std::string _stream, | 521 | std::string _app, std::string _stream, |
528 | std::string path, int fragment, int window | 522 | std::string path, int fragment, int window |
@@ -542,6 +536,11 @@ int SrsM3u8Muxer::segment_open() | @@ -542,6 +536,11 @@ int SrsM3u8Muxer::segment_open() | ||
542 | { | 536 | { |
543 | int ret = ERROR_SUCCESS; | 537 | int ret = ERROR_SUCCESS; |
544 | 538 | ||
539 | + if (current) { | ||
540 | + srs_warn("ignore the segment open, for segment is already open."); | ||
541 | + return ret; | ||
542 | + } | ||
543 | + | ||
545 | // TODO: create all parents dirs. | 544 | // TODO: create all parents dirs. |
546 | // create dir for app. | 545 | // create dir for app. |
547 | if ((ret = create_dir()) != ERROR_SUCCESS) { | 546 | if ((ret = create_dir()) != ERROR_SUCCESS) { |
@@ -578,8 +577,6 @@ int SrsM3u8Muxer::segment_open() | @@ -578,8 +577,6 @@ int SrsM3u8Muxer::segment_open() | ||
578 | srs_info("open HLS muxer success. vhost=%s, path=%s", | 577 | srs_info("open HLS muxer success. vhost=%s, path=%s", |
579 | vhost.c_str(), current->full_path.c_str()); | 578 | vhost.c_str(), current->full_path.c_str()); |
580 | 579 | ||
581 | - _is_open = true; | ||
582 | - | ||
583 | return ret; | 580 | return ret; |
584 | } | 581 | } |
585 | 582 | ||
@@ -587,7 +584,11 @@ int SrsM3u8Muxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | @@ -587,7 +584,11 @@ int SrsM3u8Muxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | ||
587 | { | 584 | { |
588 | int ret = ERROR_SUCCESS; | 585 | int ret = ERROR_SUCCESS; |
589 | 586 | ||
590 | - srs_assert(current); | 587 | + // if current is NULL, segment is not open, ignore the flush event. |
588 | + if (!current) { | ||
589 | + srs_warn("flush audio ignored, for segment is not open."); | ||
590 | + return ret; | ||
591 | + } | ||
591 | 592 | ||
592 | if (ab->size <= 0) { | 593 | if (ab->size <= 0) { |
593 | return ret; | 594 | return ret; |
@@ -609,10 +610,15 @@ int SrsM3u8Muxer::flush_video( | @@ -609,10 +610,15 @@ int SrsM3u8Muxer::flush_video( | ||
609 | { | 610 | { |
610 | int ret = ERROR_SUCCESS; | 611 | int ret = ERROR_SUCCESS; |
611 | 612 | ||
612 | - srs_assert(current); | 613 | + // if current is NULL, segment is not open, ignore the flush event. |
614 | + if (!current) { | ||
615 | + srs_warn("flush video ignored, for segment is not open."); | ||
616 | + return ret; | ||
617 | + } | ||
613 | 618 | ||
614 | video_stream_dts = vf->dts; | 619 | video_stream_dts = vf->dts; |
615 | 620 | ||
621 | + srs_assert(current); | ||
616 | // reopen the muxer for a gop | 622 | // reopen the muxer for a gop |
617 | if (vf->key && current->duration >= hls_fragment) { | 623 | if (vf->key && current->duration >= hls_fragment) { |
618 | // TODO: flush audio before or after segment? | 624 | // TODO: flush audio before or after segment? |
@@ -643,7 +649,6 @@ int SrsM3u8Muxer::flush_video( | @@ -643,7 +649,6 @@ int SrsM3u8Muxer::flush_video( | ||
643 | } | 649 | } |
644 | } | 650 | } |
645 | 651 | ||
646 | - srs_assert(current); | ||
647 | // update the duration of segment. | 652 | // update the duration of segment. |
648 | current->update_duration(video_stream_dts); | 653 | current->update_duration(video_stream_dts); |
649 | 654 | ||
@@ -661,6 +666,11 @@ int SrsM3u8Muxer::segment_close() | @@ -661,6 +666,11 @@ int SrsM3u8Muxer::segment_close() | ||
661 | { | 666 | { |
662 | int ret = ERROR_SUCCESS; | 667 | int ret = ERROR_SUCCESS; |
663 | 668 | ||
669 | + if (!current) { | ||
670 | + srs_warn("ignore the segment close, for segment is not open."); | ||
671 | + return ret; | ||
672 | + } | ||
673 | + | ||
664 | // when close current segment, the current segment must not be NULL. | 674 | // when close current segment, the current segment must not be NULL. |
665 | srs_assert(current); | 675 | srs_assert(current); |
666 | 676 | ||
@@ -718,8 +728,6 @@ int SrsM3u8Muxer::segment_close() | @@ -718,8 +728,6 @@ int SrsM3u8Muxer::segment_close() | ||
718 | return ret; | 728 | return ret; |
719 | } | 729 | } |
720 | 730 | ||
721 | - _is_open = false; | ||
722 | - | ||
723 | return ret; | 731 | return ret; |
724 | } | 732 | } |
725 | 733 | ||
@@ -1186,14 +1194,12 @@ void SrsHls::on_unpublish() | @@ -1186,14 +1194,12 @@ void SrsHls::on_unpublish() | ||
1186 | { | 1194 | { |
1187 | int ret = ERROR_SUCCESS; | 1195 | int ret = ERROR_SUCCESS; |
1188 | 1196 | ||
1189 | - if (muxer->is_open()) { | ||
1190 | - // close muxer when unpublish. | ||
1191 | - ret = ts_cache->flush_audio(muxer); | ||
1192 | - ret += muxer->segment_close(); | 1197 | + // close muxer when unpublish. |
1198 | + ret = ts_cache->flush_audio(muxer); | ||
1199 | + ret += muxer->segment_close(); | ||
1193 | 1200 | ||
1194 | - if (ret != ERROR_SUCCESS) { | ||
1195 | - srs_error("ignore m3u8 muxer flush/close audio failed. ret=%d", ret); | ||
1196 | - } | 1201 | + if (ret != ERROR_SUCCESS) { |
1202 | + srs_error("ignore m3u8 muxer flush/close audio failed. ret=%d", ret); | ||
1197 | } | 1203 | } |
1198 | 1204 | ||
1199 | hls_enabled = false; | 1205 | hls_enabled = false; |
@@ -132,7 +132,6 @@ private: | @@ -132,7 +132,6 @@ private: | ||
132 | int hls_fragment; | 132 | int hls_fragment; |
133 | int hls_window; | 133 | int hls_window; |
134 | private: | 134 | private: |
135 | - bool _is_open; | ||
136 | int file_index; | 135 | int file_index; |
137 | std::string m3u8; | 136 | std::string m3u8; |
138 | private: | 137 | private: |
@@ -150,7 +149,6 @@ public: | @@ -150,7 +149,6 @@ public: | ||
150 | SrsM3u8Muxer(); | 149 | SrsM3u8Muxer(); |
151 | virtual ~SrsM3u8Muxer(); | 150 | virtual ~SrsM3u8Muxer(); |
152 | public: | 151 | public: |
153 | - virtual bool is_open(); | ||
154 | virtual int update_config(std::string _app, std::string _stream, std::string path, int fragment, int window); | 152 | virtual int update_config(std::string _app, std::string _stream, std::string path, int fragment, int window); |
155 | virtual int segment_open(); | 153 | virtual int segment_open(); |
156 | virtual int flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab); | 154 | virtual int flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab); |
-
请 注册 或 登录 后发表评论