1 // Copyright 2013 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 "chrome/browser/media/encrypted_media_message_filter_android.h"
9 #include "chrome/common/encrypted_media_messages_android.h"
10 #include "ipc/ipc_message_macros.h"
11 #include "media/base/android/media_codec_bridge.h"
12 #include "media/base/android/media_drm_bridge.h"
14 using content::BrowserThread;
15 using media::MediaCodecBridge;
16 using media::MediaDrmBridge;
20 const size_t kMaxKeySystemLength = 256;
22 // Check whether the available codecs are supported.
23 static android::SupportedCodecs GetSupportedCodecs(
24 android::SupportedCodecs requested_codecs,
25 bool video_must_be_compositable) {
26 android::SupportedCodecs supported_codecs = android::NO_SUPPORTED_CODECS;
27 // TODO(qinmin): Remove this DCHECK and query VP8/Vorbis capabilities
28 // once webm support is added to Android.
29 DCHECK(!(requested_codecs & android::WEBM_VP8_AND_VORBIS));
31 #if defined(USE_PROPRIETARY_CODECS)
32 if ((requested_codecs & android::MP4_AAC) &&
33 MediaCodecBridge::CanDecode("mp4a", false)) {
34 supported_codecs = static_cast<android::SupportedCodecs>(
35 supported_codecs | android::MP4_AAC);
38 // TODO(qinmin): Remove the composition logic when secure contents can be
40 if ((requested_codecs & android::MP4_AVC1) &&
41 MediaCodecBridge::CanDecode("avc1", !video_must_be_compositable)) {
42 supported_codecs = static_cast<android::SupportedCodecs>(
43 supported_codecs | android::MP4_AVC1);
45 #endif // defined(USE_PROPRIETARY_CODECS)
47 return supported_codecs;
50 EncryptedMediaMessageFilterAndroid::EncryptedMediaMessageFilterAndroid()
51 : BrowserMessageFilter(EncryptedMediaMsgStart) {}
53 EncryptedMediaMessageFilterAndroid::~EncryptedMediaMessageFilterAndroid() {}
55 bool EncryptedMediaMessageFilterAndroid::OnMessageReceived(
56 const IPC::Message& message, bool* message_was_ok) {
58 IPC_BEGIN_MESSAGE_MAP_EX(
59 EncryptedMediaMessageFilterAndroid, message, *message_was_ok)
60 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_GetSupportedKeySystems,
61 OnGetSupportedKeySystems)
62 IPC_MESSAGE_UNHANDLED(handled = false)
63 IPC_END_MESSAGE_MAP_EX()
67 void EncryptedMediaMessageFilterAndroid::OverrideThreadForMessage(
68 const IPC::Message& message, BrowserThread::ID* thread) {
69 // Move the IPC handling to FILE thread as it is not very cheap.
70 if (message.type() == ChromeViewHostMsg_GetSupportedKeySystems::ID)
71 *thread = BrowserThread::FILE;
74 void EncryptedMediaMessageFilterAndroid::OnGetSupportedKeySystems(
75 const SupportedKeySystemRequest& request,
76 SupportedKeySystemResponse* response) {
78 NOTREACHED() << "NULL response pointer provided.";
82 if (request.key_system.size() > kMaxKeySystemLength) {
83 NOTREACHED() << "Invalid key system: " << request.key_system;
87 // TODO(qinmin): Convert codecs to container types and check whether they
88 // are supported with the key system.
89 if (!MediaDrmBridge::IsKeySystemSupportedWithType(request.key_system, ""))
92 DCHECK_EQ(request.codecs >> 3, 0) << "unrecognized codec";
93 response->key_system = request.key_system;
94 // TODO(qinmin): check composition is supported or not.
95 response->compositing_codecs = GetSupportedCodecs(request.codecs, true);
96 response->non_compositing_codecs = GetSupportedCodecs(request.codecs, false);