Let SetMuxerListener() take ownership of listeners

Change-Id: Id7a9d6f6768556ac4bcaa9c000792a61ee6b758f
This commit is contained in:
Kongqun Yang 2015-05-05 16:30:14 -07:00
parent 5f64698144
commit 71e39e40ad
3 changed files with 8 additions and 21 deletions

View File

@ -104,9 +104,7 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
const MuxerOptions& muxer_options,
KeySource* key_source,
MpdNotifier* mpd_notifier,
std::vector<MuxerListener*>* muxer_listeners,
std::vector<RemuxJob*>* remux_jobs) {
DCHECK(muxer_listeners);
DCHECK(remux_jobs);
std::string previous_input;
@ -181,10 +179,8 @@ bool CreateRemuxJobs(const StreamDescriptorList& stream_descriptors,
muxer_listener = mpd_notify_muxer_listener.Pass();
}
if (muxer_listener) {
muxer_listeners->push_back(muxer_listener.release());
muxer->SetMuxerListener(muxer_listeners->back());
}
if (muxer_listener)
muxer->SetMuxerListener(muxer_listener.Pass());
if (!AddStreamToMuxer(remux_jobs->back()->demuxer()->streams(),
stream_iter->stream_selector,
@ -274,17 +270,12 @@ bool RunPackager(const StreamDescriptorList& stream_descriptors) {
}
}
// TODO(kqyang): Should Muxer::SetMuxerListener take owership of the
// muxer_listeners object? Then we can get rid of |muxer_listeners|.
std::vector<MuxerListener*> muxer_listeners;
STLElementDeleter<std::vector<MuxerListener*> > deleter(&muxer_listeners);
std::vector<RemuxJob*> remux_jobs;
STLElementDeleter<std::vector<RemuxJob*> > scoped_jobs_deleter(&remux_jobs);
if (!CreateRemuxJobs(stream_descriptors,
muxer_options,
encryption_key_source.get(),
mpd_notifier.get(),
&muxer_listeners,
&remux_jobs)) {
return false;
}

View File

@ -20,7 +20,6 @@ Muxer::Muxer(const MuxerOptions& options)
clear_lead_in_seconds_(0),
crypto_period_duration_in_seconds_(0),
cancelled_(false),
muxer_listener_(NULL),
clock_(NULL) {}
Muxer::~Muxer() {}
@ -80,8 +79,8 @@ void Muxer::Cancel() {
cancelled_ = true;
}
void Muxer::SetMuxerListener(media::event::MuxerListener* muxer_listener) {
muxer_listener_ = muxer_listener;
void Muxer::SetMuxerListener(scoped_ptr<event::MuxerListener> muxer_listener) {
muxer_listener_ = muxer_listener.Pass();
}
Status Muxer::AddSample(const MediaStream* stream,

View File

@ -16,6 +16,7 @@
#include "packager/base/time/clock.h"
#include "packager/media/base/muxer_options.h"
#include "packager/media/base/status.h"
#include "packager/media/event/muxer_listener.h"
namespace edash_packager {
namespace media {
@ -24,10 +25,6 @@ class KeySource;
class MediaSample;
class MediaStream;
namespace event {
class MuxerListener;
}
/// Muxer is responsible for taking elementary stream samples and producing
/// media containers. An optional KeySource can be provided to Muxer
/// to generate encrypted outputs.
@ -63,7 +60,7 @@ class Muxer {
/// Set a MuxerListener event handler for this object.
/// @param muxer_listener should not be NULL.
void SetMuxerListener(event::MuxerListener* muxer_listener);
void SetMuxerListener(scoped_ptr<event::MuxerListener> muxer_listener);
const std::vector<MediaStream*>& streams() const { return streams_; }
@ -87,7 +84,7 @@ class Muxer {
double crypto_period_duration_in_seconds() const {
return crypto_period_duration_in_seconds_;
}
event::MuxerListener* muxer_listener() { return muxer_listener_; }
event::MuxerListener* muxer_listener() { return muxer_listener_.get(); }
base::Clock* clock() { return clock_; }
private:
@ -116,7 +113,7 @@ class Muxer {
double crypto_period_duration_in_seconds_;
bool cancelled_;
event::MuxerListener* muxer_listener_;
scoped_ptr<event::MuxerListener> muxer_listener_;
// An external injected clock, can be NULL.
base::Clock* clock_;