From e262147e81d56ed6bb435e9a3262e755c8b6be06 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 15 Dec 2013 20:29:18 +0800 Subject: [PATCH] fix the hls reload bug, feed it the sequence header. --- README.md | 1 + trunk/conf/srs.conf | 2 +- trunk/src/core/srs_core_hls.cpp | 15 +++++++++++---- trunk/src/core/srs_core_hls.hpp | 8 +++++--- trunk/src/core/srs_core_source.cpp | 28 +++++++++++++++++++++++++--- trunk/src/core/srs_core_source.hpp | 4 +++- 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4e10b14e5..dde6d578c 100755 --- a/README.md +++ b/README.md @@ -212,6 +212,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw * nginx v1.5.0: 139524 lines
### History +* v0.9, 2013-12-15, fix the hls reload bug, feed it the sequence header. * v0.9, 2013-12-15, refine protocol, use int64_t timestamp for ts and jitter. * v0.9, 2013-12-15, support set the live queue length(in seconds), drop when full. * v0.9, 2013-12-15, fix the forwarder reconnect bug, feed it the sequence header. diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf index 3a9edda52..af102c496 100755 --- a/trunk/conf/srs.conf +++ b/trunk/conf/srs.conf @@ -96,7 +96,7 @@ vhost dev { queue_length 10; forward 127.0.0.1:19350; hls { - enabled off; + enabled on; hls_path ./objs/nginx/html; hls_fragment 5; hls_window 30; diff --git a/trunk/src/core/srs_core_hls.cpp b/trunk/src/core/srs_core_hls.cpp index 6bc4dfd23..706fd0081 100644 --- a/trunk/src/core/srs_core_hls.cpp +++ b/trunk/src/core/srs_core_hls.cpp @@ -1109,10 +1109,11 @@ int SrsTSCache::cache_video(SrsCodec* codec, SrsCodecSample* sample) return ret; } -SrsHls::SrsHls() +SrsHls::SrsHls(SrsSource* _source) { hls_enabled = false; + source = _source; codec = new SrsCodec(); sample = new SrsCodecSample(); jitter = new SrsRtmpJitter(); @@ -1171,6 +1172,12 @@ int SrsHls::on_publish(SrsRequest* req) srs_error("m3u8 muxer open segment failed. ret=%d", ret); return ret; } + + // notice the source to get the cached sequence header. + if ((ret = source->on_hls_start()) != ERROR_SUCCESS) { + srs_error("callback source hls start failed. ret=%d", ret); + return ret; + } return ret; } @@ -1195,16 +1202,16 @@ void SrsHls::on_unpublish() hls_enabled = false; } -int SrsHls::on_meta_data(SrsOnMetaDataPacket* metadata) +int SrsHls::on_meta_data(SrsAmf0Object* metadata) { int ret = ERROR_SUCCESS; - if (!metadata || !metadata->metadata) { + if (!metadata) { srs_trace("no metadata persent, hls ignored it."); return ret; } - SrsAmf0Object* obj = metadata->metadata; + SrsAmf0Object* obj = metadata; if (obj->size() <= 0) { srs_trace("no metadata persent, hls ignored it."); return ret; diff --git a/trunk/src/core/srs_core_hls.hpp b/trunk/src/core/srs_core_hls.hpp index f82cbece5..7bc49ade9 100644 --- a/trunk/src/core/srs_core_hls.hpp +++ b/trunk/src/core/srs_core_hls.hpp @@ -34,16 +34,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -class SrsOnMetaDataPacket; class SrsSharedPtrMessage; class SrsCodecSample; class SrsCodecBuffer; class SrsMpegtsFrame; +class SrsAmf0Object; class SrsRtmpJitter; class SrsTSMuxer; class SrsCodec; class SrsRequest; class SrsPithyPrint; +class SrsSource; /** * jitter correct for audio, @@ -207,17 +208,18 @@ private: SrsTSCache* ts_cache; private: bool hls_enabled; + SrsSource* source; SrsCodec* codec; SrsCodecSample* sample; SrsRtmpJitter* jitter; SrsPithyPrint* pithy_print; public: - SrsHls(); + SrsHls(SrsSource* _source); virtual ~SrsHls(); public: virtual int on_publish(SrsRequest* req); virtual void on_unpublish(); - virtual int on_meta_data(SrsOnMetaDataPacket* metadata); + virtual int on_meta_data(SrsAmf0Object* metadata); virtual int on_audio(SrsSharedPtrMessage* audio); virtual int on_video(SrsSharedPtrMessage* video); private: diff --git a/trunk/src/core/srs_core_source.cpp b/trunk/src/core/srs_core_source.cpp index bd79e7921..0143fed2c 100644 --- a/trunk/src/core/srs_core_source.cpp +++ b/trunk/src/core/srs_core_source.cpp @@ -410,7 +410,7 @@ SrsSource::SrsSource(SrsRequest* _req) req = _req->copy(); #ifdef SRS_HLS - hls = new SrsHls(); + hls = new SrsHls(this); #endif #ifdef SRS_FFMPEG encoder = new SrsEncoder(); @@ -553,7 +553,6 @@ int SrsSource::on_reload_hls(string vhost) srs_error("hls publish failed. ret=%d", ret); return ret; } - // TODO: FIXME: must feed it the sequence header. srs_trace("vhost %s hls reload success", vhost.c_str()); #endif @@ -602,6 +601,29 @@ int SrsSource::on_forwarder_start(SrsForwarder* forwarder) return ret; } +int SrsSource::on_hls_start() +{ + int ret = ERROR_SUCCESS; + +#ifdef SRS_HLS + + // feed the hls the metadata/sequence header, + // when reload to enable the hls. + // TODO: maybe need to decode the metadata? + if (cache_sh_video && (ret = hls->on_video(cache_sh_video->copy())) != ERROR_SUCCESS) { + srs_error("hls process video sequence header message failed. ret=%d", ret); + return ret; + } + if (cache_sh_audio && (ret = hls->on_audio(cache_sh_audio->copy())) != ERROR_SUCCESS) { + srs_error("hls process audio sequence header message failed. ret=%d", ret); + return ret; + } + +#endif + + return ret; +} + bool SrsSource::can_publish() { return _can_publish; @@ -612,7 +634,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata int ret = ERROR_SUCCESS; #ifdef SRS_HLS - if ((ret = hls->on_meta_data(metadata)) != ERROR_SUCCESS) { + if (metadata && (ret = hls->on_meta_data(metadata->metadata)) != ERROR_SUCCESS) { srs_error("hls process onMetaData message failed. ret=%d", ret); return ret; } diff --git a/trunk/src/core/srs_core_source.hpp b/trunk/src/core/srs_core_source.hpp index 2c008f703..405c51e53 100644 --- a/trunk/src/core/srs_core_source.hpp +++ b/trunk/src/core/srs_core_source.hpp @@ -257,9 +257,11 @@ public: virtual int on_reload_forward(std::string vhost); virtual int on_reload_hls(std::string vhost); virtual int on_reload_transcode(std::string vhost); -// for the SrsForwarder to callback to request the sequence headers. public: + // for the SrsForwarder to callback to request the sequence headers. virtual int on_forwarder_start(SrsForwarder* forwarder); + // for the SrsHls to callback to request the sequence headers. + virtual int on_hls_start(); public: virtual bool can_publish(); virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);