Home | History | Annotate | Download | only in crypto
      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.
      4 
      5 #include "content/renderer/media/crypto/key_systems_info.h"
      6 #include "third_party/WebKit/public/platform/WebString.h"
      7 
      8 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
      9 
     10 // The following must be after widevine_cdm_version.h.
     11 
     12 #if defined(WIDEVINE_CDM_AVAILABLE) && \
     13     defined(OS_LINUX) && !defined(OS_CHROMEOS)
     14 #include <gnu/libc-version.h>
     15 #include "base/logging.h"
     16 #include "base/version.h"
     17 #endif
     18 
     19 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
     20 #include "base/command_line.h"
     21 #include "media/base/media_switches.h"
     22 #endif
     23 
     24 namespace content {
     25 
     26 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
     27 
     28 static const char kExternalClearKeyKeySystem[] =
     29     "org.chromium.externalclearkey";
     30 
     31 #if defined(WIDEVINE_CDM_AVAILABLE)
     32 // TODO(ddorwin): Automatically support parent systems: http://crbug.com/164303.
     33 static const char kWidevineBaseKeySystem[] = "com.widevine";
     34 
     35 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
     36 // The supported codecs depend on what the CDM provides.
     37 static const char kWidevineVideoMp4Codecs[] =
     38 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \
     39     defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
     40     "avc1,mp4a";
     41 #elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
     42     "avc1";
     43 #else
     44     "";  // No codec strings are supported.
     45 #endif
     46 
     47 static const char kWidevineAudioMp4Codecs[] =
     48 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
     49     "mp4a";
     50 #else
     51     "";  // No codec strings are supported.
     52 #endif
     53 #endif  // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
     54 
     55 static inline bool IsWidevine(const std::string& key_system) {
     56   return key_system == kWidevineKeySystem ||
     57          key_system == kWidevineBaseKeySystem;
     58 }
     59 #endif  // defined(WIDEVINE_CDM_AVAILABLE)
     60 
     61 const MediaFormatAndKeySystem kSupportedFormatKeySystemCombinations[] = {
     62   // Clear Key.
     63   { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem },
     64   { "audio/webm", "vorbis", kClearKeyKeySystem },
     65 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
     66   { "video/mp4", "avc1,mp4a", kClearKeyKeySystem },
     67   { "audio/mp4", "mp4a", kClearKeyKeySystem },
     68 #endif
     69 
     70   // External Clear Key (used for testing).
     71   { "video/webm", "vorbis,vp8,vp8.0", kExternalClearKeyKeySystem },
     72   { "audio/webm", "vorbis", kExternalClearKeyKeySystem },
     73 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
     74   { "video/mp4", "avc1,mp4a", kExternalClearKeyKeySystem },
     75   { "audio/mp4", "mp4a", kExternalClearKeyKeySystem },
     76 #endif
     77 
     78 #if defined(WIDEVINE_CDM_AVAILABLE)
     79   // Widevine.
     80   { "video/webm", "vorbis,vp8,vp8.0", kWidevineKeySystem },
     81   { "audio/webm", "vorbis", kWidevineKeySystem },
     82   { "video/webm", "vorbis,vp8,vp8.0", kWidevineBaseKeySystem },
     83   { "audio/webm", "vorbis", kWidevineBaseKeySystem },
     84 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
     85 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
     86   { "video/mp4", kWidevineVideoMp4Codecs, kWidevineKeySystem },
     87   { "video/mp4", kWidevineVideoMp4Codecs, kWidevineBaseKeySystem },
     88   { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineKeySystem },
     89   { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineBaseKeySystem },
     90 #endif  // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
     91 #endif  // defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
     92 #endif  // WIDEVINE_CDM_AVAILABLE
     93 };
     94 
     95 const int kNumSupportedFormatKeySystemCombinations =
     96     arraysize(kSupportedFormatKeySystemCombinations);
     97 
     98 #if defined(ENABLE_PEPPER_CDMS)
     99 const KeySystemPepperTypePair kKeySystemToPepperTypeMapping[] = {
    100   { kExternalClearKeyKeySystem, "application/x-ppapi-clearkey-cdm"},
    101 #if defined(WIDEVINE_CDM_AVAILABLE)
    102   { kWidevineKeySystem, kWidevineCdmPluginMimeType}
    103 #endif  // WIDEVINE_CDM_AVAILABLE
    104 };
    105 
    106 const int kNumKeySystemToPepperTypeMapping =
    107     arraysize(kKeySystemToPepperTypeMapping);
    108 #endif  // defined(ENABLE_PEPPER_CDMS)
    109 
    110 #if defined(OS_ANDROID)
    111 // TODO(qinmin): add UUIDs for other key systems.
    112 const KeySystemUUIDPair kKeySystemToUUIDMapping[] = {
    113 #if defined(WIDEVINE_CDM_AVAILABLE)
    114   { kWidevineKeySystem, { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
    115                           0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }
    116   }
    117 #endif  // defined(WIDEVINE_CDM_AVAILABLE)
    118 };
    119 
    120 // arraySize() does not work if the array is empty, so use ARRAYSIZE_UNSAFE().
    121 const int kNumKeySystemToUUIDMapping =
    122     ARRAYSIZE_UNSAFE(kKeySystemToUUIDMapping);
    123 #endif  // defined(OS_ANDROID)
    124 
    125 bool IsSystemCompatible(const std::string& key_system) {
    126 #if defined(WIDEVINE_CDM_AVAILABLE) && \
    127     defined(OS_LINUX) && !defined(OS_CHROMEOS)
    128   if (IsWidevine(key_system)) {
    129     Version glibc_version(gnu_get_libc_version());
    130     DCHECK(glibc_version.IsValid());
    131     return !glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION);
    132   }
    133 #endif
    134   return true;
    135 }
    136 
    137 bool IsCanPlayTypeSuppressed(const std::string& key_system) {
    138 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
    139   // See http://crbug.com/237627.
    140   if (IsWidevine(key_system) &&
    141       !CommandLine::ForCurrentProcess()->HasSwitch(
    142           switches::kOverrideEncryptedMediaCanPlayType))
    143     return true;
    144 #endif
    145   return false;
    146 }
    147 
    148 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) {
    149   if (key_system == kClearKeyKeySystem)
    150     return "ClearKey";
    151 #if defined(WIDEVINE_CDM_AVAILABLE)
    152   if (key_system == kWidevineKeySystem)
    153     return "Widevine";
    154 #endif  // WIDEVINE_CDM_AVAILABLE
    155   return "Unknown";
    156 }
    157 
    158 bool CanUseBuiltInAesDecryptor(const std::string& key_system) {
    159   return  key_system == kClearKeyKeySystem;
    160 }
    161 
    162 } // namespace content
    163