Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / media / base / android / browser_cdm_factory_android.cc
blob475af4c75d3a179d2c72e9681914692f4e7ff638
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/base/android/browser_cdm_factory_android.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "media/base/android/media_drm_bridge.h"
11 #include "media/base/media_switches.h"
12 #include "third_party/widevine/cdm/widevine_cdm_common.h"
14 namespace media {
16 scoped_ptr<BrowserCdm> BrowserCdmFactoryAndroid::CreateBrowserCdm(
17 const std::string& key_system,
18 bool use_secure_surface,
19 const SessionMessageCB& session_message_cb,
20 const SessionClosedCB& session_closed_cb,
21 const LegacySessionErrorCB& legacy_session_error_cb,
22 const SessionKeysChangeCB& session_keys_change_cb,
23 const SessionExpirationUpdateCB& session_expiration_update_cb) {
24 if (!MediaDrmBridge::IsKeySystemSupported(key_system)) {
25 NOTREACHED() << "Unsupported key system: " << key_system;
26 return scoped_ptr<BrowserCdm>();
29 scoped_ptr<MediaDrmBridge> cdm(
30 MediaDrmBridge::Create(key_system, session_message_cb, session_closed_cb,
31 legacy_session_error_cb, session_keys_change_cb,
32 session_expiration_update_cb));
33 if (!cdm) {
34 NOTREACHED() << "MediaDrmBridge cannot be created for " << key_system;
35 return scoped_ptr<BrowserCdm>();
38 // TODO(sandersd): Pass the security level from key system.
39 // http://crbug.com/467779
40 if (key_system == kWidevineKeySystem) {
41 MediaDrmBridge::SecurityLevel security_level =
42 use_secure_surface ? MediaDrmBridge::SECURITY_LEVEL_1
43 : MediaDrmBridge::SECURITY_LEVEL_3;
44 if (!cdm->SetSecurityLevel(security_level)) {
45 DVLOG(1) << "failed to set security level " << security_level;
46 return scoped_ptr<BrowserCdm>();
48 } else {
49 // Assume other key systems do not support full compositing.
50 if (!use_secure_surface) {
51 NOTREACHED()
52 << key_system
53 << " may require use_video_overlay_for_embedded_encrypted_video";
54 return scoped_ptr<BrowserCdm>();
58 return cdm.Pass();
61 } // namespace media