Provides method for setting a BrowserCdmFactory for IPC-based CDM.
R=xhwang@chromium.org
BUG=435176
TEST=manually verified EME playback on ContentShell APK
Review URL: https://codereview.chromium.org/774423002
Cr-Commit-Position: refs/heads/master@{#306964}
diff --git a/media/base/BUILD.gn b/media/base/BUILD.gn
index 3a1beff..8b69fc1a 100644
--- a/media/base/BUILD.gn
+++ b/media/base/BUILD.gn
@@ -196,6 +196,7 @@
sources += [
"browser_cdm.cc",
"browser_cdm.h",
+ "browser_cdm_factory.cc",
"browser_cdm_factory.h",
]
}
diff --git a/media/base/android/BUILD.gn b/media/base/android/BUILD.gn
index 3e7ffe7..71e9edc7 100644
--- a/media/base/android/BUILD.gn
+++ b/media/base/android/BUILD.gn
@@ -15,6 +15,7 @@
"audio_decoder_job.cc",
"audio_decoder_job.h",
"browser_cdm_factory_android.cc",
+ "browser_cdm_factory_android.h",
"demuxer_android.h",
"demuxer_stream_player_params.cc",
"demuxer_stream_player_params.h",
diff --git a/media/base/android/browser_cdm_factory_android.cc b/media/base/android/browser_cdm_factory_android.cc
index d43c4af3..9fa308e 100644
--- a/media/base/android/browser_cdm_factory_android.cc
+++ b/media/base/android/browser_cdm_factory_android.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "media/base/browser_cdm_factory.h"
+#include "media/base/android/browser_cdm_factory_android.h"
#include "base/command_line.h"
#include "base/logging.h"
@@ -12,7 +12,7 @@
namespace media {
-scoped_ptr<BrowserCdm> CreateBrowserCdm(
+scoped_ptr<BrowserCdm> BrowserCdmFactoryAndroid::CreateBrowserCdm(
const std::string& key_system,
const BrowserCdm::SessionCreatedCB& session_created_cb,
const BrowserCdm::SessionMessageCB& session_message_cb,
diff --git a/media/base/android/browser_cdm_factory_android.h b/media/base/android/browser_cdm_factory_android.h
new file mode 100644
index 0000000..e43e2353
--- /dev/null
+++ b/media/base/android/browser_cdm_factory_android.h
@@ -0,0 +1,33 @@
+// 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_BASE_BROWSER_CDM_FACTORY_ANDROID_H_
+#define MEDIA_BASE_BROWSER_CDM_FACTORY_ANDROID_H_
+
+#include "base/macros.h"
+#include "media/base/browser_cdm_factory.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+class MEDIA_EXPORT BrowserCdmFactoryAndroid : public BrowserCdmFactory {
+ public:
+ BrowserCdmFactoryAndroid() {}
+ ~BrowserCdmFactoryAndroid() final {};
+
+ scoped_ptr<BrowserCdm> CreateBrowserCdm(
+ const std::string& key_system,
+ const BrowserCdm::SessionCreatedCB& session_created_cb,
+ const BrowserCdm::SessionMessageCB& session_message_cb,
+ const BrowserCdm::SessionReadyCB& session_ready_cb,
+ const BrowserCdm::SessionClosedCB& session_closed_cb,
+ const BrowserCdm::SessionErrorCB& session_error_cb) final;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BrowserCdmFactoryAndroid);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_BROWSER_CDM_FACTORY_ANDROID_H_
diff --git a/media/base/browser_cdm_factory.cc b/media/base/browser_cdm_factory.cc
new file mode 100644
index 0000000..5eda155
--- /dev/null
+++ b/media/base/browser_cdm_factory.cc
@@ -0,0 +1,48 @@
+// 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/base/browser_cdm_factory.h"
+
+#include "base/logging.h"
+
+#if defined(OS_ANDROID)
+#include "media/base/android/browser_cdm_factory_android.h"
+#endif
+
+namespace media {
+
+namespace {
+BrowserCdmFactory* g_cdm_factory = NULL;
+}
+
+void SetBrowserCdmFactory(BrowserCdmFactory* factory) {
+ DCHECK(!g_cdm_factory);
+ g_cdm_factory = factory;
+}
+
+scoped_ptr<BrowserCdm> CreateBrowserCdm(
+ const std::string& key_system,
+ const BrowserCdm::SessionCreatedCB& session_created_cb,
+ const BrowserCdm::SessionMessageCB& session_message_cb,
+ const BrowserCdm::SessionReadyCB& session_ready_cb,
+ const BrowserCdm::SessionClosedCB& session_closed_cb,
+ const BrowserCdm::SessionErrorCB& session_error_cb) {
+ if (!g_cdm_factory) {
+#if defined(OS_ANDROID)
+ SetBrowserCdmFactory(new BrowserCdmFactoryAndroid);
+#else
+ LOG(ERROR) << "Cannot create BrowserCdm: no BrowserCdmFactory available!";
+ return scoped_ptr<BrowserCdm>();
+#endif
+ }
+
+ return g_cdm_factory->CreateBrowserCdm(key_system,
+ session_created_cb,
+ session_message_cb,
+ session_ready_cb,
+ session_closed_cb,
+ session_error_cb);
+}
+
+} // namespace media
diff --git a/media/base/browser_cdm_factory.h b/media/base/browser_cdm_factory.h
index e6fa47b..f73ca5d 100644
--- a/media/base/browser_cdm_factory.h
+++ b/media/base/browser_cdm_factory.h
@@ -7,12 +7,34 @@
#include <string>
+#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "media/base/browser_cdm.h"
#include "media/base/media_export.h"
namespace media {
+class MEDIA_EXPORT BrowserCdmFactory {
+ public:
+ BrowserCdmFactory() {}
+ virtual ~BrowserCdmFactory() {}
+
+ virtual scoped_ptr<BrowserCdm> CreateBrowserCdm(
+ const std::string& key_system,
+ const BrowserCdm::SessionCreatedCB& session_created_cb,
+ const BrowserCdm::SessionMessageCB& session_message_cb,
+ const BrowserCdm::SessionReadyCB& session_ready_cb,
+ const BrowserCdm::SessionClosedCB& session_closed_cb,
+ const BrowserCdm::SessionErrorCB& session_error_cb) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BrowserCdmFactory);
+};
+
+// Provides a factory for creating BrowserCdm instances. There is only one
+// BrowserCdmFactory per process.
+void SetBrowserCdmFactory(BrowserCdmFactory* factory);
+
// Creates a BrowserCdm for |key_system|. Returns NULL if the CDM cannot be
// created.
// TODO(xhwang): Add ifdef for IPC based CDM.
diff --git a/media/media.gyp b/media/media.gyp
index 055507ff..30b8777 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -660,6 +660,7 @@
'sources': [
'base/browser_cdm.cc',
'base/browser_cdm.h',
+ 'base/browser_cdm_factory.cc',
'base/browser_cdm_factory.h',
],
}],
@@ -1697,6 +1698,7 @@
'base/android/audio_decoder_job.cc',
'base/android/audio_decoder_job.h',
'base/android/browser_cdm_factory_android.cc',
+ 'base/android/browser_cdm_factory_android.h',
'base/android/demuxer_android.h',
'base/android/demuxer_stream_player_params.cc',
'base/android/demuxer_stream_player_params.h',