diff --git a/packager/hls/base/media_playlist.cc b/packager/hls/base/media_playlist.cc index 16ce34c1b6..66cbd941aa 100644 --- a/packager/hls/base/media_playlist.cc +++ b/packager/hls/base/media_playlist.cc @@ -123,7 +123,8 @@ HlsEntry::~HlsEntry() {} MediaPlaylist::MediaPlaylist(const std::string& file_name, const std::string& name, const std::string& group_id) - : file_name_(file_name), name_(name), group_id_(group_id) {} + : file_name_(file_name), name_(name), group_id_(group_id), + entries_deleter_(&entries_) {} MediaPlaylist::~MediaPlaylist() {} void MediaPlaylist::SetTypeForTesting(MediaPlaylistType type) { @@ -164,8 +165,7 @@ void MediaPlaylist::AddSegment(const std::string& file_name, LOG(WARNING) << "Timescale is not set and the duration for " << duration << " cannot be calculated. The output will be wrong."; - scoped_ptr info(new SegmentInfoEntry(file_name, 0.0)); - entries_.push_back(info.Pass()); + entries_.push_back(new SegmentInfoEntry(file_name, 0.0)); return; } @@ -177,9 +177,7 @@ void MediaPlaylist::AddSegment(const std::string& file_name, total_segments_size_ += size; ++total_num_segments_; - scoped_ptr info( - new SegmentInfoEntry(file_name, segment_duration)); - entries_.push_back(info.Pass()); + entries_.push_back(new SegmentInfoEntry(file_name, segment_duration)); } // TODO(rkuroiwa): This works for single key format but won't work for multiple @@ -194,11 +192,12 @@ void MediaPlaylist::AddSegment(const std::string& file_name, // invalidated. void MediaPlaylist::RemoveOldestSegment() { static_assert( - std::is_same>>::value, + base::is_same>::value, "This algorithm assumes std::list."); if (entries_.empty()) return; if (entries_.front()->type() == HlsEntry::EntryType::kExtInf) { + delete entries_.front(); entries_.pop_front(); return; } @@ -216,8 +215,10 @@ void MediaPlaylist::RemoveOldestSegment() { auto entries_itr = entries_.begin(); ++entries_itr; if ((*entries_itr)->type() == HlsEntry::EntryType::kExtKey) { + delete entries_.front(); entries_.pop_front(); } else { + delete *entries_itr; entries_.erase(entries_itr); } return; @@ -227,6 +228,7 @@ void MediaPlaylist::RemoveOldestSegment() { ++entries_itr; if ((*entries_itr)->type() == HlsEntry::EntryType::kExtInf) { DCHECK((*entries_itr)->type() == HlsEntry::EntryType::kExtInf); + delete *entries_itr; entries_.erase(entries_itr); return; } @@ -235,7 +237,9 @@ void MediaPlaylist::RemoveOldestSegment() { // This assumes that there is a segment between 2 EXT-X-KEY entries. // Which should be the case due to logic in AddEncryptionInfo(). DCHECK((*entries_itr)->type() == HlsEntry::EntryType::kExtInf); + delete *entries_itr; entries_.erase(entries_itr); + delete entries_.front(); entries_.pop_front(); } @@ -250,9 +254,9 @@ void MediaPlaylist::AddEncryptionInfo(MediaPlaylist::EncryptionMethod method, if (entries_.back()->type() == HlsEntry::EntryType::kExtKey) entries_.pop_back(); } - scoped_ptr info(new EncryptionInfoEntry( - method, url, iv, key_format, key_format_versions)); - entries_.push_back(info.Pass()); + entries_.push_back( + new EncryptionInfoEntry( + method, url, iv, key_format, key_format_versions)); } bool MediaPlaylist::WriteToFile(media::File* file) { diff --git a/packager/hls/base/media_playlist.h b/packager/hls/base/media_playlist.h index 37c3b4113d..fd21f7cda0 100644 --- a/packager/hls/base/media_playlist.h +++ b/packager/hls/base/media_playlist.h @@ -12,6 +12,7 @@ #include "packager/base/macros.h" #include "packager/base/memory/scoped_ptr.h" +#include "packager/base/stl_util.h" #include "packager/mpd/base/media_info.pb.h" namespace edash_packager { @@ -164,7 +165,8 @@ class MediaPlaylist { bool target_duration_set_ = false; uint32_t target_duration_ = 0; - std::list> entries_; + std::list entries_; + STLElementDeleter entries_deleter_; DISALLOW_COPY_AND_ASSIGN(MediaPlaylist); };