Commit 1a428218 authored by halliwell's avatar halliwell Committed by Commit bot

Allow CastContentBrowserClient to customise media pipeline device

We need a hook to customise how MediaPipelineDevice is created,
orthogonal to the vendor-specific aspect of creation.  Decided to
keep existing factory method for the vendor customisation so there's
no need to change vendor implementations for now (although this
will all get moved into libcast_media before long).  New hook is
in CastContentBrowserClient and can be substituted as the other
Platform* functions already are.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#333090}
parent cd7c6485
......@@ -24,6 +24,7 @@
#include "chromecast/browser/media/cma_message_filter_host.h"
#include "chromecast/browser/url_request_context_factory.h"
#include "chromecast/common/global_descriptors.h"
#include "chromecast/media/cma/backend/media_pipeline_device.h"
#include "components/crash/app/breakpad_linux.h"
#include "components/crash/browser/crash_handler_host_linux.h"
#include "components/network_hints/browser/network_hints_message_filter.h"
......@@ -75,7 +76,11 @@ void CastContentBrowserClient::RenderProcessWillLaunch(
content::RenderProcessHost* host) {
#if !defined(OS_ANDROID)
scoped_refptr<media::CmaMessageFilterHost> cma_message_filter(
new media::CmaMessageFilterHost(host->GetID()));
new media::CmaMessageFilterHost(
host->GetID(),
base::Bind(
&CastContentBrowserClient::PlatformCreateMediaPipelineDevice,
base::Unretained(this))));
host->AddFilter(cma_message_filter.get());
#endif // !defined(OS_ANDROID)
......
......@@ -30,6 +30,11 @@ class HostResolver;
}
namespace chromecast {
namespace media {
class MediaPipelineDevice;
class MediaPipelineDeviceParams;
}
namespace shell {
class CastBrowserMainParts;
......@@ -48,6 +53,13 @@ class CastContentBrowserClient: public content::ContentBrowserClient {
std::vector<scoped_refptr<content::BrowserMessageFilter>>
PlatformGetBrowserMessageFilters();
#if !defined(OS_ANDROID)
// Creates a MediaPipelineDevice (CMA backend) for media playback, called
// once per media player instance.
scoped_ptr<media::MediaPipelineDevice> PlatformCreateMediaPipelineDevice(
const media::MediaPipelineDeviceParams& params);
#endif
// content::ContentBrowserClient implementation:
content::BrowserMainParts* CreateBrowserMainParts(
const content::MainFunctionParams& parameters) override;
......
......@@ -4,6 +4,7 @@
#include "chromecast/browser/cast_content_browser_client.h"
#include "chromecast/media/cma/backend/media_pipeline_device.h"
#include "content/public/browser/browser_message_filter.h"
#include "media/audio/audio_manager_factory.h"
......@@ -26,5 +27,13 @@ CastContentBrowserClient::PlatformCreateAudioManagerFactory() {
return scoped_ptr<::media::AudioManagerFactory>();
}
#if !defined(OS_ANDROID)
scoped_ptr<media::MediaPipelineDevice>
CastContentBrowserClient::PlatformCreateMediaPipelineDevice(
const media::MediaPipelineDeviceParams& params) {
return media::CreateMediaPipelineDevice(params);
}
#endif
} // namespace shell
} // namespace chromecast
......@@ -297,9 +297,12 @@ void UpdateVideoSurfaceHost(int surface_id, const gfx::QuadF& quad) {
} // namespace
CmaMessageFilterHost::CmaMessageFilterHost(int render_process_id)
CmaMessageFilterHost::CmaMessageFilterHost(
int render_process_id,
const media::CreatePipelineDeviceCB& create_pipeline_device_cb)
: content::BrowserMessageFilter(CastMediaMsgStart),
process_id_(render_process_id),
create_pipeline_device_cb_(create_pipeline_device_cb),
task_runner_(CmaMessageLoop::GetTaskRunner()),
weak_factory_(this) {
weak_this_ = weak_factory_.GetWeakPtr();
......@@ -382,10 +385,9 @@ void CmaMessageFilterHost::CreateMedia(int media_id, LoadType load_type) {
base::Bind(&SetMediaPipeline,
process_id_, media_id, media_pipeline_host.get()));
task_runner_->PostTask(
FROM_HERE,
base::Bind(&MediaPipelineHost::Initialize,
base::Unretained(media_pipeline_host.get()),
load_type, client));
FROM_HERE, base::Bind(&MediaPipelineHost::Initialize,
base::Unretained(media_pipeline_host.get()),
load_type, client, create_pipeline_device_cb_));
std::pair<MediaPipelineMap::iterator, bool> ret =
media_pipelines_.insert(
std::make_pair(media_id, media_pipeline_host.release()));
......
......@@ -12,6 +12,7 @@
#include "base/memory/shared_memory.h"
#include "base/memory/weak_ptr.h"
#include "chromecast/common/media/cma_ipc_common.h"
#include "chromecast/media/cma/backend/media_pipeline_device.h"
#include "chromecast/media/cma/pipeline/load_type.h"
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/browser_thread.h"
......@@ -42,7 +43,9 @@ class MediaPipelineHost;
class CmaMessageFilterHost
: public content::BrowserMessageFilter {
public:
explicit CmaMessageFilterHost(int render_process_id);
CmaMessageFilterHost(
int render_process_id,
const media::CreatePipelineDeviceCB& create_pipeline_device_cb);
// content::BrowserMessageFilter implementation.
void OnChannelClosing() override;
......@@ -109,6 +112,9 @@ class CmaMessageFilterHost
// Render process ID correponding to this message filter.
const int process_id_;
// Factory function for device-specific part of media pipeline creation
media::CreatePipelineDeviceCB create_pipeline_device_cb_;
// List of media pipeline and message loop media pipelines are running on.
MediaPipelineMap media_pipelines_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
......@@ -123,4 +129,3 @@ class CmaMessageFilterHost
} // namespace chromecast
#endif // CHROMECAST_BROWSER_MEDIA_CMA_MESSAGE_FILTER_HOST_H_
......@@ -52,15 +52,15 @@ MediaPipelineHost::~MediaPipelineHost() {
void MediaPipelineHost::Initialize(
LoadType load_type,
const MediaPipelineClient& client) {
const MediaPipelineClient& client,
const media::CreatePipelineDeviceCB& create_pipeline_device_cb) {
DCHECK(thread_checker_.CalledOnValidThread());
media_pipeline_.reset(new MediaPipelineImpl());
MediaPipelineDeviceParams default_parameters;
if (load_type == kLoadTypeMediaStream)
default_parameters.sync_type = MediaPipelineDeviceParams::kModeIgnorePts;
media_pipeline_->Initialize(
load_type,
CreateMediaPipelineDevice(default_parameters).Pass());
load_type, create_pipeline_device_cb.Run(default_parameters).Pass());
media_pipeline_->SetClient(client);
}
......@@ -171,4 +171,3 @@ void MediaPipelineHost::NotifyPipeWrite(TrackId track_id) {
} // namespace media
} // namespace chromecast
......@@ -14,6 +14,7 @@
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "chromecast/common/media/cma_ipc_common.h"
#include "chromecast/media/cma/backend/media_pipeline_device.h"
#include "chromecast/media/cma/pipeline/load_type.h"
#include "media/base/pipeline_status.h"
......@@ -40,8 +41,10 @@ class MediaPipelineHost {
MediaPipelineHost();
~MediaPipelineHost();
void Initialize(LoadType load_type,
const MediaPipelineClient& client);
void Initialize(
LoadType load_type,
const MediaPipelineClient& client,
const media::CreatePipelineDeviceCB& create_pipeline_device_cb);
void SetAvPipe(TrackId track_id,
scoped_ptr<base::SharedMemory> shared_mem,
......@@ -83,4 +86,3 @@ class MediaPipelineHost {
} // namespace chromecast
#endif // CHROMECAST_BROWSER_MEDIA_MEDIA_PIPELINE_HOST_H_
......@@ -5,6 +5,7 @@
#ifndef CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_DEVICE_H_
#define CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_DEVICE_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
......@@ -32,7 +33,12 @@ class MediaPipelineDevice {
DISALLOW_COPY_AND_ASSIGN(MediaPipelineDevice);
};
// Factory to create a MediaPipelineDevice.
// Factory method to create a MediaPipelineDevice.
typedef base::Callback<scoped_ptr<MediaPipelineDevice>(
const MediaPipelineDeviceParams&)> CreatePipelineDeviceCB;
// Direct creation of vendor-specific media device pipeline.
// TODO(halliwell): move into libcast_media
scoped_ptr<MediaPipelineDevice> CreateMediaPipelineDevice(
const MediaPipelineDeviceParams& params);
......
......@@ -41,9 +41,9 @@ class CastContentRendererClient : public content::ContentRendererClient {
void AddKeySystems(
std::vector< ::media::KeySystemInfo>* key_systems) override;
#if !defined(OS_ANDROID)
scoped_ptr<media::RendererFactory> CreateMediaRendererFactory(
scoped_ptr<::media::RendererFactory> CreateMediaRendererFactory(
content::RenderFrame* render_frame,
const scoped_refptr<media::MediaLog>& media_log) override;
const scoped_refptr<::media::MediaLog>& media_log) override;
#endif
blink::WebPrescientNetworking* GetPrescientNetworking() override;
void DeferMediaLoad(content::RenderFrame* render_frame,
......
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