Replace scoped_refptr with std::shared_ptr

Change-Id: Ie8ea66e78c42c7387a97bb1abc331c636be11aa4
This commit is contained in:
Kongqun Yang 2017-01-23 16:55:02 -08:00 committed by KongQun Yang
parent 24b0e3031a
commit 97fbaaa567
85 changed files with 378 additions and 424 deletions

View File

@ -27,6 +27,8 @@ class AudioStreamInfo : public StreamInfo {
uint32_t avg_bitrate, const std::string& language, uint32_t avg_bitrate, const std::string& language,
bool is_encrypted); bool is_encrypted);
~AudioStreamInfo() override;
/// @name StreamInfo implementation overrides. /// @name StreamInfo implementation overrides.
/// @{ /// @{
bool IsValidConfig() const override; bool IsValidConfig() const override;
@ -54,8 +56,6 @@ class AudioStreamInfo : public StreamInfo {
static std::string GetCodecString(Codec codec, uint8_t audio_object_type); static std::string GetCodecString(Codec codec, uint8_t audio_object_type);
private: private:
~AudioStreamInfo() override;
uint8_t sample_bits_; uint8_t sample_bits_;
uint8_t num_channels_; uint8_t num_channels_;
uint32_t sampling_frequency_; uint32_t sampling_frequency_;

View File

@ -119,19 +119,19 @@ Status Demuxer::Initialize() {
} }
void Demuxer::ParserInitEvent( void Demuxer::ParserInitEvent(
const std::vector<scoped_refptr<StreamInfo>>& stream_infos) { const std::vector<std::shared_ptr<StreamInfo>>& stream_infos) {
init_event_received_ = true; init_event_received_ = true;
for (const scoped_refptr<StreamInfo>& stream_info : stream_infos) for (const std::shared_ptr<StreamInfo>& stream_info : stream_infos)
streams_.emplace_back(new MediaStream(stream_info, this)); streams_.emplace_back(new MediaStream(stream_info, this));
} }
Demuxer::QueuedSample::QueuedSample(uint32_t local_track_id, Demuxer::QueuedSample::QueuedSample(uint32_t local_track_id,
scoped_refptr<MediaSample> local_sample) std::shared_ptr<MediaSample> local_sample)
: track_id(local_track_id), sample(local_sample) {} : track_id(local_track_id), sample(local_sample) {}
Demuxer::QueuedSample::~QueuedSample() {} Demuxer::QueuedSample::~QueuedSample() {}
bool Demuxer::NewSampleEvent(uint32_t track_id, bool Demuxer::NewSampleEvent(uint32_t track_id,
const scoped_refptr<MediaSample>& sample) { const std::shared_ptr<MediaSample>& sample) {
if (!init_event_received_) { if (!init_event_received_) {
if (queued_samples_.size() >= kQueuedSamplesLimit) { if (queued_samples_.size() >= kQueuedSamplesLimit) {
LOG(ERROR) << "Queued samples limit reached: " << 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, bool Demuxer::PushSample(uint32_t track_id,
const scoped_refptr<MediaSample>& sample) { const std::shared_ptr<MediaSample>& sample) {
for (const std::unique_ptr<MediaStream>& stream : streams_) { for (const std::unique_ptr<MediaStream>& stream : streams_) {
if (track_id == stream->info()->track_id()) { if (track_id == stream->info()->track_id()) {
Status status = stream->PushSample(sample); Status status = stream->PushSample(sample);
@ -184,7 +184,7 @@ Status Demuxer::Run() {
if (status.error_code() == error::END_OF_STREAM) { if (status.error_code() == error::END_OF_STREAM) {
// Push EOS sample to muxer to indicate end of stream. // Push EOS sample to muxer to indicate end of stream.
const scoped_refptr<MediaSample>& sample = MediaSample::CreateEOSBuffer(); const std::shared_ptr<MediaSample>& sample = MediaSample::CreateEOSBuffer();
for (const std::unique_ptr<MediaStream>& stream : streams_) { for (const std::unique_ptr<MediaStream>& stream : streams_) {
status = stream->PushSample(sample); status = stream->PushSample(sample);
if (!status.ok()) if (!status.ok())

View File

@ -12,7 +12,6 @@
#include <vector> #include <vector>
#include "packager/base/compiler_specific.h" #include "packager/base/compiler_specific.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/container_names.h" #include "packager/media/base/container_names.h"
#include "packager/media/base/status.h" #include "packager/media/base/status.h"
@ -74,23 +73,27 @@ class Demuxer {
MediaContainerName container_name() { return container_name_; } MediaContainerName container_name() { return container_name_; }
private: private:
Demuxer(const Demuxer&) = delete;
Demuxer& operator=(const Demuxer&) = delete;
struct QueuedSample { struct QueuedSample {
QueuedSample(uint32_t track_id, scoped_refptr<MediaSample> sample); QueuedSample(uint32_t track_id, std::shared_ptr<MediaSample> sample);
~QueuedSample(); ~QueuedSample();
uint32_t track_id; uint32_t track_id;
scoped_refptr<MediaSample> sample; std::shared_ptr<MediaSample> sample;
}; };
// Parser init event. // Parser init event.
void ParserInitEvent(const std::vector<scoped_refptr<StreamInfo> >& streams); void ParserInitEvent(const std::vector<std::shared_ptr<StreamInfo>>& streams);
// Parser new sample event handler. Queues the samples if init event has not // Parser new sample event handler. Queues the samples if init event has not
// been received, otherwise calls PushSample() to push the sample to // been received, otherwise calls PushSample() to push the sample to
// corresponding stream. // corresponding stream.
bool NewSampleEvent(uint32_t track_id, bool NewSampleEvent(uint32_t track_id,
const scoped_refptr<MediaSample>& sample); const std::shared_ptr<MediaSample>& sample);
// Helper function to push the sample to corresponding stream. // Helper function to push the sample to corresponding stream.
bool PushSample(uint32_t track_id, const scoped_refptr<MediaSample>& sample); bool PushSample(uint32_t track_id,
const std::shared_ptr<MediaSample>& sample);
std::string file_name_; std::string file_name_;
File* media_file_; File* media_file_;
@ -104,8 +107,6 @@ class Demuxer {
std::unique_ptr<uint8_t[]> buffer_; std::unique_ptr<uint8_t[]> buffer_;
std::unique_ptr<KeySource> key_source_; std::unique_ptr<KeySource> key_source_;
bool cancelled_; bool cancelled_;
DISALLOW_COPY_AND_ASSIGN(Demuxer);
}; };
} // namespace media } // namespace media

View File

@ -12,7 +12,6 @@
#include <vector> #include <vector>
#include "packager/base/callback.h" #include "packager/base/callback.h"
#include "packager/base/compiler_specific.h" #include "packager/base/compiler_specific.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/container_names.h" #include "packager/media/base/container_names.h"
namespace shaka { namespace shaka {
@ -30,8 +29,9 @@ class MediaParser {
/// Called upon completion of parser initialization. /// Called upon completion of parser initialization.
/// @param stream_info contains the stream info of all the elementary streams /// @param stream_info contains the stream info of all the elementary streams
/// within this file. /// within this file.
typedef base::Callback< typedef base::Callback<void(
void(const std::vector<scoped_refptr<StreamInfo> >& stream_info)> InitCB; const std::vector<std::shared_ptr<StreamInfo> >& stream_info)>
InitCB;
/// Called when a new media sample has been parsed. /// Called when a new media sample has been parsed.
/// @param track_id is the track id of the new sample. /// @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 /// @return true if the sample is accepted, false if something was wrong
/// with the sample and a parsing error should be signaled. /// with the sample and a parsing error should be signaled.
typedef base::Callback<bool(uint32_t track_id, typedef base::Callback<bool(uint32_t track_id,
const scoped_refptr<MediaSample>& media_sample)> const std::shared_ptr<MediaSample>& media_sample)>
NewSampleCB; NewSampleCB;
/// Initialize the parser with necessary callbacks. Must be called before any /// Initialize the parser with necessary callbacks. Must be called before any

View File

@ -42,43 +42,42 @@ MediaSample::MediaSample() : dts_(0),
MediaSample::~MediaSample() {} MediaSample::~MediaSample() {}
// static // static
scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data, std::shared_ptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data,
size_t data_size, size_t data_size,
bool is_key_frame) { bool is_key_frame) {
// If you hit this CHECK you likely have a bug in a demuxer. Go fix it. // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
CHECK(data); CHECK(data);
return make_scoped_refptr( return std::make_shared<MediaSample>(data, data_size, nullptr, 0u,
new MediaSample(data, data_size, NULL, 0u, is_key_frame)); is_key_frame);
} }
// static // static
scoped_refptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data, std::shared_ptr<MediaSample> MediaSample::CopyFrom(const uint8_t* data,
size_t data_size, size_t data_size,
const uint8_t* side_data, const uint8_t* side_data,
size_t side_data_size, size_t side_data_size,
bool is_key_frame) { bool is_key_frame) {
// If you hit this CHECK you likely have a bug in a demuxer. Go fix it. // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
CHECK(data); CHECK(data);
return make_scoped_refptr(new MediaSample( return std::make_shared<MediaSample>(data, data_size, side_data,
data, data_size, side_data, side_data_size, is_key_frame)); side_data_size, is_key_frame);
} }
// static // static
scoped_refptr<MediaSample> MediaSample::FromMetadata(const uint8_t* metadata, std::shared_ptr<MediaSample> MediaSample::FromMetadata(const uint8_t* metadata,
size_t metadata_size) { size_t metadata_size) {
return make_scoped_refptr( return std::make_shared<MediaSample>(nullptr, 0, metadata, metadata_size,
new MediaSample(nullptr, 0, metadata, metadata_size, false)); false);
} }
// static // static
scoped_refptr<MediaSample> MediaSample::CreateEmptyMediaSample() { std::shared_ptr<MediaSample> MediaSample::CreateEmptyMediaSample() {
MediaSample* media_sample = new MediaSample(); return std::make_shared<MediaSample>();
return make_scoped_refptr(media_sample);
} }
// static // static
scoped_refptr<MediaSample> MediaSample::CreateEOSBuffer() { std::shared_ptr<MediaSample> MediaSample::CreateEOSBuffer() {
return make_scoped_refptr(new MediaSample(NULL, 0, NULL, 0, false)); return std::make_shared<MediaSample>(nullptr, 0, nullptr, 0, false);
} }
std::string MediaSample::ToString() const { std::string MediaSample::ToString() const {

View File

@ -8,27 +8,27 @@
#define MEDIA_BASE_MEDIA_SAMPLE_H_ #define MEDIA_BASE_MEDIA_SAMPLE_H_
#include <deque> #include <deque>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "packager/base/logging.h" #include "packager/base/logging.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/decrypt_config.h" #include "packager/media/base/decrypt_config.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
/// Class to hold a media sample. /// Class to hold a media sample.
class MediaSample : public base::RefCountedThreadSafe<MediaSample> { class MediaSample {
public: public:
/// Create a MediaSample object from input. /// Create a MediaSample object from input.
/// @param data points to the buffer containing the sample data. /// @param data points to the buffer containing the sample data.
/// Must not be NULL. /// Must not be NULL.
/// @param size indicates sample size in bytes. Must not be negative. /// @param size indicates sample size in bytes. Must not be negative.
/// @param is_key_frame indicates whether the sample is a key frame. /// @param is_key_frame indicates whether the sample is a key frame.
static scoped_refptr<MediaSample> CopyFrom(const uint8_t* data, static std::shared_ptr<MediaSample> CopyFrom(const uint8_t* data,
size_t size, size_t size,
bool is_key_frame); bool is_key_frame);
/// Create a MediaSample object from input. /// Create a MediaSample object from input.
/// @param data points to the buffer containing the sample data. /// @param data points to the buffer containing the sample data.
@ -39,11 +39,11 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
/// @param size indicates sample size in bytes. Must not be negative. /// @param size indicates sample size in bytes. Must not be negative.
/// @param side_data_size indicates additional sample data size in bytes. /// @param side_data_size indicates additional sample data size in bytes.
/// @param is_key_frame indicates whether the sample is a key frame. /// @param is_key_frame indicates whether the sample is a key frame.
static scoped_refptr<MediaSample> CopyFrom(const uint8_t* data, static std::shared_ptr<MediaSample> CopyFrom(const uint8_t* data,
size_t size, size_t size,
const uint8_t* side_data, const uint8_t* side_data,
size_t side_data_size, size_t side_data_size,
bool is_key_frame); bool is_key_frame);
/// Create a MediaSample object from metadata. /// Create a MediaSample object from metadata.
/// Unlike other factory methods, this cannot be a key frame. It must be only /// Unlike other factory methods, this cannot be a key frame. It must be only
@ -51,16 +51,27 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
/// @param metadata points to the buffer containing metadata. /// @param metadata points to the buffer containing metadata.
/// Must not be NULL. /// Must not be NULL.
/// @param metadata_size is the size of metadata in bytes. /// @param metadata_size is the size of metadata in bytes.
static scoped_refptr<MediaSample> FromMetadata(const uint8_t* metadata, static std::shared_ptr<MediaSample> FromMetadata(const uint8_t* metadata,
size_t metadata_size); size_t metadata_size);
/// Create a MediaSample object with default members. /// Create a MediaSample object with default members.
static scoped_refptr<MediaSample> CreateEmptyMediaSample(); static std::shared_ptr<MediaSample> CreateEmptyMediaSample();
/// Create a MediaSample indicating we've reached end of stream. /// Create a MediaSample indicating we've reached end of stream.
/// Calling any method other than end_of_stream() on the resulting buffer /// Calling any method other than end_of_stream() on the resulting buffer
/// is disallowed. /// is disallowed.
static scoped_refptr<MediaSample> CreateEOSBuffer(); static std::shared_ptr<MediaSample> 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 { int64_t dts() const {
DCHECK(!end_of_stream()); DCHECK(!end_of_stream());
@ -154,19 +165,6 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
std::string ToString() const; std::string ToString() const;
private: private:
friend class base::RefCountedThreadSafe<MediaSample>;
// 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. // Decoding time stamp.
int64_t dts_; int64_t dts_;
// Presentation time stamp. // Presentation time stamp.
@ -193,7 +191,7 @@ class MediaSample : public base::RefCountedThreadSafe<MediaSample> {
DISALLOW_COPY_AND_ASSIGN(MediaSample); DISALLOW_COPY_AND_ASSIGN(MediaSample);
}; };
typedef std::deque<scoped_refptr<MediaSample> > BufferQueue; typedef std::deque<std::shared_ptr<MediaSample>> BufferQueue;
} // namespace media } // namespace media
} // namespace shaka } // namespace shaka

View File

@ -16,12 +16,12 @@
namespace shaka { namespace shaka {
namespace media { namespace media {
MediaStream::MediaStream(scoped_refptr<StreamInfo> info, Demuxer* demuxer) MediaStream::MediaStream(std::shared_ptr<StreamInfo> info, Demuxer* demuxer)
: info_(info), demuxer_(demuxer), muxer_(NULL), state_(kIdle) {} : info_(info), demuxer_(demuxer), muxer_(NULL), state_(kIdle) {}
MediaStream::~MediaStream() {} MediaStream::~MediaStream() {}
Status MediaStream::PullSample(scoped_refptr<MediaSample>* sample) { Status MediaStream::PullSample(std::shared_ptr<MediaSample>* sample) {
DCHECK(state_ == kPulling || state_ == kIdle); DCHECK(state_ == kPulling || state_ == kIdle);
// Trigger a new parse in demuxer if no more samples. // Trigger a new parse in demuxer if no more samples.
@ -36,7 +36,7 @@ Status MediaStream::PullSample(scoped_refptr<MediaSample>* sample) {
return Status::OK; return Status::OK;
} }
Status MediaStream::PushSample(const scoped_refptr<MediaSample>& sample) { Status MediaStream::PushSample(const std::shared_ptr<MediaSample>& sample) {
switch (state_) { switch (state_) {
case kIdle: case kIdle:
case kPulling: case kPulling:
@ -98,7 +98,9 @@ Status MediaStream::Start(MediaStreamOperation operation) {
} }
} }
const scoped_refptr<StreamInfo> MediaStream::info() const { return info_; } const std::shared_ptr<StreamInfo> MediaStream::info() const {
return info_;
}
std::string MediaStream::ToString() const { std::string MediaStream::ToString() const {
return base::StringPrintf("state: %d\n samples in the queue: %zu\n %s", return base::StringPrintf("state: %d\n samples in the queue: %zu\n %s",

View File

@ -10,7 +10,6 @@
#include <deque> #include <deque>
#include <memory> #include <memory>
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/status.h" #include "packager/media/base/status.h"
namespace shaka { namespace shaka {
@ -31,7 +30,7 @@ class MediaStream {
}; };
/// Create MediaStream from StreamInfo and Demuxer. /// Create MediaStream from StreamInfo and Demuxer.
/// @param demuxer cannot be NULL. /// @param demuxer cannot be NULL.
MediaStream(scoped_refptr<StreamInfo> info, Demuxer* demuxer); MediaStream(std::shared_ptr<StreamInfo> info, Demuxer* demuxer);
~MediaStream(); ~MediaStream();
/// Connect the stream to Muxer. /// Connect the stream to Muxer.
@ -42,19 +41,22 @@ class MediaStream {
Status Start(MediaStreamOperation operation); Status Start(MediaStreamOperation operation);
/// Push sample to Muxer (triggered by Demuxer). /// Push sample to Muxer (triggered by Demuxer).
Status PushSample(const scoped_refptr<MediaSample>& sample); Status PushSample(const std::shared_ptr<MediaSample>& sample);
/// Pull sample from Demuxer (triggered by Muxer). /// Pull sample from Demuxer (triggered by Muxer).
Status PullSample(scoped_refptr<MediaSample>* sample); Status PullSample(std::shared_ptr<MediaSample>* sample);
Demuxer* demuxer() { return demuxer_; } Demuxer* demuxer() { return demuxer_; }
Muxer* muxer() { return muxer_; } Muxer* muxer() { return muxer_; }
const scoped_refptr<StreamInfo> info() const; const std::shared_ptr<StreamInfo> info() const;
/// @return a human-readable string describing |*this|. /// @return a human-readable string describing |*this|.
std::string ToString() const; std::string ToString() const;
private: private:
MediaStream(const MediaStream&) = delete;
MediaStream& operator=(const MediaStream&) = delete;
// State transition diagram available @ http://goo.gl/ThJQbl. // State transition diagram available @ http://goo.gl/ThJQbl.
enum State { enum State {
kIdle, kIdle,
@ -64,14 +66,12 @@ class MediaStream {
kPulling, kPulling,
}; };
scoped_refptr<StreamInfo> info_; std::shared_ptr<StreamInfo> info_;
Demuxer* demuxer_; Demuxer* demuxer_;
Muxer* muxer_; Muxer* muxer_;
State state_; State state_;
// An internal buffer to store samples temporarily. // An internal buffer to store samples temporarily.
std::deque<scoped_refptr<MediaSample> > samples_; std::deque<std::shared_ptr<MediaSample>> samples_;
DISALLOW_COPY_AND_ASSIGN(MediaStream);
}; };
} // namespace media } // namespace media

View File

@ -71,7 +71,7 @@ Status Muxer::Run() {
if (cancelled_) if (cancelled_)
return Status(error::CANCELLED, "muxer run cancelled"); return Status(error::CANCELLED, "muxer run cancelled");
scoped_refptr<MediaSample> sample; std::shared_ptr<MediaSample> sample;
status = streams_[current_stream_id]->PullSample(&sample); status = streams_[current_stream_id]->PullSample(&sample);
if (!status.ok()) if (!status.ok())
break; break;
@ -101,7 +101,7 @@ void Muxer::SetProgressListener(
} }
Status Muxer::AddSample(const MediaStream* stream, Status Muxer::AddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) { std::shared_ptr<MediaSample> sample) {
DCHECK(std::find(streams_.begin(), streams_.end(), stream) != streams_.end()); DCHECK(std::find(streams_.begin(), streams_.end(), stream) != streams_.end());
if (!initialized_) { if (!initialized_) {

View File

@ -12,7 +12,6 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "packager/base/memory/ref_counted.h"
#include "packager/base/time/clock.h" #include "packager/base/time/clock.h"
#include "packager/media/base/fourccs.h" #include "packager/media/base/fourccs.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
@ -118,7 +117,7 @@ class Muxer {
// Add new media sample. // Add new media sample.
Status AddSample(const MediaStream* stream, Status AddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample); std::shared_ptr<MediaSample> sample);
// Initialize the muxer. // Initialize the muxer.
virtual Status Initialize() = 0; virtual Status Initialize() = 0;
@ -128,7 +127,7 @@ class Muxer {
// AddSample implementation. // AddSample implementation.
virtual Status DoAddSample(const MediaStream* stream, virtual Status DoAddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) = 0; std::shared_ptr<MediaSample> sample) = 0;
MuxerOptions options_; MuxerOptions options_;
bool initialized_; bool initialized_;

View File

@ -10,8 +10,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "packager/base/memory/ref_counted.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -50,13 +48,15 @@ enum Codec {
}; };
/// Abstract class holds stream information. /// Abstract class holds stream information.
class StreamInfo : public base::RefCountedThreadSafe<StreamInfo> { class StreamInfo {
public: public:
StreamInfo(StreamType stream_type, int track_id, uint32_t time_scale, StreamInfo(StreamType stream_type, int track_id, uint32_t time_scale,
uint64_t duration, Codec codec, const std::string& codec_string, uint64_t duration, Codec codec, const std::string& codec_string,
const uint8_t* codec_config, size_t codec_config_size, const uint8_t* codec_config, size_t codec_config_size,
const std::string& language, bool is_encrypted); const std::string& language, bool is_encrypted);
virtual ~StreamInfo();
/// @return true if this object has appropriate configuration values, false /// @return true if this object has appropriate configuration values, false
/// otherwise. /// otherwise.
virtual bool IsValidConfig() const = 0; virtual bool IsValidConfig() const = 0;
@ -82,10 +82,6 @@ class StreamInfo : public base::RefCountedThreadSafe<StreamInfo> {
} }
void set_language(const std::string& language) { language_ = language; } void set_language(const std::string& language) { language_ = language; }
protected:
friend class base::RefCountedThreadSafe<StreamInfo>;
virtual ~StreamInfo();
private: private:
// Whether the stream is Audio or Video. // Whether the stream is Audio or Video.
StreamType stream_type_; StreamType stream_type_;

View File

@ -32,14 +32,13 @@ class TextStreamInfo : public StreamInfo {
const std::string& codec_config, uint16_t width, const std::string& codec_config, uint16_t width,
uint16_t height, const std::string& language); uint16_t height, const std::string& language);
~TextStreamInfo() override;
bool IsValidConfig() const override; bool IsValidConfig() const override;
uint16_t width() const { return width_; } uint16_t width() const { return width_; }
uint16_t height() const { return height_; } uint16_t height() const { return height_; }
protected:
~TextStreamInfo() override;
private: private:
uint16_t width_; uint16_t width_;
uint16_t height_; uint16_t height_;

View File

@ -26,6 +26,8 @@ class VideoStreamInfo : public StreamInfo {
uint8_t nalu_length_size, const std::string& language, uint8_t nalu_length_size, const std::string& language,
bool is_encrypted); bool is_encrypted);
~VideoStreamInfo() override;
/// @name StreamInfo implementation overrides. /// @name StreamInfo implementation overrides.
/// @{ /// @{
bool IsValidConfig() const override; bool IsValidConfig() const override;
@ -54,8 +56,6 @@ class VideoStreamInfo : public StreamInfo {
} }
private: private:
~VideoStreamInfo() override;
uint16_t width_; uint16_t width_;
uint16_t height_; uint16_t height_;

View File

@ -12,7 +12,6 @@
#include "packager/base/bind.h" #include "packager/base/bind.h"
#include "packager/base/json/json_reader.h" #include "packager/base/json/json_reader.h"
#include "packager/base/json/json_writer.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/fixed_key_source.h"
#include "packager/media/base/http_key_fetcher.h" #include "packager/media/base/http_key_fetcher.h"
#include "packager/media/base/producer_consumer_queue.h" #include "packager/media/base/producer_consumer_queue.h"
@ -110,27 +109,6 @@ bool GetPsshDataFromTrack(const base::DictionaryValue& track_dict,
namespace media { namespace media {
// A ref counted wrapper for EncryptionKeyMap.
class WidevineKeySource::RefCountedEncryptionKeyMap
: public base::RefCountedThreadSafe<RefCountedEncryptionKeyMap> {
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>;
~RefCountedEncryptionKeyMap() {}
EncryptionKeyMap encryption_key_map_;
DISALLOW_COPY_AND_ASSIGN(RefCountedEncryptionKeyMap);
};
WidevineKeySource::WidevineKeySource(const std::string& server_url, WidevineKeySource::WidevineKeySource(const std::string& server_url,
bool add_common_pssh) bool add_common_pssh)
: key_production_thread_("KeyProductionThread", : 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_LE(track_type, NUM_VALID_TRACK_TYPES);
DCHECK_NE(track_type, TRACK_TYPE_UNKNOWN); DCHECK_NE(track_type, TRACK_TYPE_UNKNOWN);
scoped_refptr<RefCountedEncryptionKeyMap> ref_counted_encryption_key_map; std::shared_ptr<EncryptionKeyMap> encryption_key_map;
Status status = Status status = key_pool_->Peek(crypto_period_index, &encryption_key_map,
key_pool_->Peek(crypto_period_index, &ref_counted_encryption_key_map, kGetKeyTimeoutInSeconds * 1000);
kGetKeyTimeoutInSeconds * 1000);
if (!status.ok()) { if (!status.ok()) {
if (status.error_code() == error::STOPPED) { if (status.error_code() == error::STOPPED) {
CHECK(!common_encryption_request_status_.ok()); CHECK(!common_encryption_request_status_.ok());
@ -300,13 +277,11 @@ Status WidevineKeySource::GetKeyInternal(uint32_t crypto_period_index,
return status; return status;
} }
const EncryptionKeyMap& encryption_key_map = if (encryption_key_map->find(track_type) == encryption_key_map->end()) {
ref_counted_encryption_key_map->map();
if (encryption_key_map.find(track_type) == encryption_key_map.end()) {
return Status(error::INTERNAL_ERROR, return Status(error::INTERNAL_ERROR,
"Cannot find key of type " + TrackTypeToString(track_type)); "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; return Status::OK;
} }
@ -601,11 +576,9 @@ bool WidevineKeySource::PushToKeyPool(
EncryptionKeyMap* encryption_key_map) { EncryptionKeyMap* encryption_key_map) {
DCHECK(key_pool_); DCHECK(key_pool_);
DCHECK(encryption_key_map); DCHECK(encryption_key_map);
Status status = auto encryption_key_map_shared = std::make_shared<EncryptionKeyMap>();
key_pool_->Push(scoped_refptr<RefCountedEncryptionKeyMap>( encryption_key_map_shared->swap(*encryption_key_map);
new RefCountedEncryptionKeyMap(encryption_key_map)), Status status = key_pool_->Push(encryption_key_map_shared, kInfiniteTimeout);
kInfiniteTimeout);
encryption_key_map->clear();
if (!status.ok()) { if (!status.ok()) {
DCHECK_EQ(error::STOPPED, status.error_code()); DCHECK_EQ(error::STOPPED, status.error_code());
return false; return false;

View File

@ -68,8 +68,7 @@ class WidevineKeySource : public KeySource {
private: private:
typedef std::map<TrackType, std::unique_ptr<EncryptionKey>> EncryptionKeyMap; typedef std::map<TrackType, std::unique_ptr<EncryptionKey>> EncryptionKeyMap;
class RefCountedEncryptionKeyMap; typedef ProducerConsumerQueue<std::shared_ptr<EncryptionKeyMap>>
typedef ProducerConsumerQueue<scoped_refptr<RefCountedEncryptionKeyMap> >
EncryptionKeyQueue; EncryptionKeyQueue;
// Internal routine for getting keys. // Internal routine for getting keys.

View File

@ -21,9 +21,9 @@ class BufferWriter;
/// A base class that is used to convert H.26x byte streams to NAL unit streams. /// A base class that is used to convert H.26x byte streams to NAL unit streams.
class H26xByteToUnitStreamConverter { class H26xByteToUnitStreamConverter {
public: public:
static const size_t kUnitStreamNaluLengthSize = 4; static constexpr size_t kUnitStreamNaluLengthSize = 4;
H26xByteToUnitStreamConverter(Nalu::CodecType type); explicit H26xByteToUnitStreamConverter(Nalu::CodecType type);
virtual ~H26xByteToUnitStreamConverter(); virtual ~H26xByteToUnitStreamConverter();
/// Converts a whole byte stream encoded video frame to NAL unit stream /// Converts a whole byte stream encoded video frame to NAL unit stream
@ -61,4 +61,3 @@ class H26xByteToUnitStreamConverter {
} // namespace shaka } // namespace shaka
#endif // MEDIA_CODECS_H26x_BYTE_TO_UNIT_STREAM_CONVERTER_H_ #endif // MEDIA_CODECS_H26x_BYTE_TO_UNIT_STREAM_CONVERTER_H_

View File

@ -11,7 +11,6 @@
#include <vector> #include <vector>
#include "packager/base/macros.h" #include "packager/base/macros.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/decrypt_config.h" #include "packager/media/base/decrypt_config.h"
namespace shaka { namespace shaka {

View File

@ -106,7 +106,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionInfoReadyBeforeMediaStart) {
TEST_F(HlsNotifyMuxerListenerTest, OnMediaStart) { TEST_F(HlsNotifyMuxerListenerTest, OnMediaStart) {
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
EXPECT_CALL(mock_notifier_, EXPECT_CALL(mock_notifier_,
@ -143,7 +143,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStart) {
ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _)) ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _))
.WillByDefault(Return(true)); .WillByDefault(Return(true));
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
MuxerOptions muxer_options; MuxerOptions muxer_options;
@ -183,7 +183,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStartBeforeMediaStart) {
ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _)) ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _))
.WillByDefault(Return(true)); .WillByDefault(Return(true));
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
MuxerOptions muxer_options; MuxerOptions muxer_options;
@ -222,7 +222,7 @@ TEST_F(HlsNotifyMuxerListenerTest, NoEncryptionUpdateIfNotifyNewStreamFails) {
EXPECT_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _)) EXPECT_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _))
.WillOnce(Return(false)); .WillOnce(Return(false));
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
MuxerOptions muxer_options; MuxerOptions muxer_options;
@ -237,7 +237,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionInfoReady) {
ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _)) ON_CALL(mock_notifier_, NotifyNewStream(_, _, _, _, _))
.WillByDefault(Return(true)); .WillByDefault(Return(true));
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
MuxerOptions muxer_options; MuxerOptions muxer_options;
listener_.OnMediaStart(muxer_options, *video_stream_info, 90000, listener_.OnMediaStart(muxer_options, *video_stream_info, 90000,

View File

@ -111,7 +111,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodClearContent) {
MuxerOptions muxer_options; MuxerOptions muxer_options;
SetDefaultMuxerOptionsValues(&muxer_options); SetDefaultMuxerOptionsValues(&muxer_options);
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
EXPECT_CALL(*notifier_, NotifyNewContainer(_, _)).Times(0); EXPECT_CALL(*notifier_, NotifyNewContainer(_, _)).Times(0);
@ -156,7 +156,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContent) {
MuxerOptions muxer_options; MuxerOptions muxer_options;
SetDefaultMuxerOptionsValues(&muxer_options); SetDefaultMuxerOptionsValues(&muxer_options);
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
const std::vector<uint8_t> default_key_id( const std::vector<uint8_t> default_key_id(
@ -199,7 +199,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodOnSampleDurationReady) {
MuxerOptions muxer_options; MuxerOptions muxer_options;
SetDefaultMuxerOptionsValues(&muxer_options); SetDefaultMuxerOptionsValues(&muxer_options);
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
const uint32_t kSampleDuration = 1234u; const uint32_t kSampleDuration = 1234u;
const char kExpectedMediaInfo[] = const char kExpectedMediaInfo[] =
@ -246,7 +246,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodOnNewSegment) {
MuxerOptions muxer_options; MuxerOptions muxer_options;
SetDefaultMuxerOptionsValues(&muxer_options); SetDefaultMuxerOptionsValues(&muxer_options);
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
const uint64_t kStartTime1 = 0u; const uint64_t kStartTime1 = 0u;
@ -283,7 +283,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveNoKeyRotation) {
MuxerOptions muxer_options; MuxerOptions muxer_options;
SetDefaultLiveMuxerOptionsValues(&muxer_options); SetDefaultLiveMuxerOptionsValues(&muxer_options);
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
const std::string kExpectedMediaInfo = const std::string kExpectedMediaInfo =
@ -355,7 +355,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveWithKeyRotation) {
MuxerOptions muxer_options; MuxerOptions muxer_options;
SetDefaultLiveMuxerOptionsValues(&muxer_options); SetDefaultLiveMuxerOptionsValues(&muxer_options);
VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams(); VideoStreamInfoParameters video_params = GetDefaultVideoStreamInfoParams();
scoped_refptr<StreamInfo> video_stream_info = std::shared_ptr<StreamInfo> video_stream_info =
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
// Note that this media info has protected_content with default key id. // Note that this media info has protected_content with default key id.

View File

@ -14,14 +14,14 @@ namespace media {
VideoStreamInfoParameters::VideoStreamInfoParameters() {} VideoStreamInfoParameters::VideoStreamInfoParameters() {}
VideoStreamInfoParameters::~VideoStreamInfoParameters() {} VideoStreamInfoParameters::~VideoStreamInfoParameters() {}
scoped_refptr<StreamInfo> CreateVideoStreamInfo( std::shared_ptr<StreamInfo> CreateVideoStreamInfo(
const VideoStreamInfoParameters& param) { const VideoStreamInfoParameters& param) {
return scoped_refptr<StreamInfo>(new VideoStreamInfo( return std::make_shared<VideoStreamInfo>(
param.track_id, param.time_scale, param.duration, param.codec, param.track_id, param.time_scale, param.duration, param.codec,
param.codec_string, param.codec_config.data(), param.codec_config.size(), param.codec_string, param.codec_config.data(), param.codec_config.size(),
param.width, param.height, param.pixel_width, param.pixel_height, param.width, param.height, param.pixel_width, param.pixel_height,
0, // trick_play_rate 0, // trick_play_rate
param.nalu_length_size, param.language, param.is_encrypted)); param.nalu_length_size, param.language, param.is_encrypted);
} }
VideoStreamInfoParameters GetDefaultVideoStreamInfoParams() { VideoStreamInfoParameters GetDefaultVideoStreamInfoParams() {

View File

@ -10,7 +10,6 @@
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/key_source.h" #include "packager/media/base/key_source.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
#include "packager/media/base/stream_info.h" #include "packager/media/base/stream_info.h"
@ -85,7 +84,7 @@ struct OnMediaEndParameters {
}; };
// Creates StreamInfo instance from VideoStreamInfoParameters. // Creates StreamInfo instance from VideoStreamInfoParameters.
scoped_refptr<StreamInfo> CreateVideoStreamInfo( std::shared_ptr<StreamInfo> CreateVideoStreamInfo(
const VideoStreamInfoParameters& param); const VideoStreamInfoParameters& param);
// Returns the "default" VideoStreamInfoParameters for testing. // Returns the "default" VideoStreamInfoParameters for testing.

View File

@ -124,7 +124,7 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test {
}; };
TEST_F(VodMediaInfoDumpMuxerListenerTest, UnencryptedStream_Normal) { TEST_F(VodMediaInfoDumpMuxerListenerTest, UnencryptedStream_Normal) {
scoped_refptr<StreamInfo> stream_info = std::shared_ptr<StreamInfo> stream_info =
CreateVideoStreamInfo(GetDefaultVideoStreamInfoParams()); CreateVideoStreamInfo(GetDefaultVideoStreamInfoParams());
FireOnMediaStartWithDefaultMuxerOptions(*stream_info, !kEnableEncryption); FireOnMediaStartWithDefaultMuxerOptions(*stream_info, !kEnableEncryption);
@ -157,7 +157,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, UnencryptedStream_Normal) {
} }
TEST_F(VodMediaInfoDumpMuxerListenerTest, EncryptedStream_Normal) { TEST_F(VodMediaInfoDumpMuxerListenerTest, EncryptedStream_Normal) {
scoped_refptr<StreamInfo> stream_info = std::shared_ptr<StreamInfo> stream_info =
CreateVideoStreamInfo(GetDefaultVideoStreamInfoParams()); CreateVideoStreamInfo(GetDefaultVideoStreamInfoParams());
FireOnMediaStartWithDefaultMuxerOptions(*stream_info, kEnableEncryption); FireOnMediaStartWithDefaultMuxerOptions(*stream_info, kEnableEncryption);
OnMediaEndParameters media_end_param = GetDefaultOnMediaEndParams(); OnMediaEndParameters media_end_param = GetDefaultOnMediaEndParams();
@ -204,7 +204,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckPixelWidthAndHeightSet) {
params.pixel_width = 8; params.pixel_width = 8;
params.pixel_height = 9; params.pixel_height = 9;
scoped_refptr<StreamInfo> stream_info = CreateVideoStreamInfo(params); std::shared_ptr<StreamInfo> stream_info = CreateVideoStreamInfo(params);
FireOnMediaStartWithDefaultMuxerOptions(*stream_info, !kEnableEncryption); FireOnMediaStartWithDefaultMuxerOptions(*stream_info, !kEnableEncryption);
OnMediaEndParameters media_end_param = GetDefaultOnMediaEndParams(); OnMediaEndParameters media_end_param = GetDefaultOnMediaEndParams();
FireOnMediaEndWithParams(media_end_param); FireOnMediaEndWithParams(media_end_param);

View File

@ -8,7 +8,6 @@
#include <stdint.h> #include <stdint.h>
#include "packager/base/callback.h" #include "packager/base/callback.h"
#include "packager/base/memory/ref_counted.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -20,9 +19,9 @@ namespace mp2t {
class EsParser { class EsParser {
public: public:
typedef base::Callback<void(const scoped_refptr<StreamInfo>&)> typedef base::Callback<void(const std::shared_ptr<StreamInfo>&)>
NewStreamInfoCB; NewStreamInfoCB;
typedef base::Callback<void(uint32_t, const scoped_refptr<MediaSample>&)> typedef base::Callback<void(uint32_t, const std::shared_ptr<MediaSample>&)>
EmitSampleCB; EmitSampleCB;
EsParser(uint32_t pid) : pid_(pid) {} EsParser(uint32_t pid) : pid_(pid) {}

View File

@ -159,11 +159,8 @@ bool EsParserAdts::Parse(const uint8_t* buf,
// Emit an audio frame. // Emit an audio frame.
bool is_key_frame = true; bool is_key_frame = true;
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample = MediaSample::CopyFrom(
MediaSample::CopyFrom( frame_ptr + header_size, frame_size - header_size, is_key_frame);
frame_ptr + header_size,
frame_size - header_size,
is_key_frame);
sample->set_pts(current_pts); sample->set_pts(current_pts);
sample->set_dts(current_pts); sample->set_dts(current_pts);
sample->set_duration(frame_duration); sample->set_duration(frame_duration);
@ -188,7 +185,7 @@ void EsParserAdts::Flush() {
void EsParserAdts::Reset() { void EsParserAdts::Reset() {
es_byte_queue_.Reset(); es_byte_queue_.Reset();
pts_list_.clear(); pts_list_.clear();
last_audio_decoder_config_ = scoped_refptr<AudioStreamInfo>(); last_audio_decoder_config_ = std::shared_ptr<AudioStreamInfo>();
} }
bool EsParserAdts::UpdateAudioConfiguration(const uint8_t* adts_frame, 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) ? std::min(2 * samples_per_second, 48000)
: samples_per_second; : samples_per_second;
last_audio_decoder_config_ = scoped_refptr<StreamInfo>(new AudioStreamInfo( last_audio_decoder_config_ = std::make_shared<AudioStreamInfo>(
pid(), kMpeg2Timescale, kInfiniteDuration, kCodecAAC, pid(), kMpeg2Timescale, kInfiniteDuration, kCodecAAC,
AudioStreamInfo::GetCodecString(kCodecAAC, adts_header.GetObjectType()), AudioStreamInfo::GetCodecString(kCodecAAC, adts_header.GetObjectType()),
audio_specific_config.data(), audio_specific_config.size(), audio_specific_config.data(), audio_specific_config.size(),
kAacSampleSizeBits, adts_header.GetNumChannels(), kAacSampleSizeBits, adts_header.GetNumChannels(),
extended_samples_per_second, 0 /* seek preroll */, 0 /* codec delay */, 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) << "Sampling frequency: " << samples_per_second;
DVLOG(1) << "Extended sampling frequency: " << extended_samples_per_second; DVLOG(1) << "Extended sampling frequency: " << extended_samples_per_second;

View File

@ -67,7 +67,7 @@ class EsParserAdts : public EsParser {
// Interpolated PTS for frames that don't have one. // Interpolated PTS for frames that don't have one.
std::unique_ptr<AudioTimestampHelper> audio_timestamp_helper_; std::unique_ptr<AudioTimestampHelper> audio_timestamp_helper_;
scoped_refptr<StreamInfo> last_audio_decoder_config_; std::shared_ptr<StreamInfo> last_audio_decoder_config_;
DISALLOW_COPY_AND_ASSIGN(EsParserAdts); DISALLOW_COPY_AND_ASSIGN(EsParserAdts);
}; };

View File

@ -36,7 +36,7 @@ EsParserH264::~EsParserH264() {}
void EsParserH264::Reset() { void EsParserH264::Reset() {
DVLOG(1) << "EsParserH264::Reset"; DVLOG(1) << "EsParserH264::Reset";
h264_parser_.reset(new H264Parser()); h264_parser_.reset(new H264Parser());
last_video_decoder_config_ = scoped_refptr<StreamInfo>(); last_video_decoder_config_ = std::shared_ptr<StreamInfo>();
decoder_config_check_pending_ = false; decoder_config_check_pending_ = false;
EsParserH26x::Reset(); EsParserH26x::Reset();
} }
@ -146,15 +146,16 @@ bool EsParserH264::UpdateVideoDecoderConfig(int pps_id) {
return false; return false;
} }
last_video_decoder_config_ = scoped_refptr<StreamInfo>(new VideoStreamInfo( const uint8_t nalu_length_size =
H26xByteToUnitStreamConverter::kUnitStreamNaluLengthSize;
last_video_decoder_config_ = std::make_shared<VideoStreamInfo>(
pid(), kMpeg2Timescale, kInfiniteDuration, kCodecH264, pid(), kMpeg2Timescale, kInfiniteDuration, kCodecH264,
AVCDecoderConfigurationRecord::GetCodecString(decoder_config_record[1], AVCDecoderConfigurationRecord::GetCodecString(decoder_config_record[1],
decoder_config_record[2], decoder_config_record[2],
decoder_config_record[3]), decoder_config_record[3]),
decoder_config_record.data(), decoder_config_record.size(), coded_width, decoder_config_record.data(), decoder_config_record.size(), coded_width,
coded_height, pixel_width, pixel_height, 0, coded_height, pixel_width, pixel_height, 0, nalu_length_size,
H264ByteToUnitStreamConverter::kUnitStreamNaluLengthSize, std::string(), std::string(), false);
false));
DVLOG(1) << "Profile IDC: " << sps->profile_idc; DVLOG(1) << "Profile IDC: " << sps->profile_idc;
DVLOG(1) << "Level IDC: " << sps->level_idc; DVLOG(1) << "Level IDC: " << sps->level_idc;
DVLOG(1) << "log2_max_frame_num_minus4: " << sps->log2_max_frame_num_minus4; DVLOG(1) << "log2_max_frame_num_minus4: " << sps->log2_max_frame_num_minus4;

View File

@ -43,7 +43,7 @@ class EsParserH264 : public EsParserH26x {
// Callback to pass the stream configuration. // Callback to pass the stream configuration.
NewStreamInfoCB new_stream_info_cb_; NewStreamInfoCB new_stream_info_cb_;
scoped_refptr<StreamInfo> last_video_decoder_config_; std::shared_ptr<StreamInfo> last_video_decoder_config_;
bool decoder_config_check_pending_; bool decoder_config_check_pending_;
std::unique_ptr<H264Parser> h264_parser_; std::unique_ptr<H264Parser> h264_parser_;

View File

@ -124,13 +124,13 @@ class EsParserH264Test : public testing::Test {
void LoadStream(const char* filename); void LoadStream(const char* filename);
void ProcessPesPackets(const std::vector<Packet>& pes_packets); void ProcessPesPackets(const std::vector<Packet>& pes_packets);
void EmitSample(uint32_t pid, const scoped_refptr<MediaSample>& sample) { void EmitSample(uint32_t pid, const std::shared_ptr<MediaSample>& sample) {
sample_count_++; sample_count_++;
if (sample_count_ == 1) if (sample_count_ == 1)
first_frame_is_key_frame_ = sample->is_key_frame(); first_frame_is_key_frame_ = sample->is_key_frame();
} }
void NewVideoConfig(const scoped_refptr<StreamInfo>& config) { void NewVideoConfig(const std::shared_ptr<StreamInfo>& config) {
DVLOG(1) << config->ToString(); DVLOG(1) << config->ToString();
stream_map_[config->track_id()] = config; stream_map_[config->track_id()] = config;
} }
@ -145,7 +145,7 @@ class EsParserH264Test : public testing::Test {
std::vector<Packet> access_units_; std::vector<Packet> access_units_;
protected: protected:
typedef std::map<int, scoped_refptr<StreamInfo> > StreamMap; typedef std::map<int, std::shared_ptr<StreamInfo>> StreamMap;
StreamMap stream_map_; StreamMap stream_map_;
size_t sample_count_; size_t sample_count_;
bool first_frame_is_key_frame_; bool first_frame_is_key_frame_;

View File

@ -39,7 +39,7 @@ EsParserH265::~EsParserH265() {}
void EsParserH265::Reset() { void EsParserH265::Reset() {
DVLOG(1) << "EsParserH265::Reset"; DVLOG(1) << "EsParserH265::Reset";
h265_parser_.reset(new H265Parser()); h265_parser_.reset(new H265Parser());
last_video_decoder_config_ = scoped_refptr<StreamInfo>(); last_video_decoder_config_ = std::shared_ptr<StreamInfo>();
decoder_config_check_pending_ = false; decoder_config_check_pending_ = false;
EsParserH26x::Reset(); EsParserH26x::Reset();
} }
@ -151,12 +151,13 @@ bool EsParserH265::UpdateVideoDecoderConfig(int pps_id) {
return false; return false;
} }
last_video_decoder_config_ = scoped_refptr<StreamInfo>(new VideoStreamInfo( const uint8_t nalu_length_size =
H26xByteToUnitStreamConverter::kUnitStreamNaluLengthSize;
last_video_decoder_config_ = std::make_shared<VideoStreamInfo>(
pid(), kMpeg2Timescale, kInfiniteDuration, kCodecHVC1, pid(), kMpeg2Timescale, kInfiniteDuration, kCodecHVC1,
decoder_config.GetCodecString(kCodecHVC1), decoder_config_record.data(), decoder_config.GetCodecString(kCodecHVC1), decoder_config_record.data(),
decoder_config_record.size(), coded_width, coded_height, pixel_width, decoder_config_record.size(), coded_width, coded_height, pixel_width,
pixel_height, 0, H26xByteToUnitStreamConverter::kUnitStreamNaluLengthSize, pixel_height, 0, nalu_length_size, std::string(), false);
std::string(), false));
// Video config notification. // Video config notification.
new_stream_info_cb_.Run(last_video_decoder_config_); new_stream_info_cb_.Run(last_video_decoder_config_);

View File

@ -46,7 +46,7 @@ class EsParserH265 : public EsParserH26x {
NewStreamInfoCB new_stream_info_cb_; NewStreamInfoCB new_stream_info_cb_;
// Last video decoder config. // Last video decoder config.
scoped_refptr<StreamInfo> last_video_decoder_config_; std::shared_ptr<StreamInfo> last_video_decoder_config_;
bool decoder_config_check_pending_; bool decoder_config_check_pending_;
std::unique_ptr<H265Parser> h265_parser_; std::unique_ptr<H265Parser> h265_parser_;

View File

@ -94,7 +94,7 @@ void EsParserH26x::Flush() {
DCHECK(pending_sample_duration_); DCHECK(pending_sample_duration_);
pending_sample_->set_duration(pending_sample_duration_); pending_sample_->set_duration(pending_sample_duration_);
emit_sample_cb_.Run(pid(), pending_sample_); emit_sample_cb_.Run(pid(), pending_sample_);
pending_sample_ = scoped_refptr<MediaSample>(); pending_sample_ = std::shared_ptr<MediaSample>();
} }
} }
@ -107,7 +107,7 @@ void EsParserH26x::Reset() {
next_access_unit_position_ = 0; next_access_unit_position_ = 0;
current_nalu_info_.reset(); current_nalu_info_.reset();
timing_desc_list_.clear(); timing_desc_list_.clear();
pending_sample_ = scoped_refptr<MediaSample>(); pending_sample_ = std::shared_ptr<MediaSample>();
pending_sample_duration_ = 0; pending_sample_duration_ = 0;
waiting_for_key_frame_ = true; 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 // Create the media sample, emitting always the previous sample after
// calculating its duration. // calculating its duration.
scoped_refptr<MediaSample> media_sample = MediaSample::CopyFrom( std::shared_ptr<MediaSample> media_sample = MediaSample::CopyFrom(
converted_frame.data(), converted_frame.size(), is_key_frame); converted_frame.data(), converted_frame.size(), is_key_frame);
media_sample->set_dts(current_timing_desc.dts); media_sample->set_dts(current_timing_desc.dts);
media_sample->set_pts(current_timing_desc.pts); media_sample->set_pts(current_timing_desc.pts);

View File

@ -126,7 +126,7 @@ class EsParserH26x : public EsParser {
std::unique_ptr<H26xByteToUnitStreamConverter> stream_converter_; std::unique_ptr<H26xByteToUnitStreamConverter> stream_converter_;
// Frame for which we do not yet have a duration. // Frame for which we do not yet have a duration.
scoped_refptr<MediaSample> pending_sample_; std::shared_ptr<MediaSample> pending_sample_;
uint64_t pending_sample_duration_ = 0; uint64_t pending_sample_duration_ = 0;
// Indicates whether waiting for first key frame. // Indicates whether waiting for first key frame.

View File

@ -163,7 +163,7 @@ class EsParserH26xTest : public testing::Test {
const H26xNaluType* types, const H26xNaluType* types,
size_t types_count); size_t types_count);
void EmitSample(uint32_t pid, const scoped_refptr<MediaSample>& sample) { void EmitSample(uint32_t pid, const std::shared_ptr<MediaSample>& sample) {
size_t sample_id = sample_count_; size_t sample_id = sample_count_;
sample_count_++; sample_count_++;
if (sample_count_ == 1) if (sample_count_ == 1)
@ -175,7 +175,7 @@ class EsParserH26xTest : public testing::Test {
EXPECT_EQ(samples_[sample_id], sample_data); EXPECT_EQ(samples_[sample_id], sample_data);
} }
void NewVideoConfig(const scoped_refptr<StreamInfo>& config) { void NewVideoConfig(const std::shared_ptr<StreamInfo>& config) {
has_stream_info_ = true; has_stream_info_ = true;
} }

View File

@ -61,8 +61,10 @@ class PidState {
PidType pid_type() const { return pid_type_; } PidType pid_type() const { return pid_type_; }
scoped_refptr<StreamInfo>& config() { return config_; } std::shared_ptr<StreamInfo>& config() { return config_; }
void set_config(const scoped_refptr<StreamInfo>& config) { config_ = config; } void set_config(const std::shared_ptr<StreamInfo>& config) {
config_ = config;
}
SampleQueue& sample_queue() { return sample_queue_; } SampleQueue& sample_queue() { return sample_queue_; }
@ -75,7 +77,7 @@ class PidState {
bool enable_; bool enable_;
int continuity_counter_; int continuity_counter_;
scoped_refptr<StreamInfo> config_; std::shared_ptr<StreamInfo> config_;
SampleQueue sample_queue_; SampleQueue sample_queue_;
}; };
@ -333,7 +335,7 @@ void Mp2tMediaParser::RegisterPes(int pmt_pid,
} }
void Mp2tMediaParser::OnNewStreamInfo( void Mp2tMediaParser::OnNewStreamInfo(
const scoped_refptr<StreamInfo>& new_stream_info) { const std::shared_ptr<StreamInfo>& new_stream_info) {
DCHECK(new_stream_info); DCHECK(new_stream_info);
DVLOG(1) << "OnVideoConfigChanged for pid=" << new_stream_info->track_id(); DVLOG(1) << "OnVideoConfigChanged for pid=" << new_stream_info->track_id();
@ -360,7 +362,7 @@ bool Mp2tMediaParser::FinishInitializationIfNeeded() {
if (pids_.empty()) if (pids_.empty())
return true; return true;
std::vector<scoped_refptr<StreamInfo> > all_stream_info; std::vector<std::shared_ptr<StreamInfo>> all_stream_info;
uint32_t num_es(0); uint32_t num_es(0);
for (PidMap::const_iterator iter = pids_.begin(); iter != pids_.end(); for (PidMap::const_iterator iter = pids_.begin(); iter != pids_.end();
++iter) { ++iter) {
@ -383,7 +385,7 @@ bool Mp2tMediaParser::FinishInitializationIfNeeded() {
void Mp2tMediaParser::OnEmitSample( void Mp2tMediaParser::OnEmitSample(
uint32_t pes_pid, uint32_t pes_pid,
const scoped_refptr<MediaSample>& new_sample) { const std::shared_ptr<MediaSample>& new_sample) {
DCHECK(new_sample); DCHECK(new_sample);
DVLOG(LOG_LEVEL_ES) DVLOG(LOG_LEVEL_ES)
<< "OnEmitSample: " << "OnEmitSample: "

View File

@ -9,7 +9,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/byte_queue.h" #include "packager/media/base/byte_queue.h"
#include "packager/media/base/media_parser.h" #include "packager/media/base/media_parser.h"
#include "packager/media/base/stream_info.h" #include "packager/media/base/stream_info.h"
@ -25,7 +24,7 @@ class PidState;
class TsPacket; class TsPacket;
class TsSection; class TsSection;
typedef std::deque<scoped_refptr<MediaSample> > SampleQueue; typedef std::deque<std::shared_ptr<MediaSample>> SampleQueue;
class Mp2tMediaParser : public MediaParser { class Mp2tMediaParser : public MediaParser {
public: public:
@ -56,12 +55,12 @@ class Mp2tMediaParser : public MediaParser {
// Callback invoked each time the audio/video decoder configuration is // Callback invoked each time the audio/video decoder configuration is
// changed. // changed.
void OnNewStreamInfo(const scoped_refptr<StreamInfo>& new_stream_info); void OnNewStreamInfo(const std::shared_ptr<StreamInfo>& new_stream_info);
// Callback invoked by the ES media parser // Callback invoked by the ES media parser
// to emit a new audio/video access unit. // to emit a new audio/video access unit.
void OnEmitSample(uint32_t pes_pid, void OnEmitSample(uint32_t pes_pid,
const scoped_refptr<MediaSample>& new_sample); const std::shared_ptr<MediaSample>& new_sample);
// Invoke the initialization callback if needed. // Invoke the initialization callback if needed.
bool FinishInitializationIfNeeded(); bool FinishInitializationIfNeeded();

View File

@ -10,7 +10,6 @@
#include "packager/base/bind.h" #include "packager/base/bind.h"
#include "packager/base/bind_helpers.h" #include "packager/base/bind_helpers.h"
#include "packager/base/logging.h" #include "packager/base/logging.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/media_sample.h" #include "packager/media/base/media_sample.h"
#include "packager/media/base/stream_info.h" #include "packager/media/base/stream_info.h"
#include "packager/media/base/timestamp.h" #include "packager/media/base/timestamp.h"
@ -34,7 +33,7 @@ class Mp2tMediaParserTest : public testing::Test {
} }
protected: protected:
typedef std::map<int, scoped_refptr<StreamInfo> > StreamMap; typedef std::map<int, std::shared_ptr<StreamInfo>> StreamMap;
std::unique_ptr<Mp2tMediaParser> parser_; std::unique_ptr<Mp2tMediaParser> parser_;
StreamMap stream_map_; StreamMap stream_map_;
@ -62,17 +61,16 @@ class Mp2tMediaParserTest : public testing::Test {
return true; return true;
} }
void OnInit(const std::vector<scoped_refptr<StreamInfo> >& stream_infos) { void OnInit(const std::vector<std::shared_ptr<StreamInfo>>& stream_infos) {
DVLOG(1) << "OnInit: " << stream_infos.size() << " streams."; DVLOG(1) << "OnInit: " << stream_infos.size() << " streams.";
for (std::vector<scoped_refptr<StreamInfo> >::const_iterator iter = for (const auto& stream_info : stream_infos) {
stream_infos.begin(); iter != stream_infos.end(); ++iter) { DVLOG(1) << stream_info->ToString();
DVLOG(1) << (*iter)->ToString(); stream_map_[stream_info->track_id()] = stream_info;
stream_map_[(*iter)->track_id()] = *iter;
} }
} }
bool OnNewSample(uint32_t track_id, bool OnNewSample(uint32_t track_id,
const scoped_refptr<MediaSample>& sample) { const std::shared_ptr<MediaSample>& sample) {
StreamMap::const_iterator stream = stream_map_.find(track_id); StreamMap::const_iterator stream = stream_map_.find(track_id);
EXPECT_NE(stream_map_.end(), stream); EXPECT_NE(stream_map_.end(), stream);
if (stream != stream_map_.end()) { if (stream != stream_map_.end()) {

View File

@ -124,7 +124,7 @@ bool PesPacketGenerator::Initialize(const StreamInfo& stream_info) {
return false; return false;
} }
bool PesPacketGenerator::PushSample(scoped_refptr<MediaSample> sample) { bool PesPacketGenerator::PushSample(std::shared_ptr<MediaSample> sample) {
if (!current_processing_pes_) if (!current_processing_pes_)
current_processing_pes_.reset(new PesPacket()); current_processing_pes_.reset(new PesPacket());

View File

@ -44,7 +44,7 @@ class PesPacketGenerator {
/// NumberOfReadyPesPackets(). /// NumberOfReadyPesPackets().
/// If this returns false, the object may end up in an undefined state. /// If this returns false, the object may end up in an undefined state.
/// @return true on success, false otherwise. /// @return true on success, false otherwise.
virtual bool PushSample(scoped_refptr<MediaSample> sample); virtual bool PushSample(std::shared_ptr<MediaSample> sample);
/// Sets the encryption key for encrypting samples. /// Sets the encryption key for encrypting samples.
/// @param encryption_key is the key that will be used to encrypt further /// @param encryption_key is the key that will be used to encrypt further

View File

@ -102,16 +102,16 @@ class MockAACAudioSpecificConfig : public AACAudioSpecificConfig {
MOCK_CONST_METHOD1(ConvertToADTS, bool(std::vector<uint8_t>* buffer)); MOCK_CONST_METHOD1(ConvertToADTS, bool(std::vector<uint8_t>* buffer));
}; };
scoped_refptr<VideoStreamInfo> CreateVideoStreamInfo(Codec codec) { std::shared_ptr<VideoStreamInfo> CreateVideoStreamInfo(Codec codec) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, codec, kCodecString, kVideoExtraData, kTrackId, kTimeScale, kDuration, codec, kCodecString, kVideoExtraData,
arraysize(kVideoExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kVideoExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
return stream_info; return stream_info;
} }
scoped_refptr<AudioStreamInfo> CreateAudioStreamInfo(Codec codec) { std::shared_ptr<AudioStreamInfo> CreateAudioStreamInfo(Codec codec) {
scoped_refptr<AudioStreamInfo> stream_info(new AudioStreamInfo( std::shared_ptr<AudioStreamInfo> stream_info(new AudioStreamInfo(
kTrackId, kTimeScale, kDuration, codec, kCodecString, kAudioExtraData, kTrackId, kTimeScale, kDuration, codec, kCodecString, kAudioExtraData,
arraysize(kAudioExtraData), kSampleBits, kNumChannels, kSamplingFrequency, arraysize(kAudioExtraData), kSampleBits, kNumChannels, kSamplingFrequency,
kSeekPreroll, kCodecDelay, kMaxBitrate, kAverageBitrate, kLanguage, kSeekPreroll, kCodecDelay, kMaxBitrate, kAverageBitrate, kLanguage,
@ -138,12 +138,12 @@ class PesPacketGeneratorTest : public ::testing::Test {
size_t input_size, size_t input_size,
const uint8_t* expected_output, const uint8_t* expected_output,
size_t expected_output_size) { size_t expected_output_size) {
scoped_refptr<VideoStreamInfo> stream_info( std::shared_ptr<VideoStreamInfo> stream_info(
CreateVideoStreamInfo(kH264Codec)); CreateVideoStreamInfo(kH264Codec));
EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_TRUE(generator_.Initialize(*stream_info));
EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets());
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
MediaSample::CopyFrom(input, input_size, kIsKeyFrame); MediaSample::CopyFrom(input, input_size, kIsKeyFrame);
const uint32_t kPts = 12345; const uint32_t kPts = 12345;
const uint32_t kDts = 12300; const uint32_t kDts = 12300;
@ -187,15 +187,15 @@ class PesPacketGeneratorTest : public ::testing::Test {
size_t input_size, size_t input_size,
const uint8_t* expected_output, const uint8_t* expected_output,
size_t expected_output_size) { size_t expected_output_size) {
scoped_refptr<AudioStreamInfo> stream_info( std::shared_ptr<AudioStreamInfo> stream_info(
CreateAudioStreamInfo(kAacCodec)); CreateAudioStreamInfo(kAacCodec));
EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_TRUE(generator_.Initialize(*stream_info));
EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets());
// For aac, the input from MediaSample is used. Then ADTS header is added, // For aac, the input from MediaSample is used. Then ADTS header is added,
// so EXPECT_CALL does not return the |input| data. // so EXPECT_CALL does not return the |input| data.
scoped_refptr<MediaSample> sample = MediaSample::CopyFrom( std::shared_ptr<MediaSample> sample =
input, input_size, kIsKeyFrame); MediaSample::CopyFrom(input, input_size, kIsKeyFrame);
std::unique_ptr<MockAACAudioSpecificConfig> mock( std::unique_ptr<MockAACAudioSpecificConfig> mock(
new MockAACAudioSpecificConfig()); new MockAACAudioSpecificConfig());
@ -223,41 +223,44 @@ class PesPacketGeneratorTest : public ::testing::Test {
}; };
TEST_F(PesPacketGeneratorTest, InitializeVideo) { TEST_F(PesPacketGeneratorTest, InitializeVideo) {
scoped_refptr<VideoStreamInfo> stream_info(CreateVideoStreamInfo(kH264Codec)); std::shared_ptr<VideoStreamInfo> stream_info(
CreateVideoStreamInfo(kH264Codec));
EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_TRUE(generator_.Initialize(*stream_info));
} }
TEST_F(PesPacketGeneratorTest, InitializeVideoNonH264) { TEST_F(PesPacketGeneratorTest, InitializeVideoNonH264) {
scoped_refptr<VideoStreamInfo> stream_info( std::shared_ptr<VideoStreamInfo> stream_info(
CreateVideoStreamInfo(Codec::kCodecVP9)); CreateVideoStreamInfo(Codec::kCodecVP9));
EXPECT_FALSE(generator_.Initialize(*stream_info)); EXPECT_FALSE(generator_.Initialize(*stream_info));
} }
TEST_F(PesPacketGeneratorTest, InitializeAudio) { TEST_F(PesPacketGeneratorTest, InitializeAudio) {
scoped_refptr<AudioStreamInfo> stream_info(CreateAudioStreamInfo(kAacCodec)); std::shared_ptr<AudioStreamInfo> stream_info(
CreateAudioStreamInfo(kAacCodec));
EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_TRUE(generator_.Initialize(*stream_info));
} }
TEST_F(PesPacketGeneratorTest, InitializeAudioNonAac) { TEST_F(PesPacketGeneratorTest, InitializeAudioNonAac) {
scoped_refptr<AudioStreamInfo> stream_info( std::shared_ptr<AudioStreamInfo> stream_info(
CreateAudioStreamInfo(Codec::kCodecOpus)); CreateAudioStreamInfo(Codec::kCodecOpus));
EXPECT_FALSE(generator_.Initialize(*stream_info)); EXPECT_FALSE(generator_.Initialize(*stream_info));
} }
// Text is not supported yet. // Text is not supported yet.
TEST_F(PesPacketGeneratorTest, InitializeTextInfo) { TEST_F(PesPacketGeneratorTest, InitializeTextInfo) {
scoped_refptr<TextStreamInfo> stream_info( std::shared_ptr<TextStreamInfo> stream_info(
new TextStreamInfo(kTrackId, kTimeScale, kDuration, kCodecString, new TextStreamInfo(kTrackId, kTimeScale, kDuration, kCodecString,
std::string(), kWidth, kHeight, kLanguage)); std::string(), kWidth, kHeight, kLanguage));
EXPECT_FALSE(generator_.Initialize(*stream_info)); EXPECT_FALSE(generator_.Initialize(*stream_info));
} }
TEST_F(PesPacketGeneratorTest, AddVideoSample) { TEST_F(PesPacketGeneratorTest, AddVideoSample) {
scoped_refptr<VideoStreamInfo> stream_info(CreateVideoStreamInfo(kH264Codec)); std::shared_ptr<VideoStreamInfo> stream_info(
CreateVideoStreamInfo(kH264Codec));
EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_TRUE(generator_.Initialize(*stream_info));
EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets());
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
const uint32_t kPts = 12345; const uint32_t kPts = 12345;
const uint32_t kDts = 12300; const uint32_t kDts = 12300;
@ -289,11 +292,12 @@ TEST_F(PesPacketGeneratorTest, AddVideoSample) {
} }
TEST_F(PesPacketGeneratorTest, AddVideoSampleFailedToConvert) { TEST_F(PesPacketGeneratorTest, AddVideoSampleFailedToConvert) {
scoped_refptr<VideoStreamInfo> stream_info(CreateVideoStreamInfo(kH264Codec)); std::shared_ptr<VideoStreamInfo> stream_info(
CreateVideoStreamInfo(kH264Codec));
EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_TRUE(generator_.Initialize(*stream_info));
EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets());
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
std::vector<uint8_t> expected_data(kAnyData, kAnyData + arraysize(kAnyData)); std::vector<uint8_t> expected_data(kAnyData, kAnyData + arraysize(kAnyData));
@ -311,11 +315,12 @@ TEST_F(PesPacketGeneratorTest, AddVideoSampleFailedToConvert) {
} }
TEST_F(PesPacketGeneratorTest, AddAudioSample) { TEST_F(PesPacketGeneratorTest, AddAudioSample) {
scoped_refptr<AudioStreamInfo> stream_info(CreateAudioStreamInfo(kAacCodec)); std::shared_ptr<AudioStreamInfo> stream_info(
CreateAudioStreamInfo(kAacCodec));
EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_TRUE(generator_.Initialize(*stream_info));
EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets());
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
std::vector<uint8_t> expected_data(kAnyData, kAnyData + arraysize(kAnyData)); std::vector<uint8_t> expected_data(kAnyData, kAnyData + arraysize(kAnyData));
@ -340,11 +345,12 @@ TEST_F(PesPacketGeneratorTest, AddAudioSample) {
} }
TEST_F(PesPacketGeneratorTest, AddAudioSampleFailedToConvert) { TEST_F(PesPacketGeneratorTest, AddAudioSampleFailedToConvert) {
scoped_refptr<AudioStreamInfo> stream_info(CreateAudioStreamInfo(kAacCodec)); std::shared_ptr<AudioStreamInfo> stream_info(
CreateAudioStreamInfo(kAacCodec));
EXPECT_TRUE(generator_.Initialize(*stream_info)); EXPECT_TRUE(generator_.Initialize(*stream_info));
EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets());
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
std::unique_ptr<MockAACAudioSpecificConfig> mock( std::unique_ptr<MockAACAudioSpecificConfig> mock(
@ -362,7 +368,7 @@ TEST_F(PesPacketGeneratorTest, AddAudioSampleFailedToConvert) {
// are scaled. // are scaled.
TEST_F(PesPacketGeneratorTest, TimeStampScaling) { TEST_F(PesPacketGeneratorTest, TimeStampScaling) {
const uint32_t kTestTimescale = 1000; const uint32_t kTestTimescale = 1000;
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTestTimescale, kDuration, kH264Codec, kCodecString, kTrackId, kTestTimescale, kDuration, kH264Codec, kCodecString,
kVideoExtraData, arraysize(kVideoExtraData), kWidth, kHeight, kPixelWidth, kVideoExtraData, arraysize(kVideoExtraData), kWidth, kHeight, kPixelWidth,
kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -370,7 +376,7 @@ TEST_F(PesPacketGeneratorTest, TimeStampScaling) {
EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets()); EXPECT_EQ(0u, generator_.NumberOfReadyPesPackets());
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
const uint32_t kPts = 5000; const uint32_t kPts = 5000;
const uint32_t kDts = 4000; const uint32_t kDts = 4000;

View File

@ -36,7 +36,7 @@ Status TsMuxer::Finalize() {
} }
Status TsMuxer::DoAddSample(const MediaStream* stream, Status TsMuxer::DoAddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) { std::shared_ptr<MediaSample> sample) {
return segmenter_->AddSample(sample); return segmenter_->AddSample(sample);
} }

View File

@ -27,7 +27,7 @@ class TsMuxer : public Muxer {
Status Initialize() override; Status Initialize() override;
Status Finalize() override; Status Finalize() override;
Status DoAddSample(const MediaStream* stream, Status DoAddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) override; std::shared_ptr<MediaSample> sample) override;
void FireOnMediaStartEvent(); void FireOnMediaStartEvent();
void FireOnMediaEndEvent(); void FireOnMediaEndEvent();

View File

@ -88,7 +88,7 @@ Status TsSegmenter::Finalize() {
// First checks whether the sample is a key frame. If so and the segment has // 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 // passed the segment duration, then flush the generator and write all the data
// to file. // to file.
Status TsSegmenter::AddSample(scoped_refptr<MediaSample> sample) { Status TsSegmenter::AddSample(std::shared_ptr<MediaSample> sample) {
const bool passed_segment_duration = const bool passed_segment_duration =
current_segment_total_sample_duration_ > muxer_options_.segment_duration; current_segment_total_sample_duration_ > muxer_options_.segment_duration;
if (sample->is_key_frame() && passed_segment_duration) { if (sample->is_key_frame() && passed_segment_duration) {

View File

@ -53,7 +53,7 @@ class TsSegmenter {
/// @param sample gets added to this object. /// @param sample gets added to this object.
/// @return OK on success. /// @return OK on success.
Status AddSample(scoped_refptr<MediaSample> sample); Status AddSample(std::shared_ptr<MediaSample> sample);
/// Only for testing. /// Only for testing.
void InjectTsWriterForTesting(std::unique_ptr<TsWriter> writer); void InjectTsWriterForTesting(std::unique_ptr<TsWriter> writer);

View File

@ -53,7 +53,7 @@ const uint8_t kAnyData[] = {
class MockPesPacketGenerator : public PesPacketGenerator { class MockPesPacketGenerator : public PesPacketGenerator {
public: public:
MOCK_METHOD1(Initialize, bool(const StreamInfo& info)); MOCK_METHOD1(Initialize, bool(const StreamInfo& info));
MOCK_METHOD1(PushSample, bool(scoped_refptr<MediaSample> sample)); MOCK_METHOD1(PushSample, bool(std::shared_ptr<MediaSample> sample));
MOCK_METHOD1(SetEncryptionKeyMock, bool(EncryptionKey* encryption_key)); MOCK_METHOD1(SetEncryptionKeyMock, bool(EncryptionKey* encryption_key));
bool SetEncryptionKey( bool SetEncryptionKey(
std::unique_ptr<EncryptionKey> encryption_key) override { std::unique_ptr<EncryptionKey> encryption_key) override {
@ -108,7 +108,7 @@ class TsSegmenterTest : public ::testing::Test {
}; };
TEST_F(TsSegmenterTest, Initialize) { TEST_F(TsSegmenterTest, Initialize) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -128,7 +128,7 @@ TEST_F(TsSegmenterTest, Initialize) {
} }
TEST_F(TsSegmenterTest, AddSample) { TEST_F(TsSegmenterTest, AddSample) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -141,7 +141,7 @@ TEST_F(TsSegmenterTest, AddSample) {
EXPECT_CALL(*mock_pes_packet_generator_, Initialize(_)) EXPECT_CALL(*mock_pes_packet_generator_, Initialize(_))
.WillOnce(Return(true)); .WillOnce(Return(true));
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
Sequence writer_sequence; Sequence writer_sequence;
@ -183,7 +183,7 @@ TEST_F(TsSegmenterTest, PassedSegmentDuration) {
// Use something significantly smaller than 90000 to check that the scaling is // Use something significantly smaller than 90000 to check that the scaling is
// done correctly in the segmenter. // done correctly in the segmenter.
const uint32_t kInputTimescale = 1001; const uint32_t kInputTimescale = 1001;
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kInputTimescale, kDuration, kH264Codec, kCodecString, kTrackId, kInputTimescale, kDuration, kH264Codec, kCodecString,
kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth,
kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -200,9 +200,9 @@ TEST_F(TsSegmenterTest, PassedSegmentDuration) {
EXPECT_CALL(*mock_pes_packet_generator_, Initialize(_)) EXPECT_CALL(*mock_pes_packet_generator_, Initialize(_))
.WillOnce(Return(true)); .WillOnce(Return(true));
scoped_refptr<MediaSample> sample1 = std::shared_ptr<MediaSample> sample1 =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
scoped_refptr<MediaSample> sample2 = std::shared_ptr<MediaSample> sample2 =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
// 11 seconds > 10 seconds (segment duration). // 11 seconds > 10 seconds (segment duration).
@ -282,7 +282,7 @@ TEST_F(TsSegmenterTest, PassedSegmentDuration) {
// Finalize right after Initialize(). The writer will not be initialized. // Finalize right after Initialize(). The writer will not be initialized.
TEST_F(TsSegmenterTest, InitializeThenFinalize) { TEST_F(TsSegmenterTest, InitializeThenFinalize) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); 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 // The test does not really add any samples but instead simulates an initialized
// writer with a mock. // writer with a mock.
TEST_F(TsSegmenterTest, Finalize) { TEST_F(TsSegmenterTest, Finalize) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); 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. // Verify that it won't finish a segment if the sample is not a key frame.
TEST_F(TsSegmenterTest, SegmentOnlyBeforeKeyFrame) { TEST_F(TsSegmenterTest, SegmentOnlyBeforeKeyFrame) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -356,11 +356,11 @@ TEST_F(TsSegmenterTest, SegmentOnlyBeforeKeyFrame) {
const uint8_t kAnyData[] = { const uint8_t kAnyData[] = {
0x01, 0x0F, 0x3C, 0x01, 0x0F, 0x3C,
}; };
scoped_refptr<MediaSample> key_frame_sample1 = std::shared_ptr<MediaSample> key_frame_sample1 =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
scoped_refptr<MediaSample> non_key_frame_sample = std::shared_ptr<MediaSample> non_key_frame_sample =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), !kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), !kIsKeyFrame);
scoped_refptr<MediaSample> key_frame_sample2 = std::shared_ptr<MediaSample> key_frame_sample2 =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
// 11 seconds > 10 seconds (segment duration). // 11 seconds > 10 seconds (segment duration).
@ -446,7 +446,7 @@ TEST_F(TsSegmenterTest, SegmentOnlyBeforeKeyFrame) {
} }
TEST_F(TsSegmenterTest, WithEncryptionNoClearLead) { TEST_F(TsSegmenterTest, WithEncryptionNoClearLead) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); 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 // Verify that the muxer listener pointer is not used without checking that it's
// not null. // not null.
TEST_F(TsSegmenterTest, WithEncryptionNoClearLeadNoMuxerListener) { TEST_F(TsSegmenterTest, WithEncryptionNoClearLeadNoMuxerListener) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -529,7 +529,7 @@ TEST_F(TsSegmenterTest, WithEncryptionNoClearLeadNoMuxerListener) {
// Verify that encryption notification is sent to objects after clear lead. // Verify that encryption notification is sent to objects after clear lead.
TEST_F(TsSegmenterTest, WithEncryptionWithClearLead) { TEST_F(TsSegmenterTest, WithEncryptionWithClearLead) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -555,9 +555,9 @@ TEST_F(TsSegmenterTest, WithEncryptionWithClearLead) {
const uint8_t kAnyData[] = { const uint8_t kAnyData[] = {
0x01, 0x0F, 0x3C, 0x01, 0x0F, 0x3C,
}; };
scoped_refptr<MediaSample> sample1 = std::shared_ptr<MediaSample> sample1 =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
scoped_refptr<MediaSample> sample2 = std::shared_ptr<MediaSample> sample2 =
MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame); MediaSample::CopyFrom(kAnyData, arraysize(kAnyData), kIsKeyFrame);
// Something longer than 1.0 (segment duration and clear lead). // Something longer than 1.0 (segment duration and clear lead).

View File

@ -157,7 +157,7 @@ class TsWriterTest : public ::testing::Test {
}; };
TEST_F(TsWriterTest, InitializeVideoH264) { TEST_F(TsWriterTest, InitializeVideoH264) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -165,7 +165,7 @@ TEST_F(TsWriterTest, InitializeVideoH264) {
} }
TEST_F(TsWriterTest, InitializeVideoNonH264) { TEST_F(TsWriterTest, InitializeVideoNonH264) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, Codec::kCodecVP9, kCodecString, kTrackId, kTimeScale, kDuration, Codec::kCodecVP9, kCodecString,
kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kExtraData, arraysize(kExtraData), kWidth, kHeight, kPixelWidth,
kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kPixelHeight, kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -173,7 +173,7 @@ TEST_F(TsWriterTest, InitializeVideoNonH264) {
} }
TEST_F(TsWriterTest, InitializeAudioAac) { TEST_F(TsWriterTest, InitializeAudioAac) {
scoped_refptr<AudioStreamInfo> stream_info(new AudioStreamInfo( std::shared_ptr<AudioStreamInfo> stream_info(new AudioStreamInfo(
kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kExtraData,
arraysize(kExtraData), kSampleBits, kNumChannels, kSamplingFrequency, arraysize(kExtraData), kSampleBits, kNumChannels, kSamplingFrequency,
kSeekPreroll, kCodecDelay, kMaxBitrate, kAverageBitrate, kLanguage, kSeekPreroll, kCodecDelay, kMaxBitrate, kAverageBitrate, kLanguage,
@ -182,7 +182,7 @@ TEST_F(TsWriterTest, InitializeAudioAac) {
} }
TEST_F(TsWriterTest, InitializeAudioNonAac) { TEST_F(TsWriterTest, InitializeAudioNonAac) {
scoped_refptr<AudioStreamInfo> stream_info(new AudioStreamInfo( std::shared_ptr<AudioStreamInfo> stream_info(new AudioStreamInfo(
kTrackId, kTimeScale, kDuration, Codec::kCodecOpus, kCodecString, kTrackId, kTimeScale, kDuration, Codec::kCodecOpus, kCodecString,
kExtraData, arraysize(kExtraData), kSampleBits, kNumChannels, kExtraData, arraysize(kExtraData), kSampleBits, kNumChannels,
kSamplingFrequency, kSeekPreroll, kCodecDelay, kMaxBitrate, kSamplingFrequency, kSeekPreroll, kCodecDelay, kMaxBitrate,
@ -198,7 +198,7 @@ TEST_F(TsWriterTest, ClearH264Psi) {
new MockProgramMapTableWriter()); new MockProgramMapTableWriter());
EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)).WillOnce(WriteOnePmt()); EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)).WillOnce(WriteOnePmt());
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -252,7 +252,7 @@ TEST_F(TsWriterTest, ClearAacPmt) {
new MockProgramMapTableWriter()); new MockProgramMapTableWriter());
EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)).WillOnce(WriteOnePmt()); EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)).WillOnce(WriteOnePmt());
scoped_refptr<AudioStreamInfo> stream_info(new AudioStreamInfo( std::shared_ptr<AudioStreamInfo> stream_info(new AudioStreamInfo(
kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString,
kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData), kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData),
kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay,
@ -280,7 +280,7 @@ TEST_F(TsWriterTest, ClearLeadH264Pmt) {
EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)) EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_))
.WillOnce(WriteTwoPmts()); .WillOnce(WriteTwoPmts());
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); 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, ClearSegmentPmt(_)).WillOnce(Return(true));
EXPECT_CALL(*mock_pmt_writer, EncryptedSegmentPmt(_)).WillOnce(WriteOnePmt()); EXPECT_CALL(*mock_pmt_writer, EncryptedSegmentPmt(_)).WillOnce(WriteOnePmt());
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -340,7 +340,7 @@ TEST_F(TsWriterTest, ClearLeadAacPmt) {
EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_)) EXPECT_CALL(*mock_pmt_writer, ClearSegmentPmt(_))
.WillOnce(WriteTwoPmts()); .WillOnce(WriteTwoPmts());
scoped_refptr<AudioStreamInfo> stream_info(new AudioStreamInfo( std::shared_ptr<AudioStreamInfo> stream_info(new AudioStreamInfo(
kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString,
kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData), kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData),
kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, 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, ClearSegmentPmt(_)).WillOnce(Return(true));
EXPECT_CALL(*mock_pmt_writer, EncryptedSegmentPmt(_)).WillOnce(WriteOnePmt()); EXPECT_CALL(*mock_pmt_writer, EncryptedSegmentPmt(_)).WillOnce(WriteOnePmt());
scoped_refptr<AudioStreamInfo> stream_info(new AudioStreamInfo( std::shared_ptr<AudioStreamInfo> stream_info(new AudioStreamInfo(
kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString, kTrackId, kTimeScale, kDuration, kAacCodec, kCodecString,
kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData), kAacBasicProfileExtraData, arraysize(kAacBasicProfileExtraData),
kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay, kSampleBits, kNumChannels, kSamplingFrequency, kSeekPreroll, kCodecDelay,
@ -397,7 +397,7 @@ TEST_F(TsWriterTest, EncryptedSegmentsAacPmt) {
TEST_F(TsWriterTest, AddPesPacket) { TEST_F(TsWriterTest, AddPesPacket) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -462,7 +462,7 @@ TEST_F(TsWriterTest, AddPesPacket) {
// Verify that PES packet > 64KiB can be handled. // Verify that PES packet > 64KiB can be handled.
TEST_F(TsWriterTest, BigPesPacket) { TEST_F(TsWriterTest, BigPesPacket) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); 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 // Bug found in code review. It should check whether PTS is present not whether
// PTS (implicilty) cast to bool is true. // PTS (implicilty) cast to bool is true.
TEST_F(TsWriterTest, PesPtsZeroNoDts) { TEST_F(TsWriterTest, PesPtsZeroNoDts) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));
@ -558,7 +558,7 @@ TEST_F(TsWriterTest, PesPtsZeroNoDts) {
// Verify that TS packet with payload 183 is handled correctly, e.g. // Verify that TS packet with payload 183 is handled correctly, e.g.
// adaptation_field_length should be 0. // adaptation_field_length should be 0.
TEST_F(TsWriterTest, TsPacketPayload183Bytes) { TEST_F(TsWriterTest, TsPacketPayload183Bytes) {
scoped_refptr<VideoStreamInfo> stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> stream_info(new VideoStreamInfo(
kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData, kTrackId, kTimeScale, kDuration, kH264Codec, kCodecString, kExtraData,
arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight, arraysize(kExtraData), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, kIsEncrypted));

View File

@ -59,7 +59,7 @@ uint8_t GetNaluLengthSize(const StreamInfo& stream_info) {
} // namespace } // namespace
EncryptingFragmenter::EncryptingFragmenter( EncryptingFragmenter::EncryptingFragmenter(
scoped_refptr<StreamInfo> info, std::shared_ptr<StreamInfo> info,
TrackFragment* traf, TrackFragment* traf,
std::unique_ptr<EncryptionKey> encryption_key, std::unique_ptr<EncryptionKey> encryption_key,
int64_t clear_time, int64_t clear_time,
@ -103,7 +103,7 @@ EncryptingFragmenter::EncryptingFragmenter(
EncryptingFragmenter::~EncryptingFragmenter() {} EncryptingFragmenter::~EncryptingFragmenter() {}
Status EncryptingFragmenter::AddSample(scoped_refptr<MediaSample> sample) { Status EncryptingFragmenter::AddSample(std::shared_ptr<MediaSample> sample) {
DCHECK(sample); DCHECK(sample);
if (!fragment_initialized()) { if (!fragment_initialized()) {
Status status = InitializeFragment(sample->dts()); Status status = InitializeFragment(sample->dts());
@ -248,7 +248,8 @@ void EncryptingFragmenter::EncryptBytes(uint8_t* data, size_t size) {
CHECK(encryptor_->Crypt(data, size, data)); CHECK(encryptor_->Crypt(data, size, data));
} }
Status EncryptingFragmenter::EncryptSample(scoped_refptr<MediaSample> sample) { Status EncryptingFragmenter::EncryptSample(
std::shared_ptr<MediaSample> sample) {
DCHECK(encryptor_); DCHECK(encryptor_);
SampleEncryptionEntry sample_encryption_entry; SampleEncryptionEntry sample_encryption_entry;

View File

@ -8,7 +8,6 @@
#define MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_ #define MEDIA_FORMATS_MP4_ENCRYPTING_FRAGMENTER_H_
#include <memory> #include <memory>
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/fourccs.h" #include "packager/media/base/fourccs.h"
#include "packager/media/codecs/video_slice_header_parser.h" #include "packager/media/codecs/video_slice_header_parser.h"
#include "packager/media/codecs/vpx_parser.h" #include "packager/media/codecs/vpx_parser.h"
@ -38,7 +37,7 @@ class EncryptingFragmenter : public Fragmenter {
/// pattern based encryption. /// pattern based encryption.
/// @param skip_byte_block indicates number of unencrypted blocks (16-byte) /// @param skip_byte_block indicates number of unencrypted blocks (16-byte)
/// in pattern based encryption. /// in pattern based encryption.
EncryptingFragmenter(scoped_refptr<StreamInfo> info, EncryptingFragmenter(std::shared_ptr<StreamInfo> info,
TrackFragment* traf, TrackFragment* traf,
std::unique_ptr<EncryptionKey> encryption_key, std::unique_ptr<EncryptionKey> encryption_key,
int64_t clear_time, int64_t clear_time,
@ -51,7 +50,7 @@ class EncryptingFragmenter : public Fragmenter {
/// @name Fragmenter implementation overrides. /// @name Fragmenter implementation overrides.
/// @{ /// @{
Status AddSample(scoped_refptr<MediaSample> sample) override; Status AddSample(std::shared_ptr<MediaSample> sample) override;
Status InitializeFragment(int64_t first_sample_dts) override; Status InitializeFragment(int64_t first_sample_dts) override;
void FinalizeFragment() override; void FinalizeFragment() override;
/// @} /// @}
@ -80,12 +79,12 @@ class EncryptingFragmenter : public Fragmenter {
private: private:
void EncryptBytes(uint8_t* data, size_t size); void EncryptBytes(uint8_t* data, size_t size);
Status EncryptSample(scoped_refptr<MediaSample> sample); Status EncryptSample(std::shared_ptr<MediaSample> sample);
// Should we enable subsample encryption? // Should we enable subsample encryption?
bool IsSubsampleEncryptionRequired(); bool IsSubsampleEncryptionRequired();
scoped_refptr<StreamInfo> info_; std::shared_ptr<StreamInfo> info_;
std::unique_ptr<EncryptionKey> encryption_key_; std::unique_ptr<EncryptionKey> encryption_key_;
std::unique_ptr<AesCryptor> encryptor_; std::unique_ptr<AesCryptor> encryptor_;
// If this stream contains AVC, subsample encryption specifies that the size // If this stream contains AVC, subsample encryption specifies that the size

View File

@ -29,7 +29,7 @@ uint64_t GetSeekPreroll(const StreamInfo& stream_info) {
} }
} // namespace } // namespace
Fragmenter::Fragmenter(scoped_refptr<StreamInfo> info, TrackFragment* traf) Fragmenter::Fragmenter(std::shared_ptr<StreamInfo> info, TrackFragment* traf)
: use_decoding_timestamp_in_timeline_(false), : use_decoding_timestamp_in_timeline_(false),
traf_(traf), traf_(traf),
seek_preroll_(GetSeekPreroll(*info)), seek_preroll_(GetSeekPreroll(*info)),
@ -43,7 +43,7 @@ Fragmenter::Fragmenter(scoped_refptr<StreamInfo> info, TrackFragment* traf)
Fragmenter::~Fragmenter() {} Fragmenter::~Fragmenter() {}
Status Fragmenter::AddSample(scoped_refptr<MediaSample> sample) { Status Fragmenter::AddSample(std::shared_ptr<MediaSample> sample) {
DCHECK(sample); DCHECK(sample);
if (sample->duration() == 0) { if (sample->duration() == 0) {
LOG(WARNING) << "Unexpected sample with zero duration @ dts " LOG(WARNING) << "Unexpected sample with zero duration @ dts "

View File

@ -11,7 +11,6 @@
#include <vector> #include <vector>
#include "packager/base/logging.h" #include "packager/base/logging.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/status.h" #include "packager/media/base/status.h"
namespace shaka { namespace shaka {
@ -32,14 +31,14 @@ class Fragmenter {
public: public:
/// @param info contains stream information. /// @param info contains stream information.
/// @param traf points to a TrackFragment box. /// @param traf points to a TrackFragment box.
Fragmenter(scoped_refptr<StreamInfo> info, TrackFragment* traf); Fragmenter(std::shared_ptr<StreamInfo> info, TrackFragment* traf);
virtual ~Fragmenter(); virtual ~Fragmenter();
/// Add a sample to the fragmenter. /// Add a sample to the fragmenter.
/// @param sample points to the sample to be added. /// @param sample points to the sample to be added.
/// @return OK on success, an error status otherwise. /// @return OK on success, an error status otherwise.
virtual Status AddSample(scoped_refptr<MediaSample> sample); virtual Status AddSample(std::shared_ptr<MediaSample> sample);
/// Initialize the fragment with default data. /// Initialize the fragment with default data.
/// @param first_sample_dts specifies the decoding timestamp for the first /// @param first_sample_dts specifies the decoding timestamp for the first

View File

@ -18,7 +18,7 @@ const bool kInitialEncryptionInfo = true;
} // namespace } // namespace
KeyRotationFragmenter::KeyRotationFragmenter(MovieFragment* moof, KeyRotationFragmenter::KeyRotationFragmenter(MovieFragment* moof,
scoped_refptr<StreamInfo> info, std::shared_ptr<StreamInfo> info,
TrackFragment* traf, TrackFragment* traf,
KeySource* encryption_key_source, KeySource* encryption_key_source,
KeySource::TrackType track_type, KeySource::TrackType track_type,

View File

@ -42,7 +42,7 @@ class KeyRotationFragmenter : public EncryptingFragmenter {
/// @param muxer_listener is a pointer to MuxerListener for notifying /// @param muxer_listener is a pointer to MuxerListener for notifying
/// muxer related events. This may be null. /// muxer related events. This may be null.
KeyRotationFragmenter(MovieFragment* moof, KeyRotationFragmenter(MovieFragment* moof,
scoped_refptr<StreamInfo> info, std::shared_ptr<StreamInfo> info,
TrackFragment* traf, TrackFragment* traf,
KeySource* encryption_key_source, KeySource* encryption_key_source,
KeySource::TrackType track_type, KeySource::TrackType track_type,

View File

@ -10,7 +10,6 @@
#include "packager/base/callback.h" #include "packager/base/callback.h"
#include "packager/base/callback_helpers.h" #include "packager/base/callback_helpers.h"
#include "packager/base/logging.h" #include "packager/base/logging.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_number_conversions.h"
#include "packager/media/base/audio_stream_info.h" #include "packager/media/base/audio_stream_info.h"
#include "packager/media/base/buffer_reader.h" #include "packager/media/base/buffer_reader.h"
@ -281,7 +280,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) {
RCHECK(moov_->Parse(reader)); RCHECK(moov_->Parse(reader));
runs_.reset(); runs_.reset();
std::vector<scoped_refptr<StreamInfo> > streams; std::vector<std::shared_ptr<StreamInfo>> streams;
for (std::vector<Track>::const_iterator track = moov_->tracks.begin(); for (std::vector<Track>::const_iterator track = moov_->tracks.begin();
track != moov_->tracks.end(); ++track) { track != moov_->tracks.end(); ++track) {
@ -466,7 +465,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) {
const bool is_encrypted = const bool is_encrypted =
entry.sinf.info.track_encryption.default_is_protected == 1; entry.sinf.info.track_encryption.default_is_protected == 1;
DVLOG(1) << "is_audio_track_encrypted_: " << is_encrypted; 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, track->header.track_id, timescale, duration, codec,
AudioStreamInfo::GetCodecString(codec, audio_object_type), AudioStreamInfo::GetCodecString(codec, audio_object_type),
codec_config.data(), codec_config.size(), entry.samplesize, codec_config.data(), codec_config.size(), entry.samplesize,
@ -562,7 +561,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) {
const bool is_encrypted = const bool is_encrypted =
entry.sinf.info.track_encryption.default_is_protected == 1; entry.sinf.info.track_encryption.default_is_protected == 1;
DVLOG(1) << "is_video_track_encrypted_: " << is_encrypted; DVLOG(1) << "is_video_track_encrypted_: " << is_encrypted;
scoped_refptr<VideoStreamInfo> video_stream_info(new VideoStreamInfo( std::shared_ptr<VideoStreamInfo> video_stream_info(new VideoStreamInfo(
track->header.track_id, timescale, duration, video_codec, track->header.track_id, timescale, duration, video_codec,
codec_string, entry.codec_configuration.data.data(), codec_string, entry.codec_configuration.data.data(),
entry.codec_configuration.data.size(), coded_width, coded_height, entry.codec_configuration.data.size(), coded_width, coded_height,
@ -694,8 +693,8 @@ bool MP4MediaParser::EnqueueSample(bool* err) {
return false; return false;
} }
scoped_refptr<MediaSample> stream_sample(MediaSample::CopyFrom( std::shared_ptr<MediaSample> stream_sample(
buf, runs_->sample_size(), runs_->is_keyframe())); MediaSample::CopyFrom(buf, runs_->sample_size(), runs_->is_keyframe()));
if (runs_->is_encrypted()) { if (runs_->is_encrypted()) {
std::unique_ptr<DecryptConfig> decrypt_config = runs_->GetDecryptConfig(); std::unique_ptr<DecryptConfig> decrypt_config = runs_->GetDecryptConfig();
if (!decrypt_config) { if (!decrypt_config) {

View File

@ -14,7 +14,6 @@
#include <vector> #include <vector>
#include "packager/base/callback_forward.h" #include "packager/base/callback_forward.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/decryptor_source.h" #include "packager/media/base/decryptor_source.h"
#include "packager/media/base/media_parser.h" #include "packager/media/base/media_parser.h"
#include "packager/media/base/offset_byte_queue.h" #include "packager/media/base/offset_byte_queue.h"

View File

@ -46,7 +46,7 @@ class MP4MediaParserTest : public testing::Test {
} }
protected: protected:
typedef std::map<int, scoped_refptr<StreamInfo> > StreamMap; typedef std::map<int, std::shared_ptr<StreamInfo>> StreamMap;
StreamMap stream_map_; StreamMap stream_map_;
std::unique_ptr<MP4MediaParser> parser_; std::unique_ptr<MP4MediaParser> parser_;
size_t num_streams_; size_t num_streams_;
@ -71,19 +71,17 @@ class MP4MediaParserTest : public testing::Test {
return true; return true;
} }
void InitF(const std::vector<scoped_refptr<StreamInfo> >& streams) { void InitF(const std::vector<std::shared_ptr<StreamInfo>>& streams) {
for (std::vector<scoped_refptr<StreamInfo> >::const_iterator iter = for (const auto& stream_info : streams) {
streams.begin(); DVLOG(2) << stream_info->ToString();
iter != streams.end(); stream_map_[stream_info->track_id()] = stream_info;
++iter) {
DVLOG(2) << (*iter)->ToString();
stream_map_[(*iter)->track_id()] = *iter;
} }
num_streams_ = streams.size(); num_streams_ = streams.size();
num_samples_ = 0; num_samples_ = 0;
} }
bool NewSampleF(uint32_t track_id, const scoped_refptr<MediaSample>& sample) { bool NewSampleF(uint32_t track_id,
const std::shared_ptr<MediaSample>& sample) {
DVLOG(2) << "Track Id: " << track_id << " " DVLOG(2) << "Track Id: " << track_id << " "
<< sample->ToString(); << sample->ToString();
++num_samples_; ++num_samples_;

View File

@ -168,7 +168,7 @@ Status MP4Muxer::Finalize() {
} }
Status MP4Muxer::DoAddSample(const MediaStream* stream, Status MP4Muxer::DoAddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) { std::shared_ptr<MediaSample> sample) {
DCHECK(segmenter_); DCHECK(segmenter_);
return segmenter_->AddSample(stream, sample); return segmenter_->AddSample(stream, sample);
} }

View File

@ -38,7 +38,7 @@ class MP4Muxer : public Muxer {
Status Initialize() override; Status Initialize() override;
Status Finalize() override; Status Finalize() override;
Status DoAddSample(const MediaStream* stream, Status DoAddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) override; std::shared_ptr<MediaSample> sample) override;
// Generate Audio/Video Track box. // Generate Audio/Video Track box.
void InitializeTrak(const StreamInfo* info, Track* trak); void InitializeTrak(const StreamInfo* info, Track* trak);

View File

@ -321,7 +321,7 @@ Status Segmenter::Finalize() {
} }
Status Segmenter::AddSample(const MediaStream* stream, Status Segmenter::AddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) { std::shared_ptr<MediaSample> sample) {
// Find the fragmenter for this stream. // Find the fragmenter for this stream.
DCHECK(stream); DCHECK(stream);
DCHECK(stream_map_.find(stream) != stream_map_.end()); DCHECK(stream_map_.find(stream) != stream_map_.end());

View File

@ -11,7 +11,6 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/fourccs.h" #include "packager/media/base/fourccs.h"
#include "packager/media/base/status.h" #include "packager/media/base/status.h"
#include "packager/media/formats/mp4/box_definitions.h" #include "packager/media/formats/mp4/box_definitions.h"
@ -91,7 +90,7 @@ class Segmenter {
/// @param sample points to the sample to be added. /// @param sample points to the sample to be added.
/// @return OK on success, an error status otherwise. /// @return OK on success, an error status otherwise.
Status AddSample(const MediaStream* stream, Status AddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample); std::shared_ptr<MediaSample> sample);
/// @return true if there is an initialization range, while setting @a offset /// @return true if there is an initialization range, while setting @a offset
/// and @a size; or false if initialization range does not apply. /// and @a size; or false if initialization range does not apply.

View File

@ -203,7 +203,7 @@ class EncrypedSegmenterTest : public SegmentTestBase {
options, info_.get(), key_source_.get(), &segmenter_)); options, info_.get(), key_source_.get(), &segmenter_));
} }
scoped_refptr<StreamInfo> info_; std::shared_ptr<StreamInfo> info_;
std::unique_ptr<webm::Segmenter> segmenter_; std::unique_ptr<webm::Segmenter> segmenter_;
std::unique_ptr<KeySource> key_source_; std::unique_ptr<KeySource> key_source_;
}; };
@ -217,7 +217,7 @@ TEST_F(EncrypedSegmenterTest, BasicSupport) {
// There should be 2 segments with the first segment in clear and the second // There should be 2 segments with the first segment in clear and the second
// segment encrypted. // segment encrypted.
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(kKeyFrame, kDuration, kNoSideData); CreateSample(kKeyFrame, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }

View File

@ -73,7 +73,7 @@ Status Encryptor::AddTrackInfo(mkvmuxer::Track* track) {
return CreateContentEncryption(track, key_.get()); return CreateContentEncryption(track, key_.get());
} }
Status Encryptor::EncryptFrame(scoped_refptr<MediaSample> sample, Status Encryptor::EncryptFrame(std::shared_ptr<MediaSample> sample,
bool encrypt_frame) { bool encrypt_frame) {
DCHECK(encryptor_); DCHECK(encryptor_);

View File

@ -9,7 +9,6 @@
#include <memory> #include <memory>
#include "packager/base/macros.h" #include "packager/base/macros.h"
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/key_source.h" #include "packager/media/base/key_source.h"
#include "packager/media/base/status.h" #include "packager/media/base/status.h"
#include "packager/media/base/stream_info.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 /// Encrypt the data. This needs to be told whether the current frame will
/// be encrypted (e.g. for a clear lead). /// be encrypted (e.g. for a clear lead).
/// @return OK on success, an error status otherwise. /// @return OK on success, an error status otherwise.
Status EncryptFrame(scoped_refptr<MediaSample> sample, Status EncryptFrame(std::shared_ptr<MediaSample> sample, bool encrypt_frame);
bool encrypt_frame);
private: private:
// Create the encryptor for the internal encryption key. // Create the encryptor for the internal encryption key.

View File

@ -108,7 +108,7 @@ class MultiSegmentSegmenterTest : public SegmentTestBase {
return GetSegmentName(segment_template_, 0, number, 0); return GetSegmentName(segment_template_, 0, number, 0);
} }
scoped_refptr<StreamInfo> info_; std::shared_ptr<StreamInfo> info_;
std::string segment_template_; std::string segment_template_;
std::unique_ptr<webm::Segmenter> segmenter_; std::unique_ptr<webm::Segmenter> segmenter_;
}; };
@ -120,7 +120,7 @@ TEST_F(MultiSegmentSegmenterTest, BasicSupport) {
// Write the samples to the Segmenter. // Write the samples to the Segmenter.
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(kKeyFrame, kDuration, kNoSideData); CreateSample(kKeyFrame, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }
@ -142,7 +142,7 @@ TEST_F(MultiSegmentSegmenterTest, SplitsFilesOnSegmentDuration) {
// Write the samples to the Segmenter. // Write the samples to the Segmenter.
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(kKeyFrame, kDuration, kNoSideData); CreateSample(kKeyFrame, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }
@ -171,7 +171,7 @@ TEST_F(MultiSegmentSegmenterTest, RespectsSegmentSAPAlign) {
// Write the samples to the Segmenter. // Write the samples to the Segmenter.
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame; const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame;
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(key_frame_flag, kDuration, kNoSideData); CreateSample(key_frame_flag, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }
@ -198,7 +198,7 @@ TEST_F(MultiSegmentSegmenterTest, SplitsClustersOnFragmentDuration) {
// Write the samples to the Segmenter. // Write the samples to the Segmenter.
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(kKeyFrame, kDuration, kNoSideData); CreateSample(kKeyFrame, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }
@ -224,7 +224,7 @@ TEST_F(MultiSegmentSegmenterTest, RespectsFragmentSAPAlign) {
// Write the samples to the Segmenter. // Write the samples to the Segmenter.
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame; const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame;
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(key_frame_flag, kDuration, kNoSideData); CreateSample(key_frame_flag, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }

View File

@ -121,7 +121,7 @@ Status Segmenter::Finalize() {
return DoFinalize(); return DoFinalize();
} }
Status Segmenter::AddSample(scoped_refptr<MediaSample> sample) { Status Segmenter::AddSample(std::shared_ptr<MediaSample> sample) {
if (sample_duration_ == 0) { if (sample_duration_ == 0) {
first_timestamp_ = sample->pts(); first_timestamp_ = sample->pts();
sample_duration_ = sample->duration(); sample_duration_ = sample->duration();

View File

@ -8,7 +8,6 @@
#define MEDIA_FORMATS_WEBM_SEGMENTER_H_ #define MEDIA_FORMATS_WEBM_SEGMENTER_H_
#include <memory> #include <memory>
#include "packager/base/memory/ref_counted.h"
#include "packager/media/base/status.h" #include "packager/media/base/status.h"
#include "packager/media/formats/webm/encryptor.h" #include "packager/media/formats/webm/encryptor.h"
#include "packager/media/formats/webm/mkv_writer.h" #include "packager/media/formats/webm/mkv_writer.h"
@ -75,7 +74,7 @@ class Segmenter {
/// Add sample to the indicated stream. /// Add sample to the indicated stream.
/// @param sample points to the sample to be added. /// @param sample points to the sample to be added.
/// @return OK on success, an error status otherwise. /// @return OK on success, an error status otherwise.
Status AddSample(scoped_refptr<MediaSample> sample); Status AddSample(std::shared_ptr<MediaSample> sample);
/// @return true if there is an initialization range, while setting @a start /// @return true if there is an initialization range, while setting @a start
/// and @a end; or false if initialization range does not apply. /// 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; virtual Status NewSegment(uint64_t start_timescale) = 0;
// Store the previous sample so we know which one is the last frame. // Store the previous sample so we know which one is the last frame.
scoped_refptr<MediaSample> prev_sample_; std::shared_ptr<MediaSample> prev_sample_;
// The reference frame timestamp; used to populate the ReferenceBlock element // The reference frame timestamp; used to populate the ReferenceBlock element
// when writing non-keyframe BlockGroups. // when writing non-keyframe BlockGroups.
uint64_t reference_frame_timestamp_; uint64_t reference_frame_timestamp_;

View File

@ -49,11 +49,11 @@ void SegmentTestBase::TearDown() {
MemoryFile::DeleteAll(); MemoryFile::DeleteAll();
} }
scoped_refptr<MediaSample> SegmentTestBase::CreateSample( std::shared_ptr<MediaSample> SegmentTestBase::CreateSample(
KeyFrameFlag key_frame_flag, KeyFrameFlag key_frame_flag,
uint64_t duration, uint64_t duration,
SideDataFlag side_data_flag) { SideDataFlag side_data_flag) {
scoped_refptr<MediaSample> sample; std::shared_ptr<MediaSample> sample;
const bool is_key_frame = key_frame_flag == kKeyFrame; const bool is_key_frame = key_frame_flag == kKeyFrame;
if (side_data_flag == kGenerateSideData) { if (side_data_flag == kGenerateSideData) {
sample = MediaSample::CopyFrom( sample = MediaSample::CopyFrom(

View File

@ -62,9 +62,9 @@ class SegmentTestBase : public ::testing::Test {
} }
/// Creates a new media sample. /// Creates a new media sample.
scoped_refptr<MediaSample> CreateSample(KeyFrameFlag key_frame_flag, std::shared_ptr<MediaSample> CreateSample(KeyFrameFlag key_frame_flag,
uint64_t duration, uint64_t duration,
SideDataFlag side_data_flag); SideDataFlag side_data_flag);
/// Creates a Muxer options object for testing. /// Creates a Muxer options object for testing.
MuxerOptions CreateMuxerOptions() const; MuxerOptions CreateMuxerOptions() const;
/// Creates a video stream info object for testing. /// Creates a video stream info object for testing.

View File

@ -143,7 +143,7 @@ class SingleSegmentSegmenterTest : public SegmentTestBase {
options, info_.get(), NULL, &segmenter_)); options, info_.get(), NULL, &segmenter_));
} }
scoped_refptr<StreamInfo> info_; std::shared_ptr<StreamInfo> info_;
std::unique_ptr<webm::Segmenter> segmenter_; std::unique_ptr<webm::Segmenter> segmenter_;
}; };
@ -155,7 +155,7 @@ TEST_F(SingleSegmentSegmenterTest, BasicSupport) {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
const SideDataFlag side_data_flag = const SideDataFlag side_data_flag =
i == 3 ? kGenerateSideData : kNoSideData; i == 3 ? kGenerateSideData : kNoSideData;
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(kKeyFrame, kDuration, side_data_flag); CreateSample(kKeyFrame, kDuration, side_data_flag);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }
@ -171,7 +171,7 @@ TEST_F(SingleSegmentSegmenterTest, SplitsClustersOnSegmentDuration) {
// Write the samples to the Segmenter. // Write the samples to the Segmenter.
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(kKeyFrame, kDuration, kNoSideData); CreateSample(kKeyFrame, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }
@ -192,7 +192,7 @@ TEST_F(SingleSegmentSegmenterTest, IgnoresFragmentDuration) {
// Write the samples to the Segmenter. // Write the samples to the Segmenter.
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(kKeyFrame, kDuration, kNoSideData); CreateSample(kKeyFrame, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }
@ -214,7 +214,7 @@ TEST_F(SingleSegmentSegmenterTest, RespectsSAPAlign) {
// Write the samples to the Segmenter. // Write the samples to the Segmenter.
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame; const KeyFrameFlag key_frame_flag = i == 6 ? kKeyFrame : kNotKeyFrame;
scoped_refptr<MediaSample> sample = std::shared_ptr<MediaSample> sample =
CreateSample(key_frame_flag, kDuration, kNoSideData); CreateSample(key_frame_flag, kDuration, kNoSideData);
ASSERT_OK(segmenter_->AddSample(sample)); ASSERT_OK(segmenter_->AddSample(sample));
} }

View File

@ -28,7 +28,7 @@ void WebMAudioClient::Reset() {
output_samples_per_second_ = -1; output_samples_per_second_ = -1;
} }
scoped_refptr<AudioStreamInfo> WebMAudioClient::GetAudioStreamInfo( std::shared_ptr<AudioStreamInfo> WebMAudioClient::GetAudioStreamInfo(
int64_t track_num, int64_t track_num,
const std::string& codec_id, const std::string& codec_id,
const std::vector<uint8_t>& codec_private, const std::vector<uint8_t>& codec_private,
@ -43,11 +43,11 @@ scoped_refptr<AudioStreamInfo> WebMAudioClient::GetAudioStreamInfo(
audio_codec = kCodecOpus; audio_codec = kCodecOpus;
} else { } else {
LOG(ERROR) << "Unsupported audio codec_id " << codec_id; LOG(ERROR) << "Unsupported audio codec_id " << codec_id;
return scoped_refptr<AudioStreamInfo>(); return std::shared_ptr<AudioStreamInfo>();
} }
if (samples_per_second_ <= 0) if (samples_per_second_ <= 0)
return scoped_refptr<AudioStreamInfo>(); return std::shared_ptr<AudioStreamInfo>();
// Set channel layout default if a Channels element was not present. // Set channel layout default if a Channels element was not present.
if (channels_ == -1) if (channels_ == -1)
@ -68,12 +68,12 @@ scoped_refptr<AudioStreamInfo> WebMAudioClient::GetAudioStreamInfo(
} }
const uint8_t kSampleSizeInBits = 16u; const uint8_t kSampleSizeInBits = 16u;
return scoped_refptr<AudioStreamInfo>(new AudioStreamInfo( return std::make_shared<AudioStreamInfo>(
track_num, kWebMTimeScale, 0, audio_codec, track_num, kWebMTimeScale, 0, audio_codec,
AudioStreamInfo::GetCodecString(audio_codec, 0), codec_config, AudioStreamInfo::GetCodecString(audio_codec, 0), codec_config,
codec_config_size, kSampleSizeInBits, channels_, sampling_frequency, codec_config_size, kSampleSizeInBits, channels_, sampling_frequency,
seek_preroll < 0 ? 0 : seek_preroll, codec_delay < 0 ? 0 : codec_delay, 0, 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) { bool WebMAudioClient::OnUInt(int id, int64_t val) {

View File

@ -37,10 +37,10 @@ class WebMAudioClient : public WebMParserClient {
/// value of 0 is used. /// value of 0 is used.
/// @param language indicates the language for the track. /// @param language indicates the language for the track.
/// @param is_encrypted indicates whether the stream is encrypted. /// @param is_encrypted indicates whether the stream is encrypted.
/// @return An AudioStreamInfo scoped_refptr if successful. /// @return An AudioStreamInfo if successful.
/// @return An empty scoped_refptr if there was unexpected values in the /// @return An empty pointer if there was unexpected values in the
/// provided parameters or audio track element fields. /// provided parameters or audio track element fields.
scoped_refptr<AudioStreamInfo> GetAudioStreamInfo( std::shared_ptr<AudioStreamInfo> GetAudioStreamInfo(
int64_t track_num, int64_t track_num,
const std::string& codec_id, const std::string& codec_id,
const std::vector<uint8_t>& codec_private, const std::vector<uint8_t>& codec_private,

View File

@ -28,8 +28,8 @@ const int64_t kMicrosecondsPerMillisecond = 1000;
WebMClusterParser::WebMClusterParser( WebMClusterParser::WebMClusterParser(
int64_t timecode_scale, int64_t timecode_scale,
scoped_refptr<AudioStreamInfo> audio_stream_info, std::shared_ptr<AudioStreamInfo> audio_stream_info,
scoped_refptr<VideoStreamInfo> video_stream_info, std::shared_ptr<VideoStreamInfo> video_stream_info,
int64_t audio_default_duration, int64_t audio_default_duration,
int64_t video_default_duration, int64_t video_default_duration,
const WebMTracksParser::TextTracks& text_tracks, const WebMTracksParser::TextTracks& text_tracks,
@ -352,7 +352,7 @@ bool WebMClusterParser::OnBlock(bool is_simple_block,
int64_t timestamp = (cluster_timecode_ + timecode) * timecode_multiplier_; int64_t timestamp = (cluster_timecode_ + timecode) * timecode_multiplier_;
scoped_refptr<MediaSample> buffer; std::shared_ptr<MediaSample> buffer;
if (stream_type != kStreamText) { if (stream_type != kStreamText) {
// Every encrypted Block has a signal byte and IV prepended to it. Current // Every encrypted Block has a signal byte and IV prepended to it. Current
// encrypted WebM request for comments specification is here // encrypted WebM request for comments specification is here
@ -407,7 +407,7 @@ bool WebMClusterParser::OnBlock(bool is_simple_block,
: kNoTimestamp); : kNoTimestamp);
if (!init_cb_.is_null() && !initialized_) { if (!init_cb_.is_null() && !initialized_) {
std::vector<scoped_refptr<StreamInfo>> streams; std::vector<std::shared_ptr<StreamInfo>> streams;
if (audio_stream_info_) if (audio_stream_info_)
streams.push_back(audio_stream_info_); streams.push_back(audio_stream_info_);
if (video_stream_info_) { if (video_stream_info_) {
@ -474,7 +474,7 @@ WebMClusterParser::Track::Track(int track_num,
WebMClusterParser::Track::~Track() {} WebMClusterParser::Track::~Track() {}
bool WebMClusterParser::Track::EmitBuffer( bool WebMClusterParser::Track::EmitBuffer(
const scoped_refptr<MediaSample>& buffer) { const std::shared_ptr<MediaSample>& buffer) {
DVLOG(2) << "EmitBuffer() : " << track_num_ DVLOG(2) << "EmitBuffer() : " << track_num_
<< " ts " << buffer->pts() << " ts " << buffer->pts()
<< " dur " << buffer->duration() << " dur " << buffer->duration()
@ -493,7 +493,7 @@ bool WebMClusterParser::Track::EmitBuffer(
<< last_added_buffer_missing_duration_->duration() << last_added_buffer_missing_duration_->duration()
<< " kf " << last_added_buffer_missing_duration_->is_key_frame() << " kf " << last_added_buffer_missing_duration_->is_key_frame()
<< " size " << last_added_buffer_missing_duration_->data_size(); << " size " << last_added_buffer_missing_duration_->data_size();
scoped_refptr<MediaSample> updated_buffer = std::shared_ptr<MediaSample> updated_buffer =
last_added_buffer_missing_duration_; last_added_buffer_missing_duration_;
last_added_buffer_missing_duration_ = NULL; last_added_buffer_missing_duration_ = NULL;
if (!EmitBufferHelp(updated_buffer)) if (!EmitBufferHelp(updated_buffer))
@ -540,7 +540,7 @@ void WebMClusterParser::Track::Reset() {
} }
bool WebMClusterParser::Track::EmitBufferHelp( bool WebMClusterParser::Track::EmitBufferHelp(
const scoped_refptr<MediaSample>& buffer) { const std::shared_ptr<MediaSample>& buffer) {
DCHECK(!last_added_buffer_missing_duration_.get()); DCHECK(!last_added_buffer_missing_duration_.get());
int64_t duration = buffer->duration(); int64_t duration = buffer->duration();

View File

@ -50,7 +50,7 @@ class WebMClusterParser : public WebMParserClient {
// relative to |buffer|'s timestamp, and emits it and unsets // relative to |buffer|'s timestamp, and emits it and unsets
// |last_added_buffer_missing_duration_|. Otherwise, if |buffer| is missing // |last_added_buffer_missing_duration_|. Otherwise, if |buffer| is missing
// duration, saves |buffer| into |last_added_buffer_missing_duration_|. // duration, saves |buffer| into |last_added_buffer_missing_duration_|.
bool EmitBuffer(const scoped_refptr<MediaSample>& buffer); bool EmitBuffer(const std::shared_ptr<MediaSample>& buffer);
// If |last_added_buffer_missing_duration_| is set, estimate the duration // If |last_added_buffer_missing_duration_| is set, estimate the duration
// for this buffer using helper function GetDurationEstimate() then emits it // 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|. // |estimated_next_frame_duration_|, and emits |buffer|.
// Returns false if |buffer| failed sanity check and therefore was not // Returns false if |buffer| failed sanity check and therefore was not
// emitted. Returns true otherwise. // emitted. Returns true otherwise.
bool EmitBufferHelp(const scoped_refptr<MediaSample>& buffer); bool EmitBufferHelp(const std::shared_ptr<MediaSample>& buffer);
// Helper function that calculates the buffer duration to use in // Helper function that calculates the buffer duration to use in
// ApplyDurationEstimateIfNeeded(). // ApplyDurationEstimateIfNeeded().
@ -79,7 +79,7 @@ class WebMClusterParser : public WebMParserClient {
// Holding the sample that is missing duration. The duration will be // Holding the sample that is missing duration. The duration will be
// computed from the difference in timestamp when next sample arrives; or // computed from the difference in timestamp when next sample arrives; or
// estimated if it is the last sample in this track. // estimated if it is the last sample in this track.
scoped_refptr<MediaSample> last_added_buffer_missing_duration_; std::shared_ptr<MediaSample> last_added_buffer_missing_duration_;
// If kNoTimestamp, then |estimated_next_frame_duration_| will be used. // If kNoTimestamp, then |estimated_next_frame_duration_| will be used.
int64_t default_duration_; int64_t default_duration_;
@ -118,8 +118,8 @@ class WebMClusterParser : public WebMParserClient {
/// @param decryption_key_source points to a decryption key source to fetch /// @param decryption_key_source points to a decryption key source to fetch
/// decryption keys. Should not be NULL if the tracks are encrypted. /// decryption keys. Should not be NULL if the tracks are encrypted.
WebMClusterParser(int64_t timecode_scale, WebMClusterParser(int64_t timecode_scale,
scoped_refptr<AudioStreamInfo> audio_stream_info, std::shared_ptr<AudioStreamInfo> audio_stream_info,
scoped_refptr<VideoStreamInfo> video_stream_info, std::shared_ptr<VideoStreamInfo> video_stream_info,
int64_t audio_default_duration, int64_t audio_default_duration,
int64_t video_default_duration, int64_t video_default_duration,
const WebMTracksParser::TextTracks& text_tracks, const WebMTracksParser::TextTracks& text_tracks,
@ -186,8 +186,8 @@ class WebMClusterParser : public WebMParserClient {
// Multiplier used to convert timecodes into microseconds. // Multiplier used to convert timecodes into microseconds.
double timecode_multiplier_; double timecode_multiplier_;
scoped_refptr<AudioStreamInfo> audio_stream_info_; std::shared_ptr<AudioStreamInfo> audio_stream_info_;
scoped_refptr<VideoStreamInfo> video_stream_info_; std::shared_ptr<VideoStreamInfo> video_stream_info_;
std::set<int64_t> ignored_tracks_; std::set<int64_t> ignored_tracks_;
std::unique_ptr<DecryptorSource> decryptor_source_; std::unique_ptr<DecryptorSource> decryptor_source_;

View File

@ -275,7 +275,7 @@ bool VerifyBuffersHelper(const BufferQueue& audio_buffers,
return false; return false;
} }
scoped_refptr<MediaSample> buffer = (*buffers)[(*offset)++]; std::shared_ptr<MediaSample> buffer = (*buffers)[(*offset)++];
EXPECT_EQ(block_info[i].timestamp * kMicrosecondsPerMillisecond, EXPECT_EQ(block_info[i].timestamp * kMicrosecondsPerMillisecond,
buffer->pts()); buffer->pts());
@ -306,7 +306,7 @@ bool VerifyTextBuffers(const BlockInfo* block_info_ptr,
EXPECT_FALSE(block_info.use_simple_block); EXPECT_FALSE(block_info.use_simple_block);
EXPECT_FALSE(buffer_iter == buffer_end); EXPECT_FALSE(buffer_iter == buffer_end);
const scoped_refptr<MediaSample> buffer = *buffer_iter++; const std::shared_ptr<MediaSample> buffer = *buffer_iter++;
EXPECT_EQ(block_info.timestamp * kMicrosecondsPerMillisecond, EXPECT_EQ(block_info.timestamp * kMicrosecondsPerMillisecond,
buffer->pts()); buffer->pts());
EXPECT_EQ(std::abs(block_info.duration) * kMicrosecondsPerMillisecond, EXPECT_EQ(std::abs(block_info.duration) * kMicrosecondsPerMillisecond,
@ -349,12 +349,12 @@ class WebMClusterParserTest : public testing::Test {
default_audio_duration, default_video_duration)); default_audio_duration, default_video_duration));
} }
void InitEvent(const std::vector<scoped_refptr<StreamInfo>>& stream_info) { void InitEvent(const std::vector<std::shared_ptr<StreamInfo>>& stream_info) {
streams_from_init_event_ = stream_info; streams_from_init_event_ = stream_info;
} }
bool NewSampleEvent(uint32_t track_id, bool NewSampleEvent(uint32_t track_id,
const scoped_refptr<MediaSample>& sample) { const std::shared_ptr<MediaSample>& sample) {
switch (track_id) { switch (track_id) {
case kAudioTrackNum: case kAudioTrackNum:
audio_buffers_.push_back(sample); audio_buffers_.push_back(sample);
@ -448,10 +448,10 @@ class WebMClusterParserTest : public testing::Test {
return result; return result;
} }
scoped_refptr<AudioStreamInfo> audio_stream_info_; std::shared_ptr<AudioStreamInfo> audio_stream_info_;
scoped_refptr<VideoStreamInfo> video_stream_info_; std::shared_ptr<VideoStreamInfo> video_stream_info_;
std::unique_ptr<WebMClusterParser> parser_; std::unique_ptr<WebMClusterParser> parser_;
std::vector<scoped_refptr<StreamInfo>> streams_from_init_event_; std::vector<std::shared_ptr<StreamInfo>> streams_from_init_event_;
BufferQueue audio_buffers_; BufferQueue audio_buffers_;
BufferQueue video_buffers_; BufferQueue video_buffers_;
TextBufferQueueMap text_buffers_map_; TextBufferQueueMap text_buffers_map_;
@ -837,7 +837,7 @@ TEST_F(WebMClusterParserTest, ParseEncryptedBlock) {
EXPECT_EQ(cluster->size(), result); EXPECT_EQ(cluster->size(), result);
EXPECT_TRUE(parser_->Flush()); EXPECT_TRUE(parser_->Flush());
ASSERT_EQ(1UL, video_buffers_.size()); ASSERT_EQ(1UL, video_buffers_.size());
scoped_refptr<MediaSample> buffer = video_buffers_[0]; std::shared_ptr<MediaSample> buffer = video_buffers_[0];
EXPECT_EQ(std::vector<uint8_t>( EXPECT_EQ(std::vector<uint8_t>(
kExpectedDecryptedFrame, kExpectedDecryptedFrame,
kExpectedDecryptedFrame + arraysize(kExpectedDecryptedFrame)), kExpectedDecryptedFrame + arraysize(kExpectedDecryptedFrame)),
@ -879,7 +879,7 @@ TEST_F(WebMClusterParserTest, ParseClearFrameInEncryptedTrack) {
EXPECT_EQ(cluster->size(), result); EXPECT_EQ(cluster->size(), result);
EXPECT_TRUE(parser_->Flush()); EXPECT_TRUE(parser_->Flush());
ASSERT_EQ(1UL, video_buffers_.size()); ASSERT_EQ(1UL, video_buffers_.size());
scoped_refptr<MediaSample> buffer = video_buffers_[0]; std::shared_ptr<MediaSample> buffer = video_buffers_[0];
EXPECT_EQ(std::vector<uint8_t>( EXPECT_EQ(std::vector<uint8_t>(
kExpectedClearFrame, kExpectedClearFrame,
kExpectedClearFrame + arraysize(kExpectedClearFrame)), kExpectedClearFrame + arraysize(kExpectedClearFrame)),

View File

@ -184,7 +184,7 @@ int WebMMediaParser::ParseInfoAndTracks(const uint8_t* data, int size) {
double timecode_scale_in_us = info_parser.timecode_scale() / 1000.0; double timecode_scale_in_us = info_parser.timecode_scale() / 1000.0;
int64_t duration_in_us = info_parser.duration() * timecode_scale_in_us; int64_t duration_in_us = info_parser.duration() * timecode_scale_in_us;
scoped_refptr<AudioStreamInfo> audio_stream_info = std::shared_ptr<AudioStreamInfo> audio_stream_info =
tracks_parser.audio_stream_info(); tracks_parser.audio_stream_info();
if (audio_stream_info) { if (audio_stream_info) {
audio_stream_info->set_duration(duration_in_us); 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."; VLOG(1) << "No audio track info found.";
} }
scoped_refptr<VideoStreamInfo> video_stream_info = std::shared_ptr<VideoStreamInfo> video_stream_info =
tracks_parser.video_stream_info(); tracks_parser.video_stream_info();
if (video_stream_info) { if (video_stream_info) {
video_stream_info->set_duration(duration_in_us); video_stream_info->set_duration(duration_in_us);

View File

@ -7,7 +7,6 @@
#include "packager/base/callback_forward.h" #include "packager/base/callback_forward.h"
#include "packager/base/compiler_specific.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/byte_queue.h"
#include "packager/media/base/media_parser.h" #include "packager/media/base/media_parser.h"

View File

@ -74,7 +74,7 @@ Status WebMMuxer::Finalize() {
} }
Status WebMMuxer::DoAddSample(const MediaStream* stream, Status WebMMuxer::DoAddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) { std::shared_ptr<MediaSample> sample) {
DCHECK(segmenter_); DCHECK(segmenter_);
DCHECK(stream == streams()[0]); DCHECK(stream == streams()[0]);
return segmenter_->AddSample(sample); return segmenter_->AddSample(sample);

View File

@ -27,7 +27,7 @@ class WebMMuxer : public Muxer {
Status Initialize() override; Status Initialize() override;
Status Finalize() override; Status Finalize() override;
Status DoAddSample(const MediaStream* stream, Status DoAddSample(const MediaStream* stream,
scoped_refptr<MediaSample> sample) override; std::shared_ptr<MediaSample> sample) override;
void FireOnMediaStartEvent(); void FireOnMediaStartEvent();
void FireOnMediaEndEvent(); void FireOnMediaEndEvent();

View File

@ -51,7 +51,7 @@ class WebMTracksParser : public WebMParserClient {
return audio_encryption_key_id_; return audio_encryption_key_id_;
} }
scoped_refptr<AudioStreamInfo> audio_stream_info() { std::shared_ptr<AudioStreamInfo> audio_stream_info() {
return audio_stream_info_; return audio_stream_info_;
} }
@ -59,7 +59,7 @@ class WebMTracksParser : public WebMParserClient {
return video_encryption_key_id_; return video_encryption_key_id_;
} }
scoped_refptr<VideoStreamInfo> video_stream_info() { std::shared_ptr<VideoStreamInfo> video_stream_info() {
return video_stream_info_; return video_stream_info_;
} }
@ -100,10 +100,10 @@ class WebMTracksParser : public WebMParserClient {
std::string video_encryption_key_id_; std::string video_encryption_key_id_;
WebMAudioClient audio_client_; WebMAudioClient audio_client_;
scoped_refptr<AudioStreamInfo> audio_stream_info_; std::shared_ptr<AudioStreamInfo> audio_stream_info_;
WebMVideoClient video_client_; WebMVideoClient video_client_;
scoped_refptr<VideoStreamInfo> video_stream_info_; std::shared_ptr<VideoStreamInfo> video_stream_info_;
DISALLOW_COPY_AND_ASSIGN(WebMTracksParser); DISALLOW_COPY_AND_ASSIGN(WebMTracksParser);
}; };

View File

@ -144,13 +144,13 @@ TEST_F(WebMTracksParserTest, AudioVideoDefaultDurationUnset) {
EXPECT_EQ(kNoTimestamp, EXPECT_EQ(kNoTimestamp,
parser->GetVideoDefaultDuration(kDefaultTimecodeScaleInUs)); parser->GetVideoDefaultDuration(kDefaultTimecodeScaleInUs));
scoped_refptr<VideoStreamInfo> video_stream_info = std::shared_ptr<VideoStreamInfo> video_stream_info =
parser->video_stream_info(); parser->video_stream_info();
EXPECT_TRUE(video_stream_info); EXPECT_TRUE(video_stream_info);
EXPECT_EQ(320u, video_stream_info->width()); EXPECT_EQ(320u, video_stream_info->width());
EXPECT_EQ(240u, video_stream_info->height()); EXPECT_EQ(240u, video_stream_info->height());
scoped_refptr<AudioStreamInfo> audio_stream_info = std::shared_ptr<AudioStreamInfo> audio_stream_info =
parser->audio_stream_info(); parser->audio_stream_info();
EXPECT_TRUE(audio_stream_info); EXPECT_TRUE(audio_stream_info);
EXPECT_EQ(2u, audio_stream_info->num_channels()); EXPECT_EQ(2u, audio_stream_info->num_channels());

View File

@ -47,7 +47,7 @@ void WebMVideoClient::Reset() {
alpha_mode_ = -1; alpha_mode_ = -1;
} }
scoped_refptr<VideoStreamInfo> WebMVideoClient::GetVideoStreamInfo( std::shared_ptr<VideoStreamInfo> WebMVideoClient::GetVideoStreamInfo(
int64_t track_num, int64_t track_num,
const std::string& codec_id, const std::string& codec_id,
const std::vector<uint8_t>& codec_private, const std::vector<uint8_t>& codec_private,
@ -64,11 +64,11 @@ scoped_refptr<VideoStreamInfo> WebMVideoClient::GetVideoStreamInfo(
video_codec = kCodecVP10; video_codec = kCodecVP10;
} else { } else {
LOG(ERROR) << "Unsupported video codec_id " << codec_id; LOG(ERROR) << "Unsupported video codec_id " << codec_id;
return scoped_refptr<VideoStreamInfo>(); return std::shared_ptr<VideoStreamInfo>();
} }
if (pixel_width_ <= 0 || pixel_height_ <= 0) if (pixel_width_ <= 0 || pixel_height_ <= 0)
return scoped_refptr<VideoStreamInfo>(); return std::shared_ptr<VideoStreamInfo>();
// Set crop and display unit defaults if these elements are not present. // Set crop and display unit defaults if these elements are not present.
if (crop_bottom_ == -1) if (crop_bottom_ == -1)
@ -96,10 +96,10 @@ scoped_refptr<VideoStreamInfo> WebMVideoClient::GetVideoStreamInfo(
display_height_ = height_after_crop; display_height_ = height_after_crop;
} else if (display_unit_ == 3) { } else if (display_unit_ == 3) {
if (display_width_ <= 0 || display_height_ <= 0) if (display_width_ <= 0 || display_height_ <= 0)
return scoped_refptr<VideoStreamInfo>(); return std::shared_ptr<VideoStreamInfo>();
} else { } else {
LOG(ERROR) << "Unsupported display unit type " << display_unit_; LOG(ERROR) << "Unsupported display unit type " << display_unit_;
return scoped_refptr<VideoStreamInfo>(); return std::shared_ptr<VideoStreamInfo>();
} }
// Calculate sample aspect ratio. // Calculate sample aspect ratio.
int64_t sar_x = display_width_ * height_after_crop; int64_t sar_x = display_width_ * height_after_crop;
@ -108,10 +108,10 @@ scoped_refptr<VideoStreamInfo> WebMVideoClient::GetVideoStreamInfo(
sar_x /= gcd; sar_x /= gcd;
sar_y /= gcd; sar_y /= gcd;
return scoped_refptr<VideoStreamInfo>(new VideoStreamInfo( return std::make_shared<VideoStreamInfo>(
track_num, kWebMTimeScale, 0, video_codec, std::string(), track_num, kWebMTimeScale, 0, video_codec, std::string(),
codec_private.data(), codec_private.size(), width_after_crop, 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) { bool WebMVideoClient::OnUInt(int id, int64_t val) {

View File

@ -28,10 +28,10 @@ class WebMVideoClient : public WebMParserClient {
/// Create a VideoStreamInfo with the data in |track_num|, |codec_id|, /// Create a VideoStreamInfo with the data in |track_num|, |codec_id|,
/// |codec_private|, |is_encrypted| and the fields parsed from the last video /// |codec_private|, |is_encrypted| and the fields parsed from the last video
/// track element this object was used to parse. /// track element this object was used to parse.
/// @return A VideoStreamInfo scoped_refptr if successful. /// @return A VideoStreamInfo if successful.
/// @return An empty scoped_refptr if there was unexpected values in the /// @return An empty pointer if there was unexpected values in the
/// provided parameters or video track element fields. /// provided parameters or video track element fields.
scoped_refptr<VideoStreamInfo> GetVideoStreamInfo( std::shared_ptr<VideoStreamInfo> GetVideoStreamInfo(
int64_t track_num, int64_t track_num,
const std::string& codec_id, const std::string& codec_id,
const std::vector<uint8_t>& codec_private, const std::vector<uint8_t>& codec_private,

View File

@ -188,7 +188,7 @@ bool ParseTimingAndSettingsLine(const std::string& line,
// comment --> side data (and side data only sample) // comment --> side data (and side data only sample)
// settings --> side data // settings --> side data
// start_time --> pts // start_time --> pts
scoped_refptr<MediaSample> CueToMediaSample(const Cue& cue) { std::shared_ptr<MediaSample> CueToMediaSample(const Cue& cue) {
const bool kKeyFrame = true; const bool kKeyFrame = true;
if (!cue.comment.empty()) { if (!cue.comment.empty()) {
const std::string comment = base::JoinString(cue.comment, "\n"); const std::string comment = base::JoinString(cue.comment, "\n");
@ -197,12 +197,10 @@ scoped_refptr<MediaSample> CueToMediaSample(const Cue& cue) {
} }
const std::string payload = base::JoinString(cue.payload, "\n"); const std::string payload = base::JoinString(cue.payload, "\n");
scoped_refptr<MediaSample> media_sample = MediaSample::CopyFrom( std::shared_ptr<MediaSample> media_sample = MediaSample::CopyFrom(
reinterpret_cast<const uint8_t*>(payload.data()), reinterpret_cast<const uint8_t*>(payload.data()), payload.size(),
payload.size(),
reinterpret_cast<const uint8_t*>(cue.settings.data()), reinterpret_cast<const uint8_t*>(cue.settings.data()),
cue.settings.size(), cue.settings.size(), !kKeyFrame);
!kKeyFrame);
media_sample->set_config_id(cue.identifier); media_sample->set_config_id(cue.identifier);
media_sample->set_pts(cue.start_time); media_sample->set_pts(cue.start_time);
@ -282,7 +280,7 @@ bool WebVttMediaParser::Parse(const uint8_t* buf, int size) {
break; break;
case kMetadata: { case kMetadata: {
if (line.empty()) { if (line.empty()) {
std::vector<scoped_refptr<StreamInfo> > streams; std::vector<std::shared_ptr<StreamInfo>> streams;
// The resolution of timings are in milliseconds. // The resolution of timings are in milliseconds.
const int kTimescale = 1000; 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 // There is no one metadata to determine what the language is. Parts
// of the text may be annotated as some specific language. // of the text may be annotated as some specific language.
const char kLanguage[] = ""; const char kLanguage[] = "";
streams.push_back(new TextStreamInfo(kTrackId, kTimescale, kDuration, streams.emplace_back(
"wvtt", new TextStreamInfo(kTrackId, kTimescale, kDuration, "wvtt",
base::JoinString(header_, "\n"), base::JoinString(header_, "\n"),
0, // Not necessary. 0, // Not necessary.
0, 0,
kLanguage)); // Not necessary. kLanguage)); // Not necessary.
init_cb_.Run(streams); init_cb_.Run(streams);
state_ = kCueIdentifierOrTimingOrComment; state_ = kCueIdentifierOrTimingOrComment;

View File

@ -15,11 +15,12 @@
namespace shaka { namespace shaka {
namespace media { namespace media {
typedef testing::MockFunction<void(const std::vector<scoped_refptr<StreamInfo>>& typedef testing::MockFunction<void(
stream_info)> MockInitCallback; const std::vector<std::shared_ptr<StreamInfo>>& stream_info)>
typedef testing::MockFunction<bool( MockInitCallback;
uint32_t track_id, typedef testing::MockFunction<
const scoped_refptr<MediaSample>& media_sample)> MockNewSampleCallback; bool(uint32_t track_id, const std::shared_ptr<MediaSample>& media_sample)>
MockNewSampleCallback;
using testing::_; using testing::_;
using testing::InSequence; using testing::InSequence;

View File

@ -487,8 +487,9 @@ bool WvmMediaParser::Parse(const uint8_t* buf, int size) {
return true; return true;
} }
bool WvmMediaParser::EmitLastSample(uint32_t stream_id, bool WvmMediaParser::EmitLastSample(
scoped_refptr<MediaSample>& new_sample) { uint32_t stream_id,
const std::shared_ptr<MediaSample>& new_sample) {
std::string key = base::UintToString(current_program_id_) std::string key = base::UintToString(current_program_id_)
.append(":") .append(":")
.append(base::UintToString(stream_id)); .append(base::UintToString(stream_id));
@ -739,7 +740,7 @@ bool WvmMediaParser::ParseIndexEntry() {
if (has_video) { if (has_video) {
Codec video_codec = kCodecH264; 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, stream_id_count_, time_scale, track_duration, video_codec,
std::string(), video_codec_config.data(), video_codec_config.size(), std::string(), video_codec_config.data(), video_codec_config.size(),
video_width, video_height, pixel_width, pixel_height, trick_play_rate, video_width, video_height, pixel_width, pixel_height, trick_play_rate,
@ -754,7 +755,7 @@ bool WvmMediaParser::ParseIndexEntry() {
if (has_audio) { if (has_audio) {
const Codec audio_codec = kCodecAAC; const Codec audio_codec = kCodecAAC;
// TODO(beil): Pass in max and average bitrate in wvm container. // 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, stream_id_count_, time_scale, track_duration, audio_codec,
std::string(), audio_codec_config.data(), audio_codec_config.size(), std::string(), audio_codec_config.data(), audio_codec_config.size(),
kAacSampleSizeBits, num_channels, sampling_frequency, 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, bool WvmMediaParser::EmitSample(uint32_t parsed_audio_or_video_stream_id,
uint32_t stream_id, uint32_t stream_id,
scoped_refptr<MediaSample>& new_sample, const std::shared_ptr<MediaSample>& new_sample,
bool isLastSample) { bool isLastSample) {
DCHECK(new_sample); DCHECK(new_sample);
if (isLastSample) { if (isLastSample) {

View File

@ -32,7 +32,7 @@ struct DemuxStreamIdMediaSample {
~DemuxStreamIdMediaSample(); ~DemuxStreamIdMediaSample();
uint32_t demux_stream_id; uint32_t demux_stream_id;
uint32_t parsed_audio_or_video_stream_id; uint32_t parsed_audio_or_video_stream_id;
scoped_refptr<MediaSample> media_sample; std::shared_ptr<MediaSample> media_sample;
}; };
struct PrevSampleData { struct PrevSampleData {
@ -40,8 +40,8 @@ struct PrevSampleData {
PrevSampleData(); PrevSampleData();
~PrevSampleData(); ~PrevSampleData();
void Reset(); void Reset();
scoped_refptr<MediaSample> audio_sample; std::shared_ptr<MediaSample> audio_sample;
scoped_refptr<MediaSample> video_sample; std::shared_ptr<MediaSample> video_sample;
uint32_t audio_stream_id; uint32_t audio_stream_id;
uint32_t video_stream_id; uint32_t video_stream_id;
int64_t audio_sample_duration; int64_t audio_sample_duration;
@ -206,13 +206,13 @@ class WvmMediaParser : public MediaParser {
// to emit a new audio/video access unit. // to emit a new audio/video access unit.
bool EmitSample(uint32_t parsed_audio_or_video_stream_id, bool EmitSample(uint32_t parsed_audio_or_video_stream_id,
uint32_t stream_id, uint32_t stream_id,
scoped_refptr<MediaSample>& new_sample, const std::shared_ptr<MediaSample>& new_sample,
bool isLastSample); bool isLastSample);
bool EmitPendingSamples(); bool EmitPendingSamples();
bool EmitLastSample(uint32_t stream_id, bool EmitLastSample(uint32_t stream_id,
scoped_refptr<MediaSample>& new_sample); const std::shared_ptr<MediaSample>& new_sample);
// List of callbacks.t // List of callbacks.t
InitCB init_cb_; InitCB init_cb_;
@ -237,17 +237,17 @@ class WvmMediaParser : public MediaParser {
uint64_t pts_; uint64_t pts_;
uint64_t dts_; uint64_t dts_;
uint8_t index_program_id_; uint8_t index_program_id_;
scoped_refptr<MediaSample> media_sample_; std::shared_ptr<MediaSample> media_sample_;
size_t crypto_unit_start_pos_; size_t crypto_unit_start_pos_;
PrevSampleData prev_media_sample_data_; PrevSampleData prev_media_sample_data_;
H264ByteToUnitStreamConverter byte_to_unit_stream_converter_; H264ByteToUnitStreamConverter byte_to_unit_stream_converter_;
std::vector<uint8_t, std::allocator<uint8_t> > ecm_; std::vector<uint8_t, std::allocator<uint8_t>> ecm_;
std::vector<uint8_t> psm_data_; std::vector<uint8_t> psm_data_;
std::vector<uint8_t> index_data_; std::vector<uint8_t> index_data_;
std::map<std::string, uint32_t> program_demux_stream_map_; std::map<std::string, uint32_t> program_demux_stream_map_;
int stream_id_count_; int stream_id_count_;
std::vector<scoped_refptr<StreamInfo> > stream_infos_; std::vector<std::shared_ptr<StreamInfo>> stream_infos_;
std::deque<DemuxStreamIdMediaSample> media_sample_queue_; std::deque<DemuxStreamIdMediaSample> media_sample_queue_;
std::vector<uint8_t> sample_data_; std::vector<uint8_t> sample_data_;
KeySource* decryption_key_source_; KeySource* decryption_key_source_;

View File

@ -11,7 +11,6 @@
#include "packager/base/bind.h" #include "packager/base/bind.h"
#include "packager/base/bind_helpers.h" #include "packager/base/bind_helpers.h"
#include "packager/base/logging.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/audio_stream_info.h"
#include "packager/media/base/fixed_key_source.h" #include "packager/media/base/fixed_key_source.h"
#include "packager/media/base/media_sample.h" #include "packager/media/base/media_sample.h"
@ -78,7 +77,7 @@ class WvmMediaParserTest : public testing::Test {
} }
protected: protected:
typedef std::map<int, scoped_refptr<StreamInfo> > StreamMap; typedef std::map<int, std::shared_ptr<StreamInfo>> StreamMap;
std::unique_ptr<WvmMediaParser> parser_; std::unique_ptr<WvmMediaParser> parser_;
std::unique_ptr<MockKeySource> key_source_; std::unique_ptr<MockKeySource> key_source_;
@ -90,17 +89,16 @@ class WvmMediaParserTest : public testing::Test {
int32_t current_track_id_; int32_t current_track_id_;
EncryptionKey encryption_key_; EncryptionKey encryption_key_;
void OnInit(const std::vector<scoped_refptr<StreamInfo> >& stream_infos) { void OnInit(const std::vector<std::shared_ptr<StreamInfo>>& stream_infos) {
DVLOG(1) << "OnInit: " << stream_infos.size() << " streams."; DVLOG(1) << "OnInit: " << stream_infos.size() << " streams.";
for (std::vector<scoped_refptr<StreamInfo> >::const_iterator iter = for (const auto& stream_info : stream_infos) {
stream_infos.begin(); iter != stream_infos.end(); ++iter) { DVLOG(1) << stream_info->ToString();
DVLOG(1) << (*iter)->ToString(); stream_map_[stream_info->track_id()] = stream_info;
stream_map_[(*iter)->track_id()] = *iter;
} }
} }
bool OnNewSample(uint32_t track_id, bool OnNewSample(uint32_t track_id,
const scoped_refptr<MediaSample>& sample) { const std::shared_ptr<MediaSample>& sample) {
std::string stream_type; std::string stream_type;
if (static_cast<int32_t>(track_id) != current_track_id_) { if (static_cast<int32_t>(track_id) != current_track_id_) {
// onto next track. // onto next track.