summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 19:55:20 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 19:55:20 +0000
commita9415292f9aedca5c528532f1260118ad384aaed (patch)
treedf6dde3058efb3594a77ef78ce904c624f78da30
parentd2353452f11b73f763ea0be9f1a608d03cfddeac (diff)
downloadchromium_src-a9415292f9aedca5c528532f1260118ad384aaed.zip
chromium_src-a9415292f9aedca5c528532f1260118ad384aaed.tar.gz
chromium_src-a9415292f9aedca5c528532f1260118ad384aaed.tar.bz2
Replace DataSourceFactory with explicitly initialized DataSources.
BUG=107324 TEST=layout tests Review URL: https://chromiumcodereview.appspot.com/9243016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118338 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/base/async_filter_factory_base.cc113
-rw-r--r--media/base/async_filter_factory_base.h121
-rw-r--r--media/base/composite_data_source_factory.cc98
-rw-r--r--media/base/composite_data_source_factory.h42
-rw-r--r--media/base/demuxer_factory.cc (renamed from media/base/filter_factories.cc)6
-rw-r--r--media/base/demuxer_factory.h (renamed from media/base/filter_factories.h)20
-rw-r--r--media/base/filter_collection.h2
-rw-r--r--media/filters/chunk_demuxer_factory.cc19
-rw-r--r--media/filters/chunk_demuxer_factory.h13
-rw-r--r--media/filters/dummy_demuxer_factory.h2
-rw-r--r--media/filters/ffmpeg_demuxer_factory.cc32
-rw-r--r--media/filters/ffmpeg_demuxer_factory.h6
-rw-r--r--media/filters/file_data_source_factory.cc34
-rw-r--r--media/filters/file_data_source_factory.h27
-rw-r--r--media/filters/pipeline_integration_test.cc13
-rw-r--r--media/media.gyp10
-rw-r--r--media/tools/player_wtl/movie.cc21
-rw-r--r--media/tools/player_x11/player_x11.cc15
-rw-r--r--webkit/media/buffered_data_source.cc34
-rw-r--r--webkit/media/buffered_data_source.h14
-rw-r--r--webkit/media/buffered_data_source_unittest.cc2
-rw-r--r--webkit/media/filter_helpers.cc81
-rw-r--r--webkit/media/filter_helpers.h53
-rw-r--r--webkit/media/simple_data_source.cc38
-rw-r--r--webkit/media/simple_data_source.h14
-rw-r--r--webkit/media/simple_data_source_unittest.cc6
-rw-r--r--webkit/media/web_data_source.h27
-rw-r--r--webkit/media/web_data_source_factory.cc105
-rw-r--r--webkit/media/web_data_source_factory.h56
-rw-r--r--webkit/media/webkit_media.gypi6
-rw-r--r--webkit/media/webmediaplayer_impl.cc154
-rw-r--r--webkit/media/webmediaplayer_impl.h16
-rw-r--r--webkit/media/webmediaplayer_proxy.cc37
-rw-r--r--webkit/media/webmediaplayer_proxy.h17
34 files changed, 322 insertions, 932 deletions
diff --git a/media/base/async_filter_factory_base.cc b/media/base/async_filter_factory_base.cc
deleted file mode 100644
index 464f3b8..0000000
--- a/media/base/async_filter_factory_base.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "media/base/async_filter_factory_base.h"
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/stl_util.h"
-
-namespace media {
-
-AsyncDataSourceFactoryBase::AsyncDataSourceFactoryBase() {}
-
-AsyncDataSourceFactoryBase::~AsyncDataSourceFactoryBase() {
- base::AutoLock auto_lock(lock_);
- STLDeleteElements(&outstanding_requests_);
-}
-
-void AsyncDataSourceFactoryBase::Build(const std::string& url,
- const BuildCallback& callback) {
- DCHECK(!callback.is_null());
- BuildRequest* request = NULL;
- {
- base::AutoLock auto_lock(lock_);
-
- if (url.empty()) {
- ReportError(PIPELINE_ERROR_URL_NOT_FOUND, callback);
- return;
- }
-
- if (!AllowRequests()) {
- ReportError(DATASOURCE_ERROR_URL_NOT_SUPPORTED, callback);
- return;
- }
-
- request = CreateRequest(url, callback);
-
- if (!request) {
- ReportError(DATASOURCE_ERROR_URL_NOT_SUPPORTED, callback);
- return;
- }
-
- outstanding_requests_.insert(request);
- }
-
- request->Start(base::Bind(
- &AsyncDataSourceFactoryBase::BuildRequestDone, base::Unretained(this)));
-}
-
-void AsyncDataSourceFactoryBase::ReportError(
- PipelineStatus error,
- const BuildCallback& callback) const {
- DCHECK_NE(error, PIPELINE_OK);
- DCHECK(!callback.is_null());
-
- callback.Run(error, NULL);
-}
-
-void AsyncDataSourceFactoryBase::BuildRequestDone(BuildRequest* request) {
- base::AutoLock auto_lock(lock_);
- outstanding_requests_.erase(request);
- delete request;
-}
-
-AsyncDataSourceFactoryBase::BuildRequest::BuildRequest(
- const std::string& url, const BuildCallback& callback)
- : url_(url),
- callback_(callback) {
-}
-
-AsyncDataSourceFactoryBase::BuildRequest::~BuildRequest() {}
-
-void AsyncDataSourceFactoryBase::BuildRequest::Start(
- const RequestDoneCallback& done_callback) {
- DCHECK(!done_callback.is_null());
- DCHECK(done_callback_.is_null());
-
- done_callback_ = done_callback;
- DoStart();
- // Don't do anything after this line since the object could
- // have been deleted at this point if the request was completed
- // inside the call.
-}
-
-void AsyncDataSourceFactoryBase::BuildRequest::RequestComplete(
- PipelineStatus status, DataSource* data_source) {
- DCHECK(!callback_.is_null());
- DCHECK(!done_callback_.is_null());
-
- // Transfer ownership to local variables just in case the
- // request object gets deleted by one of the callbacks.
- RequestDoneCallback done_callback;
- std::swap(done_callback, done_callback_);
- BuildCallback callback;
- std::swap(callback, callback_);
-
- // Notify factory that this request has completed. We do this before
- // calling |callback| so the factory doesn't consider this request
- // pending if |callback| happens to destroy the factory.
- //
- // NOTE: This BuildRequest object is destroyed inside this callback so
- // no modifications should be made to this object after this call.
- done_callback.Run(this);
-
- callback.Run(status, data_source);
-}
-
-const std::string& AsyncDataSourceFactoryBase::BuildRequest::url() const {
- return url_;
-}
-
-} // namespace media
diff --git a/media/base/async_filter_factory_base.h b/media/base/async_filter_factory_base.h
deleted file mode 100644
index 87b4b3e..0000000
--- a/media/base/async_filter_factory_base.h
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MEDIA_BASE_ASYNC_FILTER_FACTORY_BASE_H_
-#define MEDIA_BASE_ASYNC_FILTER_FACTORY_BASE_H_
-
-#include <set>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/synchronization/lock.h"
-#include "media/base/filter_factories.h"
-
-namespace media {
-
-// This is a helper base class for DataSourceFactory implementation that
-// actually require asynchronous operations to build a data source. It
-// provides a common framework for dealing with an asychronous build.
-// Factories are expected to derive from this object and implement
-// AllowRequests(), CreateRequest(), and an custom implementation that derives
-// from BuildRequest.
-//
-// AllowRequests() just checks to see if the factory is in a state where it can
-// accept Build() requests. If it returns false, this base class will signal an
-// error through the BuildCallback and not call any of the other code. If
-// AllowRequests() returns true then this class will continue with the build
-// process by calling CreateRequest().
-//
-// CreateRequest() allows the derived implementation to create an instance of
-// their custom BuildRequest implementation that is specific to its asynchronous
-// build process. The custom BuildRequest should contain all of the state that
-// needs to be maintained for a particular build request. This state could
-// consist of partially initialized objects that require asynchronous operations
-// to complete before the build completes. This implementation MUST derive from
-// AsyncDataSourceFactoryBase::BuildRequest.
-//
-// Once CreateRequest() returns a BuildRequest implementation, this class adds
-// the object to its request list and then calls Start() on the BuildRequest
-// instance. BuildRequest::Start() manages storing the |done_callback| passed to
-// it and then call DoStart() on the derived object. DoStart() is where this
-// framework expects any neccesary asynchronous operations to be initiated.
-//
-// Once all asynchronous operations are completed and a fully initialized
-// DataSource object has been created, the BuildRequest instance should call
-// the RequestComplete() method. This call signals the end of the request and
-// the BuildRequest should be in a state where it can be deleted from inside
-// this call. If an error occurs during the build process, RequestComplete()
-// can also be called to signal the error.
-class MEDIA_EXPORT AsyncDataSourceFactoryBase : public DataSourceFactory {
- public:
- AsyncDataSourceFactoryBase();
- virtual ~AsyncDataSourceFactoryBase();
-
- // DataSourceFactory method.
- // Derived classes should not overload this Build() method. AllowRequests() &
- // CreateRequest() should be implemented instead.
- virtual void Build(const std::string& url,
- const BuildCallback& callback) OVERRIDE;
-
- protected:
- class MEDIA_EXPORT BuildRequest {
- public:
- BuildRequest(const std::string& url, const BuildCallback& callback);
- virtual ~BuildRequest();
-
- typedef base::Callback<void(BuildRequest*)> RequestDoneCallback;
- // Starts the build request.
- void Start(const RequestDoneCallback& done_callback);
-
- // Derived objects call this method to indicate that the build request
- // has completed. If the build was successful |status| should be set to
- // PIPELINE_OK and |data_source| should contain the DataSource object
- // that was built by this request. Ownership of |data_source| is being
- // passed in this call. If an error occurs during the build process, this
- // method should be called with |status| set to an appropriate status code
- // and |data_source| set to NULL.
- //
- // The derived object should be in a state where it can be deleted from
- // within this call. This class as well AsyncDataSourceFactoryBase use this
- // method to cleanup state associated with this request.
- void RequestComplete(media::PipelineStatus status, DataSource* data_source);
-
- protected:
- // Implemented by the derived object to start the build. Called by Start().
- virtual void DoStart() = 0;
-
- // Gets the requested URL.
- const std::string& url() const;
-
- private:
- std::string url_;
- BuildCallback callback_;
- RequestDoneCallback done_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(BuildRequest);
- };
-
- // Implemented by derived class. Called by Build() to check if the
- // factory is in a state where it can accept requests.
- virtual bool AllowRequests() const = 0;
-
- // Implemented by derived class. Called by Build() to allow derived objects
- // to create their own custom BuildRequest implementations.
- virtual BuildRequest* CreateRequest(const std::string& url,
- const BuildCallback& callback) = 0;
-
- private:
- void ReportError(PipelineStatus error, const BuildCallback& callback) const;
-
- void BuildRequestDone(BuildRequest* request);
-
- base::Lock lock_;
- typedef std::set<BuildRequest*> RequestSet;
- RequestSet outstanding_requests_;
-
- DISALLOW_COPY_AND_ASSIGN(AsyncDataSourceFactoryBase);
-};
-
-} // namespace media
-
-#endif // MEDIA_BASE_ASYNC_FILTER_FACTORY_BASE_H_
diff --git a/media/base/composite_data_source_factory.cc b/media/base/composite_data_source_factory.cc
deleted file mode 100644
index e91415f..0000000
--- a/media/base/composite_data_source_factory.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "media/base/composite_data_source_factory.h"
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/stl_util.h"
-
-namespace media {
-
-class CompositeDataSourceFactory::BuildRequest
- : public AsyncDataSourceFactoryBase::BuildRequest {
- public:
- BuildRequest(const std::string& url, const BuildCallback& callback,
- const FactoryList& factories);
- ~BuildRequest();
-
- protected:
- // AsyncDataSourceFactoryBase::BuildRequest method.
- virtual void DoStart();
-
- private:
- void CallNextFactory();
- void OnBuildDone(PipelineStatus status, DataSource* data_source);
-
- FactoryList factories_; // Not owned by this class.
-};
-
-CompositeDataSourceFactory::CompositeDataSourceFactory() {}
-
-CompositeDataSourceFactory::~CompositeDataSourceFactory() {
- STLDeleteElements(&factories_);
-}
-
-void CompositeDataSourceFactory::AddFactory(
- scoped_ptr<DataSourceFactory> factory) {
- DCHECK(factory.get());
- factories_.push_back(factory.release());
-}
-
-bool CompositeDataSourceFactory::AllowRequests() const {
- return !factories_.empty();
-}
-
-AsyncDataSourceFactoryBase::BuildRequest*
-CompositeDataSourceFactory::CreateRequest(const std::string& url,
- const BuildCallback& callback) {
- return new BuildRequest(url, callback, factories_);
-}
-
-CompositeDataSourceFactory::BuildRequest::BuildRequest(
- const std::string& url,
- const BuildCallback& callback,
- const FactoryList& factories)
- : AsyncDataSourceFactoryBase::BuildRequest(url, callback),
- factories_(factories){
- DCHECK(!factories.empty());
-}
-
-CompositeDataSourceFactory::BuildRequest::~BuildRequest() {}
-
-void CompositeDataSourceFactory::BuildRequest::DoStart() {
- CallNextFactory();
-}
-
-void CompositeDataSourceFactory::BuildRequest::CallNextFactory() {
- DCHECK(!factories_.empty());
-
- DataSourceFactory* factory = factories_.front();
- factories_.pop_front();
-
- factory->Build(url(), base::Bind(&BuildRequest::OnBuildDone,
- base::Unretained(this)));
-}
-
-void CompositeDataSourceFactory::BuildRequest::OnBuildDone(
- PipelineStatus status,
- DataSource* data_source) {
-
- if (status == PIPELINE_OK) {
- DCHECK(data_source);
- RequestComplete(status, data_source);
- return;
- }
-
- DCHECK(!data_source);
- if ((status == DATASOURCE_ERROR_URL_NOT_SUPPORTED) && !factories_.empty()) {
- CallNextFactory();
- return;
- }
-
- RequestComplete(status, data_source);
-}
-
-} // namespace media
diff --git a/media/base/composite_data_source_factory.h b/media/base/composite_data_source_factory.h
deleted file mode 100644
index 54f6387..0000000
--- a/media/base/composite_data_source_factory.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MEDIA_BASE_COMPOSITE_DATA_SOURCE_FACTORY_H_
-#define MEDIA_BASE_COMPOSITE_DATA_SOURCE_FACTORY_H_
-
-#include <list>
-#include <set>
-
-#include "base/synchronization/lock.h"
-#include "media/base/async_filter_factory_base.h"
-
-namespace media {
-
-class MEDIA_EXPORT CompositeDataSourceFactory
- : public AsyncDataSourceFactoryBase {
- public:
- CompositeDataSourceFactory();
- virtual ~CompositeDataSourceFactory();
-
- // Add factory to this composite.
- void AddFactory(scoped_ptr<DataSourceFactory> factory);
-
- protected:
- // AsyncDataSourceFactoryBase methods.
- virtual bool AllowRequests() const OVERRIDE;
- virtual AsyncDataSourceFactoryBase::BuildRequest* CreateRequest(
- const std::string& url, const BuildCallback& callback) OVERRIDE;
-
- private:
- class BuildRequest;
-
- typedef std::list<DataSourceFactory*> FactoryList;
- FactoryList factories_;
-
- DISALLOW_COPY_AND_ASSIGN(CompositeDataSourceFactory);
-};
-
-} // namespace media
-
-#endif // MEDIA_BASE_COMPOSITE_DATA_SOURCE_FACTORY_H_
diff --git a/media/base/filter_factories.cc b/media/base/demuxer_factory.cc
index c074cc6..1f968d7 100644
--- a/media/base/filter_factories.cc
+++ b/media/base/demuxer_factory.cc
@@ -1,13 +1,11 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "media/base/filter_factories.h"
+#include "media/base/demuxer_factory.h"
namespace media {
-DataSourceFactory::~DataSourceFactory() {}
-
DemuxerFactory::~DemuxerFactory() {}
} // namespace media
diff --git a/media/base/filter_factories.h b/media/base/demuxer_factory.h
index 0e004ef..6a13356 100644
--- a/media/base/filter_factories.h
+++ b/media/base/demuxer_factory.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MEDIA_BASE_FILTER_FACTORIES_H_
-#define MEDIA_BASE_FILTER_FACTORIES_H_
+#ifndef MEDIA_BASE_DEMUXER_FACTORY_H_
+#define MEDIA_BASE_DEMUXER_FACTORY_H_
#include <string>
@@ -13,20 +13,6 @@
namespace media {
-class DataSource;
-
-// Asynchronous factory interface for building DataSource objects.
-class MEDIA_EXPORT DataSourceFactory {
- public:
- // Ownership of the DataSource is transferred through this callback.
- typedef base::Callback<void(PipelineStatus, DataSource*)> BuildCallback;
-
- virtual ~DataSourceFactory();
-
- // Builds a DataSource for |url| and returns it via |callback|.
- virtual void Build(const std::string& url, const BuildCallback& callback) = 0;
-};
-
class Demuxer;
// Asynchronous factory interface for building Demuxer objects.
@@ -43,4 +29,4 @@ class MEDIA_EXPORT DemuxerFactory {
} // namespace media
-#endif // MEDIA_BASE_FILTER_FACTORIES_H_
+#endif // MEDIA_BASE_DEMUXER_FACTORY_H_
diff --git a/media/base/filter_collection.h b/media/base/filter_collection.h
index f129723..35bd1de 100644
--- a/media/base/filter_collection.h
+++ b/media/base/filter_collection.h
@@ -8,8 +8,8 @@
#include <list>
#include "base/memory/ref_counted.h"
+#include "media/base/demuxer_factory.h"
#include "media/base/filters.h"
-#include "media/base/filter_factories.h"
namespace media {
diff --git a/media/filters/chunk_demuxer_factory.cc b/media/filters/chunk_demuxer_factory.cc
index a441cf7..8455d58 100644
--- a/media/filters/chunk_demuxer_factory.cc
+++ b/media/filters/chunk_demuxer_factory.cc
@@ -19,28 +19,17 @@ static void InitDone(MessageLoop* message_loop,
message_loop->PostTask(FROM_HERE, base::Bind(cb, status, demuxer));
}
-ChunkDemuxerFactory::ChunkDemuxerFactory(
- const std::string& url,
- scoped_ptr<DemuxerFactory> delegate_factory,
- ChunkDemuxerClient* client)
- : url_(url),
- delegate_factory_(delegate_factory.Pass()),
- client_(client) {
- DCHECK(delegate_factory_.get());
+ChunkDemuxerFactory::ChunkDemuxerFactory(ChunkDemuxerClient* client)
+ : client_(client) {
+ DCHECK(client_);
}
ChunkDemuxerFactory::~ChunkDemuxerFactory() {}
void ChunkDemuxerFactory::Build(const std::string& url,
const BuildCallback& cb) {
- // Check to see if this is the URL we are looking for. If not delegate
- // building to the delegate factory.
- if (url != url_) {
- delegate_factory_->Build(url, cb);
- return;
- }
-
scoped_refptr<ChunkDemuxer> demuxer(new ChunkDemuxer(client_));
+
// Call Init() on demuxer. Note that ownership is being passed to the
// callback here.
demuxer->Init(base::Bind(&InitDone, MessageLoop::current(), cb, demuxer));
diff --git a/media/filters/chunk_demuxer_factory.h b/media/filters/chunk_demuxer_factory.h
index 7a3c9fc..9e34a12 100644
--- a/media/filters/chunk_demuxer_factory.h
+++ b/media/filters/chunk_demuxer_factory.h
@@ -8,7 +8,7 @@
#include <string>
#include "base/memory/scoped_ptr.h"
-#include "media/base/filter_factories.h"
+#include "media/base/demuxer_factory.h"
namespace media {
@@ -16,23 +16,16 @@ class ChunkDemuxer;
class ChunkDemuxerClient;
// Factory for building ChunkDemuxers. The factory will only build a
-// ChunkDemuxer for build URLs that match the one passed into the constructor.
-// All other URLs are delegated to |delegate_factory_|. The url passed to
-// the constructor represents the "special" URL that indicates that the
-// ChunkDemuxer should be used for playback.
+// ChunkDemuxer with the given client.
class MEDIA_EXPORT ChunkDemuxerFactory : public DemuxerFactory {
public:
- ChunkDemuxerFactory(const std::string& url,
- scoped_ptr<DemuxerFactory> delegate_factory,
- ChunkDemuxerClient* client);
+ ChunkDemuxerFactory(ChunkDemuxerClient* client);
virtual ~ChunkDemuxerFactory();
// DemuxerFactory methods.
virtual void Build(const std::string& url, const BuildCallback& cb) OVERRIDE;
private:
- std::string url_;
- scoped_ptr<DemuxerFactory> delegate_factory_;
ChunkDemuxerClient* client_;
DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerFactory);
diff --git a/media/filters/dummy_demuxer_factory.h b/media/filters/dummy_demuxer_factory.h
index 266314c..6bbf441 100644
--- a/media/filters/dummy_demuxer_factory.h
+++ b/media/filters/dummy_demuxer_factory.h
@@ -8,7 +8,7 @@
#define MEDIA_FILTERS_DUMMY_DEMUXER_FACTORY_H_
#include "base/compiler_specific.h"
-#include "media/base/filter_factories.h"
+#include "media/base/demuxer_factory.h"
namespace media {
diff --git a/media/filters/ffmpeg_demuxer_factory.cc b/media/filters/ffmpeg_demuxer_factory.cc
index 414c165..0c5e402 100644
--- a/media/filters/ffmpeg_demuxer_factory.cc
+++ b/media/filters/ffmpeg_demuxer_factory.cc
@@ -11,9 +11,11 @@
namespace media {
FFmpegDemuxerFactory::FFmpegDemuxerFactory(
- scoped_ptr<DataSourceFactory> data_source_factory,
+ const scoped_refptr<DataSource>& data_source,
MessageLoop* loop)
- : data_source_factory_(data_source_factory.Pass()), loop_(loop) {}
+ : data_source_(data_source),
+ loop_(loop) {
+}
FFmpegDemuxerFactory::~FFmpegDemuxerFactory() {}
@@ -24,32 +26,18 @@ static void DemuxerInitDone(const DemuxerFactory::BuildCallback& cb,
cb.Run(status, NULL);
return;
}
- cb.Run(PIPELINE_OK, demuxer.get());
-}
-
-static void InitializeDemuxerBasedOnDataSourceStatus(
- const DemuxerFactory::BuildCallback& cb,
- MessageLoop* loop, bool local_source,
- PipelineStatus status, DataSource* data_source) {
- if (status != PIPELINE_OK) {
- cb.Run(status, NULL);
- return;
- }
- DCHECK(data_source);
- scoped_refptr<FFmpegDemuxer> demuxer = new FFmpegDemuxer(loop, local_source);
- demuxer->Initialize(
- data_source,
- base::Bind(&DemuxerInitDone, cb, demuxer));
+ cb.Run(PIPELINE_OK, demuxer);
}
void FFmpegDemuxerFactory::Build(const std::string& url,
const BuildCallback& cb) {
GURL gurl = GURL(url);
bool local_source = !gurl.SchemeIs("http") && !gurl.SchemeIs("https");
- data_source_factory_->Build(
- url,
- base::Bind(&InitializeDemuxerBasedOnDataSourceStatus,
- cb, loop_, local_source));
+ scoped_refptr<FFmpegDemuxer> demuxer = new FFmpegDemuxer(loop_, local_source);
+
+ demuxer->Initialize(
+ data_source_,
+ base::Bind(&DemuxerInitDone, cb, demuxer));
}
} // namespace media
diff --git a/media/filters/ffmpeg_demuxer_factory.h b/media/filters/ffmpeg_demuxer_factory.h
index f35e5d5..6a9463f 100644
--- a/media/filters/ffmpeg_demuxer_factory.h
+++ b/media/filters/ffmpeg_demuxer_factory.h
@@ -9,7 +9,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
-#include "media/base/filter_factories.h"
+#include "media/base/demuxer_factory.h"
class MessageLoop;
@@ -17,7 +17,7 @@ namespace media {
class MEDIA_EXPORT FFmpegDemuxerFactory : public DemuxerFactory {
public:
- FFmpegDemuxerFactory(scoped_ptr<DataSourceFactory> data_source_factory,
+ FFmpegDemuxerFactory(const scoped_refptr<DataSource>& data_source,
MessageLoop* loop);
virtual ~FFmpegDemuxerFactory();
@@ -25,7 +25,7 @@ class MEDIA_EXPORT FFmpegDemuxerFactory : public DemuxerFactory {
virtual void Build(const std::string& url, const BuildCallback& cb) OVERRIDE;
private:
- scoped_ptr<DataSourceFactory> data_source_factory_;
+ scoped_refptr<DataSource> data_source_;
MessageLoop* loop_; // Unowned.
DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegDemuxerFactory);
diff --git a/media/filters/file_data_source_factory.cc b/media/filters/file_data_source_factory.cc
deleted file mode 100644
index 39b07f6..0000000
--- a/media/filters/file_data_source_factory.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "media/filters/file_data_source_factory.h"
-
-#include "base/logging.h"
-#include "media/filters/file_data_source.h"
-
-namespace media {
-
-FileDataSourceFactory::FileDataSourceFactory() {}
-
-FileDataSourceFactory::~FileDataSourceFactory() {}
-
-void FileDataSourceFactory::Build(const std::string& url,
- const BuildCallback& callback) {
- DCHECK(!callback.is_null());
-
- if (url.empty()) {
- callback.Run(media::PIPELINE_ERROR_URL_NOT_FOUND,
- static_cast<media::DataSource*>(NULL));
- return;
- }
-
- scoped_refptr<FileDataSource> file_data_source = new FileDataSource();
-
- PipelineStatus status = file_data_source->Initialize(url);
- DataSource* data_source =
- (status == PIPELINE_OK) ? file_data_source.get() : NULL;
- callback.Run(status, data_source);
-}
-
-} // namespace media
diff --git a/media/filters/file_data_source_factory.h b/media/filters/file_data_source_factory.h
deleted file mode 100644
index af15a1f..0000000
--- a/media/filters/file_data_source_factory.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MEDIA_FILTERS_FILE_DATA_SOURCE_FACTORY_H_
-#define MEDIA_FILTERS_FILE_DATA_SOURCE_FACTORY_H_
-
-#include "media/base/filter_factories.h"
-
-namespace media {
-
-class MEDIA_EXPORT FileDataSourceFactory : public DataSourceFactory {
- public:
- FileDataSourceFactory();
- virtual ~FileDataSourceFactory();
-
- // DataSourceFactory methods.
- virtual void Build(const std::string& url,
- const BuildCallback& callback) OVERRIDE;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(FileDataSourceFactory);
-};
-
-} // namespace media
-
-#endif // MEDIA_FILTERS_FILE_DATA_SOURCE_FACTORY_H_
diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc
index eeb6d60..b64ed09 100644
--- a/media/filters/pipeline_integration_test.cc
+++ b/media/filters/pipeline_integration_test.cc
@@ -12,7 +12,7 @@
#include "media/filters/ffmpeg_audio_decoder.h"
#include "media/filters/ffmpeg_demuxer_factory.h"
#include "media/filters/ffmpeg_video_decoder.h"
-#include "media/filters/file_data_source_factory.h"
+#include "media/filters/file_data_source.h"
#include "media/filters/null_audio_renderer.h"
#include "media/filters/video_renderer_base.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -82,7 +82,7 @@ class PipelineIntegrationTest : public testing::Test {
MOCK_METHOD1(OnError, void(PipelineStatus));
void Start(const std::string& url, PipelineStatus expected_status) {
- pipeline_->Start(CreateFilterCollection(), url,
+ pipeline_->Start(CreateFilterCollection(url), url,
QuitOnStatusCB(expected_status));
message_loop_.Run();
}
@@ -135,13 +135,14 @@ class PipelineIntegrationTest : public testing::Test {
message_loop_.Run();
}
- scoped_ptr<FilterCollection> CreateFilterCollection() {
+ scoped_ptr<FilterCollection> CreateFilterCollection(const std::string& url) {
+ scoped_refptr<FileDataSource> data_source = new FileDataSource();
+ CHECK_EQ(PIPELINE_OK, data_source->Initialize(url));
+
scoped_ptr<FilterCollection> collection(
new FilterCollection());
collection->SetDemuxerFactory(scoped_ptr<DemuxerFactory>(
- new FFmpegDemuxerFactory(
- scoped_ptr<DataSourceFactory>(new FileDataSourceFactory()),
- &message_loop_)));
+ new FFmpegDemuxerFactory(data_source, &message_loop_)));
collection->AddAudioDecoder(new FFmpegAudioDecoder(
message_loop_factory_->GetMessageLoop("AudioDecoderThread")));
collection->AddVideoDecoder(new FFmpegVideoDecoder(
diff --git a/media/media.gyp b/media/media.gyp
index 4d550df..d206ca4 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -96,8 +96,6 @@
'audio/win/wavein_input_win.h',
'audio/win/waveout_output_win.cc',
'audio/win/waveout_output_win.h',
- 'base/async_filter_factory_base.cc',
- 'base/async_filter_factory_base.h',
'base/audio_decoder_config.cc',
'base/audio_decoder_config.h',
'base/bitstream_buffer.h',
@@ -109,8 +107,6 @@
'base/channel_layout.h',
'base/clock.cc',
'base/clock.h',
- 'base/composite_data_source_factory.cc',
- 'base/composite_data_source_factory.h',
'base/composite_filter.cc',
'base/composite_filter.h',
'base/data_buffer.cc',
@@ -119,6 +115,8 @@
'base/data_source.h',
'base/demuxer.cc',
'base/demuxer.h',
+ 'base/demuxer_factory.cc',
+ 'base/demuxer_factory.h',
'base/demuxer_stream.cc',
'base/demuxer_stream.h',
'base/djb2.cc',
@@ -127,8 +125,6 @@
'base/download_rate_monitor.h',
'base/filter_collection.cc',
'base/filter_collection.h',
- 'base/filter_factories.cc',
- 'base/filter_factories.h',
'base/filter_host.h',
'base/filters.cc',
'base/filters.h',
@@ -203,8 +199,6 @@
'filters/ffmpeg_video_decoder.h',
'filters/file_data_source.cc',
'filters/file_data_source.h',
- 'filters/file_data_source_factory.cc',
- 'filters/file_data_source_factory.h',
'filters/gpu_video_decoder.cc',
'filters/gpu_video_decoder.h',
'filters/in_memory_url_protocol.cc',
diff --git a/media/tools/player_wtl/movie.cc b/media/tools/player_wtl/movie.cc
index f97f88a..fcecd5f 100644
--- a/media/tools/player_wtl/movie.cc
+++ b/media/tools/player_wtl/movie.cc
@@ -15,7 +15,7 @@
#include "media/filters/ffmpeg_audio_decoder.h"
#include "media/filters/ffmpeg_demuxer_factory.h"
#include "media/filters/ffmpeg_video_decoder.h"
-#include "media/filters/file_data_source_factory.h"
+#include "media/filters/file_data_source.h"
#include "media/filters/null_audio_renderer.h"
#include "media/filters/reference_audio_renderer.h"
#include "media/filters/video_renderer_base.h"
@@ -23,7 +23,7 @@
using media::FFmpegAudioDecoder;
using media::FFmpegDemuxerFactory;
using media::FFmpegVideoDecoder;
-using media::FileDataSourceFactory;
+using media::FileDataSource;
using media::FilterCollection;
using media::Pipeline;
using media::ReferenceAudioRenderer;
@@ -70,12 +70,17 @@ bool Movie::Open(const wchar_t* url, VideoRendererBase* video_renderer) {
message_loop_factory_->GetMessageLoop("PipelineThread");
pipeline_ = new Pipeline(pipeline_loop, new media::MediaLog());
+ // Open the file.
+ std::string url_utf8 = WideToUTF8(string16(url));
+ scoped_refptr<FileDataSource> data_source = new FileDataSource();
+ if (data_source->Initialize(url_utf8) != PIPELINE_OK) {
+ return false;
+ }
+
// Create filter collection.
scoped_ptr<FilterCollection> collection(new FilterCollection());
- collection->SetDemuxerFactory(
- scoped_ptr<DemuxerFactory>(new FFmpegDemuxerFactory(
- scoped_ptr<DataSourceFactory>(new FileDataSourceFactory()),
- pipeline_loop)));
+ collection->SetDemuxerFactory(scoped_ptr<DemuxerFactory>(
+ new FFmpegDemuxerFactory(data_source, pipeline_loop)));
collection->AddAudioDecoder(new FFmpegAudioDecoder(
message_loop_factory_->GetMessageLoop("AudioDecoderThread")));
collection->AddVideoDecoder(new FFmpegVideoDecoder(
@@ -91,8 +96,8 @@ bool Movie::Open(const wchar_t* url, VideoRendererBase* video_renderer) {
// Create and start our pipeline.
media::PipelineStatusNotification note;
- pipeline_->Start(collection.Pass(), WideToUTF8(string16(url)),
- note.Callback());
+ pipeline_->Start(collection.Pass(), url_utf8, note.Callback());
+
// Wait until the pipeline is fully initialized.
note.Wait();
if (note.status() != PIPELINE_OK)
diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc
index f4b9fcc..ef4f126 100644
--- a/media/tools/player_x11/player_x11.cc
+++ b/media/tools/player_x11/player_x11.cc
@@ -26,7 +26,7 @@
#include "media/filters/ffmpeg_audio_decoder.h"
#include "media/filters/ffmpeg_demuxer_factory.h"
#include "media/filters/ffmpeg_video_decoder.h"
-#include "media/filters/file_data_source_factory.h"
+#include "media/filters/file_data_source.h"
#include "media/filters/null_audio_renderer.h"
#include "media/filters/reference_audio_renderer.h"
#include "media/filters/video_renderer_base.h"
@@ -109,13 +109,18 @@ bool InitPipeline(MessageLoop* message_loop,
return false;
}
+ // Open the file.
+ scoped_refptr<media::FileDataSource> data_source =
+ new media::FileDataSource();
+ if (data_source->Initialize(filename) != media::PIPELINE_OK) {
+ return false;
+ }
+
// Create our filter factories.
scoped_ptr<media::FilterCollection> collection(
new media::FilterCollection());
- collection->SetDemuxerFactory(
- scoped_ptr<media::DemuxerFactory>(
- new media::FFmpegDemuxerFactory(scoped_ptr<media::DataSourceFactory>(
- new media::FileDataSourceFactory()), message_loop)));
+ collection->SetDemuxerFactory(scoped_ptr<media::DemuxerFactory>(
+ new media::FFmpegDemuxerFactory(data_source, message_loop)));
collection->AddAudioDecoder(new media::FFmpegAudioDecoder(
message_loop_factory->GetMessageLoop("AudioDecoderThread")));
collection->AddVideoDecoder(new media::FFmpegVideoDecoder(
diff --git a/webkit/media/buffered_data_source.cc b/webkit/media/buffered_data_source.cc
index 20b9b7a..70c29cd 100644
--- a/webkit/media/buffered_data_source.cc
+++ b/webkit/media/buffered_data_source.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "media/base/media_log.h"
#include "net/base/net_errors.h"
-#include "webkit/media/web_data_source_factory.h"
using WebKit::WebFrame;
@@ -22,22 +21,6 @@ static const int kInitialReadBufferSize = 32768;
// error.
static const int kNumCacheMissRetries = 3;
-static WebDataSource* NewBufferedDataSource(MessageLoop* render_loop,
- WebKit::WebFrame* frame,
- media::MediaLog* media_log) {
- return new BufferedDataSource(render_loop, frame, media_log);
-}
-
-// static
-media::DataSourceFactory* BufferedDataSource::CreateFactory(
- MessageLoop* render_loop,
- WebKit::WebFrame* frame,
- media::MediaLog* media_log,
- const WebDataSourceBuildObserverHack& build_observer) {
- return new WebDataSourceFactory(render_loop, frame, media_log,
- &NewBufferedDataSource, build_observer);
-}
-
BufferedDataSource::BufferedDataSource(
MessageLoop* render_loop,
WebFrame* frame,
@@ -93,10 +76,9 @@ void BufferedDataSource::set_host(media::DataSourceHost* host) {
}
}
-void BufferedDataSource::Initialize(const std::string& url,
+void BufferedDataSource::Initialize(const GURL& url,
const media::PipelineStatusCB& callback) {
- // Saves the url.
- url_ = GURL(url);
+ url_ = url;
// This data source doesn't support data:// protocol so reject it.
if (url_.SchemeIs(kDataScheme)) {
@@ -115,16 +97,6 @@ void BufferedDataSource::Initialize(const std::string& url,
base::Bind(&BufferedDataSource::InitializeTask, this));
}
-void BufferedDataSource::CancelInitialize() {
- base::AutoLock auto_lock(lock_);
- DCHECK(!initialize_cb_.is_null());
-
- initialize_cb_.Reset();
-
- render_loop_->PostTask(
- FROM_HERE, base::Bind(&BufferedDataSource::CleanupTask, this));
-}
-
/////////////////////////////////////////////////////////////////////////////
// media::Filter implementation.
void BufferedDataSource::Stop(const base::Closure& callback) {
diff --git a/webkit/media/buffered_data_source.h b/webkit/media/buffered_data_source.h
index eac8e13..8e4215f 100644
--- a/webkit/media/buffered_data_source.h
+++ b/webkit/media/buffered_data_source.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,7 +10,7 @@
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
-#include "media/base/filter_factories.h"
+#include "googleurl/src/gurl.h"
#include "media/base/data_source.h"
#include "webkit/media/buffered_resource_loader.h"
@@ -24,13 +24,6 @@ namespace webkit_media {
// thread as well as media-specific threads.
class BufferedDataSource : public WebDataSource {
public:
- // Creates a DataSourceFactory for building BufferedDataSource objects.
- static media::DataSourceFactory* CreateFactory(
- MessageLoop* render_loop,
- WebKit::WebFrame* frame,
- media::MediaLog* media_log,
- const WebDataSourceBuildObserverHack& build_observer);
-
BufferedDataSource(MessageLoop* render_loop,
WebKit::WebFrame* frame,
media::MediaLog* media_log);
@@ -54,9 +47,8 @@ class BufferedDataSource : public WebDataSource {
virtual void SetBitrate(int bitrate) OVERRIDE;
// webkit_glue::WebDataSource implementation.
- virtual void Initialize(const std::string& url,
+ virtual void Initialize(const GURL& url,
const media::PipelineStatusCB& callback) OVERRIDE;
- virtual void CancelInitialize() OVERRIDE;
virtual bool HasSingleOrigin() OVERRIDE;
virtual void Abort() OVERRIDE;
diff --git a/webkit/media/buffered_data_source_unittest.cc b/webkit/media/buffered_data_source_unittest.cc
index f1d60e2..6680633 100644
--- a/webkit/media/buffered_data_source_unittest.cc
+++ b/webkit/media/buffered_data_source_unittest.cc
@@ -92,7 +92,7 @@ class BufferedDataSourceTest : public testing::Test {
void Initialize(media::PipelineStatus expected) {
ExpectCreateResourceLoader();
- data_source_->Initialize(response_generator_.gurl().spec(),
+ data_source_->Initialize(response_generator_.gurl(),
media::NewExpectedStatusCB(expected));
message_loop_->RunAllPending();
}
diff --git a/webkit/media/filter_helpers.cc b/webkit/media/filter_helpers.cc
new file mode 100644
index 0000000..f31e5f2
--- /dev/null
+++ b/webkit/media/filter_helpers.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/media/filter_helpers.h"
+
+#include "media/base/filter_collection.h"
+#include "media/base/message_loop_factory.h"
+#include "media/filters/chunk_demuxer_factory.h"
+#include "media/filters/dummy_demuxer_factory.h"
+#include "media/filters/ffmpeg_audio_decoder.h"
+#include "media/filters/ffmpeg_demuxer_factory.h"
+#include "media/filters/ffmpeg_video_decoder.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
+#include "webkit/media/media_stream_client.h"
+
+namespace webkit_media {
+
+// Constructs and adds the default audio/video decoders to |filter_collection|.
+static void AddDefaultDecodersToCollection(
+ media::MessageLoopFactory* message_loop_factory,
+ media::FilterCollection* filter_collection) {
+ filter_collection->AddAudioDecoder(new media::FFmpegAudioDecoder(
+ message_loop_factory->GetMessageLoop("AudioDecoderThread")));
+ filter_collection->AddVideoDecoder(new media::FFmpegVideoDecoder(
+ message_loop_factory->GetMessageLoop("VideoDecoderThread")));
+}
+
+bool BuildMediaStreamCollection(const WebKit::WebURL& url,
+ MediaStreamClient* client,
+ media::MessageLoopFactory* message_loop_factory,
+ media::FilterCollection* filter_collection) {
+ if (!client)
+ return false;
+
+ scoped_refptr<media::VideoDecoder> video_decoder = client->GetVideoDecoder(
+ url, message_loop_factory);
+ if (!video_decoder)
+ return false;
+
+ filter_collection->AddVideoDecoder(video_decoder);
+
+ // TODO(vrk/wjia): Setting true for local_source is under the assumption
+ // that the MediaStream represents a local webcam. This will need to
+ // change in the future when GetVideoDecoder is no longer hardcoded to
+ // only return CaptureVideoDecoders.
+ scoped_ptr<media::DemuxerFactory> demuxer_factory(
+ new media::DummyDemuxerFactory(true, false, true));
+ filter_collection->SetDemuxerFactory(demuxer_factory.Pass());
+
+ return true;
+}
+
+bool BuildMediaSourceCollection(const WebKit::WebURL& url,
+ const WebKit::WebURL& media_source_url,
+ media::ChunkDemuxerClient* client,
+ media::MessageLoopFactory* message_loop_factory,
+ media::FilterCollection* filter_collection) {
+ if (media_source_url.isEmpty() || url != media_source_url)
+ return false;
+
+ scoped_ptr<media::DemuxerFactory> demuxer_factory(
+ new media::ChunkDemuxerFactory(client));
+ filter_collection->SetDemuxerFactory(demuxer_factory.Pass());
+
+ AddDefaultDecodersToCollection(message_loop_factory, filter_collection);
+ return true;
+}
+
+void BuildDefaultCollection(const scoped_refptr<media::DataSource>& data_source,
+ media::MessageLoopFactory* message_loop_factory,
+ media::FilterCollection* filter_collection) {
+ scoped_ptr<media::DemuxerFactory> demuxer_factory(
+ new media::FFmpegDemuxerFactory(
+ data_source, message_loop_factory->GetMessageLoop("PipelineThread")));
+ filter_collection->SetDemuxerFactory(demuxer_factory.Pass());
+
+ AddDefaultDecodersToCollection(message_loop_factory, filter_collection);
+}
+
+} // webkit_media
diff --git a/webkit/media/filter_helpers.h b/webkit/media/filter_helpers.h
new file mode 100644
index 0000000..9370d98
--- /dev/null
+++ b/webkit/media/filter_helpers.h
@@ -0,0 +1,53 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_MEDIA_FILTER_HELPERS_H_
+#define WEBKIT_MEDIA_FILTER_HELPERS_H_
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+
+namespace media {
+class ChunkDemuxerClient;
+class DataSource;
+class FilterCollection;
+class MessageLoopFactory;
+}
+
+namespace WebKit {
+class WebURL;
+}
+
+namespace webkit_media {
+
+class MediaStreamClient;
+
+// Builds the required filters for handling media stream URLs and adds them to
+// |filter_collection| returning true if successful.
+//
+// |filter_collection| is not modified if this method returns false.
+bool BuildMediaStreamCollection(const WebKit::WebURL& url,
+ MediaStreamClient* client,
+ media::MessageLoopFactory* message_loop_factory,
+ media::FilterCollection* filter_collection);
+
+// Builds the required filters for handling media source URLs and adds them to
+// |filter_collection| returning true if successful.
+//
+// |filter_collection| is not modified if this method returns false.
+bool BuildMediaSourceCollection(const WebKit::WebURL& url,
+ const WebKit::WebURL& media_source_url,
+ media::ChunkDemuxerClient* client,
+ media::MessageLoopFactory* message_loop_factory,
+ media::FilterCollection* filter_collection);
+
+// Builds the required filters for handling regular URLs and adds them to
+// |filter_collection|.
+void BuildDefaultCollection(const scoped_refptr<media::DataSource>& data_source,
+ media::MessageLoopFactory* message_loop_factory,
+ media::FilterCollection* filter_collection);
+
+} // webkit_media
+
+#endif // WEBKIT_MEDIA_FILTER_HELPERS_H_
diff --git a/webkit/media/simple_data_source.cc b/webkit/media/simple_data_source.cc
index cc950dc..d521b32 100644
--- a/webkit/media/simple_data_source.cc
+++ b/webkit/media/simple_data_source.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,7 +16,6 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h"
-#include "webkit/media/web_data_source_factory.h"
using WebKit::WebString;
using WebKit::WebURLLoaderOptions;
@@ -25,22 +24,6 @@ namespace webkit_media {
static const char kDataScheme[] = "data";
-static WebDataSource* NewSimpleDataSource(MessageLoop* render_loop,
- WebKit::WebFrame* frame,
- media::MediaLog* media_log) {
- return new SimpleDataSource(render_loop, frame);
-}
-
-// static
-media::DataSourceFactory* SimpleDataSource::CreateFactory(
- MessageLoop* render_loop,
- WebKit::WebFrame* frame,
- media::MediaLog* media_log,
- const WebDataSourceBuildObserverHack& build_observer) {
- return new WebDataSourceFactory(render_loop, frame, media_log,
- &NewSimpleDataSource, build_observer);
-}
-
SimpleDataSource::SimpleDataSource(
MessageLoop* render_loop,
WebKit::WebFrame* frame)
@@ -79,7 +62,7 @@ void SimpleDataSource::Stop(const base::Closure& callback) {
}
void SimpleDataSource::Initialize(
- const std::string& url,
+ const GURL& url,
const media::PipelineStatusCB& callback) {
// Reference to prevent destruction while inside the |initialize_cb_|
// call. This is a temporary fix to prevent crashes caused by holding the
@@ -93,7 +76,7 @@ void SimpleDataSource::Initialize(
initialize_cb_ = callback;
// Validate the URL.
- url_ = GURL(url);
+ url_ = url;
if (!url_.is_valid()) {
DoneInitialization_Locked(false);
return;
@@ -105,17 +88,6 @@ void SimpleDataSource::Initialize(
}
}
-void SimpleDataSource::CancelInitialize() {
- base::AutoLock auto_lock(lock_);
- DCHECK(!initialize_cb_.is_null());
- state_ = STOPPED;
- initialize_cb_.Reset();
-
- // Post a task to the render thread to cancel loading the resource.
- render_loop_->PostTask(FROM_HERE,
- base::Bind(&SimpleDataSource::CancelTask, this));
-}
-
void SimpleDataSource::Read(int64 position,
size_t size,
uint8* data,
@@ -263,6 +235,10 @@ bool SimpleDataSource::HasSingleOrigin() {
void SimpleDataSource::Abort() {
DCHECK(MessageLoop::current() == render_loop_);
+ base::AutoLock auto_lock(lock_);
+ state_ = STOPPED;
+ initialize_cb_.Reset();
+ CancelTask();
frame_ = NULL;
}
diff --git a/webkit/media/simple_data_source.h b/webkit/media/simple_data_source.h
index e905be9..94f144f 100644
--- a/webkit/media/simple_data_source.h
+++ b/webkit/media/simple_data_source.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,7 +15,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
-#include "media/base/filter_factories.h"
+#include "googleurl/src/gurl.h"
#include "media/base/data_source.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader.h"
@@ -36,13 +36,6 @@ class SimpleDataSource
: public WebDataSource,
public WebKit::WebURLLoaderClient {
public:
- // Creates a DataSourceFactory for building SimpleDataSource objects.
- static media::DataSourceFactory* CreateFactory(
- MessageLoop* render_loop,
- WebKit::WebFrame* frame,
- media::MediaLog* media_log,
- const WebDataSourceBuildObserverHack& build_observer);
-
SimpleDataSource(MessageLoop* render_loop, WebKit::WebFrame* frame);
virtual ~SimpleDataSource();
@@ -92,9 +85,8 @@ class SimpleDataSource
const WebKit::WebURLError&);
// webkit_glue::WebDataSource implementation.
- virtual void Initialize(const std::string& url,
+ virtual void Initialize(const GURL& url,
const media::PipelineStatusCB& callback) OVERRIDE;
- virtual void CancelInitialize() OVERRIDE;
virtual bool HasSingleOrigin() OVERRIDE;
virtual void Abort() OVERRIDE;
diff --git a/webkit/media/simple_data_source_unittest.cc b/webkit/media/simple_data_source_unittest.cc
index a21135f..becef10 100644
--- a/webkit/media/simple_data_source_unittest.cc
+++ b/webkit/media/simple_data_source_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -80,7 +80,7 @@ class SimpleDataSourceTest : public testing::Test {
data_source_->set_host(&host_);
data_source_->SetURLLoaderForTest(url_loader_);
- data_source_->Initialize(url, callback);
+ data_source_->Initialize(gurl_, callback);
MessageLoop::current()->RunAllPending();
}
@@ -197,7 +197,7 @@ TEST_F(SimpleDataSourceTest, InitializeData) {
EXPECT_CALL(host_, SetTotalBytes(sizeof(kDataUrlDecoded)));
EXPECT_CALL(host_, SetBufferedBytes(sizeof(kDataUrlDecoded)));
- data_source_->Initialize(kDataUrl,
+ data_source_->Initialize(GURL(kDataUrl),
media::NewExpectedStatusCB(media::PIPELINE_OK));
MessageLoop::current()->RunAllPending();
diff --git a/webkit/media/web_data_source.h b/webkit/media/web_data_source.h
index e492e88..260e003 100644
--- a/webkit/media/web_data_source.h
+++ b/webkit/media/web_data_source.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,6 +9,8 @@
#include "media/base/data_source.h"
#include "media/base/pipeline_status.h"
+class GURL;
+
namespace webkit_media {
// An interface that allows WebMediaPlayerImpl::Proxy to communicate with the
@@ -20,23 +22,17 @@ class WebDataSource : public media::DataSource {
// Initialize this object using |url|. This object calls |callback| when
// initialization has completed.
- virtual void Initialize(const std::string& url,
+ virtual void Initialize(const GURL& url,
const media::PipelineStatusCB& callback) = 0;
- // Called to cancel initialization. The callback passed in Initialize() will
- // be destroyed and will not be called after this method returns. Once this
- // method returns, the object will be in an uninitialized state and
- // Initialize() cannot be called again. The caller is expected to release
- // its handle to this object and never call it again.
- virtual void CancelInitialize() = 0;
-
// Returns true if the media resource has a single origin, false otherwise.
//
// Method called on the render thread.
virtual bool HasSingleOrigin() = 0;
- // This method is used to unblock any read calls that would cause the
- // media pipeline to stall.
+ // Cancels initialization, any pending loaders, and any pending read calls
+ // from the demuxer. The caller is expected to release its reference to this
+ // object and never call it again.
//
// Method called on the render thread.
virtual void Abort() = 0;
@@ -45,15 +41,6 @@ class WebDataSource : public media::DataSource {
DISALLOW_COPY_AND_ASSIGN(WebDataSource);
};
-// Temporary hack to allow WebMediaPlayerImpl::Proxy::AddDataSource() to
-// be called when WebDataSource objects are created. This can be removed
-// once WebMediaPlayerImpl::Proxy is fixed so it doesn't have to track
-// WebDataSources. Proxy only has to track WebDataSources so it can call Abort()
-// on them at shutdown. Once cancellation is added to DataSource and pause
-// support in Demuxers cancel pending reads, Proxy shouldn't have to keep
-// a WebDataSource list or call Abort().
-typedef base::Callback<void(WebDataSource*)> WebDataSourceBuildObserverHack;
-
} // namespace webkit_media
#endif // WEBKIT_MEDIA_WEB_DATA_SOURCE_H_
diff --git a/webkit/media/web_data_source_factory.cc b/webkit/media/web_data_source_factory.cc
deleted file mode 100644
index c522ab6..0000000
--- a/webkit/media/web_data_source_factory.cc
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "webkit/media/web_data_source_factory.h"
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "media/base/media_log.h"
-
-namespace webkit_media {
-
-class WebDataSourceFactory::BuildRequest
- : public media::AsyncDataSourceFactoryBase::BuildRequest {
- public:
- BuildRequest(const std::string& url, const BuildCallback& callback,
- WebDataSource* data_source,
- const WebDataSourceBuildObserverHack& build_observer);
- virtual ~BuildRequest();
-
- protected:
- // AsyncDataSourceFactoryBase::BuildRequest method.
- virtual void DoStart();
-
- private:
- void InitDone(media::PipelineStatus status);
-
- scoped_refptr<WebDataSource> data_source_;
- WebDataSourceBuildObserverHack build_observer_;
-
- DISALLOW_COPY_AND_ASSIGN(BuildRequest);
-};
-
-WebDataSourceFactory::WebDataSourceFactory(
- MessageLoop* render_loop,
- WebKit::WebFrame* frame,
- media::MediaLog* media_log,
- FactoryFunction factory_function,
- const WebDataSourceBuildObserverHack& build_observer)
- : render_loop_(render_loop),
- frame_(frame),
- media_log_(media_log),
- factory_function_(factory_function),
- build_observer_(build_observer) {
- DCHECK(render_loop_);
- DCHECK(frame_);
- DCHECK(media_log_);
- DCHECK(factory_function_);
-}
-
-WebDataSourceFactory::~WebDataSourceFactory() {}
-
-bool WebDataSourceFactory::AllowRequests() const {
- return true;
-}
-
-media::AsyncDataSourceFactoryBase::BuildRequest*
-WebDataSourceFactory::CreateRequest(const std::string& url,
- const BuildCallback& callback) {
- WebDataSource* data_source = factory_function_(render_loop_, frame_,
- media_log_);
-
- return new WebDataSourceFactory::BuildRequest(url, callback, data_source,
- build_observer_);
-}
-
-WebDataSourceFactory::BuildRequest::BuildRequest(
- const std::string& url,
- const BuildCallback& callback,
- WebDataSource* data_source,
- const WebDataSourceBuildObserverHack& build_observer)
- : AsyncDataSourceFactoryBase::BuildRequest(url, callback),
- data_source_(data_source),
- build_observer_(build_observer) {
-}
-
-WebDataSourceFactory::BuildRequest::~BuildRequest() {
- if (data_source_.get()) {
- data_source_->CancelInitialize();
- data_source_ = NULL;
- }
-}
-
-void WebDataSourceFactory::BuildRequest::DoStart() {
- data_source_->Initialize(url(), base::Bind(&BuildRequest::InitDone,
- base::Unretained(this)));
-}
-
-void WebDataSourceFactory::BuildRequest::InitDone(
- media::PipelineStatus status) {
- scoped_refptr<WebDataSource> data_source;
-
- data_source = (status == media::PIPELINE_OK) ? data_source_ : NULL;
- data_source_ = NULL;
-
- if (!build_observer_.is_null() && data_source.get()) {
- build_observer_.Run(data_source.get());
- }
-
- RequestComplete(status, data_source);
- // Don't do anything after this line. This object is deleted by
- // RequestComplete().
-}
-
-} // namespace webkit_media
diff --git a/webkit/media/web_data_source_factory.h b/webkit/media/web_data_source_factory.h
deleted file mode 100644
index 0eb577e..0000000
--- a/webkit/media/web_data_source_factory.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef WEBKIT_MEDIA_WEB_DATA_SOURCE_FACTORY_H_
-#define WEBKIT_MEDIA_WEB_DATA_SOURCE_FACTORY_H_
-
-#include "base/memory/ref_counted.h"
-#include "media/base/async_filter_factory_base.h"
-#include "webkit/media/web_data_source.h"
-
-class MessageLoop;
-
-namespace media {
-class MediaLog;
-}
-
-namespace WebKit {
-class WebFrame;
-}
-
-namespace webkit_media {
-
-class WebDataSourceFactory : public media::AsyncDataSourceFactoryBase {
- public:
- typedef WebDataSource* (*FactoryFunction)(MessageLoop* render_loop,
- WebKit::WebFrame* frame,
- media::MediaLog* media_log);
-
- WebDataSourceFactory(MessageLoop* render_loop, WebKit::WebFrame* frame,
- media::MediaLog* media_log,
- FactoryFunction factory_function,
- const WebDataSourceBuildObserverHack& build_observer);
- virtual ~WebDataSourceFactory();
-
- protected:
- // AsyncDataSourceFactoryBase methods.
- virtual bool AllowRequests() const OVERRIDE;
- virtual AsyncDataSourceFactoryBase::BuildRequest* CreateRequest(
- const std::string& url, const BuildCallback& callback) OVERRIDE;
-
- private:
- class BuildRequest;
-
- MessageLoop* render_loop_;
- WebKit::WebFrame* frame_;
- scoped_refptr<media::MediaLog> media_log_;
- FactoryFunction factory_function_;
- WebDataSourceBuildObserverHack build_observer_;
-
- DISALLOW_COPY_AND_ASSIGN(WebDataSourceFactory);
-};
-
-} // namespace webkit_media
-
-#endif // WEBKIT_MEDIA_WEB_DATA_SOURCE_FACTORY_H_
diff --git a/webkit/media/webkit_media.gypi b/webkit/media/webkit_media.gypi
index 1f691c3..3f567be 100644
--- a/webkit/media/webkit_media.gypi
+++ b/webkit/media/webkit_media.gypi
@@ -1,4 +1,4 @@
-# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -23,14 +23,14 @@
'buffered_data_source.h',
'buffered_resource_loader.cc',
'buffered_resource_loader.h',
+ 'filter_helpers.cc',
+ 'filter_helpers.h',
'media_stream_client.h',
'simple_data_source.cc',
'simple_data_source.h',
'skcanvas_video_renderer.cc',
'skcanvas_video_renderer.h',
'web_data_source.cc',
- 'web_data_source_factory.cc',
- 'web_data_source_factory.h',
'web_data_source.h',
'webmediaplayer_delegate.h',
'webmediaplayer_impl.cc',
diff --git a/webkit/media/webmediaplayer_impl.cc b/webkit/media/webmediaplayer_impl.cc
index 706ab8f..011e630 100644
--- a/webkit/media/webmediaplayer_impl.cc
+++ b/webkit/media/webmediaplayer_impl.cc
@@ -11,18 +11,12 @@
#include "base/callback.h"
#include "base/command_line.h"
#include "base/metrics/histogram.h"
-#include "media/base/composite_data_source_factory.h"
#include "media/base/filter_collection.h"
#include "media/base/limits.h"
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "media/base/pipeline.h"
#include "media/base/video_frame.h"
-#include "media/filters/chunk_demuxer_factory.h"
-#include "media/filters/dummy_demuxer_factory.h"
-#include "media/filters/ffmpeg_audio_decoder.h"
-#include "media/filters/ffmpeg_demuxer_factory.h"
-#include "media/filters/ffmpeg_video_decoder.h"
#include "media/filters/null_audio_renderer.h"
#include "media/filters/video_renderer_base.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h"
@@ -32,7 +26,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "v8/include/v8.h"
#include "webkit/media/buffered_data_source.h"
-#include "webkit/media/media_stream_client.h"
+#include "webkit/media/filter_helpers.h"
#include "webkit/media/simple_data_source.h"
#include "webkit/media/webmediaplayer_delegate.h"
#include "webkit/media/webmediaplayer_proxy.h"
@@ -107,10 +101,12 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
media::MessageLoopFactory* message_loop_factory,
MediaStreamClient* media_stream_client,
media::MediaLog* media_log)
- : network_state_(WebKit::WebMediaPlayer::Empty),
+ : frame_(frame),
+ network_state_(WebKit::WebMediaPlayer::Empty),
ready_state_(WebKit::WebMediaPlayer::HaveNothing),
main_loop_(MessageLoop::current()),
filter_collection_(collection),
+ started_(false),
message_loop_factory_(message_loop_factory),
paused_(true),
seeking_(false),
@@ -165,41 +161,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
filter_collection_->AddVideoRenderer(video_renderer);
proxy_->set_frame_provider(video_renderer);
- // A simple data source that keeps all data in memory.
- scoped_ptr<media::DataSourceFactory> simple_data_source_factory(
- SimpleDataSource::CreateFactory(MessageLoop::current(), frame,
- media_log_,
- proxy_->GetBuildObserver()));
-
- // A sophisticated data source that does memory caching.
- scoped_ptr<media::DataSourceFactory> buffered_data_source_factory(
- BufferedDataSource::CreateFactory(MessageLoop::current(), frame,
- media_log_,
- proxy_->GetBuildObserver()));
-
- scoped_ptr<media::CompositeDataSourceFactory> data_source_factory(
- new media::CompositeDataSourceFactory());
- data_source_factory->AddFactory(buffered_data_source_factory.Pass());
- data_source_factory->AddFactory(simple_data_source_factory.Pass());
-
- scoped_ptr<media::DemuxerFactory> demuxer_factory(
- new media::FFmpegDemuxerFactory(scoped_ptr<media::DataSourceFactory>(
- data_source_factory.release()), pipeline_message_loop));
-
- std::string source_url = GetClient()->sourceURL().spec();
- if (!source_url.empty()) {
- demuxer_factory.reset(
- new media::ChunkDemuxerFactory(source_url,
- demuxer_factory.Pass(),
- proxy_));
- }
- filter_collection_->SetDemuxerFactory(demuxer_factory.Pass());
-
- // Add in the default filter factories.
- filter_collection_->AddAudioDecoder(new media::FFmpegAudioDecoder(
- message_loop_factory_->GetMessageLoop("AudioDecoderThread")));
- filter_collection_->AddVideoDecoder(new media::FFmpegVideoDecoder(
- message_loop_factory_->GetMessageLoop("VideoDecoderThread")));
+ // Create default audio renderer.
filter_collection_->AddAudioRenderer(new media::NullAudioRenderer());
}
@@ -254,47 +216,44 @@ URLSchemeForHistogram URLScheme(const GURL& url) {
void WebMediaPlayerImpl::load(const WebKit::WebURL& url) {
DCHECK_EQ(main_loop_, MessageLoop::current());
- UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), kMaxURLScheme);
-
- if (media_stream_client_) {
- bool has_video = false;
- bool has_audio = false;
- scoped_refptr<media::VideoDecoder> new_decoder =
- media_stream_client_->GetVideoDecoder(url, message_loop_factory_.get());
- if (new_decoder.get()) {
- // Remove the default decoder.
- scoped_refptr<media::VideoDecoder> old_videodecoder;
- filter_collection_->SelectVideoDecoder(&old_videodecoder);
- filter_collection_->AddVideoDecoder(new_decoder.get());
- has_video = true;
- }
-
- // TODO(wjia): add audio decoder handling when it's available.
- if (has_video || has_audio) {
- // TODO(vrk/wjia): Setting true for local_source is under the assumption
- // that the MediaStream represents a local webcam. This will need to
- // change in the future when GetVideoDecoder is no longer hardcoded to
- // only return CaptureVideoDecoders.
- filter_collection_->SetDemuxerFactory(scoped_ptr<media::DemuxerFactory>(
- new media::DummyDemuxerFactory(has_video, has_audio, true)));
- }
- }
+ GURL gurl(url);
+ UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme);
- // Handle any volume changes that occured before load().
+ // Handle any volume/preload changes that occured before load().
setVolume(GetClient()->volume());
- // Get the preload value.
setPreload(GetClient()->preload());
- // Initialize the pipeline.
SetNetworkState(WebKit::WebMediaPlayer::Loading);
SetReadyState(WebKit::WebMediaPlayer::HaveNothing);
- pipeline_->Start(
- filter_collection_.Pass(),
- url.spec(),
- base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback,
- proxy_.get()));
-
media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec()));
+
+ // Media streams pipelines can start immediately.
+ if (BuildMediaStreamCollection(url, media_stream_client_,
+ message_loop_factory_.get(),
+ filter_collection_.get())) {
+ StartPipeline(gurl);
+ return;
+ }
+
+ // Media source pipelines can start immediately.
+ if (BuildMediaSourceCollection(url, GetClient()->sourceURL(), proxy_,
+ message_loop_factory_.get(),
+ filter_collection_.get())) {
+ StartPipeline(gurl);
+ return;
+ }
+
+ // Otherwise it's a regular request which requires resolving the URL first.
+ scoped_refptr<WebDataSource> data_source;
+ if (gurl.SchemeIs(kDataScheme)) {
+ data_source = new SimpleDataSource(main_loop_, frame_);
+ } else {
+ data_source = new BufferedDataSource(main_loop_, frame_, media_log_);
+ }
+ proxy_->set_data_source(data_source);
+ data_source->Initialize(url, base::Bind(
+ &WebMediaPlayerImpl::DataSourceInitialized,
+ base::Unretained(this), gurl));
}
void WebMediaPlayerImpl::cancelLoad() {
@@ -856,6 +815,32 @@ void WebMediaPlayerImpl::SetOpaque(bool opaque) {
GetClient()->setOpaque(opaque);
}
+void WebMediaPlayerImpl::DataSourceInitialized(
+ const GURL& gurl,
+ media::PipelineStatus status) {
+ DCHECK_EQ(main_loop_, MessageLoop::current());
+
+ if (status != media::PIPELINE_OK) {
+ SetNetworkState(WebKit::WebMediaPlayer::FormatError);
+ Repaint();
+ return;
+ }
+
+ BuildDefaultCollection(proxy_->data_source(),
+ message_loop_factory_.get(),
+ filter_collection_.get());
+ StartPipeline(gurl);
+}
+
+void WebMediaPlayerImpl::StartPipeline(const GURL& gurl) {
+ started_ = true;
+ pipeline_->Start(
+ filter_collection_.Pass(),
+ gurl.spec(),
+ base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback,
+ proxy_.get()));
+}
+
void WebMediaPlayerImpl::SetNetworkState(
WebKit::WebMediaPlayer::NetworkState state) {
DCHECK_EQ(main_loop_, MessageLoop::current());
@@ -878,22 +863,23 @@ void WebMediaPlayerImpl::Destroy() {
// Tell the data source to abort any pending reads so that the pipeline is
// not blocked when issuing stop commands to the other filters.
if (proxy_) {
- proxy_->AbortDataSources();
+ proxy_->AbortDataSource();
proxy_->DemuxerShutdown();
}
// Make sure to kill the pipeline so there's no more media threads running.
// Note: stopping the pipeline might block for a long time.
- if (pipeline_) {
+ if (started_) {
media::PipelineStatusNotification note;
pipeline_->Stop(note.Callback());
note.Wait();
+ started_ = false;
+ }
- // Let V8 know we are not using extra resources anymore.
- if (incremented_externally_allocated_memory_) {
- v8::V8::AdjustAmountOfExternalAllocatedMemory(-kPlayerExtraMemory);
- incremented_externally_allocated_memory_ = false;
- }
+ // Let V8 know we are not using extra resources anymore.
+ if (incremented_externally_allocated_memory_) {
+ v8::V8::AdjustAmountOfExternalAllocatedMemory(-kPlayerExtraMemory);
+ incremented_externally_allocated_memory_ = false;
}
message_loop_factory_.reset();
diff --git a/webkit/media/webmediaplayer_impl.h b/webkit/media/webmediaplayer_impl.h
index b3b2b42..fea3b92 100644
--- a/webkit/media/webmediaplayer_impl.h
+++ b/webkit/media/webmediaplayer_impl.h
@@ -52,6 +52,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
+#include "googleurl/src/gurl.h"
#include "media/base/audio_renderer_sink.h"
#include "media/base/filters.h"
#include "media/base/message_loop_factory.h"
@@ -191,6 +192,12 @@ class WebMediaPlayerImpl
void SetOpaque(bool);
private:
+ // Called after asynchronous initialization of a data source completed.
+ void DataSourceInitialized(const GURL& gurl, media::PipelineStatus status);
+
+ // Finishes starting the pipeline due to a call to load().
+ void StartPipeline(const GURL& gurl);
+
// Helpers that set the network/ready state and notifies the client if
// they've changed.
void SetNetworkState(WebKit::WebMediaPlayer::NetworkState state);
@@ -205,6 +212,8 @@ class WebMediaPlayerImpl
// Lets V8 know that player uses extra resources not managed by V8.
void IncrementExternallyAllocatedMemory();
+ WebKit::WebFrame* frame_;
+
// TODO(hclam): get rid of these members and read from the pipeline directly.
WebKit::WebMediaPlayer::NetworkState network_state_;
WebKit::WebMediaPlayer::ReadyState ready_state_;
@@ -219,8 +228,13 @@ class WebMediaPlayerImpl
// A collection of filters.
scoped_ptr<media::FilterCollection> filter_collection_;
- // The actual pipeline and the thread it runs on.
+ // The media pipeline and a bool tracking whether we have started it yet.
+ //
+ // TODO(scherkus): replace |started_| with a pointer check for |pipeline_| and
+ // have WebMediaPlayerImpl return the default values to WebKit instead of
+ // relying on Pipeline to take care of default values.
scoped_refptr<media::Pipeline> pipeline_;
+ bool started_;
scoped_ptr<media::MessageLoopFactory> message_loop_factory_;
diff --git a/webkit/media/webmediaplayer_proxy.cc b/webkit/media/webmediaplayer_proxy.cc
index 2271878..4a2d929 100644
--- a/webkit/media/webmediaplayer_proxy.cc
+++ b/webkit/media/webmediaplayer_proxy.cc
@@ -50,10 +50,6 @@ void WebMediaPlayerProxy::SetOpaque(bool opaque) {
&WebMediaPlayerProxy::SetOpaqueTask, this, opaque));
}
-WebDataSourceBuildObserverHack WebMediaPlayerProxy::GetBuildObserver() {
- return base::Bind(&WebMediaPlayerProxy::AddDataSource, this);
-}
-
void WebMediaPlayerProxy::Paint(SkCanvas* canvas, const gfx::Rect& dest_rect) {
DCHECK(MessageLoop::current() == render_loop_);
if (frame_provider_) {
@@ -66,38 +62,22 @@ void WebMediaPlayerProxy::Paint(SkCanvas* canvas, const gfx::Rect& dest_rect) {
bool WebMediaPlayerProxy::HasSingleOrigin() {
DCHECK(MessageLoop::current() == render_loop_);
-
- base::AutoLock auto_lock(data_sources_lock_);
-
- for (DataSourceList::iterator itr = data_sources_.begin();
- itr != data_sources_.end();
- itr++) {
- if (!(*itr)->HasSingleOrigin())
- return false;
- }
+ if (data_source_)
+ return data_source_->HasSingleOrigin();
return true;
}
-void WebMediaPlayerProxy::AbortDataSources() {
+void WebMediaPlayerProxy::AbortDataSource() {
DCHECK(MessageLoop::current() == render_loop_);
- base::AutoLock auto_lock(data_sources_lock_);
-
- for (DataSourceList::iterator itr = data_sources_.begin();
- itr != data_sources_.end();
- itr++) {
- (*itr)->Abort();
- }
+ if (data_source_)
+ data_source_->Abort();
}
void WebMediaPlayerProxy::Detach() {
DCHECK(MessageLoop::current() == render_loop_);
webmediaplayer_ = NULL;
+ data_source_ = NULL;
frame_provider_ = NULL;
-
- {
- base::AutoLock auto_lock(data_sources_lock_);
- data_sources_.clear();
- }
}
void WebMediaPlayerProxy::PipelineInitializationCallback(
@@ -127,11 +107,6 @@ void WebMediaPlayerProxy::NetworkEventCallback(NetworkEvent type) {
&WebMediaPlayerProxy::NetworkEventTask, this, type));
}
-void WebMediaPlayerProxy::AddDataSource(WebDataSource* data_source) {
- base::AutoLock auto_lock(data_sources_lock_);
- data_sources_.push_back(make_scoped_refptr(data_source));
-}
-
void WebMediaPlayerProxy::RepaintTask() {
DCHECK(MessageLoop::current() == render_loop_);
{
diff --git a/webkit/media/webmediaplayer_proxy.h b/webkit/media/webmediaplayer_proxy.h
index e974f5a..da0ec50 100644
--- a/webkit/media/webmediaplayer_proxy.h
+++ b/webkit/media/webmediaplayer_proxy.h
@@ -38,6 +38,12 @@ class WebMediaPlayerProxy
public:
WebMediaPlayerProxy(MessageLoop* render_loop,
WebMediaPlayerImpl* webmediaplayer);
+ const scoped_refptr<WebDataSource>& data_source() {
+ return data_source_;
+ }
+ void set_data_source(const scoped_refptr<WebDataSource>& data_source) {
+ data_source_ = data_source;
+ }
// TODO(scherkus): remove this once VideoRendererBase::PaintCB passes
// ownership of the VideoFrame http://crbug.com/108435
@@ -48,7 +54,6 @@ class WebMediaPlayerProxy
// Methods for Filter -> WebMediaPlayerImpl communication.
void Repaint();
void SetOpaque(bool opaque);
- WebDataSourceBuildObserverHack GetBuildObserver();
// Methods for WebMediaPlayerImpl -> Filter communication.
void Paint(SkCanvas* canvas, const gfx::Rect& dest_rect);
@@ -56,7 +61,7 @@ class WebMediaPlayerProxy
void GetCurrentFrame(scoped_refptr<media::VideoFrame>* frame_out);
void PutCurrentFrame(scoped_refptr<media::VideoFrame> frame);
bool HasSingleOrigin();
- void AbortDataSources();
+ void AbortDataSource();
// Methods for Pipeline -> WebMediaPlayerImpl communication.
void PipelineInitializationCallback(media::PipelineStatus status);
@@ -85,9 +90,6 @@ class WebMediaPlayerProxy
friend class base::RefCountedThreadSafe<WebMediaPlayerProxy>;
virtual ~WebMediaPlayerProxy();
- // Adds a data source to data_sources_.
- void AddDataSource(WebDataSource* data_source);
-
// Invoke |webmediaplayer_| to perform a repaint.
void RepaintTask();
@@ -114,10 +116,7 @@ class WebMediaPlayerProxy
MessageLoop* render_loop_;
WebMediaPlayerImpl* webmediaplayer_;
- base::Lock data_sources_lock_;
- typedef std::list<scoped_refptr<WebDataSource> > DataSourceList;
- DataSourceList data_sources_;
-
+ scoped_refptr<WebDataSource> data_source_;
scoped_refptr<media::VideoRendererBase> frame_provider_;
SkCanvasVideoRenderer video_renderer_;