1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine code for hstrs.

This commit is contained in:
winlin 2015-07-16 18:42:27 +08:00
parent c2ef779523
commit 99db2888e7
2 changed files with 15 additions and 11 deletions

View file

@ -63,6 +63,9 @@ SrsStreamCache::SrsStreamCache(SrsSource* s, SrsRequest* r)
source = s; source = s;
queue = new SrsMessageQueue(true); queue = new SrsMessageQueue(true);
pthread = new SrsEndlessThread("http-stream", this); pthread = new SrsEndlessThread("http-stream", this);
// TODO: FIXME: support reload.
fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost);
} }
SrsStreamCache::~SrsStreamCache() SrsStreamCache::~SrsStreamCache()
@ -82,8 +85,6 @@ int SrsStreamCache::dump_cache(SrsConsumer* consumer, SrsRtmpJitterAlgorithm jit
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
double fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost);
if (fast_cache <= 0) { if (fast_cache <= 0) {
srs_info("http: ignore dump fast cache."); srs_info("http: ignore dump fast cache.");
return ret; return ret;
@ -104,6 +105,13 @@ int SrsStreamCache::cycle()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
// TODO: FIXME: support reload.
if (fast_cache <= 0) {
return ret;
}
// the stream cache will create consumer to cache stream,
// which will trigger to fetch stream from origin for edge.
SrsConsumer* consumer = NULL; SrsConsumer* consumer = NULL;
if ((ret = source->create_consumer(consumer, false, false, true)) != ERROR_SUCCESS) { if ((ret = source->create_consumer(consumer, false, false, true)) != ERROR_SUCCESS) {
srs_error("http: create consumer failed. ret=%d", ret); srs_error("http: create consumer failed. ret=%d", ret);
@ -116,11 +124,9 @@ int SrsStreamCache::cycle()
SrsMessageArray msgs(SRS_PERF_MW_MSGS); SrsMessageArray msgs(SRS_PERF_MW_MSGS);
// set the queue size, which used for max cache.
// TODO: FIXME: support reload. // TODO: FIXME: support reload.
double fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost); queue->set_queue_size(fast_cache);
if (fast_cache > 0) {
queue->set_queue_size(fast_cache);
}
while (true) { while (true) {
pprint->elapse(); pprint->elapse();
@ -150,11 +156,7 @@ int SrsStreamCache::cycle()
// free the messages. // free the messages.
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
SrsSharedPtrMessage* msg = msgs.msgs[i]; SrsSharedPtrMessage* msg = msgs.msgs[i];
if (fast_cache > 0) { queue->enqueue(msg);
queue->enqueue(msg);
} else {
srs_freep(msg);
}
} }
} }

View file

@ -41,6 +41,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
class SrsStreamCache : public ISrsEndlessThreadHandler class SrsStreamCache : public ISrsEndlessThreadHandler
{ {
private:
double fast_cache;
private: private:
SrsMessageQueue* queue; SrsMessageQueue* queue;
SrsSource* source; SrsSource* source;