winlin

for #512, partical hotfix the hls pure audio. 2.0.196

@@ -336,6 +336,7 @@ Remark: @@ -336,6 +336,7 @@ Remark:
336 336
337 ## History 337 ## History
338 338
  339 +* v2.0, 2015-10-27, for [#512][bug #512] partical hotfix the hls pure audio. 2.0.196
339 * <strong>v2.0, 2015-10-08, [2.0 alpha2(2.0.195)][r2.0a2] released. 89358 lines.</strong> 340 * <strong>v2.0, 2015-10-08, [2.0 alpha2(2.0.195)][r2.0a2] released. 89358 lines.</strong>
340 * v2.0, 2015-10-04, for [#448][bug #448] fix the bug of response of http hooks. 2.0.195 341 * v2.0, 2015-10-04, for [#448][bug #448] fix the bug of response of http hooks. 2.0.195
341 * v2.0, 2015-10-01, for [#497][bug #497] response error when client not found to kickoff. 2.0.194 342 * v2.0, 2015-10-01, for [#497][bug #497] response error when client not found to kickoff. 2.0.194
@@ -578,6 +578,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) @@ -578,6 +578,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
578 current->full_path.c_str(), tmp_file.c_str()); 578 current->full_path.c_str(), tmp_file.c_str());
579 579
580 // set the segment muxer audio codec. 580 // set the segment muxer audio codec.
  581 + // TODO: FIXME: refine code, use event instead.
581 if (acodec != SrsCodecAudioReserved1) { 582 if (acodec != SrsCodecAudioReserved1) {
582 current->muxer->update_acodec(acodec); 583 current->muxer->update_acodec(acodec);
583 } 584 }
@@ -1069,6 +1070,13 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t @@ -1069,6 +1070,13 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t
1069 } 1070 }
1070 } 1071 }
1071 1072
  1073 + // for pure audio, aggregate some frame to one.
  1074 + if (muxer->pure_audio() && cache->audio) {
  1075 + if (pts - cache->audio->start_pts < SRS_CONSTS_HLS_PURE_AUDIO_AGGREGATE) {
  1076 + return ret;
  1077 + }
  1078 + }
  1079 +
1072 // directly write the audio frame by frame to ts, 1080 // directly write the audio frame by frame to ts,
1073 // it's ok for the hls overload, or maybe cause the audio corrupt, 1081 // it's ok for the hls overload, or maybe cause the audio corrupt,
1074 // which introduced by aggregate the audios to a big one. 1082 // which introduced by aggregate the audios to a big one.
@@ -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 195 34 +#define VERSION_REVISION 196
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -459,8 +459,11 @@ int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t p @@ -459,8 +459,11 @@ int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t p
459 while (p < end) { 459 while (p < end) {
460 SrsTsPacket* pkt = NULL; 460 SrsTsPacket* pkt = NULL;
461 if (p == start) { 461 if (p == start) {
462 - // for pure audio stream, always write pcr. 462 + // write pcr according to message.
463 bool write_pcr = msg->write_pcr; 463 bool write_pcr = msg->write_pcr;
  464 +
  465 + // for pure audio, always write pcr.
  466 + // TODO: FIXME: maybe only need to write at begin and end of ts.
464 if (pure_audio && msg->is_audio()) { 467 if (pure_audio && msg->is_audio()) {
465 write_pcr = true; 468 write_pcr = true;
466 } 469 }
@@ -2785,11 +2788,12 @@ int SrsTsCache::cache_audio(SrsAvcAacCodec* codec, int64_t dts, SrsCodecSample* @@ -2785,11 +2788,12 @@ int SrsTsCache::cache_audio(SrsAvcAacCodec* codec, int64_t dts, SrsCodecSample*
2785 if (!audio) { 2788 if (!audio) {
2786 audio = new SrsTsMessage(); 2789 audio = new SrsTsMessage();
2787 audio->write_pcr = false; 2790 audio->write_pcr = false;
2788 - audio->start_pts = dts; 2791 + audio->dts = audio->pts = audio->start_pts = dts;
2789 } 2792 }
2790 2793
2791 - audio->dts = dts;  
2792 - audio->pts = audio->dts; 2794 + // TODO: FIXME: refine code.
  2795 + //audio->dts = dts;
  2796 + //audio->pts = audio->dts;
2793 audio->sid = SrsTsPESStreamIdAudioCommon; 2797 audio->sid = SrsTsPESStreamIdAudioCommon;
2794 2798
2795 // must be aac or mp3 2799 // must be aac or mp3
@@ -3139,6 +3143,8 @@ int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size) @@ -3139,6 +3143,8 @@ int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size)
3139 return ret; 3143 return ret;
3140 } 3144 }
3141 3145
  3146 + // TODO: FIXME: for pure audio, aggregate some frame to one.
  3147 +
3142 // always flush audio frame by frame. 3148 // always flush audio frame by frame.
3143 // @see https://github.com/simple-rtmp-server/srs/issues/512 3149 // @see https://github.com/simple-rtmp-server/srs/issues/512
3144 return flush_audio(); 3150 return flush_audio();
@@ -54,6 +54,9 @@ class SrsTsContext; @@ -54,6 +54,9 @@ class SrsTsContext;
54 // Transport Stream packets are 188 bytes in length. 54 // Transport Stream packets are 188 bytes in length.
55 #define SRS_TS_PACKET_SIZE 188 55 #define SRS_TS_PACKET_SIZE 188
56 56
  57 +// the aggregate pure audio for hls, in ts tbn(ms * 90).
  58 +#define SRS_CONSTS_HLS_PURE_AUDIO_AGGREGATE 720 * 90
  59 +
57 /** 60 /**
58 * the pid of ts packet, 61 * the pid of ts packet,
59 * Table 2-3 - PID table, hls-mpeg-ts-iso13818-1.pdf, page 37 62 * Table 2-3 - PID table, hls-mpeg-ts-iso13818-1.pdf, page 37
@@ -359,6 +362,7 @@ public: @@ -359,6 +362,7 @@ public:
359 /** 362 /**
360 * whether the hls stream is pure audio stream. 363 * whether the hls stream is pure audio stream.
361 */ 364 */
  365 + // TODO: FIXME: merge with muxer codec detect.
362 virtual bool is_pure_audio(); 366 virtual bool is_pure_audio();
363 /** 367 /**
364 * when PMT table parsed, we know some info about stream. 368 * when PMT table parsed, we know some info about stream.