diff --git a/packager/media/base/audio_stream_info.h b/packager/media/base/audio_stream_info.h index a68c4e1364..0d233c172a 100644 --- a/packager/media/base/audio_stream_info.h +++ b/packager/media/base/audio_stream_info.h @@ -27,6 +27,8 @@ class AudioStreamInfo : public StreamInfo { uint32_t avg_bitrate, const std::string& language, bool is_encrypted); + ~AudioStreamInfo() override; + /// @name StreamInfo implementation overrides. /// @{ bool IsValidConfig() const override; @@ -54,8 +56,6 @@ class AudioStreamInfo : public StreamInfo { static std::string GetCodecString(Codec codec, uint8_t audio_object_type); private: - ~AudioStreamInfo() override; - uint8_t sample_bits_; uint8_t num_channels_; uint32_t sampling_frequency_; diff --git a/packager/media/base/demuxer.cc b/packager/media/base/demuxer.cc index 1369d538f9..ccd71cae6e 100644 --- a/packager/media/base/demuxer.cc +++ b/packager/media/base/demuxer.cc @@ -119,19 +119,19 @@ Status Demuxer::Initialize() { } void Demuxer::ParserInitEvent( - const std::vector>& stream_infos) { + const std::vector>& stream_infos) { init_event_received_ = true; - for (const scoped_refptr& stream_info : stream_infos) + for (const std::shared_ptr& stream_info : stream_infos) streams_.emplace_back(new MediaStream(stream_info, this)); } Demuxer::QueuedSample::QueuedSample(uint32_t local_track_id, - scoped_refptr local_sample) + std::shared_ptr local_sample) : track_id(local_track_id), sample(local_sample) {} Demuxer::QueuedSample::~QueuedSample() {} bool Demuxer::NewSampleEvent(uint32_t track_id, - const scoped_refptr& sample) { + const std::shared_ptr& sample) { if (!init_event_received_) { if (queued_samples_.size() >= kQueuedSamplesLimit) { LOG(ERROR) << "Queued samples limit reached: " << kQueuedSamplesLimit; @@ -151,7 +151,7 @@ bool Demuxer::NewSampleEvent(uint32_t track_id, } bool Demuxer::PushSample(uint32_t track_id, - const scoped_refptr& sample) { + const std::shared_ptr& sample) { for (const std::unique_ptr& stream : streams_) { if (track_id == stream->info()->track_id()) { Status status = stream->PushSample(sample); @@ -184,7 +184,7 @@ 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(); + const std::shared_ptr& sample = MediaSample::CreateEOSBuffer(); for (const std::unique_ptr& stream : streams_) { status = stream->PushSample(sample); if (!status.ok()) diff --git a/packager/media/base/demuxer.h b/packager/media/base/demuxer.h index 08122c51ca..48ea2418b8 100644 --- a/packager/media/base/demuxer.h +++ b/packager/media/base/demuxer.h @@ -12,7 +12,6 @@ #include #include "packager/base/compiler_specific.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/container_names.h" #include "packager/media/base/status.h" @@ -74,23 +73,27 @@ class Demuxer { MediaContainerName container_name() { return container_name_; } private: + Demuxer(const Demuxer&) = delete; + Demuxer& operator=(const Demuxer&) = delete; + struct QueuedSample { - QueuedSample(uint32_t track_id, scoped_refptr sample); + QueuedSample(uint32_t track_id, std::shared_ptr sample); ~QueuedSample(); uint32_t track_id; - scoped_refptr sample; + std::shared_ptr sample; }; // Parser init event. - void ParserInitEvent(const std::vector >& streams); + void ParserInitEvent(const std::vector>& streams); // Parser new sample event handler. Queues the samples if init event has not // been received, otherwise calls PushSample() to push the sample to // corresponding stream. bool NewSampleEvent(uint32_t track_id, - const scoped_refptr& sample); + const std::shared_ptr& sample); // Helper function to push the sample to corresponding stream. - bool PushSample(uint32_t track_id, const scoped_refptr& sample); + bool PushSample(uint32_t track_id, + const std::shared_ptr& sample); std::string file_name_; File* media_file_; @@ -104,8 +107,6 @@ class Demuxer { std::unique_ptr buffer_; std::unique_ptr key_source_; bool cancelled_; - - DISALLOW_COPY_AND_ASSIGN(Demuxer); }; } // namespace media diff --git a/packager/media/base/media_parser.h b/packager/media/base/media_parser.h index a6257ae623..585f31a2d4 100644 --- a/packager/media/base/media_parser.h +++ b/packager/media/base/media_parser.h @@ -12,7 +12,6 @@ #include #include "packager/base/callback.h" #include "packager/base/compiler_specific.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/container_names.h" namespace shaka { @@ -30,8 +29,9 @@ class MediaParser { /// Called upon completion of parser initialization. /// @param stream_info contains the stream info of all the elementary streams /// within this file. - typedef base::Callback< - void(const std::vector >& stream_info)> InitCB; + typedef base::Callback >& stream_info)> + InitCB; /// Called when a new media sample has been parsed. /// @param track_id is the track id of the new sample. @@ -39,7 +39,7 @@ class MediaParser { /// @return true if the sample is accepted, false if something was wrong /// with the sample and a parsing error should be signaled. typedef base::Callback& media_sample)> + const std::shared_ptr& media_sample)> NewSampleCB; /// Initialize the parser with necessary callbacks. Must be called before any diff --git a/packager/media/base/media_sample.cc b/packager/media/base/media_sample.cc index f9240c27b5..f52f8f99d6 100644 --- a/packager/media/base/media_sample.cc +++ b/packager/media/base/media_sample.cc @@ -42,43 +42,42 @@ MediaSample::MediaSample() : dts_(0), MediaSample::~MediaSample() {} // static -scoped_refptr MediaSample::CopyFrom(const uint8_t* data, - size_t data_size, - bool is_key_frame) { +std::shared_ptr MediaSample::CopyFrom(const uint8_t* data, + size_t data_size, + bool is_key_frame) { // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. CHECK(data); - return make_scoped_refptr( - new MediaSample(data, data_size, NULL, 0u, is_key_frame)); + return std::make_shared(data, data_size, nullptr, 0u, + is_key_frame); } // static -scoped_refptr MediaSample::CopyFrom(const uint8_t* data, - size_t data_size, - const uint8_t* side_data, - size_t side_data_size, - bool is_key_frame) { +std::shared_ptr MediaSample::CopyFrom(const uint8_t* data, + size_t data_size, + const uint8_t* side_data, + size_t side_data_size, + bool is_key_frame) { // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. CHECK(data); - return make_scoped_refptr(new MediaSample( - data, data_size, side_data, side_data_size, is_key_frame)); + return std::make_shared(data, data_size, side_data, + side_data_size, is_key_frame); } // static -scoped_refptr MediaSample::FromMetadata(const uint8_t* metadata, - size_t metadata_size) { - return make_scoped_refptr( - new MediaSample(nullptr, 0, metadata, metadata_size, false)); +std::shared_ptr MediaSample::FromMetadata(const uint8_t* metadata, + size_t metadata_size) { + return std::make_shared(nullptr, 0, metadata, metadata_size, + false); } // static -scoped_refptr MediaSample::CreateEmptyMediaSample() { - MediaSample* media_sample = new MediaSample(); - return make_scoped_refptr(media_sample); +std::shared_ptr MediaSample::CreateEmptyMediaSample() { + return std::make_shared(); } // static -scoped_refptr MediaSample::CreateEOSBuffer() { - return make_scoped_refptr(new MediaSample(NULL, 0, NULL, 0, false)); +std::shared_ptr MediaSample::CreateEOSBuffer() { + return std::make_shared(nullptr, 0, nullptr, 0, false); } std::string MediaSample::ToString() const { diff --git a/packager/media/base/media_sample.h b/packager/media/base/media_sample.h index 166a2ec26d..f9c23433ed 100644 --- a/packager/media/base/media_sample.h +++ b/packager/media/base/media_sample.h @@ -8,27 +8,27 @@ #define MEDIA_BASE_MEDIA_SAMPLE_H_ #include +#include #include #include #include "packager/base/logging.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/decrypt_config.h" namespace shaka { namespace media { /// Class to hold a media sample. -class MediaSample : public base::RefCountedThreadSafe { +class MediaSample { public: /// Create a MediaSample object from input. /// @param data points to the buffer containing the sample data. /// Must not be NULL. /// @param size indicates sample size in bytes. Must not be negative. /// @param is_key_frame indicates whether the sample is a key frame. - static scoped_refptr CopyFrom(const uint8_t* data, - size_t size, - bool is_key_frame); + static std::shared_ptr CopyFrom(const uint8_t* data, + size_t size, + bool is_key_frame); /// Create a MediaSample object from input. /// @param data points to the buffer containing the sample data. @@ -39,11 +39,11 @@ class MediaSample : public base::RefCountedThreadSafe { /// @param size indicates sample size in bytes. Must not be negative. /// @param side_data_size indicates additional sample data size in bytes. /// @param is_key_frame indicates whether the sample is a key frame. - static scoped_refptr CopyFrom(const uint8_t* data, - size_t size, - const uint8_t* side_data, - size_t side_data_size, - bool is_key_frame); + static std::shared_ptr CopyFrom(const uint8_t* data, + size_t size, + const uint8_t* side_data, + size_t side_data_size, + bool is_key_frame); /// Create a MediaSample object from metadata. /// Unlike other factory methods, this cannot be a key frame. It must be only @@ -51,16 +51,27 @@ class MediaSample : public base::RefCountedThreadSafe { /// @param metadata points to the buffer containing metadata. /// Must not be NULL. /// @param metadata_size is the size of metadata in bytes. - static scoped_refptr FromMetadata(const uint8_t* metadata, - size_t metadata_size); + static std::shared_ptr FromMetadata(const uint8_t* metadata, + size_t metadata_size); /// Create a MediaSample object with default members. - static scoped_refptr CreateEmptyMediaSample(); + static std::shared_ptr CreateEmptyMediaSample(); /// Create a MediaSample indicating we've reached end of stream. /// Calling any method other than end_of_stream() on the resulting buffer /// is disallowed. - static scoped_refptr CreateEOSBuffer(); + static std::shared_ptr CreateEOSBuffer(); + + // Create a MediaSample. Buffer will be padded and aligned as necessary. + // |data|,|side_data| can be NULL, which indicates an empty sample. + // |size|,|side_data_size| should not be negative. + MediaSample(const uint8_t* data, + size_t size, + const uint8_t* side_data, + size_t side_data_size, + bool is_key_frame); + MediaSample(); + virtual ~MediaSample(); int64_t dts() const { DCHECK(!end_of_stream()); @@ -154,19 +165,6 @@ class MediaSample : public base::RefCountedThreadSafe { std::string ToString() const; private: - friend class base::RefCountedThreadSafe; - - // Create a MediaSample. Buffer will be padded and aligned as necessary. - // |data|,|side_data| can be NULL, which indicates an empty sample. - // |size|,|side_data_size| should not be negative. - MediaSample(const uint8_t* data, - size_t size, - const uint8_t* side_data, - size_t side_data_size, - bool is_key_frame); - MediaSample(); - virtual ~MediaSample(); - // Decoding time stamp. int64_t dts_; // Presentation time stamp. @@ -193,7 +191,7 @@ class MediaSample : public base::RefCountedThreadSafe { DISALLOW_COPY_AND_ASSIGN(MediaSample); }; -typedef std::deque > BufferQueue; +typedef std::deque> BufferQueue; } // namespace media } // namespace shaka diff --git a/packager/media/base/media_stream.cc b/packager/media/base/media_stream.cc index a6f2db486c..ef7f55d3c2 100644 --- a/packager/media/base/media_stream.cc +++ b/packager/media/base/media_stream.cc @@ -16,12 +16,12 @@ namespace shaka { namespace media { -MediaStream::MediaStream(scoped_refptr info, Demuxer* demuxer) +MediaStream::MediaStream(std::shared_ptr info, Demuxer* demuxer) : info_(info), demuxer_(demuxer), muxer_(NULL), state_(kIdle) {} MediaStream::~MediaStream() {} -Status MediaStream::PullSample(scoped_refptr* sample) { +Status MediaStream::PullSample(std::shared_ptr* sample) { DCHECK(state_ == kPulling || state_ == kIdle); // Trigger a new parse in demuxer if no more samples. @@ -36,7 +36,7 @@ Status MediaStream::PullSample(scoped_refptr* sample) { return Status::OK; } -Status MediaStream::PushSample(const scoped_refptr& sample) { +Status MediaStream::PushSample(const std::shared_ptr& sample) { switch (state_) { case kIdle: case kPulling: @@ -98,7 +98,9 @@ Status MediaStream::Start(MediaStreamOperation operation) { } } -const scoped_refptr MediaStream::info() const { return info_; } +const std::shared_ptr MediaStream::info() const { + return info_; +} std::string MediaStream::ToString() const { return base::StringPrintf("state: %d\n samples in the queue: %zu\n %s", diff --git a/packager/media/base/media_stream.h b/packager/media/base/media_stream.h index 7c326dcad8..0335b68a3b 100644 --- a/packager/media/base/media_stream.h +++ b/packager/media/base/media_stream.h @@ -10,7 +10,6 @@ #include #include -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/status.h" namespace shaka { @@ -31,7 +30,7 @@ class MediaStream { }; /// Create MediaStream from StreamInfo and Demuxer. /// @param demuxer cannot be NULL. - MediaStream(scoped_refptr info, Demuxer* demuxer); + MediaStream(std::shared_ptr info, Demuxer* demuxer); ~MediaStream(); /// Connect the stream to Muxer. @@ -42,19 +41,22 @@ class MediaStream { Status Start(MediaStreamOperation operation); /// Push sample to Muxer (triggered by Demuxer). - Status PushSample(const scoped_refptr& sample); + Status PushSample(const std::shared_ptr& sample); /// Pull sample from Demuxer (triggered by Muxer). - Status PullSample(scoped_refptr* sample); + Status PullSample(std::shared_ptr* sample); Demuxer* demuxer() { return demuxer_; } Muxer* muxer() { return muxer_; } - const scoped_refptr info() const; + const std::shared_ptr info() const; /// @return a human-readable string describing |*this|. std::string ToString() const; private: + MediaStream(const MediaStream&) = delete; + MediaStream& operator=(const MediaStream&) = delete; + // State transition diagram available @ http://goo.gl/ThJQbl. enum State { kIdle, @@ -64,14 +66,12 @@ class MediaStream { kPulling, }; - scoped_refptr info_; + std::shared_ptr info_; Demuxer* demuxer_; Muxer* muxer_; State state_; // An internal buffer to store samples temporarily. - std::deque > samples_; - - DISALLOW_COPY_AND_ASSIGN(MediaStream); + std::deque> samples_; }; } // namespace media diff --git a/packager/media/base/muxer.cc b/packager/media/base/muxer.cc index 4ab37e957a..194fa1d0db 100644 --- a/packager/media/base/muxer.cc +++ b/packager/media/base/muxer.cc @@ -71,7 +71,7 @@ Status Muxer::Run() { if (cancelled_) return Status(error::CANCELLED, "muxer run cancelled"); - scoped_refptr sample; + std::shared_ptr sample; status = streams_[current_stream_id]->PullSample(&sample); if (!status.ok()) break; @@ -101,7 +101,7 @@ void Muxer::SetProgressListener( } Status Muxer::AddSample(const MediaStream* stream, - scoped_refptr sample) { + std::shared_ptr sample) { DCHECK(std::find(streams_.begin(), streams_.end(), stream) != streams_.end()); if (!initialized_) { diff --git a/packager/media/base/muxer.h b/packager/media/base/muxer.h index 0412b4a215..ae518cc575 100644 --- a/packager/media/base/muxer.h +++ b/packager/media/base/muxer.h @@ -12,7 +12,6 @@ #include #include -#include "packager/base/memory/ref_counted.h" #include "packager/base/time/clock.h" #include "packager/media/base/fourccs.h" #include "packager/media/base/muxer_options.h" @@ -118,7 +117,7 @@ class Muxer { // Add new media sample. Status AddSample(const MediaStream* stream, - scoped_refptr sample); + std::shared_ptr sample); // Initialize the muxer. virtual Status Initialize() = 0; @@ -128,7 +127,7 @@ class Muxer { // AddSample implementation. virtual Status DoAddSample(const MediaStream* stream, - scoped_refptr sample) = 0; + std::shared_ptr sample) = 0; MuxerOptions options_; bool initialized_; diff --git a/packager/media/base/stream_info.h b/packager/media/base/stream_info.h index 7384d87bc1..b98183239b 100644 --- a/packager/media/base/stream_info.h +++ b/packager/media/base/stream_info.h @@ -10,8 +10,6 @@ #include #include -#include "packager/base/memory/ref_counted.h" - namespace shaka { namespace media { @@ -50,13 +48,15 @@ enum Codec { }; /// Abstract class holds stream information. -class StreamInfo : public base::RefCountedThreadSafe { +class StreamInfo { public: StreamInfo(StreamType stream_type, int track_id, uint32_t time_scale, uint64_t duration, Codec codec, const std::string& codec_string, const uint8_t* codec_config, size_t codec_config_size, const std::string& language, bool is_encrypted); + virtual ~StreamInfo(); + /// @return true if this object has appropriate configuration values, false /// otherwise. virtual bool IsValidConfig() const = 0; @@ -82,10 +82,6 @@ class StreamInfo : public base::RefCountedThreadSafe { } void set_language(const std::string& language) { language_ = language; } - protected: - friend class base::RefCountedThreadSafe; - virtual ~StreamInfo(); - private: // Whether the stream is Audio or Video. StreamType stream_type_; diff --git a/packager/media/base/text_stream_info.h b/packager/media/base/text_stream_info.h index 294dfd3089..3f804bd070 100644 --- a/packager/media/base/text_stream_info.h +++ b/packager/media/base/text_stream_info.h @@ -32,14 +32,13 @@ class TextStreamInfo : public StreamInfo { const std::string& codec_config, uint16_t width, uint16_t height, const std::string& language); + ~TextStreamInfo() override; + bool IsValidConfig() const override; uint16_t width() const { return width_; } uint16_t height() const { return height_; } - protected: - ~TextStreamInfo() override; - private: uint16_t width_; uint16_t height_; diff --git a/packager/media/base/video_stream_info.h b/packager/media/base/video_stream_info.h index b375689b94..4d9f42b0f6 100644 --- a/packager/media/base/video_stream_info.h +++ b/packager/media/base/video_stream_info.h @@ -26,6 +26,8 @@ class VideoStreamInfo : public StreamInfo { uint8_t nalu_length_size, const std::string& language, bool is_encrypted); + ~VideoStreamInfo() override; + /// @name StreamInfo implementation overrides. /// @{ bool IsValidConfig() const override; @@ -54,8 +56,6 @@ class VideoStreamInfo : public StreamInfo { } private: - ~VideoStreamInfo() override; - uint16_t width_; uint16_t height_; diff --git a/packager/media/base/widevine_key_source.cc b/packager/media/base/widevine_key_source.cc index c15ece9b1d..f1ceee1c2d 100644 --- a/packager/media/base/widevine_key_source.cc +++ b/packager/media/base/widevine_key_source.cc @@ -12,7 +12,6 @@ #include "packager/base/bind.h" #include "packager/base/json/json_reader.h" #include "packager/base/json/json_writer.h" -#include "packager/base/memory/ref_counted.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" @@ -110,27 +109,6 @@ bool GetPsshDataFromTrack(const base::DictionaryValue& track_dict, namespace media { -// A ref counted wrapper for EncryptionKeyMap. -class WidevineKeySource::RefCountedEncryptionKeyMap - : public base::RefCountedThreadSafe { - public: - explicit RefCountedEncryptionKeyMap(EncryptionKeyMap* encryption_key_map) { - DCHECK(encryption_key_map); - encryption_key_map_.swap(*encryption_key_map); - } - - const EncryptionKeyMap& map() { return encryption_key_map_; } - - private: - friend class base::RefCountedThreadSafe; - - ~RefCountedEncryptionKeyMap() {} - - EncryptionKeyMap encryption_key_map_; - - DISALLOW_COPY_AND_ASSIGN(RefCountedEncryptionKeyMap); -}; - WidevineKeySource::WidevineKeySource(const std::string& server_url, bool add_common_pssh) : key_production_thread_("KeyProductionThread", @@ -288,10 +266,9 @@ Status WidevineKeySource::GetKeyInternal(uint32_t crypto_period_index, DCHECK_LE(track_type, NUM_VALID_TRACK_TYPES); DCHECK_NE(track_type, TRACK_TYPE_UNKNOWN); - scoped_refptr ref_counted_encryption_key_map; - Status status = - key_pool_->Peek(crypto_period_index, &ref_counted_encryption_key_map, - kGetKeyTimeoutInSeconds * 1000); + std::shared_ptr encryption_key_map; + Status status = key_pool_->Peek(crypto_period_index, &encryption_key_map, + kGetKeyTimeoutInSeconds * 1000); if (!status.ok()) { if (status.error_code() == error::STOPPED) { CHECK(!common_encryption_request_status_.ok()); @@ -300,13 +277,11 @@ Status WidevineKeySource::GetKeyInternal(uint32_t crypto_period_index, return status; } - const EncryptionKeyMap& encryption_key_map = - ref_counted_encryption_key_map->map(); - if (encryption_key_map.find(track_type) == encryption_key_map.end()) { + 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.at(track_type); + *key = *encryption_key_map->at(track_type); return Status::OK; } @@ -601,11 +576,9 @@ bool WidevineKeySource::PushToKeyPool( EncryptionKeyMap* encryption_key_map) { DCHECK(key_pool_); DCHECK(encryption_key_map); - Status status = - key_pool_->Push(scoped_refptr( - new RefCountedEncryptionKeyMap(encryption_key_map)), - kInfiniteTimeout); - encryption_key_map->clear(); + auto encryption_key_map_shared = std::make_shared(); + encryption_key_map_shared->swap(*encryption_key_map); + Status status = key_pool_->Push(encryption_key_map_shared, kInfiniteTimeout); if (!status.ok()) { DCHECK_EQ(error::STOPPED, status.error_code()); return false; diff --git a/packager/media/base/widevine_key_source.h b/packager/media/base/widevine_key_source.h index da68770d63..3e3717ef69 100644 --- a/packager/media/base/widevine_key_source.h +++ b/packager/media/base/widevine_key_source.h @@ -68,8 +68,7 @@ class WidevineKeySource : public KeySource { private: typedef std::map> EncryptionKeyMap; - class RefCountedEncryptionKeyMap; - typedef ProducerConsumerQueue > + typedef ProducerConsumerQueue> EncryptionKeyQueue; // Internal routine for getting keys. diff --git a/packager/media/codecs/h26x_byte_to_unit_stream_converter.h b/packager/media/codecs/h26x_byte_to_unit_stream_converter.h index b43da69528..7c98c6c35a 100644 --- a/packager/media/codecs/h26x_byte_to_unit_stream_converter.h +++ b/packager/media/codecs/h26x_byte_to_unit_stream_converter.h @@ -21,9 +21,9 @@ class BufferWriter; /// A base class that is used to convert H.26x byte streams to NAL unit streams. class H26xByteToUnitStreamConverter { public: - static const size_t kUnitStreamNaluLengthSize = 4; + static constexpr size_t kUnitStreamNaluLengthSize = 4; - H26xByteToUnitStreamConverter(Nalu::CodecType type); + explicit H26xByteToUnitStreamConverter(Nalu::CodecType type); virtual ~H26xByteToUnitStreamConverter(); /// Converts a whole byte stream encoded video frame to NAL unit stream @@ -61,4 +61,3 @@ class H26xByteToUnitStreamConverter { } // namespace shaka #endif // MEDIA_CODECS_H26x_BYTE_TO_UNIT_STREAM_CONVERTER_H_ - diff --git a/packager/media/codecs/nal_unit_to_byte_stream_converter.h b/packager/media/codecs/nal_unit_to_byte_stream_converter.h index b312d60400..d3a1b88136 100644 --- a/packager/media/codecs/nal_unit_to_byte_stream_converter.h +++ b/packager/media/codecs/nal_unit_to_byte_stream_converter.h @@ -11,7 +11,6 @@ #include #include "packager/base/macros.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/decrypt_config.h" namespace shaka { diff --git a/packager/media/event/hls_notify_muxer_listener_unittest.cc b/packager/media/event/hls_notify_muxer_listener_unittest.cc index 88dde1d79a..11e6d9b734 100644 --- a/packager/media/event/hls_notify_muxer_listener_unittest.cc +++ b/packager/media/event/hls_notify_muxer_listener_unittest.cc @@ -106,7 +106,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionInfoReadyBeforeMediaStart) { TEST_F(HlsNotifyMuxerListenerTest, OnMediaStart) { VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); EXPECT_CALL(mock_notifier_, @@ -143,7 +143,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStart) { ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _)) .WillByDefault(Return(true)); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); MuxerOptions muxer_options; @@ -183,7 +183,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStartBeforeMediaStart) { ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _)) .WillByDefault(Return(true)); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); MuxerOptions muxer_options; @@ -222,7 +222,7 @@ TEST_F(HlsNotifyMuxerListenerTest, NoEncryptionUpdateIfNotifyNewStreamFails) { EXPECT_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _)) .WillOnce(Return(false)); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); MuxerOptions muxer_options; @@ -237,7 +237,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionInfoReady) { ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _)) .WillByDefault(Return(true)); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); MuxerOptions muxer_options; listener_.OnMediaStart(muxer_options, *video_stream_info, 90000, diff --git a/packager/media/event/mpd_notify_muxer_listener_unittest.cc b/packager/media/event/mpd_notify_muxer_listener_unittest.cc index 98b6b412b0..fc8c9985f5 100644 --- a/packager/media/event/mpd_notify_muxer_listener_unittest.cc +++ b/packager/media/event/mpd_notify_muxer_listener_unittest.cc @@ -111,7 +111,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodClearContent) { MuxerOptions muxer_options; SetDefaultMuxerOptionsValues(&muxer_options); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); EXPECT_CALL(*notifier_, NotifyNewContainer(_, _)).Times(0); @@ -156,7 +156,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContent) { MuxerOptions muxer_options; SetDefaultMuxerOptionsValues(&muxer_options); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); const std::vector default_key_id( @@ -199,7 +199,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodOnSampleDurationReady) { MuxerOptions muxer_options; SetDefaultMuxerOptionsValues(&muxer_options); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); const uint32_t kSampleDuration = 1234u; const char kExpectedMediaInfo[] = @@ -246,7 +246,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodOnNewSegment) { MuxerOptions muxer_options; SetDefaultMuxerOptionsValues(&muxer_options); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); const uint64_t kStartTime1 = 0u; @@ -283,7 +283,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveNoKeyRotation) { MuxerOptions muxer_options; SetDefaultLiveMuxerOptionsValues(&muxer_options); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); const std::string kExpectedMediaInfo = @@ -355,7 +355,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveWithKeyRotation) { MuxerOptions muxer_options; SetDefaultLiveMuxerOptionsValues(&muxer_options); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = CreateVideoStreamInfo(video_params); // Note that this media info has protected_content with default key id. diff --git a/packager/media/event/muxer_listener_test_helper.cc b/packager/media/event/muxer_listener_test_helper.cc index 38b0f83f06..f309ad6602 100644 --- a/packager/media/event/muxer_listener_test_helper.cc +++ b/packager/media/event/muxer_listener_test_helper.cc @@ -14,14 +14,14 @@ namespace media { VideoStreamInfoParameters::VideoStreamInfoParameters() {} VideoStreamInfoParameters::~VideoStreamInfoParameters() {} -scoped_refptr CreateVideoStreamInfo( +std::shared_ptr CreateVideoStreamInfo( const VideoStreamInfoParameters& param) { - return scoped_refptr(new VideoStreamInfo( + return std::make_shared( param.track_id, param.time_scale, param.duration, param.codec, param.codec_string, param.codec_config.data(), param.codec_config.size(), param.width, param.height, param.pixel_width, param.pixel_height, 0, // trick_play_rate - param.nalu_length_size, param.language, param.is_encrypted)); + param.nalu_length_size, param.language, param.is_encrypted); } VideoStreamInfoParameters GetDefaultVideoStreamInfoParams() { diff --git a/packager/media/event/muxer_listener_test_helper.h b/packager/media/event/muxer_listener_test_helper.h index f196f803db..93ba6deb1f 100644 --- a/packager/media/event/muxer_listener_test_helper.h +++ b/packager/media/event/muxer_listener_test_helper.h @@ -10,7 +10,6 @@ #include #include -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/key_source.h" #include "packager/media/base/muxer_options.h" #include "packager/media/base/stream_info.h" @@ -85,7 +84,7 @@ struct OnMediaEndParameters { }; // Creates StreamInfo instance from VideoStreamInfoParameters. -scoped_refptr CreateVideoStreamInfo( +std::shared_ptr CreateVideoStreamInfo( const VideoStreamInfoParameters& param); // Returns the "default" VideoStreamInfoParameters for testing. diff --git a/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc b/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc index 2a664f28d1..2967142648 100644 --- a/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc +++ b/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc @@ -124,7 +124,7 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test { }; TEST_F(VodMediaInfoDumpMuxerListenerTest, UnencryptedStream_Normal) { - scoped_refptr stream_info = + std::shared_ptr stream_info = CreateVideoStreamInfo(GetDefaultVideoStreamInfoParams()); FireOnMediaStartWithDefaultMuxerOptions(*stream_info, !kEnableEncryption); @@ -157,7 +157,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, UnencryptedStream_Normal) { } TEST_F(VodMediaInfoDumpMuxerListenerTest, EncryptedStream_Normal) { - scoped_refptr stream_info = + std::shared_ptr stream_info = CreateVideoStreamInfo(GetDefaultVideoStreamInfoParams()); FireOnMediaStartWithDefaultMuxerOptions(*stream_info, kEnableEncryption); OnMediaEndParameters media_end_param = GetDefaultOnMediaEndParams(); @@ -204,7 +204,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckPixelWidthAndHeightSet) { params.pixel_width = 8; params.pixel_height = 9; - scoped_refptr stream_info = CreateVideoStreamInfo(params); + std::shared_ptr stream_info = CreateVideoStreamInfo(params); FireOnMediaStartWithDefaultMuxerOptions(*stream_info, !kEnableEncryption); OnMediaEndParameters media_end_param = GetDefaultOnMediaEndParams(); FireOnMediaEndWithParams(media_end_param); diff --git a/packager/media/formats/mp2t/es_parser.h b/packager/media/formats/mp2t/es_parser.h index f01034a4d9..2c40b1bcc1 100644 --- a/packager/media/formats/mp2t/es_parser.h +++ b/packager/media/formats/mp2t/es_parser.h @@ -8,7 +8,6 @@ #include #include "packager/base/callback.h" -#include "packager/base/memory/ref_counted.h" namespace shaka { namespace media { @@ -20,9 +19,9 @@ namespace mp2t { class EsParser { public: - typedef base::Callback&)> + typedef base::Callback&)> NewStreamInfoCB; - typedef base::Callback&)> + typedef base::Callback&)> EmitSampleCB; EsParser(uint32_t pid) : pid_(pid) {} diff --git a/packager/media/formats/mp2t/es_parser_adts.cc b/packager/media/formats/mp2t/es_parser_adts.cc index 63bca9a5ac..4aa81989e4 100644 --- a/packager/media/formats/mp2t/es_parser_adts.cc +++ b/packager/media/formats/mp2t/es_parser_adts.cc @@ -159,11 +159,8 @@ bool EsParserAdts::Parse(const uint8_t* buf, // Emit an audio frame. bool is_key_frame = true; - scoped_refptr sample = - MediaSample::CopyFrom( - frame_ptr + header_size, - frame_size - header_size, - is_key_frame); + std::shared_ptr sample = MediaSample::CopyFrom( + frame_ptr + header_size, frame_size - header_size, is_key_frame); sample->set_pts(current_pts); sample->set_dts(current_pts); sample->set_duration(frame_duration); @@ -188,7 +185,7 @@ void EsParserAdts::Flush() { void EsParserAdts::Reset() { es_byte_queue_.Reset(); pts_list_.clear(); - last_audio_decoder_config_ = scoped_refptr(); + last_audio_decoder_config_ = std::shared_ptr(); } bool EsParserAdts::UpdateAudioConfiguration(const uint8_t* adts_frame, @@ -222,13 +219,13 @@ bool EsParserAdts::UpdateAudioConfiguration(const uint8_t* adts_frame, ? std::min(2 * samples_per_second, 48000) : samples_per_second; - last_audio_decoder_config_ = scoped_refptr(new AudioStreamInfo( + last_audio_decoder_config_ = std::make_shared( pid(), kMpeg2Timescale, kInfiniteDuration, kCodecAAC, AudioStreamInfo::GetCodecString(kCodecAAC, adts_header.GetObjectType()), audio_specific_config.data(), audio_specific_config.size(), kAacSampleSizeBits, adts_header.GetNumChannels(), extended_samples_per_second, 0 /* seek preroll */, 0 /* codec delay */, - 0 /* max bitrate */, 0 /* avg bitrate */, std::string(), false)); + 0 /* max bitrate */, 0 /* avg bitrate */, std::string(), false); DVLOG(1) << "Sampling frequency: " << samples_per_second; DVLOG(1) << "Extended sampling frequency: " << extended_samples_per_second; diff --git a/packager/media/formats/mp2t/es_parser_adts.h b/packager/media/formats/mp2t/es_parser_adts.h index 12524e346d..e0e6b0b109 100644 --- a/packager/media/formats/mp2t/es_parser_adts.h +++ b/packager/media/formats/mp2t/es_parser_adts.h @@ -67,7 +67,7 @@ class EsParserAdts : public EsParser { // Interpolated PTS for frames that don't have one. std::unique_ptr audio_timestamp_helper_; - scoped_refptr last_audio_decoder_config_; + std::shared_ptr last_audio_decoder_config_; DISALLOW_COPY_AND_ASSIGN(EsParserAdts); }; diff --git a/packager/media/formats/mp2t/es_parser_h264.cc b/packager/media/formats/mp2t/es_parser_h264.cc index ccc8da4493..c180480920 100644 --- a/packager/media/formats/mp2t/es_parser_h264.cc +++ b/packager/media/formats/mp2t/es_parser_h264.cc @@ -36,7 +36,7 @@ EsParserH264::~EsParserH264() {} void EsParserH264::Reset() { DVLOG(1) << "EsParserH264::Reset"; h264_parser_.reset(new H264Parser()); - last_video_decoder_config_ = scoped_refptr(); + last_video_decoder_config_ = std::shared_ptr(); decoder_config_check_pending_ = false; EsParserH26x::Reset(); } @@ -146,15 +146,16 @@ bool EsParserH264::UpdateVideoDecoderConfig(int pps_id) { return false; } - last_video_decoder_config_ = scoped_refptr(new VideoStreamInfo( + const uint8_t nalu_length_size = + H26xByteToUnitStreamConverter::kUnitStreamNaluLengthSize; + last_video_decoder_config_ = std::make_shared( pid(), kMpeg2Timescale, kInfiniteDuration, kCodecH264, AVCDecoderConfigurationRecord::GetCodecString(decoder_config_record[1], decoder_config_record[2], decoder_config_record[3]), decoder_config_record.data(), decoder_config_record.size(), coded_width, - coded_height, pixel_width, pixel_height, 0, - H264ByteToUnitStreamConverter::kUnitStreamNaluLengthSize, std::string(), - false)); + coded_height, pixel_width, pixel_height, 0, nalu_length_size, + std::string(), false); DVLOG(1) << "Profile IDC: " << sps->profile_idc; DVLOG(1) << "Level IDC: " << sps->level_idc; DVLOG(1) << "log2_max_frame_num_minus4: " << sps->log2_max_frame_num_minus4; diff --git a/packager/media/formats/mp2t/es_parser_h264.h b/packager/media/formats/mp2t/es_parser_h264.h index 03fff73486..0fd8f601bf 100644 --- a/packager/media/formats/mp2t/es_parser_h264.h +++ b/packager/media/formats/mp2t/es_parser_h264.h @@ -43,7 +43,7 @@ class EsParserH264 : public EsParserH26x { // Callback to pass the stream configuration. NewStreamInfoCB new_stream_info_cb_; - scoped_refptr last_video_decoder_config_; + std::shared_ptr last_video_decoder_config_; bool decoder_config_check_pending_; std::unique_ptr h264_parser_; diff --git a/packager/media/formats/mp2t/es_parser_h264_unittest.cc b/packager/media/formats/mp2t/es_parser_h264_unittest.cc index cd5b307de9..405ea49e9a 100644 --- a/packager/media/formats/mp2t/es_parser_h264_unittest.cc +++ b/packager/media/formats/mp2t/es_parser_h264_unittest.cc @@ -124,13 +124,13 @@ class EsParserH264Test : public testing::Test { void LoadStream(const char* filename); void ProcessPesPackets(const std::vector& pes_packets); - void EmitSample(uint32_t pid, const scoped_refptr& sample) { + void EmitSample(uint32_t pid, const std::shared_ptr& sample) { sample_count_++; if (sample_count_ == 1) first_frame_is_key_frame_ = sample->is_key_frame(); } - void NewVideoConfig(const scoped_refptr& config) { + void NewVideoConfig(const std::shared_ptr& config) { DVLOG(1) << config->ToString(); stream_map_[config->track_id()] = config; } @@ -145,7 +145,7 @@ class EsParserH264Test : public testing::Test { std::vector access_units_; protected: - typedef std::map > StreamMap; + typedef std::map> StreamMap; StreamMap stream_map_; size_t sample_count_; bool first_frame_is_key_frame_; diff --git a/packager/media/formats/mp2t/es_parser_h265.cc b/packager/media/formats/mp2t/es_parser_h265.cc index 6318700fc2..9fc4681392 100644 --- a/packager/media/formats/mp2t/es_parser_h265.cc +++ b/packager/media/formats/mp2t/es_parser_h265.cc @@ -39,7 +39,7 @@ EsParserH265::~EsParserH265() {} void EsParserH265::Reset() { DVLOG(1) << "EsParserH265::Reset"; h265_parser_.reset(new H265Parser()); - last_video_decoder_config_ = scoped_refptr(); + last_video_decoder_config_ = std::shared_ptr(); decoder_config_check_pending_ = false; EsParserH26x::Reset(); } @@ -151,12 +151,13 @@ bool EsParserH265::UpdateVideoDecoderConfig(int pps_id) { return false; } - last_video_decoder_config_ = scoped_refptr(new VideoStreamInfo( + const uint8_t nalu_length_size = + H26xByteToUnitStreamConverter::kUnitStreamNaluLengthSize; + last_video_decoder_config_ = std::make_shared( pid(), kMpeg2Timescale, kInfiniteDuration, kCodecHVC1, decoder_config.GetCodecString(kCodecHVC1), decoder_config_record.data(), decoder_config_record.size(), coded_width, coded_height, pixel_width, - pixel_height, 0, H26xByteToUnitStreamConverter::kUnitStreamNaluLengthSize, - std::string(), false)); + pixel_height, 0, nalu_length_size, std::string(), false); // Video config notification. new_stream_info_cb_.Run(last_video_decoder_config_); diff --git a/packager/media/formats/mp2t/es_parser_h265.h b/packager/media/formats/mp2t/es_parser_h265.h index 18b972e333..cdbff11ad5 100644 --- a/packager/media/formats/mp2t/es_parser_h265.h +++ b/packager/media/formats/mp2t/es_parser_h265.h @@ -46,7 +46,7 @@ class EsParserH265 : public EsParserH26x { NewStreamInfoCB new_stream_info_cb_; // Last video decoder config. - scoped_refptr last_video_decoder_config_; + std::shared_ptr last_video_decoder_config_; bool decoder_config_check_pending_; std::unique_ptr h265_parser_; diff --git a/packager/media/formats/mp2t/es_parser_h26x.cc b/packager/media/formats/mp2t/es_parser_h26x.cc index eab393fb81..cb75c3fd74 100644 --- a/packager/media/formats/mp2t/es_parser_h26x.cc +++ b/packager/media/formats/mp2t/es_parser_h26x.cc @@ -94,7 +94,7 @@ void EsParserH26x::Flush() { DCHECK(pending_sample_duration_); pending_sample_->set_duration(pending_sample_duration_); emit_sample_cb_.Run(pid(), pending_sample_); - pending_sample_ = scoped_refptr(); + pending_sample_ = std::shared_ptr(); } } @@ -107,7 +107,7 @@ void EsParserH26x::Reset() { next_access_unit_position_ = 0; current_nalu_info_.reset(); timing_desc_list_.clear(); - pending_sample_ = scoped_refptr(); + pending_sample_ = std::shared_ptr(); pending_sample_duration_ = 0; waiting_for_key_frame_ = true; } @@ -299,7 +299,7 @@ bool EsParserH26x::EmitFrame(int64_t access_unit_pos, // Create the media sample, emitting always the previous sample after // calculating its duration. - scoped_refptr media_sample = MediaSample::CopyFrom( + std::shared_ptr media_sample = MediaSample::CopyFrom( converted_frame.data(), converted_frame.size(), is_key_frame); media_sample->set_dts(current_timing_desc.dts); media_sample->set_pts(current_timing_desc.pts); diff --git a/packager/media/formats/mp2t/es_parser_h26x.h b/packager/media/formats/mp2t/es_parser_h26x.h index e5bcb82c07..45a1a9f04e 100644 --- a/packager/media/formats/mp2t/es_parser_h26x.h +++ b/packager/media/formats/mp2t/es_parser_h26x.h @@ -126,7 +126,7 @@ class EsParserH26x : public EsParser { std::unique_ptr stream_converter_; // Frame for which we do not yet have a duration. - scoped_refptr pending_sample_; + std::shared_ptr pending_sample_; uint64_t pending_sample_duration_ = 0; // Indicates whether waiting for first key frame. diff --git a/packager/media/formats/mp2t/es_parser_h26x_unittest.cc b/packager/media/formats/mp2t/es_parser_h26x_unittest.cc index dc6bc957b9..5298e02630 100644 --- a/packager/media/formats/mp2t/es_parser_h26x_unittest.cc +++ b/packager/media/formats/mp2t/es_parser_h26x_unittest.cc @@ -163,7 +163,7 @@ class EsParserH26xTest : public testing::Test { const H26xNaluType* types, size_t types_count); - void EmitSample(uint32_t pid, const scoped_refptr& sample) { + void EmitSample(uint32_t pid, const std::shared_ptr& sample) { size_t sample_id = sample_count_; sample_count_++; if (sample_count_ == 1) @@ -175,7 +175,7 @@ class EsParserH26xTest : public testing::Test { EXPECT_EQ(samples_[sample_id], sample_data); } - void NewVideoConfig(const scoped_refptr& config) { + void NewVideoConfig(const std::shared_ptr& config) { has_stream_info_ = true; } diff --git a/packager/media/formats/mp2t/mp2t_media_parser.cc b/packager/media/formats/mp2t/mp2t_media_parser.cc index aa7c005d21..e672320340 100644 --- a/packager/media/formats/mp2t/mp2t_media_parser.cc +++ b/packager/media/formats/mp2t/mp2t_media_parser.cc @@ -61,8 +61,10 @@ class PidState { PidType pid_type() const { return pid_type_; } - scoped_refptr& config() { return config_; } - void set_config(const scoped_refptr& config) { config_ = config; } + std::shared_ptr& config() { return config_; } + void set_config(const std::shared_ptr& config) { + config_ = config; + } SampleQueue& sample_queue() { return sample_queue_; } @@ -75,7 +77,7 @@ class PidState { bool enable_; int continuity_counter_; - scoped_refptr config_; + std::shared_ptr config_; SampleQueue sample_queue_; }; @@ -333,7 +335,7 @@ void Mp2tMediaParser::RegisterPes(int pmt_pid, } void Mp2tMediaParser::OnNewStreamInfo( - const scoped_refptr& new_stream_info) { + const std::shared_ptr& new_stream_info) { DCHECK(new_stream_info); DVLOG(1) << "OnVideoConfigChanged for pid=" << new_stream_info->track_id(); @@ -360,7 +362,7 @@ bool Mp2tMediaParser::FinishInitializationIfNeeded() { if (pids_.empty()) return true; - std::vector > all_stream_info; + std::vector> all_stream_info; uint32_t num_es(0); for (PidMap::const_iterator iter = pids_.begin(); iter != pids_.end(); ++iter) { @@ -383,7 +385,7 @@ bool Mp2tMediaParser::FinishInitializationIfNeeded() { void Mp2tMediaParser::OnEmitSample( uint32_t pes_pid, - const scoped_refptr& new_sample) { + const std::shared_ptr& new_sample) { DCHECK(new_sample); DVLOG(LOG_LEVEL_ES) << "OnEmitSample: " diff --git a/packager/media/formats/mp2t/mp2t_media_parser.h b/packager/media/formats/mp2t/mp2t_media_parser.h index 4793a83a3d..ec9f9d286a 100644 --- a/packager/media/formats/mp2t/mp2t_media_parser.h +++ b/packager/media/formats/mp2t/mp2t_media_parser.h @@ -9,7 +9,6 @@ #include #include -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/byte_queue.h" #include "packager/media/base/media_parser.h" #include "packager/media/base/stream_info.h" @@ -25,7 +24,7 @@ class PidState; class TsPacket; class TsSection; -typedef std::deque > SampleQueue; +typedef std::deque> SampleQueue; class Mp2tMediaParser : public MediaParser { public: @@ -56,12 +55,12 @@ class Mp2tMediaParser : public MediaParser { // Callback invoked each time the audio/video decoder configuration is // changed. - void OnNewStreamInfo(const scoped_refptr& new_stream_info); + void OnNewStreamInfo(const std::shared_ptr& new_stream_info); // Callback invoked by the ES media parser // to emit a new audio/video access unit. void OnEmitSample(uint32_t pes_pid, - const scoped_refptr& new_sample); + const std::shared_ptr& new_sample); // Invoke the initialization callback if needed. bool FinishInitializationIfNeeded(); diff --git a/packager/media/formats/mp2t/mp2t_media_parser_unittest.cc b/packager/media/formats/mp2t/mp2t_media_parser_unittest.cc index 0be3a1d742..15959bf200 100644 --- a/packager/media/formats/mp2t/mp2t_media_parser_unittest.cc +++ b/packager/media/formats/mp2t/mp2t_media_parser_unittest.cc @@ -10,7 +10,6 @@ #include "packager/base/bind.h" #include "packager/base/bind_helpers.h" #include "packager/base/logging.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/media_sample.h" #include "packager/media/base/stream_info.h" #include "packager/media/base/timestamp.h" @@ -34,7 +33,7 @@ class Mp2tMediaParserTest : public testing::Test { } protected: - typedef std::map > StreamMap; + typedef std::map> StreamMap; std::unique_ptr parser_; StreamMap stream_map_; @@ -62,17 +61,16 @@ class Mp2tMediaParserTest : public testing::Test { return true; } - void OnInit(const std::vector >& stream_infos) { + void OnInit(const std::vector>& stream_infos) { DVLOG(1) << "OnInit: " << stream_infos.size() << " streams."; - for (std::vector >::const_iterator iter = - stream_infos.begin(); iter != stream_infos.end(); ++iter) { - DVLOG(1) << (*iter)->ToString(); - stream_map_[(*iter)->track_id()] = *iter; + for (const auto& stream_info : stream_infos) { + DVLOG(1) << stream_info->ToString(); + stream_map_[stream_info->track_id()] = stream_info; } } bool OnNewSample(uint32_t track_id, - const scoped_refptr& sample) { + const std::shared_ptr& sample) { StreamMap::const_iterator stream = stream_map_.find(track_id); EXPECT_NE(stream_map_.end(), stream); if (stream != stream_map_.end()) { diff --git a/packager/media/formats/mp2t/pes_packet_generator.cc b/packager/media/formats/mp2t/pes_packet_generator.cc index 287c0fe995..2e4cd3b119 100644 --- a/packager/media/formats/mp2t/pes_packet_generator.cc +++ b/packager/media/formats/mp2t/pes_packet_generator.cc @@ -124,7 +124,7 @@ bool PesPacketGenerator::Initialize(const StreamInfo& stream_info) { return false; } -bool PesPacketGenerator::PushSample(scoped_refptr sample) { +bool PesPacketGenerator::PushSample(std::shared_ptr sample) { if (!current_processing_pes_) current_processing_pes_.reset(new PesPacket()); diff --git a/packager/media/formats/mp2t/pes_packet_generator.h b/packager/media/formats/mp2t/pes_packet_generator.h index 7a31910caf..ff23cd85a2 100644 --- a/packager/media/formats/mp2t/pes_packet_generator.h +++ b/packager/media/formats/mp2t/pes_packet_generator.h @@ -44,7 +44,7 @@ class PesPacketGenerator { /// NumberOfReadyPesPackets(). /// If this returns false, the object may end up in an undefined state. /// @return true on success, false otherwise. - virtual bool PushSample(scoped_refptr sample); + virtual bool PushSample(std::shared_ptr sample); /// Sets the encryption key for encrypting samples. /// @param encryption_key is the key that will be used to encrypt further diff --git a/packager/media/formats/mp2t/pes_packet_generator_unittest.cc b/packager/media/formats/mp2t/pes_packet_generator_unittest.cc index 94fc32bdaf..1b8a970eb7 100644 --- a/packager/media/formats/mp2t/pes_packet_generator_unittest.cc +++ b/packager/media/formats/mp2t/pes_packet_generator_unittest.cc @@ -102,16 +102,16 @@ class MockAACAudioSpecificConfig : public AACAudioSpecificConfig { MOCK_CONST_METHOD1(ConvertToADTS, bool(std::vector* buffer)); }; -scoped_refptr CreateVideoStreamInfo(Codec codec) { - scoped_refptr stream_info(new VideoStreamInfo( +std::shared_ptr CreateVideoStreamInfo(Codec codec) { + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, codec, kCodecString, kVideoExtraData, arraysize(kVideoExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); return stream_info; } -scoped_refptr CreateAudioStreamInfo(Codec codec) { - scoped_refptr stream_info(new AudioStreamInfo( +std::shared_ptr CreateAudioStreamInfo(Codec codec) { + std::shared_ptr stream_info(new AudioStreamInfo( kTrackId, kTimeScale, kDuration, codec, kCodecString, kAudioExtraData, arraysize(kAudioExtraData), kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, kMaxBitrate, kAverageBitrate, kLanguage, @@ -138,12 +138,12 @@ class PesPacketGeneratorTest : public ::testing::Test { size_t input_size, const uint8_t* expected_output, size_t expected_output_size) { - scoped_refptr stream_info( + std::shared_ptr stream_info( CreateVideoStreamInfo(kH264Codec)); EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); - scoped_refptr sample = + std::shared_ptr sample = MediaSample::CopyFrom(input, input_size, kIsKeyFrame); const uint32_t kPts = 12345; const uint32_t kDts = 12300; @@ -187,15 +187,15 @@ class PesPacketGeneratorTest : public ::testing::Test { size_t input_size, const uint8_t* expected_output, size_t expected_output_size) { - scoped_refptr stream_info( + std::shared_ptr stream_info( CreateAudioStreamInfo(kAacCodec)); EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); // For aac, the input from MediaSample is used. Then ADTS header is added, // so EXPECT_CALL does not return the |input| data. - scoped_refptr sample = MediaSample::CopyFrom( - input, input_size, kIsKeyFrame); + std::shared_ptr sample = + MediaSample::CopyFrom(input, input_size, kIsKeyFrame); std::unique_ptr mock( new MockAACAudioSpecificConfig()); @@ -223,41 +223,44 @@ class PesPacketGeneratorTest : public ::testing::Test { }; TEST_F(PesPacketGeneratorTest, InitializeVideo) { - scoped_refptr stream_info(CreateVideoStreamInfo(kH264Codec)); + std::shared_ptr stream_info( + CreateVideoStreamInfo(kH264Codec)); EXPECT_TRUE(generator_.Initialize(*stream_info)); } TEST_F(PesPacketGeneratorTest, InitializeVideoNonH264) { - scoped_refptr stream_info( + std::shared_ptr stream_info( CreateVideoStreamInfo(Codec::kCodecVP9)); EXPECT_FALSE(generator_.Initialize(*stream_info)); } TEST_F(PesPacketGeneratorTest, InitializeAudio) { - scoped_refptr stream_info(CreateAudioStreamInfo(kAacCodec)); + std::shared_ptr stream_info( + CreateAudioStreamInfo(kAacCodec)); EXPECT_TRUE(generator_.Initialize(*stream_info)); } TEST_F(PesPacketGeneratorTest, InitializeAudioNonAac) { - scoped_refptr stream_info( + std::shared_ptr stream_info( CreateAudioStreamInfo(Codec::kCodecOpus)); EXPECT_FALSE(generator_.Initialize(*stream_info)); } // Text is not supported yet. TEST_F(PesPacketGeneratorTest, InitializeTextInfo) { - scoped_refptr stream_info( + std::shared_ptr stream_info( new TextStreamInfo(kTrackId, kTimeScale, kDuration, kCodecString, std::string(), kWidth, kHeight, kLanguage)); EXPECT_FALSE(generator_.Initialize(*stream_info)); } TEST_F(PesPacketGeneratorTest, AddVideoSample) { - scoped_refptr stream_info(CreateVideoStreamInfo(kH264Codec)); + std::shared_ptr stream_info( + CreateVideoStreamInfo(kH264Codec)); EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); - scoped_refptr sample = + std::shared_ptr sample = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); const uint32_t kPts = 12345; const uint32_t kDts = 12300; @@ -289,11 +292,12 @@ TEST_F(PesPacketGeneratorTest, AddVideoSample) { } TEST_F(PesPacketGeneratorTest, AddVideoSampleFailedToConvert) { - scoped_refptr stream_info(CreateVideoStreamInfo(kH264Codec)); + std::shared_ptr stream_info( + CreateVideoStreamInfo(kH264Codec)); EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); - scoped_refptr sample = + std::shared_ptr sample = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); std::vector expected_data(kAnyData, kAnyData + arraysize(kAnyData)); @@ -311,11 +315,12 @@ TEST_F(PesPacketGeneratorTest, AddVideoSampleFailedToConvert) { } TEST_F(PesPacketGeneratorTest, AddAudioSample) { - scoped_refptr stream_info(CreateAudioStreamInfo(kAacCodec)); + std::shared_ptr stream_info( + CreateAudioStreamInfo(kAacCodec)); EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); - scoped_refptr sample = + std::shared_ptr sample = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); std::vector expected_data(kAnyData, kAnyData + arraysize(kAnyData)); @@ -340,11 +345,12 @@ TEST_F(PesPacketGeneratorTest, AddAudioSample) { } TEST_F(PesPacketGeneratorTest, AddAudioSampleFailedToConvert) { - scoped_refptr stream_info(CreateAudioStreamInfo(kAacCodec)); + std::shared_ptr stream_info( + CreateAudioStreamInfo(kAacCodec)); EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); - scoped_refptr sample = + std::shared_ptr sample = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); std::unique_ptr mock( @@ -362,7 +368,7 @@ TEST_F(PesPacketGeneratorTest, AddAudioSampleFailedToConvert) { // are scaled. TEST_F(PesPacketGeneratorTest, TimeStampScaling) { const uint32_t kTestTimescale = 1000; - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTestTimescale, kDuration, kH264Codec, kCodecString, kVideoExtraData, arraysize(kVideoExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -370,7 +376,7 @@ TEST_F(PesPacketGeneratorTest, TimeStampScaling) { EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); - scoped_refptr sample = + std::shared_ptr sample = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); const uint32_t kPts = 5000; const uint32_t kDts = 4000; diff --git a/packager/media/formats/mp2t/ts_muxer.cc b/packager/media/formats/mp2t/ts_muxer.cc index 0b822fade7..75ea2cfd88 100644 --- a/packager/media/formats/mp2t/ts_muxer.cc +++ b/packager/media/formats/mp2t/ts_muxer.cc @@ -36,7 +36,7 @@ Status TsMuxer::Finalize() { } Status TsMuxer::DoAddSample(const MediaStream* stream, - scoped_refptr sample) { + std::shared_ptr sample) { return segmenter_->AddSample(sample); } diff --git a/packager/media/formats/mp2t/ts_muxer.h b/packager/media/formats/mp2t/ts_muxer.h index 35a1fa333b..d36b423686 100644 --- a/packager/media/formats/mp2t/ts_muxer.h +++ b/packager/media/formats/mp2t/ts_muxer.h @@ -27,7 +27,7 @@ class TsMuxer : public Muxer { Status Initialize() override; Status Finalize() override; Status DoAddSample(const MediaStream* stream, - scoped_refptr sample) override; + std::shared_ptr sample) override; void FireOnMediaStartEvent(); void FireOnMediaEndEvent(); diff --git a/packager/media/formats/mp2t/ts_segmenter.cc b/packager/media/formats/mp2t/ts_segmenter.cc index 99a1afb01a..e74bd21e2c 100644 --- a/packager/media/formats/mp2t/ts_segmenter.cc +++ b/packager/media/formats/mp2t/ts_segmenter.cc @@ -88,7 +88,7 @@ Status TsSegmenter::Finalize() { // First checks whether the sample is a key frame. If so and the segment has // passed the segment duration, then flush the generator and write all the data // to file. -Status TsSegmenter::AddSample(scoped_refptr sample) { +Status TsSegmenter::AddSample(std::shared_ptr sample) { const bool passed_segment_duration = current_segment_total_sample_duration_ > muxer_options_.segment_duration; if (sample->is_key_frame() && passed_segment_duration) { diff --git a/packager/media/formats/mp2t/ts_segmenter.h b/packager/media/formats/mp2t/ts_segmenter.h index b61da4be1c..2a0496dc95 100644 --- a/packager/media/formats/mp2t/ts_segmenter.h +++ b/packager/media/formats/mp2t/ts_segmenter.h @@ -53,7 +53,7 @@ class TsSegmenter { /// @param sample gets added to this object. /// @return OK on success. - Status AddSample(scoped_refptr sample); + Status AddSample(std::shared_ptr sample); /// Only for testing. void InjectTsWriterForTesting(std::unique_ptr writer); diff --git a/packager/media/formats/mp2t/ts_segmenter_unittest.cc b/packager/media/formats/mp2t/ts_segmenter_unittest.cc index d2f1e240de..b6a59d95e4 100644 --- a/packager/media/formats/mp2t/ts_segmenter_unittest.cc +++ b/packager/media/formats/mp2t/ts_segmenter_unittest.cc @@ -53,7 +53,7 @@ const uint8_t kAnyData[] = { class MockPesPacketGenerator : public PesPacketGenerator { public: MOCK_METHOD1(Initialize, bool(const StreamInfo& info)); - MOCK_METHOD1(PushSample, bool(scoped_refptr sample)); + MOCK_METHOD1(PushSample, bool(std::shared_ptr sample)); MOCK_METHOD1(SetEncryptionKeyMock, bool(EncryptionKey* encryption_key)); bool SetEncryptionKey( std::unique_ptr encryption_key) override { @@ -108,7 +108,7 @@ class TsSegmenterTest : public ::testing::Test { }; TEST_F(TsSegmenterTest, Initialize) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -128,7 +128,7 @@ TEST_F(TsSegmenterTest, Initialize) { } TEST_F(TsSegmenterTest, AddSample) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -141,7 +141,7 @@ TEST_F(TsSegmenterTest, AddSample) { EXPECT_CALL(*mock_pes_packet_generator_, Initialize(_)) .WillOnce(Return(true)); - scoped_refptr sample = + std::shared_ptr sample = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); Sequence writer_sequence; @@ -183,7 +183,7 @@ TEST_F(TsSegmenterTest, PassedSegmentDuration) { // Use something significantly smaller than 90000 to check that the scaling is // done correctly in the segmenter. const uint32_t kInputTimescale = 1001; - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kInputTimescale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -200,9 +200,9 @@ TEST_F(TsSegmenterTest, PassedSegmentDuration) { EXPECT_CALL(*mock_pes_packet_generator_, Initialize(_)) .WillOnce(Return(true)); - scoped_refptr sample1 = + std::shared_ptr sample1 = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); - scoped_refptr sample2 = + std::shared_ptr sample2 = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); // 11 seconds > 10 seconds (segment duration). @@ -282,7 +282,7 @@ TEST_F(TsSegmenterTest, PassedSegmentDuration) { // Finalize right after Initialize(). The writer will not be initialized. TEST_F(TsSegmenterTest, InitializeThenFinalize) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -311,7 +311,7 @@ TEST_F(TsSegmenterTest, InitializeThenFinalize) { // The test does not really add any samples but instead simulates an initialized // writer with a mock. TEST_F(TsSegmenterTest, Finalize) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -340,7 +340,7 @@ TEST_F(TsSegmenterTest, Finalize) { // Verify that it won't finish a segment if the sample is not a key frame. TEST_F(TsSegmenterTest, SegmentOnlyBeforeKeyFrame) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -356,11 +356,11 @@ TEST_F(TsSegmenterTest, SegmentOnlyBeforeKeyFrame) { const uint8_t kAnyData[] = { 0x01, 0x0F, 0x3C, }; - scoped_refptr key_frame_sample1 = + std::shared_ptr key_frame_sample1 = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); - scoped_refptr non_key_frame_sample = + std::shared_ptr non_key_frame_sample = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), !kIsKeyFrame); - scoped_refptr key_frame_sample2 = + std::shared_ptr key_frame_sample2 = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); // 11 seconds > 10 seconds (segment duration). @@ -446,7 +446,7 @@ TEST_F(TsSegmenterTest, SegmentOnlyBeforeKeyFrame) { } TEST_F(TsSegmenterTest, WithEncryptionNoClearLead) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -489,7 +489,7 @@ TEST_F(TsSegmenterTest, WithEncryptionNoClearLead) { // Verify that the muxer listener pointer is not used without checking that it's // not null. TEST_F(TsSegmenterTest, WithEncryptionNoClearLeadNoMuxerListener) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -529,7 +529,7 @@ TEST_F(TsSegmenterTest, WithEncryptionNoClearLeadNoMuxerListener) { // Verify that encryption notification is sent to objects after clear lead. TEST_F(TsSegmenterTest, WithEncryptionWithClearLead) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -555,9 +555,9 @@ TEST_F(TsSegmenterTest, WithEncryptionWithClearLead) { const uint8_t kAnyData[] = { 0x01, 0x0F, 0x3C, }; - scoped_refptr sample1 = + std::shared_ptr sample1 = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); - scoped_refptr sample2 = + std::shared_ptr sample2 = MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); // Something longer than 1.0 (segment duration and clear lead). diff --git a/packager/media/formats/mp2t/ts_writer_unittest.cc b/packager/media/formats/mp2t/ts_writer_unittest.cc index b632d7bec9..bb90dfb72c 100644 --- a/packager/media/formats/mp2t/ts_writer_unittest.cc +++ b/packager/media/formats/mp2t/ts_writer_unittest.cc @@ -157,7 +157,7 @@ class TsWriterTest : public ::testing::Test { }; TEST_F(TsWriterTest, InitializeVideoH264) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -165,7 +165,7 @@ TEST_F(TsWriterTest, InitializeVideoH264) { } TEST_F(TsWriterTest, InitializeVideoNonH264) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, Codec::kCodecVP9, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -173,7 +173,7 @@ TEST_F(TsWriterTest, InitializeVideoNonH264) { } TEST_F(TsWriterTest, InitializeAudioAac) { - scoped_refptr stream_info(new AudioStreamInfo( + std::shared_ptr stream_info(new AudioStreamInfo( kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kExtraData, arraysize(kExtraData), kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, kMaxBitrate, kAverageBitrate, kLanguage, @@ -182,7 +182,7 @@ TEST_F(TsWriterTest, InitializeAudioAac) { } TEST_F(TsWriterTest, InitializeAudioNonAac) { - scoped_refptr stream_info(new AudioStreamInfo( + std::shared_ptr stream_info(new AudioStreamInfo( kTrackId, kTimeScale, kDuration, Codec::kCodecOpus, kCodecString, kExtraData, arraysize(kExtraData), kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, kMaxBitrate, @@ -198,7 +198,7 @@ TEST_F(TsWriterTest, ClearH264Psi) { new MockProgramMapTableWriter()); EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)).WillOnce(WriteOnePmt()); - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -252,7 +252,7 @@ TEST_F(TsWriterTest, ClearAacPmt) { new MockProgramMapTableWriter()); EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)).WillOnce(WriteOnePmt()); - scoped_refptr stream_info(new AudioStreamInfo( + std::shared_ptr stream_info(new AudioStreamInfo( kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData), kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, @@ -280,7 +280,7 @@ TEST_F(TsWriterTest, ClearLeadH264Pmt) { EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)) .WillOnce(WriteTwoPmts()); - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -309,7 +309,7 @@ TEST_F(TsWriterTest, EncryptedSegmentsH264Pmt) { EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)).WillOnce(Return(true)); EXPECT_CALL(*mock_pmt_writer, EncryptedSegmentPmt(_)).WillOnce(WriteOnePmt()); - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -340,7 +340,7 @@ TEST_F(TsWriterTest, ClearLeadAacPmt) { EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)) .WillOnce(WriteTwoPmts()); - scoped_refptr stream_info(new AudioStreamInfo( + std::shared_ptr stream_info(new AudioStreamInfo( kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData), kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, @@ -370,7 +370,7 @@ TEST_F(TsWriterTest, EncryptedSegmentsAacPmt) { EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)).WillOnce(Return(true)); EXPECT_CALL(*mock_pmt_writer, EncryptedSegmentPmt(_)).WillOnce(WriteOnePmt()); - scoped_refptr stream_info(new AudioStreamInfo( + std::shared_ptr stream_info(new AudioStreamInfo( kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData), kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, @@ -397,7 +397,7 @@ TEST_F(TsWriterTest, EncryptedSegmentsAacPmt) { TEST_F(TsWriterTest, AddPesPacket) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -462,7 +462,7 @@ TEST_F(TsWriterTest, AddPesPacket) { // Verify that PES packet > 64KiB can be handled. TEST_F(TsWriterTest, BigPesPacket) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -498,7 +498,7 @@ TEST_F(TsWriterTest, BigPesPacket) { // Bug found in code review. It should check whether PTS is present not whether // PTS (implicilty) cast to bool is true. TEST_F(TsWriterTest, PesPtsZeroNoDts) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); @@ -558,7 +558,7 @@ TEST_F(TsWriterTest, PesPtsZeroNoDts) { // Verify that TS packet with payload 183 is handled correctly, e.g. // adaptation_field_length should be 0. TEST_F(TsWriterTest, TsPacketPayload183Bytes) { - scoped_refptr stream_info(new VideoStreamInfo( + std::shared_ptr stream_info(new VideoStreamInfo( kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); diff --git a/packager/media/formats/mp4/encrypting_fragmenter.cc b/packager/media/formats/mp4/encrypting_fragmenter.cc index 859ec8104c..7fa2e1e911 100644 --- a/packager/media/formats/mp4/encrypting_fragmenter.cc +++ b/packager/media/formats/mp4/encrypting_fragmenter.cc @@ -59,7 +59,7 @@ uint8_t GetNaluLengthSize(const StreamInfo& stream_info) { } // namespace EncryptingFragmenter::EncryptingFragmenter( - scoped_refptr info, + std::shared_ptr info, TrackFragment* traf, std::unique_ptr encryption_key, int64_t clear_time, @@ -103,7 +103,7 @@ EncryptingFragmenter::EncryptingFragmenter( EncryptingFragmenter::~EncryptingFragmenter() {} -Status EncryptingFragmenter::AddSample(scoped_refptr sample) { +Status EncryptingFragmenter::AddSample(std::shared_ptr sample) { DCHECK(sample); if (!fragment_initialized()) { Status status = InitializeFragment(sample->dts()); @@ -248,7 +248,8 @@ void EncryptingFragmenter::EncryptBytes(uint8_t* data, size_t size) { CHECK(encryptor_->Crypt(data, size, data)); } -Status EncryptingFragmenter::EncryptSample(scoped_refptr sample) { +Status EncryptingFragmenter::EncryptSample( + std::shared_ptr sample) { DCHECK(encryptor_); SampleEncryptionEntry sample_encryption_entry; diff --git a/packager/media/formats/mp4/encrypting_fragmenter.h b/packager/media/formats/mp4/encrypting_fragmenter.h index 57c93b45fe..f3a6a7cdc5 100644 --- a/packager/media/formats/mp4/encrypting_fragmenter.h +++ b/packager/media/formats/mp4/encrypting_fragmenter.h @@ -8,7 +8,6 @@ #define MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_ #include -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/fourccs.h" #include "packager/media/codecs/video_slice_header_parser.h" #include "packager/media/codecs/vpx_parser.h" @@ -38,7 +37,7 @@ class EncryptingFragmenter : public Fragmenter { /// pattern based encryption. /// @param skip_byte_block indicates number of unencrypted blocks (16-byte) /// in pattern based encryption. - EncryptingFragmenter(scoped_refptr info, + EncryptingFragmenter(std::shared_ptr info, TrackFragment* traf, std::unique_ptr encryption_key, int64_t clear_time, @@ -51,7 +50,7 @@ class EncryptingFragmenter : public Fragmenter { /// @name Fragmenter implementation overrides. /// @{ - Status AddSample(scoped_refptr sample) override; + Status AddSample(std::shared_ptr sample) override; Status InitializeFragment(int64_t first_sample_dts) override; void FinalizeFragment() override; /// @} @@ -80,12 +79,12 @@ class EncryptingFragmenter : public Fragmenter { private: void EncryptBytes(uint8_t* data, size_t size); - Status EncryptSample(scoped_refptr sample); + Status EncryptSample(std::shared_ptr sample); // Should we enable subsample encryption? bool IsSubsampleEncryptionRequired(); - scoped_refptr info_; + std::shared_ptr info_; std::unique_ptr encryption_key_; std::unique_ptr encryptor_; // If this stream contains AVC, subsample encryption specifies that the size diff --git a/packager/media/formats/mp4/fragmenter.cc b/packager/media/formats/mp4/fragmenter.cc index 016d4f39b1..784b946d67 100644 --- a/packager/media/formats/mp4/fragmenter.cc +++ b/packager/media/formats/mp4/fragmenter.cc @@ -29,7 +29,7 @@ uint64_t GetSeekPreroll(const StreamInfo& stream_info) { } } // namespace -Fragmenter::Fragmenter(scoped_refptr info, TrackFragment* traf) +Fragmenter::Fragmenter(std::shared_ptr info, TrackFragment* traf) : use_decoding_timestamp_in_timeline_(false), traf_(traf), seek_preroll_(GetSeekPreroll(*info)), @@ -43,7 +43,7 @@ Fragmenter::Fragmenter(scoped_refptr info, TrackFragment* traf) Fragmenter::~Fragmenter() {} -Status Fragmenter::AddSample(scoped_refptr sample) { +Status Fragmenter::AddSample(std::shared_ptr sample) { DCHECK(sample); if (sample->duration() == 0) { LOG(WARNING) << "Unexpected sample with zero duration @ dts " diff --git a/packager/media/formats/mp4/fragmenter.h b/packager/media/formats/mp4/fragmenter.h index 91c32194dd..2150a1df87 100644 --- a/packager/media/formats/mp4/fragmenter.h +++ b/packager/media/formats/mp4/fragmenter.h @@ -11,7 +11,6 @@ #include #include "packager/base/logging.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/status.h" namespace shaka { @@ -32,14 +31,14 @@ class Fragmenter { public: /// @param info contains stream information. /// @param traf points to a TrackFragment box. - Fragmenter(scoped_refptr info, TrackFragment* traf); + Fragmenter(std::shared_ptr info, TrackFragment* traf); virtual ~Fragmenter(); /// Add a sample to the fragmenter. /// @param sample points to the sample to be added. /// @return OK on success, an error status otherwise. - virtual Status AddSample(scoped_refptr sample); + virtual Status AddSample(std::shared_ptr sample); /// Initialize the fragment with default data. /// @param first_sample_dts specifies the decoding timestamp for the first diff --git a/packager/media/formats/mp4/key_rotation_fragmenter.cc b/packager/media/formats/mp4/key_rotation_fragmenter.cc index 5a9702250a..43fe30640f 100644 --- a/packager/media/formats/mp4/key_rotation_fragmenter.cc +++ b/packager/media/formats/mp4/key_rotation_fragmenter.cc @@ -18,7 +18,7 @@ const bool kInitialEncryptionInfo = true; } // namespace KeyRotationFragmenter::KeyRotationFragmenter(MovieFragment* moof, - scoped_refptr info, + std::shared_ptr info, TrackFragment* traf, KeySource* encryption_key_source, KeySource::TrackType track_type, diff --git a/packager/media/formats/mp4/key_rotation_fragmenter.h b/packager/media/formats/mp4/key_rotation_fragmenter.h index e496a8659c..3dca1442ac 100644 --- a/packager/media/formats/mp4/key_rotation_fragmenter.h +++ b/packager/media/formats/mp4/key_rotation_fragmenter.h @@ -42,7 +42,7 @@ class KeyRotationFragmenter : public EncryptingFragmenter { /// @param muxer_listener is a pointer to MuxerListener for notifying /// muxer related events. This may be null. KeyRotationFragmenter(MovieFragment* moof, - scoped_refptr info, + std::shared_ptr info, TrackFragment* traf, KeySource* encryption_key_source, KeySource::TrackType track_type, diff --git a/packager/media/formats/mp4/mp4_media_parser.cc b/packager/media/formats/mp4/mp4_media_parser.cc index 6147328404..721cb51037 100644 --- a/packager/media/formats/mp4/mp4_media_parser.cc +++ b/packager/media/formats/mp4/mp4_media_parser.cc @@ -10,7 +10,6 @@ #include "packager/base/callback.h" #include "packager/base/callback_helpers.h" #include "packager/base/logging.h" -#include "packager/base/memory/ref_counted.h" #include "packager/base/strings/string_number_conversions.h" #include "packager/media/base/audio_stream_info.h" #include "packager/media/base/buffer_reader.h" @@ -281,7 +280,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { RCHECK(moov_->Parse(reader)); runs_.reset(); - std::vector > streams; + std::vector> streams; for (std::vector::const_iterator track = moov_->tracks.begin(); track != moov_->tracks.end(); ++track) { @@ -466,7 +465,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { const bool is_encrypted = entry.sinf.info.track_encryption.default_is_protected == 1; DVLOG(1) << "is_audio_track_encrypted_: " << is_encrypted; - streams.push_back(new AudioStreamInfo( + streams.emplace_back(new AudioStreamInfo( track->header.track_id, timescale, duration, codec, AudioStreamInfo::GetCodecString(codec, audio_object_type), codec_config.data(), codec_config.size(), entry.samplesize, @@ -562,7 +561,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { const bool is_encrypted = entry.sinf.info.track_encryption.default_is_protected == 1; DVLOG(1) << "is_video_track_encrypted_: " << is_encrypted; - scoped_refptr video_stream_info(new VideoStreamInfo( + std::shared_ptr video_stream_info(new VideoStreamInfo( track->header.track_id, timescale, duration, video_codec, codec_string, entry.codec_configuration.data.data(), entry.codec_configuration.data.size(), coded_width, coded_height, @@ -694,8 +693,8 @@ bool MP4MediaParser::EnqueueSample(bool* err) { return false; } - scoped_refptr stream_sample(MediaSample::CopyFrom( - buf, runs_->sample_size(), runs_->is_keyframe())); + std::shared_ptr stream_sample( + MediaSample::CopyFrom(buf, runs_->sample_size(), runs_->is_keyframe())); if (runs_->is_encrypted()) { std::unique_ptr decrypt_config = runs_->GetDecryptConfig(); if (!decrypt_config) { diff --git a/packager/media/formats/mp4/mp4_media_parser.h b/packager/media/formats/mp4/mp4_media_parser.h index d68930f588..8f7ede4d7d 100644 --- a/packager/media/formats/mp4/mp4_media_parser.h +++ b/packager/media/formats/mp4/mp4_media_parser.h @@ -14,7 +14,6 @@ #include #include "packager/base/callback_forward.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/decryptor_source.h" #include "packager/media/base/media_parser.h" #include "packager/media/base/offset_byte_queue.h" diff --git a/packager/media/formats/mp4/mp4_media_parser_unittest.cc b/packager/media/formats/mp4/mp4_media_parser_unittest.cc index 258ca3cc63..7731889d26 100644 --- a/packager/media/formats/mp4/mp4_media_parser_unittest.cc +++ b/packager/media/formats/mp4/mp4_media_parser_unittest.cc @@ -46,7 +46,7 @@ class MP4MediaParserTest : public testing::Test { } protected: - typedef std::map > StreamMap; + typedef std::map> StreamMap; StreamMap stream_map_; std::unique_ptr parser_; size_t num_streams_; @@ -71,19 +71,17 @@ class MP4MediaParserTest : public testing::Test { return true; } - void InitF(const std::vector >& streams) { - for (std::vector >::const_iterator iter = - streams.begin(); - iter != streams.end(); - ++iter) { - DVLOG(2) << (*iter)->ToString(); - stream_map_[(*iter)->track_id()] = *iter; + void InitF(const std::vector>& streams) { + for (const auto& stream_info : streams) { + DVLOG(2) << stream_info->ToString(); + stream_map_[stream_info->track_id()] = stream_info; } num_streams_ = streams.size(); num_samples_ = 0; } - bool NewSampleF(uint32_t track_id, const scoped_refptr& sample) { + bool NewSampleF(uint32_t track_id, + const std::shared_ptr& sample) { DVLOG(2) << "Track Id: " << track_id << " " << sample->ToString(); ++num_samples_; diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index 58fbbdb554..7d135bf844 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -168,7 +168,7 @@ Status MP4Muxer::Finalize() { } Status MP4Muxer::DoAddSample(const MediaStream* stream, - scoped_refptr sample) { + std::shared_ptr sample) { DCHECK(segmenter_); return segmenter_->AddSample(stream, sample); } diff --git a/packager/media/formats/mp4/mp4_muxer.h b/packager/media/formats/mp4/mp4_muxer.h index 9ef82aad02..4b2508aed0 100644 --- a/packager/media/formats/mp4/mp4_muxer.h +++ b/packager/media/formats/mp4/mp4_muxer.h @@ -38,7 +38,7 @@ class MP4Muxer : public Muxer { Status Initialize() override; Status Finalize() override; Status DoAddSample(const MediaStream* stream, - scoped_refptr sample) override; + std::shared_ptr sample) override; // Generate Audio/Video Track box. void InitializeTrak(const StreamInfo* info, Track* trak); diff --git a/packager/media/formats/mp4/segmenter.cc b/packager/media/formats/mp4/segmenter.cc index 977a45ffb5..7553c4690d 100644 --- a/packager/media/formats/mp4/segmenter.cc +++ b/packager/media/formats/mp4/segmenter.cc @@ -321,7 +321,7 @@ Status Segmenter::Finalize() { } Status Segmenter::AddSample(const MediaStream* stream, - scoped_refptr sample) { + std::shared_ptr sample) { // Find the fragmenter for this stream. DCHECK(stream); DCHECK(stream_map_.find(stream) != stream_map_.end()); diff --git a/packager/media/formats/mp4/segmenter.h b/packager/media/formats/mp4/segmenter.h index e3d57ba9d8..aa3274a63c 100644 --- a/packager/media/formats/mp4/segmenter.h +++ b/packager/media/formats/mp4/segmenter.h @@ -11,7 +11,6 @@ #include #include -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/fourccs.h" #include "packager/media/base/status.h" #include "packager/media/formats/mp4/box_definitions.h" @@ -91,7 +90,7 @@ class Segmenter { /// @param sample points to the sample to be added. /// @return OK on success, an error status otherwise. Status AddSample(const MediaStream* stream, - scoped_refptr sample); + std::shared_ptr sample); /// @return true if there is an initialization range, while setting @a offset /// and @a size; or false if initialization range does not apply. diff --git a/packager/media/formats/webm/encrypted_segmenter_unittest.cc b/packager/media/formats/webm/encrypted_segmenter_unittest.cc index b263f94d00..ac6a55ceaa 100644 --- a/packager/media/formats/webm/encrypted_segmenter_unittest.cc +++ b/packager/media/formats/webm/encrypted_segmenter_unittest.cc @@ -203,7 +203,7 @@ class EncrypedSegmenterTest : public SegmentTestBase { options, info_.get(), key_source_.get(), &segmenter_)); } - scoped_refptr info_; + std::shared_ptr info_; std::unique_ptr segmenter_; std::unique_ptr key_source_; }; @@ -217,7 +217,7 @@ TEST_F(EncrypedSegmenterTest, BasicSupport) { // There should be 2 segments with the first segment in clear and the second // segment encrypted. for (int i = 0; i < 5; i++) { - scoped_refptr sample = + std::shared_ptr sample = CreateSample(kKeyFrame, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } diff --git a/packager/media/formats/webm/encryptor.cc b/packager/media/formats/webm/encryptor.cc index e090c3602e..fc146faec9 100644 --- a/packager/media/formats/webm/encryptor.cc +++ b/packager/media/formats/webm/encryptor.cc @@ -73,7 +73,7 @@ Status Encryptor::AddTrackInfo(mkvmuxer::Track* track) { return CreateContentEncryption(track, key_.get()); } -Status Encryptor::EncryptFrame(scoped_refptr sample, +Status Encryptor::EncryptFrame(std::shared_ptr sample, bool encrypt_frame) { DCHECK(encryptor_); diff --git a/packager/media/formats/webm/encryptor.h b/packager/media/formats/webm/encryptor.h index 29511cdd75..5c873e2915 100644 --- a/packager/media/formats/webm/encryptor.h +++ b/packager/media/formats/webm/encryptor.h @@ -9,7 +9,6 @@ #include #include "packager/base/macros.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/key_source.h" #include "packager/media/base/status.h" #include "packager/media/base/stream_info.h" @@ -48,8 +47,7 @@ class Encryptor { /// Encrypt the data. This needs to be told whether the current frame will /// be encrypted (e.g. for a clear lead). /// @return OK on success, an error status otherwise. - Status EncryptFrame(scoped_refptr sample, - bool encrypt_frame); + Status EncryptFrame(std::shared_ptr sample, bool encrypt_frame); private: // Create the encryptor for the internal encryption key. diff --git a/packager/media/formats/webm/multi_segment_segmenter_unittest.cc b/packager/media/formats/webm/multi_segment_segmenter_unittest.cc index 30888b7516..9140e975b1 100644 --- a/packager/media/formats/webm/multi_segment_segmenter_unittest.cc +++ b/packager/media/formats/webm/multi_segment_segmenter_unittest.cc @@ -108,7 +108,7 @@ class MultiSegmentSegmenterTest : public SegmentTestBase { return GetSegmentName(segment_template_, 0, number, 0); } - scoped_refptr info_; + std::shared_ptr info_; std::string segment_template_; std::unique_ptr segmenter_; }; @@ -120,7 +120,7 @@ TEST_F(MultiSegmentSegmenterTest, BasicSupport) { // Write the samples to the Segmenter. for (int i = 0; i < 5; i++) { - scoped_refptr sample = + std::shared_ptr sample = CreateSample(kKeyFrame, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } @@ -142,7 +142,7 @@ TEST_F(MultiSegmentSegmenterTest, SplitsFilesOnSegmentDuration) { // Write the samples to the Segmenter. for (int i = 0; i < 8; i++) { - scoped_refptr sample = + std::shared_ptr sample = CreateSample(kKeyFrame, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } @@ -171,7 +171,7 @@ TEST_F(MultiSegmentSegmenterTest, RespectsSegmentSAPAlign) { // Write the samples to the Segmenter. for (int i = 0; i < 10; i++) { const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame; - scoped_refptr sample = + std::shared_ptr sample = CreateSample(key_frame_flag, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } @@ -198,7 +198,7 @@ TEST_F(MultiSegmentSegmenterTest, SplitsClustersOnFragmentDuration) { // Write the samples to the Segmenter. for (int i = 0; i < 8; i++) { - scoped_refptr sample = + std::shared_ptr sample = CreateSample(kKeyFrame, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } @@ -224,7 +224,7 @@ TEST_F(MultiSegmentSegmenterTest, RespectsFragmentSAPAlign) { // Write the samples to the Segmenter. for (int i = 0; i < 10; i++) { const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame; - scoped_refptr sample = + std::shared_ptr sample = CreateSample(key_frame_flag, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index 78a0ab9f25..ea376ff165 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -121,7 +121,7 @@ Status Segmenter::Finalize() { return DoFinalize(); } -Status Segmenter::AddSample(scoped_refptr sample) { +Status Segmenter::AddSample(std::shared_ptr sample) { if (sample_duration_ == 0) { first_timestamp_ = sample->pts(); sample_duration_ = sample->duration(); diff --git a/packager/media/formats/webm/segmenter.h b/packager/media/formats/webm/segmenter.h index aeea449eb5..9095a4760e 100644 --- a/packager/media/formats/webm/segmenter.h +++ b/packager/media/formats/webm/segmenter.h @@ -8,7 +8,6 @@ #define MEDIA_FORMATS_WEBM_SEGMENTER_H_ #include -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/status.h" #include "packager/media/formats/webm/encryptor.h" #include "packager/media/formats/webm/mkv_writer.h" @@ -75,7 +74,7 @@ class Segmenter { /// Add sample to the indicated stream. /// @param sample points to the sample to be added. /// @return OK on success, an error status otherwise. - Status AddSample(scoped_refptr sample); + Status AddSample(std::shared_ptr sample); /// @return true if there is an initialization range, while setting @a start /// and @a end; or false if initialization range does not apply. @@ -140,7 +139,7 @@ class Segmenter { virtual Status NewSegment(uint64_t start_timescale) = 0; // Store the previous sample so we know which one is the last frame. - scoped_refptr prev_sample_; + std::shared_ptr prev_sample_; // The reference frame timestamp; used to populate the ReferenceBlock element // when writing non-keyframe BlockGroups. uint64_t reference_frame_timestamp_; diff --git a/packager/media/formats/webm/segmenter_test_base.cc b/packager/media/formats/webm/segmenter_test_base.cc index c8573ada70..a1deed791a 100644 --- a/packager/media/formats/webm/segmenter_test_base.cc +++ b/packager/media/formats/webm/segmenter_test_base.cc @@ -49,11 +49,11 @@ void SegmentTestBase::TearDown() { MemoryFile::DeleteAll(); } -scoped_refptr SegmentTestBase::CreateSample( +std::shared_ptr SegmentTestBase::CreateSample( KeyFrameFlag key_frame_flag, uint64_t duration, SideDataFlag side_data_flag) { - scoped_refptr sample; + std::shared_ptr sample; const bool is_key_frame = key_frame_flag == kKeyFrame; if (side_data_flag == kGenerateSideData) { sample = MediaSample::CopyFrom( diff --git a/packager/media/formats/webm/segmenter_test_base.h b/packager/media/formats/webm/segmenter_test_base.h index 1113f9d253..8df148cbc1 100644 --- a/packager/media/formats/webm/segmenter_test_base.h +++ b/packager/media/formats/webm/segmenter_test_base.h @@ -62,9 +62,9 @@ class SegmentTestBase : public ::testing::Test { } /// Creates a new media sample. - scoped_refptr CreateSample(KeyFrameFlag key_frame_flag, - uint64_t duration, - SideDataFlag side_data_flag); + std::shared_ptr CreateSample(KeyFrameFlag key_frame_flag, + uint64_t duration, + SideDataFlag side_data_flag); /// Creates a Muxer options object for testing. MuxerOptions CreateMuxerOptions() const; /// Creates a video stream info object for testing. diff --git a/packager/media/formats/webm/single_segment_segmenter_unittest.cc b/packager/media/formats/webm/single_segment_segmenter_unittest.cc index 5756fada19..6d5bf2d5fb 100644 --- a/packager/media/formats/webm/single_segment_segmenter_unittest.cc +++ b/packager/media/formats/webm/single_segment_segmenter_unittest.cc @@ -143,7 +143,7 @@ class SingleSegmentSegmenterTest : public SegmentTestBase { options, info_.get(), NULL, &segmenter_)); } - scoped_refptr info_; + std::shared_ptr info_; std::unique_ptr segmenter_; }; @@ -155,7 +155,7 @@ TEST_F(SingleSegmentSegmenterTest, BasicSupport) { for (int i = 0; i < 5; i++) { const SideDataFlag side_data_flag = i == 3 ? kGenerateSideData : kNoSideData; - scoped_refptr sample = + std::shared_ptr sample = CreateSample(kKeyFrame, kDuration, side_data_flag); ASSERT_OK(segmenter_->AddSample(sample)); } @@ -171,7 +171,7 @@ TEST_F(SingleSegmentSegmenterTest, SplitsClustersOnSegmentDuration) { // Write the samples to the Segmenter. for (int i = 0; i < 8; i++) { - scoped_refptr sample = + std::shared_ptr sample = CreateSample(kKeyFrame, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } @@ -192,7 +192,7 @@ TEST_F(SingleSegmentSegmenterTest, IgnoresFragmentDuration) { // Write the samples to the Segmenter. for (int i = 0; i < 8; i++) { - scoped_refptr sample = + std::shared_ptr sample = CreateSample(kKeyFrame, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } @@ -214,7 +214,7 @@ TEST_F(SingleSegmentSegmenterTest, RespectsSAPAlign) { // Write the samples to the Segmenter. for (int i = 0; i < 10; i++) { const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame; - scoped_refptr sample = + std::shared_ptr sample = CreateSample(key_frame_flag, kDuration, kNoSideData); ASSERT_OK(segmenter_->AddSample(sample)); } diff --git a/packager/media/formats/webm/webm_audio_client.cc b/packager/media/formats/webm/webm_audio_client.cc index bce44299f8..0917cfca12 100644 --- a/packager/media/formats/webm/webm_audio_client.cc +++ b/packager/media/formats/webm/webm_audio_client.cc @@ -28,7 +28,7 @@ void WebMAudioClient::Reset() { output_samples_per_second_ = -1; } -scoped_refptr WebMAudioClient::GetAudioStreamInfo( +std::shared_ptr WebMAudioClient::GetAudioStreamInfo( int64_t track_num, const std::string& codec_id, const std::vector& codec_private, @@ -43,11 +43,11 @@ scoped_refptr WebMAudioClient::GetAudioStreamInfo( audio_codec = kCodecOpus; } else { LOG(ERROR) << "Unsupported audio codec_id " << codec_id; - return scoped_refptr(); + return std::shared_ptr(); } if (samples_per_second_ <= 0) - return scoped_refptr(); + return std::shared_ptr(); // Set channel layout default if a Channels element was not present. if (channels_ == -1) @@ -68,12 +68,12 @@ scoped_refptr WebMAudioClient::GetAudioStreamInfo( } const uint8_t kSampleSizeInBits = 16u; - return scoped_refptr(new AudioStreamInfo( + return std::make_shared( track_num, kWebMTimeScale, 0, audio_codec, AudioStreamInfo::GetCodecString(audio_codec, 0), codec_config, codec_config_size, kSampleSizeInBits, channels_, sampling_frequency, seek_preroll < 0 ? 0 : seek_preroll, codec_delay < 0 ? 0 : codec_delay, 0, - 0, language, is_encrypted)); + 0, language, is_encrypted); } bool WebMAudioClient::OnUInt(int id, int64_t val) { diff --git a/packager/media/formats/webm/webm_audio_client.h b/packager/media/formats/webm/webm_audio_client.h index 2f255aab10..9b94f6df6c 100644 --- a/packager/media/formats/webm/webm_audio_client.h +++ b/packager/media/formats/webm/webm_audio_client.h @@ -37,10 +37,10 @@ class WebMAudioClient : public WebMParserClient { /// value of 0 is used. /// @param language indicates the language for the track. /// @param is_encrypted indicates whether the stream is encrypted. - /// @return An AudioStreamInfo scoped_refptr if successful. - /// @return An empty scoped_refptr if there was unexpected values in the + /// @return An AudioStreamInfo if successful. + /// @return An empty pointer if there was unexpected values in the /// provided parameters or audio track element fields. - scoped_refptr GetAudioStreamInfo( + std::shared_ptr GetAudioStreamInfo( int64_t track_num, const std::string& codec_id, const std::vector& codec_private, diff --git a/packager/media/formats/webm/webm_cluster_parser.cc b/packager/media/formats/webm/webm_cluster_parser.cc index 7df945abd2..49b00dd725 100644 --- a/packager/media/formats/webm/webm_cluster_parser.cc +++ b/packager/media/formats/webm/webm_cluster_parser.cc @@ -28,8 +28,8 @@ const int64_t kMicrosecondsPerMillisecond = 1000; WebMClusterParser::WebMClusterParser( int64_t timecode_scale, - scoped_refptr audio_stream_info, - scoped_refptr video_stream_info, + std::shared_ptr audio_stream_info, + std::shared_ptr video_stream_info, int64_t audio_default_duration, int64_t video_default_duration, const WebMTracksParser::TextTracks& text_tracks, @@ -352,7 +352,7 @@ bool WebMClusterParser::OnBlock(bool is_simple_block, int64_t timestamp = (cluster_timecode_ + timecode) * timecode_multiplier_; - scoped_refptr buffer; + std::shared_ptr buffer; if (stream_type != kStreamText) { // Every encrypted Block has a signal byte and IV prepended to it. Current // encrypted WebM request for comments specification is here @@ -407,7 +407,7 @@ bool WebMClusterParser::OnBlock(bool is_simple_block, : kNoTimestamp); if (!init_cb_.is_null() && !initialized_) { - std::vector> streams; + std::vector> streams; if (audio_stream_info_) streams.push_back(audio_stream_info_); if (video_stream_info_) { @@ -474,7 +474,7 @@ WebMClusterParser::Track::Track(int track_num, WebMClusterParser::Track::~Track() {} bool WebMClusterParser::Track::EmitBuffer( - const scoped_refptr& buffer) { + const std::shared_ptr& buffer) { DVLOG(2) << "EmitBuffer() : " << track_num_ << " ts " << buffer->pts() << " dur " << buffer->duration() @@ -493,7 +493,7 @@ bool WebMClusterParser::Track::EmitBuffer( << last_added_buffer_missing_duration_->duration() << " kf " << last_added_buffer_missing_duration_->is_key_frame() << " size " << last_added_buffer_missing_duration_->data_size(); - scoped_refptr updated_buffer = + std::shared_ptr updated_buffer = last_added_buffer_missing_duration_; last_added_buffer_missing_duration_ = NULL; if (!EmitBufferHelp(updated_buffer)) @@ -540,7 +540,7 @@ void WebMClusterParser::Track::Reset() { } bool WebMClusterParser::Track::EmitBufferHelp( - const scoped_refptr& buffer) { + const std::shared_ptr& buffer) { DCHECK(!last_added_buffer_missing_duration_.get()); int64_t duration = buffer->duration(); diff --git a/packager/media/formats/webm/webm_cluster_parser.h b/packager/media/formats/webm/webm_cluster_parser.h index 20e294ddad..5a1a09229d 100644 --- a/packager/media/formats/webm/webm_cluster_parser.h +++ b/packager/media/formats/webm/webm_cluster_parser.h @@ -50,7 +50,7 @@ class WebMClusterParser : public WebMParserClient { // relative to |buffer|'s timestamp, and emits it and unsets // |last_added_buffer_missing_duration_|. Otherwise, if |buffer| is missing // duration, saves |buffer| into |last_added_buffer_missing_duration_|. - bool EmitBuffer(const scoped_refptr& buffer); + bool EmitBuffer(const std::shared_ptr& buffer); // If |last_added_buffer_missing_duration_| is set, estimate the duration // for this buffer using helper function GetDurationEstimate() then emits it @@ -67,7 +67,7 @@ class WebMClusterParser : public WebMParserClient { // |estimated_next_frame_duration_|, and emits |buffer|. // Returns false if |buffer| failed sanity check and therefore was not // emitted. Returns true otherwise. - bool EmitBufferHelp(const scoped_refptr& buffer); + bool EmitBufferHelp(const std::shared_ptr& buffer); // Helper function that calculates the buffer duration to use in // ApplyDurationEstimateIfNeeded(). @@ -79,7 +79,7 @@ class WebMClusterParser : public WebMParserClient { // Holding the sample that is missing duration. The duration will be // computed from the difference in timestamp when next sample arrives; or // estimated if it is the last sample in this track. - scoped_refptr last_added_buffer_missing_duration_; + std::shared_ptr last_added_buffer_missing_duration_; // If kNoTimestamp, then |estimated_next_frame_duration_| will be used. int64_t default_duration_; @@ -118,8 +118,8 @@ class WebMClusterParser : public WebMParserClient { /// @param decryption_key_source points to a decryption key source to fetch /// decryption keys. Should not be NULL if the tracks are encrypted. WebMClusterParser(int64_t timecode_scale, - scoped_refptr audio_stream_info, - scoped_refptr video_stream_info, + std::shared_ptr audio_stream_info, + std::shared_ptr video_stream_info, int64_t audio_default_duration, int64_t video_default_duration, const WebMTracksParser::TextTracks& text_tracks, @@ -186,8 +186,8 @@ class WebMClusterParser : public WebMParserClient { // Multiplier used to convert timecodes into microseconds. double timecode_multiplier_; - scoped_refptr audio_stream_info_; - scoped_refptr video_stream_info_; + std::shared_ptr audio_stream_info_; + std::shared_ptr video_stream_info_; std::set ignored_tracks_; std::unique_ptr decryptor_source_; diff --git a/packager/media/formats/webm/webm_cluster_parser_unittest.cc b/packager/media/formats/webm/webm_cluster_parser_unittest.cc index c145dfb5b4..77ea0f1fdf 100644 --- a/packager/media/formats/webm/webm_cluster_parser_unittest.cc +++ b/packager/media/formats/webm/webm_cluster_parser_unittest.cc @@ -275,7 +275,7 @@ bool VerifyBuffersHelper(const BufferQueue& audio_buffers, return false; } - scoped_refptr buffer = (*buffers)[(*offset)++]; + std::shared_ptr buffer = (*buffers)[(*offset)++]; EXPECT_EQ(block_info[i].timestamp * kMicrosecondsPerMillisecond, buffer->pts()); @@ -306,7 +306,7 @@ bool VerifyTextBuffers(const BlockInfo* block_info_ptr, EXPECT_FALSE(block_info.use_simple_block); EXPECT_FALSE(buffer_iter == buffer_end); - const scoped_refptr buffer = *buffer_iter++; + const std::shared_ptr buffer = *buffer_iter++; EXPECT_EQ(block_info.timestamp * kMicrosecondsPerMillisecond, buffer->pts()); EXPECT_EQ(std::abs(block_info.duration) * kMicrosecondsPerMillisecond, @@ -349,12 +349,12 @@ class WebMClusterParserTest : public testing::Test { default_audio_duration, default_video_duration)); } - void InitEvent(const std::vector>& stream_info) { + void InitEvent(const std::vector>& stream_info) { streams_from_init_event_ = stream_info; } bool NewSampleEvent(uint32_t track_id, - const scoped_refptr& sample) { + const std::shared_ptr& sample) { switch (track_id) { case kAudioTrackNum: audio_buffers_.push_back(sample); @@ -448,10 +448,10 @@ class WebMClusterParserTest : public testing::Test { return result; } - scoped_refptr audio_stream_info_; - scoped_refptr video_stream_info_; + std::shared_ptr audio_stream_info_; + std::shared_ptr video_stream_info_; std::unique_ptr parser_; - std::vector> streams_from_init_event_; + std::vector> streams_from_init_event_; BufferQueue audio_buffers_; BufferQueue video_buffers_; TextBufferQueueMap text_buffers_map_; @@ -837,7 +837,7 @@ TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { EXPECT_EQ(cluster->size(), result); EXPECT_TRUE(parser_->Flush()); ASSERT_EQ(1UL, video_buffers_.size()); - scoped_refptr buffer = video_buffers_[0]; + std::shared_ptr buffer = video_buffers_[0]; EXPECT_EQ(std::vector( kExpectedDecryptedFrame, kExpectedDecryptedFrame + arraysize(kExpectedDecryptedFrame)), @@ -879,7 +879,7 @@ TEST_F(WebMClusterParserTest, ParseClearFrameInEncryptedTrack) { EXPECT_EQ(cluster->size(), result); EXPECT_TRUE(parser_->Flush()); ASSERT_EQ(1UL, video_buffers_.size()); - scoped_refptr buffer = video_buffers_[0]; + std::shared_ptr buffer = video_buffers_[0]; EXPECT_EQ(std::vector( kExpectedClearFrame, kExpectedClearFrame + arraysize(kExpectedClearFrame)), diff --git a/packager/media/formats/webm/webm_media_parser.cc b/packager/media/formats/webm/webm_media_parser.cc index 967cd74f89..7d08f8e4fd 100644 --- a/packager/media/formats/webm/webm_media_parser.cc +++ b/packager/media/formats/webm/webm_media_parser.cc @@ -184,7 +184,7 @@ int WebMMediaParser::ParseInfoAndTracks(const uint8_t* data, int size) { double timecode_scale_in_us = info_parser.timecode_scale() / 1000.0; int64_t duration_in_us = info_parser.duration() * timecode_scale_in_us; - scoped_refptr audio_stream_info = + std::shared_ptr audio_stream_info = tracks_parser.audio_stream_info(); if (audio_stream_info) { audio_stream_info->set_duration(duration_in_us); @@ -192,7 +192,7 @@ int WebMMediaParser::ParseInfoAndTracks(const uint8_t* data, int size) { VLOG(1) << "No audio track info found."; } - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = tracks_parser.video_stream_info(); if (video_stream_info) { video_stream_info->set_duration(duration_in_us); diff --git a/packager/media/formats/webm/webm_media_parser.h b/packager/media/formats/webm/webm_media_parser.h index b4bd3ab61e..e5031be8ac 100644 --- a/packager/media/formats/webm/webm_media_parser.h +++ b/packager/media/formats/webm/webm_media_parser.h @@ -7,7 +7,6 @@ #include "packager/base/callback_forward.h" #include "packager/base/compiler_specific.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/byte_queue.h" #include "packager/media/base/media_parser.h" diff --git a/packager/media/formats/webm/webm_muxer.cc b/packager/media/formats/webm/webm_muxer.cc index d32259cbf7..0191121c24 100644 --- a/packager/media/formats/webm/webm_muxer.cc +++ b/packager/media/formats/webm/webm_muxer.cc @@ -74,7 +74,7 @@ Status WebMMuxer::Finalize() { } Status WebMMuxer::DoAddSample(const MediaStream* stream, - scoped_refptr sample) { + std::shared_ptr sample) { DCHECK(segmenter_); DCHECK(stream == streams()[0]); return segmenter_->AddSample(sample); diff --git a/packager/media/formats/webm/webm_muxer.h b/packager/media/formats/webm/webm_muxer.h index 828e4de335..5d869949b8 100644 --- a/packager/media/formats/webm/webm_muxer.h +++ b/packager/media/formats/webm/webm_muxer.h @@ -27,7 +27,7 @@ class WebMMuxer : public Muxer { Status Initialize() override; Status Finalize() override; Status DoAddSample(const MediaStream* stream, - scoped_refptr sample) override; + std::shared_ptr sample) override; void FireOnMediaStartEvent(); void FireOnMediaEndEvent(); diff --git a/packager/media/formats/webm/webm_tracks_parser.h b/packager/media/formats/webm/webm_tracks_parser.h index ca4c40a5c1..ecd001d113 100644 --- a/packager/media/formats/webm/webm_tracks_parser.h +++ b/packager/media/formats/webm/webm_tracks_parser.h @@ -51,7 +51,7 @@ class WebMTracksParser : public WebMParserClient { return audio_encryption_key_id_; } - scoped_refptr audio_stream_info() { + std::shared_ptr audio_stream_info() { return audio_stream_info_; } @@ -59,7 +59,7 @@ class WebMTracksParser : public WebMParserClient { return video_encryption_key_id_; } - scoped_refptr video_stream_info() { + std::shared_ptr video_stream_info() { return video_stream_info_; } @@ -100,10 +100,10 @@ class WebMTracksParser : public WebMParserClient { std::string video_encryption_key_id_; WebMAudioClient audio_client_; - scoped_refptr audio_stream_info_; + std::shared_ptr audio_stream_info_; WebMVideoClient video_client_; - scoped_refptr video_stream_info_; + std::shared_ptr video_stream_info_; DISALLOW_COPY_AND_ASSIGN(WebMTracksParser); }; diff --git a/packager/media/formats/webm/webm_tracks_parser_unittest.cc b/packager/media/formats/webm/webm_tracks_parser_unittest.cc index b9b873a9b4..36dd2db57e 100644 --- a/packager/media/formats/webm/webm_tracks_parser_unittest.cc +++ b/packager/media/formats/webm/webm_tracks_parser_unittest.cc @@ -144,13 +144,13 @@ TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationUnset) { EXPECT_EQ(kNoTimestamp, parser->GetVideoDefaultDuration(kDefaultTimecodeScaleInUs)); - scoped_refptr video_stream_info = + std::shared_ptr video_stream_info = parser->video_stream_info(); EXPECT_TRUE(video_stream_info); EXPECT_EQ(320u, video_stream_info->width()); EXPECT_EQ(240u, video_stream_info->height()); - scoped_refptr audio_stream_info = + std::shared_ptr audio_stream_info = parser->audio_stream_info(); EXPECT_TRUE(audio_stream_info); EXPECT_EQ(2u, audio_stream_info->num_channels()); diff --git a/packager/media/formats/webm/webm_video_client.cc b/packager/media/formats/webm/webm_video_client.cc index 9e2f9fd06d..b941e89b66 100644 --- a/packager/media/formats/webm/webm_video_client.cc +++ b/packager/media/formats/webm/webm_video_client.cc @@ -47,7 +47,7 @@ void WebMVideoClient::Reset() { alpha_mode_ = -1; } -scoped_refptr WebMVideoClient::GetVideoStreamInfo( +std::shared_ptr WebMVideoClient::GetVideoStreamInfo( int64_t track_num, const std::string& codec_id, const std::vector& codec_private, @@ -64,11 +64,11 @@ scoped_refptr WebMVideoClient::GetVideoStreamInfo( video_codec = kCodecVP10; } else { LOG(ERROR) << "Unsupported video codec_id " << codec_id; - return scoped_refptr(); + return std::shared_ptr(); } if (pixel_width_ <= 0 || pixel_height_ <= 0) - return scoped_refptr(); + return std::shared_ptr(); // Set crop and display unit defaults if these elements are not present. if (crop_bottom_ == -1) @@ -96,10 +96,10 @@ scoped_refptr WebMVideoClient::GetVideoStreamInfo( display_height_ = height_after_crop; } else if (display_unit_ == 3) { if (display_width_ <= 0 || display_height_ <= 0) - return scoped_refptr(); + return std::shared_ptr(); } else { LOG(ERROR) << "Unsupported display unit type " << display_unit_; - return scoped_refptr(); + return std::shared_ptr(); } // Calculate sample aspect ratio. int64_t sar_x = display_width_ * height_after_crop; @@ -108,10 +108,10 @@ scoped_refptr WebMVideoClient::GetVideoStreamInfo( sar_x /= gcd; sar_y /= gcd; - return scoped_refptr(new VideoStreamInfo( + return std::make_shared( track_num, kWebMTimeScale, 0, video_codec, std::string(), codec_private.data(), codec_private.size(), width_after_crop, - height_after_crop, sar_x, sar_y, 0, 0, std::string(), is_encrypted)); + height_after_crop, sar_x, sar_y, 0, 0, std::string(), is_encrypted); } bool WebMVideoClient::OnUInt(int id, int64_t val) { diff --git a/packager/media/formats/webm/webm_video_client.h b/packager/media/formats/webm/webm_video_client.h index 26f085745f..6b43d6fc10 100644 --- a/packager/media/formats/webm/webm_video_client.h +++ b/packager/media/formats/webm/webm_video_client.h @@ -28,10 +28,10 @@ class WebMVideoClient : public WebMParserClient { /// Create a VideoStreamInfo with the data in |track_num|, |codec_id|, /// |codec_private|, |is_encrypted| and the fields parsed from the last video /// track element this object was used to parse. - /// @return A VideoStreamInfo scoped_refptr if successful. - /// @return An empty scoped_refptr if there was unexpected values in the + /// @return A VideoStreamInfo if successful. + /// @return An empty pointer if there was unexpected values in the /// provided parameters or video track element fields. - scoped_refptr GetVideoStreamInfo( + std::shared_ptr GetVideoStreamInfo( int64_t track_num, const std::string& codec_id, const std::vector& codec_private, diff --git a/packager/media/formats/webvtt/webvtt_media_parser.cc b/packager/media/formats/webvtt/webvtt_media_parser.cc index dad0688177..ed5c36fd40 100644 --- a/packager/media/formats/webvtt/webvtt_media_parser.cc +++ b/packager/media/formats/webvtt/webvtt_media_parser.cc @@ -188,7 +188,7 @@ bool ParseTimingAndSettingsLine(const std::string& line, // comment --> side data (and side data only sample) // settings --> side data // start_time --> pts -scoped_refptr CueToMediaSample(const Cue& cue) { +std::shared_ptr CueToMediaSample(const Cue& cue) { const bool kKeyFrame = true; if (!cue.comment.empty()) { const std::string comment = base::JoinString(cue.comment, "\n"); @@ -197,12 +197,10 @@ scoped_refptr CueToMediaSample(const Cue& cue) { } const std::string payload = base::JoinString(cue.payload, "\n"); - scoped_refptr media_sample = MediaSample::CopyFrom( - reinterpret_cast(payload.data()), - payload.size(), + std::shared_ptr media_sample = MediaSample::CopyFrom( + reinterpret_cast(payload.data()), payload.size(), reinterpret_cast(cue.settings.data()), - cue.settings.size(), - !kKeyFrame); + cue.settings.size(), !kKeyFrame); media_sample->set_config_id(cue.identifier); media_sample->set_pts(cue.start_time); @@ -282,7 +280,7 @@ bool WebVttMediaParser::Parse(const uint8_t* buf, int size) { break; case kMetadata: { if (line.empty()) { - std::vector > streams; + std::vector> streams; // The resolution of timings are in milliseconds. const int kTimescale = 1000; @@ -294,12 +292,12 @@ bool WebVttMediaParser::Parse(const uint8_t* buf, int size) { // There is no one metadata to determine what the language is. Parts // of the text may be annotated as some specific language. const char kLanguage[] = ""; - streams.push_back(new TextStreamInfo(kTrackId, kTimescale, kDuration, - "wvtt", - base::JoinString(header_, "\n"), - 0, // Not necessary. - 0, - kLanguage)); // Not necessary. + streams.emplace_back( + new TextStreamInfo(kTrackId, kTimescale, kDuration, "wvtt", + base::JoinString(header_, "\n"), + 0, // Not necessary. + 0, + kLanguage)); // Not necessary. init_cb_.Run(streams); state_ = kCueIdentifierOrTimingOrComment; diff --git a/packager/media/formats/webvtt/webvtt_media_parser_unittest.cc b/packager/media/formats/webvtt/webvtt_media_parser_unittest.cc index 4bfdc251d5..3734f6b81b 100644 --- a/packager/media/formats/webvtt/webvtt_media_parser_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_media_parser_unittest.cc @@ -15,11 +15,12 @@ namespace shaka { namespace media { -typedef testing::MockFunction>& - stream_info)> MockInitCallback; -typedef testing::MockFunction& media_sample)> MockNewSampleCallback; +typedef testing::MockFunction>& stream_info)> + MockInitCallback; +typedef testing::MockFunction< + bool(uint32_t track_id, const std::shared_ptr& media_sample)> + MockNewSampleCallback; using testing::_; using testing::InSequence; diff --git a/packager/media/formats/wvm/wvm_media_parser.cc b/packager/media/formats/wvm/wvm_media_parser.cc index 19206a87a3..5351338251 100644 --- a/packager/media/formats/wvm/wvm_media_parser.cc +++ b/packager/media/formats/wvm/wvm_media_parser.cc @@ -487,8 +487,9 @@ bool WvmMediaParser::Parse(const uint8_t* buf, int size) { return true; } -bool WvmMediaParser::EmitLastSample(uint32_t stream_id, - scoped_refptr& new_sample) { +bool WvmMediaParser::EmitLastSample( + uint32_t stream_id, + const std::shared_ptr& new_sample) { std::string key = base::UintToString(current_program_id_) .append(":") .append(base::UintToString(stream_id)); @@ -739,7 +740,7 @@ bool WvmMediaParser::ParseIndexEntry() { if (has_video) { Codec video_codec = kCodecH264; - stream_infos_.push_back(new VideoStreamInfo( + stream_infos_.emplace_back(new VideoStreamInfo( stream_id_count_, time_scale, track_duration, video_codec, std::string(), video_codec_config.data(), video_codec_config.size(), video_width, video_height, pixel_width, pixel_height, trick_play_rate, @@ -754,7 +755,7 @@ bool WvmMediaParser::ParseIndexEntry() { if (has_audio) { const Codec audio_codec = kCodecAAC; // TODO(beil): Pass in max and average bitrate in wvm container. - stream_infos_.push_back(new AudioStreamInfo( + stream_infos_.emplace_back(new AudioStreamInfo( stream_id_count_, time_scale, track_duration, audio_codec, std::string(), audio_codec_config.data(), audio_codec_config.size(), kAacSampleSizeBits, num_channels, sampling_frequency, @@ -994,7 +995,7 @@ bool WvmMediaParser::Output(bool output_encrypted_sample) { bool WvmMediaParser::EmitSample(uint32_t parsed_audio_or_video_stream_id, uint32_t stream_id, - scoped_refptr& new_sample, + const std::shared_ptr& new_sample, bool isLastSample) { DCHECK(new_sample); if (isLastSample) { diff --git a/packager/media/formats/wvm/wvm_media_parser.h b/packager/media/formats/wvm/wvm_media_parser.h index 68d76ff955..9884249d7e 100644 --- a/packager/media/formats/wvm/wvm_media_parser.h +++ b/packager/media/formats/wvm/wvm_media_parser.h @@ -32,7 +32,7 @@ struct DemuxStreamIdMediaSample { ~DemuxStreamIdMediaSample(); uint32_t demux_stream_id; uint32_t parsed_audio_or_video_stream_id; - scoped_refptr media_sample; + std::shared_ptr media_sample; }; struct PrevSampleData { @@ -40,8 +40,8 @@ struct PrevSampleData { PrevSampleData(); ~PrevSampleData(); void Reset(); - scoped_refptr audio_sample; - scoped_refptr video_sample; + std::shared_ptr audio_sample; + std::shared_ptr video_sample; uint32_t audio_stream_id; uint32_t video_stream_id; int64_t audio_sample_duration; @@ -206,13 +206,13 @@ class WvmMediaParser : public MediaParser { // to emit a new audio/video access unit. bool EmitSample(uint32_t parsed_audio_or_video_stream_id, uint32_t stream_id, - scoped_refptr& new_sample, + const std::shared_ptr& new_sample, bool isLastSample); bool EmitPendingSamples(); bool EmitLastSample(uint32_t stream_id, - scoped_refptr& new_sample); + const std::shared_ptr& new_sample); // List of callbacks.t InitCB init_cb_; @@ -237,17 +237,17 @@ class WvmMediaParser : public MediaParser { uint64_t pts_; uint64_t dts_; uint8_t index_program_id_; - scoped_refptr media_sample_; + std::shared_ptr media_sample_; size_t crypto_unit_start_pos_; PrevSampleData prev_media_sample_data_; H264ByteToUnitStreamConverter byte_to_unit_stream_converter_; - std::vector > ecm_; + std::vector> ecm_; std::vector psm_data_; std::vector index_data_; std::map program_demux_stream_map_; int stream_id_count_; - std::vector > stream_infos_; + std::vector> stream_infos_; std::deque media_sample_queue_; std::vector sample_data_; KeySource* decryption_key_source_; diff --git a/packager/media/formats/wvm/wvm_media_parser_unittest.cc b/packager/media/formats/wvm/wvm_media_parser_unittest.cc index 57d36c5947..e051304b0a 100644 --- a/packager/media/formats/wvm/wvm_media_parser_unittest.cc +++ b/packager/media/formats/wvm/wvm_media_parser_unittest.cc @@ -11,7 +11,6 @@ #include "packager/base/bind.h" #include "packager/base/bind_helpers.h" #include "packager/base/logging.h" -#include "packager/base/memory/ref_counted.h" #include "packager/media/base/audio_stream_info.h" #include "packager/media/base/fixed_key_source.h" #include "packager/media/base/media_sample.h" @@ -78,7 +77,7 @@ class WvmMediaParserTest : public testing::Test { } protected: - typedef std::map > StreamMap; + typedef std::map> StreamMap; std::unique_ptr parser_; std::unique_ptr key_source_; @@ -90,17 +89,16 @@ class WvmMediaParserTest : public testing::Test { int32_t current_track_id_; EncryptionKey encryption_key_; - void OnInit(const std::vector >& stream_infos) { + void OnInit(const std::vector>& stream_infos) { DVLOG(1) << "OnInit: " << stream_infos.size() << " streams."; - for (std::vector >::const_iterator iter = - stream_infos.begin(); iter != stream_infos.end(); ++iter) { - DVLOG(1) << (*iter)->ToString(); - stream_map_[(*iter)->track_id()] = *iter; + for (const auto& stream_info : stream_infos) { + DVLOG(1) << stream_info->ToString(); + stream_map_[stream_info->track_id()] = stream_info; } } bool OnNewSample(uint32_t track_id, - const scoped_refptr& sample) { + const std::shared_ptr& sample) { std::string stream_type; if (static_cast(track_id) != current_track_id_) { // onto next track.