正在显示
11 个修改的文件
包含
80 行增加
和
26 行删除
@@ -77,22 +77,22 @@ void SrsKbpsSlice::sample() | @@ -77,22 +77,22 @@ void SrsKbpsSlice::sample() | ||
77 | } | 77 | } |
78 | 78 | ||
79 | if (now - sample_30s.time > 30 * 1000) { | 79 | if (now - sample_30s.time > 30 * 1000) { |
80 | - sample_30s.kbps = (total_bytes - sample_30s.bytes) * 8 / (now - sample_30s.time); | 80 | + sample_30s.kbps = (int)((total_bytes - sample_30s.bytes) * 8 / (now - sample_30s.time)); |
81 | sample_30s.time = now; | 81 | sample_30s.time = now; |
82 | sample_30s.bytes = total_bytes; | 82 | sample_30s.bytes = total_bytes; |
83 | } | 83 | } |
84 | if (now - sample_1m.time > 60 * 1000) { | 84 | if (now - sample_1m.time > 60 * 1000) { |
85 | - sample_1m.kbps = (total_bytes - sample_1m.bytes) * 8 / (now - sample_1m.time); | 85 | + sample_1m.kbps = (int)((total_bytes - sample_1m.bytes) * 8 / (now - sample_1m.time)); |
86 | sample_1m.time = now; | 86 | sample_1m.time = now; |
87 | sample_1m.bytes = total_bytes; | 87 | sample_1m.bytes = total_bytes; |
88 | } | 88 | } |
89 | if (now - sample_5m.time > 300 * 1000) { | 89 | if (now - sample_5m.time > 300 * 1000) { |
90 | - sample_5m.kbps = (total_bytes - sample_5m.bytes) * 8 / (now - sample_5m.time); | 90 | + sample_5m.kbps = (int)((total_bytes - sample_5m.bytes) * 8 / (now - sample_5m.time)); |
91 | sample_5m.time = now; | 91 | sample_5m.time = now; |
92 | sample_5m.bytes = total_bytes; | 92 | sample_5m.bytes = total_bytes; |
93 | } | 93 | } |
94 | if (now - sample_60m.time > 3600 * 1000) { | 94 | if (now - sample_60m.time > 3600 * 1000) { |
95 | - sample_60m.kbps = (total_bytes - sample_60m.bytes) * 8 / (now - sample_60m.time); | 95 | + sample_60m.kbps = (int)((total_bytes - sample_60m.bytes) * 8 / (now - sample_60m.time)); |
96 | sample_60m.time = now; | 96 | sample_60m.time = now; |
97 | sample_60m.bytes = total_bytes; | 97 | sample_60m.bytes = total_bytes; |
98 | } | 98 | } |
@@ -160,7 +160,7 @@ int SrsKbps::get_send_kbps() | @@ -160,7 +160,7 @@ int SrsKbps::get_send_kbps() | ||
160 | return 0; | 160 | return 0; |
161 | } | 161 | } |
162 | int64_t bytes = get_send_bytes(); | 162 | int64_t bytes = get_send_bytes(); |
163 | - return bytes * 8 / duration; | 163 | + return (int)(bytes * 8 / duration); |
164 | } | 164 | } |
165 | 165 | ||
166 | int SrsKbps::get_recv_kbps() | 166 | int SrsKbps::get_recv_kbps() |
@@ -170,7 +170,7 @@ int SrsKbps::get_recv_kbps() | @@ -170,7 +170,7 @@ int SrsKbps::get_recv_kbps() | ||
170 | return 0; | 170 | return 0; |
171 | } | 171 | } |
172 | int64_t bytes = get_recv_bytes(); | 172 | int64_t bytes = get_recv_bytes(); |
173 | - return bytes * 8 / duration; | 173 | + return (int)(bytes * 8 / duration); |
174 | } | 174 | } |
175 | 175 | ||
176 | int SrsKbps::get_send_kbps_30s() | 176 | int SrsKbps::get_send_kbps_30s() |
@@ -54,6 +54,11 @@ ISrsUdpHandler::~ISrsUdpHandler() | @@ -54,6 +54,11 @@ ISrsUdpHandler::~ISrsUdpHandler() | ||
54 | { | 54 | { |
55 | } | 55 | } |
56 | 56 | ||
57 | +int ISrsUdpHandler::on_stfd_change(st_netfd_t /*fd*/) | ||
58 | +{ | ||
59 | + return ERROR_SUCCESS; | ||
60 | +} | ||
61 | + | ||
57 | ISrsTcpHandler::ISrsTcpHandler() | 62 | ISrsTcpHandler::ISrsTcpHandler() |
58 | { | 63 | { |
59 | } | 64 | } |
@@ -69,7 +74,7 @@ SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, string i, int p) | @@ -69,7 +74,7 @@ SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, string i, int p) | ||
69 | port = p; | 74 | port = p; |
70 | 75 | ||
71 | _fd = -1; | 76 | _fd = -1; |
72 | - stfd = NULL; | 77 | + _stfd = NULL; |
73 | 78 | ||
74 | nb_buf = SRS_UDP_MAX_PACKET_SIZE; | 79 | nb_buf = SRS_UDP_MAX_PACKET_SIZE; |
75 | buf = new char[nb_buf]; | 80 | buf = new char[nb_buf]; |
@@ -80,7 +85,7 @@ SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, string i, int p) | @@ -80,7 +85,7 @@ SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, string i, int p) | ||
80 | SrsUdpListener::~SrsUdpListener() | 85 | SrsUdpListener::~SrsUdpListener() |
81 | { | 86 | { |
82 | // close the stfd to trigger thread to interrupted. | 87 | // close the stfd to trigger thread to interrupted. |
83 | - srs_close_stfd(stfd); | 88 | + srs_close_stfd(_stfd); |
84 | 89 | ||
85 | pthread->stop(); | 90 | pthread->stop(); |
86 | srs_freep(pthread); | 91 | srs_freep(pthread); |
@@ -97,6 +102,11 @@ int SrsUdpListener::fd() | @@ -97,6 +102,11 @@ int SrsUdpListener::fd() | ||
97 | return _fd; | 102 | return _fd; |
98 | } | 103 | } |
99 | 104 | ||
105 | +st_netfd_t SrsUdpListener::stfd() | ||
106 | +{ | ||
107 | + return _stfd; | ||
108 | +} | ||
109 | + | ||
100 | int SrsUdpListener::listen() | 110 | int SrsUdpListener::listen() |
101 | { | 111 | { |
102 | int ret = ERROR_SUCCESS; | 112 | int ret = ERROR_SUCCESS; |
@@ -127,7 +137,7 @@ int SrsUdpListener::listen() | @@ -127,7 +137,7 @@ int SrsUdpListener::listen() | ||
127 | } | 137 | } |
128 | srs_verbose("bind socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); | 138 | srs_verbose("bind socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); |
129 | 139 | ||
130 | - if ((stfd = st_netfd_open_socket(_fd)) == NULL){ | 140 | + if ((_stfd = st_netfd_open_socket(_fd)) == NULL){ |
131 | ret = ERROR_ST_OPEN_SOCKET; | 141 | ret = ERROR_ST_OPEN_SOCKET; |
132 | srs_error("st_netfd_open_socket open socket failed. ep=%s:%d, ret=%d", ip.c_str(), port, ret); | 142 | srs_error("st_netfd_open_socket open socket failed. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
133 | return ret; | 143 | return ret; |
@@ -153,7 +163,7 @@ int SrsUdpListener::cycle() | @@ -153,7 +163,7 @@ int SrsUdpListener::cycle() | ||
153 | int nb_from = sizeof(sockaddr_in); | 163 | int nb_from = sizeof(sockaddr_in); |
154 | int nread = 0; | 164 | int nread = 0; |
155 | 165 | ||
156 | - if ((nread = st_recvfrom(stfd, buf, nb_buf, (sockaddr*)&from, &nb_from, ST_UTIME_NO_TIMEOUT)) <= 0) { | 166 | + if ((nread = st_recvfrom(_stfd, buf, nb_buf, (sockaddr*)&from, &nb_from, ST_UTIME_NO_TIMEOUT)) <= 0) { |
157 | srs_warn("ignore recv udp packet failed, nread=%d", nread); | 167 | srs_warn("ignore recv udp packet failed, nread=%d", nread); |
158 | continue; | 168 | continue; |
159 | } | 169 | } |
@@ -178,7 +188,7 @@ SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, string i, int p) | @@ -178,7 +188,7 @@ SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, string i, int p) | ||
178 | port = p; | 188 | port = p; |
179 | 189 | ||
180 | _fd = -1; | 190 | _fd = -1; |
181 | - stfd = NULL; | 191 | + _stfd = NULL; |
182 | 192 | ||
183 | pthread = new SrsThread("tcp", this, 0, true); | 193 | pthread = new SrsThread("tcp", this, 0, true); |
184 | } | 194 | } |
@@ -186,7 +196,7 @@ SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, string i, int p) | @@ -186,7 +196,7 @@ SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, string i, int p) | ||
186 | SrsTcpListener::~SrsTcpListener() | 196 | SrsTcpListener::~SrsTcpListener() |
187 | { | 197 | { |
188 | // close the stfd to trigger thread to interrupted. | 198 | // close the stfd to trigger thread to interrupted. |
189 | - srs_close_stfd(stfd); | 199 | + srs_close_stfd(_stfd); |
190 | 200 | ||
191 | pthread->stop(); | 201 | pthread->stop(); |
192 | srs_freep(pthread); | 202 | srs_freep(pthread); |
@@ -238,7 +248,7 @@ int SrsTcpListener::listen() | @@ -238,7 +248,7 @@ int SrsTcpListener::listen() | ||
238 | } | 248 | } |
239 | srs_verbose("listen socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); | 249 | srs_verbose("listen socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); |
240 | 250 | ||
241 | - if ((stfd = st_netfd_open_socket(_fd)) == NULL){ | 251 | + if ((_stfd = st_netfd_open_socket(_fd)) == NULL){ |
242 | ret = ERROR_ST_OPEN_SOCKET; | 252 | ret = ERROR_ST_OPEN_SOCKET; |
243 | srs_error("st_netfd_open_socket open socket failed. ep=%s:%d, ret=%d", ip.c_str(), port, ret); | 253 | srs_error("st_netfd_open_socket open socket failed. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
244 | return ret; | 254 | return ret; |
@@ -258,7 +268,7 @@ int SrsTcpListener::cycle() | @@ -258,7 +268,7 @@ int SrsTcpListener::cycle() | ||
258 | { | 268 | { |
259 | int ret = ERROR_SUCCESS; | 269 | int ret = ERROR_SUCCESS; |
260 | 270 | ||
261 | - st_netfd_t client_stfd = st_accept(stfd, NULL, NULL, ST_UTIME_NO_TIMEOUT); | 271 | + st_netfd_t client_stfd = st_accept(_stfd, NULL, NULL, ST_UTIME_NO_TIMEOUT); |
262 | 272 | ||
263 | if(client_stfd == NULL){ | 273 | if(client_stfd == NULL){ |
264 | // ignore error. | 274 | // ignore error. |
@@ -47,6 +47,12 @@ public: | @@ -47,6 +47,12 @@ public: | ||
47 | virtual ~ISrsUdpHandler(); | 47 | virtual ~ISrsUdpHandler(); |
48 | public: | 48 | public: |
49 | /** | 49 | /** |
50 | + * when fd changed, for instance, reload the listen port, | ||
51 | + * notify the handler and user can do something. | ||
52 | + */ | ||
53 | + virtual int on_stfd_change(st_netfd_t fd); | ||
54 | +public: | ||
55 | + /** | ||
50 | * when udp listener got a udp packet, notice server to process it. | 56 | * when udp listener got a udp packet, notice server to process it. |
51 | * @param type, the client type, used to create concrete connection, | 57 | * @param type, the client type, used to create concrete connection, |
52 | * for instance RTMP connection to serve client. | 58 | * for instance RTMP connection to serve client. |
@@ -80,7 +86,7 @@ class SrsUdpListener : public ISrsThreadHandler | @@ -80,7 +86,7 @@ class SrsUdpListener : public ISrsThreadHandler | ||
80 | { | 86 | { |
81 | private: | 87 | private: |
82 | int _fd; | 88 | int _fd; |
83 | - st_netfd_t stfd; | 89 | + st_netfd_t _stfd; |
84 | SrsThread* pthread; | 90 | SrsThread* pthread; |
85 | private: | 91 | private: |
86 | char* buf; | 92 | char* buf; |
@@ -94,6 +100,7 @@ public: | @@ -94,6 +100,7 @@ public: | ||
94 | virtual ~SrsUdpListener(); | 100 | virtual ~SrsUdpListener(); |
95 | public: | 101 | public: |
96 | virtual int fd(); | 102 | virtual int fd(); |
103 | + virtual st_netfd_t stfd(); | ||
97 | public: | 104 | public: |
98 | virtual int listen(); | 105 | virtual int listen(); |
99 | // interface ISrsThreadHandler. | 106 | // interface ISrsThreadHandler. |
@@ -108,7 +115,7 @@ class SrsTcpListener : public ISrsThreadHandler | @@ -108,7 +115,7 @@ class SrsTcpListener : public ISrsThreadHandler | ||
108 | { | 115 | { |
109 | private: | 116 | private: |
110 | int _fd; | 117 | int _fd; |
111 | - st_netfd_t stfd; | 118 | + st_netfd_t _stfd; |
112 | SrsThread* pthread; | 119 | SrsThread* pthread; |
113 | private: | 120 | private: |
114 | ISrsTcpHandler* handler; | 121 | ISrsTcpHandler* handler; |
@@ -330,6 +330,12 @@ int SrsUdpStreamListener::listen(string i, int p) | @@ -330,6 +330,12 @@ int SrsUdpStreamListener::listen(string i, int p) | ||
330 | srs_info("listen thread cid=%d, current_cid=%d, " | 330 | srs_info("listen thread cid=%d, current_cid=%d, " |
331 | "listen at port=%d, type=%d, fd=%d started success, ep=%s:%d", | 331 | "listen at port=%d, type=%d, fd=%d started success, ep=%s:%d", |
332 | pthread->cid(), _srs_context->get_id(), port, type, fd, ip.c_str(), port); | 332 | pthread->cid(), _srs_context->get_id(), port, type, fd, ip.c_str(), port); |
333 | + | ||
334 | + // notify the handler the fd changed. | ||
335 | + if ((ret = caster->on_stfd_change(listener->stfd())) != ERROR_SUCCESS) { | ||
336 | + srs_error("notify handler fd changed. ret=%d", ret); | ||
337 | + return ret; | ||
338 | + } | ||
333 | 339 | ||
334 | srs_trace("%s listen at udp://%s:%d, fd=%d", srs_listener_type2string(type).c_str(), ip.c_str(), port, listener->fd()); | 340 | srs_trace("%s listen at udp://%s:%d, fd=%d", srs_listener_type2string(type).c_str(), ip.c_str(), port, listener->fd()); |
335 | 341 |
@@ -45,6 +45,7 @@ using namespace std; | @@ -45,6 +45,7 @@ using namespace std; | ||
45 | #include <srs_app_hds.hpp> | 45 | #include <srs_app_hds.hpp> |
46 | #include <srs_app_statistic.hpp> | 46 | #include <srs_app_statistic.hpp> |
47 | #include <srs_core_autofree.hpp> | 47 | #include <srs_core_autofree.hpp> |
48 | +#include <srs_rtmp_utility.hpp> | ||
48 | 49 | ||
49 | #define CONST_MAX_JITTER_MS 500 | 50 | #define CONST_MAX_JITTER_MS 500 |
50 | #define DEFAULT_FRAME_TIME_MS 40 | 51 | #define DEFAULT_FRAME_TIME_MS 40 |
@@ -759,6 +760,20 @@ SrsSource* SrsSource::fetch(SrsRequest* r) | @@ -759,6 +760,20 @@ SrsSource* SrsSource::fetch(SrsRequest* r) | ||
759 | return source; | 760 | return source; |
760 | } | 761 | } |
761 | 762 | ||
763 | +SrsSource* SrsSource::fetch(std::string vhost, std::string app, std::string stream) | ||
764 | +{ | ||
765 | + SrsSource* source = NULL; | ||
766 | + string stream_url = srs_generate_stream_url(vhost, app, stream); | ||
767 | + | ||
768 | + if (pool.find(stream_url) == pool.end()) { | ||
769 | + return NULL; | ||
770 | + } | ||
771 | + | ||
772 | + source = pool[stream_url]; | ||
773 | + | ||
774 | + return source; | ||
775 | +} | ||
776 | + | ||
762 | void SrsSource::destroy() | 777 | void SrsSource::destroy() |
763 | { | 778 | { |
764 | std::map<std::string, SrsSource*>::iterator it; | 779 | std::map<std::string, SrsSource*>::iterator it; |
@@ -407,6 +407,10 @@ public: | @@ -407,6 +407,10 @@ public: | ||
407 | */ | 407 | */ |
408 | static SrsSource* fetch(SrsRequest* r); | 408 | static SrsSource* fetch(SrsRequest* r); |
409 | /** | 409 | /** |
410 | + * get the exists source by stream info(vhost, app, stream), NULL when not exists. | ||
411 | + */ | ||
412 | + static SrsSource* fetch(std::string vhost, std::string app, std::string stream); | ||
413 | + /** | ||
410 | * when system exit, destroy the sources, | 414 | * when system exit, destroy the sources, |
411 | * for gmc to analysis mem leaks. | 415 | * for gmc to analysis mem leaks. |
412 | */ | 416 | */ |
@@ -195,6 +195,7 @@ int SrsStatistic::on_client(int id, SrsRequest* req) | @@ -195,6 +195,7 @@ int SrsStatistic::on_client(int id, SrsRequest* req) | ||
195 | SrsStatisticClient* client = NULL; | 195 | SrsStatisticClient* client = NULL; |
196 | if (clients.find(id) == clients.end()) { | 196 | if (clients.find(id) == clients.end()) { |
197 | client = new SrsStatisticClient(); | 197 | client = new SrsStatisticClient(); |
198 | + client->id = id; | ||
198 | client->stream = stream; | 199 | client->stream = stream; |
199 | clients[id] = client; | 200 | clients[id] = client; |
200 | } else { | 201 | } else { |
@@ -255,7 +255,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -255,7 +255,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
255 | #define ERROR_HTTP_INVALID_CHUNK_HEADER 4026 | 255 | #define ERROR_HTTP_INVALID_CHUNK_HEADER 4026 |
256 | #define ERROR_AVC_NALU_UEV 4027 | 256 | #define ERROR_AVC_NALU_UEV 4027 |
257 | #define ERROR_AAC_BYTES_INVALID 4028 | 257 | #define ERROR_AAC_BYTES_INVALID 4028 |
258 | -#define ERROR_HTTP_REQUEST_EOF 4029 | 258 | +#define ERROR_HTTP_REQUEST_EOF 4029 |
259 | 259 | ||
260 | /////////////////////////////////////////////////////// | 260 | /////////////////////////////////////////////////////// |
261 | // user-define error. | 261 | // user-define error. |
@@ -99,15 +99,7 @@ void SrsRequest::update_auth(SrsRequest* req) | @@ -99,15 +99,7 @@ void SrsRequest::update_auth(SrsRequest* req) | ||
99 | 99 | ||
100 | string SrsRequest::get_stream_url() | 100 | string SrsRequest::get_stream_url() |
101 | { | 101 | { |
102 | - std::string url = ""; | ||
103 | - | ||
104 | - url += vhost; | ||
105 | - url += "/"; | ||
106 | - url += app; | ||
107 | - url += "/"; | ||
108 | - url += stream; | ||
109 | - | ||
110 | - return url; | 102 | + return srs_generate_stream_url(vhost, app, stream); |
111 | } | 103 | } |
112 | 104 | ||
113 | void SrsRequest::strip() | 105 | void SrsRequest::strip() |
@@ -31,6 +31,7 @@ using namespace std; | @@ -31,6 +31,7 @@ using namespace std; | ||
31 | #include <srs_kernel_stream.hpp> | 31 | #include <srs_kernel_stream.hpp> |
32 | #include <srs_rtmp_stack.hpp> | 32 | #include <srs_rtmp_stack.hpp> |
33 | #include <srs_kernel_codec.hpp> | 33 | #include <srs_kernel_codec.hpp> |
34 | +#include <srs_kernel_consts.hpp> | ||
34 | 35 | ||
35 | void srs_discovery_tc_url( | 36 | void srs_discovery_tc_url( |
36 | string tcUrl, | 37 | string tcUrl, |
@@ -346,3 +347,18 @@ int srs_rtmp_create_msg(char type, u_int32_t timestamp, char* data, int size, in | @@ -346,3 +347,18 @@ int srs_rtmp_create_msg(char type, u_int32_t timestamp, char* data, int size, in | ||
346 | return ret; | 347 | return ret; |
347 | } | 348 | } |
348 | 349 | ||
350 | +std::string srs_generate_stream_url(std::string vhost, std::string app, std::string stream) | ||
351 | +{ | ||
352 | + std::string url = ""; | ||
353 | + | ||
354 | + if (SRS_CONSTS_RTMP_DEFAULT_VHOST != vhost){ | ||
355 | + url += vhost; | ||
356 | + } | ||
357 | + url += "/"; | ||
358 | + url += app; | ||
359 | + url += "/"; | ||
360 | + url += stream; | ||
361 | + | ||
362 | + return url; | ||
363 | +} | ||
364 | + |
@@ -120,5 +120,8 @@ extern int srs_chunk_header_c3( | @@ -120,5 +120,8 @@ extern int srs_chunk_header_c3( | ||
120 | */ | 120 | */ |
121 | extern int srs_rtmp_create_msg(char type, u_int32_t timestamp, char* data, int size, int stream_id, SrsSharedPtrMessage** ppmsg); | 121 | extern int srs_rtmp_create_msg(char type, u_int32_t timestamp, char* data, int size, int stream_id, SrsSharedPtrMessage** ppmsg); |
122 | 122 | ||
123 | +// get the stream identify, vhost/app/stream. | ||
124 | +extern std::string srs_generate_stream_url(std::string vhost, std::string app, std::string stream); | ||
125 | + | ||
123 | #endif | 126 | #endif |
124 | 127 |
-
请 注册 或 登录 后发表评论