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

View file

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