winlin

Merge branch '2.0release' into develop

@@ -41,6 +41,7 @@ SrsConnection::SrsConnection(IConnectionManager* cm, st_netfd_t c) @@ -41,6 +41,7 @@ SrsConnection::SrsConnection(IConnectionManager* cm, st_netfd_t c)
41 manager = cm; 41 manager = cm;
42 stfd = c; 42 stfd = c;
43 disposed = false; 43 disposed = false;
  44 + expired = false;
44 45
45 // the client thread should reap itself, 46 // the client thread should reap itself,
46 // so we never use joinable. 47 // so we never use joinable.
@@ -116,4 +117,9 @@ int SrsConnection::srs_id() @@ -116,4 +117,9 @@ int SrsConnection::srs_id()
116 return id; 117 return id;
117 } 118 }
118 119
  120 +void SrsConnection::expire()
  121 +{
  122 + expired = true;
  123 +}
  124 +
119 125
@@ -88,6 +88,11 @@ protected: @@ -88,6 +88,11 @@ protected:
88 * when disposed, connection should stop cycle and cleanup itself. 88 * when disposed, connection should stop cycle and cleanup itself.
89 */ 89 */
90 bool disposed; 90 bool disposed;
  91 + /**
  92 + * whether connection is expired, application definition.
  93 + * when expired, the connection must never be served and quit ASAP.
  94 + */
  95 + bool expired;
91 public: 96 public:
92 SrsConnection(IConnectionManager* cm, st_netfd_t c); 97 SrsConnection(IConnectionManager* cm, st_netfd_t c);
93 virtual ~SrsConnection(); 98 virtual ~SrsConnection();
@@ -125,6 +130,10 @@ public: @@ -125,6 +130,10 @@ public:
125 * get the srs id which identify the client. 130 * get the srs id which identify the client.
126 */ 131 */
127 virtual int srs_id(); 132 virtual int srs_id();
  133 + /**
  134 + * set connection to expired.
  135 + */
  136 + virtual void expire();
128 protected: 137 protected:
129 /** 138 /**
130 * for concrete connection to do the cycle. 139 * for concrete connection to do the cycle.
@@ -660,22 +660,8 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -660,22 +660,8 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
660 srs_error("stream stream_id=%d not found. ret=%d", sid, ret); 660 srs_error("stream stream_id=%d not found. ret=%d", sid, ret);
661 return srs_http_response_code(w, ret); 661 return srs_http_response_code(w, ret);
662 } 662 }
663 -  
664 - if (r->is_http_delete()) {  
665 - srs_assert(stream);  
666 -  
667 - SrsSource* source = SrsSource::fetch(stream->vhost->vhost, stream->app, stream->stream);  
668 - if (!source) {  
669 - ret = ERROR_SOURCE_NOT_FOUND;  
670 - srs_warn("source not found for sid=%d", sid);  
671 - return srs_http_response_code(w, ret);  
672 - }  
673 -  
674 - source->set_expired();  
675 - srs_warn("disconnent stream=%d successfully. vhost=%s, app=%s, stream=%s.",  
676 - sid, stream->vhost->vhost.c_str(), stream->app.c_str(), stream->stream.c_str());  
677 - return srs_http_response_code(w, ret);  
678 - } else if (r->is_http_get()) { 663 +
  664 + if (r->is_http_get()) {
679 std::stringstream data; 665 std::stringstream data;
680 666
681 if (!stream) { 667 if (!stream) {
@@ -726,10 +712,15 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -726,10 +712,15 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
726 ret = ERROR_RTMP_STREAM_NOT_FOUND; 712 ret = ERROR_RTMP_STREAM_NOT_FOUND;
727 srs_error("stream client_id=%d not found. ret=%d", cid, ret); 713 srs_error("stream client_id=%d not found. ret=%d", cid, ret);
728 return srs_http_response_code(w, ret); 714 return srs_http_response_code(w, ret);
729 -  
730 } 715 }
731 716
732 - if (r->is_http_get()) { 717 + if (r->is_http_delete()) {
  718 + srs_assert(client);
  719 +
  720 + client->conn->expire();
  721 + srs_warn("delete client=%d ok", cid);
  722 + return srs_http_response_code(w, ret);
  723 + } else if (r->is_http_get()) {
733 std::stringstream data; 724 std::stringstream data;
734 725
735 if (!client) { 726 if (!client) {
@@ -751,6 +742,8 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -751,6 +742,8 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
751 } 742 }
752 743
753 return srs_http_response_json(w, ss.str()); 744 return srs_http_response_json(w, ss.str());
  745 + } else {
  746 + return srs_go_http_error(w, SRS_CONSTS_HTTP_MethodNotAllowed);
754 } 747 }
755 748
756 return ret; 749 return ret;
@@ -495,7 +495,7 @@ int SrsRtmpConn::stream_service_cycle() @@ -495,7 +495,7 @@ int SrsRtmpConn::stream_service_cycle()
495 495
496 // update the statistic when source disconveried. 496 // update the statistic when source disconveried.
497 SrsStatistic* stat = SrsStatistic::instance(); 497 SrsStatistic* stat = SrsStatistic::instance();
498 - if ((ret = stat->on_client(_srs_context->get_id(), req)) != ERROR_SUCCESS) { 498 + if ((ret = stat->on_client(_srs_context->get_id(), req, this, type)) != ERROR_SUCCESS) {
499 srs_error("stat client failed. ret=%d", ret); 499 srs_error("stat client failed. ret=%d", ret);
500 return ret; 500 return ret;
501 } 501 }
@@ -671,6 +671,13 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe @@ -671,6 +671,13 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
671 while (!disposed) { 671 while (!disposed) {
672 // collect elapse for pithy print. 672 // collect elapse for pithy print.
673 pprint->elapse(); 673 pprint->elapse();
  674 +
  675 + // when source is set to expired, disconnect it.
  676 + if (expired) {
  677 + ret = ERROR_USER_DISCONNECT;
  678 + srs_error("connection expired. ret=%d", ret);
  679 + return ret;
  680 + }
674 681
675 // to use isolate thread to recv, can improve about 33% performance. 682 // to use isolate thread to recv, can improve about 33% performance.
676 // @see: https://github.com/simple-rtmp-server/srs/issues/196 683 // @see: https://github.com/simple-rtmp-server/srs/issues/196
@@ -875,9 +882,9 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) @@ -875,9 +882,9 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd)
875 pprint->elapse(); 882 pprint->elapse();
876 883
877 // when source is set to expired, disconnect it. 884 // when source is set to expired, disconnect it.
878 - if (source->expired()) { 885 + if (expired) {
879 ret = ERROR_USER_DISCONNECT; 886 ret = ERROR_USER_DISCONNECT;
880 - srs_error("source is expired. ret=%d", ret); 887 + srs_error("connection expired. ret=%d", ret);
881 return ret; 888 return ret;
882 } 889 }
883 890
@@ -898,7 +898,6 @@ SrsSource::SrsSource() @@ -898,7 +898,6 @@ SrsSource::SrsSource()
898 jitter_algorithm = SrsRtmpJitterAlgorithmOFF; 898 jitter_algorithm = SrsRtmpJitterAlgorithmOFF;
899 mix_correct = false; 899 mix_correct = false;
900 mix_queue = new SrsMixQueue(); 900 mix_queue = new SrsMixQueue();
901 - is_expired = false;  
902 901
903 #ifdef SRS_AUTO_HLS 902 #ifdef SRS_AUTO_HLS
904 hls = new SrsHls(); 903 hls = new SrsHls();
@@ -2066,7 +2065,7 @@ int SrsSource::on_publish() @@ -2066,7 +2065,7 @@ int SrsSource::on_publish()
2066 return ret; 2065 return ret;
2067 } 2066 }
2068 SrsStatistic* stat = SrsStatistic::instance(); 2067 SrsStatistic* stat = SrsStatistic::instance();
2069 - stat->on_stream_publish(_req); 2068 + stat->on_stream_publish(_req, _source_id);
2070 return ret; 2069 return ret;
2071 } 2070 }
2072 2071
@@ -2101,7 +2100,6 @@ void SrsSource::on_unpublish() @@ -2101,7 +2100,6 @@ void SrsSource::on_unpublish()
2101 2100
2102 _can_publish = true; 2101 _can_publish = true;
2103 _source_id = -1; 2102 _source_id = -1;
2104 - is_expired = false;  
2105 2103
2106 // notify the handler. 2104 // notify the handler.
2107 srs_assert(handler); 2105 srs_assert(handler);
@@ -2260,13 +2258,3 @@ void SrsSource::destroy_forwarders() @@ -2260,13 +2258,3 @@ void SrsSource::destroy_forwarders()
2260 forwarders.clear(); 2258 forwarders.clear();
2261 } 2259 }
2262 2260
2263 -bool SrsSource::expired()  
2264 -{  
2265 - return is_expired;  
2266 -}  
2267 -  
2268 -void SrsSource::set_expired()  
2269 -{  
2270 - is_expired = true;  
2271 -}  
2272 -  
@@ -453,8 +453,6 @@ private: @@ -453,8 +453,6 @@ private:
453 // whether use interlaced/mixed algorithm to correct timestamp. 453 // whether use interlaced/mixed algorithm to correct timestamp.
454 bool mix_correct; 454 bool mix_correct;
455 SrsMixQueue* mix_queue; 455 SrsMixQueue* mix_queue;
456 - // the flag of source expired or not.  
457 - bool is_expired;  
458 // whether stream is monotonically increase. 456 // whether stream is monotonically increase.
459 bool is_monotonically_increase; 457 bool is_monotonically_increase;
460 int64_t last_packet_time; 458 int64_t last_packet_time;
@@ -586,12 +584,6 @@ public: @@ -586,12 +584,6 @@ public:
586 private: 584 private:
587 virtual int create_forwarders(); 585 virtual int create_forwarders();
588 virtual void destroy_forwarders(); 586 virtual void destroy_forwarders();
589 -public:  
590 - virtual bool expired();  
591 - /**  
592 - * set source expired.  
593 - */  
594 - virtual void set_expired();  
595 }; 587 };
596 588
597 #endif 589 #endif
@@ -72,8 +72,8 @@ int SrsStatisticVhost::dumps(stringstream& ss) @@ -72,8 +72,8 @@ int SrsStatisticVhost::dumps(stringstream& ss)
72 << SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT 72 << SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT
73 << SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT 73 << SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT
74 << SRS_JFIELD_OBJ("kbps") 74 << SRS_JFIELD_OBJ("kbps")
75 - << SRS_JFIELD_ORG("r30s", kbps->get_recv_kbps_30s()) << SRS_JFIELD_CONT  
76 - << SRS_JFIELD_ORG("s30s", kbps->get_send_kbps_30s()) 75 + << SRS_JFIELD_ORG("recv_30s", kbps->get_recv_kbps_30s()) << SRS_JFIELD_CONT
  76 + << SRS_JFIELD_ORG("send_30s", kbps->get_send_kbps_30s())
77 << SRS_JOBJECT_END << SRS_JFIELD_CONT 77 << SRS_JOBJECT_END << SRS_JFIELD_CONT
78 << SRS_JFIELD_NAME("hls") << SRS_JOBJECT_START 78 << SRS_JFIELD_NAME("hls") << SRS_JOBJECT_START
79 << SRS_JFIELD_BOOL("enabled", hls_enabled); 79 << SRS_JFIELD_BOOL("enabled", hls_enabled);
@@ -91,7 +91,8 @@ SrsStatisticStream::SrsStatisticStream() @@ -91,7 +91,8 @@ SrsStatisticStream::SrsStatisticStream()
91 { 91 {
92 id = srs_generate_id(); 92 id = srs_generate_id();
93 vhost = NULL; 93 vhost = NULL;
94 - status = STATISTIC_STREAM_STATUS_IDLING; 94 + active = false;
  95 + connection_cid = -1;
95 96
96 has_video = false; 97 has_video = false;
97 vcodec = SrsCodecVideoReserved; 98 vcodec = SrsCodecVideoReserved;
@@ -124,15 +125,18 @@ int SrsStatisticStream::dumps(stringstream& ss) @@ -124,15 +125,18 @@ int SrsStatisticStream::dumps(stringstream& ss)
124 << SRS_JFIELD_STR("name", stream) << SRS_JFIELD_CONT 125 << SRS_JFIELD_STR("name", stream) << SRS_JFIELD_CONT
125 << SRS_JFIELD_ORG("vhost", vhost->id) << SRS_JFIELD_CONT 126 << SRS_JFIELD_ORG("vhost", vhost->id) << SRS_JFIELD_CONT
126 << SRS_JFIELD_STR("app", app) << SRS_JFIELD_CONT 127 << SRS_JFIELD_STR("app", app) << SRS_JFIELD_CONT
  128 + << SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT
127 << SRS_JFIELD_ORG("clients", nb_clients) << SRS_JFIELD_CONT 129 << SRS_JFIELD_ORG("clients", nb_clients) << SRS_JFIELD_CONT
128 << SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT 130 << SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT
129 << SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT 131 << SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT
130 << SRS_JFIELD_OBJ("kbps") 132 << SRS_JFIELD_OBJ("kbps")
131 - << SRS_JFIELD_ORG("r30s", kbps->get_recv_kbps_30s()) << SRS_JFIELD_CONT  
132 - << SRS_JFIELD_ORG("s30s", kbps->get_send_kbps_30s()) 133 + << SRS_JFIELD_ORG("recv_30s", kbps->get_recv_kbps_30s()) << SRS_JFIELD_CONT
  134 + << SRS_JFIELD_ORG("send_30s", kbps->get_send_kbps_30s())
133 << SRS_JOBJECT_END << SRS_JFIELD_CONT 135 << SRS_JOBJECT_END << SRS_JFIELD_CONT
134 - << SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT  
135 - << SRS_JFIELD_STR("status", status) << SRS_JFIELD_CONT; 136 + << SRS_JFIELD_OBJ("publish")
  137 + << SRS_JFIELD_BOOL("active", active) << SRS_JFIELD_CONT
  138 + << SRS_JFIELD_ORG("cid", connection_cid)
  139 + << SRS_JOBJECT_END << SRS_JFIELD_CONT;
136 140
137 if (!has_video) { 141 if (!has_video) {
138 ss << SRS_JFIELD_NULL("video") << SRS_JFIELD_CONT; 142 ss << SRS_JFIELD_NULL("video") << SRS_JFIELD_CONT;
@@ -161,21 +165,27 @@ int SrsStatisticStream::dumps(stringstream& ss) @@ -161,21 +165,27 @@ int SrsStatisticStream::dumps(stringstream& ss)
161 return ret; 165 return ret;
162 } 166 }
163 167
164 -void SrsStatisticStream::publish() 168 +void SrsStatisticStream::publish(int cid)
165 { 169 {
166 - status = STATISTIC_STREAM_STATUS_PUBLISHING; 170 + connection_cid = cid;
  171 + active = true;
167 } 172 }
168 173
169 void SrsStatisticStream::close() 174 void SrsStatisticStream::close()
170 { 175 {
171 has_video = false; 176 has_video = false;
172 has_audio = false; 177 has_audio = false;
173 - status = STATISTIC_STREAM_STATUS_IDLING; 178 + active = false;
174 } 179 }
175 180
176 SrsStatisticClient::SrsStatisticClient() 181 SrsStatisticClient::SrsStatisticClient()
177 { 182 {
178 id = 0; 183 id = 0;
  184 + stream = NULL;
  185 + conn = NULL;
  186 + req = NULL;
  187 + type = SrsRtmpConnUnknown;
  188 + create = srs_get_system_time_ms();
179 } 189 }
180 190
181 SrsStatisticClient::~SrsStatisticClient() 191 SrsStatisticClient::~SrsStatisticClient()
@@ -187,7 +197,17 @@ int SrsStatisticClient::dumps(stringstream& ss) @@ -187,7 +197,17 @@ int SrsStatisticClient::dumps(stringstream& ss)
187 int ret = ERROR_SUCCESS; 197 int ret = ERROR_SUCCESS;
188 198
189 ss << SRS_JOBJECT_START 199 ss << SRS_JOBJECT_START
190 - << SRS_JFIELD_ORG("id", id) 200 + << SRS_JFIELD_ORG("id", id) << SRS_JFIELD_CONT
  201 + << SRS_JFIELD_ORG("vhost", stream->vhost->id) << SRS_JFIELD_CONT
  202 + << SRS_JFIELD_ORG("stream", stream->id) << SRS_JFIELD_CONT
  203 + << SRS_JFIELD_STR("ip", req->ip) << SRS_JFIELD_CONT
  204 + << SRS_JFIELD_STR("pageUrl", req->pageUrl) << SRS_JFIELD_CONT
  205 + << SRS_JFIELD_STR("swfUrl", req->swfUrl) << SRS_JFIELD_CONT
  206 + << SRS_JFIELD_STR("tcUrl", req->tcUrl) << SRS_JFIELD_CONT
  207 + << SRS_JFIELD_STR("url", req->get_stream_url()) << SRS_JFIELD_CONT
  208 + << SRS_JFIELD_STR("type", srs_client_type_string(type)) << SRS_JFIELD_CONT
  209 + << SRS_JFIELD_BOOL("publish", srs_client_type_is_publish(type)) << SRS_JFIELD_CONT
  210 + << SRS_JFIELD_ORG("alive", srs_get_system_time_ms() - create)
191 << SRS_JOBJECT_END; 211 << SRS_JOBJECT_END;
192 212
193 return ret; 213 return ret;
@@ -301,12 +321,12 @@ int SrsStatistic::on_audio_info(SrsRequest* req, @@ -301,12 +321,12 @@ int SrsStatistic::on_audio_info(SrsRequest* req,
301 return ret; 321 return ret;
302 } 322 }
303 323
304 -void SrsStatistic::on_stream_publish(SrsRequest* req) 324 +void SrsStatistic::on_stream_publish(SrsRequest* req, int cid)
305 { 325 {
306 SrsStatisticVhost* vhost = create_vhost(req); 326 SrsStatisticVhost* vhost = create_vhost(req);
307 SrsStatisticStream* stream = create_stream(vhost, req); 327 SrsStatisticStream* stream = create_stream(vhost, req);
308 328
309 - stream->publish(); 329 + stream->publish(cid);
310 } 330 }
311 331
312 void SrsStatistic::on_stream_close(SrsRequest* req) 332 void SrsStatistic::on_stream_close(SrsRequest* req)
@@ -317,7 +337,7 @@ void SrsStatistic::on_stream_close(SrsRequest* req) @@ -317,7 +337,7 @@ void SrsStatistic::on_stream_close(SrsRequest* req)
317 stream->close(); 337 stream->close();
318 } 338 }
319 339
320 -int SrsStatistic::on_client(int id, SrsRequest* req) 340 +int SrsStatistic::on_client(int id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type)
321 { 341 {
322 int ret = ERROR_SUCCESS; 342 int ret = ERROR_SUCCESS;
323 343
@@ -336,6 +356,9 @@ int SrsStatistic::on_client(int id, SrsRequest* req) @@ -336,6 +356,9 @@ int SrsStatistic::on_client(int id, SrsRequest* req)
336 } 356 }
337 357
338 // got client. 358 // got client.
  359 + client->conn = conn;
  360 + client->req = req;
  361 + client->type = type;
339 stream->nb_clients++; 362 stream->nb_clients++;
340 vhost->nb_clients++; 363 vhost->nb_clients++;
341 364
@@ -458,7 +481,7 @@ int SrsStatistic::dumps_clients(stringstream& ss, int start, int count) @@ -458,7 +481,7 @@ int SrsStatistic::dumps_clients(stringstream& ss, int start, int count)
458 481
459 ss << SRS_JARRAY_START; 482 ss << SRS_JARRAY_START;
460 std::map<int, SrsStatisticClient*>::iterator it = clients.begin(); 483 std::map<int, SrsStatisticClient*>::iterator it = clients.begin();
461 - for (int i = 0; i < count && it != clients.end(); it++) { 484 + for (int i = 0; i < start + count && it != clients.end(); it++, i++) {
462 if (i < start) { 485 if (i < start) {
463 continue; 486 continue;
464 } 487 }
@@ -34,9 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -34,9 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 #include <string> 34 #include <string>
35 35
36 #include <srs_kernel_codec.hpp> 36 #include <srs_kernel_codec.hpp>
37 -  
38 -#define STATISTIC_STREAM_STATUS_PUBLISHING "publishing"  
39 -#define STATISTIC_STREAM_STATUS_IDLING "idling" 37 +#include <srs_rtmp_stack.hpp>
40 38
41 class SrsKbps; 39 class SrsKbps;
42 class SrsRequest; 40 class SrsRequest;
@@ -68,7 +66,8 @@ public: @@ -68,7 +66,8 @@ public:
68 std::string app; 66 std::string app;
69 std::string stream; 67 std::string stream;
70 std::string url; 68 std::string url;
71 - std::string status; 69 + bool active;
  70 + int connection_cid;
72 int nb_clients; 71 int nb_clients;
73 public: 72 public:
74 /** 73 /**
@@ -103,7 +102,7 @@ public: @@ -103,7 +102,7 @@ public:
103 /** 102 /**
104 * publish the stream. 103 * publish the stream.
105 */ 104 */
106 - virtual void publish(); 105 + virtual void publish(int cid);
107 /** 106 /**
108 * close the stream. 107 * close the stream.
109 */ 108 */
@@ -114,7 +113,11 @@ struct SrsStatisticClient @@ -114,7 +113,11 @@ struct SrsStatisticClient
114 { 113 {
115 public: 114 public:
116 SrsStatisticStream* stream; 115 SrsStatisticStream* stream;
  116 + SrsConnection* conn;
  117 + SrsRequest* req;
  118 + SrsRtmpConnType type;
117 int id; 119 int id;
  120 + int64_t create;
118 public: 121 public:
119 SrsStatisticClient(); 122 SrsStatisticClient();
120 virtual ~SrsStatisticClient(); 123 virtual ~SrsStatisticClient();
@@ -169,9 +172,11 @@ public: @@ -169,9 +172,11 @@ public:
169 SrsAacObjectType aac_object 172 SrsAacObjectType aac_object
170 ); 173 );
171 /** 174 /**
172 - * when publish stream.  
173 - */  
174 - virtual void on_stream_publish(SrsRequest* req); 175 + * when publish stream.
  176 + * @param req the request object of publish connection.
  177 + * @param cid the cid of publish connection.
  178 + */
  179 + virtual void on_stream_publish(SrsRequest* req, int cid);
175 /** 180 /**
176 * when close stream. 181 * when close stream.
177 */ 182 */
@@ -181,8 +186,10 @@ public: @@ -181,8 +186,10 @@ public:
181 * when got a client to publish/play stream, 186 * when got a client to publish/play stream,
182 * @param id, the client srs id. 187 * @param id, the client srs id.
183 * @param req, the client request object. 188 * @param req, the client request object.
  189 + * @param conn, the physical absract connection object.
  190 + * @param type, the type of connection.
184 */ 191 */
185 - virtual int on_client(int id, SrsRequest* req); 192 + virtual int on_client(int id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type);
186 /** 193 /**
187 * client disconnect 194 * client disconnect
188 * @remark the on_disconnect always call, while the on_client is call when 195 * @remark the on_disconnect always call, while the on_client is call when
@@ -264,6 +264,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -264,6 +264,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
264 #define ERROR_HTTP_REQUEST_EOF 4029 264 #define ERROR_HTTP_REQUEST_EOF 4029
265 265
266 /////////////////////////////////////////////////////// 266 ///////////////////////////////////////////////////////
  267 +// HTTP API error.
  268 +///////////////////////////////////////////////////////
  269 +//#define ERROR_API_METHOD_NOT_ALLOWD
  270 +
  271 +///////////////////////////////////////////////////////
267 // user-define error. 272 // user-define error.
268 /////////////////////////////////////////////////////// 273 ///////////////////////////////////////////////////////
269 #define ERROR_USER_START 9000 274 #define ERROR_USER_START 9000
@@ -120,8 +120,11 @@ string srs_go_http_detect(char* data, int size) @@ -120,8 +120,11 @@ string srs_go_http_detect(char* data, int size)
120 return "application/octet-stream"; // fallback 120 return "application/octet-stream"; // fallback
121 } 121 }
122 122
123 -// Error replies to the request with the specified error message and HTTP code.  
124 -// The error message should be plain text. 123 +int srs_go_http_error(ISrsHttpResponseWriter* w, int code)
  124 +{
  125 + return srs_go_http_error(w, code, srs_generate_http_status_text(code));
  126 +}
  127 +
125 int srs_go_http_error(ISrsHttpResponseWriter* w, int code, string error) 128 int srs_go_http_error(ISrsHttpResponseWriter* w, int code, string error)
126 { 129 {
127 int ret = ERROR_SUCCESS; 130 int ret = ERROR_SUCCESS;
@@ -287,7 +290,7 @@ bool SrsHttpNotFoundHandler::is_not_found() @@ -287,7 +290,7 @@ bool SrsHttpNotFoundHandler::is_not_found()
287 290
288 int SrsHttpNotFoundHandler::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) 291 int SrsHttpNotFoundHandler::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
289 { 292 {
290 - return srs_go_http_error(w, SRS_CONSTS_HTTP_NotFound, SRS_CONSTS_HTTP_NotFound_str); 293 + return srs_go_http_error(w, SRS_CONSTS_HTTP_NotFound);
291 } 294 }
292 295
293 SrsHttpFileServer::SrsHttpFileServer(string root_dir) 296 SrsHttpFileServer::SrsHttpFileServer(string root_dir)
@@ -76,6 +76,11 @@ class ISrsHttpResponseWriter; @@ -76,6 +76,11 @@ class ISrsHttpResponseWriter;
76 #define SRS_CONSTS_HTTP_PUT HTTP_PUT 76 #define SRS_CONSTS_HTTP_PUT HTTP_PUT
77 #define SRS_CONSTS_HTTP_DELETE HTTP_DELETE 77 #define SRS_CONSTS_HTTP_DELETE HTTP_DELETE
78 78
  79 +// Error replies to the request with the specified error message and HTTP code.
  80 +// The error message should be plain text.
  81 +extern int srs_go_http_error(ISrsHttpResponseWriter* w, int code);
  82 +extern int srs_go_http_error(ISrsHttpResponseWriter* w, int code, std::string error);
  83 +
79 // helper function: response in json format. 84 // helper function: response in json format.
80 extern int srs_http_response_json(ISrsHttpResponseWriter* w, std::string data); 85 extern int srs_http_response_json(ISrsHttpResponseWriter* w, std::string data);
81 /** 86 /**
@@ -1747,12 +1747,17 @@ string srs_client_type_string(SrsRtmpConnType type) @@ -1747,12 +1747,17 @@ string srs_client_type_string(SrsRtmpConnType type)
1747 { 1747 {
1748 switch (type) { 1748 switch (type) {
1749 case SrsRtmpConnPlay: return "Play"; 1749 case SrsRtmpConnPlay: return "Play";
1750 - case SrsRtmpConnFlashPublish: return "publish(FlashPublish)";  
1751 - case SrsRtmpConnFMLEPublish: return "publish(FMLEPublish)"; 1750 + case SrsRtmpConnFlashPublish: return "flash-publish)";
  1751 + case SrsRtmpConnFMLEPublish: return "fmle-publish";
1752 default: return "Unknown"; 1752 default: return "Unknown";
1753 } 1753 }
1754 } 1754 }
1755 1755
  1756 +bool srs_client_type_is_publish(SrsRtmpConnType type)
  1757 +{
  1758 + return type != SrsRtmpConnPlay;
  1759 +}
  1760 +
1756 SrsHandshakeBytes::SrsHandshakeBytes() 1761 SrsHandshakeBytes::SrsHandshakeBytes()
1757 { 1762 {
1758 c0c1 = s0s1s2 = c2 = NULL; 1763 c0c1 = s0s1s2 = c2 = NULL;
@@ -622,6 +622,7 @@ enum SrsRtmpConnType @@ -622,6 +622,7 @@ enum SrsRtmpConnType
622 SrsRtmpConnFlashPublish, 622 SrsRtmpConnFlashPublish,
623 }; 623 };
624 std::string srs_client_type_string(SrsRtmpConnType type); 624 std::string srs_client_type_string(SrsRtmpConnType type);
  625 +bool srs_client_type_is_publish(SrsRtmpConnType type);
625 626
626 /** 627 /**
627 * store the handshake bytes, 628 * store the handshake bytes,
@@ -247,7 +247,7 @@ int srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* iovs, int size, s @@ -247,7 +247,7 @@ int srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* iovs, int size, s
247 // for srs-librtmp, @see https://github.com/simple-rtmp-server/srs/issues/213 247 // for srs-librtmp, @see https://github.com/simple-rtmp-server/srs/issues/213
248 #ifndef _WIN32 248 #ifndef _WIN32
249 // for linux, generally it's 1024. 249 // for linux, generally it's 1024.
250 - static int limits = sysconf(_SC_IOV_MAX); 250 + static int limits = (int)sysconf(_SC_IOV_MAX);
251 #else 251 #else
252 static int limits = 1024; 252 static int limits = 1024;
253 #endif 253 #endif