fix bug of hls muxer, support close/open/flush even muxer is closed.

pull/133/head
winlin 11 years ago
parent 6207a2f19e
commit 8c5661b9ff

@ -503,7 +503,6 @@ SrsM3u8Muxer::SrsM3u8Muxer()
video_stream_dts = 0;
file_index = 0;
current = NULL;
_is_open = false;
}
SrsM3u8Muxer::~SrsM3u8Muxer()
@ -518,11 +517,6 @@ SrsM3u8Muxer::~SrsM3u8Muxer()
srs_freep(current);
}
bool SrsM3u8Muxer::is_open()
{
return _is_open;
}
int SrsM3u8Muxer::update_config(
std::string _app, std::string _stream,
std::string path, int fragment, int window
@ -542,6 +536,11 @@ int SrsM3u8Muxer::segment_open()
{
int ret = ERROR_SUCCESS;
if (current) {
srs_warn("ignore the segment open, for segment is already open.");
return ret;
}
// TODO: create all parents dirs.
// create dir for app.
if ((ret = create_dir()) != ERROR_SUCCESS) {
@ -578,8 +577,6 @@ int SrsM3u8Muxer::segment_open()
srs_info("open HLS muxer success. vhost=%s, path=%s",
vhost.c_str(), current->full_path.c_str());
_is_open = true;
return ret;
}
@ -587,7 +584,11 @@ int SrsM3u8Muxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab)
{
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) {
return ret;
@ -609,10 +610,15 @@ int SrsM3u8Muxer::flush_video(
{
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;
srs_assert(current);
// reopen the muxer for a gop
if (vf->key && current->duration >= hls_fragment) {
// TODO: flush audio before or after segment?
@ -643,7 +649,6 @@ int SrsM3u8Muxer::flush_video(
}
}
srs_assert(current);
// update the duration of segment.
current->update_duration(video_stream_dts);
@ -661,6 +666,11 @@ int SrsM3u8Muxer::segment_close()
{
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.
srs_assert(current);
@ -718,8 +728,6 @@ int SrsM3u8Muxer::segment_close()
return ret;
}
_is_open = false;
return ret;
}
@ -1186,14 +1194,12 @@ void SrsHls::on_unpublish()
{
int ret = ERROR_SUCCESS;
if (muxer->is_open()) {
// close muxer when unpublish.
ret = ts_cache->flush_audio(muxer);
ret += muxer->segment_close();
// close muxer when unpublish.
ret = ts_cache->flush_audio(muxer);
ret += muxer->segment_close();
if (ret != ERROR_SUCCESS) {
srs_error("ignore m3u8 muxer flush/close audio failed. ret=%d", ret);
}
if (ret != ERROR_SUCCESS) {
srs_error("ignore m3u8 muxer flush/close audio failed. ret=%d", ret);
}
hls_enabled = false;

@ -132,7 +132,6 @@ private:
int hls_fragment;
int hls_window;
private:
bool _is_open;
int file_index;
std::string m3u8;
private:
@ -150,7 +149,6 @@ public:
SrsM3u8Muxer();
virtual ~SrsM3u8Muxer();
public:
virtual bool is_open();
virtual int update_config(std::string _app, std::string _stream, std::string path, int fragment, int window);
virtual int segment_open();
virtual int flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab);

Loading…
Cancel
Save