Commit a61ce5a9 authored by sandersd@chromium.org's avatar sandersd@chromium.org

Separate DemuxerHost from DataSourceHost.

This is the first part of work to remove byte range computations out of media::Pipeline, and instead have the DataSource report those directly to Pipeline's parent, which will avoid crossing thread boundaries unnecessarily. This first CL just cleans up the interfaces required to do that, but already eliminates some of the stranger parts of the set-up code.

BUG=122071

Review URL: https://codereview.chromium.org/212803004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261494 0039d316-1c4b-4281-b951-d872f2087c98
parent 0142a952
...@@ -21,14 +21,6 @@ IPCDataSource::~IPCDataSource() { ...@@ -21,14 +21,6 @@ IPCDataSource::~IPCDataSource() {
DCHECK(utility_thread_checker_.CalledOnValidThread()); DCHECK(utility_thread_checker_.CalledOnValidThread());
} }
void IPCDataSource::set_host(media::DataSourceHost* host) {
DCHECK(data_source_thread_checker_.CalledOnValidThread());
DataSource::set_host(host);
if (media::DataSource::host()) {
media::DataSource::host()->SetTotalBytes(total_size_);
}
}
void IPCDataSource::Stop(const base::Closure& callback) { void IPCDataSource::Stop(const base::Closure& callback) {
DCHECK(data_source_thread_checker_.CalledOnValidThread()); DCHECK(data_source_thread_checker_.CalledOnValidThread());
callback.Run(); callback.Run();
......
...@@ -32,7 +32,6 @@ class IPCDataSource: public media::DataSource, ...@@ -32,7 +32,6 @@ class IPCDataSource: public media::DataSource,
// Implementation of DataSource. These methods may be called on any single // Implementation of DataSource. These methods may be called on any single
// thread. First usage of these methods attaches a thread checker. // thread. First usage of these methods attaches a thread checker.
virtual void set_host(media::DataSourceHost* host) OVERRIDE;
virtual void Stop(const base::Closure& callback) OVERRIDE; virtual void Stop(const base::Closure& callback) OVERRIDE;
virtual void Read(int64 position, int size, uint8* data, virtual void Read(int64 position, int size, uint8* data,
const ReadCB& read_cb) OVERRIDE; const ReadCB& read_cb) OVERRIDE;
......
...@@ -300,14 +300,6 @@ void MediaSourceDelegate::SeekInternal(const base::TimeDelta& seek_time) { ...@@ -300,14 +300,6 @@ void MediaSourceDelegate::SeekInternal(const base::TimeDelta& seek_time) {
media_weak_factory_.GetWeakPtr())); media_weak_factory_.GetWeakPtr()));
} }
void MediaSourceDelegate::SetTotalBytes(int64 total_bytes) {
NOTIMPLEMENTED();
}
void MediaSourceDelegate::AddBufferedByteRange(int64 start, int64 end) {
NOTIMPLEMENTED();
}
void MediaSourceDelegate::AddBufferedTimeRange(base::TimeDelta start, void MediaSourceDelegate::AddBufferedTimeRange(base::TimeDelta start,
base::TimeDelta end) { base::TimeDelta end) {
buffered_time_ranges_.Add(start, end); buffered_time_ranges_.Add(start, end);
......
...@@ -111,8 +111,6 @@ class MediaSourceDelegate : public media::DemuxerHost { ...@@ -111,8 +111,6 @@ class MediaSourceDelegate : public media::DemuxerHost {
virtual ~MediaSourceDelegate(); virtual ~MediaSourceDelegate();
// Methods inherited from DemuxerHost. // Methods inherited from DemuxerHost.
virtual void SetTotalBytes(int64 total_bytes) OVERRIDE;
virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE;
virtual void AddBufferedTimeRange(base::TimeDelta start, virtual void AddBufferedTimeRange(base::TimeDelta start,
base::TimeDelta end) OVERRIDE; base::TimeDelta end) OVERRIDE;
virtual void SetDuration(base::TimeDelta duration) OVERRIDE; virtual void SetDuration(base::TimeDelta duration) OVERRIDE;
......
...@@ -81,6 +81,7 @@ BufferedDataSource::BufferedDataSource( ...@@ -81,6 +81,7 @@ BufferedDataSource::BufferedDataSource(
const scoped_refptr<base::MessageLoopProxy>& render_loop, const scoped_refptr<base::MessageLoopProxy>& render_loop,
WebFrame* frame, WebFrame* frame,
media::MediaLog* media_log, media::MediaLog* media_log,
media::DataSourceHost* host,
const DownloadingCB& downloading_cb) const DownloadingCB& downloading_cb)
: cors_mode_(BufferedResourceLoader::kUnspecified), : cors_mode_(BufferedResourceLoader::kUnspecified),
total_bytes_(kPositionNotSpecified), total_bytes_(kPositionNotSpecified),
...@@ -96,8 +97,10 @@ BufferedDataSource::BufferedDataSource( ...@@ -96,8 +97,10 @@ BufferedDataSource::BufferedDataSource(
bitrate_(0), bitrate_(0),
playback_rate_(0.0), playback_rate_(0.0),
media_log_(media_log), media_log_(media_log),
host_(host),
downloading_cb_(downloading_cb), downloading_cb_(downloading_cb),
weak_factory_(this) { weak_factory_(this) {
DCHECK(host_);
DCHECK(!downloading_cb_.is_null()); DCHECK(!downloading_cb_.is_null());
} }
...@@ -124,15 +127,6 @@ BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( ...@@ -124,15 +127,6 @@ BufferedResourceLoader* BufferedDataSource::CreateResourceLoader(
media_log_.get()); media_log_.get());
} }
void BufferedDataSource::set_host(media::DataSourceHost* host) {
DataSource::set_host(host);
if (loader_) {
base::AutoLock auto_lock(lock_);
UpdateHostState_Locked();
}
}
void BufferedDataSource::Initialize( void BufferedDataSource::Initialize(
const GURL& url, const GURL& url,
BufferedResourceLoader::CORSMode cors_mode, BufferedResourceLoader::CORSMode cors_mode,
...@@ -380,7 +374,12 @@ void BufferedDataSource::StartCallback( ...@@ -380,7 +374,12 @@ void BufferedDataSource::StartCallback(
return; return;
if (success) { if (success) {
UpdateHostState_Locked(); if (total_bytes_ != kPositionNotSpecified) {
host_->SetTotalBytes(total_bytes_);
if (assume_fully_buffered_)
host_->AddBufferedByteRange(0, total_bytes_);
}
media_log_->SetBooleanProperty("single_origin", loader_->HasSingleOrigin()); media_log_->SetBooleanProperty("single_origin", loader_->HasSingleOrigin());
media_log_->SetBooleanProperty("passed_cors_access_check", media_log_->SetBooleanProperty("passed_cors_access_check",
loader_->DidPassCORSAccessCheck()); loader_->DidPassCORSAccessCheck());
...@@ -460,10 +459,10 @@ void BufferedDataSource::ReadCallback( ...@@ -460,10 +459,10 @@ void BufferedDataSource::ReadCallback(
// fail like they would if we had known the file size at the beginning. // fail like they would if we had known the file size at the beginning.
total_bytes_ = loader_->instance_size(); total_bytes_ = loader_->instance_size();
if (host() && total_bytes_ != kPositionNotSpecified) { if (total_bytes_ != kPositionNotSpecified) {
host()->SetTotalBytes(total_bytes_); host_->SetTotalBytes(total_bytes_);
host()->AddBufferedByteRange(loader_->first_byte_position(), host_->AddBufferedByteRange(loader_->first_byte_position(),
total_bytes_); total_bytes_);
} }
} }
ReadOperation::Run(read_op_.Pass(), bytes_read); ReadOperation::Run(read_op_.Pass(), bytes_read);
...@@ -510,35 +509,7 @@ void BufferedDataSource::ProgressCallback(int64 position) { ...@@ -510,35 +509,7 @@ void BufferedDataSource::ProgressCallback(int64 position) {
if (stop_signal_received_) if (stop_signal_received_)
return; return;
ReportOrQueueBufferedBytes(loader_->first_byte_position(), position); host_->AddBufferedByteRange(loader_->first_byte_position(), position);
}
void BufferedDataSource::ReportOrQueueBufferedBytes(int64 start, int64 end) {
if (host())
host()->AddBufferedByteRange(start, end);
else
queued_buffered_byte_ranges_.Add(start, end);
}
void BufferedDataSource::UpdateHostState_Locked() {
lock_.AssertAcquired();
if (!host())
return;
for (size_t i = 0; i < queued_buffered_byte_ranges_.size(); ++i) {
host()->AddBufferedByteRange(queued_buffered_byte_ranges_.start(i),
queued_buffered_byte_ranges_.end(i));
}
queued_buffered_byte_ranges_.clear();
if (total_bytes_ == kPositionNotSpecified)
return;
host()->SetTotalBytes(total_bytes_);
if (assume_fully_buffered_)
host()->AddBufferedByteRange(0, total_bytes_);
} }
void BufferedDataSource::UpdateDeferStrategy(bool paused) { void BufferedDataSource::UpdateDeferStrategy(bool paused) {
......
...@@ -36,11 +36,14 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource { ...@@ -36,11 +36,14 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource {
public: public:
typedef base::Callback<void(bool)> DownloadingCB; typedef base::Callback<void(bool)> DownloadingCB;
// |downloading_cb| will be called whenever the downloading/paused state of // Buffered byte range changes will be reported to |host|. |downloading_cb|
// the source changes. // will be called whenever the downloading/paused state of the source changes.
// TODO(sandersd): Move media::DataSourceHost to
// content::BufferedDataSourceHost.
BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop, BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop,
blink::WebFrame* frame, blink::WebFrame* frame,
media::MediaLog* media_log, media::MediaLog* media_log,
media::DataSourceHost* host,
const DownloadingCB& downloading_cb); const DownloadingCB& downloading_cb);
virtual ~BufferedDataSource(); virtual ~BufferedDataSource();
...@@ -81,7 +84,6 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource { ...@@ -81,7 +84,6 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource {
// media::DataSource implementation. // media::DataSource implementation.
// Called from demuxer thread. // Called from demuxer thread.
virtual void set_host(media::DataSourceHost* host) OVERRIDE;
virtual void Stop(const base::Closure& closure) OVERRIDE; virtual void Stop(const base::Closure& closure) OVERRIDE;
virtual void Read(int64 position, int size, uint8* data, virtual void Read(int64 position, int size, uint8* data,
...@@ -129,12 +131,6 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource { ...@@ -129,12 +131,6 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource {
void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state); void LoadingStateChangedCallback(BufferedResourceLoader::LoadingState state);
void ProgressCallback(int64 position); void ProgressCallback(int64 position);
// Report a buffered byte range [start,end] or queue it for later
// reporting if set_host() hasn't been called yet.
void ReportOrQueueBufferedBytes(int64 start, int64 end);
void UpdateHostState_Locked();
// Update |loader_|'s deferring strategy in response to a play/pause, or // Update |loader_|'s deferring strategy in response to a play/pause, or
// change in playback rate. // change in playback rate.
void UpdateDeferStrategy(bool paused); void UpdateDeferStrategy(bool paused);
...@@ -207,11 +203,11 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource { ...@@ -207,11 +203,11 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource {
// Current playback rate. // Current playback rate.
float playback_rate_; float playback_rate_;
// Buffered byte ranges awaiting set_host() being called to report to host().
media::Ranges<int64> queued_buffered_byte_ranges_;
scoped_refptr<media::MediaLog> media_log_; scoped_refptr<media::MediaLog> media_log_;
// Host object to report buffered byte range changes to.
media::DataSourceHost* host_;
DownloadingCB downloading_cb_; DownloadingCB downloading_cb_;
// NOTE: Weak pointers must be invalidated before all other member variables. // NOTE: Weak pointers must be invalidated before all other member variables.
......
...@@ -37,8 +37,9 @@ class MockBufferedDataSource : public BufferedDataSource { ...@@ -37,8 +37,9 @@ class MockBufferedDataSource : public BufferedDataSource {
public: public:
MockBufferedDataSource( MockBufferedDataSource(
const scoped_refptr<base::MessageLoopProxy>& message_loop, const scoped_refptr<base::MessageLoopProxy>& message_loop,
WebFrame* frame) WebFrame* frame,
: BufferedDataSource(message_loop, frame, new media::MediaLog(), media::DataSourceHost* host)
: BufferedDataSource(message_loop, frame, new media::MediaLog(), host,
base::Bind(&MockBufferedDataSource::set_downloading, base::Bind(&MockBufferedDataSource::set_downloading,
base::Unretained(this))), base::Unretained(this))),
downloading_(false), downloading_(false),
...@@ -96,8 +97,7 @@ class BufferedDataSourceTest : public testing::Test { ...@@ -96,8 +97,7 @@ class BufferedDataSourceTest : public testing::Test {
view_->setMainFrame(frame_); view_->setMainFrame(frame_);
data_source_.reset(new MockBufferedDataSource( data_source_.reset(new MockBufferedDataSource(
message_loop_.message_loop_proxy(), view_->mainFrame())); message_loop_.message_loop_proxy(), view_->mainFrame(), &host_));
data_source_->set_host(&host_);
} }
virtual ~BufferedDataSourceTest() { virtual ~BufferedDataSourceTest() {
......
...@@ -308,10 +308,13 @@ void WebMediaPlayerImpl::DoLoad(LoadType load_type, ...@@ -308,10 +308,13 @@ void WebMediaPlayerImpl::DoLoad(LoadType load_type,
} }
// Otherwise it's a regular request which requires resolving the URL first. // Otherwise it's a regular request which requires resolving the URL first.
// TODO(sandersd): Make WMPI a DataSourceHost and pass |this| instead of
// |&pipeline_|.
data_source_.reset(new BufferedDataSource( data_source_.reset(new BufferedDataSource(
main_loop_, main_loop_,
frame_, frame_,
media_log_.get(), media_log_.get(),
&pipeline_,
base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr())));
data_source_->Initialize( data_source_->Initialize(
url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode),
......
...@@ -13,16 +13,8 @@ const int DataSource::kReadError = -1; ...@@ -13,16 +13,8 @@ const int DataSource::kReadError = -1;
DataSourceHost::~DataSourceHost() {} DataSourceHost::~DataSourceHost() {}
DataSource::DataSource() : host_(NULL) {} DataSource::DataSource() {}
DataSource::~DataSource() {} DataSource::~DataSource() {}
void DataSource::set_host(DataSourceHost* host) {
DCHECK(host);
DCHECK(!host_);
host_ = host;
}
DataSourceHost* DataSource::host() { return host_; }
} // namespace media } // namespace media
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
namespace media { namespace media {
// TODO(sandersd): Rename to BufferedDataSourceHost and move to
// content/renderer/media/.
class MEDIA_EXPORT DataSourceHost { class MEDIA_EXPORT DataSourceHost {
public: public:
// Set the total size of the media file. // Set the total size of the media file.
...@@ -21,10 +23,6 @@ class MEDIA_EXPORT DataSourceHost { ...@@ -21,10 +23,6 @@ class MEDIA_EXPORT DataSourceHost {
// pull-based. http://crbug.com/131444 // pull-based. http://crbug.com/131444
virtual void AddBufferedByteRange(int64 start, int64 end) = 0; virtual void AddBufferedByteRange(int64 start, int64 end) = 0;
// Notify the host that time range [start,end] has been buffered.
virtual void AddBufferedTimeRange(base::TimeDelta start,
base::TimeDelta end) = 0;
protected: protected:
virtual ~DataSourceHost(); virtual ~DataSourceHost();
}; };
...@@ -38,8 +36,6 @@ class MEDIA_EXPORT DataSource { ...@@ -38,8 +36,6 @@ class MEDIA_EXPORT DataSource {
DataSource(); DataSource();
virtual ~DataSource(); virtual ~DataSource();
virtual void set_host(DataSourceHost* host);
// Reads |size| bytes from |position| into |data|. And when the read is done // Reads |size| bytes from |position| into |data|. And when the read is done
// or failed, |read_cb| is called with the number of bytes read or // or failed, |read_cb| is called with the number of bytes read or
// kReadError in case of error. // kReadError in case of error.
...@@ -62,12 +58,7 @@ class MEDIA_EXPORT DataSource { ...@@ -62,12 +58,7 @@ class MEDIA_EXPORT DataSource {
// Values of |bitrate| <= 0 are invalid and should be ignored. // Values of |bitrate| <= 0 are invalid and should be ignored.
virtual void SetBitrate(int bitrate) = 0; virtual void SetBitrate(int bitrate) = 0;
protected:
DataSourceHost* host();
private: private:
DataSourceHost* host_;
DISALLOW_COPY_AND_ASSIGN(DataSource); DISALLOW_COPY_AND_ASSIGN(DataSource);
}; };
......
...@@ -17,8 +17,12 @@ namespace media { ...@@ -17,8 +17,12 @@ namespace media {
class TextTrackConfig; class TextTrackConfig;
class MEDIA_EXPORT DemuxerHost : public DataSourceHost { class MEDIA_EXPORT DemuxerHost {
public: public:
// Notify the host that time range [start,end] has been buffered.
virtual void AddBufferedTimeRange(base::TimeDelta start,
base::TimeDelta end) = 0;
// Sets the duration of the media in microseconds. // Sets the duration of the media in microseconds.
// Duration may be kInfiniteDuration() if the duration is not known. // Duration may be kInfiniteDuration() if the duration is not known.
virtual void SetDuration(base::TimeDelta duration) = 0; virtual void SetDuration(base::TimeDelta duration) = 0;
......
...@@ -24,13 +24,9 @@ class DemuxerHostImpl : public media::DemuxerHost { ...@@ -24,13 +24,9 @@ class DemuxerHostImpl : public media::DemuxerHost {
DemuxerHostImpl() {} DemuxerHostImpl() {}
virtual ~DemuxerHostImpl() {} virtual ~DemuxerHostImpl() {}
// DataSourceHost implementation. // DemuxerHost implementation.
virtual void SetTotalBytes(int64 total_bytes) OVERRIDE {}
virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE {}
virtual void AddBufferedTimeRange(base::TimeDelta start, virtual void AddBufferedTimeRange(base::TimeDelta start,
base::TimeDelta end) OVERRIDE {} base::TimeDelta end) OVERRIDE {}
// DemuxerHost implementation.
virtual void SetDuration(base::TimeDelta duration) OVERRIDE {} virtual void SetDuration(base::TimeDelta duration) OVERRIDE {}
virtual void OnDemuxerError(media::PipelineStatus error) OVERRIDE {} virtual void OnDemuxerError(media::PipelineStatus error) OVERRIDE {}
virtual void AddTextStream(media::DemuxerStream* text_stream, virtual void AddTextStream(media::DemuxerStream* text_stream,
......
...@@ -17,11 +17,8 @@ class MockDataSourceHost : public DataSourceHost { ...@@ -17,11 +17,8 @@ class MockDataSourceHost : public DataSourceHost {
MockDataSourceHost(); MockDataSourceHost();
virtual ~MockDataSourceHost(); virtual ~MockDataSourceHost();
// DataSourceHost implementation.
MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes)); MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes));
MOCK_METHOD2(AddBufferedByteRange, void(int64 start, int64 end)); MOCK_METHOD2(AddBufferedByteRange, void(int64 start, int64 end));
MOCK_METHOD2(AddBufferedTimeRange, void(base::TimeDelta start,
base::TimeDelta end));
private: private:
DISALLOW_COPY_AND_ASSIGN(MockDataSourceHost); DISALLOW_COPY_AND_ASSIGN(MockDataSourceHost);
......
...@@ -16,15 +16,10 @@ class MockDemuxerHost : public DemuxerHost { ...@@ -16,15 +16,10 @@ class MockDemuxerHost : public DemuxerHost {
MockDemuxerHost(); MockDemuxerHost();
virtual ~MockDemuxerHost(); virtual ~MockDemuxerHost();
// DataSourceHost implementation.
MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes));
MOCK_METHOD2(AddBufferedByteRange, void(int64 start, int64 end));
MOCK_METHOD2(AddBufferedTimeRange, void(base::TimeDelta start, MOCK_METHOD2(AddBufferedTimeRange, void(base::TimeDelta start,
base::TimeDelta end)); base::TimeDelta end));
// DemuxerHost implementation.
MOCK_METHOD1(OnDemuxerError, void(PipelineStatus error));
MOCK_METHOD1(SetDuration, void(base::TimeDelta duration)); MOCK_METHOD1(SetDuration, void(base::TimeDelta duration));
MOCK_METHOD1(OnDemuxerError, void(PipelineStatus error));
MOCK_METHOD2(AddTextStream, void(DemuxerStream*, MOCK_METHOD2(AddTextStream, void(DemuxerStream*,
const TextTrackConfig&)); const TextTrackConfig&));
MOCK_METHOD1(RemoveTextStream, void(DemuxerStream*)); MOCK_METHOD1(RemoveTextStream, void(DemuxerStream*));
......
...@@ -374,7 +374,6 @@ void Pipeline::SetDuration(TimeDelta duration) { ...@@ -374,7 +374,6 @@ void Pipeline::SetDuration(TimeDelta duration) {
} }
void Pipeline::SetTotalBytes(int64 total_bytes) { void Pipeline::SetTotalBytes(int64 total_bytes) {
DCHECK(IsRunning());
media_log_->AddEvent( media_log_->AddEvent(
media_log_->CreateStringEvent( media_log_->CreateStringEvent(
MediaLogEvent::TOTAL_BYTES_SET, "total_bytes", MediaLogEvent::TOTAL_BYTES_SET, "total_bytes",
...@@ -685,7 +684,6 @@ void Pipeline::OnStopCompleted(PipelineStatus status) { ...@@ -685,7 +684,6 @@ void Pipeline::OnStopCompleted(PipelineStatus status) {
} }
void Pipeline::AddBufferedByteRange(int64 start, int64 end) { void Pipeline::AddBufferedByteRange(int64 start, int64 end) {
DCHECK(IsRunning());
base::AutoLock auto_lock(lock_); base::AutoLock auto_lock(lock_);
buffered_byte_ranges_.Add(start, end); buffered_byte_ranges_.Add(start, end);
did_loading_progress_ = true; did_loading_progress_ = true;
......
...@@ -76,7 +76,7 @@ typedef base::Callback<void(PipelineMetadata)> PipelineMetadataCB; ...@@ -76,7 +76,7 @@ typedef base::Callback<void(PipelineMetadata)> PipelineMetadataCB;
// If any error ever happens, this object will transition to the "Error" state // If any error ever happens, this object will transition to the "Error" state
// from any state. If Stop() is ever called, this object will transition to // from any state. If Stop() is ever called, this object will transition to
// "Stopped" state. // "Stopped" state.
class MEDIA_EXPORT Pipeline : public DemuxerHost { class MEDIA_EXPORT Pipeline : public DataSourceHost, public DemuxerHost {
public: public:
// Constructs a media pipeline that will execute on |task_runner|. // Constructs a media pipeline that will execute on |task_runner|.
Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
......
...@@ -38,11 +38,9 @@ using ::testing::WithArg; ...@@ -38,11 +38,9 @@ using ::testing::WithArg;
namespace media { namespace media {
// Demuxer properties.
const int kTotalBytes = 1024; const int kTotalBytes = 1024;
ACTION_P(SetDemuxerProperties, duration) { ACTION_P(SetDemuxerProperties, duration) {
arg0->SetTotalBytes(kTotalBytes);
arg0->SetDuration(duration); arg0->SetDuration(duration);
} }
...@@ -219,6 +217,13 @@ class PipelineTest : public ::testing::Test { ...@@ -219,6 +217,13 @@ class PipelineTest : public ::testing::Test {
EXPECT_CALL(callbacks_, OnPrerollCompleted()); EXPECT_CALL(callbacks_, OnPrerollCompleted());
} }
// HACK: This is required to test the time range code now that DemuxerHost
// does not include SetTotalBytes(). The test cases that depend on this will
// be moved out of pipeline_unittest when Pipeline stops implementing
// DataSourceHost, see http://crbug.com/122071.
DataSourceHost* host = pipeline_.get();
host->SetTotalBytes(kTotalBytes);
pipeline_->Start( pipeline_->Start(
filter_collection_.Pass(), filter_collection_.Pass(),
base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
......
...@@ -444,10 +444,6 @@ void FFmpegDemuxer::Initialize(DemuxerHost* host, ...@@ -444,10 +444,6 @@ void FFmpegDemuxer::Initialize(DemuxerHost* host,
host_ = host; host_ = host;
text_enabled_ = enable_text_tracks; text_enabled_ = enable_text_tracks;
// TODO(scherkus): DataSource should have a host by this point,
// see http://crbug.com/122071
data_source_->set_host(host);
url_protocol_.reset(new BlockingUrlProtocol(data_source_, BindToCurrentLoop( url_protocol_.reset(new BlockingUrlProtocol(data_source_, BindToCurrentLoop(
base::Bind(&FFmpegDemuxer::OnDataSourceError, base::Unretained(this))))); base::Bind(&FFmpegDemuxer::OnDataSourceError, base::Unretained(this)))));
glue_.reset(new FFmpegGlue(url_protocol_.get())); glue_.reset(new FFmpegGlue(url_protocol_.get()));
......
...@@ -75,8 +75,6 @@ class FFmpegDemuxerTest : public testing::Test { ...@@ -75,8 +75,6 @@ class FFmpegDemuxerTest : public testing::Test {
void CreateDemuxer(const std::string& name) { void CreateDemuxer(const std::string& name) {
CHECK(!demuxer_); CHECK(!demuxer_);
EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber());
EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber());
EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber());
CreateDataSource(name); CreateDataSource(name);
......
...@@ -18,25 +18,12 @@ FileDataSource::FileDataSource() ...@@ -18,25 +18,12 @@ FileDataSource::FileDataSource()
FileDataSource::FileDataSource(base::File file) FileDataSource::FileDataSource(base::File file)
: force_read_errors_(false), : force_read_errors_(false),
force_streaming_(false) { force_streaming_(false) {
if (!file_.Initialize(file.Pass())) file_.Initialize(file.Pass());
return;
UpdateHostBytes();
} }
bool FileDataSource::Initialize(const base::FilePath& file_path) { bool FileDataSource::Initialize(const base::FilePath& file_path) {
DCHECK(!file_.IsValid()); DCHECK(!file_.IsValid());
return file_.Initialize(file_path);
if (!file_.Initialize(file_path))
return false;
UpdateHostBytes();
return true;
}
void FileDataSource::set_host(DataSourceHost* host) {
DataSource::set_host(host);
UpdateHostBytes();
} }
void FileDataSource::Stop(const base::Closure& callback) { void FileDataSource::Stop(const base::Closure& callback) {
...@@ -77,11 +64,4 @@ void FileDataSource::SetBitrate(int bitrate) {} ...@@ -77,11 +64,4 @@ void FileDataSource::SetBitrate(int bitrate) {}
FileDataSource::~FileDataSource() {} FileDataSource::~FileDataSource() {}
void FileDataSource::UpdateHostBytes() {
if (host() && file_.IsValid()) {
host()->SetTotalBytes(file_.length());
host()->AddBufferedByteRange(0, file_.length());
}
}
} // namespace media } // namespace media
...@@ -25,7 +25,6 @@ class MEDIA_EXPORT FileDataSource : public DataSource { ...@@ -25,7 +25,6 @@ class MEDIA_EXPORT FileDataSource : public DataSource {
bool Initialize(const base::FilePath& file_path); bool Initialize(const base::FilePath& file_path);
// Implementation of DataSource. // Implementation of DataSource.
virtual void set_host(DataSourceHost* host) OVERRIDE;
virtual void Stop(const base::Closure& callback) OVERRIDE; virtual void Stop(const base::Closure& callback) OVERRIDE;
virtual void Read(int64 position, int size, uint8* data, virtual void Read(int64 position, int size, uint8* data,
const DataSource::ReadCB& read_cb) OVERRIDE; const DataSource::ReadCB& read_cb) OVERRIDE;
...@@ -38,9 +37,6 @@ class MEDIA_EXPORT FileDataSource : public DataSource { ...@@ -38,9 +37,6 @@ class MEDIA_EXPORT FileDataSource : public DataSource {
void force_streaming_for_testing() { force_streaming_ = true; } void force_streaming_for_testing() { force_streaming_ = true; }
private: private:
// Informs the host of changes in total and buffered bytes.
void UpdateHostBytes();
base::MemoryMappedFile file_; base::MemoryMappedFile file_;
bool force_read_errors_; bool force_read_errors_;
......
...@@ -44,31 +44,15 @@ base::FilePath TestFileURL() { ...@@ -44,31 +44,15 @@ base::FilePath TestFileURL() {
return data_dir; return data_dir;
} }
// Test that FileDataSource call the appropriate methods on its filter host.
TEST(FileDataSourceTest, OpenFile) {
StrictMock<MockDataSourceHost> host;
EXPECT_CALL(host, SetTotalBytes(10));
EXPECT_CALL(host, AddBufferedByteRange(0, 10));
FileDataSource data_source;
data_source.set_host(&host);
EXPECT_TRUE(data_source.Initialize(TestFileURL()));
data_source.Stop(NewExpectedClosure());
}
// Use the mock filter host to directly call the Read and GetPosition methods. // Use the mock filter host to directly call the Read and GetPosition methods.
TEST(FileDataSourceTest, ReadData) { TEST(FileDataSourceTest, ReadData) {
int64 size; int64 size;
uint8 ten_bytes[10]; uint8 ten_bytes[10];
// Create our mock filter host and initialize the data source. // Create our mock filter host and initialize the data source.
NiceMock<MockDataSourceHost> host;
FileDataSource data_source; FileDataSource data_source;
data_source.set_host(&host);
EXPECT_TRUE(data_source.Initialize(TestFileURL())); EXPECT_TRUE(data_source.Initialize(TestFileURL()));
EXPECT_TRUE(data_source.GetSize(&size)); EXPECT_TRUE(data_source.GetSize(&size));
EXPECT_EQ(10, size); EXPECT_EQ(10, size);
......
...@@ -1166,10 +1166,6 @@ TEST_P(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) { ...@@ -1166,10 +1166,6 @@ TEST_P(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) {
TEST_F(PipelineIntegrationTest, BasicPlayback_AudioOnly_Opus_WebM) { TEST_F(PipelineIntegrationTest, BasicPlayback_AudioOnly_Opus_WebM) {
ASSERT_TRUE(Start(GetTestDataFilePath("bear-opus-end-trimming.webm"), ASSERT_TRUE(Start(GetTestDataFilePath("bear-opus-end-trimming.webm"),
PIPELINE_OK)); PIPELINE_OK));
EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
Play(); Play();
ASSERT_TRUE(WaitUntilOnEnded()); ASSERT_TRUE(WaitUntilOnEnded());
} }
......
...@@ -25,11 +25,6 @@ DataSourceLogger::DataSourceLogger( ...@@ -25,11 +25,6 @@ DataSourceLogger::DataSourceLogger(
streaming_(streaming) { streaming_(streaming) {
} }
void DataSourceLogger::set_host(media::DataSourceHost* host) {
VLOG(1) << "set_host(" << host << ")";
data_source_->set_host(host);
}
void DataSourceLogger::Stop(const base::Closure& closure) { void DataSourceLogger::Stop(const base::Closure& closure) {
VLOG(1) << "Stop() started"; VLOG(1) << "Stop() started";
data_source_->Stop(base::Bind(&LogAndRunStopClosure, closure)); data_source_->Stop(base::Bind(&LogAndRunStopClosure, closure));
......
...@@ -22,7 +22,6 @@ class DataSourceLogger : public media::DataSource { ...@@ -22,7 +22,6 @@ class DataSourceLogger : public media::DataSource {
virtual ~DataSourceLogger(); virtual ~DataSourceLogger();
// media::DataSource implementation. // media::DataSource implementation.
virtual void set_host(media::DataSourceHost* host) OVERRIDE;
virtual void Stop(const base::Closure& closure) OVERRIDE; virtual void Stop(const base::Closure& closure) OVERRIDE;
virtual void Read( virtual void Read(
int64 position, int size, uint8* data, int64 position, int size, uint8* data,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment