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 // Check whether the available codecs are supported.
21 static android::SupportedCodecs GetSupportedCodecs(
22 android::SupportedCodecs requested_codecs,
23 bool video_must_be_compositable) {
24 android::SupportedCodecs supported_codecs = android::NO_SUPPORTED_CODECS;
25 // TODO(qinmin): Remove this DCHECK and query VP8/Vorbis capabilities
26 // once webm support is added to Android.
27 DCHECK(!(requested_codecs & android::WEBM_VP8_AND_VORBIS));
29 #if defined(USE_PROPRIETARY_CODECS)
30 if ((requested_codecs & android::MP4_AAC) &&
31 MediaCodecBridge::CanDecode("mp4a", false)) {
32 supported_codecs = static_cast<android::SupportedCodecs>(
33 supported_codecs | android::MP4_AAC);
36 // TODO(qinmin): Remove the composition logic when secure contents can be
38 if ((requested_codecs & android::MP4_AVC1) &&
39 MediaCodecBridge::CanDecode("avc1", !video_must_be_compositable)) {
40 supported_codecs = static_cast<android::SupportedCodecs>(
41 supported_codecs | android::MP4_AVC1);
43 #endif // defined(USE_PROPRIETARY_CODECS)
45 return supported_codecs;
48 EncryptedMediaMessageFilterAndroid::EncryptedMediaMessageFilterAndroid() {}
50 EncryptedMediaMessageFilterAndroid::~EncryptedMediaMessageFilterAndroid() {}
52 bool EncryptedMediaMessageFilterAndroid::OnMessageReceived(
53 const IPC::Message& message, bool* message_was_ok) {
55 IPC_BEGIN_MESSAGE_MAP_EX(
56 EncryptedMediaMessageFilterAndroid, message, *message_was_ok)
57 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_GetSupportedKeySystems,
58 OnGetSupportedKeySystems)
59 IPC_MESSAGE_UNHANDLED(handled = false)
60 IPC_END_MESSAGE_MAP_EX()
64 void EncryptedMediaMessageFilterAndroid::OverrideThreadForMessage(
65 const IPC::Message& message, BrowserThread::ID* thread) {
66 // Move the IPC handling to FILE thread as it is not very cheap.
67 if (message.type() == ChromeViewHostMsg_GetSupportedKeySystems::ID)
68 *thread = BrowserThread::FILE;
71 void EncryptedMediaMessageFilterAndroid::OnGetSupportedKeySystems(
72 const SupportedKeySystemRequest& request,
73 SupportedKeySystemResponse* response) {
74 if (!MediaDrmBridge::IsAvailable() || !MediaCodecBridge::IsAvailable())
77 // TODO(qinmin): Convert codecs to container types and check whether they
78 // are supported with the key system.
79 if (!MediaDrmBridge::IsCryptoSchemeSupported(request.uuid, ""))
82 DCHECK_EQ(request.codecs >> 3, 0) << "unrecognized codec";
83 response->uuid = request.uuid;
84 // TODO(qinmin): check composition is supported or not.
85 response->compositing_codecs =
86 GetSupportedCodecs(request.codecs, true);
87 response->non_compositing_codecs =
88 GetSupportedCodecs(request.codecs, false);