winlin

for #474, refine the hls publish, donot fetch from source when publish

@@ -1252,7 +1252,7 @@ int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h) @@ -1252,7 +1252,7 @@ int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h)
1252 return ret; 1252 return ret;
1253 } 1253 }
1254 1254
1255 -int SrsHls::on_publish(SrsRequest* req) 1255 +int SrsHls::on_publish(SrsRequest* req, bool fetch_sequence_header)
1256 { 1256 {
1257 int ret = ERROR_SUCCESS; 1257 int ret = ERROR_SUCCESS;
1258 1258
@@ -1282,12 +1282,16 @@ int SrsHls::on_publish(SrsRequest* req) @@ -1282,12 +1282,16 @@ int SrsHls::on_publish(SrsRequest* req)
1282 // ok, the hls can be dispose, or need to be dispose. 1282 // ok, the hls can be dispose, or need to be dispose.
1283 hls_can_dispose = true; 1283 hls_can_dispose = true;
1284 1284
1285 - // notice the source to get the cached sequence header.  
1286 - // when reload to start hls, hls will never get the sequence header in stream,  
1287 - // use the SrsSource.on_hls_start to push the sequence header to HLS.  
1288 - if ((ret = source->on_hls_start()) != ERROR_SUCCESS) {  
1289 - srs_error("callback source hls start failed. ret=%d", ret);  
1290 - return ret; 1285 + // when publish, don't need to fetch sequence header, which is old and maybe corrupt.
  1286 + // when reload, we must fetch the sequence header from source cache.
  1287 + if (fetch_sequence_header) {
  1288 + // notice the source to get the cached sequence header.
  1289 + // when reload to start hls, hls will never get the sequence header in stream,
  1290 + // use the SrsSource.on_hls_start to push the sequence header to HLS.
  1291 + if ((ret = source->on_hls_start()) != ERROR_SUCCESS) {
  1292 + srs_error("callback source hls start failed. ret=%d", ret);
  1293 + return ret;
  1294 + }
1291 } 1295 }
1292 1296
1293 return ret; 1297 return ret;
@@ -424,10 +424,11 @@ public: @@ -424,10 +424,11 @@ public:
424 */ 424 */
425 virtual int initialize(SrsSource* s, ISrsHlsHandler* h); 425 virtual int initialize(SrsSource* s, ISrsHlsHandler* h);
426 /** 426 /**
427 - * publish stream event, continue to write the m3u8,  
428 - * for the muxer object not destroyed.  
429 - */  
430 - virtual int on_publish(SrsRequest* req); 427 + * publish stream event, continue to write the m3u8,
  428 + * for the muxer object not destroyed.
  429 + * @param fetch_sequence_header whether fetch sequence from source.
  430 + */
  431 + virtual int on_publish(SrsRequest* req, bool fetch_sequence_header);
431 /** 432 /**
432 * the unpublish event, only close the muxer, donot destroy the 433 * the unpublish event, only close the muxer, donot destroy the
433 * muxer, for when we continue to publish, the m3u8 will continue. 434 * muxer, for when we continue to publish, the m3u8 will continue.
@@ -1180,7 +1180,7 @@ int SrsSource::on_reload_vhost_hls(string vhost) @@ -1180,7 +1180,7 @@ int SrsSource::on_reload_vhost_hls(string vhost)
1180 1180
1181 #ifdef SRS_AUTO_HLS 1181 #ifdef SRS_AUTO_HLS
1182 hls->on_unpublish(); 1182 hls->on_unpublish();
1183 - if ((ret = hls->on_publish(_req)) != ERROR_SUCCESS) { 1183 + if ((ret = hls->on_publish(_req, true)) != ERROR_SUCCESS) {
1184 srs_error("hls publish failed. ret=%d", ret); 1184 srs_error("hls publish failed. ret=%d", ret);
1185 return ret; 1185 return ret;
1186 } 1186 }
@@ -2039,7 +2039,7 @@ int SrsSource::on_publish() @@ -2039,7 +2039,7 @@ int SrsSource::on_publish()
2039 2039
2040 // TODO: FIXME: use initialize to set req. 2040 // TODO: FIXME: use initialize to set req.
2041 #ifdef SRS_AUTO_HLS 2041 #ifdef SRS_AUTO_HLS
2042 - if ((ret = hls->on_publish(_req)) != ERROR_SUCCESS) { 2042 + if ((ret = hls->on_publish(_req, false)) != ERROR_SUCCESS) {
2043 srs_error("start hls failed. ret=%d", ret); 2043 srs_error("start hls failed. ret=%d", ret);
2044 return ret; 2044 return ret;
2045 } 2045 }