Fix potential incorrect target duration in iFrame Playlist
This may happen if media segments do not start with iframes. Change-Id: Ie7b2d33a14405a5dcd071644f2fa3d5f9656dd07
This commit is contained in:
parent
cf40accaa8
commit
1a52a9b7c0
|
@ -521,8 +521,8 @@ void MediaPlaylist::AddSegmentInfoEntry(const std::string& segment_file_name,
|
|||
static_cast<double>(start_time) / time_scale_;
|
||||
const double segment_duration_seconds =
|
||||
static_cast<double>(duration) / time_scale_;
|
||||
if (segment_duration_seconds > longest_segment_duration_)
|
||||
longest_segment_duration_ = segment_duration_seconds;
|
||||
longest_segment_duration_ =
|
||||
std::max(longest_segment_duration_, segment_duration_seconds);
|
||||
|
||||
const int kBitsInByte = 8;
|
||||
const uint64_t bitrate = kBitsInByte * size / segment_duration_seconds;
|
||||
|
@ -539,15 +539,19 @@ void MediaPlaylist::AdjustLastSegmentInfoEntryDuration(
|
|||
if (time_scale_ == 0)
|
||||
return;
|
||||
|
||||
const double scaled_next_timestamp =
|
||||
const double next_timestamp_seconds =
|
||||
static_cast<double>(next_timestamp) / time_scale_;
|
||||
|
||||
for (auto iter = entries_.rbegin(); iter != entries_.rend(); ++iter) {
|
||||
if (iter->get()->type() == HlsEntry::EntryType::kExtInf) {
|
||||
SegmentInfoEntry* segment_info =
|
||||
reinterpret_cast<SegmentInfoEntry*>(iter->get());
|
||||
segment_info->set_duration(scaled_next_timestamp -
|
||||
segment_info->start_time());
|
||||
|
||||
const double segment_duration_seconds =
|
||||
next_timestamp_seconds - segment_info->start_time();
|
||||
segment_info->set_duration(segment_duration_seconds);
|
||||
longest_segment_duration_ =
|
||||
std::max(longest_segment_duration_, segment_duration_seconds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -811,7 +811,7 @@ TEST_F(IFrameMediaPlaylistTest, SingleSegment) {
|
|||
"#EXT-X-VERSION:6\n"
|
||||
"## Generated with https://github.com/google/shaka-packager version "
|
||||
"test\n"
|
||||
"#EXT-X-TARGETDURATION:8\n"
|
||||
"#EXT-X-TARGETDURATION:9\n"
|
||||
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
||||
"#EXT-X-I-FRAMES-ONLY\n"
|
||||
"#EXT-X-MAP:URI=\"file.mp4\",BYTERANGE=\"501@0\"\n"
|
||||
|
|
Loading…
Reference in New Issue