winlin

update the signature of server

@@ -45,6 +45,7 @@ url: rtmp://127.0.0.1:1935/live/livestream @@ -45,6 +45,7 @@ url: rtmp://127.0.0.1:1935/live/livestream
45 * nginx v1.5.0: 139524 lines <br/> 45 * nginx v1.5.0: 139524 lines <br/>
46 46
47 ### History 47 ### History
  48 +* v0.3, 2013-10-28, support librtmp without extended-timestamp in 0xCX chunk packet.
48 * v0.3, 2013-10-27, support cache last gop for client fast startup. 49 * v0.3, 2013-10-27, support cache last gop for client fast startup.
49 * v0.2, 2013-10-25, v0.2 released. 10125 lines. 50 * v0.2, 2013-10-25, v0.2 released. 10125 lines.
50 * v0.2, 2013-10-25, support flash publish. 51 * v0.2, 2013-10-25, support flash publish.
@@ -62,13 +62,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -62,13 +62,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62 } \ 62 } \
63 (void)0 63 (void)0
64 64
  65 +// current release version
  66 +#define RTMP_SIG_SRS_VERSION "0.2"
65 // server info. 67 // server info.
66 #define RTMP_SIG_SRS_KEY "srs" 68 #define RTMP_SIG_SRS_KEY "srs"
  69 +#define RTMP_SIG_SRS_ROLE "origin server"
67 #define RTMP_SIG_SRS_NAME RTMP_SIG_SRS_KEY"(simple rtmp server)" 70 #define RTMP_SIG_SRS_NAME RTMP_SIG_SRS_KEY"(simple rtmp server)"
68 -#define RTMP_SIG_SRS_URL "https://github.com/winlinvip/simple-rtmp-server" 71 +#define RTMP_SIG_SRS_URL "https://"RTMP_SIG_SRS_URL_SHORT
  72 +#define RTMP_SIG_SRS_URL_SHORT "github.com/winlinvip/simple-rtmp-server"
69 #define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin" 73 #define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin"
70 #define RTMP_SIG_SRS_EMAIL "winterserver@126.com" 74 #define RTMP_SIG_SRS_EMAIL "winterserver@126.com"
71 -#define RTMP_SIG_SRS_VERSION "0.1" 75 +#define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)"
  76 +#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013 winlin"
72 77
73 // compare 78 // compare
74 #define srs_min(a, b) ((a < b)? a : b) 79 #define srs_min(a, b) ((a < b)? a : b)
@@ -63,8 +63,8 @@ int SrsClient::do_cycle() @@ -63,8 +63,8 @@ int SrsClient::do_cycle()
63 } 63 }
64 srs_verbose("get peer ip success. ip=%s", ip); 64 srs_verbose("get peer ip success. ip=%s", ip);
65 65
66 - rtmp->set_recv_timeout(SRS_SEND_TIMEOUT_MS);  
67 - rtmp->set_send_timeout(SRS_SEND_TIMEOUT_MS); 66 + rtmp->set_recv_timeout(SRS_SEND_TIMEOUT_MS * 1000);
  67 + rtmp->set_send_timeout(SRS_SEND_TIMEOUT_MS * 1000);
68 68
69 if ((ret = rtmp->handshake()) != ERROR_SUCCESS) { 69 if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {
70 srs_error("rtmp handshake failed. ret=%d", ret); 70 srs_error("rtmp handshake failed. ret=%d", ret);
@@ -185,7 +185,7 @@ int SrsClient::streaming_play(SrsSource* source) @@ -185,7 +185,7 @@ int SrsClient::streaming_play(SrsSource* source)
185 SrsAutoFree(SrsConsumer, consumer, false); 185 SrsAutoFree(SrsConsumer, consumer, false);
186 srs_verbose("consumer created success."); 186 srs_verbose("consumer created success.");
187 187
188 - rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_MS); 188 + rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_MS * 1000);
189 189
190 int64_t report_time = 0; 190 int64_t report_time = 0;
191 int64_t reported_time = 0; 191 int64_t reported_time = 0;
@@ -249,6 +249,9 @@ messages. @@ -249,6 +249,9 @@ messages.
249 /**************************************************************************** 249 /****************************************************************************
250 ***************************************************************************** 250 *****************************************************************************
251 ****************************************************************************/ 251 ****************************************************************************/
  252 +// when got a messae header, increase recv timeout to got an entire message.
  253 +#define SRS_MIN_RECV_TIMEOUT_US 3000
  254 +
252 SrsProtocol::AckWindowSize::AckWindowSize() 255 SrsProtocol::AckWindowSize::AckWindowSize()
253 { 256 {
254 ack_window_size = acked_size = 0; 257 ack_window_size = acked_size = 0;
@@ -278,14 +281,19 @@ SrsProtocol::~SrsProtocol() @@ -278,14 +281,19 @@ SrsProtocol::~SrsProtocol()
278 srs_freep(skt); 281 srs_freep(skt);
279 } 282 }
280 283
281 -void SrsProtocol::set_recv_timeout(int timeout_ms) 284 +void SrsProtocol::set_recv_timeout(int64_t timeout_us)
  285 +{
  286 + return skt->set_recv_timeout(timeout_us);
  287 +}
  288 +
  289 +int64_t SrsProtocol::get_recv_timeout()
282 { 290 {
283 - return skt->set_recv_timeout(timeout_ms); 291 + return skt->get_recv_timeout();
284 } 292 }
285 293
286 -void SrsProtocol::set_send_timeout(int timeout_ms) 294 +void SrsProtocol::set_send_timeout(int64_t timeout_us)
287 { 295 {
288 - return skt->set_send_timeout(timeout_ms); 296 + return skt->set_send_timeout(timeout_us);
289 } 297 }
290 298
291 int SrsProtocol::recv_message(SrsCommonMessage** pmsg) 299 int SrsProtocol::recv_message(SrsCommonMessage** pmsg)
@@ -602,17 +610,31 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) @@ -602,17 +610,31 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
602 } 610 }
603 return ret; 611 return ret;
604 } 612 }
605 - srs_info("read basic header success. fmt=%d, cid=%d, bh_size=%d", fmt, cid, bh_size); 613 + srs_verbose("read basic header success. fmt=%d, cid=%d, bh_size=%d", fmt, cid, bh_size);
  614 +
  615 + // once we got the chunk message header,
  616 + // that is there is a real message in cache,
  617 + // increase the timeout to got it.
  618 + // For example, in the play loop, we set timeout to 100ms,
  619 + // when we got a chunk header, we should increase the timeout,
  620 + // or we maybe timeout and disconnect the client.
  621 + int64_t timeout_us = skt->get_recv_timeout();
  622 + if (timeout_us != (int64_t)ST_UTIME_NO_TIMEOUT) {
  623 + int64_t pkt_timeout_us = srs_max(timeout_us, SRS_MIN_RECV_TIMEOUT_US);
  624 + skt->set_recv_timeout(pkt_timeout_us);
  625 + srs_verbose("change recv timeout_us "
  626 + "from %"PRId64" to %"PRId64"", timeout_us, pkt_timeout_us);
  627 + }
606 628
607 // get the cached chunk stream. 629 // get the cached chunk stream.
608 SrsChunkStream* chunk = NULL; 630 SrsChunkStream* chunk = NULL;
609 631
610 if (chunk_streams.find(cid) == chunk_streams.end()) { 632 if (chunk_streams.find(cid) == chunk_streams.end()) {
611 chunk = chunk_streams[cid] = new SrsChunkStream(cid); 633 chunk = chunk_streams[cid] = new SrsChunkStream(cid);
612 - srs_info("cache new chunk stream: fmt=%d, cid=%d", fmt, cid); 634 + srs_verbose("cache new chunk stream: fmt=%d, cid=%d", fmt, cid);
613 } else { 635 } else {
614 chunk = chunk_streams[cid]; 636 chunk = chunk_streams[cid];
615 - srs_info("cached chunk stream: fmt=%d, cid=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)", 637 + srs_verbose("cached chunk stream: fmt=%d, cid=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)",
616 chunk->fmt, chunk->cid, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, chunk->header.payload_length, 638 chunk->fmt, chunk->cid, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, chunk->header.payload_length,
617 chunk->header.timestamp, chunk->header.stream_id); 639 chunk->header.timestamp, chunk->header.stream_id);
618 } 640 }
@@ -625,7 +647,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) @@ -625,7 +647,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
625 } 647 }
626 return ret; 648 return ret;
627 } 649 }
628 - srs_info("read message header success. " 650 + srs_verbose("read message header success. "
629 "fmt=%d, mh_size=%d, ext_time=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)", 651 "fmt=%d, mh_size=%d, ext_time=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)",
630 fmt, mh_size, chunk->extended_timestamp, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type, 652 fmt, mh_size, chunk->extended_timestamp, (chunk->msg? chunk->msg->size : 0), chunk->header.message_type,
631 chunk->header.payload_length, chunk->header.timestamp, chunk->header.stream_id); 653 chunk->header.payload_length, chunk->header.timestamp, chunk->header.stream_id);
@@ -640,9 +662,15 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) @@ -640,9 +662,15 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
640 return ret; 662 return ret;
641 } 663 }
642 664
  665 + // reset the recv timeout
  666 + if (timeout_us != (int64_t)ST_UTIME_NO_TIMEOUT) {
  667 + skt->set_recv_timeout(timeout_us);
  668 + srs_verbose("reset recv timeout_us to %"PRId64"", timeout_us);
  669 + }
  670 +
643 // not got an entire RTMP message, try next chunk. 671 // not got an entire RTMP message, try next chunk.
644 if (!msg) { 672 if (!msg) {
645 - srs_info("get partial message success. chunk_payload_size=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)", 673 + srs_verbose("get partial message success. chunk_payload_size=%d, size=%d, message(type=%d, size=%d, time=%d, sid=%d)",
646 payload_size, (msg? msg->size : (chunk->msg? chunk->msg->size : 0)), chunk->header.message_type, chunk->header.payload_length, 674 payload_size, (msg? msg->size : (chunk->msg? chunk->msg->size : 0)), chunk->header.message_type, chunk->header.payload_length,
647 chunk->header.timestamp, chunk->header.stream_id); 675 chunk->header.timestamp, chunk->header.stream_id);
648 return ret; 676 return ret;
@@ -104,11 +104,12 @@ public: @@ -104,11 +104,12 @@ public:
104 virtual ~SrsProtocol(); 104 virtual ~SrsProtocol();
105 public: 105 public:
106 /** 106 /**
107 - * set the timeout in ms. 107 + * set the timeout in us.
108 * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. 108 * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
109 */ 109 */
110 - virtual void set_recv_timeout(int timeout_ms);  
111 - virtual void set_send_timeout(int timeout_ms); 110 + virtual void set_recv_timeout(int64_t timeout_us);
  111 + virtual int64_t get_recv_timeout();
  112 + virtual void set_send_timeout(int64_t timeout_us);
112 /** 113 /**
113 * recv a message with raw/undecoded payload from peer. 114 * recv a message with raw/undecoded payload from peer.
114 * the payload is not decoded, use srs_rtmp_expect_message<T> if requires 115 * the payload is not decoded, use srs_rtmp_expect_message<T> if requires
@@ -149,14 +149,19 @@ SrsRtmp::~SrsRtmp() @@ -149,14 +149,19 @@ SrsRtmp::~SrsRtmp()
149 srs_freep(complex_handshake); 149 srs_freep(complex_handshake);
150 } 150 }
151 151
152 -void SrsRtmp::set_recv_timeout(int timeout_ms) 152 +void SrsRtmp::set_recv_timeout(int64_t timeout_us)
153 { 153 {
154 - return protocol->set_recv_timeout(timeout_ms); 154 + return protocol->set_recv_timeout(timeout_us);
155 } 155 }
156 156
157 -void SrsRtmp::set_send_timeout(int timeout_ms) 157 +int64_t SrsRtmp::get_recv_timeout()
158 { 158 {
159 - return protocol->set_send_timeout(timeout_ms); 159 + return protocol->get_recv_timeout();
  160 +}
  161 +
  162 +void SrsRtmp::set_send_timeout(int64_t timeout_us)
  163 +{
  164 + return protocol->set_send_timeout(timeout_us);
160 } 165 }
161 166
162 int SrsRtmp::recv_message(SrsCommonMessage** pmsg) 167 int SrsRtmp::recv_message(SrsCommonMessage** pmsg)
@@ -176,7 +181,6 @@ int SrsRtmp::handshake() @@ -176,7 +181,6 @@ int SrsRtmp::handshake()
176 ssize_t nsize; 181 ssize_t nsize;
177 SrsSocket skt(stfd); 182 SrsSocket skt(stfd);
178 183
179 - // TODO: complex handshake for h264/aac codec.  
180 char* c0c1 = new char[1537]; 184 char* c0c1 = new char[1537];
181 SrsAutoFree(char, c0c1, true); 185 SrsAutoFree(char, c0c1, true);
182 if ((ret = skt.read_fully(c0c1, 1537, &nsize)) != ERROR_SUCCESS) { 186 if ((ret = skt.read_fully(c0c1, 1537, &nsize)) != ERROR_SUCCESS) {
@@ -325,10 +329,15 @@ int SrsRtmp::response_connect_app(SrsRequest* req) @@ -325,10 +329,15 @@ int SrsRtmp::response_connect_app(SrsRequest* req)
325 SrsASrsAmf0EcmaArray* data = new SrsASrsAmf0EcmaArray(); 329 SrsASrsAmf0EcmaArray* data = new SrsASrsAmf0EcmaArray();
326 pkt->info->set("data", data); 330 pkt->info->set("data", data);
327 331
328 - data->set("version", new SrsAmf0String(RTMP_SIG_FMS_VER));  
329 - data->set("server", new SrsAmf0String(RTMP_SIG_SRS_NAME)); 332 + data->set("srs_version", new SrsAmf0String(RTMP_SIG_FMS_VER));
  333 + data->set("srs_server", new SrsAmf0String(RTMP_SIG_SRS_NAME));
  334 + data->set("srs_license", new SrsAmf0String(RTMP_SIG_SRS_LICENSE));
  335 + data->set("srs_role", new SrsAmf0String(RTMP_SIG_SRS_ROLE));
330 data->set("srs_url", new SrsAmf0String(RTMP_SIG_SRS_URL)); 336 data->set("srs_url", new SrsAmf0String(RTMP_SIG_SRS_URL));
331 data->set("srs_version", new SrsAmf0String(RTMP_SIG_SRS_VERSION)); 337 data->set("srs_version", new SrsAmf0String(RTMP_SIG_SRS_VERSION));
  338 + data->set("srs_site", new SrsAmf0String(RTMP_SIG_SRS_WEB));
  339 + data->set("srs_email", new SrsAmf0String(RTMP_SIG_SRS_EMAIL));
  340 + data->set("srs_copyright", new SrsAmf0String(RTMP_SIG_SRS_COPYRIGHT));
332 341
333 msg->set_packet(pkt, 0); 342 msg->set_packet(pkt, 0);
334 343
@@ -105,8 +105,9 @@ public: @@ -105,8 +105,9 @@ public:
105 SrsRtmp(st_netfd_t client_stfd); 105 SrsRtmp(st_netfd_t client_stfd);
106 virtual ~SrsRtmp(); 106 virtual ~SrsRtmp();
107 public: 107 public:
108 - virtual void set_recv_timeout(int timeout_ms);  
109 - virtual void set_send_timeout(int timeout_ms); 108 + virtual void set_recv_timeout(int64_t timeout_us);
  109 + virtual int64_t get_recv_timeout();
  110 + virtual void set_send_timeout(int64_t timeout_us);
110 virtual int recv_message(SrsCommonMessage** pmsg); 111 virtual int recv_message(SrsCommonMessage** pmsg);
111 virtual int send_message(ISrsMessage* msg); 112 virtual int send_message(ISrsMessage* msg);
112 public: 113 public:
@@ -36,14 +36,19 @@ SrsSocket::~SrsSocket() @@ -36,14 +36,19 @@ SrsSocket::~SrsSocket()
36 { 36 {
37 } 37 }
38 38
39 -void SrsSocket::set_recv_timeout(int timeout_ms) 39 +void SrsSocket::set_recv_timeout(int64_t timeout_us)
40 { 40 {
41 - recv_timeout = timeout_ms * 1000; 41 + recv_timeout = timeout_us;
42 } 42 }
43 43
44 -void SrsSocket::set_send_timeout(int timeout_ms) 44 +int64_t SrsSocket::get_recv_timeout()
45 { 45 {
46 - send_timeout = timeout_ms * 1000; 46 + return recv_timeout;
  47 +}
  48 +
  49 +void SrsSocket::set_send_timeout(int64_t timeout_us)
  50 +{
  51 + send_timeout = timeout_us;
47 } 52 }
48 53
49 int64_t SrsSocket::get_recv_bytes() 54 int64_t SrsSocket::get_recv_bytes()
@@ -48,8 +48,9 @@ public: @@ -48,8 +48,9 @@ public:
48 SrsSocket(st_netfd_t client_stfd); 48 SrsSocket(st_netfd_t client_stfd);
49 virtual ~SrsSocket(); 49 virtual ~SrsSocket();
50 public: 50 public:
51 - virtual void set_recv_timeout(int timeout_ms);  
52 - virtual void set_send_timeout(int timeout_ms); 51 + virtual void set_recv_timeout(int64_t timeout_us);
  52 + virtual int64_t get_recv_timeout();
  53 + virtual void set_send_timeout(int64_t timeout_us);
53 virtual int64_t get_recv_bytes(); 54 virtual int64_t get_recv_bytes();
54 virtual int64_t get_send_bytes(); 55 virtual int64_t get_send_bytes();
55 public: 56 public:
@@ -179,8 +179,8 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata @@ -179,8 +179,8 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata
179 { 179 {
180 int ret = ERROR_SUCCESS; 180 int ret = ERROR_SUCCESS;
181 181
182 - metadata->metadata->set("server",  
183 - new SrsAmf0String(RTMP_SIG_SRS_NAME""RTMP_SIG_SRS_VERSION)); 182 + metadata->metadata->set("server", new SrsAmf0String(
  183 + RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")"));
184 184
185 // encode the metadata to payload 185 // encode the metadata to payload
186 int size = metadata->get_payload_length(); 186 int size = metadata->get_payload_length();