fix #293, support http live flv/aac/mp3 stream with fast cache. 2.0.100.
正在显示
9 个修改的文件
包含
87 行增加
和
8 行删除
| @@ -515,6 +515,7 @@ Supported operating systems and hardware: | @@ -515,6 +515,7 @@ Supported operating systems and hardware: | ||
| 515 | 515 | ||
| 516 | ## History | 516 | ## History |
| 517 | 517 | ||
| 518 | +* v2.0, 2015-01-19, fix [#293](https://github.com/winlinvip/simple-rtmp-server/issues/293), support http live flv/aac/mp3 stream with fast cache. 2.0.100. | ||
| 518 | * v2.0, 2015-01-18, fix [#293](https://github.com/winlinvip/simple-rtmp-server/issues/293), support rtmp remux to http flv live stream. 2.0.99. | 519 | * v2.0, 2015-01-18, fix [#293](https://github.com/winlinvip/simple-rtmp-server/issues/293), support rtmp remux to http flv live stream. 2.0.99. |
| 519 | * v2.0, 2015-01-17, fix [#277](https://github.com/winlinvip/simple-rtmp-server/issues/277), refine http server refer to go http-framework. 2.0.98 | 520 | * v2.0, 2015-01-17, fix [#277](https://github.com/winlinvip/simple-rtmp-server/issues/277), refine http server refer to go http-framework. 2.0.98 |
| 520 | * v2.0, 2015-01-17, for [#277](https://github.com/winlinvip/simple-rtmp-server/issues/277), refine http api refer to go http-framework. 2.0.97 | 521 | * v2.0, 2015-01-17, for [#277](https://github.com/winlinvip/simple-rtmp-server/issues/277), refine http api refer to go http-framework. 2.0.97 |
| @@ -371,12 +371,21 @@ vhost http.flv.srs.com { | @@ -371,12 +371,21 @@ vhost http.flv.srs.com { | ||
| 371 | # whether enable the http flv live streaming service for vhost. | 371 | # whether enable the http flv live streaming service for vhost. |
| 372 | # default: off | 372 | # default: off |
| 373 | enabled on; | 373 | enabled on; |
| 374 | + # the fast cache for audio stream(mp3/aac), | ||
| 375 | + # to cache more audio and send to client in a time to make android(weixin) happy. | ||
| 376 | + # @remark the flv stream ignore it | ||
| 377 | + # default: 30 | ||
| 378 | + fast_cache 30; | ||
| 374 | # the stream mout for rtmp to remux to flv live streaming. | 379 | # the stream mout for rtmp to remux to flv live streaming. |
| 375 | # for example, if mount to [vhost]/[app]/[stream].flv, user access by http://[vhost]/[app]/[stream].flv | 380 | # for example, if mount to [vhost]/[app]/[stream].flv, user access by http://[vhost]/[app]/[stream].flv |
| 376 | # the variables: | 381 | # the variables: |
| 377 | # [vhost] current vhost for http flv live stream. | 382 | # [vhost] current vhost for http flv live stream. |
| 378 | # [app] current app for http flv live stream. | 383 | # [app] current app for http flv live stream. |
| 379 | # [stream] current stream for http flv live stream. | 384 | # [stream] current stream for http flv live stream. |
| 385 | + # the extension: | ||
| 386 | + # .flv mount http live flv stream, use default gop cache. | ||
| 387 | + # .mp3 mount http live mp3 stream, ignore video and audio mp3 codec required. | ||
| 388 | + # .aac mount http live aac stream, ignore video and audio aac codec required. | ||
| 380 | # default: [vhost]/[app]/[stream].flv | 389 | # default: [vhost]/[app]/[stream].flv |
| 381 | mount [vhost]/[app]/[stream].flv; | 390 | mount [vhost]/[app]/[stream].flv; |
| 382 | } | 391 | } |
trunk/conf/http.aac.live.conf
0 → 100644
| 1 | +# the config for srs to remux rtmp to aac live stream. | ||
| 2 | +# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHttpFlvStream | ||
| 3 | +# @see full.conf for detail config. | ||
| 4 | + | ||
| 5 | +listen 1935; | ||
| 6 | +max_connections 1000; | ||
| 7 | +http_stream { | ||
| 8 | + enabled on; | ||
| 9 | + listen 8080; | ||
| 10 | + dir ./objs/nginx/html; | ||
| 11 | +} | ||
| 12 | +vhost __defaultVhost__ { | ||
| 13 | + http_flv { | ||
| 14 | + enabled on; | ||
| 15 | + fast_cache 30; | ||
| 16 | + mount [vhost]/[app]/[stream].aac; | ||
| 17 | + } | ||
| 18 | +} |
trunk/conf/http.mp3.live.conf
0 → 100644
| 1 | +# the config for srs to remux rtmp to mp3 live stream. | ||
| 2 | +# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHttpFlvStream | ||
| 3 | +# @see full.conf for detail config. | ||
| 4 | + | ||
| 5 | +listen 1935; | ||
| 6 | +max_connections 1000; | ||
| 7 | +http_stream { | ||
| 8 | + enabled on; | ||
| 9 | + listen 8080; | ||
| 10 | + dir ./objs/nginx/html; | ||
| 11 | +} | ||
| 12 | +vhost __defaultVhost__ { | ||
| 13 | + http_flv { | ||
| 14 | + enabled on; | ||
| 15 | + fast_cache 30; | ||
| 16 | + mount [vhost]/[app]/[stream].mp3; | ||
| 17 | + } | ||
| 18 | +} |
| @@ -1426,7 +1426,7 @@ int SrsConfig::check_config() | @@ -1426,7 +1426,7 @@ int SrsConfig::check_config() | ||
| 1426 | } else if (n == "http_flv") { | 1426 | } else if (n == "http_flv") { |
| 1427 | for (int j = 0; j < (int)conf->directives.size(); j++) { | 1427 | for (int j = 0; j < (int)conf->directives.size(); j++) { |
| 1428 | string m = conf->at(j)->name.c_str(); | 1428 | string m = conf->at(j)->name.c_str(); |
| 1429 | - if (m != "enabled" && m != "mount") { | 1429 | + if (m != "enabled" && m != "mount" && m != "fast_cache") { |
| 1430 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 1430 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
| 1431 | srs_error("unsupported vhost http_flv directive %s, ret=%d", m.c_str(), ret); | 1431 | srs_error("unsupported vhost http_flv directive %s, ret=%d", m.c_str(), ret); |
| 1432 | return ret; | 1432 | return ret; |
| @@ -3469,6 +3469,30 @@ bool SrsConfig::get_vhost_http_flv_enabled(string vhost) | @@ -3469,6 +3469,30 @@ bool SrsConfig::get_vhost_http_flv_enabled(string vhost) | ||
| 3469 | return false; | 3469 | return false; |
| 3470 | } | 3470 | } |
| 3471 | 3471 | ||
| 3472 | +double SrsConfig::get_vhost_http_flv_fast_cache(string vhost) | ||
| 3473 | +{ | ||
| 3474 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 3475 | + if (!conf) { | ||
| 3476 | + return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE; | ||
| 3477 | + } | ||
| 3478 | + | ||
| 3479 | + conf = conf->get("http_flv"); | ||
| 3480 | + if (!conf) { | ||
| 3481 | + return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE; | ||
| 3482 | + } | ||
| 3483 | + | ||
| 3484 | + conf = conf->get("fast_cache"); | ||
| 3485 | + if (!conf) { | ||
| 3486 | + return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE; | ||
| 3487 | + } | ||
| 3488 | + | ||
| 3489 | + if (conf->arg0().empty()) { | ||
| 3490 | + return SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE; | ||
| 3491 | + } | ||
| 3492 | + | ||
| 3493 | + return ::atof(conf->arg0().c_str()); | ||
| 3494 | +} | ||
| 3495 | + | ||
| 3472 | string SrsConfig::get_vhost_http_flv_mount(string vhost) | 3496 | string SrsConfig::get_vhost_http_flv_mount(string vhost) |
| 3473 | { | 3497 | { |
| 3474 | SrsConfDirective* conf = get_vhost(vhost); | 3498 | SrsConfDirective* conf = get_vhost(vhost); |
| @@ -68,6 +68,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -68,6 +68,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 68 | #define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/" | 68 | #define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/" |
| 69 | #define SRS_CONF_DEFAULT_HTTP_FLV_MOUNT "[vhost]/[app]/[stream].flv" | 69 | #define SRS_CONF_DEFAULT_HTTP_FLV_MOUNT "[vhost]/[app]/[stream].flv" |
| 70 | #define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH | 70 | #define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH |
| 71 | +#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 30 | ||
| 71 | 72 | ||
| 72 | #define SRS_CONF_DEFAULT_HTTP_STREAM_PORT 8080 | 73 | #define SRS_CONF_DEFAULT_HTTP_STREAM_PORT 8080 |
| 73 | #define SRS_CONF_DEFAULT_HTTP_API_PORT 1985 | 74 | #define SRS_CONF_DEFAULT_HTTP_API_PORT 1985 |
| @@ -971,6 +972,10 @@ public: | @@ -971,6 +972,10 @@ public: | ||
| 971 | */ | 972 | */ |
| 972 | virtual bool get_vhost_http_flv_enabled(std::string vhost); | 973 | virtual bool get_vhost_http_flv_enabled(std::string vhost); |
| 973 | /** | 974 | /** |
| 975 | + * get the fast cache duration for http audio live stream. | ||
| 976 | + */ | ||
| 977 | + virtual double get_vhost_http_flv_fast_cache(std::string vhost); | ||
| 978 | + /** | ||
| 974 | * get the http flv live stream mount point for vhost. | 979 | * get the http flv live stream mount point for vhost. |
| 975 | * used to generate the flv stream mount path. | 980 | * used to generate the flv stream mount path. |
| 976 | */ | 981 | */ |
| @@ -140,8 +140,9 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* | @@ -140,8 +140,9 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* | ||
| 140 | return ret; | 140 | return ret; |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | -SrsStreamCache::SrsStreamCache(SrsSource* s) | 143 | +SrsStreamCache::SrsStreamCache(SrsSource* s, SrsRequest* r) |
| 144 | { | 144 | { |
| 145 | + req = r->copy(); | ||
| 145 | source = s; | 146 | source = s; |
| 146 | queue = new SrsMessageQueue(true); | 147 | queue = new SrsMessageQueue(true); |
| 147 | pthread = new SrsThread("http-stream", this, 0, false); | 148 | pthread = new SrsThread("http-stream", this, 0, false); |
| @@ -153,6 +154,7 @@ SrsStreamCache::~SrsStreamCache() | @@ -153,6 +154,7 @@ SrsStreamCache::~SrsStreamCache() | ||
| 153 | srs_freep(pthread); | 154 | srs_freep(pthread); |
| 154 | 155 | ||
| 155 | srs_freep(queue); | 156 | srs_freep(queue); |
| 157 | + srs_freep(req); | ||
| 156 | } | 158 | } |
| 157 | 159 | ||
| 158 | int SrsStreamCache::start() | 160 | int SrsStreamCache::start() |
| @@ -168,7 +170,8 @@ int SrsStreamCache::dump_cache(SrsConsumer* consumer) | @@ -168,7 +170,8 @@ int SrsStreamCache::dump_cache(SrsConsumer* consumer) | ||
| 168 | return ret; | 170 | return ret; |
| 169 | } | 171 | } |
| 170 | 172 | ||
| 171 | - srs_trace("http: dump cache %d msgs, duration=%dms", queue->size(), queue->duration()); | 173 | + srs_trace("http: dump cache %d msgs, duration=%dms, cache=%.2fs", |
| 174 | + queue->size(), queue->duration(), _srs_config->get_vhost_http_flv_fast_cache(req->vhost)); | ||
| 172 | 175 | ||
| 173 | return ret; | 176 | return ret; |
| 174 | } | 177 | } |
| @@ -187,8 +190,8 @@ int SrsStreamCache::cycle() | @@ -187,8 +190,8 @@ int SrsStreamCache::cycle() | ||
| 187 | SrsMessageArray msgs(SRS_PERF_MW_MSGS); | 190 | SrsMessageArray msgs(SRS_PERF_MW_MSGS); |
| 188 | // TODO: FIMXE: add pithy print. | 191 | // TODO: FIMXE: add pithy print. |
| 189 | 192 | ||
| 190 | - // TODO: FIXME: config it. | ||
| 191 | - queue->set_queue_size(60); | 193 | + // TODO: FIXME: support reload. |
| 194 | + queue->set_queue_size(_srs_config->get_vhost_http_flv_fast_cache(req->vhost)); | ||
| 192 | 195 | ||
| 193 | while (true) { | 196 | while (true) { |
| 194 | // get messages from consumer. | 197 | // get messages from consumer. |
| @@ -616,7 +619,7 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r) | @@ -616,7 +619,7 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r) | ||
| 616 | // remove the default vhost mount | 619 | // remove the default vhost mount |
| 617 | mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/"); | 620 | mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/"); |
| 618 | 621 | ||
| 619 | - entry->cache = new SrsStreamCache(s); | 622 | + entry->cache = new SrsStreamCache(s, r); |
| 620 | entry->stream = new SrsLiveStream(s, r, entry->cache); | 623 | entry->stream = new SrsLiveStream(s, r, entry->cache); |
| 621 | 624 | ||
| 622 | // start http stream cache thread | 625 | // start http stream cache thread |
| @@ -77,9 +77,10 @@ class SrsStreamCache : public ISrsThreadHandler | @@ -77,9 +77,10 @@ class SrsStreamCache : public ISrsThreadHandler | ||
| 77 | private: | 77 | private: |
| 78 | SrsMessageQueue* queue; | 78 | SrsMessageQueue* queue; |
| 79 | SrsSource* source; | 79 | SrsSource* source; |
| 80 | + SrsRequest* req; | ||
| 80 | SrsThread* pthread; | 81 | SrsThread* pthread; |
| 81 | public: | 82 | public: |
| 82 | - SrsStreamCache(SrsSource* s); | 83 | + SrsStreamCache(SrsSource* s, SrsRequest* r); |
| 83 | virtual ~SrsStreamCache(); | 84 | virtual ~SrsStreamCache(); |
| 84 | public: | 85 | public: |
| 85 | virtual int start(); | 86 | virtual int start(); |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 99 | 34 | +#define VERSION_REVISION 100 |
| 35 | 35 | ||
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
-
请 注册 或 登录 后发表评论