正在显示
6 个修改的文件
包含
46 行增加
和
12 行删除
| @@ -212,6 +212,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw | @@ -212,6 +212,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw | ||
| 212 | * nginx v1.5.0: 139524 lines <br/> | 212 | * nginx v1.5.0: 139524 lines <br/> |
| 213 | 213 | ||
| 214 | ### History | 214 | ### History |
| 215 | +* v0.9, 2013-12-15, fix the hls reload bug, feed it the sequence header. | ||
| 215 | * v0.9, 2013-12-15, refine protocol, use int64_t timestamp for ts and jitter. | 216 | * v0.9, 2013-12-15, refine protocol, use int64_t timestamp for ts and jitter. |
| 216 | * v0.9, 2013-12-15, support set the live queue length(in seconds), drop when full. | 217 | * v0.9, 2013-12-15, support set the live queue length(in seconds), drop when full. |
| 217 | * v0.9, 2013-12-15, fix the forwarder reconnect bug, feed it the sequence header. | 218 | * v0.9, 2013-12-15, fix the forwarder reconnect bug, feed it the sequence header. |
| @@ -96,7 +96,7 @@ vhost dev { | @@ -96,7 +96,7 @@ vhost dev { | ||
| 96 | queue_length 10; | 96 | queue_length 10; |
| 97 | forward 127.0.0.1:19350; | 97 | forward 127.0.0.1:19350; |
| 98 | hls { | 98 | hls { |
| 99 | - enabled off; | 99 | + enabled on; |
| 100 | hls_path ./objs/nginx/html; | 100 | hls_path ./objs/nginx/html; |
| 101 | hls_fragment 5; | 101 | hls_fragment 5; |
| 102 | hls_window 30; | 102 | hls_window 30; |
| @@ -1109,10 +1109,11 @@ int SrsTSCache::cache_video(SrsCodec* codec, SrsCodecSample* sample) | @@ -1109,10 +1109,11 @@ int SrsTSCache::cache_video(SrsCodec* codec, SrsCodecSample* sample) | ||
| 1109 | return ret; | 1109 | return ret; |
| 1110 | } | 1110 | } |
| 1111 | 1111 | ||
| 1112 | -SrsHls::SrsHls() | 1112 | +SrsHls::SrsHls(SrsSource* _source) |
| 1113 | { | 1113 | { |
| 1114 | hls_enabled = false; | 1114 | hls_enabled = false; |
| 1115 | 1115 | ||
| 1116 | + source = _source; | ||
| 1116 | codec = new SrsCodec(); | 1117 | codec = new SrsCodec(); |
| 1117 | sample = new SrsCodecSample(); | 1118 | sample = new SrsCodecSample(); |
| 1118 | jitter = new SrsRtmpJitter(); | 1119 | jitter = new SrsRtmpJitter(); |
| @@ -1171,6 +1172,12 @@ int SrsHls::on_publish(SrsRequest* req) | @@ -1171,6 +1172,12 @@ int SrsHls::on_publish(SrsRequest* req) | ||
| 1171 | srs_error("m3u8 muxer open segment failed. ret=%d", ret); | 1172 | srs_error("m3u8 muxer open segment failed. ret=%d", ret); |
| 1172 | return ret; | 1173 | return ret; |
| 1173 | } | 1174 | } |
| 1175 | + | ||
| 1176 | + // notice the source to get the cached sequence header. | ||
| 1177 | + if ((ret = source->on_hls_start()) != ERROR_SUCCESS) { | ||
| 1178 | + srs_error("callback source hls start failed. ret=%d", ret); | ||
| 1179 | + return ret; | ||
| 1180 | + } | ||
| 1174 | 1181 | ||
| 1175 | return ret; | 1182 | return ret; |
| 1176 | } | 1183 | } |
| @@ -1195,16 +1202,16 @@ void SrsHls::on_unpublish() | @@ -1195,16 +1202,16 @@ void SrsHls::on_unpublish() | ||
| 1195 | hls_enabled = false; | 1202 | hls_enabled = false; |
| 1196 | } | 1203 | } |
| 1197 | 1204 | ||
| 1198 | -int SrsHls::on_meta_data(SrsOnMetaDataPacket* metadata) | 1205 | +int SrsHls::on_meta_data(SrsAmf0Object* metadata) |
| 1199 | { | 1206 | { |
| 1200 | int ret = ERROR_SUCCESS; | 1207 | int ret = ERROR_SUCCESS; |
| 1201 | 1208 | ||
| 1202 | - if (!metadata || !metadata->metadata) { | 1209 | + if (!metadata) { |
| 1203 | srs_trace("no metadata persent, hls ignored it."); | 1210 | srs_trace("no metadata persent, hls ignored it."); |
| 1204 | return ret; | 1211 | return ret; |
| 1205 | } | 1212 | } |
| 1206 | 1213 | ||
| 1207 | - SrsAmf0Object* obj = metadata->metadata; | 1214 | + SrsAmf0Object* obj = metadata; |
| 1208 | if (obj->size() <= 0) { | 1215 | if (obj->size() <= 0) { |
| 1209 | srs_trace("no metadata persent, hls ignored it."); | 1216 | srs_trace("no metadata persent, hls ignored it."); |
| 1210 | return ret; | 1217 | return ret; |
| @@ -34,16 +34,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,16 +34,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 34 | #include <string> | 34 | #include <string> |
| 35 | #include <vector> | 35 | #include <vector> |
| 36 | 36 | ||
| 37 | -class SrsOnMetaDataPacket; | ||
| 38 | class SrsSharedPtrMessage; | 37 | class SrsSharedPtrMessage; |
| 39 | class SrsCodecSample; | 38 | class SrsCodecSample; |
| 40 | class SrsCodecBuffer; | 39 | class SrsCodecBuffer; |
| 41 | class SrsMpegtsFrame; | 40 | class SrsMpegtsFrame; |
| 41 | +class SrsAmf0Object; | ||
| 42 | class SrsRtmpJitter; | 42 | class SrsRtmpJitter; |
| 43 | class SrsTSMuxer; | 43 | class SrsTSMuxer; |
| 44 | class SrsCodec; | 44 | class SrsCodec; |
| 45 | class SrsRequest; | 45 | class SrsRequest; |
| 46 | class SrsPithyPrint; | 46 | class SrsPithyPrint; |
| 47 | +class SrsSource; | ||
| 47 | 48 | ||
| 48 | /** | 49 | /** |
| 49 | * jitter correct for audio, | 50 | * jitter correct for audio, |
| @@ -207,17 +208,18 @@ private: | @@ -207,17 +208,18 @@ private: | ||
| 207 | SrsTSCache* ts_cache; | 208 | SrsTSCache* ts_cache; |
| 208 | private: | 209 | private: |
| 209 | bool hls_enabled; | 210 | bool hls_enabled; |
| 211 | + SrsSource* source; | ||
| 210 | SrsCodec* codec; | 212 | SrsCodec* codec; |
| 211 | SrsCodecSample* sample; | 213 | SrsCodecSample* sample; |
| 212 | SrsRtmpJitter* jitter; | 214 | SrsRtmpJitter* jitter; |
| 213 | SrsPithyPrint* pithy_print; | 215 | SrsPithyPrint* pithy_print; |
| 214 | public: | 216 | public: |
| 215 | - SrsHls(); | 217 | + SrsHls(SrsSource* _source); |
| 216 | virtual ~SrsHls(); | 218 | virtual ~SrsHls(); |
| 217 | public: | 219 | public: |
| 218 | virtual int on_publish(SrsRequest* req); | 220 | virtual int on_publish(SrsRequest* req); |
| 219 | virtual void on_unpublish(); | 221 | virtual void on_unpublish(); |
| 220 | - virtual int on_meta_data(SrsOnMetaDataPacket* metadata); | 222 | + virtual int on_meta_data(SrsAmf0Object* metadata); |
| 221 | virtual int on_audio(SrsSharedPtrMessage* audio); | 223 | virtual int on_audio(SrsSharedPtrMessage* audio); |
| 222 | virtual int on_video(SrsSharedPtrMessage* video); | 224 | virtual int on_video(SrsSharedPtrMessage* video); |
| 223 | private: | 225 | private: |
| @@ -410,7 +410,7 @@ SrsSource::SrsSource(SrsRequest* _req) | @@ -410,7 +410,7 @@ SrsSource::SrsSource(SrsRequest* _req) | ||
| 410 | req = _req->copy(); | 410 | req = _req->copy(); |
| 411 | 411 | ||
| 412 | #ifdef SRS_HLS | 412 | #ifdef SRS_HLS |
| 413 | - hls = new SrsHls(); | 413 | + hls = new SrsHls(this); |
| 414 | #endif | 414 | #endif |
| 415 | #ifdef SRS_FFMPEG | 415 | #ifdef SRS_FFMPEG |
| 416 | encoder = new SrsEncoder(); | 416 | encoder = new SrsEncoder(); |
| @@ -553,7 +553,6 @@ int SrsSource::on_reload_hls(string vhost) | @@ -553,7 +553,6 @@ int SrsSource::on_reload_hls(string vhost) | ||
| 553 | srs_error("hls publish failed. ret=%d", ret); | 553 | srs_error("hls publish failed. ret=%d", ret); |
| 554 | return ret; | 554 | return ret; |
| 555 | } | 555 | } |
| 556 | - // TODO: FIXME: must feed it the sequence header. | ||
| 557 | srs_trace("vhost %s hls reload success", vhost.c_str()); | 556 | srs_trace("vhost %s hls reload success", vhost.c_str()); |
| 558 | #endif | 557 | #endif |
| 559 | 558 | ||
| @@ -602,6 +601,29 @@ int SrsSource::on_forwarder_start(SrsForwarder* forwarder) | @@ -602,6 +601,29 @@ int SrsSource::on_forwarder_start(SrsForwarder* forwarder) | ||
| 602 | return ret; | 601 | return ret; |
| 603 | } | 602 | } |
| 604 | 603 | ||
| 604 | +int SrsSource::on_hls_start() | ||
| 605 | +{ | ||
| 606 | + int ret = ERROR_SUCCESS; | ||
| 607 | + | ||
| 608 | +#ifdef SRS_HLS | ||
| 609 | + | ||
| 610 | + // feed the hls the metadata/sequence header, | ||
| 611 | + // when reload to enable the hls. | ||
| 612 | + // TODO: maybe need to decode the metadata? | ||
| 613 | + if (cache_sh_video && (ret = hls->on_video(cache_sh_video->copy())) != ERROR_SUCCESS) { | ||
| 614 | + srs_error("hls process video sequence header message failed. ret=%d", ret); | ||
| 615 | + return ret; | ||
| 616 | + } | ||
| 617 | + if (cache_sh_audio && (ret = hls->on_audio(cache_sh_audio->copy())) != ERROR_SUCCESS) { | ||
| 618 | + srs_error("hls process audio sequence header message failed. ret=%d", ret); | ||
| 619 | + return ret; | ||
| 620 | + } | ||
| 621 | + | ||
| 622 | +#endif | ||
| 623 | + | ||
| 624 | + return ret; | ||
| 625 | +} | ||
| 626 | + | ||
| 605 | bool SrsSource::can_publish() | 627 | bool SrsSource::can_publish() |
| 606 | { | 628 | { |
| 607 | return _can_publish; | 629 | return _can_publish; |
| @@ -612,7 +634,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | @@ -612,7 +634,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | ||
| 612 | int ret = ERROR_SUCCESS; | 634 | int ret = ERROR_SUCCESS; |
| 613 | 635 | ||
| 614 | #ifdef SRS_HLS | 636 | #ifdef SRS_HLS |
| 615 | - if ((ret = hls->on_meta_data(metadata)) != ERROR_SUCCESS) { | 637 | + if (metadata && (ret = hls->on_meta_data(metadata->metadata)) != ERROR_SUCCESS) { |
| 616 | srs_error("hls process onMetaData message failed. ret=%d", ret); | 638 | srs_error("hls process onMetaData message failed. ret=%d", ret); |
| 617 | return ret; | 639 | return ret; |
| 618 | } | 640 | } |
| @@ -257,9 +257,11 @@ public: | @@ -257,9 +257,11 @@ public: | ||
| 257 | virtual int on_reload_forward(std::string vhost); | 257 | virtual int on_reload_forward(std::string vhost); |
| 258 | virtual int on_reload_hls(std::string vhost); | 258 | virtual int on_reload_hls(std::string vhost); |
| 259 | virtual int on_reload_transcode(std::string vhost); | 259 | virtual int on_reload_transcode(std::string vhost); |
| 260 | -// for the SrsForwarder to callback to request the sequence headers. | ||
| 261 | public: | 260 | public: |
| 261 | + // for the SrsForwarder to callback to request the sequence headers. | ||
| 262 | virtual int on_forwarder_start(SrsForwarder* forwarder); | 262 | virtual int on_forwarder_start(SrsForwarder* forwarder); |
| 263 | + // for the SrsHls to callback to request the sequence headers. | ||
| 264 | + virtual int on_hls_start(); | ||
| 263 | public: | 265 | public: |
| 264 | virtual bool can_publish(); | 266 | virtual bool can_publish(); |
| 265 | virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); | 267 | virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); |
-
请 注册 或 登录 后发表评论