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
This commit is contained in:
parent
ba2a649c00
commit
c3d1dc1733
|
@ -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> demuxer)
|
||||
: SimpleThread("RemuxJob"), demuxer_(std::move(demuxer)) {}
|
||||
|
||||
~RemuxJob() override {
|
||||
STLDeleteElements(&muxers_);
|
||||
}
|
||||
~RemuxJob() override {}
|
||||
|
||||
void AddMuxer(std::unique_ptr<Muxer> 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> demuxer_;
|
||||
std::vector<Muxer*> muxers_;
|
||||
std::vector<std::unique_ptr<Muxer>> 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<RemuxJob*>* remux_jobs) {
|
||||
std::vector<std::unique_ptr<RemuxJob>>* 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<RemuxJob*>& remux_jobs) {
|
||||
Status RunRemuxJobs(const std::vector<std::unique_ptr<RemuxJob>>& remux_jobs) {
|
||||
// Start the job threads.
|
||||
for (std::vector<RemuxJob*>::const_iterator job_iter = remux_jobs.begin();
|
||||
job_iter != remux_jobs.end();
|
||||
++job_iter) {
|
||||
(*job_iter)->Start();
|
||||
}
|
||||
for (const std::unique_ptr<RemuxJob>& 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<RemuxJob*>::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<RemuxJob>& 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<RemuxJob*> remux_jobs;
|
||||
STLElementDeleter<std::vector<RemuxJob*> > scoped_jobs_deleter(&remux_jobs);
|
||||
std::vector<std::unique_ptr<RemuxJob>> remux_jobs;
|
||||
FakeClock fake_clock;
|
||||
if (!CreateRemuxJobs(stream_descriptors, muxer_options, &fake_clock,
|
||||
encryption_key_source.get(), mpd_notifier.get(),
|
||||
|
|
|
@ -36,7 +36,7 @@ DEFINE_bool(dump_stream_info, false, "Dump demuxed stream info.");
|
|||
namespace shaka {
|
||||
namespace media {
|
||||
|
||||
void DumpStreamInfo(const std::vector<MediaStream*>& streams) {
|
||||
void DumpStreamInfo(const std::vector<std::unique_ptr<MediaStream>>& 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<MediaStream*>& streams,
|
||||
StreamType stream_type) {
|
||||
typedef std::vector<MediaStream*>::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<std::unique_ptr<MediaStream>>& streams,
|
||||
StreamType stream_type) {
|
||||
for (const std::unique_ptr<MediaStream>& stream : streams) {
|
||||
if (stream->info()->stream_type() == stream_type)
|
||||
return stream.get();
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
MediaStream* FindFirstVideoStream(const std::vector<MediaStream*>& streams) {
|
||||
MediaStream* FindFirstVideoStream(
|
||||
const std::vector<std::unique_ptr<MediaStream>>& streams) {
|
||||
return FindFirstStreamOfType(streams, kStreamVideo);
|
||||
}
|
||||
MediaStream* FindFirstAudioStream(const std::vector<MediaStream*>& streams) {
|
||||
MediaStream* FindFirstAudioStream(
|
||||
const std::vector<std::unique_ptr<MediaStream>>& streams) {
|
||||
return FindFirstStreamOfType(streams, kStreamAudio);
|
||||
}
|
||||
|
||||
bool AddStreamToMuxer(const std::vector<MediaStream*>& streams,
|
||||
bool AddStreamToMuxer(const std::vector<std::unique_ptr<MediaStream>>& 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<MediaStream*>& streams,
|
|||
<< streams.size() - 1 << "].";
|
||||
return false;
|
||||
}
|
||||
stream = streams[stream_id];
|
||||
stream = streams[stream_id].get();
|
||||
DCHECK(stream);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<MediaStream*>& streams);
|
||||
void DumpStreamInfo(const std::vector<std::unique_ptr<MediaStream>>& 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<MediaStream*>& streams,
|
||||
bool AddStreamToMuxer(const std::vector<std::unique_ptr<MediaStream>>& streams,
|
||||
const std::string& stream_selector,
|
||||
const std::string& language_override,
|
||||
Muxer* muxer);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
#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<decltype(entries_), std::list<HlsEntry*>>::value,
|
||||
static_assert(std::is_same<decltype(entries_),
|
||||
std::list<std::unique_ptr<HlsEntry>>>::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) {
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
#define PACKAGER_HLS_BASE_MEDIA_PLAYLIST_H_
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#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<HlsEntry*> entries_;
|
||||
STLElementDeleter<decltype(entries_)> entries_deleter_;
|
||||
std::list<std::unique_ptr<HlsEntry>> entries_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(MediaPlaylist);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<MediaPlaylistFactory> media_playlist_factory_;
|
||||
std::unique_ptr<MasterPlaylist> master_playlist_;
|
||||
std::map<uint32_t, MediaPlaylist*> media_playlist_map_;
|
||||
STLValueDeleter<decltype(media_playlist_map_)> media_playlist_map_deleter_;
|
||||
std::map<uint32_t, std::unique_ptr<MediaPlaylist>> media_playlist_map_;
|
||||
|
||||
base::AtomicSequenceNumber sequence_number_;
|
||||
|
||||
|
|
|
@ -101,7 +101,8 @@ class SimpleHlsNotifierTest : public ::testing::Test {
|
|||
notifier->master_playlist_ = std::move(playlist);
|
||||
}
|
||||
|
||||
const std::map<uint32_t, MediaPlaylist*>& GetMediaPlaylistMap() {
|
||||
const std::map<uint32_t, std::unique_ptr<MediaPlaylist>>&
|
||||
GetMediaPlaylistMap() {
|
||||
return notifier_.media_playlist_map_;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,15 +6,14 @@
|
|||
|
||||
#include "packager/media/base/aes_cryptor.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<const uint8_t*>(text.data()), text_size,
|
||||
reinterpret_cast<uint8_t*>(string_as_array(crypt_text)),
|
||||
&crypt_text_size))
|
||||
reinterpret_cast<uint8_t*>(&(*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
|
||||
|
||||
|
||||
|
|
|
@ -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.";
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define MEDIA_BASE_DECRYPTOR_SOURCE_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "packager/media/base/aes_decryptor.h"
|
||||
|
@ -29,7 +30,7 @@ class DecryptorSource {
|
|||
|
||||
private:
|
||||
KeySource* key_source_;
|
||||
std::map<std::vector<uint8_t>, AesCryptor*> decryptor_map_;
|
||||
std::map<std::vector<uint8_t>, std::unique_ptr<AesCryptor>> decryptor_map_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DecryptorSource);
|
||||
};
|
||||
|
|
|
@ -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<KeySource> key_source) {
|
||||
|
@ -121,13 +119,10 @@ Status Demuxer::Initialize() {
|
|||
}
|
||||
|
||||
void Demuxer::ParserInitEvent(
|
||||
const std::vector<scoped_refptr<StreamInfo> >& streams) {
|
||||
const std::vector<scoped_refptr<StreamInfo>>& stream_infos) {
|
||||
init_event_received_ = true;
|
||||
|
||||
std::vector<scoped_refptr<StreamInfo> >::const_iterator it = streams.begin();
|
||||
for (; it != streams.end(); ++it) {
|
||||
streams_.push_back(new MediaStream(*it, this));
|
||||
}
|
||||
for (const scoped_refptr<StreamInfo>& 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<MediaSample>& sample) {
|
||||
std::vector<MediaStream*>::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<MediaStream>& 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<MediaStream*>::iterator it = streams_.begin();
|
||||
it != streams_.end();
|
||||
++it) {
|
||||
status = (*it)->Start(MediaStream::kPush);
|
||||
for (const std::unique_ptr<MediaStream>& 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<MediaSample>& sample = MediaSample::CreateEOSBuffer();
|
||||
for (std::vector<MediaStream*>::iterator it = streams_.begin();
|
||||
it != streams_.end();
|
||||
++it) {
|
||||
status = (*it)->PushSample(sample);
|
||||
for (const std::unique_ptr<MediaStream>& stream : streams_) {
|
||||
status = stream->PushSample(sample);
|
||||
if (!status.ok())
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -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<MediaStream*>& streams() { return streams_; }
|
||||
const std::vector<std::unique_ptr<MediaStream>>& 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<QueuedSample> queued_samples_;
|
||||
std::unique_ptr<MediaParser> parser_;
|
||||
std::vector<MediaStream*> streams_;
|
||||
std::vector<std::unique_ptr<MediaStream>> streams_;
|
||||
MediaContainerName container_name_;
|
||||
std::unique_ptr<uint8_t[]> buffer_;
|
||||
std::unique_ptr<KeySource> key_source_;
|
||||
|
|
|
@ -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<const uint8_t*>(encrypted_message.data()),
|
||||
reinterpret_cast<uint8_t*>(string_as_array(decrypted_message)),
|
||||
rsa_key_,
|
||||
rsa_size, reinterpret_cast<const uint8_t*>(encrypted_message.data()),
|
||||
reinterpret_cast<uint8_t*>(&(*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<uint8_t> padded_digest(rsa_size);
|
||||
if (!RSA_padding_add_PKCS1_PSS_mgf1(
|
||||
rsa_key_,
|
||||
&padded_digest[0],
|
||||
reinterpret_cast<uint8_t*>(string_as_array(&message_digest)),
|
||||
EVP_sha1(),
|
||||
EVP_sha1(),
|
||||
kPssSaltLength)) {
|
||||
rsa_key_, &padded_digest[0],
|
||||
reinterpret_cast<uint8_t*>(&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<uint8_t*>(string_as_array(signature)),
|
||||
rsa_key_,
|
||||
RSA_NO_PADDING);
|
||||
padded_digest.size(), &padded_digest[0],
|
||||
reinterpret_cast<uint8_t*>(&(*signature)[0]), rsa_key_, RSA_NO_PADDING);
|
||||
|
||||
if (signature_size != static_cast<int>(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<const uint8_t*>(clear_message.data()),
|
||||
reinterpret_cast<uint8_t*>(string_as_array(encrypted_message)),
|
||||
rsa_key_,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
int encrypted_size =
|
||||
RSA_public_encrypt(clear_message.size(),
|
||||
reinterpret_cast<const uint8_t*>(clear_message.data()),
|
||||
reinterpret_cast<uint8_t*>(&(*encrypted_message)[0]),
|
||||
rsa_key_, RSA_PKCS1_OAEP_PADDING);
|
||||
|
||||
if (encrypted_size != static_cast<int>(rsa_size)) {
|
||||
LOG(ERROR) << "RSA public encrypt failure: " << ERR_error_string(
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<KeySource::TrackType, EncryptionKey*>& map() {
|
||||
return encryption_key_map_;
|
||||
}
|
||||
const EncryptionKeyMap& map() { return encryption_key_map_; }
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<RefCountedEncryptionKeyMap>;
|
||||
|
||||
~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<uint8_t>& content_id,
|
||||
|
@ -243,12 +239,9 @@ Status WidevineKeySource::GetKey(TrackType track_type, EncryptionKey* key) {
|
|||
Status WidevineKeySource::GetKey(const std::vector<uint8_t>& key_id,
|
||||
EncryptionKey* key) {
|
||||
DCHECK(key);
|
||||
for (std::map<TrackType, EncryptionKey*>::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);
|
||||
|
|
|
@ -67,7 +67,7 @@ class WidevineKeySource : public KeySource {
|
|||
ClosureThread key_production_thread_;
|
||||
|
||||
private:
|
||||
typedef std::map<TrackType, EncryptionKey*> EncryptionKeyMap;
|
||||
typedef std::map<TrackType, std::unique_ptr<EncryptionKey>> EncryptionKeyMap;
|
||||
class RefCountedEncryptionKeyMap;
|
||||
typedef ProducerConsumerQueue<scoped_refptr<RefCountedEncryptionKeyMap> >
|
||||
EncryptionKeyQueue;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <memory>
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#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<int, H264Sps*> SpsById;
|
||||
typedef std::map<int, H264Pps*> PpsById;
|
||||
typedef std::map<int, std::unique_ptr<H264Sps>> SpsById;
|
||||
typedef std::map<int, std::unique_ptr<H264Pps>> PpsById;
|
||||
SpsById active_SPSes_;
|
||||
PpsById active_PPSes_;
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <algorithm>
|
||||
|
||||
#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,
|
||||
|
|
|
@ -342,8 +342,8 @@ class H265Parser {
|
|||
bool sub_pic_hdr_params_present_flag,
|
||||
H26xBitReader* br);
|
||||
|
||||
typedef std::map<int, H265Sps*> SpsById;
|
||||
typedef std::map<int, H265Pps*> PpsById;
|
||||
typedef std::map<int, std::unique_ptr<H265Sps>> SpsById;
|
||||
typedef std::map<int, std::unique_ptr<H265Pps>> PpsById;
|
||||
|
||||
SpsById active_spses_;
|
||||
PpsById active_ppses_;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <memory>
|
||||
#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<int, PidState*>::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<int, PidState*>::iterator it = pids_.find(ts_packet->pid());
|
||||
std::map<int, std::unique_ptr<PidState>>::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<PidState> pat_pid_state(new PidState(
|
||||
ts_packet->pid(), PidState::kPidPat, std::move(pat_section_parser)));
|
||||
pat_pid_state->Enable();
|
||||
it = pids_.insert(
|
||||
std::pair<int, PidState*>(ts_packet->pid(),
|
||||
pat_pid_state.release())).first;
|
||||
it = pids_
|
||||
.insert(std::pair<int, std::unique_ptr<PidState>>(
|
||||
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<int, PidState*>::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<PidState> pmt_pid_state(
|
||||
new PidState(pmt_pid, PidState::kPidPmt, std::move(pmt_section_parser)));
|
||||
pmt_pid_state->Enable();
|
||||
pids_.insert(std::pair<int, PidState*>(pmt_pid, pmt_pid_state.release()));
|
||||
pids_.insert(std::pair<int, std::unique_ptr<PidState>>(
|
||||
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<int, PidState*>::iterator it = pids_.find(pes_pid);
|
||||
std::map<int, std::unique_ptr<PidState>>::iterator it = pids_.find(pes_pid);
|
||||
if (it != pids_.end())
|
||||
return;
|
||||
|
||||
|
@ -331,7 +328,8 @@ void Mp2tMediaParser::RegisterPes(int pmt_pid,
|
|||
std::unique_ptr<PidState> pes_pid_state(
|
||||
new PidState(pes_pid, pid_type, std::move(pes_section_parser)));
|
||||
pes_pid_state->Enable();
|
||||
pids_.insert(std::pair<int, PidState*>(pes_pid, pes_pid_state.release()));
|
||||
pids_.insert(std::pair<int, std::unique_ptr<PidState>>(
|
||||
pes_pid, std::move(pes_pid_state)));
|
||||
}
|
||||
|
||||
void Mp2tMediaParser::OnNewStreamInfo(
|
||||
|
|
|
@ -42,7 +42,7 @@ class Mp2tMediaParser : public MediaParser {
|
|||
/// @}
|
||||
|
||||
private:
|
||||
typedef std::map<int, PidState*> PidMap;
|
||||
typedef std::map<int, std::unique_ptr<PidState>> PidMap;
|
||||
|
||||
// Callback invoked to register a Program Map Table.
|
||||
// Note: Does nothing if the PID is already registered.
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#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<MediaSample> 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<MediaSample> 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<PesPacket> PesPacketGenerator::GetNextPesPacket() {
|
||||
DCHECK(!pes_packets_.empty());
|
||||
PesPacket* pes = pes_packets_.front();
|
||||
std::unique_ptr<PesPacket> pes = std::move(pes_packets_.front());
|
||||
pes_packets_.pop_front();
|
||||
return std::unique_ptr<PesPacket>(pes);
|
||||
return pes;
|
||||
}
|
||||
|
||||
bool PesPacketGenerator::Flush() {
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#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<PesPacket> current_processing_pes_;
|
||||
|
||||
std::list<PesPacket*> pes_packets_;
|
||||
STLElementDeleter<decltype(pes_packets_)> pes_packets_deleter_;
|
||||
std::list<std::unique_ptr<PesPacket>> pes_packets_;
|
||||
|
||||
// Current encryption key.
|
||||
std::unique_ptr<AesCryptor> encryptor_;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <algorithm>
|
||||
|
||||
#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<MediaStream*>& streams,
|
||||
MuxerListener* muxer_listener,
|
||||
|
@ -191,7 +190,8 @@ Status Segmenter::Initialize(const std::vector<MediaStream*>& 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<MediaStream*>& 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<MediaStream*>& 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<MediaStream*>& streams,
|
|||
}
|
||||
|
||||
Status Segmenter::Finalize() {
|
||||
for (std::vector<Fragmenter*>::iterator it = fragmenters_.begin();
|
||||
it != fragmenters_.end();
|
||||
++it) {
|
||||
Status status = FinalizeFragment(true, *it);
|
||||
for (const std::unique_ptr<Fragmenter>& 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<Fragmenter*>::iterator it = fragmenters_.begin();
|
||||
it != fragmenters_.end();
|
||||
++it) {
|
||||
if (!(*it)->fragment_finalized())
|
||||
for (const std::unique_ptr<Fragmenter>& 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>& fragmenter : fragmenters_)
|
||||
fragment_buffer_->AppendBuffer(*fragmenter->data());
|
||||
|
||||
// Increase sequence_number for next fragment.
|
||||
|
|
|
@ -134,7 +134,7 @@ class Segmenter {
|
|||
std::unique_ptr<MovieFragment> moof_;
|
||||
std::unique_ptr<BufferWriter> fragment_buffer_;
|
||||
std::unique_ptr<SegmentIndex> sidx_;
|
||||
std::vector<Fragmenter*> fragmenters_;
|
||||
std::vector<std::unique_ptr<Fragmenter>> fragmenters_;
|
||||
std::vector<uint64_t> segment_durations_;
|
||||
std::map<const MediaStream*, uint32_t> stream_map_;
|
||||
MuxerListener* muxer_listener_;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -9,14 +9,13 @@
|
|||
#include <vector>
|
||||
|
||||
#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<ContentEncoding*> ContentEncodings;
|
||||
typedef std::vector<std::unique_ptr<ContentEncoding>> ContentEncodings;
|
||||
|
||||
/// Parser for WebM ContentEncodings element.
|
||||
class WebMContentEncodingsClient : public WebMParserClient {
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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<MediaStream*>& streams,
|
||||
StreamType stream_type) {
|
||||
typedef std::vector<MediaStream*>::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<std::unique_ptr<MediaStream>>& streams,
|
||||
StreamType stream_type) {
|
||||
for (const std::unique_ptr<MediaStream>& stream : streams) {
|
||||
if (stream->info()->stream_type() == stream_type)
|
||||
return stream.get();
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
MediaStream* FindFirstVideoStream(const std::vector<MediaStream*>& streams) {
|
||||
MediaStream* FindFirstVideoStream(
|
||||
const std::vector<std::unique_ptr<MediaStream>>& streams) {
|
||||
return FindFirstStreamOfType(streams, kStreamVideo);
|
||||
}
|
||||
MediaStream* FindFirstAudioStream(const std::vector<MediaStream*>& streams) {
|
||||
MediaStream* FindFirstAudioStream(
|
||||
const std::vector<std::unique_ptr<MediaStream>>& streams) {
|
||||
return FindFirstStreamOfType(streams, kStreamAudio);
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<AdaptationSet*>::iterator adaptation_sets_it =
|
||||
adaptation_sets_.begin();
|
||||
for (; adaptation_sets_it != adaptation_sets_.end(); ++adaptation_sets_it) {
|
||||
xml::scoped_xml_ptr<xmlNode> child((*adaptation_sets_it)->GetXml());
|
||||
for (const std::unique_ptr<AdaptationSet>& adaptation_set :
|
||||
adaptation_sets_) {
|
||||
xml::scoped_xml_ptr<xmlNode> 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<AdaptationSet*>::const_iterator iter =
|
||||
adaptation_sets_.begin();
|
||||
iter != adaptation_sets_.end(); ++iter) {
|
||||
for (const std::unique_ptr<AdaptationSet>& 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<xmlNode> 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>& 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<Representation*>::const_iterator iter =
|
||||
representations_.begin();
|
||||
iter != representations_.end(); ++iter) {
|
||||
for (const std::unique_ptr<Representation>& representation :
|
||||
representations_) {
|
||||
double timestamp;
|
||||
if ((*iter)->GetEarliestTimestamp(×tamp) &&
|
||||
if (representation->GetEarliestTimestamp(×tamp) &&
|
||||
((earliest_timestamp < 0) || (timestamp < earliest_timestamp))) {
|
||||
earliest_timestamp = timestamp;
|
||||
}
|
||||
|
|
|
@ -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<AdaptationSet*> adaptation_sets_;
|
||||
STLElementDeleter<std::list<AdaptationSet*> > adaptation_sets_deleter_;
|
||||
std::list<std::unique_ptr<AdaptationSet>> adaptation_sets_;
|
||||
|
||||
std::list<std::string> base_urls_;
|
||||
std::string availability_start_time_;
|
||||
|
@ -341,8 +339,7 @@ class AdaptationSet {
|
|||
void RecordFrameRate(uint32_t frame_duration, uint32_t timescale);
|
||||
|
||||
std::list<ContentProtectionElement> content_protection_elements_;
|
||||
std::list<Representation*> representations_;
|
||||
STLElementDeleter<std::list<Representation*> > representations_deleter_;
|
||||
std::list<std::unique_ptr<Representation>> representations_;
|
||||
|
||||
base::AtomicSequenceNumber* const representation_counter_;
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue