This source file includes following definitions.
- GetSupportedCodecs
- OnMessageReceived
- OverrideThreadForMessage
- OnGetSupportedKeySystems
#include "chrome/browser/media/encrypted_media_message_filter_android.h"
#include <string>
#include "chrome/common/encrypted_media_messages_android.h"
#include "ipc/ipc_message_macros.h"
#include "media/base/android/media_codec_bridge.h"
#include "media/base/android/media_drm_bridge.h"
using content::BrowserThread;
using media::MediaCodecBridge;
using media::MediaDrmBridge;
namespace chrome {
const size_t kMaxKeySystemLength = 256;
static android::SupportedCodecs GetSupportedCodecs(
android::SupportedCodecs requested_codecs,
bool video_must_be_compositable) {
android::SupportedCodecs supported_codecs = android::NO_SUPPORTED_CODECS;
DCHECK(!(requested_codecs & android::WEBM_VP8_AND_VORBIS));
#if defined(USE_PROPRIETARY_CODECS)
if ((requested_codecs & android::MP4_AAC) &&
MediaCodecBridge::CanDecode("mp4a", false)) {
supported_codecs = static_cast<android::SupportedCodecs>(
supported_codecs | android::MP4_AAC);
}
if ((requested_codecs & android::MP4_AVC1) &&
MediaCodecBridge::CanDecode("avc1", !video_must_be_compositable)) {
supported_codecs = static_cast<android::SupportedCodecs>(
supported_codecs | android::MP4_AVC1);
}
#endif
return supported_codecs;
}
EncryptedMediaMessageFilterAndroid::EncryptedMediaMessageFilterAndroid()
: BrowserMessageFilter(EncryptedMediaMsgStart) {}
EncryptedMediaMessageFilterAndroid::~EncryptedMediaMessageFilterAndroid() {}
bool EncryptedMediaMessageFilterAndroid::OnMessageReceived(
const IPC::Message& message, bool* message_was_ok) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(
EncryptedMediaMessageFilterAndroid, message, *message_was_ok)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_GetSupportedKeySystems,
OnGetSupportedKeySystems)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
return handled;
}
void EncryptedMediaMessageFilterAndroid::OverrideThreadForMessage(
const IPC::Message& message, BrowserThread::ID* thread) {
if (message.type() == ChromeViewHostMsg_GetSupportedKeySystems::ID)
*thread = BrowserThread::FILE;
}
void EncryptedMediaMessageFilterAndroid::OnGetSupportedKeySystems(
const SupportedKeySystemRequest& request,
SupportedKeySystemResponse* response) {
if (!response) {
NOTREACHED() << "NULL response pointer provided.";
return;
}
if (request.key_system.size() > kMaxKeySystemLength) {
NOTREACHED() << "Invalid key system: " << request.key_system;
return;
}
if (!MediaDrmBridge::IsKeySystemSupportedWithType(request.key_system, ""))
return;
DCHECK_EQ(request.codecs >> 3, 0) << "unrecognized codec";
response->key_system = request.key_system;
response->compositing_codecs = GetSupportedCodecs(request.codecs, true);
response->non_compositing_codecs = GetSupportedCodecs(request.codecs, false);
}
}