Skip to content

Commit

Permalink
for #474, refine the hls publish, donot fetch from source when publish
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 14, 2015
1 parent 44bcb40 commit 83a9ff9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
18 changes: 11 additions & 7 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h)
return ret;
}

int SrsHls::on_publish(SrsRequest* req)
int SrsHls::on_publish(SrsRequest* req, bool fetch_sequence_header)
{
int ret = ERROR_SUCCESS;

Expand Down Expand Up @@ -1282,12 +1282,16 @@ int SrsHls::on_publish(SrsRequest* req)
// ok, the hls can be dispose, or need to be dispose.
hls_can_dispose = true;

// notice the source to get the cached sequence header.
// when reload to start hls, hls will never get the sequence header in stream,
// use the SrsSource.on_hls_start to push the sequence header to HLS.
if ((ret = source->on_hls_start()) != ERROR_SUCCESS) {
srs_error("callback source hls start failed. ret=%d", ret);
return ret;
// when publish, don't need to fetch sequence header, which is old and maybe corrupt.
// when reload, we must fetch the sequence header from source cache.
if (fetch_sequence_header) {
// notice the source to get the cached sequence header.
// when reload to start hls, hls will never get the sequence header in stream,
// use the SrsSource.on_hls_start to push the sequence header to HLS.
if ((ret = source->on_hls_start()) != ERROR_SUCCESS) {
srs_error("callback source hls start failed. ret=%d", ret);
return ret;
}
}

return ret;
Expand Down
9 changes: 5 additions & 4 deletions trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,11 @@ class SrsHls
*/
virtual int initialize(SrsSource* s, ISrsHlsHandler* h);
/**
* publish stream event, continue to write the m3u8,
* for the muxer object not destroyed.
*/
virtual int on_publish(SrsRequest* req);
* publish stream event, continue to write the m3u8,
* for the muxer object not destroyed.
* @param fetch_sequence_header whether fetch sequence from source.
*/
virtual int on_publish(SrsRequest* req, bool fetch_sequence_header);
/**
* the unpublish event, only close the muxer, donot destroy the
* muxer, for when we continue to publish, the m3u8 will continue.
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ int SrsSource::on_reload_vhost_hls(string vhost)

#ifdef SRS_AUTO_HLS
hls->on_unpublish();
if ((ret = hls->on_publish(_req)) != ERROR_SUCCESS) {
if ((ret = hls->on_publish(_req, true)) != ERROR_SUCCESS) {
srs_error("hls publish failed. ret=%d", ret);
return ret;
}
Expand Down Expand Up @@ -2039,7 +2039,7 @@ int SrsSource::on_publish()

// TODO: FIXME: use initialize to set req.
#ifdef SRS_AUTO_HLS
if ((ret = hls->on_publish(_req)) != ERROR_SUCCESS) {
if ((ret = hls->on_publish(_req, false)) != ERROR_SUCCESS) {
srs_error("start hls failed. ret=%d", ret);
return ret;
}
Expand Down

0 comments on commit 83a9ff9

Please sign in to comment.