fix the hls reload bug, feed it the sequence header.

pull/133/head
winlin 11 years ago
parent 27255a3e7a
commit e262147e81

@ -212,6 +212,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
* nginx v1.5.0: 139524 lines <br/>
### 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.

@ -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;

@ -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;

@ -34,16 +34,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string>
#include <vector>
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:

@ -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;
}

@ -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);

Loading…
Cancel
Save