winlin

for bug #199, refine the header generate

@@ -600,13 +600,15 @@ void SrsProtocol::generate_chunk_header(SrsMessageHeader* mh, bool c0, int* pnbh @@ -600,13 +600,15 @@ void SrsProtocol::generate_chunk_header(SrsMessageHeader* mh, bool c0, int* pnbh
600 // generate the header. 600 // generate the header.
601 char* p = cache; 601 char* p = cache;
602 602
  603 + // timestamp for c0/c3
  604 + u_int32_t timestamp = (u_int32_t)mh->timestamp;
  605 +
603 if (c0) { 606 if (c0) {
604 // write new chunk stream header, fmt is 0 607 // write new chunk stream header, fmt is 0
605 *p++ = 0x00 | (mh->perfer_cid & 0x3F); 608 *p++ = 0x00 | (mh->perfer_cid & 0x3F);
606 609
607 // chunk message header, 11 bytes 610 // chunk message header, 11 bytes
608 // timestamp, 3bytes, big-endian 611 // timestamp, 3bytes, big-endian
609 - u_int32_t timestamp = (u_int32_t)mh->timestamp;  
610 if (timestamp < RTMP_EXTENDED_TIMESTAMP) { 612 if (timestamp < RTMP_EXTENDED_TIMESTAMP) {
611 pp = (char*)&timestamp; 613 pp = (char*)&timestamp;
612 *p++ = pp[2]; 614 *p++ = pp[2];
@@ -633,21 +635,17 @@ void SrsProtocol::generate_chunk_header(SrsMessageHeader* mh, bool c0, int* pnbh @@ -633,21 +635,17 @@ void SrsProtocol::generate_chunk_header(SrsMessageHeader* mh, bool c0, int* pnbh
633 *p++ = pp[1]; 635 *p++ = pp[1];
634 *p++ = pp[2]; 636 *p++ = pp[2];
635 *p++ = pp[3]; 637 *p++ = pp[3];
636 -  
637 - // chunk extended timestamp header, 0 or 4 bytes, big-endian  
638 - if(timestamp >= RTMP_EXTENDED_TIMESTAMP) {  
639 - pp = (char*)&timestamp;  
640 - *p++ = pp[3];  
641 - *p++ = pp[2];  
642 - *p++ = pp[1];  
643 - *p++ = pp[0];  
644 - }  
645 } else { 638 } else {
646 // write no message header chunk stream, fmt is 3 639 // write no message header chunk stream, fmt is 3
647 // @remark, if perfer_cid > 0x3F, that is, use 2B/3B chunk header, 640 // @remark, if perfer_cid > 0x3F, that is, use 2B/3B chunk header,
648 // SRS will rollback to 1B chunk header. 641 // SRS will rollback to 1B chunk header.
649 *p++ = 0xC0 | (mh->perfer_cid & 0x3F); 642 *p++ = 0xC0 | (mh->perfer_cid & 0x3F);
  643 + }
650 644
  645 + // for c0
  646 + // chunk extended timestamp header, 0 or 4 bytes, big-endian
  647 + //
  648 + // for c3:
651 // chunk extended timestamp header, 0 or 4 bytes, big-endian 649 // chunk extended timestamp header, 0 or 4 bytes, big-endian
652 // 6.1.3. Extended Timestamp 650 // 6.1.3. Extended Timestamp
653 // This field is transmitted only when the normal time stamp in the 651 // This field is transmitted only when the normal time stamp in the
@@ -662,7 +660,6 @@ void SrsProtocol::generate_chunk_header(SrsMessageHeader* mh, bool c0, int* pnbh @@ -662,7 +660,6 @@ void SrsProtocol::generate_chunk_header(SrsMessageHeader* mh, bool c0, int* pnbh
662 // @see: ngx_rtmp_prepare_message 660 // @see: ngx_rtmp_prepare_message
663 // @see: http://blog.csdn.net/win_lin/article/details/13363699 661 // @see: http://blog.csdn.net/win_lin/article/details/13363699
664 // TODO: FIXME: extract to outer. 662 // TODO: FIXME: extract to outer.
665 - u_int32_t timestamp = (u_int32_t)mh->timestamp;  
666 if (timestamp >= RTMP_EXTENDED_TIMESTAMP) { 663 if (timestamp >= RTMP_EXTENDED_TIMESTAMP) {
667 pp = (char*)&timestamp; 664 pp = (char*)&timestamp;
668 *p++ = pp[3]; 665 *p++ = pp[3];
@@ -670,7 +667,6 @@ void SrsProtocol::generate_chunk_header(SrsMessageHeader* mh, bool c0, int* pnbh @@ -670,7 +667,6 @@ void SrsProtocol::generate_chunk_header(SrsMessageHeader* mh, bool c0, int* pnbh
670 *p++ = pp[1]; 667 *p++ = pp[1];
671 *p++ = pp[0]; 668 *p++ = pp[0];
672 } 669 }
673 - }  
674 670
675 // always has header 671 // always has header
676 *pnbh = p - cache; 672 *pnbh = p - cache;