Commit 50b1254a authored by acolwell's avatar acolwell Committed by Commit bot

Hook WebMediaPlayerImpl up to Mojo's HTMLDocumentView.

This patch provides the minimal changes necessary to hook
WebMediaPlayerImpl into HTMLDocumentView so that <audio>/<video> tags
work. HTMLMediaElement will now function, but audio won't be audible
right now. Proper audio output will be added in a followup patch.

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

Cr-Commit-Position: refs/heads/master@{#294692}
parent 7e12ca68
......@@ -31,6 +31,8 @@ component("blink") {
"encrypted_media_player_support.h",
"cache_util.cc",
"cache_util.h",
"null_encrypted_media_player_support.cc",
"null_encrypted_media_player_support.h",
"texttrack_impl.cc",
"texttrack_impl.h",
"video_frame_compositor.cc",
......
......@@ -36,6 +36,8 @@
'encrypted_media_player_support.h',
'cache_util.cc',
'cache_util.h',
'null_encrypted_media_player_support.cc',
'null_encrypted_media_player_support.h',
'texttrack_impl.cc',
'texttrack_impl.h',
'video_frame_compositor.cc',
......
// Copyright 2014 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/blink/null_encrypted_media_player_support.h"
#include "third_party/WebKit/public/platform/WebContentDecryptionModule.h"
#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
namespace media {
scoped_ptr<EncryptedMediaPlayerSupport>
NullEncryptedMediaPlayerSupport::Create(blink::WebMediaPlayerClient* client) {
return scoped_ptr<EncryptedMediaPlayerSupport>(
new NullEncryptedMediaPlayerSupport());
}
NullEncryptedMediaPlayerSupport::NullEncryptedMediaPlayerSupport() {
}
NullEncryptedMediaPlayerSupport::~NullEncryptedMediaPlayerSupport() {
}
blink::WebMediaPlayer::MediaKeyException
NullEncryptedMediaPlayerSupport::GenerateKeyRequest(
blink::WebLocalFrame* frame,
const blink::WebString& key_system,
const unsigned char* init_data,
unsigned init_data_length) {
return blink::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
}
blink::WebMediaPlayer::MediaKeyException
NullEncryptedMediaPlayerSupport::AddKey(
const blink::WebString& key_system,
const unsigned char* key,
unsigned key_length,
const unsigned char* init_data,
unsigned init_data_length,
const blink::WebString& session_id) {
return blink::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
}
blink::WebMediaPlayer::MediaKeyException
NullEncryptedMediaPlayerSupport::CancelKeyRequest(
const blink::WebString& key_system,
const blink::WebString& session_id) {
return blink::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
}
void NullEncryptedMediaPlayerSupport::SetContentDecryptionModule(
blink::WebContentDecryptionModule* cdm) {
}
void NullEncryptedMediaPlayerSupport::SetContentDecryptionModule(
blink::WebContentDecryptionModule* cdm,
blink::WebContentDecryptionModuleResult result) {
result.completeWithError(
blink::WebContentDecryptionModuleExceptionNotSupportedError,
0,
"Null MediaKeys object is not supported.");
}
void NullEncryptedMediaPlayerSupport::SetContentDecryptionModuleSync(
blink::WebContentDecryptionModule* cdm) {
}
Demuxer::NeedKeyCB NullEncryptedMediaPlayerSupport::CreateNeedKeyCB() {
return Demuxer::NeedKeyCB();
}
SetDecryptorReadyCB
NullEncryptedMediaPlayerSupport::CreateSetDecryptorReadyCB() {
return SetDecryptorReadyCB();
}
void NullEncryptedMediaPlayerSupport::OnPipelineDecryptError() {
}
} // namespace media
// Copyright 2014 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_BLINK_NULL_ENCRYPTED_MEDIA_PLAYER_SUPPORT_H_
#define MEDIA_BLINK_NULL_ENCRYPTED_MEDIA_PLAYER_SUPPORT_H_
#include "media/base/media_export.h"
#include "media/blink/encrypted_media_player_support.h"
namespace media {
// A "null" implementation of the EncryptedMediaPlayerSupport interface
// that indicates all key systems are not supported. This makes sure that
// any attempts to play encrypted content always fail.
class MEDIA_EXPORT NullEncryptedMediaPlayerSupport
: public EncryptedMediaPlayerSupport {
public:
static scoped_ptr<EncryptedMediaPlayerSupport> Create(
blink::WebMediaPlayerClient* client);
virtual ~NullEncryptedMediaPlayerSupport();
// Prefixed API methods.
virtual blink::WebMediaPlayer::MediaKeyException GenerateKeyRequest(
blink::WebLocalFrame* frame,
const blink::WebString& key_system,
const unsigned char* init_data,
unsigned init_data_length) OVERRIDE;
virtual blink::WebMediaPlayer::MediaKeyException AddKey(
const blink::WebString& key_system,
const unsigned char* key,
unsigned key_length,
const unsigned char* init_data,
unsigned init_data_length,
const blink::WebString& session_id) OVERRIDE;
virtual blink::WebMediaPlayer::MediaKeyException CancelKeyRequest(
const blink::WebString& key_system,
const blink::WebString& session_id) OVERRIDE;
// Unprefixed API methods.
virtual void SetContentDecryptionModule(
blink::WebContentDecryptionModule* cdm) OVERRIDE;
virtual void SetContentDecryptionModule(
blink::WebContentDecryptionModule* cdm,
blink::WebContentDecryptionModuleResult result) OVERRIDE;
virtual void SetContentDecryptionModuleSync(
blink::WebContentDecryptionModule* cdm) OVERRIDE;
// Callback factory and notification methods used by WebMediaPlayerImpl.
// Creates a callback that Demuxers can use to signal that the content
// requires a key. This method makes sure the callback returned can be safely
// invoked from any thread.
virtual Demuxer::NeedKeyCB CreateNeedKeyCB() OVERRIDE;
// Creates a callback that renderers can use to set decryptor
// ready callback. This method makes sure the callback returned can be safely
// invoked from any thread.
virtual SetDecryptorReadyCB CreateSetDecryptorReadyCB() OVERRIDE;
// Called to inform this object that the media pipeline encountered
// and handled a decryption error.
virtual void OnPipelineDecryptError() OVERRIDE;
private:
NullEncryptedMediaPlayerSupport();
DISALLOW_COPY_AND_ASSIGN(NullEncryptedMediaPlayerSupport);
};
} // namespace media
#endif // MEDIA_BLINK_NULL_ENCRYPTED_MEDIA_PLAYER_SUPPORT_H_
......@@ -32,11 +32,12 @@ class MEDIA_EXPORT WebMediaPlayerParams {
// callback must always return a valid EncryptedMediaPlayerSupport object.
typedef base::Callback<scoped_ptr<EncryptedMediaPlayerSupport>(
blink::WebMediaPlayerClient*)> EncryptedMediaPlayerSupportCreateCB;
typedef base::Callback<void(const base::Closure&)> DeferLoadCB;
// |defer_load_cb|, |audio_renderer_sink|, and |compositor_task_runner| may be
// null.
WebMediaPlayerParams(
const base::Callback<void(const base::Closure&)>& defer_load_cb,
const DeferLoadCB& defer_load_cb,
const scoped_refptr<AudioRendererSink>& audio_renderer_sink,
const AudioHardwareConfig& audio_hardware_config,
const scoped_refptr<MediaLog>& media_log,
......
......@@ -11,6 +11,8 @@
'../cc/blink/cc_blink.gyp:cc_blink',
'../cc/cc.gyp:cc',
'../cc/cc.gyp:cc_surfaces',
'../media/blink/media_blink.gyp:media_blink',
'../media/media.gyp:media',
'../net/net.gyp:net',
'../skia/skia.gyp:skia',
'../third_party/WebKit/public/blink.gyp:blink',
......@@ -46,6 +48,8 @@
'services/html_viewer/html_document_view.h',
'services/html_viewer/webcookiejar_impl.cc',
'services/html_viewer/webcookiejar_impl.h',
'services/html_viewer/webmediaplayer_factory.cc',
'services/html_viewer/webmediaplayer_factory.h',
'services/html_viewer/webmimeregistry_impl.cc',
'services/html_viewer/webmimeregistry_impl.h',
'services/html_viewer/websockethandle_impl.cc',
......
include_rules = [
"+cc",
"+media",
"+mojo/cc",
"+mojo/services",
"+net/base",
......
......@@ -17,6 +17,7 @@
#include "mojo/services/html_viewer/blink_input_events_type_converters.h"
#include "mojo/services/html_viewer/blink_url_request_type_converters.h"
#include "mojo/services/html_viewer/weblayertreeview_impl.h"
#include "mojo/services/html_viewer/webmediaplayer_factory.h"
#include "mojo/services/html_viewer/webstoragenamespace_impl.h"
#include "mojo/services/html_viewer/weburlloader_impl.h"
#include "mojo/services/public/cpp/view_manager/view.h"
......@@ -87,12 +88,14 @@ HTMLDocumentView::HTMLDocumentView(
URLResponsePtr response,
InterfaceRequest<ServiceProvider> service_provider_request,
Shell* shell,
scoped_refptr<base::MessageLoopProxy> compositor_thread)
scoped_refptr<base::MessageLoopProxy> compositor_thread,
WebMediaPlayerFactory* web_media_player_factory)
: shell_(shell),
web_view_(NULL),
root_(NULL),
view_manager_client_factory_(shell, this),
compositor_thread_(compositor_thread),
web_media_player_factory_(web_media_player_factory),
weak_factory_(this) {
ServiceProviderImpl* exported_services = new ServiceProviderImpl();
exported_services->AddService(&view_manager_client_factory_);
......@@ -170,6 +173,13 @@ blink::WebLayerTreeView* HTMLDocumentView::layerTreeView() {
return web_layer_tree_view_impl_.get();
}
blink::WebMediaPlayer* HTMLDocumentView::createMediaPlayer(
blink::WebLocalFrame* frame,
const blink::WebURL& url,
blink::WebMediaPlayerClient* client) {
return web_media_player_factory_->CreateMediaPlayer(frame, url, client);
}
blink::WebFrame* HTMLDocumentView::createChildFrame(
blink::WebLocalFrame* parent,
const blink::WebString& frameName) {
......
......@@ -23,6 +23,7 @@ class MessageLoopProxy;
namespace mojo {
class WebMediaPlayerFactory;
class ViewManager;
class View;
class WebLayerTreeViewImpl;
......@@ -44,7 +45,8 @@ class HTMLDocumentView : public blink::WebViewClient,
HTMLDocumentView(URLResponsePtr response,
InterfaceRequest<ServiceProvider> service_provider_request,
Shell* shell,
scoped_refptr<base::MessageLoopProxy> compositor_thread);
scoped_refptr<base::MessageLoopProxy> compositor_thread,
WebMediaPlayerFactory* web_media_player_factory);
virtual ~HTMLDocumentView();
private:
......@@ -56,6 +58,10 @@ class HTMLDocumentView : public blink::WebViewClient,
virtual blink::WebLayerTreeView* layerTreeView();
// WebFrameClient methods:
virtual blink::WebMediaPlayer* createMediaPlayer(
blink::WebLocalFrame* frame,
const blink::WebURL& url,
blink::WebMediaPlayerClient* client);
virtual blink::WebFrame* createChildFrame(blink::WebLocalFrame* parent,
const blink::WebString& frameName);
virtual void frameDetached(blink::WebFrame*);
......@@ -100,6 +106,7 @@ class HTMLDocumentView : public blink::WebViewClient,
ViewManagerClientFactory view_manager_client_factory_;
scoped_ptr<WebLayerTreeViewImpl> web_layer_tree_view_impl_;
scoped_refptr<base::MessageLoopProxy> compositor_thread_;
WebMediaPlayerFactory* web_media_player_factory_;
base::WeakPtrFactory<HTMLDocumentView> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(HTMLDocumentView);
......
......@@ -12,6 +12,7 @@
#include "mojo/public/cpp/application/interface_factory_impl.h"
#include "mojo/services/html_viewer/blink_platform_impl.h"
#include "mojo/services/html_viewer/html_document_view.h"
#include "mojo/services/html_viewer/webmediaplayer_factory.h"
#include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
#include "third_party/WebKit/public/web/WebKit.h"
......@@ -22,8 +23,11 @@ class HTMLViewer;
class ContentHandlerImpl : public InterfaceImpl<ContentHandler> {
public:
ContentHandlerImpl(Shell* shell,
scoped_refptr<base::MessageLoopProxy> compositor_thread)
: shell_(shell), compositor_thread_(compositor_thread) {}
scoped_refptr<base::MessageLoopProxy> compositor_thread,
WebMediaPlayerFactory* web_media_player_factory)
: shell_(shell),
compositor_thread_(compositor_thread),
web_media_player_factory_(web_media_player_factory) {}
virtual ~ContentHandlerImpl() {}
private:
......@@ -35,11 +39,13 @@ class ContentHandlerImpl : public InterfaceImpl<ContentHandler> {
new HTMLDocumentView(response.Pass(),
service_provider_request.Pass(),
shell_,
compositor_thread_);
compositor_thread_,
web_media_player_factory_);
}
Shell* shell_;
scoped_refptr<base::MessageLoopProxy> compositor_thread_;
WebMediaPlayerFactory* web_media_player_factory_;
DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
};
......@@ -58,6 +64,8 @@ class HTMLViewer : public ApplicationDelegate,
blink_platform_impl_.reset(new BlinkPlatformImpl(app));
blink::initialize(blink_platform_impl_.get());
compositor_thread_.Start();
web_media_player_factory_.reset(new WebMediaPlayerFactory(
compositor_thread_.message_loop_proxy()));
}
virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
......@@ -70,13 +78,15 @@ class HTMLViewer : public ApplicationDelegate,
virtual void Create(ApplicationConnection* connection,
InterfaceRequest<ContentHandler> request) OVERRIDE {
BindToRequest(
new ContentHandlerImpl(shell_, compositor_thread_.message_loop_proxy()),
new ContentHandlerImpl(shell_, compositor_thread_.message_loop_proxy(),
web_media_player_factory_.get()),
&request);
}
scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
Shell* shell_;
base::Thread compositor_thread_;
scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_;
DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
};
......
// Copyright 2014 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 "mojo/services/html_viewer/webmediaplayer_factory.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/threading/thread.h"
#include "media/audio/audio_manager.h"
#include "media/audio/audio_manager_base.h"
#include "media/audio/null_audio_sink.h"
#include "media/base/audio_hardware_config.h"
#include "media/base/media.h"
#include "media/base/media_log.h"
#include "media/blink/null_encrypted_media_player_support.h"
#include "media/blink/webmediaplayer_impl.h"
#include "media/blink/webmediaplayer_params.h"
#include "media/filters/gpu_video_accelerator_factories.h"
namespace mojo {
WebMediaPlayerFactory::WebMediaPlayerFactory(
const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner)
: compositor_task_runner_(compositor_task_runner),
media_thread_("Media"),
audio_manager_(media::AudioManager::Create(&fake_audio_log_factory_)),
audio_hardware_config_(
audio_manager_->GetInputStreamParameters(
media::AudioManagerBase::kDefaultDeviceId),
audio_manager_->GetDefaultOutputStreamParameters()) {
if (!media::IsMediaLibraryInitialized()) {
base::FilePath module_dir;
CHECK(PathService::Get(base::DIR_EXE, &module_dir));
CHECK(media::InitializeMediaLibrary(module_dir));
}
}
WebMediaPlayerFactory::~WebMediaPlayerFactory() {
}
blink::WebMediaPlayer* WebMediaPlayerFactory::CreateMediaPlayer(
blink::WebLocalFrame* frame,
const blink::WebURL& url,
blink::WebMediaPlayerClient* client) {
media::WebMediaPlayerParams params(
media::WebMediaPlayerParams::DeferLoadCB(),
CreateAudioRendererSink(),
GetAudioHardwareConfig(),
new media::MediaLog(),
scoped_refptr<media::GpuVideoAcceleratorFactories>(),
GetMediaThreadTaskRunner(),
compositor_task_runner_,
base::Bind(&media::NullEncryptedMediaPlayerSupport::Create));
base::WeakPtr<media::WebMediaPlayerDelegate> delegate;
return new media::WebMediaPlayerImpl(frame, client, delegate, params);
}
const media::AudioHardwareConfig&
WebMediaPlayerFactory::GetAudioHardwareConfig() {
return audio_hardware_config_;
}
scoped_refptr<media::AudioRendererSink>
WebMediaPlayerFactory::CreateAudioRendererSink() {
// TODO(acolwell): Replace this with an AudioRendererSink implementation
// that actually talks to the audio device or an audio mojo service.
return new media::NullAudioSink(GetMediaThreadTaskRunner());
}
scoped_refptr<base::SingleThreadTaskRunner>
WebMediaPlayerFactory::GetMediaThreadTaskRunner() {
if (!media_thread_.IsRunning())
media_thread_.Start();
return media_thread_.message_loop_proxy();
}
} // namespace mojo
// Copyright 2014 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 MOJO_SERVICES_HTML_VIEWER_WEBMEDIAPLAYER_FACTORY_H_
#define MOJO_SERVICES_HTML_VIEWER_WEBMEDIAPLAYER_FACTORY_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread.h"
#include "media/audio/fake_audio_log_factory.h"
#include "media/base/audio_hardware_config.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace blink {
class WebMediaPlayer;
class WebLocalFrame;
class WebURL;
class WebMediaPlayerClient;
}
namespace media {
class AudioManager;
class AudioRendererSink;
}
namespace mojo {
// Helper class used to create blink::WebMediaPlayer objects.
// This class stores the "global state" shared across all WebMediaPlayer
// instances.
class WebMediaPlayerFactory {
public:
explicit WebMediaPlayerFactory(const scoped_refptr<
base::SingleThreadTaskRunner>& compositor_task_runner);
~WebMediaPlayerFactory();
blink::WebMediaPlayer* CreateMediaPlayer(blink::WebLocalFrame* frame,
const blink::WebURL& url,
blink::WebMediaPlayerClient* client);
private:
const media::AudioHardwareConfig& GetAudioHardwareConfig();
scoped_refptr<media::AudioRendererSink> CreateAudioRendererSink();
scoped_refptr<base::SingleThreadTaskRunner> GetMediaThreadTaskRunner();
scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
base::Thread media_thread_;
media::FakeAudioLogFactory fake_audio_log_factory_;
scoped_ptr<media::AudioManager> audio_manager_;
media::AudioHardwareConfig audio_hardware_config_;
DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerFactory);
};
} // namespace mojo
#endif // MOJO_SERVICES_HTML_VIEWER_WEBMEDIAPLAYER_FACTORY_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment