winlin

refine hls, try to fix the hls ts corrupt problem.

@@ -758,7 +758,7 @@ int SrsHlsCache::write_video(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t @@ -758,7 +758,7 @@ int SrsHlsCache::write_video(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t
758 // new segment when: 758 // new segment when:
759 // 1. base on gop. 759 // 1. base on gop.
760 // 2. some gops duration overflow. 760 // 2. some gops duration overflow.
761 - if (cache->vf->key && muxer->is_segment_overflow()) { 761 + if (sample->frame_type == SrsCodecVideoAVCFrameKeyFrame && muxer->is_segment_overflow()) {
762 if ((ret = reap_segment("video", muxer, cache->vf->dts)) != ERROR_SUCCESS) { 762 if ((ret = reap_segment("video", muxer, cache->vf->dts)) != ERROR_SUCCESS) {
763 return ret; 763 return ret;
764 } 764 }
@@ -788,6 +788,7 @@ int SrsHlsCache::reap_segment(string log_desc, SrsHlsMuxer* muxer, int64_t segme @@ -788,6 +788,7 @@ int SrsHlsCache::reap_segment(string log_desc, SrsHlsMuxer* muxer, int64_t segme
788 } 788 }
789 789
790 // TODO: flush audio before or after segment? 790 // TODO: flush audio before or after segment?
  791 + // TODO: fresh segment begin with audio or video?
791 792
792 // segment open, flush video first. 793 // segment open, flush video first.
793 if ((ret = muxer->flush_video(cache->af, cache->ab, cache->vf, cache->vb)) != ERROR_SUCCESS) { 794 if ((ret = muxer->flush_video(cache->af, cache->ab, cache->vf, cache->vb)) != ERROR_SUCCESS) {
@@ -233,10 +233,10 @@ extern int aac_sample_rates[]; @@ -233,10 +233,10 @@ extern int aac_sample_rates[];
233 #define __SRS_AAC_SAMPLE_RATE_UNSET 15 233 #define __SRS_AAC_SAMPLE_RATE_UNSET 15
234 234
235 // in ms, for HLS aac flush the audio 235 // in ms, for HLS aac flush the audio
236 -#define SRS_CONF_DEFAULT_AAC_DELAY 100 236 +#define SRS_CONF_DEFAULT_AAC_DELAY 60
237 237
238 // max PES packets size to flush the video. 238 // max PES packets size to flush the video.
239 -#define SRS_AUTO_HLS_AUDIO_CACHE_SIZE 1024 * 1024 239 +#define SRS_AUTO_HLS_AUDIO_CACHE_SIZE 128 * 1024
240 240
241 /** 241 /**
242 * the FLV/RTMP supported audio sample size. 242 * the FLV/RTMP supported audio sample size.
@@ -224,7 +224,7 @@ public: @@ -224,7 +224,7 @@ public:
224 224
225 if (first) { 225 if (first) {
226 first = false; 226 first = false;
227 - if (frame->key) { 227 + if (frame->write_pcr) {
228 p[-1] |= 0x20; // Both Adaption and Payload 228 p[-1] |= 0x20; // Both Adaption and Payload
229 *p++ = 7; // size 229 *p++ = 7; // size
230 *p++ = 0x50; // random access + PCR 230 *p++ = 0x50; // random access + PCR
@@ -399,7 +399,7 @@ SrsMpegtsFrame::SrsMpegtsFrame() @@ -399,7 +399,7 @@ SrsMpegtsFrame::SrsMpegtsFrame()
399 { 399 {
400 pts = dts = 0; 400 pts = dts = 0;
401 pid = sid = cc = 0; 401 pid = sid = cc = 0;
402 - key = false; 402 + write_pcr = false;
403 } 403 }
404 404
405 string srs_ts_stream2string(SrsTsStream stream) 405 string srs_ts_stream2string(SrsTsStream stream)
@@ -1971,7 +1971,7 @@ int SrsTsCache::cache_video(SrsAvcAacCodec* codec, int64_t dts, SrsCodecSample* @@ -1971,7 +1971,7 @@ int SrsTsCache::cache_video(SrsAvcAacCodec* codec, int64_t dts, SrsCodecSample*
1971 vf->pts = vf->dts + sample->cts * 90; 1971 vf->pts = vf->dts + sample->cts * 90;
1972 vf->pid = TS_VIDEO_PID; 1972 vf->pid = TS_VIDEO_PID;
1973 vf->sid = TS_VIDEO_AVC; 1973 vf->sid = TS_VIDEO_AVC;
1974 - vf->key = sample->frame_type == SrsCodecVideoAVCFrameKeyFrame; 1974 + vf->write_pcr = sample->frame_type == SrsCodecVideoAVCFrameKeyFrame;
1975 1975
1976 return ret; 1976 return ret;
1977 } 1977 }
@@ -60,7 +60,7 @@ public: @@ -60,7 +60,7 @@ public:
60 int pid; 60 int pid;
61 int sid; 61 int sid;
62 int cc; 62 int cc;
63 - bool key; 63 + bool write_pcr;
64 64
65 SrsMpegtsFrame(); 65 SrsMpegtsFrame();
66 }; 66 };