mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 19:31:53 +00:00
fix the hls reload bug, feed it the sequence header.
This commit is contained in:
parent
27255a3e7a
commit
e262147e81
6 changed files with 46 additions and 12 deletions
|
@ -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/>
|
* nginx v1.5.0: 139524 lines <br/>
|
||||||
|
|
||||||
### History
|
### 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, 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, 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.
|
* v0.9, 2013-12-15, fix the forwarder reconnect bug, feed it the sequence header.
|
||||||
|
|
|
@ -96,7 +96,7 @@ vhost dev {
|
||||||
queue_length 10;
|
queue_length 10;
|
||||||
forward 127.0.0.1:19350;
|
forward 127.0.0.1:19350;
|
||||||
hls {
|
hls {
|
||||||
enabled off;
|
enabled on;
|
||||||
hls_path ./objs/nginx/html;
|
hls_path ./objs/nginx/html;
|
||||||
hls_fragment 5;
|
hls_fragment 5;
|
||||||
hls_window 30;
|
hls_window 30;
|
||||||
|
|
|
@ -1109,10 +1109,11 @@ int SrsTSCache::cache_video(SrsCodec* codec, SrsCodecSample* sample)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHls::SrsHls()
|
SrsHls::SrsHls(SrsSource* _source)
|
||||||
{
|
{
|
||||||
hls_enabled = false;
|
hls_enabled = false;
|
||||||
|
|
||||||
|
source = _source;
|
||||||
codec = new SrsCodec();
|
codec = new SrsCodec();
|
||||||
sample = new SrsCodecSample();
|
sample = new SrsCodecSample();
|
||||||
jitter = new SrsRtmpJitter();
|
jitter = new SrsRtmpJitter();
|
||||||
|
@ -1172,6 +1173,12 @@ int SrsHls::on_publish(SrsRequest* req)
|
||||||
return 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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1195,16 +1202,16 @@ void SrsHls::on_unpublish()
|
||||||
hls_enabled = false;
|
hls_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHls::on_meta_data(SrsOnMetaDataPacket* metadata)
|
int SrsHls::on_meta_data(SrsAmf0Object* metadata)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (!metadata || !metadata->metadata) {
|
if (!metadata) {
|
||||||
srs_trace("no metadata persent, hls ignored it.");
|
srs_trace("no metadata persent, hls ignored it.");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAmf0Object* obj = metadata->metadata;
|
SrsAmf0Object* obj = metadata;
|
||||||
if (obj->size() <= 0) {
|
if (obj->size() <= 0) {
|
||||||
srs_trace("no metadata persent, hls ignored it.");
|
srs_trace("no metadata persent, hls ignored it.");
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -34,16 +34,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class SrsOnMetaDataPacket;
|
|
||||||
class SrsSharedPtrMessage;
|
class SrsSharedPtrMessage;
|
||||||
class SrsCodecSample;
|
class SrsCodecSample;
|
||||||
class SrsCodecBuffer;
|
class SrsCodecBuffer;
|
||||||
class SrsMpegtsFrame;
|
class SrsMpegtsFrame;
|
||||||
|
class SrsAmf0Object;
|
||||||
class SrsRtmpJitter;
|
class SrsRtmpJitter;
|
||||||
class SrsTSMuxer;
|
class SrsTSMuxer;
|
||||||
class SrsCodec;
|
class SrsCodec;
|
||||||
class SrsRequest;
|
class SrsRequest;
|
||||||
class SrsPithyPrint;
|
class SrsPithyPrint;
|
||||||
|
class SrsSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* jitter correct for audio,
|
* jitter correct for audio,
|
||||||
|
@ -207,17 +208,18 @@ private:
|
||||||
SrsTSCache* ts_cache;
|
SrsTSCache* ts_cache;
|
||||||
private:
|
private:
|
||||||
bool hls_enabled;
|
bool hls_enabled;
|
||||||
|
SrsSource* source;
|
||||||
SrsCodec* codec;
|
SrsCodec* codec;
|
||||||
SrsCodecSample* sample;
|
SrsCodecSample* sample;
|
||||||
SrsRtmpJitter* jitter;
|
SrsRtmpJitter* jitter;
|
||||||
SrsPithyPrint* pithy_print;
|
SrsPithyPrint* pithy_print;
|
||||||
public:
|
public:
|
||||||
SrsHls();
|
SrsHls(SrsSource* _source);
|
||||||
virtual ~SrsHls();
|
virtual ~SrsHls();
|
||||||
public:
|
public:
|
||||||
virtual int on_publish(SrsRequest* req);
|
virtual int on_publish(SrsRequest* req);
|
||||||
virtual void on_unpublish();
|
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_audio(SrsSharedPtrMessage* audio);
|
||||||
virtual int on_video(SrsSharedPtrMessage* video);
|
virtual int on_video(SrsSharedPtrMessage* video);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -410,7 +410,7 @@ SrsSource::SrsSource(SrsRequest* _req)
|
||||||
req = _req->copy();
|
req = _req->copy();
|
||||||
|
|
||||||
#ifdef SRS_HLS
|
#ifdef SRS_HLS
|
||||||
hls = new SrsHls();
|
hls = new SrsHls(this);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SRS_FFMPEG
|
#ifdef SRS_FFMPEG
|
||||||
encoder = new SrsEncoder();
|
encoder = new SrsEncoder();
|
||||||
|
@ -553,7 +553,6 @@ int SrsSource::on_reload_hls(string vhost)
|
||||||
srs_error("hls publish failed. ret=%d", ret);
|
srs_error("hls publish failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// TODO: FIXME: must feed it the sequence header.
|
|
||||||
srs_trace("vhost %s hls reload success", vhost.c_str());
|
srs_trace("vhost %s hls reload success", vhost.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -602,6 +601,29 @@ int SrsSource::on_forwarder_start(SrsForwarder* forwarder)
|
||||||
return ret;
|
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()
|
bool SrsSource::can_publish()
|
||||||
{
|
{
|
||||||
return _can_publish;
|
return _can_publish;
|
||||||
|
@ -612,7 +634,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
#ifdef SRS_HLS
|
#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);
|
srs_error("hls process onMetaData message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,9 +257,11 @@ public:
|
||||||
virtual int on_reload_forward(std::string vhost);
|
virtual int on_reload_forward(std::string vhost);
|
||||||
virtual int on_reload_hls(std::string vhost);
|
virtual int on_reload_hls(std::string vhost);
|
||||||
virtual int on_reload_transcode(std::string vhost);
|
virtual int on_reload_transcode(std::string vhost);
|
||||||
// for the SrsForwarder to callback to request the sequence headers.
|
|
||||||
public:
|
public:
|
||||||
|
// for the SrsForwarder to callback to request the sequence headers.
|
||||||
virtual int on_forwarder_start(SrsForwarder* forwarder);
|
virtual int on_forwarder_start(SrsForwarder* forwarder);
|
||||||
|
// for the SrsHls to callback to request the sequence headers.
|
||||||
|
virtual int on_hls_start();
|
||||||
public:
|
public:
|
||||||
virtual bool can_publish();
|
virtual bool can_publish();
|
||||||
virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);
|
virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);
|
||||||
|
|
Loading…
Reference in a new issue