From c3d1dc1733dd3ab05bceedf52d86857e6ad611bc Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Tue, 30 Aug 2016 16:01:19 -0700 Subject: [PATCH] Deprecate STLDeleter and string_as_array 1. Replace STLDeleter with unique_ptr in container, which is supported in C++11 2. Replace string_as_array with &string[0] which is guaranteed to work in C++11 Change-Id: I7f39c0e51fc8a3fcbb41313094a0ca6b33db7bf3 --- packager/app/packager_main.cc | 35 ++++++---------- packager/app/packager_util.cc | 28 +++++++------ packager/app/packager_util.h | 4 +- packager/hls/base/media_playlist.cc | 31 ++++++-------- packager/hls/base/media_playlist.h | 5 +-- packager/hls/base/simple_hls_notifier.cc | 5 +-- packager/hls/base/simple_hls_notifier.h | 4 +- .../hls/base/simple_hls_notifier_unittest.cc | 3 +- packager/media/base/aes_cryptor.cc | 12 ++---- packager/media/base/decryptor_source.cc | 13 +++--- packager/media/base/decryptor_source.h | 3 +- packager/media/base/demuxer.cc | 30 +++++--------- packager/media/base/demuxer.h | 6 ++- packager/media/base/rsa_key.cc | 34 ++++++---------- packager/media/base/video_stream_info.cc | 1 - packager/media/base/widevine_key_source.cc | 26 +++++------- packager/media/base/widevine_key_source.h | 2 +- packager/media/codecs/h264_parser.cc | 16 +++----- packager/media/codecs/h264_parser.h | 5 ++- packager/media/codecs/h265_parser.cc | 16 +++----- packager/media/codecs/h265_parser.h | 4 +- .../media/formats/mp2t/mp2t_media_parser.cc | 40 +++++++++---------- .../media/formats/mp2t/mp2t_media_parser.h | 2 +- .../formats/mp2t/pes_packet_generator.cc | 14 +++---- .../media/formats/mp2t/pes_packet_generator.h | 4 +- packager/media/formats/mp4/segmenter.cc | 30 ++++++-------- packager/media/formats/mp4/segmenter.h | 2 +- .../webm/webm_content_encodings_client.cc | 11 ++--- .../webm/webm_content_encodings_client.h | 3 +- .../media/formats/webm/webm_video_client.cc | 1 - packager/media/test/packager_test.cc | 20 +++++----- packager/mpd/base/dash_iop_mpd_notifier.cc | 1 + packager/mpd/base/mpd_builder.cc | 36 ++++++++--------- packager/mpd/base/mpd_builder.h | 7 +--- packager/mpd/base/simple_mpd_notifier.cc | 1 + packager/mpd/base/xml/xml_node.cc | 1 - 36 files changed, 190 insertions(+), 266 deletions(-) diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index f2cd87e865..deeed2503e 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -21,7 +21,6 @@ #include "packager/base/files/file_path.h" #include "packager/base/logging.h" #include "packager/base/path_service.h" -#include "packager/base/stl_util.h" #include "packager/base/strings/string_split.h" #include "packager/base/strings/stringprintf.h" #include "packager/base/threading/simple_thread.h" @@ -167,12 +166,10 @@ class RemuxJob : public base::SimpleThread { RemuxJob(std::unique_ptr demuxer) : SimpleThread("RemuxJob"), demuxer_(std::move(demuxer)) {} - ~RemuxJob() override { - STLDeleteElements(&muxers_); - } + ~RemuxJob() override {} void AddMuxer(std::unique_ptr mux) { - muxers_.push_back(mux.release()); + muxers_.push_back(std::move(mux)); } Demuxer* demuxer() { return demuxer_.get(); } @@ -185,7 +182,7 @@ class RemuxJob : public base::SimpleThread { } std::unique_ptr demuxer_; - std::vector muxers_; + std::vector> muxers_; Status status_; DISALLOW_COPY_AND_ASSIGN(RemuxJob); @@ -248,7 +245,7 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors, KeySource* key_source, MpdNotifier* mpd_notifier, hls::HlsNotifier* hls_notifier, - std::vector* remux_jobs) { + std::vector>* remux_jobs) { // No notifiers OR (mpd_notifier XOR hls_notifier); which is NAND. DCHECK(!(mpd_notifier && hls_notifier)); DCHECK(remux_jobs); @@ -326,7 +323,7 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors, if (stream_iter->output.empty()) continue; // just need stream info. } - remux_jobs->push_back(new RemuxJob(std::move(demuxer))); + remux_jobs->emplace_back(new RemuxJob(std::move(demuxer))); previous_input = stream_iter->input; } DCHECK(!remux_jobs->empty()); @@ -391,29 +388,24 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors, return true; } -Status RunRemuxJobs(const std::vector& remux_jobs) { +Status RunRemuxJobs(const std::vector>& remux_jobs) { // Start the job threads. - for (std::vector::const_iterator job_iter = remux_jobs.begin(); - job_iter != remux_jobs.end(); - ++job_iter) { - (*job_iter)->Start(); - } + for (const std::unique_ptr& job : remux_jobs) + job->Start(); // Wait for all jobs to complete or an error occurs. Status status; bool all_joined; do { all_joined = true; - for (std::vector::const_iterator job_iter = remux_jobs.begin(); - job_iter != remux_jobs.end(); - ++job_iter) { - if ((*job_iter)->HasBeenJoined()) { - status = (*job_iter)->status(); + for (const std::unique_ptr& job : remux_jobs) { + if (job->HasBeenJoined()) { + status = job->status(); if (!status.ok()) break; } else { all_joined = false; - (*job_iter)->Join(); + job->Join(); } } } while (!all_joined && status.ok()); @@ -496,8 +488,7 @@ bool RunPackager(const StreamDescriptorList& stream_descriptors) { master_playlist_name.AsUTF8Unsafe())); } - std::vector remux_jobs; - STLElementDeleter > scoped_jobs_deleter(&remux_jobs); + std::vector> remux_jobs; FakeClock fake_clock; if (!CreateRemuxJobs(stream_descriptors, muxer_options, &fake_clock, encryption_key_source.get(), mpd_notifier.get(), diff --git a/packager/app/packager_util.cc b/packager/app/packager_util.cc index e08c6a3f58..ca7cf13003 100644 --- a/packager/app/packager_util.cc +++ b/packager/app/packager_util.cc @@ -36,7 +36,7 @@ DEFINE_bool(dump_stream_info, false, "Dump demuxed stream info."); namespace shaka { namespace media { -void DumpStreamInfo(const std::vector& streams) { +void DumpStreamInfo(const std::vector>& streams) { printf("Found %zu stream(s).\n", streams.size()); for (size_t i = 0; i < streams.size(); ++i) printf("Stream [%zu] %s\n", i, streams[i]->info()->ToString().c_str()); @@ -180,29 +180,31 @@ bool GetMpdOptions(MpdOptions* mpd_options) { return true; } -MediaStream* FindFirstStreamOfType(const std::vector& streams, - StreamType stream_type) { - typedef std::vector::const_iterator StreamIterator; - for (StreamIterator it = streams.begin(); it != streams.end(); ++it) { - if ((*it)->info()->stream_type() == stream_type) - return *it; +MediaStream* FindFirstStreamOfType( + const std::vector>& streams, + StreamType stream_type) { + for (const std::unique_ptr& stream : streams) { + if (stream->info()->stream_type() == stream_type) + return stream.get(); } - return NULL; + return nullptr; } -MediaStream* FindFirstVideoStream(const std::vector& streams) { +MediaStream* FindFirstVideoStream( + const std::vector>& streams) { return FindFirstStreamOfType(streams, kStreamVideo); } -MediaStream* FindFirstAudioStream(const std::vector& streams) { +MediaStream* FindFirstAudioStream( + const std::vector>& streams) { return FindFirstStreamOfType(streams, kStreamAudio); } -bool AddStreamToMuxer(const std::vector& streams, +bool AddStreamToMuxer(const std::vector>& streams, const std::string& stream_selector, const std::string& language_override, Muxer* muxer) { DCHECK(muxer); - MediaStream* stream = NULL; + MediaStream* stream = nullptr; if (stream_selector == "video") { stream = FindFirstVideoStream(streams); } else if (stream_selector == "audio") { @@ -217,7 +219,7 @@ bool AddStreamToMuxer(const std::vector& streams, << streams.size() - 1 << "]."; return false; } - stream = streams[stream_id]; + stream = streams[stream_id].get(); DCHECK(stream); } diff --git a/packager/app/packager_util.h b/packager/app/packager_util.h index 3bc90e1627..e034224760 100644 --- a/packager/app/packager_util.h +++ b/packager/app/packager_util.h @@ -28,7 +28,7 @@ class Muxer; struct MuxerOptions; /// Print all the stream info for the provided strings to standard output. -void DumpStreamInfo(const std::vector& streams); +void DumpStreamInfo(const std::vector>& streams); /// Create KeySource based on provided command line options for content /// encryption. Also fetches keys. @@ -60,7 +60,7 @@ bool GetMpdOptions(MpdOptions* mpd_options); /// @param language_override is a string which, if non-empty, overrides the /// stream's language metadata. /// @return true if successful, false otherwise. -bool AddStreamToMuxer(const std::vector& streams, +bool AddStreamToMuxer(const std::vector>& streams, const std::string& stream_selector, const std::string& language_override, Muxer* muxer); diff --git a/packager/hls/base/media_playlist.cc b/packager/hls/base/media_playlist.cc index 77d2e5dd8a..87ad00b279 100644 --- a/packager/hls/base/media_playlist.cc +++ b/packager/hls/base/media_playlist.cc @@ -8,6 +8,7 @@ #include #include +#include #include "packager/base/logging.h" #include "packager/base/strings/stringprintf.h" @@ -125,14 +126,11 @@ MediaPlaylist::MediaPlaylist(MediaPlaylistType type, const std::string& file_name, const std::string& name, const std::string& group_id) - : file_name_(file_name), - name_(name), - group_id_(group_id), - type_(type), - entries_deleter_(&entries_) { + : file_name_(file_name), name_(name), group_id_(group_id), type_(type) { LOG_IF(WARNING, type != MediaPlaylistType::kVod) << "Non VOD Media Playlist is not supported."; } + MediaPlaylist::~MediaPlaylist() {} void MediaPlaylist::SetStreamTypeForTesting( @@ -174,7 +172,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."; - entries_.push_back(new SegmentInfoEntry(file_name, 0.0)); + entries_.emplace_back(new SegmentInfoEntry(file_name, 0.0)); return; } @@ -186,7 +184,8 @@ void MediaPlaylist::AddSegment(const std::string& file_name, const int kBitsInByte = 8; const uint64_t bitrate = kBitsInByte * size / segment_duration_seconds; max_bitrate_ = std::max(max_bitrate_, bitrate); - entries_.push_back(new SegmentInfoEntry(file_name, segment_duration_seconds)); + entries_.emplace_back( + new SegmentInfoEntry(file_name, segment_duration_seconds)); } // TODO(rkuroiwa): This works for single key format but won't work for multiple @@ -200,12 +199,12 @@ void MediaPlaylist::AddSegment(const std::string& file_name, // Note that when erasing std::list iterators, only the deleted iterators are // invalidated. void MediaPlaylist::RemoveOldestSegment() { - static_assert(std::is_same>::value, + static_assert(std::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; } @@ -223,10 +222,8 @@ 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; @@ -235,8 +232,7 @@ void MediaPlaylist::RemoveOldestSegment() { auto entries_itr = entries_.begin(); ++entries_itr; if ((*entries_itr)->type() == HlsEntry::EntryType::kExtInf) { - DCHECK((*entries_itr)->type() == HlsEntry::EntryType::kExtInf); - delete *entries_itr; + DCHECK_EQ((*entries_itr)->type(), HlsEntry::EntryType::kExtInf); entries_.erase(entries_itr); return; } @@ -244,10 +240,8 @@ void MediaPlaylist::RemoveOldestSegment() { ++entries_itr; // 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; + DCHECK_EQ((*entries_itr)->type(), HlsEntry::EntryType::kExtInf); entries_.erase(entries_itr); - delete entries_.front(); entries_.pop_front(); } @@ -262,9 +256,8 @@ void MediaPlaylist::AddEncryptionInfo(MediaPlaylist::EncryptionMethod method, if (entries_.back()->type() == HlsEntry::EntryType::kExtKey) entries_.pop_back(); } - entries_.push_back( - new EncryptionInfoEntry( - method, url, iv, key_format, key_format_versions)); + entries_.emplace_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 2a53e5df4c..583b3eebbb 100644 --- a/packager/hls/base/media_playlist.h +++ b/packager/hls/base/media_playlist.h @@ -8,10 +8,10 @@ #define PACKAGER_HLS_BASE_MEDIA_PLAYLIST_H_ #include +#include #include #include "packager/base/macros.h" -#include "packager/base/stl_util.h" #include "packager/mpd/base/media_info.pb.h" namespace shaka { @@ -169,8 +169,7 @@ class MediaPlaylist { bool target_duration_set_ = false; uint32_t target_duration_ = 0; - std::list entries_; - STLElementDeleter entries_deleter_; + std::list> entries_; DISALLOW_COPY_AND_ASSIGN(MediaPlaylist); }; diff --git a/packager/hls/base/simple_hls_notifier.cc b/packager/hls/base/simple_hls_notifier.cc index 7f5549553d..07dde8984e 100644 --- a/packager/hls/base/simple_hls_notifier.cc +++ b/packager/hls/base/simple_hls_notifier.cc @@ -131,8 +131,7 @@ SimpleHlsNotifier::SimpleHlsNotifier(HlsProfile profile, prefix_(prefix), output_dir_(output_dir), media_playlist_factory_(new MediaPlaylistFactory()), - master_playlist_(new MasterPlaylist(master_playlist_name)), - media_playlist_map_deleter_(&media_playlist_map_) {} + master_playlist_(new MasterPlaylist(master_playlist_name)) {} SimpleHlsNotifier::~SimpleHlsNotifier() {} @@ -174,7 +173,7 @@ bool SimpleHlsNotifier::NotifyNewStream(const MediaInfo& media_info, base::AutoLock auto_lock(lock_); master_playlist_->AddMediaPlaylist(media_playlist.get()); media_playlist_map_.insert( - std::make_pair(*stream_id, media_playlist.release())); + std::make_pair(*stream_id, std::move(media_playlist))); return true; } diff --git a/packager/hls/base/simple_hls_notifier.h b/packager/hls/base/simple_hls_notifier.h index 1f17041b59..f21925a41e 100644 --- a/packager/hls/base/simple_hls_notifier.h +++ b/packager/hls/base/simple_hls_notifier.h @@ -14,7 +14,6 @@ #include "packager/base/atomic_sequence_num.h" #include "packager/base/macros.h" -#include "packager/base/stl_util.h" #include "packager/base/synchronization/lock.h" #include "packager/hls/base/hls_notifier.h" #include "packager/hls/base/master_playlist.h" @@ -82,8 +81,7 @@ class SimpleHlsNotifier : public HlsNotifier { std::unique_ptr media_playlist_factory_; std::unique_ptr master_playlist_; - std::map media_playlist_map_; - STLValueDeleter media_playlist_map_deleter_; + std::map> media_playlist_map_; base::AtomicSequenceNumber sequence_number_; diff --git a/packager/hls/base/simple_hls_notifier_unittest.cc b/packager/hls/base/simple_hls_notifier_unittest.cc index 7027d25fe2..63d951d450 100644 --- a/packager/hls/base/simple_hls_notifier_unittest.cc +++ b/packager/hls/base/simple_hls_notifier_unittest.cc @@ -101,7 +101,8 @@ class SimpleHlsNotifierTest : public ::testing::Test { notifier->master_playlist_ = std::move(playlist); } - const std::map& GetMediaPlaylistMap() { + const std::map>& + GetMediaPlaylistMap() { return notifier_.media_playlist_map_; } diff --git a/packager/media/base/aes_cryptor.cc b/packager/media/base/aes_cryptor.cc index ac97e46d57..acbb8911af 100644 --- a/packager/media/base/aes_cryptor.cc +++ b/packager/media/base/aes_cryptor.cc @@ -6,15 +6,14 @@ #include "packager/media/base/aes_cryptor.h" -#include -#include - #include #include #include +#include +#include + #include "packager/base/logging.h" -#include "packager/base/stl_util.h" namespace { @@ -58,8 +57,7 @@ bool AesCryptor::Crypt(const std::string& text, std::string* crypt_text) { crypt_text->resize(text_size + NumPaddingBytes(text_size)); size_t crypt_text_size = crypt_text->size(); if (!Crypt(reinterpret_cast(text.data()), text_size, - reinterpret_cast(string_as_array(crypt_text)), - &crypt_text_size)) + reinterpret_cast(&(*crypt_text)[0]), &crypt_text_size)) return false; DCHECK_LE(crypt_text_size, crypt_text->size()); crypt_text->resize(crypt_text_size); @@ -132,5 +130,3 @@ size_t AesCryptor::NumPaddingBytes(size_t size) const { } // namespace media } // namespace shaka - - diff --git a/packager/media/base/decryptor_source.cc b/packager/media/base/decryptor_source.cc index 22d9d07686..fb18f2cfde 100644 --- a/packager/media/base/decryptor_source.cc +++ b/packager/media/base/decryptor_source.cc @@ -7,7 +7,6 @@ #include "packager/media/base/decryptor_source.h" #include "packager/base/logging.h" -#include "packager/base/stl_util.h" #include "packager/media/base/aes_decryptor.h" #include "packager/media/base/aes_pattern_cryptor.h" @@ -18,9 +17,7 @@ DecryptorSource::DecryptorSource(KeySource* key_source) : key_source_(key_source) { CHECK(key_source); } -DecryptorSource::~DecryptorSource() { - STLDeleteValues(&decryptor_map_); -} +DecryptorSource::~DecryptorSource() {} bool DecryptorSource::DecryptSampleBuffer(const DecryptConfig* decrypt_config, uint8_t* buffer, @@ -29,7 +26,7 @@ bool DecryptorSource::DecryptSampleBuffer(const DecryptConfig* decrypt_config, DCHECK(buffer); // Get the decryptor object. - AesCryptor* decryptor; + AesCryptor* decryptor = nullptr; auto found = decryptor_map_.find(decrypt_config->key_id()); if (found == decryptor_map_.end()) { // Create new AesDecryptor based on decryption mode. @@ -74,10 +71,10 @@ bool DecryptorSource::DecryptSampleBuffer(const DecryptConfig* decrypt_config, LOG(ERROR) << "Failed to initialize AesDecryptor for decryption."; return false; } - decryptor = aes_decryptor.release(); - decryptor_map_[decrypt_config->key_id()] = decryptor; + decryptor = aes_decryptor.get(); + decryptor_map_[decrypt_config->key_id()] = std::move(aes_decryptor); } else { - decryptor = found->second; + decryptor = found->second.get(); } if (!decryptor->SetIv(decrypt_config->iv())) { LOG(ERROR) << "Invalid initialization vector."; diff --git a/packager/media/base/decryptor_source.h b/packager/media/base/decryptor_source.h index 7491eed8fa..a4ac9dafbf 100644 --- a/packager/media/base/decryptor_source.h +++ b/packager/media/base/decryptor_source.h @@ -8,6 +8,7 @@ #define MEDIA_BASE_DECRYPTOR_SOURCE_H_ #include +#include #include #include "packager/media/base/aes_decryptor.h" @@ -29,7 +30,7 @@ class DecryptorSource { private: KeySource* key_source_; - std::map, AesCryptor*> decryptor_map_; + std::map, std::unique_ptr> decryptor_map_; DISALLOW_COPY_AND_ASSIGN(DecryptorSource); }; diff --git a/packager/media/base/demuxer.cc b/packager/media/base/demuxer.cc index 75276cd05e..1369d538f9 100644 --- a/packager/media/base/demuxer.cc +++ b/packager/media/base/demuxer.cc @@ -8,7 +8,6 @@ #include "packager/base/bind.h" #include "packager/base/logging.h" -#include "packager/base/stl_util.h" #include "packager/media/base/decryptor_source.h" #include "packager/media/base/key_source.h" #include "packager/media/base/media_sample.h" @@ -46,7 +45,6 @@ Demuxer::Demuxer(const std::string& file_name) Demuxer::~Demuxer() { if (media_file_) media_file_->Close(); - STLDeleteElements(&streams_); } void Demuxer::SetKeySource(std::unique_ptr key_source) { @@ -121,13 +119,10 @@ Status Demuxer::Initialize() { } void Demuxer::ParserInitEvent( - const std::vector >& streams) { + const std::vector>& stream_infos) { init_event_received_ = true; - - std::vector >::const_iterator it = streams.begin(); - for (; it != streams.end(); ++it) { - streams_.push_back(new MediaStream(*it, this)); - } + for (const scoped_refptr& stream_info : stream_infos) + streams_.emplace_back(new MediaStream(stream_info, this)); } Demuxer::QueuedSample::QueuedSample(uint32_t local_track_id, @@ -157,10 +152,9 @@ bool Demuxer::NewSampleEvent(uint32_t track_id, bool Demuxer::PushSample(uint32_t track_id, const scoped_refptr& sample) { - std::vector::iterator it = streams_.begin(); - for (; it != streams_.end(); ++it) { - if (track_id == (*it)->info()->track_id()) { - Status status = (*it)->PushSample(sample); + for (const std::unique_ptr& stream : streams_) { + if (track_id == stream->info()->track_id()) { + Status status = stream->PushSample(sample); if (!status.ok()) LOG(ERROR) << "Demuxer::PushSample failed with " << status; return status.ok(); @@ -176,10 +170,8 @@ Status Demuxer::Run() { LOG(INFO) << "Demuxer::Run() on file '" << file_name_ << "'."; // Start the streams. - for (std::vector::iterator it = streams_.begin(); - it != streams_.end(); - ++it) { - status = (*it)->Start(MediaStream::kPush); + for (const std::unique_ptr& stream : streams_) { + status = stream->Start(MediaStream::kPush); if (!status.ok()) return status; } @@ -193,10 +185,8 @@ Status Demuxer::Run() { if (status.error_code() == error::END_OF_STREAM) { // Push EOS sample to muxer to indicate end of stream. const scoped_refptr& sample = MediaSample::CreateEOSBuffer(); - for (std::vector::iterator it = streams_.begin(); - it != streams_.end(); - ++it) { - status = (*it)->PushSample(sample); + for (const std::unique_ptr& stream : streams_) { + status = stream->PushSample(sample); if (!status.ok()) return status; } diff --git a/packager/media/base/demuxer.h b/packager/media/base/demuxer.h index 4336532ca5..08122c51ca 100644 --- a/packager/media/base/demuxer.h +++ b/packager/media/base/demuxer.h @@ -65,7 +65,9 @@ class Demuxer { /// add or remove streams from the returned vector, but the caller is /// allowed to change the internal state of the streams in the vector /// through MediaStream APIs. - const std::vector& streams() { return streams_; } + const std::vector>& streams() { + return streams_; + } /// @return Container name (type). Value is CONTAINER_UNKNOWN if the demuxer /// is not initialized. @@ -97,7 +99,7 @@ class Demuxer { // Queued samples received in NewSampleEvent() before ParserInitEvent(). std::deque queued_samples_; std::unique_ptr parser_; - std::vector streams_; + std::vector> streams_; MediaContainerName container_name_; std::unique_ptr buffer_; std::unique_ptr key_source_; diff --git a/packager/media/base/rsa_key.cc b/packager/media/base/rsa_key.cc index 4edb3932d2..27e142c770 100644 --- a/packager/media/base/rsa_key.cc +++ b/packager/media/base/rsa_key.cc @@ -25,7 +25,6 @@ #include "packager/base/logging.h" #include "packager/base/sha1.h" -#include "packager/base/stl_util.h" namespace { @@ -112,10 +111,8 @@ bool RsaPrivateKey::Decrypt(const std::string& encrypted_message, decrypted_message->resize(rsa_size); int decrypted_size = RSA_private_decrypt( - rsa_size, - reinterpret_cast(encrypted_message.data()), - reinterpret_cast(string_as_array(decrypted_message)), - rsa_key_, + rsa_size, reinterpret_cast(encrypted_message.data()), + reinterpret_cast(&(*decrypted_message)[0]), rsa_key_, RSA_PKCS1_OAEP_PADDING); if (decrypted_size == -1) { @@ -141,12 +138,9 @@ bool RsaPrivateKey::GenerateSignature(const std::string& message, size_t rsa_size = RSA_size(rsa_key_); std::vector padded_digest(rsa_size); if (!RSA_padding_add_PKCS1_PSS_mgf1( - rsa_key_, - &padded_digest[0], - reinterpret_cast(string_as_array(&message_digest)), - EVP_sha1(), - EVP_sha1(), - kPssSaltLength)) { + rsa_key_, &padded_digest[0], + reinterpret_cast(&message_digest[0]), EVP_sha1(), + EVP_sha1(), kPssSaltLength)) { LOG(ERROR) << "RSA padding failure: " << ERR_error_string(ERR_get_error(), NULL); return false; @@ -155,11 +149,8 @@ bool RsaPrivateKey::GenerateSignature(const std::string& message, // Encrypt PSS padded digest. signature->resize(rsa_size); int signature_size = RSA_private_encrypt( - padded_digest.size(), - &padded_digest[0], - reinterpret_cast(string_as_array(signature)), - rsa_key_, - RSA_NO_PADDING); + padded_digest.size(), &padded_digest[0], + reinterpret_cast(&(*signature)[0]), rsa_key_, RSA_NO_PADDING); if (signature_size != static_cast(rsa_size)) { LOG(ERROR) << "RSA private encrypt failure: " << ERR_error_string( @@ -192,12 +183,11 @@ bool RsaPublicKey::Encrypt(const std::string& clear_message, size_t rsa_size = RSA_size(rsa_key_); encrypted_message->resize(rsa_size); - int encrypted_size = RSA_public_encrypt( - clear_message.size(), - reinterpret_cast(clear_message.data()), - reinterpret_cast(string_as_array(encrypted_message)), - rsa_key_, - RSA_PKCS1_OAEP_PADDING); + int encrypted_size = + RSA_public_encrypt(clear_message.size(), + reinterpret_cast(clear_message.data()), + reinterpret_cast(&(*encrypted_message)[0]), + rsa_key_, RSA_PKCS1_OAEP_PADDING); if (encrypted_size != static_cast(rsa_size)) { LOG(ERROR) << "RSA public encrypt failure: " << ERR_error_string( diff --git a/packager/media/base/video_stream_info.cc b/packager/media/base/video_stream_info.cc index 1947713ee6..81678c1ceb 100644 --- a/packager/media/base/video_stream_info.cc +++ b/packager/media/base/video_stream_info.cc @@ -7,7 +7,6 @@ #include "packager/media/base/video_stream_info.h" #include "packager/base/logging.h" -#include "packager/base/stl_util.h" #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_util.h" #include "packager/base/strings/stringprintf.h" diff --git a/packager/media/base/widevine_key_source.cc b/packager/media/base/widevine_key_source.cc index 8d88049df8..7e3eb2ba2e 100644 --- a/packager/media/base/widevine_key_source.cc +++ b/packager/media/base/widevine_key_source.cc @@ -13,7 +13,6 @@ #include "packager/base/json/json_reader.h" #include "packager/base/json/json_writer.h" #include "packager/base/memory/ref_counted.h" -#include "packager/base/stl_util.h" #include "packager/media/base/fixed_key_source.h" #include "packager/media/base/http_key_fetcher.h" #include "packager/media/base/producer_consumer_queue.h" @@ -120,14 +119,12 @@ class WidevineKeySource::RefCountedEncryptionKeyMap encryption_key_map_.swap(*encryption_key_map); } - std::map& map() { - return encryption_key_map_; - } + const EncryptionKeyMap& map() { return encryption_key_map_; } private: friend class base::RefCountedThreadSafe; - ~RefCountedEncryptionKeyMap() { STLDeleteValues(&encryption_key_map_); } + ~RefCountedEncryptionKeyMap() {} EncryptionKeyMap encryption_key_map_; @@ -159,7 +156,6 @@ WidevineKeySource::~WidevineKeySource() { start_key_production_.Signal(); key_production_thread_.Join(); } - STLDeleteValues(&encryption_key_map_); } Status WidevineKeySource::FetchKeys(const std::vector& content_id, @@ -243,12 +239,9 @@ Status WidevineKeySource::GetKey(TrackType track_type, EncryptionKey* key) { Status WidevineKeySource::GetKey(const std::vector& key_id, EncryptionKey* key) { DCHECK(key); - for (std::map::iterator iter = - encryption_key_map_.begin(); - iter != encryption_key_map_.end(); - ++iter) { - if (iter->second->key_id == key_id) { - *key = *iter->second; + for (const auto& pair : encryption_key_map_) { + if (pair.second->key_id == key_id) { + *key = *pair.second; return Status::OK; } } @@ -307,12 +300,13 @@ Status WidevineKeySource::GetKeyInternal(uint32_t crypto_period_index, return status; } - EncryptionKeyMap& encryption_key_map = ref_counted_encryption_key_map->map(); + const EncryptionKeyMap& encryption_key_map = + ref_counted_encryption_key_map->map(); if (encryption_key_map.find(track_type) == encryption_key_map.end()) { return Status(error::INTERNAL_ERROR, "Cannot find key of type " + TrackTypeToString(track_type)); } - *key = *encryption_key_map[track_type]; + *key = *encryption_key_map.at(track_type); return Status::OK; } @@ -568,7 +562,7 @@ bool WidevineKeySource::ExtractEncryptionKey( encryption_key->key_system_info.push_back(info); } - encryption_key_map[track_type] = encryption_key.release(); + encryption_key_map[track_type] = std::move(encryption_key); } // If the flag exists, create a common system ID PSSH box that contains the @@ -594,7 +588,7 @@ bool WidevineKeySource::ExtractEncryptionKey( DCHECK(!encryption_key_map.empty()); if (!enable_key_rotation) { - encryption_key_map_ = encryption_key_map; + encryption_key_map_.swap(encryption_key_map); return true; } return PushToKeyPool(&encryption_key_map); diff --git a/packager/media/base/widevine_key_source.h b/packager/media/base/widevine_key_source.h index 47b8582840..da68770d63 100644 --- a/packager/media/base/widevine_key_source.h +++ b/packager/media/base/widevine_key_source.h @@ -67,7 +67,7 @@ class WidevineKeySource : public KeySource { ClosureThread key_production_thread_; private: - typedef std::map EncryptionKeyMap; + typedef std::map> EncryptionKeyMap; class RefCountedEncryptionKeyMap; typedef ProducerConsumerQueue > EncryptionKeyQueue; diff --git a/packager/media/codecs/h264_parser.cc b/packager/media/codecs/h264_parser.cc index 55a678bed7..5d3348ab73 100644 --- a/packager/media/codecs/h264_parser.cc +++ b/packager/media/codecs/h264_parser.cc @@ -6,7 +6,6 @@ #include #include "packager/base/logging.h" -#include "packager/base/stl_util.h" #include "packager/media/base/buffer_reader.h" namespace shaka { @@ -184,17 +183,14 @@ static_assert(arraysize(kTableSarWidth) == arraysize(kTableSarHeight), H264Parser::H264Parser() {} -H264Parser::~H264Parser() { - STLDeleteValues(&active_SPSes_); - STLDeleteValues(&active_PPSes_); -} +H264Parser::~H264Parser() {} const H264Pps* H264Parser::GetPps(int pps_id) { - return active_PPSes_[pps_id]; + return active_PPSes_[pps_id].get(); } const H264Sps* H264Parser::GetSps(int sps_id) { - return active_SPSes_[sps_id]; + return active_SPSes_[sps_id].get(); } // Default scaling lists (per spec). @@ -702,8 +698,7 @@ H264Parser::Result H264Parser::ParseSps(const Nalu& nalu, int* sps_id) { // If an SPS with the same id already exists, replace it. *sps_id = sps->seq_parameter_set_id; - delete active_SPSes_[*sps_id]; - active_SPSes_[*sps_id] = sps.release(); + active_SPSes_[*sps_id] = std::move(sps); return kOk; } @@ -776,8 +771,7 @@ H264Parser::Result H264Parser::ParsePps(const Nalu& nalu, int* pps_id) { // If a PPS with the same id already exists, replace it. *pps_id = pps->pic_parameter_set_id; - delete active_PPSes_[*pps_id]; - active_PPSes_[*pps_id] = pps.release(); + active_PPSes_[*pps_id] = std::move(pps); return kOk; } diff --git a/packager/media/codecs/h264_parser.h b/packager/media/codecs/h264_parser.h index 0663d1c2ca..66717c62db 100644 --- a/packager/media/codecs/h264_parser.h +++ b/packager/media/codecs/h264_parser.h @@ -11,6 +11,7 @@ #include #include +#include #include "packager/media/codecs/h26x_bit_reader.h" #include "packager/media/codecs/nalu_reader.h" @@ -324,8 +325,8 @@ class H264Parser { Result ParseDecRefPicMarking(H26xBitReader* br, H264SliceHeader* shdr); // PPSes and SPSes stored for future reference. - typedef std::map SpsById; - typedef std::map PpsById; + typedef std::map> SpsById; + typedef std::map> PpsById; SpsById active_SPSes_; PpsById active_PPSes_; diff --git a/packager/media/codecs/h265_parser.cc b/packager/media/codecs/h265_parser.cc index 6b2cfa4641..3909111ec4 100644 --- a/packager/media/codecs/h265_parser.cc +++ b/packager/media/codecs/h265_parser.cc @@ -10,7 +10,6 @@ #include #include "packager/base/logging.h" -#include "packager/base/stl_util.h" #include "packager/media/base/macros.h" #include "packager/media/codecs/nalu_reader.h" @@ -179,10 +178,7 @@ H265SliceHeader::H265SliceHeader() {} H265SliceHeader::~H265SliceHeader() {} H265Parser::H265Parser() {} -H265Parser::~H265Parser() { - STLDeleteValues(&active_spses_); - STLDeleteValues(&active_ppses_); -} +H265Parser::~H265Parser() {} H265Parser::Result H265Parser::ParseSliceHeader(const Nalu& nalu, H265SliceHeader* slice_header) { @@ -504,8 +500,7 @@ H265Parser::Result H265Parser::ParsePps(const Nalu& nalu, int* pps_id) { // This will replace any existing PPS instance. *pps_id = pps->pic_parameter_set_id; - delete active_ppses_[*pps_id]; - active_ppses_[*pps_id] = pps.release(); + active_ppses_[*pps_id] = std::move(pps); return kOk; } @@ -621,18 +616,17 @@ H265Parser::Result H265Parser::ParseSps(const Nalu& nalu, int* sps_id) { // This will replace any existing SPS instance. *sps_id = sps->seq_parameter_set_id; - delete active_spses_[*sps_id]; - active_spses_[*sps_id] = sps.release(); + active_spses_[*sps_id] = std::move(sps); return kOk; } const H265Pps* H265Parser::GetPps(int pps_id) { - return active_ppses_[pps_id]; + return active_ppses_[pps_id].get(); } const H265Sps* H265Parser::GetSps(int sps_id) { - return active_spses_[sps_id]; + return active_spses_[sps_id].get(); } H265Parser::Result H265Parser::ParseVuiParameters(int max_num_sub_layers_minus1, diff --git a/packager/media/codecs/h265_parser.h b/packager/media/codecs/h265_parser.h index ad07418c0c..5f535b1b4c 100644 --- a/packager/media/codecs/h265_parser.h +++ b/packager/media/codecs/h265_parser.h @@ -342,8 +342,8 @@ class H265Parser { bool sub_pic_hdr_params_present_flag, H26xBitReader* br); - typedef std::map SpsById; - typedef std::map PpsById; + typedef std::map> SpsById; + typedef std::map> PpsById; SpsById active_spses_; PpsById active_ppses_; diff --git a/packager/media/formats/mp2t/mp2t_media_parser.cc b/packager/media/formats/mp2t/mp2t_media_parser.cc index 3e2d4f0a7d..aa7c005d21 100644 --- a/packager/media/formats/mp2t/mp2t_media_parser.cc +++ b/packager/media/formats/mp2t/mp2t_media_parser.cc @@ -6,7 +6,6 @@ #include #include "packager/base/bind.h" -#include "packager/base/stl_util.h" #include "packager/media/base/media_sample.h" #include "packager/media/base/stream_info.h" #include "packager/media/formats/mp2t/es_parser.h" @@ -153,9 +152,7 @@ Mp2tMediaParser::Mp2tMediaParser() is_initialized_(false) { } -Mp2tMediaParser::~Mp2tMediaParser() { - STLDeleteValues(&pids_); -} +Mp2tMediaParser::~Mp2tMediaParser() {} void Mp2tMediaParser::Init( const InitCB& init_cb, @@ -174,14 +171,13 @@ bool Mp2tMediaParser::Flush() { DVLOG(1) << "Mp2tMediaParser::Flush"; // Flush the buffers and reset the pids. - for (std::map::iterator it = pids_.begin(); - it != pids_.end(); ++it) { - DVLOG(1) << "Flushing PID: " << it->first; - PidState* pid_state = it->second; + for (const auto& pair : pids_) { + DVLOG(1) << "Flushing PID: " << pair.first; + PidState* pid_state = pair.second.get(); pid_state->Flush(); } bool result = EmitRemainingSamples(); - STLDeleteValues(&pids_); + pids_.clear(); // Remove any bytes left in the TS buffer. // (i.e. any partial TS packet => less than 188 bytes). @@ -224,7 +220,8 @@ bool Mp2tMediaParser::Parse(const uint8_t* buf, int size) { << " start_unit=" << ts_packet->payload_unit_start_indicator(); // Parse the section. - std::map::iterator it = pids_.find(ts_packet->pid()); + std::map>::iterator it = + pids_.find(ts_packet->pid()); if (it == pids_.end() && ts_packet->pid() == TsSection::kPidPat) { // Create the PAT state here if needed. @@ -233,9 +230,10 @@ bool Mp2tMediaParser::Parse(const uint8_t* buf, int size) { std::unique_ptr pat_pid_state(new PidState( ts_packet->pid(), PidState::kPidPat, std::move(pat_section_parser))); pat_pid_state->Enable(); - it = pids_.insert( - std::pair(ts_packet->pid(), - pat_pid_state.release())).first; + it = pids_ + .insert(std::pair>( + ts_packet->pid(), std::move(pat_pid_state))) + .first; } if (it != pids_.end()) { @@ -260,11 +258,9 @@ void Mp2tMediaParser::RegisterPmt(int program_number, int pmt_pid) { // Only one TS program is allowed. Ignore the incoming program map table, // if there is already one registered. - for (std::map::iterator it = pids_.begin(); - it != pids_.end(); ++it) { - PidState* pid_state = it->second; - if (pid_state->pid_type() == PidState::kPidPmt) { - DVLOG_IF(1, pmt_pid != it->first) << "More than one program is defined"; + for (const auto& pair : pids_) { + if (pair.second->pid_type() == PidState::kPidPmt) { + DVLOG_IF(1, pmt_pid != pair.first) << "More than one program is defined"; return; } } @@ -276,7 +272,8 @@ void Mp2tMediaParser::RegisterPmt(int program_number, int pmt_pid) { std::unique_ptr pmt_pid_state( new PidState(pmt_pid, PidState::kPidPmt, std::move(pmt_section_parser))); pmt_pid_state->Enable(); - pids_.insert(std::pair(pmt_pid, pmt_pid_state.release())); + pids_.insert(std::pair>( + pmt_pid, std::move(pmt_pid_state))); } void Mp2tMediaParser::RegisterPes(int pmt_pid, @@ -285,7 +282,7 @@ void Mp2tMediaParser::RegisterPes(int pmt_pid, DVLOG(1) << "RegisterPes:" << " pes_pid=" << pes_pid << " stream_type=" << std::hex << stream_type << std::dec; - std::map::iterator it = pids_.find(pes_pid); + std::map>::iterator it = pids_.find(pes_pid); if (it != pids_.end()) return; @@ -331,7 +328,8 @@ void Mp2tMediaParser::RegisterPes(int pmt_pid, std::unique_ptr pes_pid_state( new PidState(pes_pid, pid_type, std::move(pes_section_parser))); pes_pid_state->Enable(); - pids_.insert(std::pair(pes_pid, pes_pid_state.release())); + pids_.insert(std::pair>( + pes_pid, std::move(pes_pid_state))); } void Mp2tMediaParser::OnNewStreamInfo( diff --git a/packager/media/formats/mp2t/mp2t_media_parser.h b/packager/media/formats/mp2t/mp2t_media_parser.h index 13879f9d3f..4793a83a3d 100644 --- a/packager/media/formats/mp2t/mp2t_media_parser.h +++ b/packager/media/formats/mp2t/mp2t_media_parser.h @@ -42,7 +42,7 @@ class Mp2tMediaParser : public MediaParser { /// @} private: - typedef std::map PidMap; + typedef std::map> PidMap; // Callback invoked to register a Program Map Table. // Note: Does nothing if the PID is already registered. diff --git a/packager/media/formats/mp2t/pes_packet_generator.cc b/packager/media/formats/mp2t/pes_packet_generator.cc index 861b37ef35..287c0fe995 100644 --- a/packager/media/formats/mp2t/pes_packet_generator.cc +++ b/packager/media/formats/mp2t/pes_packet_generator.cc @@ -8,6 +8,7 @@ #include #include +#include #include "packager/media/base/aes_encryptor.h" #include "packager/media/base/aes_pattern_cryptor.h" @@ -86,12 +87,11 @@ bool EncryptAacSample(AesCryptor* encryptor, } } // namespace -PesPacketGenerator::PesPacketGenerator() - : pes_packets_deleter_(&pes_packets_) {} +PesPacketGenerator::PesPacketGenerator() {} PesPacketGenerator::~PesPacketGenerator() {} bool PesPacketGenerator::Initialize(const StreamInfo& stream_info) { - STLDeleteElements(&pes_packets_); + pes_packets_.clear(); stream_type_ = stream_info.stream_type(); if (stream_type_ == kStreamVideo) { @@ -148,7 +148,7 @@ bool PesPacketGenerator::PushSample(scoped_refptr sample) { } current_processing_pes_->mutable_data()->swap(byte_stream); current_processing_pes_->set_stream_id(kVideoStreamId); - pes_packets_.push_back(current_processing_pes_.release()); + pes_packets_.push_back(std::move(current_processing_pes_)); return true; } DCHECK_EQ(stream_type_, kStreamAudio); @@ -175,7 +175,7 @@ bool PesPacketGenerator::PushSample(scoped_refptr sample) { // packets. current_processing_pes_->mutable_data()->swap(aac_frame); current_processing_pes_->set_stream_id(kAudioStreamId); - pes_packets_.push_back(current_processing_pes_.release()); + pes_packets_.push_back(std::move(current_processing_pes_)); return true; } @@ -209,9 +209,9 @@ size_t PesPacketGenerator::NumberOfReadyPesPackets() { std::unique_ptr PesPacketGenerator::GetNextPesPacket() { DCHECK(!pes_packets_.empty()); - PesPacket* pes = pes_packets_.front(); + std::unique_ptr pes = std::move(pes_packets_.front()); pes_packets_.pop_front(); - return std::unique_ptr(pes); + return pes; } bool PesPacketGenerator::Flush() { diff --git a/packager/media/formats/mp2t/pes_packet_generator.h b/packager/media/formats/mp2t/pes_packet_generator.h index a2801c67a0..7a31910caf 100644 --- a/packager/media/formats/mp2t/pes_packet_generator.h +++ b/packager/media/formats/mp2t/pes_packet_generator.h @@ -10,7 +10,6 @@ #include #include -#include "packager/base/stl_util.h" #include "packager/media/base/aes_cryptor.h" #include "packager/media/base/key_source.h" #include "packager/media/base/media_sample.h" @@ -82,8 +81,7 @@ class PesPacketGenerator { // This can be used to create a PES from multiple audio samples. std::unique_ptr current_processing_pes_; - std::list pes_packets_; - STLElementDeleter pes_packets_deleter_; + std::list> pes_packets_; // Current encryption key. std::unique_ptr encryptor_; diff --git a/packager/media/formats/mp4/segmenter.cc b/packager/media/formats/mp4/segmenter.cc index a6665962ff..1487ad3849 100644 --- a/packager/media/formats/mp4/segmenter.cc +++ b/packager/media/formats/mp4/segmenter.cc @@ -9,7 +9,6 @@ #include #include "packager/base/logging.h" -#include "packager/base/stl_util.h" #include "packager/media/base/aes_cryptor.h" #include "packager/media/base/buffer_writer.h" #include "packager/media/base/key_source.h" @@ -161,7 +160,7 @@ Segmenter::Segmenter(const MuxerOptions& options, accumulated_progress_(0), sample_duration_(0u) {} -Segmenter::~Segmenter() { STLDeleteElements(&fragmenters_); } +Segmenter::~Segmenter() {} Status Segmenter::Initialize(const std::vector& streams, MuxerListener* muxer_listener, @@ -191,7 +190,8 @@ Status Segmenter::Initialize(const std::vector& streams, sidx_->reference_id = i + 1; } if (!encryption_key_source) { - fragmenters_[i] = new Fragmenter(streams[i]->info(), &moof_->tracks[i]); + fragmenters_[i].reset( + new Fragmenter(streams[i]->info(), &moof_->tracks[i])); continue; } @@ -220,13 +220,13 @@ Status Segmenter::Initialize(const std::vector& streams, encryption_key.iv, encryption_key.key_system_info); } - fragmenters_[i] = new KeyRotationFragmenter( + fragmenters_[i].reset(new KeyRotationFragmenter( moof_.get(), streams[i]->info(), &moof_->tracks[i], encryption_key_source, track_type, crypto_period_duration_in_seconds * streams[i]->info()->time_scale(), clear_lead_in_seconds * streams[i]->info()->time_scale(), protection_scheme, pattern.crypt_byte_block, pattern.skip_byte_block, - muxer_listener_); + muxer_listener_)); continue; } @@ -258,11 +258,11 @@ Status Segmenter::Initialize(const std::vector& streams, } } - fragmenters_[i] = new EncryptingFragmenter( + fragmenters_[i].reset(new EncryptingFragmenter( streams[i]->info(), &moof_->tracks[i], std::move(encryption_key), clear_lead_in_seconds * streams[i]->info()->time_scale(), protection_scheme, pattern.crypt_byte_block, pattern.skip_byte_block, - muxer_listener_); + muxer_listener_)); } if (options_.mp4_use_decoding_timestamp_in_timeline) { @@ -294,10 +294,8 @@ Status Segmenter::Initialize(const std::vector& streams, } Status Segmenter::Finalize() { - for (std::vector::iterator it = fragmenters_.begin(); - it != fragmenters_.end(); - ++it) { - Status status = FinalizeFragment(true, *it); + for (const std::unique_ptr& fragmenter : fragmenters_) { + Status status = FinalizeFragment(true, fragmenter.get()); if (!status.ok()) return status; } @@ -325,7 +323,7 @@ Status Segmenter::AddSample(const MediaStream* stream, DCHECK(stream); DCHECK(stream_map_.find(stream) != stream_map_.end()); uint32_t stream_id = stream_map_[stream]; - Fragmenter* fragmenter = fragmenters_[stream_id]; + Fragmenter* fragmenter = fragmenters_[stream_id].get(); // Set default sample duration if it has not been set yet. if (moov_->extends.tracks[stream_id].default_sample_duration == 0) { @@ -429,10 +427,8 @@ Status Segmenter::FinalizeFragment(bool finalize_segment, fragmenter->FinalizeFragment(); // Check if all tracks are ready for fragmentation. - for (std::vector::iterator it = fragmenters_.begin(); - it != fragmenters_.end(); - ++it) { - if (!(*it)->fragment_finalized()) + for (const std::unique_ptr& fragmenter : fragmenters_) { + if (!fragmenter->fragment_finalized()) return Status::OK; } @@ -470,7 +466,7 @@ Status Segmenter::FinalizeFragment(bool finalize_segment, // Write the fragment to buffer. moof_->Write(fragment_buffer_.get()); mdat.WriteHeader(fragment_buffer_.get()); - for (Fragmenter* fragmenter : fragmenters_) + for (const std::unique_ptr& fragmenter : fragmenters_) fragment_buffer_->AppendBuffer(*fragmenter->data()); // Increase sequence_number for next fragment. diff --git a/packager/media/formats/mp4/segmenter.h b/packager/media/formats/mp4/segmenter.h index ca818c3a61..450c6aaca5 100644 --- a/packager/media/formats/mp4/segmenter.h +++ b/packager/media/formats/mp4/segmenter.h @@ -134,7 +134,7 @@ class Segmenter { std::unique_ptr moof_; std::unique_ptr fragment_buffer_; std::unique_ptr sidx_; - std::vector fragmenters_; + std::vector> fragmenters_; std::vector segment_durations_; std::map stream_map_; MuxerListener* muxer_listener_; diff --git a/packager/media/formats/webm/webm_content_encodings_client.cc b/packager/media/formats/webm/webm_content_encodings_client.cc index 3c3100c2f3..2dbb386cfd 100644 --- a/packager/media/formats/webm/webm_content_encodings_client.cc +++ b/packager/media/formats/webm/webm_content_encodings_client.cc @@ -5,7 +5,6 @@ #include "packager/media/formats/webm/webm_content_encodings_client.h" #include "packager/base/logging.h" -#include "packager/base/stl_util.h" #include "packager/media/formats/webm/webm_constants.h" namespace shaka { @@ -14,9 +13,7 @@ namespace media { WebMContentEncodingsClient::WebMContentEncodingsClient() : content_encryption_encountered_(false), content_encodings_ready_(false) {} -WebMContentEncodingsClient::~WebMContentEncodingsClient() { - STLDeleteElements(&content_encodings_); -} +WebMContentEncodingsClient::~WebMContentEncodingsClient() {} const ContentEncodings& WebMContentEncodingsClient::content_encodings() const { DCHECK(content_encodings_ready_); @@ -27,7 +24,7 @@ WebMParserClient* WebMContentEncodingsClient::OnListStart(int id) { if (id == kWebMIdContentEncodings) { DCHECK(!cur_content_encoding_.get()); DCHECK(!content_encryption_encountered_); - STLDeleteElements(&content_encodings_); + content_encodings_.clear(); content_encodings_ready_ = false; return this; } @@ -102,14 +99,14 @@ bool WebMContentEncodingsClient::OnListEnd(int id) { } // Enforce mandatory elements without default values. - DCHECK(cur_content_encoding_->type() == ContentEncoding::kTypeEncryption); + DCHECK_EQ(cur_content_encoding_->type(), ContentEncoding::kTypeEncryption); if (!content_encryption_encountered_) { LOG(ERROR) << "ContentEncodingType is encryption but" << " ContentEncryption is missing."; return false; } - content_encodings_.push_back(cur_content_encoding_.release()); + content_encodings_.push_back(std::move(cur_content_encoding_)); content_encryption_encountered_ = false; return true; } diff --git a/packager/media/formats/webm/webm_content_encodings_client.h b/packager/media/formats/webm/webm_content_encodings_client.h index 0fea165b61..e2421ec4e2 100644 --- a/packager/media/formats/webm/webm_content_encodings_client.h +++ b/packager/media/formats/webm/webm_content_encodings_client.h @@ -9,14 +9,13 @@ #include #include "packager/base/callback.h" -#include "packager/base/compiler_specific.h" #include "packager/media/formats/webm/webm_content_encodings.h" #include "packager/media/formats/webm/webm_parser.h" namespace shaka { namespace media { -typedef std::vector ContentEncodings; +typedef std::vector> ContentEncodings; /// Parser for WebM ContentEncodings element. class WebMContentEncodingsClient : public WebMParserClient { diff --git a/packager/media/formats/webm/webm_video_client.cc b/packager/media/formats/webm/webm_video_client.cc index 8a22ce5b9e..9e2f9fd06d 100644 --- a/packager/media/formats/webm/webm_video_client.cc +++ b/packager/media/formats/webm/webm_video_client.cc @@ -5,7 +5,6 @@ #include "packager/media/formats/webm/webm_video_client.h" #include "packager/base/logging.h" -#include "packager/base/stl_util.h" #include "packager/media/codecs/vp_codec_configuration_record.h" #include "packager/media/formats/webm/webm_constants.h" diff --git a/packager/media/test/packager_test.cc b/packager/media/test/packager_test.cc index bd8c696289..512a0abda7 100644 --- a/packager/media/test/packager_test.cc +++ b/packager/media/test/packager_test.cc @@ -57,19 +57,21 @@ const char kKeyHex[] = "6fc96fe628a265b13aeddec0bc421f4d"; const double kClearLeadInSeconds = 1.5; const double kCryptoDurationInSeconds = 0; // Key rotation is disabled. -MediaStream* FindFirstStreamOfType(const std::vector& streams, - StreamType stream_type) { - typedef std::vector::const_iterator StreamIterator; - for (StreamIterator it = streams.begin(); it != streams.end(); ++it) { - if ((*it)->info()->stream_type() == stream_type) - return *it; +MediaStream* FindFirstStreamOfType( + const std::vector>& streams, + StreamType stream_type) { + for (const std::unique_ptr& stream : streams) { + if (stream->info()->stream_type() == stream_type) + return stream.get(); } - return NULL; + return nullptr; } -MediaStream* FindFirstVideoStream(const std::vector& streams) { +MediaStream* FindFirstVideoStream( + const std::vector>& streams) { return FindFirstStreamOfType(streams, kStreamVideo); } -MediaStream* FindFirstAudioStream(const std::vector& streams) { +MediaStream* FindFirstAudioStream( + const std::vector>& streams) { return FindFirstStreamOfType(streams, kStreamAudio); } diff --git a/packager/mpd/base/dash_iop_mpd_notifier.cc b/packager/mpd/base/dash_iop_mpd_notifier.cc index 62cba711a9..2fe01a281f 100644 --- a/packager/mpd/base/dash_iop_mpd_notifier.cc +++ b/packager/mpd/base/dash_iop_mpd_notifier.cc @@ -6,6 +6,7 @@ #include "packager/mpd/base/dash_iop_mpd_notifier.h" +#include "packager/base/stl_util.h" #include "packager/mpd/base/media_info.pb.h" #include "packager/mpd/base/mpd_notifier_util.h" #include "packager/mpd/base/mpd_utils.h" diff --git a/packager/mpd/base/mpd_builder.cc b/packager/mpd/base/mpd_builder.cc index 6caf5be2ae..c92a772f1a 100644 --- a/packager/mpd/base/mpd_builder.cc +++ b/packager/mpd/base/mpd_builder.cc @@ -401,7 +401,6 @@ class RepresentationStateChangeListenerImpl MpdBuilder::MpdBuilder(MpdType type, const MpdOptions& mpd_options) : type_(type), mpd_options_(mpd_options), - adaptation_sets_deleter_(&adaptation_sets_), clock_(new base::DefaultClock()) {} MpdBuilder::~MpdBuilder() {} @@ -416,8 +415,8 @@ AdaptationSet* MpdBuilder::AddAdaptationSet(const std::string& lang) { type_, &representation_counter_)); DCHECK(adaptation_set); - adaptation_sets_.push_back(adaptation_set.get()); - return adaptation_set.release(); + adaptation_sets_.push_back(std::move(adaptation_set)); + return adaptation_sets_.back().get(); } bool MpdBuilder::WriteMpdToFile(media::File* output_file) { @@ -464,10 +463,9 @@ xmlDocPtr MpdBuilder::GenerateMpd() { // at the moment, just use a constant. // Required for 'dynamic' MPDs. period.SetId(0); - std::list::iterator adaptation_sets_it = - adaptation_sets_.begin(); - for (; adaptation_sets_it != adaptation_sets_.end(); ++adaptation_sets_it) { - xml::scoped_xml_ptr child((*adaptation_sets_it)->GetXml()); + for (const std::unique_ptr& adaptation_set : + adaptation_sets_) { + xml::scoped_xml_ptr child(adaptation_set->GetXml()); if (!child.get() || !period.AddChild(std::move(child))) return NULL; } @@ -627,11 +625,10 @@ bool MpdBuilder::GetEarliestTimestamp(double* timestamp_seconds) { DCHECK(timestamp_seconds); double earliest_timestamp(-1); - for (std::list::const_iterator iter = - adaptation_sets_.begin(); - iter != adaptation_sets_.end(); ++iter) { + for (const std::unique_ptr& adaptation_set : + adaptation_sets_) { double timestamp; - if ((*iter)->GetEarliestTimestamp(×tamp) && + if (adaptation_set->GetEarliestTimestamp(×tamp) && ((earliest_timestamp < 0) || (timestamp < earliest_timestamp))) { earliest_timestamp = timestamp; } @@ -676,8 +673,7 @@ AdaptationSet::AdaptationSet(uint32_t adaptation_set_id, const MpdOptions& mpd_options, MpdBuilder::MpdType mpd_type, base::AtomicSequenceNumber* counter) - : representations_deleter_(&representations_), - representation_counter_(counter), + : representation_counter_(counter), id_(adaptation_set_id), lang_(lang), mpd_options_(mpd_options), @@ -730,8 +726,8 @@ Representation* AdaptationSet::AddRepresentation(const MediaInfo& media_info) { } } - representations_.push_back(representation.get()); - return representation.release(); + representations_.push_back(std::move(representation)); + return representations_.back().get(); } void AdaptationSet::AddContentProtectionElement( @@ -818,7 +814,8 @@ xml::scoped_xml_ptr AdaptationSet::GetXml() { for (AdaptationSet::Role role : roles_) adaptation_set.AddRoleElement("urn:mpeg:dash:role:2011", RoleToText(role)); - for (Representation* representation : representations_) { + for (const std::unique_ptr& representation : + representations_) { if (suppress_representation_width) representation->SuppressOnce(Representation::kSuppressWidth); if (suppress_representation_height) @@ -876,11 +873,10 @@ bool AdaptationSet::GetEarliestTimestamp(double* timestamp_seconds) { DCHECK(timestamp_seconds); double earliest_timestamp(-1); - for (std::list::const_iterator iter = - representations_.begin(); - iter != representations_.end(); ++iter) { + for (const std::unique_ptr& representation : + representations_) { double timestamp; - if ((*iter)->GetEarliestTimestamp(×tamp) && + if (representation->GetEarliestTimestamp(×tamp) && ((earliest_timestamp < 0) || (timestamp < earliest_timestamp))) { earliest_timestamp = timestamp; } diff --git a/packager/mpd/base/mpd_builder.h b/packager/mpd/base/mpd_builder.h index 77c5287449..93e142fac5 100644 --- a/packager/mpd/base/mpd_builder.h +++ b/packager/mpd/base/mpd_builder.h @@ -25,7 +25,6 @@ #include "packager/base/atomic_sequence_num.h" #include "packager/base/callback.h" #include "packager/base/gtest_prod_util.h" -#include "packager/base/stl_util.h" #include "packager/base/time/clock.h" #include "packager/base/time/time.h" #include "packager/mpd/base/bandwidth_estimator.h" @@ -146,8 +145,7 @@ class MpdBuilder { MpdType type_; MpdOptions mpd_options_; - std::list adaptation_sets_; - STLElementDeleter > adaptation_sets_deleter_; + std::list> adaptation_sets_; std::list base_urls_; std::string availability_start_time_; @@ -341,8 +339,7 @@ class AdaptationSet { void RecordFrameRate(uint32_t frame_duration, uint32_t timescale); std::list content_protection_elements_; - std::list representations_; - STLElementDeleter > representations_deleter_; + std::list> representations_; base::AtomicSequenceNumber* const representation_counter_; diff --git a/packager/mpd/base/simple_mpd_notifier.cc b/packager/mpd/base/simple_mpd_notifier.cc index 819a01fe1a..90b620c5a2 100644 --- a/packager/mpd/base/simple_mpd_notifier.cc +++ b/packager/mpd/base/simple_mpd_notifier.cc @@ -7,6 +7,7 @@ #include "packager/mpd/base/simple_mpd_notifier.h" #include "packager/base/logging.h" +#include "packager/base/stl_util.h" #include "packager/mpd/base/mpd_builder.h" #include "packager/mpd/base/mpd_notifier_util.h" #include "packager/mpd/base/mpd_utils.h" diff --git a/packager/mpd/base/xml/xml_node.cc b/packager/mpd/base/xml/xml_node.cc index e0ed414384..e12f4e4351 100644 --- a/packager/mpd/base/xml/xml_node.cc +++ b/packager/mpd/base/xml/xml_node.cc @@ -11,7 +11,6 @@ #include "packager/base/logging.h" #include "packager/base/macros.h" -#include "packager/base/stl_util.h" #include "packager/base/strings/string_number_conversions.h" #include "packager/base/sys_byteorder.h" #include "packager/mpd/base/media_info.pb.h"