From 7d86c6d9e94cffd8278f86bbe0dab993e81649c0 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 22 Jan 2015 13:16:54 +0800 Subject: [PATCH] for bug #293, refine for fast cache of http stream. --- trunk/conf/full.conf | 3 ++- trunk/src/app/srs_app_config.hpp | 2 +- trunk/src/app/srs_app_http_conn.cpp | 21 ++++++++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index ad4307eb2e..f3c65620b6 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -387,7 +387,8 @@ vhost http.remux.srs.com { # the fast cache for audio stream(mp3/aac), # to cache more audio and send to client in a time to make android(weixin) happy. # @remark the flv stream ignore it - # default: 30 + # @remark 0 to disable fast cache for http audio stream. + # default: 0 fast_cache 30; # the stream mout for rtmp to remux to flv live streaming. # typical mount to [vhost]/[app]/[stream].flv diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index f89f66dbaa..2111a9dba6 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -68,7 +68,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SRS_CONF_DEFAULT_HTTP_MOUNT "[vhost]/" #define SRS_CONF_DEFAULT_HTTP_REMUX_MOUNT "[vhost]/[app]/[stream].flv" #define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH -#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 30 +#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0 #define SRS_CONF_DEFAULT_HTTP_STREAM_PORT 8080 #define SRS_CONF_DEFAULT_HTTP_API_PORT 1985 diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index c95ace46fd..6812210a40 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -165,13 +165,21 @@ int SrsStreamCache::start() int SrsStreamCache::dump_cache(SrsConsumer* consumer) { int ret = ERROR_SUCCESS; + + double fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost); + + if (fast_cache <= 0) { + srs_info("http: ignore dump fast cache."); + return ret; + } + // TODO: FIXME: config it. if ((ret = queue->dump_packets(consumer, false, 0, 0, SrsRtmpJitterAlgorithmOFF)) != ERROR_SUCCESS) { return ret; } srs_trace("http: dump cache %d msgs, duration=%dms, cache=%.2fs", - queue->size(), queue->duration(), _srs_config->get_vhost_http_remux_fast_cache(req->vhost)); + queue->size(), queue->duration(), fast_cache); return ret; } @@ -191,7 +199,10 @@ int SrsStreamCache::cycle() // TODO: FIMXE: add pithy print. // TODO: FIXME: support reload. - queue->set_queue_size(_srs_config->get_vhost_http_remux_fast_cache(req->vhost)); + double fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost); + if (fast_cache > 0) { + queue->set_queue_size(fast_cache); + } while (true) { // get messages from consumer. @@ -216,7 +227,11 @@ int SrsStreamCache::cycle() // free the messages. for (int i = 0; i < count; i++) { SrsSharedPtrMessage* msg = msgs.msgs[i]; - queue->enqueue(msg); + if (fast_cache > 0) { + queue->enqueue(msg); + } else { + srs_freep(msg); + } } }