diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-23 01:20:37 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-23 01:20:37 +0000 |
commit | 457d83467c00c236e806bb150796a2efdc88bfcf (patch) | |
tree | 36c58186b34d36300374b232fb79540457307b23 /chrome | |
parent | 77a397cc5cf8106e559aa87a5228478afc28cec1 (diff) | |
download | chromium_src-457d83467c00c236e806bb150796a2efdc88bfcf.zip chromium_src-457d83467c00c236e806bb150796a2efdc88bfcf.tar.gz chromium_src-457d83467c00c236e806bb150796a2efdc88bfcf.tar.bz2 |
Terminate FilterFactory and his nasty friends
FilterFactory, IsMediaFormatSupported and CreateFactory are the source
of evil. They also have have a gang of template functions. This patch
terminate them all and make the world a better place.
BUG=28207
TEST=<video> runs
Review URL: http://codereview.chromium.org/3878001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63609 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/renderer/media/audio_renderer_impl.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/media/audio_renderer_impl.h | 18 | ||||
-rw-r--r-- | chrome/renderer/media/ipc_video_decoder.cc | 20 | ||||
-rw-r--r-- | chrome/renderer/media/ipc_video_decoder.h | 7 | ||||
-rw-r--r-- | chrome/renderer/media/ipc_video_renderer.cc | 31 | ||||
-rw-r--r-- | chrome/renderer/media/ipc_video_renderer.h | 41 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 38 | ||||
-rw-r--r-- | chrome/renderer/webmediaplayer_impl.h | 203 |
8 files changed, 42 insertions, 324 deletions
diff --git a/chrome/renderer/media/audio_renderer_impl.cc b/chrome/renderer/media/audio_renderer_impl.cc index 2ce02ab..e5c2f0c 100644 --- a/chrome/renderer/media/audio_renderer_impl.cc +++ b/chrome/renderer/media/audio_renderer_impl.cc @@ -51,14 +51,6 @@ base::TimeDelta AudioRendererImpl::ConvertToDuration(int bytes) { return base::TimeDelta(); } -bool AudioRendererImpl::IsMediaFormatSupported( - const media::MediaFormat& media_format) { - int channels; - int sample_rate; - int sample_bits; - return ParseMediaFormat(media_format, &channels, &sample_rate, &sample_bits); -} - bool AudioRendererImpl::OnInitialize(const media::MediaFormat& media_format) { // Parse integer values in MediaFormat. if (!ParseMediaFormat(media_format, diff --git a/chrome/renderer/media/audio_renderer_impl.h b/chrome/renderer/media/audio_renderer_impl.h index 57fb8eb..5c27ef3 100644 --- a/chrome/renderer/media/audio_renderer_impl.h +++ b/chrome/renderer/media/audio_renderer_impl.h @@ -46,7 +46,6 @@ #include "chrome/renderer/audio_message_filter.h" #include "media/audio/audio_io.h" #include "media/audio/audio_manager.h" -#include "media/base/factory.h" #include "media/base/filters.h" #include "media/filters/audio_renderer_base.h" @@ -56,13 +55,9 @@ class AudioRendererImpl : public media::AudioRendererBase, public AudioMessageFilter::Delegate, public MessageLoop::DestructionObserver { public: - // Methods called on render thread ------------------------------------------ - // Methods called during construction. - static media::FilterFactory* CreateFactory(AudioMessageFilter* filter) { - return new media::FilterFactoryImpl1<AudioRendererImpl, - AudioMessageFilter*>(filter); - } - static bool IsMediaFormatSupported(const media::MediaFormat& format); + // Methods called on Render thread ------------------------------------------ + explicit AudioRendererImpl(AudioMessageFilter* filter); + virtual ~AudioRendererImpl(); // Methods called on IO thread ---------------------------------------------- // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. @@ -94,18 +89,11 @@ class AudioRendererImpl : public media::AudioRendererBase, virtual void OnReadComplete(media::Buffer* buffer_in); private: - friend class media::FilterFactoryImpl1<AudioRendererImpl, - AudioMessageFilter*>; - // For access to constructor and IO thread methods. friend class AudioRendererImplTest; FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, Stop); FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, DestroyedMessageLoop_OnReadComplete); - - explicit AudioRendererImpl(AudioMessageFilter* filter); - virtual ~AudioRendererImpl(); - // Helper methods. // Convert number of bytes to duration of time using information about the // number of channels, sample rate and sample bits. diff --git a/chrome/renderer/media/ipc_video_decoder.cc b/chrome/renderer/media/ipc_video_decoder.cc index d06130e..12b262a 100644 --- a/chrome/renderer/media/ipc_video_decoder.cc +++ b/chrome/renderer/media/ipc_video_decoder.cc @@ -188,23 +188,3 @@ void IpcVideoDecoder::ConsumeVideoFrame( void IpcVideoDecoder::ProduceVideoSample(scoped_refptr<media::Buffer> buffer) { demuxer_stream_->Read(NewCallback(this, &IpcVideoDecoder::OnReadComplete)); } - -// static -media::FilterFactory* IpcVideoDecoder::CreateFactory( - MessageLoop* message_loop, ggl::Context* ggl_context) { - return new media::FilterFactoryImpl2< - IpcVideoDecoder, MessageLoop*, ggl::Context*>(message_loop, ggl_context); -} - -// static -bool IpcVideoDecoder::IsMediaFormatSupported(const media::MediaFormat& format) { - std::string mime_type; - if (!format.GetAsString(media::MediaFormat::kMimeType, &mime_type) && - media::mime_type::kFFmpegVideo != mime_type) - return false; - - // TODO(jiesun): Although we current only support H264 hardware decoding, - // in the future, we should query GpuVideoService for capabilities. - int codec_id; - return format.GetAsInteger(media::MediaFormat::kFFmpegCodecID, &codec_id); -} diff --git a/chrome/renderer/media/ipc_video_decoder.h b/chrome/renderer/media/ipc_video_decoder.h index c9d800d..c1f12fb 100644 --- a/chrome/renderer/media/ipc_video_decoder.h +++ b/chrome/renderer/media/ipc_video_decoder.h @@ -21,14 +21,9 @@ class Context; class IpcVideoDecoder : public media::VideoDecoder, public media::VideoDecodeEngine::EventHandler { public: - explicit IpcVideoDecoder(MessageLoop* message_loop, - ggl::Context* ggl_context); + IpcVideoDecoder(MessageLoop* message_loop, ggl::Context* ggl_context); virtual ~IpcVideoDecoder(); - static media::FilterFactory* CreateFactory(MessageLoop* message_loop, - ggl::Context* ggl_context); - static bool IsMediaFormatSupported(const media::MediaFormat& media_format); - // MediaFilter implementation. virtual void Stop(media::FilterCallback* callback); virtual void Seek(base::TimeDelta time, media::FilterCallback* callback); diff --git a/chrome/renderer/media/ipc_video_renderer.cc b/chrome/renderer/media/ipc_video_renderer.cc index d9a194d..fcf8c61 100644 --- a/chrome/renderer/media/ipc_video_renderer.cc +++ b/chrome/renderer/media/ipc_video_renderer.cc @@ -9,37 +9,15 @@ #include "media/base/video_frame.h" #include "media/base/media_format.h" -IPCVideoRenderer::IPCVideoRenderer( - webkit_glue::WebMediaPlayerImpl::Proxy* proxy, - int routing_id) - : proxy_(proxy), - created_(false), +IPCVideoRenderer::IPCVideoRenderer(int routing_id) + : created_(false), routing_id_(routing_id), stopped_(false, false) { - // TODO(hclam): decide whether to do the following line in this thread or - // in the render thread. - proxy->SetVideoRenderer(this); } IPCVideoRenderer::~IPCVideoRenderer() { } -// static -media::FilterFactory* IPCVideoRenderer::CreateFactory( - webkit_glue::WebMediaPlayerImpl::Proxy* proxy, - int routing_id) { - return new media::FilterFactoryImpl2< - IPCVideoRenderer, - webkit_glue::WebMediaPlayerImpl::Proxy*, - int>(proxy, routing_id); -} - -// static -bool IPCVideoRenderer::IsMediaFormatSupported( - const media::MediaFormat& media_format) { - return ParseMediaFormat(media_format, NULL, NULL, NULL, NULL); -} - bool IPCVideoRenderer::OnInitialize(media::VideoDecoder* decoder) { video_size_.SetSize(width(), height()); @@ -64,6 +42,11 @@ void IPCVideoRenderer::OnFrameAvailable() { NewRunnableMethod(this, &IPCVideoRenderer::DoUpdateVideo)); } +void IPCVideoRenderer::SetWebMediaPlayerImplProxy( + webkit_glue::WebMediaPlayerImpl::Proxy* proxy) { + proxy_ = proxy; +} + void IPCVideoRenderer::SetRect(const gfx::Rect& rect) { DCHECK(MessageLoop::current() == proxy_->message_loop()); diff --git a/chrome/renderer/media/ipc_video_renderer.h b/chrome/renderer/media/ipc_video_renderer.h index c934291..d032469 100644 --- a/chrome/renderer/media/ipc_video_renderer.h +++ b/chrome/renderer/media/ipc_video_renderer.h @@ -22,7 +22,12 @@ class IPCVideoRenderer : public webkit_glue::WebVideoRenderer { public: + explicit IPCVideoRenderer(int routing_id); + virtual ~IPCVideoRenderer(); + // WebVideoRenderer implementation. + virtual void SetWebMediaPlayerImplProxy( + webkit_glue::WebMediaPlayerImpl::Proxy* proxy); virtual void SetRect(const gfx::Rect& rect); virtual void Paint(skia::PlatformCanvas* canvas, const gfx::Rect& dest_rect); @@ -30,33 +35,6 @@ class IPCVideoRenderer : public webkit_glue::WebVideoRenderer { void OnUpdateVideoAck(); void OnDestroyVideo(); - // Static method for creating factory for this object. - static media::FilterFactory* CreateFactory( - webkit_glue::WebMediaPlayerImpl::Proxy* proxy, - int routing_id); - - // FilterFactoryImpl2 implementation. - static bool IsMediaFormatSupported(const media::MediaFormat& media_format); - - // TODO(scherkus): remove this mega-hack, see http://crbug.com/28207 - class FactoryFactory : public webkit_glue::WebVideoRendererFactoryFactory { - public: - explicit FactoryFactory(int routing_id) - : webkit_glue::WebVideoRendererFactoryFactory(), - routing_id_(routing_id) { - } - - virtual media::FilterFactory* CreateFactory( - webkit_glue::WebMediaPlayerImpl::Proxy* proxy) { - return IPCVideoRenderer::CreateFactory(proxy, routing_id_); - } - - private: - int routing_id_; - - DISALLOW_COPY_AND_ASSIGN(FactoryFactory); - }; - protected: // VideoRendererBase implementation. virtual bool OnInitialize(media::VideoDecoder* decoder); @@ -64,15 +42,6 @@ class IPCVideoRenderer : public webkit_glue::WebVideoRenderer { virtual void OnFrameAvailable(); private: - // Only the filter factories can create instances. - friend class media::FilterFactoryImpl2< - IPCVideoRenderer, - webkit_glue::WebMediaPlayerImpl::Proxy*, - int>; - IPCVideoRenderer(webkit_glue::WebMediaPlayerImpl::Proxy* proxy, - int routing_id); - virtual ~IPCVideoRenderer(); - // Send an IPC message to the browser process. The routing ID of the message // is assumed to match |routing_id_|. void Send(IPC::Message* msg); diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 850800b..baac89a 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -2539,14 +2539,13 @@ WebSharedWorker* RenderView::createSharedWorker( WebMediaPlayer* RenderView::createMediaPlayer( WebFrame* frame, WebMediaPlayerClient* client) { - scoped_refptr<media::FilterFactoryCollection> factory = - new media::FilterFactoryCollection(); + media::MediaFilterCollection collection; + // 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())); + collection.push_back(new AudioRendererImpl(audio_message_filter())); } if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) && @@ -2557,7 +2556,7 @@ WebMediaPlayer* RenderView::createMediaPlayer( bool ret = frame->view()->graphicsContext3D()->makeContextCurrent(); CHECK(ret) << "Failed to switch context"; - factory->AddFactory(IpcVideoDecoder::CreateFactory( + collection.push_back(new IpcVideoDecoder( MessageLoop::current(), ggl::GetCurrentContext())); } @@ -2565,7 +2564,17 @@ WebMediaPlayer* RenderView::createMediaPlayer( WebApplicationCacheHostImpl::FromFrame(frame); // TODO(hclam): obtain the following parameters from |client|. - webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = + // Create two bridge factory for two data sources. + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_simple = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL(frame->url()), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache_host ? appcache_host->host_id() : appcache::kNoHostId, + routing_id()); + + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_buffered = new webkit_glue::MediaResourceLoaderBridgeFactory( GURL(frame->url()), // referrer "null", // frame origin @@ -2574,18 +2583,23 @@ WebMediaPlayer* RenderView::createMediaPlayer( appcache_host ? appcache_host->host_id() : appcache::kNoHostId, routing_id()); - webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL; + scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer; if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) { - factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_); + scoped_refptr<IPCVideoRenderer> renderer = + new IPCVideoRenderer(routing_id_); + collection.push_back(renderer); + video_renderer = renderer; } else { bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); - factory_factory = - new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging); + scoped_refptr<webkit_glue::VideoRendererImpl> renderer = + new webkit_glue::VideoRendererImpl(pts_logging); + collection.push_back(renderer); + video_renderer = renderer; } return new webkit_glue::WebMediaPlayerImpl( - client, factory, bridge_factory, - cmd_line->HasSwitch(switches::kSimpleDataSource), factory_factory); + client, collection, bridge_factory_simple, bridge_factory_buffered, + cmd_line->HasSwitch(switches::kSimpleDataSource),video_renderer); } WebApplicationCacheHost* RenderView::createApplicationCacheHost( diff --git a/chrome/renderer/webmediaplayer_impl.h b/chrome/renderer/webmediaplayer_impl.h deleted file mode 100644 index fdaf652..0000000 --- a/chrome/renderer/webmediaplayer_impl.h +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) 2010 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 CHROME_RENDERER_WEBMEDIAPLAYER_IMPL_H_ -#define CHROME_RENDERER_WEBMEDIAPLAYER_IMPL_H_ -#pragma once - -#include <vector> - -#include "base/lock.h" -#include "base/message_loop.h" -#include "media/base/filters.h" -#include "media/base/pipeline_impl.h" -#include "skia/ext/platform_canvas.h" -#include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayer.h" -#include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerClient.h" - -class AudioRendererImpl; -class DataSourceImpl; -class GURL; -class RenderView; -class VideoRendererImpl; - -namespace media { -class FilterFactoryCollection; -} - -// 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: - WebMediaPlayerImpl(RenderView* view, WebKit::WebMediaPlayerClient* client); - 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); - - virtual void paint(WebKit::WebCanvas* canvas, const WebKit::WebRect& rect); - - // 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_; } - RenderView* view() { return view_; } - - 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_; - RenderView* view_; - - // 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); -}; - -#endif // CHROME_RENDERER_WEBMEDIAPLAYER_IMPL_H_ |