winlin

refine code for hstrs.

@@ -63,6 +63,9 @@ SrsStreamCache::SrsStreamCache(SrsSource* s, SrsRequest* r) @@ -63,6 +63,9 @@ SrsStreamCache::SrsStreamCache(SrsSource* s, SrsRequest* r)
63 source = s; 63 source = s;
64 queue = new SrsMessageQueue(true); 64 queue = new SrsMessageQueue(true);
65 pthread = new SrsEndlessThread("http-stream", this); 65 pthread = new SrsEndlessThread("http-stream", this);
  66 +
  67 + // TODO: FIXME: support reload.
  68 + fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost);
66 } 69 }
67 70
68 SrsStreamCache::~SrsStreamCache() 71 SrsStreamCache::~SrsStreamCache()
@@ -82,8 +85,6 @@ int SrsStreamCache::dump_cache(SrsConsumer* consumer, SrsRtmpJitterAlgorithm jit @@ -82,8 +85,6 @@ int SrsStreamCache::dump_cache(SrsConsumer* consumer, SrsRtmpJitterAlgorithm jit
82 { 85 {
83 int ret = ERROR_SUCCESS; 86 int ret = ERROR_SUCCESS;
84 87
85 - double fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost);  
86 -  
87 if (fast_cache <= 0) { 88 if (fast_cache <= 0) {
88 srs_info("http: ignore dump fast cache."); 89 srs_info("http: ignore dump fast cache.");
89 return ret; 90 return ret;
@@ -104,6 +105,13 @@ int SrsStreamCache::cycle() @@ -104,6 +105,13 @@ int SrsStreamCache::cycle()
104 { 105 {
105 int ret = ERROR_SUCCESS; 106 int ret = ERROR_SUCCESS;
106 107
  108 + // TODO: FIXME: support reload.
  109 + if (fast_cache <= 0) {
  110 + return ret;
  111 + }
  112 +
  113 + // the stream cache will create consumer to cache stream,
  114 + // which will trigger to fetch stream from origin for edge.
107 SrsConsumer* consumer = NULL; 115 SrsConsumer* consumer = NULL;
108 if ((ret = source->create_consumer(consumer, false, false, true)) != ERROR_SUCCESS) { 116 if ((ret = source->create_consumer(consumer, false, false, true)) != ERROR_SUCCESS) {
109 srs_error("http: create consumer failed. ret=%d", ret); 117 srs_error("http: create consumer failed. ret=%d", ret);
@@ -116,11 +124,9 @@ int SrsStreamCache::cycle() @@ -116,11 +124,9 @@ int SrsStreamCache::cycle()
116 124
117 SrsMessageArray msgs(SRS_PERF_MW_MSGS); 125 SrsMessageArray msgs(SRS_PERF_MW_MSGS);
118 126
  127 + // set the queue size, which used for max cache.
119 // TODO: FIXME: support reload. 128 // TODO: FIXME: support reload.
120 - double fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost);  
121 - if (fast_cache > 0) {  
122 - queue->set_queue_size(fast_cache);  
123 - } 129 + queue->set_queue_size(fast_cache);
124 130
125 while (true) { 131 while (true) {
126 pprint->elapse(); 132 pprint->elapse();
@@ -150,11 +156,7 @@ int SrsStreamCache::cycle() @@ -150,11 +156,7 @@ int SrsStreamCache::cycle()
150 // free the messages. 156 // free the messages.
151 for (int i = 0; i < count; i++) { 157 for (int i = 0; i < count; i++) {
152 SrsSharedPtrMessage* msg = msgs.msgs[i]; 158 SrsSharedPtrMessage* msg = msgs.msgs[i];
153 - if (fast_cache > 0) {  
154 - queue->enqueue(msg);  
155 - } else {  
156 - srs_freep(msg);  
157 - } 159 + queue->enqueue(msg);
158 } 160 }
159 } 161 }
160 162
@@ -42,6 +42,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -42,6 +42,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 class SrsStreamCache : public ISrsEndlessThreadHandler 42 class SrsStreamCache : public ISrsEndlessThreadHandler
43 { 43 {
44 private: 44 private:
  45 + double fast_cache;
  46 +private:
45 SrsMessageQueue* queue; 47 SrsMessageQueue* queue;
46 SrsSource* source; 48 SrsSource* source;
47 SrsRequest* req; 49 SrsRequest* req;