summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/chrome.gyp6
-rw-r--r--chrome/renderer/render_view.cc18
-rw-r--r--media/base/factory.h22
-rw-r--r--webkit/glue/DEPS1
-rw-r--r--webkit/glue/media/simple_data_source.cc (renamed from chrome/renderer/media/simple_data_source.cc)21
-rw-r--r--webkit/glue/media/simple_data_source.h (renamed from chrome/renderer/media/simple_data_source.h)27
-rw-r--r--webkit/glue/media/video_renderer_impl.cc (renamed from chrome/renderer/media/video_renderer_impl.cc)10
-rw-r--r--webkit/glue/media/video_renderer_impl.h (renamed from chrome/renderer/media/video_renderer_impl.h)13
-rw-r--r--webkit/glue/webmediaplayer_impl.cc (renamed from chrome/renderer/webmediaplayer_impl.cc)42
-rw-r--r--webkit/glue/webmediaplayer_impl.h229
-rw-r--r--webkit/glue/webview_delegate.h2
-rw-r--r--webkit/tools/DEPS17
-rw-r--r--webkit/tools/test_shell/test_shell.gyp2
-rw-r--r--webkit/tools/test_shell/test_shell_webkit_init.h9
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.cc7
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.h2
-rw-r--r--webkit/webkit.gyp6
17 files changed, 366 insertions, 68 deletions
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 59ddaa6..304f7be 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -2106,10 +2106,6 @@
'renderer/media/audio_renderer_impl.h',
'renderer/media/buffered_data_source.cc',
'renderer/media/buffered_data_source.h',
- 'renderer/media/simple_data_source.cc',
- 'renderer/media/simple_data_source.h',
- 'renderer/media/video_renderer_impl.cc',
- 'renderer/media/video_renderer_impl.h',
'renderer/net/render_dns_master.cc',
'renderer/net/render_dns_master.h',
'renderer/net/render_dns_queue.cc',
@@ -2166,8 +2162,6 @@
'renderer/user_script_slave.h',
'renderer/visitedlink_slave.cc',
'renderer/visitedlink_slave.h',
- 'renderer/webmediaplayer_impl.cc',
- 'renderer/webmediaplayer_impl.h',
'renderer/webplugin_delegate_proxy.cc',
'renderer/webplugin_delegate_proxy.h',
'renderer/webworker_proxy.cc',
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 59155ed8..b982b26 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -38,12 +38,12 @@
#include "chrome/renderer/extensions/extension_process_bindings.h"
#include "chrome/renderer/localized_error.h"
#include "chrome/renderer/media/audio_renderer_impl.h"
+#include "chrome/renderer/media/buffered_data_source.h"
#include "chrome/renderer/print_web_view_helper.h"
#include "chrome/renderer/render_process.h"
#include "chrome/renderer/renderer_logging.h"
#include "chrome/renderer/user_script_slave.h"
#include "chrome/renderer/visitedlink_slave.h"
-#include "chrome/renderer/webmediaplayer_impl.h"
#include "chrome/renderer/webplugin_delegate_proxy.h"
#include "chrome/renderer/webworker_proxy.h"
#include "grit/generated_resources.h"
@@ -72,6 +72,7 @@
#include "webkit/glue/weberror.h"
#include "webkit/glue/webframe.h"
#include "webkit/glue/webkit_glue.h"
+#include "webkit/glue/webmediaplayer_impl.h"
#include "webkit/glue/webpreferences.h"
#include "webkit/glue/webplugin_delegate.h"
#include "webkit/glue/webresponse.h"
@@ -1751,7 +1752,20 @@ WebPluginDelegate* RenderView::CreatePluginDelegate(
WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer(
WebKit::WebMediaPlayerClient* client) {
- return new WebMediaPlayerImpl(this, client);
+ scoped_refptr<media::FilterFactoryCollection> factory =
+ new media::FilterFactoryCollection();
+ // Add in any custom filter factories first.
+ const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
+ if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
+ // Add the chrome specific audio renderer.
+ factory->AddFactory(
+ AudioRendererImpl::CreateFactory(audio_message_filter()));
+ }
+ if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
+ // Add the chrome specific media data source.
+ factory->AddFactory(BufferedDataSource::CreateFactory(routing_id()));
+ }
+ return new webkit_glue::WebMediaPlayerImpl(client, factory);
}
void RenderView::OnMissingPluginStatus(WebPluginDelegate* delegate,
diff --git a/media/base/factory.h b/media/base/factory.h
index 91e5bc4..3ccfcb1 100644
--- a/media/base/factory.h
+++ b/media/base/factory.h
@@ -156,6 +156,28 @@ class FilterFactoryImpl1 : public FilterFactory {
DISALLOW_COPY_AND_ASSIGN(FilterFactoryImpl1);
};
+template <class Filter, class A, class B>
+class FilterFactoryImpl2 : public FilterFactory {
+ public:
+ FilterFactoryImpl2(A a, B b) : a_(a), b_(b) {}
+
+ protected:
+ virtual MediaFilter* Create(FilterType filter_type,
+ const MediaFormat& media_format) {
+ Filter* filter = NULL;
+ if (Filter::filter_type() == filter_type &&
+ Filter::IsMediaFormatSupported(media_format)) {
+ filter = new Filter(a_, b_);
+ }
+ return filter;
+ }
+
+ private:
+ A const a_;
+ B const b_;
+
+ DISALLOW_COPY_AND_ASSIGN(FilterFactoryImpl2);
+};
//------------------------------------------------------------------------------
diff --git a/webkit/glue/DEPS b/webkit/glue/DEPS
index beea903..1129c20 100644
--- a/webkit/glue/DEPS
+++ b/webkit/glue/DEPS
@@ -1,4 +1,5 @@
include_rules = [
+ "+media",
"+skia/ext",
"+skia/include",
"+webkit/tools/test_shell", # Needed for test shell tests.
diff --git a/chrome/renderer/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc
index d029382..16fbd04 100644
--- a/chrome/renderer/media/simple_data_source.cc
+++ b/webkit/glue/media/simple_data_source.cc
@@ -2,24 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/message_loop.h"
#include "base/process_util.h"
-#include "chrome/renderer/media/simple_data_source.h"
-#include "chrome/renderer/render_thread.h"
-#include "chrome/renderer/render_view.h"
#include "media/base/filter_host.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request_status.h"
+#include "webkit/glue/media/simple_data_source.h"
+#include "webkit/glue/resource_loader_bridge.h"
#include "webkit/glue/webappcachecontext.h"
-SimpleDataSource::SimpleDataSource(int32 routing_id)
+namespace webkit_glue {
+
+SimpleDataSource::SimpleDataSource(MessageLoop* render_loop, int32 routing_id)
: routing_id_(routing_id),
- render_loop_(RenderThread::current()->message_loop()),
+ render_loop_(render_loop),
size_(-1),
position_(0) {
+ DCHECK(render_loop);
}
-SimpleDataSource::~SimpleDataSource() {}
+SimpleDataSource::~SimpleDataSource() {
+}
void SimpleDataSource::Stop() {}
@@ -32,7 +36,7 @@ bool SimpleDataSource::Initialize(const std::string& url) {
}
// Create our bridge and post a task to start loading the resource.
- bridge_.reset(RenderThread::current()->resource_dispatcher()->CreateBridge(
+ bridge_.reset(webkit_glue::ResourceLoaderBridge::Create(
"GET",
url_,
url_,
@@ -43,7 +47,6 @@ bool SimpleDataSource::Initialize(const std::string& url) {
net::LOAD_BYPASS_CACHE,
base::GetCurrentProcId(),
ResourceType::MEDIA,
- 0,
// TODO(michaeln): delegate->mediaplayer->frame->
// app_cache_context()->context_id()
// For now don't service media resource requests from the appcache.
@@ -139,3 +142,5 @@ void SimpleDataSource::StartTask() {
DCHECK(MessageLoop::current() == render_loop_);
bridge_->Start(this);
}
+
+} // namespace webkit_glue
diff --git a/chrome/renderer/media/simple_data_source.h b/webkit/glue/media/simple_data_source.h
index cd3b8fa..c1e0a00 100644
--- a/chrome/renderer/media/simple_data_source.h
+++ b/webkit/glue/media/simple_data_source.h
@@ -7,9 +7,10 @@
// Primarily used to test <audio> and <video> with buffering/caching removed
// from the equation.
-#ifndef CHROME_RENDERER_MEDIA_SIMPLE_DATA_SOURCE_H_
-#define CHROME_RENDERER_MEDIA_SIMPLE_DATA_SOURCE_H_
+#ifndef WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_
+#define WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_
+#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "media/base/factory.h"
#include "media/base/filters.h"
@@ -18,12 +19,16 @@
class MessageLoop;
class WebMediaPlayerDelegateImpl;
-class SimpleDataSource :
- public media::DataSource,
- public webkit_glue::ResourceLoaderBridge::Peer {
+namespace webkit_glue {
+
+class SimpleDataSource : public media::DataSource,
+ public webkit_glue::ResourceLoaderBridge::Peer {
public:
- static media::FilterFactory* CreateFactory(int32 routing_id) {
- return new media::FilterFactoryImpl1<SimpleDataSource, int32>(routing_id);
+ static media::FilterFactory* CreateFactory(MessageLoop* message_loop,
+ int32 routing_id) {
+ return new media::FilterFactoryImpl2<SimpleDataSource,
+ MessageLoop*,
+ int32>(message_loop, routing_id);
}
// MediaFilter implementation.
@@ -51,8 +56,8 @@ class SimpleDataSource :
virtual std::string GetURLForDebugging();
private:
- friend class media::FilterFactoryImpl1<SimpleDataSource, int32>;
- SimpleDataSource(int32 routing_id);
+ friend class media::FilterFactoryImpl2<SimpleDataSource, MessageLoop*, int32>;
+ SimpleDataSource(MessageLoop* render_loop, int32 routing_id);
virtual ~SimpleDataSource();
// Updates |url_| and |media_format_| with the given URL.
@@ -79,4 +84,6 @@ class SimpleDataSource :
DISALLOW_COPY_AND_ASSIGN(SimpleDataSource);
};
-#endif // CHROME_RENDERER_MEDIA_SIMPLE_DATA_SOURCE_H_
+} // namespace webkit_glue
+
+#endif // WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_
diff --git a/chrome/renderer/media/video_renderer_impl.cc b/webkit/glue/media/video_renderer_impl.cc
index 0064abd..f9aa998 100644
--- a/chrome/renderer/media/video_renderer_impl.cc
+++ b/webkit/glue/media/video_renderer_impl.cc
@@ -2,9 +2,12 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
-#include "chrome/renderer/media/video_renderer_impl.h"
#include "media/base/buffers.h"
#include "media/base/yuv_convert.h"
+#include "webkit/glue/media/video_renderer_impl.h"
+#include "webkit/glue/webmediaplayer_impl.h"
+
+namespace webkit_glue {
VideoRendererImpl::VideoRendererImpl(WebMediaPlayerImpl* delegate)
: delegate_(delegate),
@@ -44,7 +47,8 @@ bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) {
return false;
}
-void VideoRendererImpl::SetRect(const gfx::Rect& rect) {}
+void VideoRendererImpl::SetRect(const gfx::Rect& rect) {
+}
void VideoRendererImpl::OnFrameAvailable() {
delegate_->PostRepaintTask();
@@ -267,3 +271,5 @@ void VideoRendererImpl::TransformToSkIRect(const SkMatrix& matrix,
matrix.mapRect(&transformed_rect, skia_dest_rect);
transformed_rect.round(dest_rect);
}
+
+} // namespace webkit_glue
diff --git a/chrome/renderer/media/video_renderer_impl.h b/webkit/glue/media/video_renderer_impl.h
index bf91282..b17848b 100644
--- a/chrome/renderer/media/video_renderer_impl.h
+++ b/webkit/glue/media/video_renderer_impl.h
@@ -11,19 +11,22 @@
// Paint()
// SetRect()
-#ifndef CHROME_RENDERER_MEDIA_VIDEO_RENDERER_IMPL_H_
-#define CHROME_RENDERER_MEDIA_VIDEO_RENDERER_IMPL_H_
+#ifndef WEBKIT_GLUE_MEDIA_VIDEO_RENDERER_IMPL_H_
+#define WEBKIT_GLUE_MEDIA_VIDEO_RENDERER_IMPL_H_
#include "base/gfx/platform_canvas.h"
#include "base/gfx/rect.h"
#include "base/gfx/size.h"
-#include "chrome/renderer/webmediaplayer_impl.h"
#include "media/base/buffers.h"
#include "media/base/factory.h"
#include "media/base/filters.h"
#include "media/filters/video_thread.h"
#include "webkit/api/public/WebMediaPlayer.h"
+namespace webkit_glue {
+
+class WebMediaPlayerImpl;
+
class VideoRendererImpl : public media::VideoThread {
public:
// Methods for painting called by the WebMediaPlayerDelegateImpl
@@ -105,4 +108,6 @@ class VideoRendererImpl : public media::VideoThread {
DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl);
};
-#endif // CHROME_RENDERER_MEDIA_VIDEO_RENDERER_IMPL_H_
+} // namespace webkit_glue
+
+#endif // WEBKIT_GLUE_MEDIA_VIDEO_RENDERER_IMPL_H_
diff --git a/chrome/renderer/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc
index 781c49b..ee6f7b5f 100644
--- a/chrome/renderer/webmediaplayer_impl.cc
+++ b/webkit/glue/webmediaplayer_impl.cc
@@ -2,15 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/webmediaplayer_impl.h"
-
#include "base/command_line.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/renderer/media/audio_renderer_impl.h"
-#include "chrome/renderer/media/buffered_data_source.h"
-#include "chrome/renderer/media/simple_data_source.h"
-#include "chrome/renderer/media/video_renderer_impl.h"
-#include "chrome/renderer/render_view.h"
#include "googleurl/src/gurl.h"
#include "media/filters/ffmpeg_audio_decoder.h"
#include "media/filters/ffmpeg_demuxer.h"
@@ -19,10 +11,15 @@
#include "webkit/api/public/WebRect.h"
#include "webkit/api/public/WebSize.h"
#include "webkit/api/public/WebURL.h"
+#include "webkit/glue/media/simple_data_source.h"
+#include "webkit/glue/media/video_renderer_impl.h"
+#include "webkit/glue/webmediaplayer_impl.h"
using WebKit::WebRect;
using WebKit::WebSize;
+namespace webkit_glue {
+
/////////////////////////////////////////////////////////////////////////////
// Task to be posted on main thread that fire WebMediaPlayer methods.
@@ -54,36 +51,24 @@ class NotifyWebMediaPlayerTask : public CancelableTask {
/////////////////////////////////////////////////////////////////////////////
// WebMediaPlayerImpl implementation
-WebMediaPlayerImpl::WebMediaPlayerImpl(RenderView* view,
- WebKit::WebMediaPlayerClient* client)
+WebMediaPlayerImpl::WebMediaPlayerImpl(WebKit::WebMediaPlayerClient* client,
+ media::FilterFactoryCollection* factory)
: network_state_(WebKit::WebMediaPlayer::Empty),
ready_state_(WebKit::WebMediaPlayer::HaveNothing),
main_loop_(NULL),
- filter_factory_(new media::FilterFactoryCollection()),
+ filter_factory_(factory),
video_renderer_(NULL),
client_(client),
- view_(view),
tasks_(kLastTaskIndex) {
- // Add in any custom filter factories first.
- const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
- if (cmd_line->HasSwitch(switches::kDisableAudio)) {
- filter_factory_->AddFactory(
- media::NullAudioRenderer::CreateFilterFactory());
- }
- if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
- filter_factory_->AddFactory(
- SimpleDataSource::CreateFactory(view->routing_id()));
- }
-
// Add in the default filter factories.
filter_factory_->AddFactory(media::FFmpegDemuxer::CreateFilterFactory());
filter_factory_->AddFactory(media::FFmpegAudioDecoder::CreateFactory());
filter_factory_->AddFactory(media::FFmpegVideoDecoder::CreateFactory());
- filter_factory_->AddFactory(
- AudioRendererImpl::CreateFactory(view_->audio_message_filter()));
- filter_factory_->AddFactory(
- BufferedDataSource::CreateFactory(view->routing_id()));
+ filter_factory_->AddFactory(media::NullAudioRenderer::CreateFilterFactory());
filter_factory_->AddFactory(VideoRendererImpl::CreateFactory(this));
+ // TODO(hclam): Provide a valid routing id to simple data source.
+ filter_factory_->AddFactory(
+ SimpleDataSource::CreateFactory(MessageLoop::current(), 0));
DCHECK(client_);
@@ -148,6 +133,7 @@ void WebMediaPlayerImpl::seek(float seconds) {
// Try to preserve as much accuracy as possible.
float microseconds = seconds * base::Time::kMicrosecondsPerSecond;
+ if (seconds != 0)
pipeline_.Seek(
base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)),
NewCallback(this, &WebMediaPlayerImpl::OnPipelineSeek));
@@ -358,3 +344,5 @@ void WebMediaPlayerImpl::PostTask(int index,
void WebMediaPlayerImpl::PostRepaintTask() {
PostTask(kRepaintTaskIndex, &WebKit::WebMediaPlayerClient::repaint);
}
+
+} // namespace webkit_glue
diff --git a/webkit/glue/webmediaplayer_impl.h b/webkit/glue/webmediaplayer_impl.h
new file mode 100644
index 0000000..e670535
--- /dev/null
+++ b/webkit/glue/webmediaplayer_impl.h
@@ -0,0 +1,229 @@
+// Copyright (c) 2008-2009 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.
+//
+// Delegate calls from WebCore::MediaPlayerPrivate to Chrome's video player.
+// It contains PipelineImpl which is the actual media player pipeline, it glues
+// the media player pipeline, data source, audio renderer and renderer.
+// PipelineImpl would creates multiple threads and access some public methods
+// of this class, so we need to be extra careful about concurrent access of
+// methods and members.
+//
+// Properties that are shared by main thread and media threads:
+// CancelableTaskList tasks_;
+// ^--- This property is shared for keeping records of the tasks posted to
+// make sure there will be only one task for each task type that can
+// exist in the main thread.
+//
+// Methods that are accessed in media threads:
+// SetAudioRenderer()
+// ^--- Called during the initialization of the pipeline, essentially from the
+// the pipeline thread.
+// SetVideoRenderer()
+// ^--- Called during the initialization of the pipeline, essentially from the
+// the pipeline thread.
+// PostRepaintTask()
+// ^--- Called from the video renderer thread to notify a video frame has
+// been prepared.
+// PostTask()
+// ^--- A method that helps posting tasks to the main thread, it is
+// accessed from main thread and media threads, it access the |tasks_|
+// internally. Needs locking inside to avoid concurrent access to
+// |tasks_|.
+//
+//
+// Other issues:
+// During tear down of the whole browser or a tab, the DOM tree may not be
+// destructed nicely, and there will be some dangling media threads trying to
+// the main thread, so we need this class to listen to destruction event of the
+// main thread and cleanup the media threads when the even is received. Also
+// at destruction of this class we will need to unhook it from destruction event
+// list of the main thread.
+
+#ifndef WEBKIT_GLUE_WEBMEDIAPLAYER_IMPL_H_
+#define WEBKTI_GLUE_WEBMEDIAPLAYER_IMPL_H_
+
+#include <vector>
+
+#include "base/gfx/platform_canvas.h"
+#include "base/lock.h"
+#include "base/message_loop.h"
+#include "media/base/filters.h"
+#include "media/base/pipeline_impl.h"
+#include "webkit/api/public/WebMediaPlayer.h"
+#include "webkit/api/public/WebMediaPlayerClient.h"
+
+class AudioRendererImpl;
+class DataSourceImpl;
+class GURL;
+class RenderView;
+class VideoRendererImpl;
+
+namespace media {
+class FilterFactoryCollection;
+}
+
+namespace webkit_glue {
+
+// This typedef is used for WebMediaPlayerImpl::PostTask() and
+// NotifyWebMediaPlayerTask in the source file.
+typedef void (WebKit::WebMediaPlayerClient::*WebMediaPlayerClientMethod)();
+
+class WebMediaPlayerImpl : public WebKit::WebMediaPlayer,
+ public MessageLoop::DestructionObserver {
+ public:
+ // Construct a WebMediaPlayerImpl with reference to the client, and media
+ // filter factory collection. By providing the filter factory collection
+ // the implementor can provide more specific media filters that does resource
+ // loading and rendering. |factory| should contain filter factories for:
+ // 1. Data source
+ // 2. Audio renderer
+ // 3. Video renderer (optional)
+ //
+ // There are some default filters provided by this method:
+ // 1. FFmpeg demuxer
+ // 2. FFmpeg audio decoder
+ // 3. FFmpeg video decoder
+ // 4. Video renderer
+ // 5. Simple data source
+ // 6. Null audio renderer
+ // The video renderer provided by this class is using the graphics context
+ // provided by WebKit to perform renderering. The simple data source does
+ // resource loading by loading the whole resource object into memory. Null
+ // audio renderer is a fake audio device that plays silence. Provider of the
+ // |factory| can override the default filters by adding extra filters to
+ // |factory| before calling this method.
+ WebMediaPlayerImpl(WebKit::WebMediaPlayerClient* client,
+ media::FilterFactoryCollection* factory);
+ virtual ~WebMediaPlayerImpl();
+
+ virtual void load(const WebKit::WebURL& url);
+ virtual void cancelLoad();
+
+ // Playback controls.
+ virtual void play();
+ virtual void pause();
+ virtual void stop();
+ virtual void seek(float seconds);
+ virtual void setEndTime(float seconds);
+ virtual void setRate(float rate);
+ virtual void setVolume(float volume);
+ virtual void setVisible(bool visible);
+ virtual bool setAutoBuffer(bool autoBuffer);
+ virtual bool totalBytesKnown();
+ virtual float maxTimeBuffered() const;
+ virtual float maxTimeSeekable() const;
+
+ // Methods for painting.
+ virtual void setSize(const WebKit::WebSize& size);
+
+ // TODO(hclam): enable this for mac.
+#if WEBKIT_USING_SKIA
+ virtual void paint(WebKit::WebCanvas* canvas, const WebKit::WebRect& rect);
+#endif
+
+ // True if a video is loaded.
+ virtual bool hasVideo() const;
+
+ // Dimensions of the video.
+ virtual WebKit::WebSize naturalSize() const;
+
+ // Getters of playback state.
+ virtual bool paused() const;
+ virtual bool seeking() const;
+ virtual float duration() const;
+ virtual float currentTime() const;
+
+ // Get rate of loading the resource.
+ virtual int32 dataRate() const;
+
+ // Internal states of loading and network.
+ // TODO(hclam): Ask the pipeline about the state rather than having reading
+ // them from members which would cause race conditions.
+ virtual WebKit::WebMediaPlayer::NetworkState networkState() const {
+ return network_state_;
+ }
+ virtual WebKit::WebMediaPlayer::ReadyState readyState() const {
+ return ready_state_;
+ }
+
+ virtual unsigned long long bytesLoaded() const;
+ virtual unsigned long long totalBytes() const;
+
+ // As we are closing the tab or even the browser, |main_loop_| is destroyed
+ // even before this object gets destructed, so we need to know when
+ // |main_loop_| is being destroyed and we can stop posting repaint task
+ // to it.
+ virtual void WillDestroyCurrentMessageLoop();
+
+ // Notification from |pipeline_| when initialization has finished.
+ void OnPipelineInitialize(bool successful);
+
+ // Notification from |pipeline_| when a seek has finished.
+ void OnPipelineSeek(bool successful);
+
+ // Called from tasks posted to |main_loop_| from this object to remove
+ // reference of them.
+ void DidTask(CancelableTask* task);
+
+ // Public methods to be called from renderers and data source so that
+ // WebMediaPlayerImpl has references to them.
+ void SetVideoRenderer(VideoRendererImpl* video_renderer);
+
+ // Called from VideoRenderer to fire a repaint task to |main_loop_|.
+ void PostRepaintTask();
+
+ // Inline getters.
+ WebKit::WebMediaPlayerClient* client() { return client_; }
+
+ private:
+ // Methods for posting tasks and cancelling tasks. This method may lives in
+ // the main thread or the media threads.
+ void PostTask(int index, WebMediaPlayerClientMethod method);
+
+ // Cancel all tasks currently live in |main_loop_|.
+ void CancelAllTasks();
+
+ // Indexes for tasks.
+ enum {
+ kRepaintTaskIndex = 0,
+ kReadyStateTaskIndex,
+ kNetworkStateTaskIndex,
+ kTimeChangedTaskIndex,
+ kLastTaskIndex
+ };
+
+ // TODO(hclam): get rid of these members and read from the pipeline directly.
+ WebKit::WebMediaPlayer::NetworkState network_state_;
+ WebKit::WebMediaPlayer::ReadyState ready_state_;
+
+ // Message loops for posting tasks between Chrome's main thread. Also used
+ // for DCHECKs so methods calls won't execute in the wrong thread.
+ MessageLoop* main_loop_;
+
+ // A collection of factories for creating filters.
+ scoped_refptr<media::FilterFactoryCollection> filter_factory_;
+
+ // The actual pipeline. We do it a composition here because we expect to have
+ // the same lifetime as the pipeline.
+ media::PipelineImpl pipeline_;
+
+ // We have the interface to VideoRenderer to delegate paint messages to it
+ // from WebKit.
+ scoped_refptr<VideoRendererImpl> video_renderer_;
+
+ WebKit::WebMediaPlayerClient* client_;
+
+ // List of tasks for holding pointers to all tasks currently in the
+ // |main_loop_|. |tasks_| can be access from main thread or the media threads
+ // we need a lock for protecting it.
+ Lock task_lock_;
+ typedef std::vector<CancelableTask*> CancelableTaskList;
+ CancelableTaskList tasks_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
+};
+
+} // namespace webkit_glue
+
+#endif // WEBKIT_GLUE_WEBMEDIAPLAYER_IMPL_H_
diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h
index 7609eff..c75e1fc 100644
--- a/webkit/glue/webview_delegate.h
+++ b/webkit/glue/webview_delegate.h
@@ -137,7 +137,7 @@ class WebViewDelegate : virtual public WebWidgetDelegate {
return NULL;
}
- // Called when a WebMediaPlayerDelegate is needed.
+ // Called when a WebMediaPlayer is needed.
virtual WebKit::WebMediaPlayer* CreateWebMediaPlayer(
WebKit::WebMediaPlayerClient* client) {
return NULL;
diff --git a/webkit/tools/DEPS b/webkit/tools/DEPS
index 84a57f5..c49be3d 100644
--- a/webkit/tools/DEPS
+++ b/webkit/tools/DEPS
@@ -1,8 +1,9 @@
-include_rules = [
- "+chrome/common",
- "+skia/ext",
-
- # Allow inclusion of WebKit mac headers.
- # This may need to be cleaned up, see http://crbug.com/12149
- "+mac",
-]
+include_rules = [
+ "+chrome/common",
+ "+media",
+ "+skia/ext",
+
+ # Allow inclusion of WebKit mac headers.
+ # This may need to be cleaned up, see http://crbug.com/12149
+ "+mac",
+]
diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp
index 5932b77..08b79c5 100644
--- a/webkit/tools/test_shell/test_shell.gyp
+++ b/webkit/tools/test_shell/test_shell.gyp
@@ -32,6 +32,7 @@
'npapi_layout_test_plugin',
'../../../base/base.gyp:base',
'../../../base/base.gyp:base_gfx',
+ '../../../media/media.gyp:media',
'../../../net/net.gyp:net',
'../../../skia/skia.gyp:skia',
'../../../testing/gtest.gyp:gtest',
@@ -173,6 +174,7 @@
'msvs_guid': 'FA39524D-3067-4141-888D-28A86C66F2B9',
'dependencies': [
'test_shell_common',
+ '../../../third_party/ffmpeg/ffmpeg.gyp:ffmpeg',
],
'sources': [
'test_shell_main.cc',
diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h
index ae6a9f1..0c4a033 100644
--- a/webkit/tools/test_shell/test_shell_webkit_init.h
+++ b/webkit/tools/test_shell/test_shell_webkit_init.h
@@ -5,8 +5,10 @@
#ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_
#define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_
+#include "base/path_service.h"
#include "base/stats_counters.h"
#include "base/string_util.h"
+#include "media/base/media.h"
#include "webkit/api/public/WebData.h"
#include "webkit/api/public/WebKit.h"
#include "webkit/api/public/WebString.h"
@@ -35,6 +37,13 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl {
WebKit::registerExtension(extensions_v8::GearsExtension::Get());
WebKit::registerExtension(extensions_v8::IntervalExtension::Get());
WebKit::enableWebWorkers();
+
+ // Load libraries for media and enable the media player.
+ FilePath module_path;
+ if (PathService::Get(base::DIR_MODULE, &module_path) &&
+ media::InitializeMediaLibrary(module_path)) {
+ WebKit::enableMediaPlayer();
+ }
}
~TestShellWebKitInit() {
diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc
index 58e914d..4d0a0bf 100644
--- a/webkit/tools/test_shell/test_webview_delegate.cc
+++ b/webkit/tools/test_shell/test_webview_delegate.cc
@@ -31,6 +31,7 @@
#include "webkit/glue/webview.h"
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/glue/plugins/webplugin_delegate_impl.h"
+#include "webkit/glue/webmediaplayer_impl.h"
#include "webkit/glue/window_open_disposition.h"
#include "webkit/tools/test_shell/test_navigation_controller.h"
#include "webkit/tools/test_shell/test_shell.h"
@@ -115,6 +116,12 @@ WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview,
return shell_->CreatePopupWidget(webview);
}
+WebKit::WebMediaPlayer* TestWebViewDelegate::CreateWebMediaPlayer(
+ WebKit::WebMediaPlayerClient* client) {
+ return new webkit_glue::WebMediaPlayerImpl(
+ client, new media::FilterFactoryCollection());
+}
+
WebWorker* TestWebViewDelegate::CreateWebWorker(WebWorkerClient* client) {
#if ENABLE(WORKERS)
return TestWebWorkerHelper::CreateWebWorker(client);
diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h
index 9bf0245..6cd21ff 100644
--- a/webkit/tools/test_shell/test_webview_delegate.h
+++ b/webkit/tools/test_shell/test_webview_delegate.h
@@ -89,6 +89,8 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>,
const std::string& mime_type,
const std::string& clsid,
std::string* actual_mime_type);
+ virtual WebKit::WebMediaPlayer* CreateWebMediaPlayer(
+ WebKit::WebMediaPlayerClient* client);
virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client);
virtual void OpenURL(WebView* webview,
const GURL& url,
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 4015e4a..7ae81b3 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -4419,6 +4419,10 @@
'glue/devtools/dom_agent_impl.cc',
'glue/devtools/dom_agent_impl.h',
'glue/devtools/tools_agent.h',
+ 'glue/media/simple_data_source.cc',
+ 'glue/media/simple_data_source.h',
+ 'glue/media/video_renderer_impl.cc',
+ 'glue/media/video_renderer_impl.h',
'glue/plugins/mozilla_extensions.cc',
'glue/plugins/mozilla_extensions.h',
'glue/plugins/nphostapi.h',
@@ -4565,6 +4569,8 @@
'glue/webkit_glue.h',
'glue/webkitclient_impl.cc',
'glue/webkitclient_impl.h',
+ 'glue/webmediaplayer_impl.h',
+ 'glue/webmediaplayer_impl.cc',
'glue/webmenurunner_mac.h',
'glue/webmenurunner_mac.mm',
'glue/webplugin.h',