winlin

fix #409: support pure video hls. 2.0.172.

@@ -342,6 +342,7 @@ Remark: @@ -342,6 +342,7 @@ Remark:
342 ## History 342 ## History
343 343
344 ### SRS 2.0 history 344 ### SRS 2.0 history
  345 +* v2.0, 2015-05-29, fix [#409](https://github.com/simple-rtmp-server/srs/issues/409) support pure video hls. 2.0.172.
345 * v2.0, 2015-05-28, support [srs-dolphin][srs-dolphin], the multiple-process SRS. 346 * v2.0, 2015-05-28, support [srs-dolphin][srs-dolphin], the multiple-process SRS.
346 * v2.0, 2015-05-24, fix [#404](https://github.com/simple-rtmp-server/srs/issues/404) register handler then start http thread. 2.0.167. 347 * v2.0, 2015-05-24, fix [#404](https://github.com/simple-rtmp-server/srs/issues/404) register handler then start http thread. 2.0.167.
347 * v2.0, 2015-05-23, refine the thread, protocol, kbps code. 2.0.166 348 * v2.0, 2015-05-23, refine the thread, protocol, kbps code. 2.0.166
@@ -608,7 +608,7 @@ vhost with-hls.srs.com { @@ -608,7 +608,7 @@ vhost with-hls.srs.com {
608 # when codec changed, write the PAT/PMT table, but maybe ok util next ts. 608 # when codec changed, write the PAT/PMT table, but maybe ok util next ts.
609 # so user can set the default codec for mp3. 609 # so user can set the default codec for mp3.
610 # the available audio codec: 610 # the available audio codec:
611 - # aac, mp3 611 + # aac, mp3, an
612 # default: aac 612 # default: aac
613 hls_acodec aac; 613 hls_acodec aac;
614 # the default video codec of hls. 614 # the default video codec of hls.
@@ -420,6 +420,9 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) @@ -420,6 +420,9 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
420 } else if (default_acodec_str == "aac") { 420 } else if (default_acodec_str == "aac") {
421 default_acodec = SrsCodecAudioAAC; 421 default_acodec = SrsCodecAudioAAC;
422 srs_info("hls: use default aac acodec"); 422 srs_info("hls: use default aac acodec");
  423 + } else if (default_acodec_str == "an") {
  424 + default_acodec = SrsCodecAudioDisabled;
  425 + srs_info("hls: use default an acodec for pure video");
423 } else { 426 } else {
424 srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str()); 427 srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str());
425 } 428 }
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 171 34 +#define VERSION_REVISION 172
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -136,6 +136,9 @@ enum SrsCodecAudio @@ -136,6 +136,9 @@ enum SrsCodecAudio
136 // set to the max value to reserved, for array map. 136 // set to the max value to reserved, for array map.
137 SrsCodecAudioReserved1 = 16, 137 SrsCodecAudioReserved1 = 16,
138 138
  139 + // for user to disable audio, for example, use pure video hls.
  140 + SrsCodecAudioDisabled = 17,
  141 +
139 SrsCodecAudioLinearPCMPlatformEndian = 0, 142 SrsCodecAudioLinearPCMPlatformEndian = 0,
140 SrsCodecAudioADPCM = 1, 143 SrsCodecAudioADPCM = 1,
141 SrsCodecAudioMP3 = 2, 144 SrsCodecAudioMP3 = 2,
@@ -215,13 +215,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -215,13 +215,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
215 #define ERROR_HTTP_DVR_CREATE_REQUEST 3053 215 #define ERROR_HTTP_DVR_CREATE_REQUEST 3053
216 #define ERROR_HTTP_DVR_NO_TAEGET 3054 216 #define ERROR_HTTP_DVR_NO_TAEGET 3054
217 #define ERROR_ADTS_ID_NOT_AAC 3055 217 #define ERROR_ADTS_ID_NOT_AAC 3055
218 -// HDS error code  
219 #define ERROR_HDS_OPEN_F4M_FAILED 3056 218 #define ERROR_HDS_OPEN_F4M_FAILED 3056
220 #define ERROR_HDS_WRITE_F4M_FAILED 3057 219 #define ERROR_HDS_WRITE_F4M_FAILED 3057
221 #define ERROR_HDS_OPEN_BOOTSTRAP_FAILED 3058 220 #define ERROR_HDS_OPEN_BOOTSTRAP_FAILED 3058
222 #define ERROR_HDS_WRITE_BOOTSTRAP_FAILED 3059 221 #define ERROR_HDS_WRITE_BOOTSTRAP_FAILED 3059
223 #define ERROR_HDS_OPEN_FRAGMENT_FAILED 3060 222 #define ERROR_HDS_OPEN_FRAGMENT_FAILED 3060
224 #define ERROR_HDS_WRITE_FRAGMENT_FAILED 3061 223 #define ERROR_HDS_WRITE_FRAGMENT_FAILED 3061
  224 +#define ERROR_HLS_NO_STREAM 3062
225 225
226 /////////////////////////////////////////////////////// 226 ///////////////////////////////////////////////////////
227 // HTTP/StreamCaster protocol error. 227 // HTTP/StreamCaster protocol error.
@@ -302,10 +302,12 @@ int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo @@ -302,10 +302,12 @@ int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo
302 vs = SrsTsStreamVideoH264; 302 vs = SrsTsStreamVideoH264;
303 video_pid = TS_VIDEO_AVC_PID; 303 video_pid = TS_VIDEO_AVC_PID;
304 break; 304 break;
  305 + case SrsCodecVideoDisabled:
  306 + vs = SrsTsStreamReserved;
  307 + break;
305 case SrsCodecVideoReserved: 308 case SrsCodecVideoReserved:
306 case SrsCodecVideoReserved1: 309 case SrsCodecVideoReserved1:
307 case SrsCodecVideoReserved2: 310 case SrsCodecVideoReserved2:
308 - case SrsCodecVideoDisabled:  
309 case SrsCodecVideoSorensonH263: 311 case SrsCodecVideoSorensonH263:
310 case SrsCodecVideoScreenVideo: 312 case SrsCodecVideoScreenVideo:
311 case SrsCodecVideoOn2VP6: 313 case SrsCodecVideoOn2VP6:
@@ -323,6 +325,9 @@ int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo @@ -323,6 +325,9 @@ int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo
323 as = SrsTsStreamAudioMp3; 325 as = SrsTsStreamAudioMp3;
324 audio_pid = TS_AUDIO_MP3_PID; 326 audio_pid = TS_AUDIO_MP3_PID;
325 break; 327 break;
  328 + case SrsCodecAudioDisabled:
  329 + as = SrsTsStreamReserved;
  330 + break;
326 case SrsCodecAudioReserved1: 331 case SrsCodecAudioReserved1:
327 case SrsCodecAudioLinearPCMPlatformEndian: 332 case SrsCodecAudioLinearPCMPlatformEndian:
328 case SrsCodecAudioADPCM: 333 case SrsCodecAudioADPCM:
@@ -340,6 +345,12 @@ int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo @@ -340,6 +345,12 @@ int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo
340 break; 345 break;
341 } 346 }
342 347
  348 + if (as == SrsTsStreamReserved && vs == SrsTsStreamReserved) {
  349 + ret = ERROR_HLS_NO_STREAM;
  350 + srs_error("hls: no video or audio stream, vcodec=%d, acodec=%d. ret=%d", vc, ac, ret);
  351 + return ret;
  352 + }
  353 +
343 // when any codec changed, write PAT/PMT table. 354 // when any codec changed, write PAT/PMT table.
344 if (vcodec != vc || acodec != ac) { 355 if (vcodec != vc || acodec != ac) {
345 vcodec = vc; 356 vcodec = vc;
@@ -361,6 +372,12 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea @@ -361,6 +372,12 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea
361 { 372 {
362 int ret = ERROR_SUCCESS; 373 int ret = ERROR_SUCCESS;
363 374
  375 + if (vs != SrsTsStreamVideoH264 && as != SrsTsStreamAudioAAC && as != SrsTsStreamAudioMp3) {
  376 + ret = ERROR_HLS_NO_STREAM;
  377 + srs_error("hls: no pmt pcr pid, vs=%d, as=%d. ret=%d", vs, as, ret);
  378 + return ret;
  379 + }
  380 +
364 int16_t pmt_number = TS_PMT_NUMBER; 381 int16_t pmt_number = TS_PMT_NUMBER;
365 int16_t pmt_pid = TS_PMT_PID; 382 int16_t pmt_pid = TS_PMT_PID;
366 if (true) { 383 if (true) {
@@ -754,15 +771,17 @@ SrsTsPacket* SrsTsPacket::create_pmt(SrsTsContext* context, int16_t pmt_number, @@ -754,15 +771,17 @@ SrsTsPacket* SrsTsPacket::create_pmt(SrsTsContext* context, int16_t pmt_number,
754 pmt->last_section_number = 0; 771 pmt->last_section_number = 0;
755 pmt->program_info_length = 0; 772 pmt->program_info_length = 0;
756 773
757 - // use audio to carray pcr by default.  
758 - // for hls, there must be atleast one audio channel.  
759 - pmt->PCR_PID = apid;  
760 - pmt->infos.push_back(new SrsTsPayloadPMTESInfo(as, apid));  
761 -  
762 // if h.264 specified, use video to carry pcr. 774 // if h.264 specified, use video to carry pcr.
763 if (vs == SrsTsStreamVideoH264) { 775 if (vs == SrsTsStreamVideoH264) {
764 pmt->PCR_PID = vpid; 776 pmt->PCR_PID = vpid;
765 pmt->infos.push_back(new SrsTsPayloadPMTESInfo(vs, vpid)); 777 pmt->infos.push_back(new SrsTsPayloadPMTESInfo(vs, vpid));
  778 + } else if (as == SrsTsStreamAudioAAC || as == SrsTsStreamAudioMp3) {
  779 + // use audio to carray pcr by default.
  780 + // for hls, there must be atleast one audio channel.
  781 + pmt->PCR_PID = apid;
  782 + pmt->infos.push_back(new SrsTsPayloadPMTESInfo(as, apid));
  783 + } else {
  784 + srs_assert(false);
766 } 785 }
767 786
768 pmt->CRC_32 = 0; // calc in encode. 787 pmt->CRC_32 = 0; // calc in encode.