mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
drop ts segment when duration is too small
This commit is contained in:
parent
5758551508
commit
4f284b20f0
1 changed files with 36 additions and 15 deletions
|
@ -47,6 +47,9 @@ using namespace std;
|
||||||
// max PES packets size to flush the video.
|
// max PES packets size to flush the video.
|
||||||
#define SRS_HLS_AUDIO_CACHE_SIZE 1024 * 1024
|
#define SRS_HLS_AUDIO_CACHE_SIZE 1024 * 1024
|
||||||
|
|
||||||
|
// drop the segment when duration of ts too small.
|
||||||
|
#define SRS_HLS_SEGMENT_MIN_DURATION_MS 100
|
||||||
|
|
||||||
// @see: NGX_RTMP_HLS_DELAY,
|
// @see: NGX_RTMP_HLS_DELAY,
|
||||||
// 63000: 700ms, ts_tbn=90000
|
// 63000: 700ms, ts_tbn=90000
|
||||||
#define SRS_HLS_DELAY 63000
|
#define SRS_HLS_DELAY 63000
|
||||||
|
@ -680,24 +683,39 @@ int SrsHlsMuxer::segment_close(string log_desc)
|
||||||
it = std::find(segments.begin(), segments.end(), current);
|
it = std::find(segments.begin(), segments.end(), current);
|
||||||
srs_assert(it == segments.end());
|
srs_assert(it == segments.end());
|
||||||
|
|
||||||
// valid, add to segments.
|
// valid, add to segments if segment duration is ok
|
||||||
segments.push_back(current);
|
if (current->duration * 1000 >= SRS_HLS_SEGMENT_MIN_DURATION_MS) {
|
||||||
|
segments.push_back(current);
|
||||||
|
|
||||||
srs_trace("%s reap ts segment, sequence_no=%d, uri=%s, duration=%.2f, start=%"PRId64"",
|
srs_trace("%s reap ts segment, sequence_no=%d, uri=%s, duration=%.2f, start=%"PRId64"",
|
||||||
log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration,
|
log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration,
|
||||||
current->segment_start_dts);
|
current->segment_start_dts);
|
||||||
|
|
||||||
// close the muxer of finished segment.
|
// close the muxer of finished segment.
|
||||||
srs_freep(current->muxer);
|
srs_freep(current->muxer);
|
||||||
// rename from tmp to real path
|
// rename from tmp to real path
|
||||||
std::string tmp_file = current->full_path + ".tmp";
|
std::string tmp_file = current->full_path + ".tmp";
|
||||||
if (rename(tmp_file.c_str(), current->full_path.c_str()) < 0) {
|
if (rename(tmp_file.c_str(), current->full_path.c_str()) < 0) {
|
||||||
ret = ERROR_HLS_WRITE_FAILED;
|
ret = ERROR_HLS_WRITE_FAILED;
|
||||||
srs_error("rename ts file failed, %s => %s. ret=%d",
|
srs_error("rename ts file failed, %s => %s. ret=%d",
|
||||||
tmp_file.c_str(), current->full_path.c_str(), ret);
|
tmp_file.c_str(), current->full_path.c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
current = NULL;
|
||||||
|
} else {
|
||||||
|
// reuse current segment index.
|
||||||
|
file_index--;
|
||||||
|
|
||||||
|
srs_trace("%s drop ts segment, sequence_no=%d, uri=%s, duration=%.2f, start=%"PRId64"",
|
||||||
|
log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration,
|
||||||
|
current->segment_start_dts);
|
||||||
|
|
||||||
|
// rename from tmp to real path
|
||||||
|
std::string tmp_file = current->full_path + ".tmp";
|
||||||
|
unlink(tmp_file.c_str());
|
||||||
|
|
||||||
|
srs_freep(current);
|
||||||
}
|
}
|
||||||
current = NULL;
|
|
||||||
|
|
||||||
// the segments to remove
|
// the segments to remove
|
||||||
std::vector<SrsHlsSegment*> segment_to_remove;
|
std::vector<SrsHlsSegment*> segment_to_remove;
|
||||||
|
@ -941,6 +959,9 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment
|
||||||
// reset video count for new publish session.
|
// reset video count for new publish session.
|
||||||
video_count = 0;
|
video_count = 0;
|
||||||
|
|
||||||
|
// TODO: FIXME: support load exists m3u8, to continue publish stream.
|
||||||
|
// for the HLS donot requires the EXT-X-MEDIA-SEQUENCE be monotonically increase.
|
||||||
|
|
||||||
// open muxer
|
// open muxer
|
||||||
if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) {
|
if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) {
|
||||||
srs_error("m3u8 muxer update config failed. ret=%d", ret);
|
srs_error("m3u8 muxer update config failed. ret=%d", ret);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue