winlin

refine hls m3u8, use LR(0x0a, \n) as new line char

@@ -506,13 +506,13 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) @@ -506,13 +506,13 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
506 // #EXTM3U\n#EXT-X-VERSION:3\n 506 // #EXTM3U\n#EXT-X-VERSION:3\n
507 char header[] = { 507 char header[] = {
508 // #EXTM3U\n 508 // #EXTM3U\n
509 - 0x23, 0x45, 0x58, 0x54, 0x4d, 0x33, 0x55, 0xa, 509 + 0x23, 0x45, 0x58, 0x54, 0x4d, 0x33, 0x55, SRS_CONSTS_LF,
510 // #EXT-X-VERSION:3\n 510 // #EXT-X-VERSION:3\n
511 0x23, 0x45, 0x58, 0x54, 0x2d, 0x58, 0x2d, 0x56, 0x45, 0x52, 511 0x23, 0x45, 0x58, 0x54, 0x2d, 0x58, 0x2d, 0x56, 0x45, 0x52,
512 - 0x53, 0x49, 0x4f, 0x4e, 0x3a, 0x33, 0xa,  
513 - // #EXT-X-ALLOW-CACHE:NO 512 + 0x53, 0x49, 0x4f, 0x4e, 0x3a, 0x33, SRS_CONSTS_LF,
  513 + // #EXT-X-ALLOW-CACHE:NO\n
514 0x23, 0x45, 0x58, 0x54, 0x2d, 0x58, 0x2d, 0x41, 0x4c, 0x4c, 514 0x23, 0x45, 0x58, 0x54, 0x2d, 0x58, 0x2d, 0x41, 0x4c, 0x4c,
515 - 0x4f, 0x57, 0x2d, 0x43, 0x41, 0x43, 0x48, 0x45, 0x3a, 0x4e, 0x4f, 0x0a 515 + 0x4f, 0x57, 0x2d, 0x43, 0x41, 0x43, 0x48, 0x45, 0x3a, 0x4e, 0x4f, SRS_CONSTS_LF
516 }; 516 };
517 if ((ret = writer.write(header, sizeof(header), NULL)) != ERROR_SUCCESS) { 517 if ((ret = writer.write(header, sizeof(header), NULL)) != ERROR_SUCCESS) {
518 srs_error("write m3u8 header failed. ret=%d", ret); 518 srs_error("write m3u8 header failed. ret=%d", ret);
@@ -523,7 +523,7 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) @@ -523,7 +523,7 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
523 // #EXT-X-MEDIA-SEQUENCE:4294967295\n 523 // #EXT-X-MEDIA-SEQUENCE:4294967295\n
524 SrsHlsSegment* first = *segments.begin(); 524 SrsHlsSegment* first = *segments.begin();
525 char sequence[34] = {}; 525 char sequence[34] = {};
526 - int len = snprintf(sequence, sizeof(sequence), "#EXT-X-MEDIA-SEQUENCE:%d\n", first->sequence_no); 526 + int len = snprintf(sequence, sizeof(sequence), "#EXT-X-MEDIA-SEQUENCE:%d%c", first->sequence_no, SRS_CONSTS_LF);
527 if ((ret = writer.write(sequence, len, NULL)) != ERROR_SUCCESS) { 527 if ((ret = writer.write(sequence, len, NULL)) != ERROR_SUCCESS) {
528 srs_error("write m3u8 sequence failed. ret=%d", ret); 528 srs_error("write m3u8 sequence failed. ret=%d", ret);
529 return ret; 529 return ret;
@@ -540,7 +540,7 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) @@ -540,7 +540,7 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
540 // TODO: maybe need to take an around value 540 // TODO: maybe need to take an around value
541 target_duration += 1; 541 target_duration += 1;
542 char duration[34]; // 23+10+1 542 char duration[34]; // 23+10+1
543 - len = snprintf(duration, sizeof(duration), "#EXT-X-TARGETDURATION:%d\n", target_duration); 543 + len = snprintf(duration, sizeof(duration), "#EXT-X-TARGETDURATION:%d%c", target_duration, SRS_CONSTS_LF);
544 if ((ret = writer.write(duration, len, NULL)) != ERROR_SUCCESS) { 544 if ((ret = writer.write(duration, len, NULL)) != ERROR_SUCCESS) {
545 srs_error("write m3u8 duration failed. ret=%d", ret); 545 srs_error("write m3u8 duration failed. ret=%d", ret);
546 return ret; 546 return ret;
@@ -554,7 +554,7 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) @@ -554,7 +554,7 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
554 if (segment->is_sequence_header) { 554 if (segment->is_sequence_header) {
555 // #EXT-X-DISCONTINUITY\n 555 // #EXT-X-DISCONTINUITY\n
556 char ext_discon[22]; // 21+1 556 char ext_discon[22]; // 21+1
557 - len = snprintf(ext_discon, sizeof(ext_discon), "#EXT-X-DISCONTINUITY\n"); 557 + len = snprintf(ext_discon, sizeof(ext_discon), "#EXT-X-DISCONTINUITY%c", SRS_CONSTS_LF);
558 if ((ret = writer.write(ext_discon, len, NULL)) != ERROR_SUCCESS) { 558 if ((ret = writer.write(ext_discon, len, NULL)) != ERROR_SUCCESS) {
559 srs_error("write m3u8 segment discontinuity failed. ret=%d", ret); 559 srs_error("write m3u8 segment discontinuity failed. ret=%d", ret);
560 return ret; 560 return ret;
@@ -564,16 +564,16 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) @@ -564,16 +564,16 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
564 564
565 // "#EXTINF:4294967295.208,\n" 565 // "#EXTINF:4294967295.208,\n"
566 char ext_info[25]; // 14+10+1 566 char ext_info[25]; // 14+10+1
567 - len = snprintf(ext_info, sizeof(ext_info), "#EXTINF:%.3f,\n", segment->duration); 567 + len = snprintf(ext_info, sizeof(ext_info), "#EXTINF:%.3f,%c", segment->duration, SRS_CONSTS_LF);
568 if ((ret = writer.write(ext_info, len, NULL)) != ERROR_SUCCESS) { 568 if ((ret = writer.write(ext_info, len, NULL)) != ERROR_SUCCESS) {
569 srs_error("write m3u8 segment info failed. ret=%d", ret); 569 srs_error("write m3u8 segment info failed. ret=%d", ret);
570 return ret; 570 return ret;
571 } 571 }
572 srs_verbose("write m3u8 segment info success."); 572 srs_verbose("write m3u8 segment info success.");
573 573
574 - // file name 574 + // {file name}\n
575 std::string filename = segment->uri; 575 std::string filename = segment->uri;
576 - filename += "\n"; 576 + filename += SRS_CONSTS_LF;
577 if ((ret = writer.write((char*)filename.c_str(), (int)filename.length(), NULL)) != ERROR_SUCCESS) { 577 if ((ret = writer.write((char*)filename.c_str(), (int)filename.length(), NULL)) != ERROR_SUCCESS) {
578 srs_error("write m3u8 segment uri failed. ret=%d", ret); 578 srs_error("write m3u8 segment uri failed. ret=%d", ret);
579 return ret; 579 return ret;
@@ -51,13 +51,13 @@ class ISrsGoHttpResponseWriter; @@ -51,13 +51,13 @@ class ISrsGoHttpResponseWriter;
51 51
52 // http specification 52 // http specification
53 // CR = <US-ASCII CR, carriage return (13)> 53 // CR = <US-ASCII CR, carriage return (13)>
54 -#define __SRS_CR "\r" // 0x0D 54 +#define __SRS_CR SRS_CONSTS_CR // 0x0D
55 // LF = <US-ASCII LF, linefeed (10)> 55 // LF = <US-ASCII LF, linefeed (10)>
56 -#define __SRS_LF "\n" // 0x0A 56 +#define __SRS_LF SRS_CONSTS_LF // 0x0A
57 // SP = <US-ASCII SP, space (32)> 57 // SP = <US-ASCII SP, space (32)>
58 -#define __SRS_SP " " // 0x20 58 +#define __SRS_SP ' ' // 0x20
59 // HT = <US-ASCII HT, horizontal-tab (9)> 59 // HT = <US-ASCII HT, horizontal-tab (9)>
60 -#define __SRS_HT "\x09" // 0x09 60 +#define __SRS_HT '\x09' // 0x09
61 61
62 // HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all 62 // HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all
63 // protocol elements except the entity-body (see appendix 19.3 for 63 // protocol elements except the entity-body (see appendix 19.3 for
@@ -202,6 +202,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -202,6 +202,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
202 #define SRS_CONSTS_RTMP_ON_METADATA "onMetaData" 202 #define SRS_CONSTS_RTMP_ON_METADATA "onMetaData"
203 203
204 /////////////////////////////////////////////////////////// 204 ///////////////////////////////////////////////////////////
  205 +// HTTP/HLS consts values
  206 +///////////////////////////////////////////////////////////
  207 +// @see hls-m3u8-draft-pantos-http-live-streaming-12.pdf, page 4
  208 +// Lines are terminated by either a single LF character or a CR
  209 +// character followed by an LF character.
  210 +// CR = <US-ASCII CR, carriage return (13)>
  211 +#define SRS_CONSTS_CR '\r' // 0x0D
  212 +// LF = <US-ASCII LF, linefeed (10)>
  213 +#define SRS_CONSTS_LF '\n' // 0x0A
  214 +
  215 +///////////////////////////////////////////////////////////
205 // HTTP consts values 216 // HTTP consts values
206 /////////////////////////////////////////////////////////// 217 ///////////////////////////////////////////////////////////
207 // linux path seprator 218 // linux path seprator